diff --git a/README.md b/README.md index 29045ef..8108d9f 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,11 @@ Whenever the condition returns true, be it on page load or when the viewport cha }); ``` +## Debugging + +The plugin provides some basic debugging which you can activate by setting `$.breakpoint.debug = true`. This will cause the plugin to log information to the browser console whenever a breakpoint is entered or exited. Add a `toString` method to your breakpoint object to distinguish between breakpoints; otherwise you'll se `[object Object]` as the name of the breakpoint. + + ## Tips and tricks ### MatchMedia support in older browsers diff --git a/js/jquery.breakpoint-min.js b/js/jquery.breakpoint-min.js index 5901d51..9d6343b 100644 --- a/js/jquery.breakpoint-min.js +++ b/js/jquery.breakpoint-min.js @@ -1,4 +1,6 @@ -!function(t){"use strict" -function n(t){if(!t.condition()){if("function"==typeof t.exit)try{t.exit.apply(t)}catch(n){}t.is_active=!1}}function i(t){if(t.condition()){if("function"==typeof t.first_enter){try{t.first_enter.apply(t)}catch(n){}delete t.first_enter}if("function"==typeof t.enter)try{t.enter.apply(t)}catch(n){}t.is_active=!0}}function e(t){t.is_active?n(t):i(t)}function c(){var e=t.grep(o,function(t){return t.is_active}),c=t.grep(o,function(t){return!t.is_active}) -t.each(e,function(t,i){n(i)}),t.each(c,function(t,n){i(n)})}var o=[] -t.breakpoint=function(n,i){i=t.extend(!0,{},t.breakpoint.defaults,i),o.push(n),1===o.length&&t(window).on("resize orientationchange",function(){c()}),e(n)},t.breakpoint.breakpoints=o,t.breakpoint.check=function(t){e(t)},t.breakpoint.defaults={}}(jQuery) +!function(n){"use strict" +function t(n){if(!n.condition()){if(c("Exiting breakpoint: "+n),"function"==typeof n.exit)try{n.exit.apply(n)}catch(t){}n.is_active=!1}}function i(n){if(n.condition()){if("function"==typeof n.first_enter){c("Entering breakpoint for the first time: "+n) +try{n.first_enter.apply(n)}catch(t){}delete n.first_enter}if("function"==typeof n.enter){c("Entering breakpoint: "+n) +try{n.enter.apply(n)}catch(t){}}n.is_active=!0}}function e(n){n.is_active?t(n):i(n)}function o(){var e=n.grep(r,function(n){return n.is_active}),o=n.grep(r,function(n){return!n.is_active}) +n.each(e,function(n,i){t(i)}),n.each(o,function(n,t){i(t)})}function c(){n.breakpoint.debug&&console&&console.info&&console.info.apply(console,arguments)}var r=[] +n.breakpoint=function(t,i){i=n.extend(!0,{},n.breakpoint.defaults,i),r.push(t),1===r.length&&n(window).on("resize orientationchange",function(){o()}),e(t)},n.breakpoint.breakpoints=r,n.breakpoint.check=function(n){e(n)},n.breakpoint.defaults={},n.breakpoint.debug=!0}(jQuery) diff --git a/js/jquery.breakpoint.js b/js/jquery.breakpoint.js index 911a108..2b309d8 100644 --- a/js/jquery.breakpoint.js +++ b/js/jquery.breakpoint.js @@ -39,6 +39,7 @@ function checkActiveBreakpoint(breakpoint) { if (!breakpoint.condition()) { + debug('Exiting breakpoint: ' + breakpoint); // We have left this breakpoint. if (typeof breakpoint.exit === 'function') { @@ -56,6 +57,8 @@ // We have entered this breakpoint. if (typeof breakpoint.first_enter === 'function') { + debug('Entering breakpoint for the first time: ' + breakpoint); + try { breakpoint.first_enter.apply(breakpoint); } catch (e) {} @@ -65,6 +68,7 @@ } if (typeof breakpoint.enter === 'function') { + debug('Entering breakpoint: ' + breakpoint); try { breakpoint.enter.apply(breakpoint); } catch (e) {} @@ -106,4 +110,18 @@ }); } + /** + * Breakpoint debugging + */ + + // (De)activate breakpoint debugging. + $.breakpoint.debug = true; + + // Console logging wrapper. + function debug () { + if ($.breakpoint.debug && console && console.info) { + console.info.apply(console, arguments); + } + } + }(jQuery)); \ No newline at end of file