Last active
August 29, 2015 14:05
-
-
Save JimBobSquarePants/6ac7d3a299c7ab68b261 to your computer and use it in GitHub Desktop.
Load jQuery plugins on dom change in Responsive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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