2
2
* angular-ui-router-css
3
3
* https://github.com/harm-less/angular-ui-router-css
4
4
5
- * Version: 0.1.0 - 2017-05-27
5
+ * Version: 0.1.0 - 2017-05-30
6
6
* License: MIT
7
7
*/
8
8
( function ( angular , window ) {
9
9
10
10
'use strict' ;
11
11
12
12
// 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 */
13
14
if ( angular . isUndefined ( window . DEBUG ) ) {
14
15
window . DEBUG = true ;
15
16
}
28
29
var addedDefinitions = [ ] ;
29
30
var firstAddedStateDefinition ;
30
31
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 ) ;
33
34
}
34
35
35
36
function isInt ( value ) {
60
61
url : definition
61
62
} ;
62
63
}
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
- }
70
64
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 ;
75
72
}
76
73
77
74
// Using custom unique resource ID instead of simple array index.
117
114
*/
118
115
function loadStyleDefinition ( definition , options ) {
119
116
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
- }
124
117
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"' ) ;
128
120
}
129
- else {
121
+
122
+ definition . element = window . loadStylesheet ( definition . url , function ( ) {
130
123
deferred . resolve ( ) ;
131
- }
124
+ } , options ) ;
125
+
132
126
return deferred . promise ;
133
127
}
134
128
180
174
angular . forEach ( definitions , function ( definition ) {
181
175
if ( isInjectable ( definition ) ) {
182
176
definition = normalizeStyleDefinition ( inject ( definition ) ) ;
183
- console . log ( 'gg' , definition ) ;
184
177
}
185
178
if ( ! definition . url ) {
186
179
return ;
187
180
}
188
181
189
- console . log ( definition . url ) ;
190
182
var definitionPromise = loadStyleDefinition ( definition , {
191
183
insertBefore : linkElementPlaceholder
192
184
} ) ;
228
220
}
229
221
}
230
222
231
- angular . module ( 'hl.ui.router.css ' , [ 'ui.router' ] )
223
+ angular . module ( 'hl.css. ui.router' , [ 'ui.router' ] )
232
224
233
225
. config ( [ "$stateProvider" , function ( $stateProvider ) {
234
226
249
241
_$q = $q ;
250
242
_$injector = $injector ;
251
243
252
- $transitions . onBefore ( null , function ( transition ) {
244
+ $transitions . onBefore ( { } , function ( transition ) {
253
245
transition . addResolvable ( {
254
246
token : '@css' ,
255
247
resolveFn : function ( ) {
258
250
} ) ;
259
251
} ) ;
260
252
261
- $transitions . onSuccess ( null , function ( ) {
253
+ $transitions . onSuccess ( { } , function ( ) {
262
254
loadStylesForStateComplete ( ) ;
263
255
} ) ;
264
256
} ] )
269
261
link : function ( scope , element , attrs ) {
270
262
if ( DEBUG ) {
271
263
if ( linkElementPlaceholder ) {
272
- log ( 'The directive "uiCss" can only be set once' ) ;
264
+ error ( 'The directive "uiCss" can only be set once' ) ;
273
265
}
274
266
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' ) ;
276
268
}
277
269
}
278
270
300
292
} ) ;
301
293
}
302
294
} ;
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
+ }
303
308
} ] ) ;
304
309
305
310
} ) ( angular , window ) ;
0 commit comments