twitter bootstrap - How can I Pass a specific jquery version to booststrap.min.js -
i have widget type js application gets embedded in many web sites. widget uses own jquery , bootstrap. of websites uses jquery of lower version 1 utilize in widget.
to resolve conflict between 2 jquery instances , making website code unaware of jquery, added below simple logic:
// backup websites jquery objects var websites$=$; var websitesjquery=jquery; var my$; // code loading jquery here... function onjqueryload() { my$=$.noconflict(); // reverting jquery variable objects 1 before loading jquery $=websites$; jquery=websitesjquery; }
now want bootstrap.min.js utilize jquery version (saved in var my$). default uses predefined jquery variable. want because website's jquery old , not compatible bootstrap. appreciate help. give thanks you.
it depends on order in loading scripts. don't need of logic, in fact $.noconflict
of you.
try this
<script src="jquery_to_be_used_by_bootstrap.js"></script> <script src="bootstrap.js"></script> <script src="other_jquery_version.js"></script> <script> // 'true' tells restore *both* `$` , `jquery` // otherwise restores `$` var website_$ = $.noconflict(true); </script>
now, $
, jquery
(the global vars) jquery_to_be_used_by_bootstrap
, website_$
other_jquery_version
.
since can't edit bootstrap tell utilize different $
(or jquery
) variable, you'll need update website so.
this can fixed doing:
website_$(function($){ // in here can utilize `$` // , it'll `other_jquery_version` });
demo of concept: http://jsbin.com/dopomiyehu/1/edit?html,js,console
docs: http://api.jquery.com/jquery.noconflict/
jquery twitter-bootstrap
No comments:
Post a Comment