Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@JimBobSquarePants
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimBobSquarePants/6ac7d3a299c7ab68b261 to your computer and use it in GitHub Desktop.
Save JimBobSquarePants/6ac7d3a299c7ab68b261 to your computer and use it in GitHub Desktop.
Load jQuery plugins on dom change in Responsive
// The idea. Ensure that widgets are initialized when they are dynamically loaded into a page.
// First override the core html method in the jQuery object to allow us to trigger a custom event.
(function($, old){
$.fn.html = function(){
// Execute the original HTML method using the
// augmented arguments collection.
var result = old.apply(this, arguments);
// Trigger a custom event on the document.
$(document).trigger($.Event("domchanged"));
return result;
};
})( jQuery, jQuery.fn.html );
// In the code for our current elements we currently initialize them using $(document).on(ready.r.pluginname).
// This could be augmented
$(document).on("ready.r.carousel domchanged.r.carousel", function () {
// run our init code. We already do checks to ensure that
// elements are not being initialzed twice anyway.
}
// And there you go.... Thoughts please.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment