forked from meritt/base2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase2-jsb-p.js
9 lines (8 loc) · 18.4 KB
/
base2-jsb-p.js
1
2
3
4
5
6
7
8
9
/*
base2 - copyright 2007-2009, Dean Edwards
http://code.google.com/p/base2/
http://www.opensource.org/licenses/mit-license.php
Contributors:
Doeke Zanstra
*/
new function(_u){base2.global.jsb=new base2.Package(this,{name:"jsb",version:"0.9.6",imports:"Function2,Enumerable,dom",exports:"Animation,Rule,RuleList,behavior",INTERVAL:25,TIMEOUT:100,QUERY_SIZE:100,createStyleSheet:function(a){if(document.body){var b=document.createElement("style");b.type="text/css";if(b.textContent===undefined){b.innerHTML=a}else{b.textContent=a}new Selector("head").exec(document,1).appendChild(b)}else{document.write('<style type="text/css">'+a+'<\/style>')}},"@(document.createStyleSheet)":{createStyleSheet:function(a){document.createStyleSheet().cssText=a}}});eval(this.imports);jsb.host=_a();/*@cc_on @*/ var _b =/^on([a-z]{3,}|DOM[A-Z]\w+)$/,_i=/^mouse(up|down)|click$/,_v=/click$/,_c=/^mouse|click$/,_j=/^mouse(enter|leave|over|out)$/,_k=/^(attach|detach|(content|document)ready)$/,_l=/^(key|text)/,_m=/^(focus|blur)$/;var _n=/^(abort|error|load|scroll|DOMAttrModified|mouse(enter|leave)|(readystate|property|filter)change)$/,_o=/^(HTML|BODY)$/,_p=/^[^12]$/;var _d=/\d+/g,_q=/\d+%?/g;var _8=detect("(document.createEvent('Events'))")?"Events":"UIEvents";var _4={};var _r=partial(parseInt,undefined,16);function _e(a,b){return b.specificity-a.specificity};function _7(a,b){if(a==null)return[];a=trim(a).split(/\s+/);if(b){if(a.length==1)a[1]=a[0];if(a.length==2)a[2]=a[0];if(a.length==3)a[3]=a[1]}return a};var _f=document.createElement("span").style;function _a(){var a=location.pathname,b=Array2.item(document.getElementsByTagName("script"),-1);if(b)a=b.src||a;return a.replace(/[\?#].*$/,"").replace(/[^\/]*$/,"")};var _g=Base.extend({attach:Undefined,detach:Undefined,modify:Undefined,jsbExtendedMouse:false,jsbUseDispatch:true,jsbUseDelegation:true,ancestorOf:function(a){return a instanceof this.constructor},extend:function(d){if(!d)d={};var h=function(){};(h.prototype=new this.constructor).constructor=h;var j=d["implements"]||[];delete d["implements"];j.push(d);for(var f=0;d=j[f];f++){extend(h.prototype,d)}var g=new h;var k=[],l,m={handleEvent:function(a){jsb.eventDispatcher.dispatch(g,a.target,a)}};for(var o in g){if(typeof g[o]=="function"&&_b.test(o)){var p=o.slice(2);if(!g.jsbUseDelegation||_n.test(p)){if(!l)l=[];l.push(p)}else if(!_k.test(p)){k.push(p)}}}var n={behavior:g};g.attach=function(a){var b=a.uniqueID||assignID(a);if(n[b]===undefined){n[b]=true;if(!_4[b])_4[b]=0;_4[b]++;if(k){for(var c=0;p=k[c];c++){jsb.eventDelegator.addEventListener(p,n)}k=null}if(l){for(var c=0;p=l[c];c++){EventTarget.addEventListener(a,p,m,false)}}if(g.onattach){_5(g,a,"attach")}if(g.oncontentready){if(_1.isContentReady(a)){_5(g,a,"contentready")}else{_1.contentReadyQueue.push({behavior:g,element:a})}}if(g.ondocumentready){if(_1.ready){_5(g,a,"documentready")}else{_1.documentReadyQueue.push({behavior:g,element:a})}}if(g.onfocus&&a==document.activeElement){g.dispatchEvent(a,"focus")}}};g.detach=function(a){var b=a.uniqueID;if(n[b]){if(arguments[1]){n[b]=false}else{delete n[b]}_4[b]--;if(l){for(var c=0;p=l[c];c++){EventTarget.removeEventListener(a,p,m,false)}}}};var q=h.modifications={},r={};g.modify=function(e){e=extend(pcopy(g),e);return{isModification:true,attach:function(a,b){g.attach(a);var c=a.uniqueID;if(b.specificity>=(r[c]||0)){r[c]=b.specificity;q[c]=e}}}};return g},get:function(a,b){if(b=="textContent"){b=Traversal.TEXT_CONTENT}var c=this.constructor.modifications[a.uniqueID]||this,e=c[b],d;if(b!="type"){d=a[b]}if(d===undefined){d=Element.getAttribute(a,b)}if(d==null)return e;switch(typeof e){case"boolean":return true;case"number":return d-0}return d},set:function(a,b,c){var e=b=="innerHTML";if(e||b=="textContent"){Traversal.setTextContent(a,c,e)}else{var d=a[b];if(d===undefined){d=this.get(a,b);if(typeof this[b]=="boolean"&&!c){Element.removeAttribute(a,b)}else{Element.setAttribute(a,b,c)}}else{a[b]=c}if(d!==this.get(a,b)){this.dispatchEvent(a,"propertyset",{propertyName:b,originalValue:d})}}},toggle:function(a,b){this.set(a,b,!this.get(a,b))},dispatchEvent:function(a,b,c){if(typeof b=="string"){var e=b;b=DocumentEvent.createEvent(document,_8);var d=true,h=false;if(c){if(c.bubbles!=null)d=!!c.bubbles;if(c.cancelable!=null)h=!!c.cancelable;delete c.bubbles;delete c.cancelable}Event.initEvent(b,e,d,h)}if(c)extend(b,c);b.returnValue=undefined;b.cancelBubble=false;EventTarget.dispatchEvent(a,b)},getStyle:function(a,b){return CSSStyleDeclaration.getPropertyValue(a.style,b)},setStyle:function(a,b,c,e){var d=a.style;if(arguments.length>2){CSSStyleDeclaration.setProperty(d,b,c,e?"important":"")}else{CSSStyleDeclaration.setProperties(d,arguments[1])}},getComputedStyle:function(a,b){var c=document.defaultView;if(arguments.length==1){return ViewCSS.getComputedStyle(c,a,null)}else{return ViewCSS.getComputedPropertyValue(c,a,b)}},animate:function(a,b){return new Animation(a.style,b,a,true)},getOffsetFromBody:function(a){return ElementView.getOffsetFromBody(a)},setCapture:function(a){if(a!=_1.captureElement)this.releaseCapture();if(!_1.captureElement){_1.captureElement=a}},releaseCapture:function(){var a=_1.captureElement;if(a){delete _1.captureElement;this.dispatchEvent(a,"losecapture");if(!this.matchesSelector(a,":hover")){this.dispatchEvent(a,"mouseout")}}}});var behavior=_g.prototype;forEach.csv("setInterval,setTimeout",function(d){behavior[d]=function(a,b){if(typeof a=="string")a=this[a];var c=Array2.slice(arguments,2);var e=this;return global[d](function(){a.apply(e,c)},b||1)}});forEach.csv("querySelector,querySelectorAll",function(c){behavior[c]=function(a,b){if(arguments.length==1){b=a;a=document}return NodeSelector[c](a,b)}});forEach([EventTarget,ElementView,Node,Element],function(c){c.forEach(function(a,b){if(!behavior[b]){behavior[b]=bind(a,c)}})});ClassList.forEach(function(a,b){if(b=="contains")b="has";behavior[b+"Class"]=a});behavior=new _g;var Rule=Base.extend({constructor:function(b,c){if(!(b instanceof Selector)){b=new Selector(b)}if(typeof c=="string"){c=new External(c,function(a){c=a})}else if(!c.isModification&&!jsb.behavior.ancestorOf(c)){c=jsb.behavior.extend(c)}this.refresh=function(){if(typeof c.attach=="function"){b.exec(document).forEach(c.attach)}};this.toString=b.toString;forEach(b.split(),function(a){_1.addRule(a,c)})},refresh:Undefined});var RuleList=Collection.extend({put:function(a,b){a=String(a);if(a.indexOf("@")==0){if(detect(a.slice(1)))this.merge(b)}else{this.base.apply(this,arguments)}},refresh:function(){this.invoke("refresh")}},{Item:Rule});var Animation=Base.extend({constructor:function(l,m,o,p){var n={},q;var r=function(e,d){if(typeof e!="object"){e={end:String(e)}}if(!q)q=e;e=copy(e);e.styleElement=o;if(e.delay==null&&q.delay!=null){e.delay=q.delay}if(e.duration==null&&q.duration!=null){e.duration=q.duration}if(/^(font|background(Position)?)$/.test(d)){throw"Cannot animate shorthand property '"+d+"'.";}else if(/^border(Top|Right|Bottom|Left)?$/.test(d)){var h=d,j=_7(e.start),f=_7(e.end),g=["Width","Style","Color"];forEach(f,function(a,b){var c=copy(e);c.start=j[b];c.end=a;r(c,h+g[b])})}else if(/^(margin|padding|border(Width|Color|Style))$/.test(d)){var h=d.replace(/Width|Color|Style/,""),k=d.replace(h,"");j=_7(e.start,true);f=_7(e.end,true);forEach.csv("Top,Right,Bottom,Left",function(a,b){var c=copy(e);c.start=j[b];c.end=f[b];n[h+a+k]=c})}else{n[d]=e}};forEach(m,r);function s(a,b){return _1.transitions.add(l,a,b)};var t=false;this.start=function(){forEach(n,function(a,b){var c=s(b,a);if(!t){a.start=c.start;a.duration=c.duration}});t=true};this.reverse=function(c){forEach(n,function(a,b){s(b,{end:a.start,duration:c||a.duration,styleElement:o})})};this.accelerate=function(c){forEach(n,function(a,b){a=_1.transitions.get(a);if(a)a.accelerate(c)})};if(p)this.start()},transitions:null,accelerate:Undefined,reverse:Undefined,start:Undefined},{timingFunctions:{"ease":function(a,b,c,e){if((a/=e/2)<1){return c/2*a*a*a*a+b}return-c/2*((a-=2)*a*a*a-2)+b},"linear":function(a,b,c,e){return c*a/e+b},"ease-in":function(a,b,c,e){return c*(a/=e)*a+b},"ease-out":function(a,b,c,e){return-c*(a/=e)*(a-2)+b},"ease-in-out":function(a,b,c,e){if((a/=e/2)<1){return c/2*a*a+b}return-c/2*((--a)*(a-2)-1)+b}}});var Transition=Base.extend({constructor:function(e,d,h){extend(this,h);this.toString=K(Transition.getKey(e,d,h));this.propertyName=d;var j=this.styleElement,f=this.start,g=this.timing;if(j)d=CSSStyleDeclaration.getPropertyName(d);if(f==null){f=this.start=e[d]||(j?ViewCSS.getComputedPropertyValue(document.defaultView,j,d):"")||""}if(/color$/i.test(d)){f=this.parseColor(f);var k=this.parseColor(this.end),l=map(f,function(a,b){return k[b]-a}),m=function(c){return"#"+map(f,function(a,b){a=Math.round(g(c,a,l[b],duration));return(a<16?"0":"")+a.toString(16)}).join("")}}else if(j&&d=="clip"){f=map(match(f,_d),Number);k=map(match(this.end,_d),Number);l=map(f,function(a,b){return k[b]-a});m=function(c){return"rect("+map(f,function(a,b){return Math.round(g(c,a,l[b],duration))}).join("px, ")+"px)"}}else if(/^\-?\.?\d/.test(this.end)){var o=String(this.end).replace(/^[-.\d]+/,"").toLowerCase();if(!parseFloat(f))f=this.start=0+o;f=Number(String(f).replace(o,""));k=Number(String(this.end).replace(o,""));l=k-f;m=function(a){var b=g(a,f,l,duration);if(o=="px")b=Math.round(b);return b+o}}else{k=this.end||"";m=function(a){return g(a,0,1,duration)<1?f:k}}var p=0,n=false,q=0,r=0,s=~~(this.delay*1000),duration=~~(this.duration*1000),t=1,u=0;if(typeof g!="function"){g=Animation.timingFunctions[g]}assertType(g,"function","Invalid timing function.");this.tick=function(a){if(!p)p=a;if(!this.complete&&!r){u=a-p;if(!q&&u>=s){q=a}if(q){u=Math.round(Math.min((a-q)*t,duration));var b=n?duration-u:u;if(j){CSSStyleDeclaration.setProperty(e,d,m(b))}else{e[d]=m(b)}this.complete=u>=duration;if(this.complete){this.elapsedTime=a-p}}}};this.reverse=function(){var a=this.start;this.start=this.end;this.end=a;this.complete=false;n=!n;if(q){q=Date2.now()-(duration-u)/t}};this.setSpeed=function(a){t=a;if(q){q=Date2.now()-u/t}};this.accelerate=function(a){this.setSpeed(t*a)}},complete:false,delay:0,duration:1,timing:"ease",start:null,end:null,compare:function(a,b){if(/color$/i.test(this.propertyName)){return this.parseColor(this[b]).join(",")==this.parseColor(a).join(",")}else if(this.propertyName=="clip"){var c=/,\s*/g;return this[b].replace(c," ")==a.replace(c," ")}return this[b]==a},parseColor:function(b){b=b.toLowerCase();var c=Transition.colors,e=b,d=c[b];if(typeof d=="string"){e=d;d=""}if(!d){if(/^rgb/.test(e)){d=map(e.match(_q),function(a){return a.indexOf("%")==-1?a-0:Math.round(2.55*a.slice(0,-1))})}else if(e.indexOf("#")==0){var h=e.slice(1);if(h.length==3)h=h.replace(/([0-9a-f])/g,"$1$1");d=map(h.match(/([0-9a-f]{2})/g),_r)}else{var j=Transition._s;if(!j){j=Transition._s=document.createElement("input");j.style.cssText="position:absolute;left:0;top:-9999px;"}document.body.appendChild(j);try{j.style.color=e;var f=ViewCSS.getComputedPropertyValue(document.defaultView,j,"color")}catch(x){}document.body.removeChild(j);if(f!=e){d=this.parseColor(f||"#000")}}if(!d||d.length!=3||Array2.contains(d,NaN)){throw"Invalid color '"+b+"'.";}c[b]=d}return d}},{colors:{},getKey:function(a,b,c){var e=c.styleElement||a,d=assignID(e);if(c.styleElement)d+=".style";return d+"."+b}});var Transitions=Collection.extend({constructor:function(a){this.base(a);this.tick=bind(this.tick,this)},add:function(a,b,c){var e=Transition.getKey(a,b,c),d=this.get(e);if(d){if(d.duration!=c.duration){d.setSpeed(d.duration/(c.duration||1))}if(d.compare(c.end,"start")){d.reverse()}}else{d=this.put(e,a,b,c);if(!this._9){this._9=setTimeout(this.tick,4)}}return d},tick:function(){this.invoke("tick",Date2.now());var b=this.filter(function(a){return a.complete});b.forEach(this.remove,this);b.forEach(function(a){if(a.styleElement){behavior.dispatchEvent(a.styleElement,"transitionend",{propertyName:a.propertyName,elapsedTime:a.elapsedTime/1000})}});delete this._9;if(this.size()>0){this._9=setTimeout(this.tick,4)}}},{Item:Transition,create:function(a,b,c,e){return new this.Item(b,c,e)}});extend(jsb,"createStyleSheet",function(f){if(typeof f!="string"){var g=f;var k={toString:function(){return map(this,function(a,b){return b+a}).join("\n").replace(/!([^\w])/g,"!important$1")}};var l;var m=function(d,h){if(/,/.test(h)){forEach(new Selector(h).split(),partial(m,d))}else{if(!l){l=h=="*"?d:{}}if(h!="*"){var j=k[h];if(!j){j=k[h]=extend({toString:function(){return" {\n"+map(this,function(b,c){if(typeof b=="function")b="none";return" "+c.replace(/[A-Z]/g,function(a){return"-"+a.toLowerCase()})+": "+b}).join(";\n")+"\n}"}},l)}forEach.detect(d,function(c,e){if(_f[e]==undefined){e=CSSStyleDeclaration.getPropertyName(e)}if(_f[e]!=undefined){if(c=="initial"){forEach(j,function(a,b){if(b.indexOf(e)==0){delete j[b]}});delete j[e]}else{/*@if(@_jscript_version<5.6)if(e=="cursor"&&c=="pointer")c="hand";/*@end @*/j[e]=c}}})}}};forEach.detect(g,m);f=k.toString()}f=f.replace(/%theme%/g,"themes/"+jsb.theme);var o=/(url\s*\(\s*['"]?)([\w\.]+[^:\)]*['"]?\))/gi;this.base(f.replace(o,"$1"+_a()+"$2"));return f});var External=Base.extend({constructor:function(a,b){a=a.split("#");this.src=a[0];this.path=a[1].split(".");this.register=b},attach:true,getObject:function(){var a=global,b=0;while(a&&b<this.path.length){a=a[this.path[b++]]}return a},load:function(){var a=this.getObject();if(!a&&!this.script){External.SCRIPT.src=this.src;if(!External.scripts[External.SCRIPT.src]){External.scripts[External.SCRIPT.src]=true;this.script=document.createElement("script");this.script.type="text/javascript";this.script.src=this.src;behavior.querySelector("head").appendChild(this.script)}a=this.getObject()}if(a){this.register(a);if(!a.attach)this.attach=false}return a}},{SCRIPT:document.createElement("script"),scripts:{}});jsb.eventDelegator=new Base({types:{},addEventListener:function(a,b){var c=this.types;if(!c[a]){c[a]=[];EventTarget.addEventListener(document,a,this,_m.test(a))}c[a].push(b)},handleEvent:function(a){var b=a.target;if(b.nodeType!=1)return;var c=a.type,e=_c.test(c),d=e&&_1.captureElement;if(d&&_j.test(c))return;var h=this.types[c];if(!h||!h.length)return;if(e&&c!="mousewheel"){if(a.offsetX!=null){a=Event.cloneEvent(a)}var j=ElementView.getOffsetXY(b,a.clientX,a.clientY);a.offsetX=j.x;a.offsetY=j.y}var f=d||!a.bubbles,g=d?_1.captureElement:b;if(!f){extend(a,"stopPropagation",function(){this.base();f=true})}do{var k=g.uniqueID;if(_4[k]){for(var l=0,m;m=h[l];l++){if(m[k]){jsb.eventDispatcher.dispatch(m.behavior,g,a)}}}g=g.parentNode}while(g&&!f)}});jsb.eventDispatcher=new Base({dispatch:function(a,b,c,e){var d=c.type;_2.listener=a["on"+d];if(!_2.listener||_2.listener==Undefined)return;_2.behavior=a;_2.args=[b,c];if(_c.test(d)){if(d=="mousewheel"){_2.args.push(c.wheelDelta)}else{if(_i.test(d)){if(a.jsbExtendedMouse){_2.args.push(c.button)}else{if(!_p.test(c.button||0))return}}if(b==c.target){var h=c.offsetX,j=c.offsetY}else{var f=ElementView.getOffsetXY(b,c.clientX,c.clientY);h=f.x;j=f.y}_2.args.push(h,j,c.screenX,c.screenY)}}else if(_l.test(d)){_2.args.push(c.keyCode,c.shiftKey,c.ctrlKey,c.altKey,c.metaKey)}else if(d=="propertychange"||d=="propertyset"||d=="transitionend"){_2.args.push(c.propertyName)}if(a.jsbUseDispatch&&(e||c.bubbles||c.eventPhase==Event.CAPTURING_PHASE)){if(_6){_6.jsbEvents++}else{var g=document.createEvent(_8);g.initEvent("jsbEvents",false,false);document.dispatchEvent(g)}}else{_2.listener.apply(a,_2.args)}}});var _2=_0.jsbEvent={};if(detect.MSIE&&!detect("element.dispatchEvent")){var _6=document.createElement(/^CSS/.test(document.compatMode)?"meta":"marquee");_6.jsbEvents=0;_6.attachEvent("onpropertychange",new Function("e",'if(e.propertyName=="jsbEvents"){var d=base2.toString.jsbEvent;d.listener.apply(d.behavior,d.args)}'));document.getElementsByTagName("head")[0].appendChild(_6)}else{document.addEventListener("jsbEvents",function(){_2.listener.apply(_2.behavior,_2.args)},false)}var _3=DocumentEvent.createEvent(document,_8);_3.initEvent("dummy",false,false);_3=Event.cloneEvent(_3);function _5(a,b,c){_3.target=b;_3.type=c;jsb.eventDispatcher.dispatch(a,b,_3,true)};var _1=new Base({timestamp:Date2.now(),contentReadyQueue:[],documentReadyQueue:[],liveRules:[],rules:[],transitions:new Transitions,onDOMContentLoaded:function(){_1.loaded=true;if(!_1.ready&&!_1.rules.length){setTimeout(_1.fireReady,_1.getInterval())}_1.isContentReady=True},onblur:function(){_1._t=_1._h;_1._h=null},onfocus:function(a){_1._h=a.target},onmousedown:function(a){_1.active=_1.busy=true},onmouseup:function(){_1.active=_1.busy=false},addRule:function(a,b){var c={query:a.toDOMQuery(),behavior:b,specificity:a.getSpecificity()};_1.liveRules.push(c);if(!_1.loaded){_1.rules.push(c);_1.rules.unsorted=true}if(!_1.started){_1.started=true;_1.tick()}},getInterval:function(){return _1.busy?jsb.INTERVAL*10:jsb.INTERVAL},fireReady:function(){if(!_1.ready){_1.ready=true;Array2.batch(_1.documentReadyQueue,function(a){_5(a.behavior,a.element,"documentready")},jsb.TIMEOUT,_1.parseComplete);_1.documentReadyQueue=[]}},isContentReady:function(a){if(_o.test(a.nodeName))return _1.loaded;while(a&&!a.nextSibling){a=a.parentNode}return!!a},parseComplete:function(){_1.rules=Array2.filter(_1.liveRules,function(a){return!!a.behavior.attach});_1.rules.sort(_e);_1.tick()},tick:function(a,b,c){var e=Date2.now(),d=_1.rules,h=d.length;if(!_1.busy&&_1.timestamp-e<=jsb.INTERVAL){_1.timestamp=e;var j=_1.contentReadyQueue;var f=Date2.now(),g=f,k=0;while(j.length&&(f-g<jsb.TIMEOUT)){var l=j.shift();if(_1.isContentReady(l.element)){_5(l.behavior,l.element,"contentready")}else{j.push(l)}if(k++<5||k%50==0)f=Date2.now()}while(h&&d.length&&(f-g<jsb.TIMEOUT)){if(a==null)a=b=0;var m=d[a],o=m.behavior;if(o.attach){var p=false;if(!c){var n=m.query;var q=n.state||[];q.unshift(document,o.constructor==External?2:jsb.QUERY_SIZE);c=n.apply(null,q);p=!!n.complete}f=Date2.now();var r=c.length,k=0;if(r&&o.constructor==External){m.behavior=o.load()||o;delete n.state;c=null;a++}else{while(b<r&&(f-g<jsb.TIMEOUT)){o.attach(c[b++],m);if(k++<5||k%50==0)f=Date2.now()}if(b==r){b=0;c=null;if(_1.loaded&&p){d.splice(a,1);delete n.state}else a++}}}else{d.splice(a,1)}if(a>=d.length){a=0;if(d.unsorted){d.sort(_e);d.unsorted=false}}h--}}if(d.length){var s=function(){_1.tick(a,b,c)}}else{if(_1.ready){s=_1.parseComplete}else{s=_1.fireReady}}setTimeout(s,_1.getInterval())}});for(var i in _1)if(_b.test(i)){EventTarget.addEventListener(document,i.slice(2),_1[i],i!="onDOMContentLoaded")}EventTarget.addEventListener(window,"blur",function(a){var b=_1.captureElement;if(b&&document.body==_1._t){behavior.releaseCapture();if(behavior.matchesSelector(b,":hover")){behavior.dispatchEvent(b,"mouseout")}}},false);behavior.addClass(document.documentElement,"jsb-enabled");eval(this.exports)};