widget - Loading many jQuery files without conflicting -
i have livescore website , building widget livescore main problem is: load js file in addition newest jquery lib lib loaded file not loaded sites. tested on 1 of websites after omitting js files of site , works. question how load file without conflicting other websites' js files ??? code:
(function() { // localize jquery variable var jquery; /******** load jquery if not present *********/ if (window.jquery === undefined || window.jquery.fn.jquery !== '1.8.3') { var script_tag = document.createelement('script'); script_tag.setattribute("type","text/javascript"); script_tag.setattribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"); var script_tag1 = document.createelement('script'); script_tag1.setattribute("type","text/javascript"); script_tag1.setattribute("src", "http://example.com/include-js/jquery_timer.js"); if (script_tag.readystate) { script_tag.onreadystatechange = function () { // old versions of ie if (this.readystate == 'complete' || this.readystate == 'loaded') { scriptloadhandler(); } }; } else { // other browsers script_tag.onload = scriptloadhandler; } // try find head, otherwise default documentelement (document.getelementsbytagname("head")[0] || document.documentelement).appendchild(script_tag); (document.getelementsbytagname("head")[0] || document.documentelement).appendchild(script_tag1); } else { // jquery version on window 1 want use jquery = window.jquery; main(); } /******** called once jquery has loaded ******/ function scriptloadhandler() { // restore $ , window.jquery previous values , store // new jquery in our local jquery variable jquery = window.jquery.noconflict(true); // call our main function main(); } /******** our main function ********/ function main() { jquery(document).ready(function($) { /******* load css *******/ var css_link = $("<link>", { rel: "stylesheet", type: "text/css", href: "http://example.com/widget/red.css" }); css_link.appendto('head'); var txt; txt='<div id="wrapper">'; txt=txt+'<ul class="tabs">'; txt=txt+'<li id="fixtures_tab"><a href="#fixtures">hepsi</a></li>'; txt=txt+'<li id="live_tab"><a href="#live">canlı</a></li>'; txt=txt+'<li id="finished_tab"><a href="#finished">bitmiş</a></li>'; txt=txt+'<li id="program_tab"><a href="#program">başlamamış</a></li>'; txt=txt+'<li id="postpond_tab"><a href="#postpond">ertelenen</a></li>'; txt=txt+'<li id="selected_tab"><a id="f" href="#fav">oyunlarım (0)</a></li>'; txt=txt+'</ul>'; txt=txt+'<div class="tab-container">'; txt=txt+'<div id="fixtures" class="tab-content"><script type="text/javascript">get_all_today_matches();</script></div>'; txt=txt+'<div id="live" class="tab-content"><script type="text/javascript"></script></div>'; txt=txt+'<div id="finished" class="tab-content"><script type="text/javascript"></script></div>'; txt=txt+'<div id="program" class="tab-content"><script type="text/javascript"></script></div>'; txt=txt+'<div id="postpond" class="tab-content"><script type="text/javascript"></script></div>'; txt=txt+'<div id="fav" class="tab-content"><script type="text/javascript"></script></div>'; txt=txt+'</div>'; txt=txt+'</div>'; $('#widget-container').html(txt); }); } })(); // call our anonymous function settimeout(function(){ var timer = $.timer(function() { var cha = "'"; $('.show_hide').html(""); settimeout(function(){ $('.show_hide').html(cha); }, 500); }); timer.set({ time : 1000, autostart : true }); }, 3000);
edit: jquery_time.js:
;(function($) { $.timer = function(func, time, autostart) { this.set = function(func, time, autostart) { this.init = true; if(typeof func == 'object') { var paramlist = ['autostart', 'time']; for(var arg in paramlist) {if(func[paramlist[arg]] != undefined) {eval(paramlist[arg] + " = func[paramlist[arg]]");}}; func = func.action; } if(typeof func == 'function') {this.action = func;} if(!isnan(time)) {this.intervaltime = time;} if(autostart && !this.isactive) { this.isactive = true; this.settimer(); } return this; }; this.once = function(time) { var timer = this; if(isnan(time)) {time = 0;} window.settimeout(function() {timer.action();}, time); return this; }; this.play = function(reset) { if(!this.isactive) { if(reset) {this.settimer();} else {this.settimer(this.remaining);} this.isactive = true; } return this; }; this.pause = function() { if(this.isactive) { this.isactive = false; this.remaining -= new date() - this.last; this.cleartimer(); } return this; }; this.stop = function() { this.isactive = false; this.remaining = this.intervaltime; this.cleartimer(); return this; }; this.toggle = function(reset) { if(this.isactive) {this.pause();} else if(reset) {this.play(true);} else {this.play();} return this; }; this.reset = function() { this.isactive = false; this.play(true); return this; }; this.cleartimer = function() { window.cleartimeout(this.timeoutobject); }; this.settimer = function(time) { var timer = this; if(typeof this.action != 'function') {return;} if(isnan(time)) {time = this.intervaltime;} this.remaining = time; this.last = new date(); this.cleartimer(); this.timeoutobject = window.settimeout(function() {timer.go();}, time); }; this.go = function() { if(this.isactive) { this.action(); this.settimer(); } }; if(this.init) { return new $.timer(func, time, autostart); } else { this.set(func, time, autostart); return this; } }; })(jquery);
Comments
Post a Comment