Skip to content

Commit

Permalink
Added debugging
Browse files Browse the repository at this point in the history
Added methods for debugging breakpoints. Updated README.
  • Loading branch information
Martin Jansson committed Jan 22, 2014
1 parent d9f50c5 commit 764362c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions js/jquery.breakpoint-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions js/jquery.breakpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

function checkActiveBreakpoint(breakpoint) {
if (!breakpoint.condition()) {
debug('Exiting breakpoint: ' + breakpoint);

// We have left this breakpoint.
if (typeof breakpoint.exit === 'function') {
Expand All @@ -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) {}
Expand All @@ -65,6 +68,7 @@
}

if (typeof breakpoint.enter === 'function') {
debug('Entering breakpoint: ' + breakpoint);
try {
breakpoint.enter.apply(breakpoint);
} catch (e) {}
Expand Down Expand Up @@ -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));

0 comments on commit 764362c

Please sign in to comment.