summaryrefslogtreecommitdiffstats
path: root/js/vendor/angular-ui/modules/directives/animate
diff options
context:
space:
mode:
Diffstat (limited to 'js/vendor/angular-ui/modules/directives/animate')
-rw-r--r--js/vendor/angular-ui/modules/directives/animate/animate.js36
-rw-r--r--js/vendor/angular-ui/modules/directives/animate/test/animateSpec.js71
2 files changed, 107 insertions, 0 deletions
diff --git a/js/vendor/angular-ui/modules/directives/animate/animate.js b/js/vendor/angular-ui/modules/directives/animate/animate.js
new file mode 100644
index 000000000..430874bb0
--- /dev/null
+++ b/js/vendor/angular-ui/modules/directives/animate/animate.js
@@ -0,0 +1,36 @@
+/**
+ * Animates the injection of new DOM elements by simply creating the DOM with a class and then immediately removing it
+ * Animations must be done using CSS3 transitions, but provide excellent flexibility
+ *
+ * @todo Add proper support for animating out
+ * @param [options] {mixed} Can be an object with multiple options, or a string with the animation class
+ * class {string} the CSS class(es) to use. For example, 'ui-hide' might be an excellent alternative class.
+ * @example <li ng-repeat="item in items" ui-animate=" 'ui-hide' ">{{item}}</li>
+ */
+angular.module('ui.directives').directive('uiAnimate', ['ui.config', '$timeout', function (uiConfig, $timeout) {
+ var options = {};
+ if (angular.isString(uiConfig.animate)) {
+ options['class'] = uiConfig.animate;
+ } else if (uiConfig.animate) {
+ options = uiConfig.animate;
+ }
+ return {
+ restrict: 'A', // supports using directive as element, attribute and class
+ link: function ($scope, element, attrs) {
+ var opts = {};
+ if (attrs.uiAnimate) {
+ opts = $scope.$eval(attrs.uiAnimate);
+ if (angular.isString(opts)) {
+ opts = {'class': opts};
+ }
+ }
+ opts = angular.extend({'class': 'ui-animate'}, options, opts);
+
+ element.addClass(opts['class']);
+ $timeout(function () {
+ element.removeClass(opts['class']);
+ }, 20, false);
+ }
+ };
+}]);
+
diff --git a/js/vendor/angular-ui/modules/directives/animate/test/animateSpec.js b/js/vendor/angular-ui/modules/directives/animate/test/animateSpec.js
new file mode 100644
index 000000000..219f499a8
--- /dev/null
+++ b/js/vendor/angular-ui/modules/directives/animate/test/animateSpec.js
@@ -0,0 +1,71 @@
+/*
+ * sample unit testing for sample templates and implementations
+ */
+describe('uiAnimate', function () {
+
+ // declare these up here to be global to all tests
+ var $rootScope, $compile, $timeout, uiConfig = angular.module('ui.config');
+
+ beforeEach(module('ui.directives'));
+
+ // inject in angular constructs. Injector knows about leading/trailing underscores and does the right thing
+ // otherwise, you would need to inject these into each test
+ beforeEach(inject(function (_$rootScope_, _$compile_, _$timeout_) {
+ $rootScope = _$rootScope_;
+ $compile = _$compile_;
+ $timeout = _$timeout_;
+ }));
+
+ afterEach(function () {
+ uiConfig.value('ui.config', {});
+ });
+
+ describe('behavior', function () {
+ it('should add a ui-animate class when the dom is compiled', function () {
+ var element = $compile('<div ui-animate></div>')($rootScope);
+ expect(element.hasClass('ui-animate')).toBeTruthy();
+ });
+ it('should remove the ui-animate class immediately after injection', function () {
+ var element = $compile('<div ui-animate></div>')($rootScope);
+ $timeout.flush();
+ expect(element.hasClass('ui-animate')).toBeFalsy();
+ });
+
+ });
+
+ describe('options', function () {
+ describe('passed', function () {
+
+ it('should use a string as the class', function () {
+ var element = $compile('<div ui-animate=" \'ui-hide\' "></div>')($rootScope);
+ expect(element.hasClass('ui-hide')).toBeTruthy();
+ });
+ it('should use an object\'s class attribute as the class', function () {
+ var element = $compile('<div ui-animate=" { \'class\' : \'ui-hide\' } "></div>')($rootScope);
+ expect(element.hasClass('ui-hide')).toBeTruthy();
+ });
+
+ });
+ describe('global', function () {
+
+ var uiConfig;
+ beforeEach(inject(function ($injector) {
+ uiConfig = $injector.get('ui.config');
+ }));
+
+ it('should use a string as the class', function () {
+ uiConfig.animate = 'ui-hide-global';
+ var element = $compile('<div ui-animate></div>')($rootScope);
+ expect(element.hasClass('ui-hide-global')).toBeTruthy();
+ });
+
+ it('should use an object\'s class attribute as the class', function () {
+ uiConfig.animate = { 'class': 'ui-hide-global' };
+ var element = $compile('<div ui-animate></div>')($rootScope);
+ expect(element.hasClass('ui-hide-global')).toBeTruthy();
+ });
+
+ });
+ });
+
+});