Code cleanup part #1: move all the services and directive JS code in the app.js file into its own files
This commit is contained in:
parent
3cae6609a7
commit
9b87999c1c
97 changed files with 7076 additions and 6870 deletions
42
static/js/services/angular-helper.js
vendored
Normal file
42
static/js/services/angular-helper.js
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* Helper code for working with angular.
|
||||
*/
|
||||
angular.module('quay').factory('AngularHelper', [function() {
|
||||
var helper = {};
|
||||
|
||||
helper.buildConditionalLinker = function($animate, name, evaluator) {
|
||||
// Based off of a solution found here: http://stackoverflow.com/questions/20325480/angularjs-whats-the-best-practice-to-add-ngif-to-a-directive-programmatically
|
||||
return function ($scope, $element, $attr, ctrl, $transclude) {
|
||||
var block;
|
||||
var childScope;
|
||||
var roles;
|
||||
|
||||
$attr.$observe(name, function (value) {
|
||||
if (evaluator($scope.$eval(value))) {
|
||||
if (!childScope) {
|
||||
childScope = $scope.$new();
|
||||
$transclude(childScope, function (clone) {
|
||||
block = {
|
||||
startNode: clone[0],
|
||||
endNode: clone[clone.length++] = document.createComment(' end ' + name + ': ' + $attr[name] + ' ')
|
||||
};
|
||||
$animate.enter(clone, $element.parent(), $element);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (childScope) {
|
||||
childScope.$destroy();
|
||||
childScope = null;
|
||||
}
|
||||
|
||||
if (block) {
|
||||
$animate.leave(getBlockElements(block));
|
||||
block = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return helper;
|
||||
}]);
|
Reference in a new issue