-
Notifications
You must be signed in to change notification settings - Fork 0
/
jforemote-demo.js
22 lines (22 loc) · 4.22 KB
/
jforemote-demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* JFO Remote Framework,Some question for email 'jimmy.song@aliyun.com'
* Declare: This framework of Javascript developed by 41zone team
* License: MIT
*/
(function(j){window.console=window.console||{log:function(a){}};var h=function(){this.settings={begin:function(){},success:function(){},error:function(){},scripts:[],styles:[],custom:{},ready:false};this.ajax={url:"",method:"GET",type:"text",cache:false,async:true,params:{},success:function(b,a){},error:function(b,a){}};this.httpRequest=false;this.scripts={len:0,list:[],loaded:0,done:false};this.styles={len:0,list:[],loaded:0};this.oid="JFO_REMOTE_"+Math.floor(Math.random()*100000)+"_"+new Date().getTime();this.div=null;this.params={};this.query={};this.src=""};var f=typeof document.all!=="undefined";h.prototype={init:function(){this.div=document.getElementById(this.oid);if(typeof this.div==="undefined"||this.div===null){document.write("<div id="+this.oid+"></div>")}this.div=document.getElementById(this.oid);this._readParams()},_lock:function(){var a=document.getElementsByTagName("script");script=a[a.length-1];this.src=script.src},_readParams:function(){this.params=this.doQuery(this.src);this.query=this.doQuery(window.location.search)},doQuery:function(a){if(!a){return{}}var c=/(?:\?|&)(.*?)=(.*?)(?=&|$)/g;var d,b={};while((d=c.exec(a))!=null){b[d[1]]=decodeURIComponent(d[2])}return b},overwrite:function(b,a){if(typeof b!=="object"||typeof a!=="object"){return b}for(var c in a){if(typeof b[c]!=="undefined"&&typeof a[c]===typeof b[c]){if(typeof b[c]==="object"&&!(b[c] instanceof Array)){this.overwrite(b[c],a[c])}else{b[c]=a[c]}}else{b[c]=a[c]}}return b},oneStep:function(b){var a=this;this.overwrite(this.settings,b);this.settings.begin(this);this.loadStyle(function(){a.loadScript(function(){a.settings.success(a)},a.settings.scripts)},this.settings.styles)},existScript:function(c){var a=this.scripts.list;for(var b=0;b<a.length;b++){if(a[b]==c){return true}}return false},existStyle:function(b){var a=this.styles.list;for(var c=0;c<a.length;c++){if(a[c]==b){return true}}return false},installLoadEvent:function(c,d,b){var a=this;if(f){c.attachEvent("onreadystatechange",function(){if(c.readyState=="loaded"||c.readyState=="complete"){d.loaded++;if(d.loaded>=d.len&&!d.done){b(a)}c.detachEvent("onreadystatechange",arguments.callee)}})}else{c.addEventListener("load",function(){d.loaded++;if(d.loaded>=d.len&&!d.done){d.done=true;b(a)}c.removeEventListener("load",arguments.call,false)},false)}},loadScript:function(a,n){if(n.length<=0){this.scripts.done=true;a(this);return}this.scripts.len=n.length;for(var e=0;e<n.length;e++){if(this.existScript(n[e])){continue}var d=n[e];var o=document.createElement("script");o.type="text/javascript";if(typeof d==="string"){o.src=encodeURI(d)}else{if(typeof d==="object"&&typeof d.url!=="undefined"){if(typeof d.conflict!=="undefined"||d.conflict!==null){var c=d.force;if(typeof window[d.conflict]!=="undefined"){this.scripts.len--;if(!c){try{console.log('The page exist object conflict script about "'+d.conflict+'"')}catch(b){}continue}}}o.src=encodeURI(d.url)}else{o=null;this.scripts.len--;continue}}this.div.appendChild(o);this.scripts.list.push(o);this.installLoadEvent(o,this.scripts,a)}if(this.scripts.len<=0){this.scripts.done=true;a(this);return}},loadStyle:function(a,d){if(d.length<=0){a(this);return}this.styles.len=d.length;for(var c=0;c<d.length;c++){if(this.existStyle(d[c])){continue}var b=document.createElement("link");b.type="text/css";b.rel="stylesheet";b.href=d[c];this.div.appendChild(b);this.styles.list.push(b);this.installLoadEvent(b,this.styles,a)}}};var i=new h();i._lock();i.init();if(j.ready){var g=(function(a,b){return function(){a.oneStep(b)}})(i,j);if(window.attachEvent){window.attachEvent("onload",g)}else{window.addEventListener("load",g,false)}}else{i.oneStep(j)}})
({
begin : function(remote) {
},
success : function(remote) {
console.log(remote.query.name + " = " + remote.params.name);
$(remote.div).css('backgroundColor', 'black').css('color', 'white');
$(remote.div).append('hi, I\'m ' + remote.params.name + ", everyone take me to somewhere for building tower high and strong.");
},
scripts : [{
url : 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
conflict : '$',
force : false
}],
styles : [],
ready : true
});