-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtangram.baseUI.js
2 lines (2 loc) · 5.92 KB
/
tangram.baseUI.js
1
2
/* Copyright (c) 2010 Baidu Licensed under the BSD License */
var T,baidu=T=baidu||{version:"1.3.9"};baidu.guid="$BAIDU$";window[baidu.guid]=window[baidu.guid]||{};baidu.ui=baidu.ui||{version:"1.3.9"};baidu.ui.getUI=function(c){var c=c.split("-"),b=baidu.ui,a=c.length,d=0;for(;d<a;d++){b=b[c[d].charAt(0).toUpperCase()+c[d].slice(1)]}return b};baidu.lang=baidu.lang||{};baidu.lang.isString=function(a){return"[object String]"==Object.prototype.toString.call(a)};baidu.isString=baidu.lang.isString;baidu.ui.create=function(b,a){if(baidu.lang.isString(b)){b=baidu.ui.getUI(b)}return new b(a)};baidu.dom=baidu.dom||{};baidu.dom.g=function(a){if("string"==typeof a||a instanceof String){return document.getElementById(a)}else{if(a&&a.nodeName&&(a.nodeType==1||a.nodeType==9)){return a}}return null};baidu.g=baidu.G=baidu.dom.g;(function(){var a=window[baidu.guid];baidu.lang.guid=function(){return"TANGRAM__"+(a._counter++).toString(36)};a._counter=a._counter||1})();window[baidu.guid]._instances=window[baidu.guid]._instances||{};baidu.lang.isFunction=function(a){return"[object Function]"==Object.prototype.toString.call(a)};baidu.lang.Class=function(a){this.guid=a||baidu.lang.guid();window[baidu.guid]._instances[this.guid]=this};window[baidu.guid]._instances=window[baidu.guid]._instances||{};baidu.lang.Class.prototype.dispose=function(){delete window[baidu.guid]._instances[this.guid];for(var a in this){if(!baidu.lang.isFunction(this[a])){delete this[a]}}this.disposed=true};baidu.lang.Class.prototype.toString=function(){return"[object "+(this._className||"Object")+"]"};baidu.lang.Event=function(a,b){this.type=a;this.returnValue=true;this.target=b||null;this.currentTarget=null};baidu.lang.Class.prototype.addEventListener=function(d,c,b){if(!baidu.lang.isFunction(c)){return}!this.__listeners&&(this.__listeners={});var a=this.__listeners,e;if(typeof b=="string"&&b){if(/[^\w\-]/.test(b)){throw ("nonstandard key:"+b)}else{c.hashCode=b;e=b}}d.indexOf("on")!=0&&(d="on"+d);typeof a[d]!="object"&&(a[d]={});e=e||baidu.lang.guid();c.hashCode=e;a[d][e]=c};baidu.lang.Class.prototype.removeEventListener=function(d,c){if(typeof c!="undefined"){if((baidu.lang.isFunction(c)&&!(c=c.hashCode))||(!baidu.lang.isString(c))){return}}!this.__listeners&&(this.__listeners={});d.indexOf("on")!=0&&(d="on"+d);var b=this.__listeners;if(!b[d]){return}if(typeof c!="undefined"){b[d][c]&&delete b[d][c]}else{for(var a in b[d]){delete b[d][a]}}};baidu.lang.Class.prototype.dispatchEvent=function(d,a){if(baidu.lang.isString(d)){d=new baidu.lang.Event(d)}!this.__listeners&&(this.__listeners={});a=a||{};for(var c in a){d[c]=a[c]}var c,b=this.__listeners,e=d.type;d.target=d.target||this;d.currentTarget=this;e.indexOf("on")!=0&&(e="on"+e);baidu.lang.isFunction(this[e])&&this[e].apply(this,arguments);if(typeof b[e]=="object"){for(c in b[e]){b[e][c].apply(this,arguments)}}return d.returnValue};baidu.event=baidu.event||{};baidu.event._listeners=baidu.event._listeners||[];baidu.dom._g=function(a){if(baidu.lang.isString(a)){return document.getElementById(a)}return a};baidu._g=baidu.dom._g;baidu.event.on=function(b,e,g){e=e.replace(/^on/i,"");b=baidu.dom._g(b);var f=function(i){g.call(b,i)},a=baidu.event._listeners,d=baidu.event._eventFilter,h,c=e;e=e.toLowerCase();if(d&&d[e]){h=d[e](b,e,f);c=h.type;f=h.listener}if(b.addEventListener){b.addEventListener(c,f,false)}else{if(b.attachEvent){b.attachEvent("on"+c,f)}}a[a.length]=[b,e,g,f,c];return b};baidu.on=baidu.event.on;baidu.event.un=function(c,f,b){c=baidu.dom._g(c);f=f.replace(/^on/i,"").toLowerCase();var i=baidu.event._listeners,d=i.length,e=!b,h,g,a;while(d--){h=i[d];if(h[1]===f&&h[0]===c&&(e||h[2]===b)){g=h[4];a=h[3];if(c.removeEventListener){c.removeEventListener(g,a,false)}else{if(c.detachEvent){c.detachEvent("on"+g,a)}}i.splice(d,1)}}return c};baidu.un=baidu.event.un;baidu.ui.Base={id:"",getId:function(a){var c=this,b;b="tangram-"+c.uiType+"--"+(c.id?c.id:c.guid);return a?b+"-"+a:b},getClass:function(b){var d=this,c=d.classPrefix,a=d.skin;if(b){c+="-"+b;a+="-"+b}if(d.skin){c+=" "+a}return c},getMain:function(){return baidu.g(this.mainId)},getBody:function(){return baidu.g(this.getId())},uiType:"",getCallRef:function(){return"window['$BAIDU$']._instances['"+this.guid+"']"},getCallString:function(d){var c=0,b=Array.prototype.slice.call(arguments,1),a=b.length;for(;c<a;c++){if(typeof b[c]=="string"){b[c]="'"+b[c]+"'"}}return this.getCallRef()+"."+d+"("+b.join(",")+");"},on:function(a,b,c){baidu.on(a,b,c);this.addEventListener("ondispose",function(){baidu.un(a,b,c)})},renderMain:function(b){var d=this,c=0,a;if(d.getMain()){return}b=baidu.g(b);if(!b){b=document.createElement("div");document.body.appendChild(b);b.style.position="absolute";b.className=d.getClass("main")}if(!b.id){b.id=d.getId("main")}d.mainId=b.id;b.setAttribute("data-guid",d.guid);return b},dispose:function(){this.dispatchEvent("dispose");baidu.lang.Class.prototype.dispose.call(this)}};baidu.object=baidu.object||{};baidu.extend=baidu.object.extend=function(c,a){for(var b in a){if(a.hasOwnProperty(b)){c[b]=a[b]}}return c};baidu.ui.createUI=function(c,j){j=j||{};var g=j.superClass||baidu.lang.Class,f=g==baidu.lang.Class?1:0,d,b,h=function(k,i){var l=this;k=k||{};g.call(l,!f?k:(k.guid||""),true);baidu.object.extend(l,h.options);baidu.object.extend(l,k);l.classPrefix=l.classPrefix||"tangram-"+l.uiType.toLowerCase();for(d in baidu.ui.behavior){if(typeof l[d]!="undefined"&&l[d]){baidu.object.extend(l,baidu.ui.behavior[d]);if(baidu.lang.isFunction(l[d])){l.addEventListener("onload",function(){baidu.ui.behavior[d].call(l[d].apply(l))})}else{baidu.ui.behavior[d].call(l)}}}c.apply(l,arguments);for(d=0,b=h._addons.length;d<b;d++){h._addons[d](l)}if(k.parent&&l.setParent){l.setParent(k.parent)}if(!i&&k.autoRender){l.render(k.element)}},a=function(){};a.prototype=g.prototype;var e=h.prototype=new a();for(d in baidu.ui.Base){e[d]=baidu.ui.Base[d]}h.extend=function(i){for(d in i){h.prototype[d]=i[d]}return h};h._addons=[];h.register=function(i){if(typeof i=="function"){h._addons.push(i)}};h.options={};return h};