Use RequireJS to load into your own scripts and wrap them with closure.
// let say tooltip was defined already $.fn.tooltip = function(data){ $(this).mouseover(function(){ console.log(data.title); }); }; // we'll apply the old tooltip to .tooltip1 $('.tooltip1').tooltip({ title: 'tada', placement: 'bottom' }); // what version of jquery did we have out here console.log($.fn.jquery); require({ "paths": { "jquery": "//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min", "bootstrap": "//twitter.imtqy.com/bootstrap/assets/js/bootstrap.min" }, shim: { "bootstrap": { deps: ['jquery'], exports: '$.fn.tooltip' } } }, ['jquery', 'bootstrap'], function($){ // what version of jquery do we have in here console.log($.fn.jquery); // now we apply the bootstrap tooltip to .tooltip2 $('.tooltip2').tooltip({ title: 'tada', placement: 'bottom' }); });
http://jsfiddle.net/moderndegree/prSUF/
Brian lewis
source share