22 * angular-ui-router-css
33 * https://github.com/harm-less/angular-ui-router-css
44
5- * Version: 0.1.0 - 2017-05-27
5+ * Version: 0.1.0 - 2017-05-30
66 * License: MIT
77 */
88( function ( angular , window ) {
99
1010 'use strict' ;
1111
1212 // used for the Uglify Grunt task when compiling the build. It sets a global variable 'DEBUG' and sets it to false.
13+ /* istanbul ignore next */
1314 if ( angular . isUndefined ( window . DEBUG ) ) {
1415 window . DEBUG = true ;
1516 }
2829 var addedDefinitions = [ ] ;
2930 var firstAddedStateDefinition ;
3031
31- function log ( message ) {
32- console . log ( 'Log "angular-ui-router-css": ' + message ) ;
32+ function error ( message ) {
33+ throw Error ( 'Error "angular-ui-router-css": ' + message ) ;
3334 }
3435
3536 function isInt ( value ) {
6061 url : definition
6162 } ;
6263 }
63- else if ( angular . isObject ( definition ) ) {
64- if ( ! definition . url ) {
65- if ( DEBUG ) {
66- log ( 'The definition needs to contain a URL: ' + JSON . stringify ( definition ) ) ;
67- }
68- return ;
69- }
7064
71- // Using specified ID as new object key.
72- if ( definition . id ) {
73- key = definition . id ;
74- }
65+ if ( angular . isUndefined ( definition . url ) ) {
66+ error ( 'The definition needs to contain a URL: ' + JSON . stringify ( definition ) ) ;
67+ }
68+
69+ // Using specified ID as new object key.
70+ if ( definition . id ) {
71+ key = definition . id ;
7572 }
7673
7774 // Using custom unique resource ID instead of simple array index.
117114 */
118115 function loadStyleDefinition ( definition , options ) {
119116 var deferred = _$q . defer ( ) ;
120- if ( definition . url ) {
121- if ( DEBUG && ! window . loadStylesheet ) {
122- log ( 'Package "betsol-load-stylesheet" must be loaded before you can use "angular-ui-router-css"' ) ;
123- }
124117
125- definition . element = window . loadStylesheet ( definition . url , function ( ) {
126- deferred . resolve ( ) ;
127- } , options ) ;
118+ if ( DEBUG && ! window . loadStylesheet ) {
119+ error ( 'Package "betsol-load-stylesheet" must be loaded before you can use "angular-ui-router-css"' ) ;
128120 }
129- else {
121+
122+ definition . element = window . loadStylesheet ( definition . url , function ( ) {
130123 deferred . resolve ( ) ;
131- }
124+ } , options ) ;
125+
132126 return deferred . promise ;
133127 }
134128
180174 angular . forEach ( definitions , function ( definition ) {
181175 if ( isInjectable ( definition ) ) {
182176 definition = normalizeStyleDefinition ( inject ( definition ) ) ;
183- console . log ( 'gg' , definition ) ;
184177 }
185178 if ( ! definition . url ) {
186179 return ;
187180 }
188181
189- console . log ( definition . url ) ;
190182 var definitionPromise = loadStyleDefinition ( definition , {
191183 insertBefore : linkElementPlaceholder
192184 } ) ;
228220 }
229221 }
230222
231- angular . module ( 'hl.ui.router.css ' , [ 'ui.router' ] )
223+ angular . module ( 'hl.css. ui.router' , [ 'ui.router' ] )
232224
233225 . config ( [ "$stateProvider" , function ( $stateProvider ) {
234226
249241 _$q = $q ;
250242 _$injector = $injector ;
251243
252- $transitions . onBefore ( null , function ( transition ) {
244+ $transitions . onBefore ( { } , function ( transition ) {
253245 transition . addResolvable ( {
254246 token : '@css' ,
255247 resolveFn : function ( ) {
258250 } ) ;
259251 } ) ;
260252
261- $transitions . onSuccess ( null , function ( ) {
253+ $transitions . onSuccess ( { } , function ( ) {
262254 loadStylesForStateComplete ( ) ;
263255 } ) ;
264256 } ] )
269261 link : function ( scope , element , attrs ) {
270262 if ( DEBUG ) {
271263 if ( linkElementPlaceholder ) {
272- log ( 'The directive "uiCss" can only be set once' ) ;
264+ error ( 'The directive "uiCss" can only be set once' ) ;
273265 }
274266 else if ( document . getElementsByTagName ( 'head' ) [ 0 ] !== element [ 0 ] . parentNode ) {
275- log ( 'The directive "uiCss" must be placed in the "head" of your HTML' ) ;
267+ error ( 'The directive "uiCss" must be placed in the "head" of your HTML' ) ;
276268 }
277269 }
278270
300292 } ) ;
301293 }
302294 } ;
295+
296+ /* istanbul ignore next */
297+ if ( DEBUG ) {
298+
299+ // necessary for resetting unit tests as those variables are not reset automatically
300+ this . reset = function ( ) {
301+ linkElementPlaceholder = null ;
302+ nextResourceId = 1 ;
303+ removeDefinitionQueue = [ ] ;
304+ addedDefinitions = [ ] ;
305+ firstAddedStateDefinition = null ;
306+ } ;
307+ }
303308 } ] ) ;
304309
305310} ) ( angular , window ) ;
0 commit comments