|
1 | 1 | /** |
2 | 2 | * CSS on-demand for AngularJS |
3 | | - * @version v1.0.4 |
| 3 | + * @version v1.0.5 |
4 | 4 | * @author DOOR3, Alex Castillo |
5 | 5 | * @link http://door3.github.io/angular-css |
6 | 6 | * @license MIT License, http://www.opensource.org/licenses/MIT |
|
299 | 299 | if (!stylesheets) { |
300 | 300 | stylesheets = []; |
301 | 301 | // Add all stylesheets from custom directives to array |
302 | | - // @TODO: preload directives once we can parse css on directive register |
303 | | - //if ($directives.length) Array.prototype.push.apply(stylesheets, $directives); |
| 302 | + if ($directives.length) Array.prototype.push.apply(stylesheets, $directives); |
304 | 303 | // Add all stylesheets from ngRoute to array |
305 | 304 | if ($injector.has('$route')) Array.prototype.push.apply(stylesheets, $css.getFromRoutes($injector.get('$route').routes)); |
306 | 305 | // Add all stylesheets from UI Router to array |
|
438 | 437 | module.directive = function(directiveName, directiveFactory) { |
439 | 438 | var originalDirectiveFactory = angular.isFunction(directiveFactory) ? |
440 | 439 | directiveFactory : directiveFactory[directiveFactory.length - 1]; |
441 | | - var directive = {}; |
442 | | - directive.directiveName = directiveName; |
443 | | - $directives.push(directive); |
| 440 | + try { |
| 441 | + var directive = angular.copy(originalDirectiveFactory)(); |
| 442 | + directive.directiveName = directiveName; |
| 443 | + if (directive.hasOwnProperty('css')) $directives.push(directive); |
| 444 | + } catch (e) { } |
444 | 445 | return originalDirective.apply(this, arguments); |
445 | 446 | }; |
446 | 447 | module.config(['$provide','$injector', function ($provide, $injector) { |
447 | | - angular.forEach($directives, function (directive) { |
448 | | - var dirProvider = directive.directiveName + 'Directive'; |
| 448 | + angular.forEach($directives, function ($directive) { |
| 449 | + var dirProvider = $directive.directiveName + 'Directive'; |
449 | 450 | if ($injector.has(dirProvider)) { |
450 | | - $provide.decorator(dirProvider, ['$delegate', '$rootScope', function ($delegate, $rootScope) { |
| 451 | + $provide.decorator(dirProvider, ['$delegate', '$rootScope', '$timeout', function ($delegate, $rootScope, $timeout) { |
451 | 452 | var directive = $delegate[0]; |
452 | 453 | var compile = directive.compile; |
453 | | - directive.compile = function(element, attrs) { |
| 454 | + if (directive.css) $directive.css = directive.css; |
| 455 | + directive.compile = function(tElement, tAttrs) { |
454 | 456 | var link = compile ? compile.apply(this, arguments): false; |
455 | 457 | return function(scope, element, attrs) { |
456 | | - if (link) link.apply(this, arguments); |
| 458 | + $timeout(function () { |
| 459 | + if (link) link.apply(this, arguments); |
| 460 | + }); |
457 | 461 | $rootScope.$broadcast('$directiveAdd', directive, scope); |
458 | 462 | }; |
459 | 463 | }; |
|
0 commit comments