Skip to content

Instantly share code, notes, and snippets.

@tsavory
Created June 8, 2012 03:53
Show Gist options
  • Save tsavory/2893463 to your computer and use it in GitHub Desktop.
Save tsavory/2893463 to your computer and use it in GitHub Desktop.
bind jquary to responsive layout
Found the answer in http://drupal.org/node/1299286#comment-5412342 (thanks @bc and @himerus)
You can bind to the jQuery global event 'responsivelayout':
jQuery('body').bind('responsivelayout', function() { /* handle event */ } );
The global event is defined in omega-mediaqueries.js with $.event.trigger. Because it's global, you can bind a listener to any object in the DOM.
So my custom code should look like:
(function($) {
Drupal.behaviors.myCustomBehavior = {
attach: function(context) {
$('body').bind('responsivelayout', function(e, d) {
if($(this).hasClass("responsive-layout-mobile")) {
console.log("a");
}
});
};
})(jQuery);
Hope this saves someone an hour or like me a day.
more resources
http://drupal.org/node/1299286#comment-5412342
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment