Skip to content

Commit cb067e3

Browse files
committed
Merge pull request #47 from graundas/debug-mode
Debug mode
2 parents 170a7d2 + d228e62 commit cb067e3

File tree

1 file changed

+39
-24
lines changed

1 file changed

+39
-24
lines changed

angular-css.js

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
**/
1717
var angularCSS = angular.module('door3.css', []);
1818

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-
2519
// Provider
2620
angularCSS.provider('$css', [function $cssProvider() {
2721

@@ -34,6 +28,15 @@
3428
method: 'append',
3529
weight: 0
3630
};
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+
};
3740

3841
this.$get = ['$rootScope','$injector','$q','$window','$timeout','$compile','$http','$filter','$log', '$interpolate',
3942
function $get($rootScope, $injector, $q, $window, $timeout, $compile, $http, $filter, $log, $interpolate) {
@@ -174,7 +177,8 @@
174177
**/
175178
function bustCache(stylesheet) {
176179
if (!stylesheet) {
177-
return $log.error('No stylesheets provided');
180+
if(DEBUG) $log.error('No stylesheets provided');
181+
return;
178182
}
179183
var queryString = '?cache=';
180184
// Append query string for bust cache only once
@@ -188,7 +192,8 @@
188192
**/
189193
function filterBy(array, prop) {
190194
if (!array || !prop) {
191-
return $log.error('filterBy: missing array or property');
195+
if(DEBUG) $log.error('filterBy: missing array or property');
196+
return;
192197
}
193198
return $filter('filter')(array, function (item) {
194199
return item[prop];
@@ -200,7 +205,8 @@
200205
**/
201206
function addViaMediaQuery(stylesheet) {
202207
if (!stylesheet) {
203-
return $log.error('No stylesheet provided');
208+
if(DEBUG) $log.error('No stylesheet provided');
209+
return;
204210
}
205211
// Media query object
206212
mediaQuery[stylesheet.href] = $window.matchMedia(stylesheet.media);
@@ -233,7 +239,8 @@
233239
**/
234240
function removeViaMediaQuery(stylesheet) {
235241
if (!stylesheet) {
236-
return $log.error('No stylesheet provided');
242+
if(DEBUG) $log.error('No stylesheet provided');
243+
return;
237244
}
238245
// Remove media query listener
239246
if ($rootScope && angular.isDefined(mediaQuery)
@@ -248,7 +255,8 @@
248255
**/
249256
function isMediaQuery(stylesheet) {
250257
if (!stylesheet) {
251-
return $log.error('No stylesheet provided');
258+
if(DEBUG) $log.error('No stylesheet provided');
259+
return;
252260
}
253261
return !!(
254262
// Check for media query setting
@@ -265,7 +273,8 @@
265273
**/
266274
$css.getFromRoute = function (route) {
267275
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;
269278
}
270279
var css = null, result = [];
271280
if (route.$$route && route.$$route.css) {
@@ -298,7 +307,8 @@
298307
**/
299308
$css.getFromRoutes = function (routes) {
300309
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;
302312
}
303313
var result = [];
304314
// Make array of all routes
@@ -316,7 +326,8 @@
316326
**/
317327
$css.getFromState = function (state) {
318328
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;
320331
}
321332
var result = [];
322333
// State "views" notation
@@ -381,7 +392,8 @@
381392
**/
382393
$css.getFromStates = function (states) {
383394
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;
385397
}
386398
var result = [];
387399
// Make array of all routes
@@ -428,7 +440,7 @@
428440
stylesheetLoadPromises.push(
429441
// Preload via ajax request
430442
$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);
432444
})
433445
);
434446
});
@@ -444,7 +456,8 @@
444456
**/
445457
$css.bind = function (css, $scope) {
446458
if (!css || !$scope) {
447-
return $log.error('No scope or stylesheets provided');
459+
if(DEBUG) $log.error('No scope or stylesheets provided');
460+
return;
448461
}
449462
var result = [];
450463
// Adds route css rules to array
@@ -456,10 +469,10 @@
456469
result.push(parse(css));
457470
}
458471
$css.add(result);
459-
$log.debug('$css.bind(): Added', result);
472+
if(DEBUG) $log.debug('$css.bind(): Added', result);
460473
$scope.$on('$destroy', function () {
461474
$css.remove(result);
462-
$log.debug('$css.bind(): Removed', result);
475+
if(DEBUG) $log.debug('$css.bind(): Removed', result);
463476
});
464477
};
465478

@@ -468,7 +481,8 @@
468481
**/
469482
$css.add = function (stylesheets, callback) {
470483
if (!stylesheets) {
471-
return $log.error('No stylesheets provided');
484+
if(DEBUG) $log.error('No stylesheets provided');
485+
return;
472486
}
473487
if (!angular.isArray(stylesheets)) {
474488
stylesheets = [stylesheets];
@@ -486,7 +500,7 @@
486500
else {
487501
$rootScope.stylesheets.push(stylesheet);
488502
}
489-
$log.debug('$css.add(): ' + stylesheet.href);
503+
if(DEBUG) $log.debug('$css.add(): ' + stylesheet.href);
490504
}
491505
});
492506
// Broadcasts custom event for css add
@@ -498,7 +512,8 @@
498512
**/
499513
$css.remove = function (stylesheets, callback) {
500514
if (!stylesheets) {
501-
return $log.error('No stylesheets provided');
515+
if(DEBUG) $log.error('No stylesheets provided');
516+
return;
502517
}
503518
if (!angular.isArray(stylesheets)) {
504519
stylesheets = [stylesheets];
@@ -519,7 +534,7 @@
519534
}
520535
// Remove stylesheet via media query
521536
removeViaMediaQuery(stylesheet);
522-
$log.debug('$css.remove(): ' + stylesheet.href);
537+
if(DEBUG) $log.debug('$css.remove(): ' + stylesheet.href);
523538
});
524539
// Broadcasts custom event for css remove
525540
$rootScope.$broadcast('$cssRemove', stylesheets, $rootScope.stylesheets);
@@ -533,7 +548,7 @@
533548
if ($rootScope && $rootScope.hasOwnProperty('stylesheets')) {
534549
$rootScope.stylesheets.length = 0;
535550
}
536-
$log.debug('all stylesheets removed');
551+
if(DEBUG) $log.debug('all stylesheets removed');
537552
};
538553

539554
// Preload all stylesheets

0 commit comments

Comments
 (0)