|
16 | 16 | **/
|
17 | 17 | var angularCSS = angular.module('door3.css', []);
|
18 | 18 |
|
19 |
| - // Config |
20 |
| - angularCSS.config(['$logProvider', function ($logProvider) { |
21 |
| - // Turn off/on in order to see console logs during dev mode |
22 |
| - $logProvider.debugEnabled(false); |
23 |
| - }]); |
24 |
| - |
25 | 19 | // Provider
|
26 | 20 | angularCSS.provider('$css', [function $cssProvider() {
|
27 | 21 |
|
|
34 | 28 | method: 'append',
|
35 | 29 | weight: 0
|
36 | 30 | };
|
| 31 | + |
| 32 | + var DEBUG = false; |
| 33 | + |
| 34 | + // Turn off/on in order to see console logs during dev mode |
| 35 | + this.debugMode = function(mode) { |
| 36 | + if (angular.isDefined(mode)) |
| 37 | + DEBUG = mode; |
| 38 | + return DEBUG; |
| 39 | + }; |
37 | 40 |
|
38 | 41 | this.$get = ['$rootScope','$injector','$q','$window','$timeout','$compile','$http','$filter','$log', '$interpolate',
|
39 | 42 | function $get($rootScope, $injector, $q, $window, $timeout, $compile, $http, $filter, $log, $interpolate) {
|
|
174 | 177 | **/
|
175 | 178 | function bustCache(stylesheet) {
|
176 | 179 | if (!stylesheet) {
|
177 |
| - return $log.error('No stylesheets provided'); |
| 180 | + if(DEBUG) $log.error('No stylesheets provided'); |
| 181 | + return; |
178 | 182 | }
|
179 | 183 | var queryString = '?cache=';
|
180 | 184 | // Append query string for bust cache only once
|
|
188 | 192 | **/
|
189 | 193 | function filterBy(array, prop) {
|
190 | 194 | if (!array || !prop) {
|
191 |
| - return $log.error('filterBy: missing array or property'); |
| 195 | + if(DEBUG) $log.error('filterBy: missing array or property'); |
| 196 | + return; |
192 | 197 | }
|
193 | 198 | return $filter('filter')(array, function (item) {
|
194 | 199 | return item[prop];
|
|
200 | 205 | **/
|
201 | 206 | function addViaMediaQuery(stylesheet) {
|
202 | 207 | if (!stylesheet) {
|
203 |
| - return $log.error('No stylesheet provided'); |
| 208 | + if(DEBUG) $log.error('No stylesheet provided'); |
| 209 | + return; |
204 | 210 | }
|
205 | 211 | // Media query object
|
206 | 212 | mediaQuery[stylesheet.href] = $window.matchMedia(stylesheet.media);
|
|
233 | 239 | **/
|
234 | 240 | function removeViaMediaQuery(stylesheet) {
|
235 | 241 | if (!stylesheet) {
|
236 |
| - return $log.error('No stylesheet provided'); |
| 242 | + if(DEBUG) $log.error('No stylesheet provided'); |
| 243 | + return; |
237 | 244 | }
|
238 | 245 | // Remove media query listener
|
239 | 246 | if ($rootScope && angular.isDefined(mediaQuery)
|
|
248 | 255 | **/
|
249 | 256 | function isMediaQuery(stylesheet) {
|
250 | 257 | if (!stylesheet) {
|
251 |
| - return $log.error('No stylesheet provided'); |
| 258 | + if(DEBUG) $log.error('No stylesheet provided'); |
| 259 | + return; |
252 | 260 | }
|
253 | 261 | return !!(
|
254 | 262 | // Check for media query setting
|
|
265 | 273 | **/
|
266 | 274 | $css.getFromRoute = function (route) {
|
267 | 275 | if (!route) {
|
268 |
| - return $log.error('Get From Route: No route provided'); |
| 276 | + if(DEBUG) $log.error('Get From Route: No route provided'); |
| 277 | + return; |
269 | 278 | }
|
270 | 279 | var css = null, result = [];
|
271 | 280 | if (route.$$route && route.$$route.css) {
|
|
298 | 307 | **/
|
299 | 308 | $css.getFromRoutes = function (routes) {
|
300 | 309 | if (!routes) {
|
301 |
| - return $log.error('Get From Routes: No routes provided'); |
| 310 | + if(DEBUG) $log.error('Get From Routes: No routes provided'); |
| 311 | + return; |
302 | 312 | }
|
303 | 313 | var result = [];
|
304 | 314 | // Make array of all routes
|
|
316 | 326 | **/
|
317 | 327 | $css.getFromState = function (state) {
|
318 | 328 | if (!state) {
|
319 |
| - return $log.error('Get From State: No state provided'); |
| 329 | + if(DEBUG) $log.error('Get From State: No state provided'); |
| 330 | + return; |
320 | 331 | }
|
321 | 332 | var result = [];
|
322 | 333 | // State "views" notation
|
|
381 | 392 | **/
|
382 | 393 | $css.getFromStates = function (states) {
|
383 | 394 | if (!states) {
|
384 |
| - return $log.error('Get From States: No states provided'); |
| 395 | + if(DEBUG) $log.error('Get From States: No states provided'); |
| 396 | + return; |
385 | 397 | }
|
386 | 398 | var result = [];
|
387 | 399 | // Make array of all routes
|
|
428 | 440 | stylesheetLoadPromises.push(
|
429 | 441 | // Preload via ajax request
|
430 | 442 | $http.get(stylesheet.href).error(function (response) {
|
431 |
| - $log.error('AngularCSS: Incorrect path for ' + stylesheet.href); |
| 443 | + if(DEBUG) $log.error('AngularCSS: Incorrect path for ' + stylesheet.href); |
432 | 444 | })
|
433 | 445 | );
|
434 | 446 | });
|
|
444 | 456 | **/
|
445 | 457 | $css.bind = function (css, $scope) {
|
446 | 458 | if (!css || !$scope) {
|
447 |
| - return $log.error('No scope or stylesheets provided'); |
| 459 | + if(DEBUG) $log.error('No scope or stylesheets provided'); |
| 460 | + return; |
448 | 461 | }
|
449 | 462 | var result = [];
|
450 | 463 | // Adds route css rules to array
|
|
456 | 469 | result.push(parse(css));
|
457 | 470 | }
|
458 | 471 | $css.add(result);
|
459 |
| - $log.debug('$css.bind(): Added', result); |
| 472 | + if(DEBUG) $log.debug('$css.bind(): Added', result); |
460 | 473 | $scope.$on('$destroy', function () {
|
461 | 474 | $css.remove(result);
|
462 |
| - $log.debug('$css.bind(): Removed', result); |
| 475 | + if(DEBUG) $log.debug('$css.bind(): Removed', result); |
463 | 476 | });
|
464 | 477 | };
|
465 | 478 |
|
|
468 | 481 | **/
|
469 | 482 | $css.add = function (stylesheets, callback) {
|
470 | 483 | if (!stylesheets) {
|
471 |
| - return $log.error('No stylesheets provided'); |
| 484 | + if(DEBUG) $log.error('No stylesheets provided'); |
| 485 | + return; |
472 | 486 | }
|
473 | 487 | if (!angular.isArray(stylesheets)) {
|
474 | 488 | stylesheets = [stylesheets];
|
|
486 | 500 | else {
|
487 | 501 | $rootScope.stylesheets.push(stylesheet);
|
488 | 502 | }
|
489 |
| - $log.debug('$css.add(): ' + stylesheet.href); |
| 503 | + if(DEBUG) $log.debug('$css.add(): ' + stylesheet.href); |
490 | 504 | }
|
491 | 505 | });
|
492 | 506 | // Broadcasts custom event for css add
|
|
498 | 512 | **/
|
499 | 513 | $css.remove = function (stylesheets, callback) {
|
500 | 514 | if (!stylesheets) {
|
501 |
| - return $log.error('No stylesheets provided'); |
| 515 | + if(DEBUG) $log.error('No stylesheets provided'); |
| 516 | + return; |
502 | 517 | }
|
503 | 518 | if (!angular.isArray(stylesheets)) {
|
504 | 519 | stylesheets = [stylesheets];
|
|
519 | 534 | }
|
520 | 535 | // Remove stylesheet via media query
|
521 | 536 | removeViaMediaQuery(stylesheet);
|
522 |
| - $log.debug('$css.remove(): ' + stylesheet.href); |
| 537 | + if(DEBUG) $log.debug('$css.remove(): ' + stylesheet.href); |
523 | 538 | });
|
524 | 539 | // Broadcasts custom event for css remove
|
525 | 540 | $rootScope.$broadcast('$cssRemove', stylesheets, $rootScope.stylesheets);
|
|
533 | 548 | if ($rootScope && $rootScope.hasOwnProperty('stylesheets')) {
|
534 | 549 | $rootScope.stylesheets.length = 0;
|
535 | 550 | }
|
536 |
| - $log.debug('all stylesheets removed'); |
| 551 | + if(DEBUG) $log.debug('all stylesheets removed'); |
537 | 552 | };
|
538 | 553 |
|
539 | 554 | // Preload all stylesheets
|
|
0 commit comments