-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsWidget.js
9 lines (9 loc) · 4.74 KB
/
jsWidget.js
1
2
3
4
5
6
7
8
9
/*
* Javascript Widget Engine v0.0.1
*
* Copyright 2009-2010, Subramaya Sastry
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Date: Tue Mar 30 11:00:00 AM CT
*/
function _jw_0(A){return(typeof A!="undefined")}function _jw_1(A,C){for(var B=0;B<A.length;B++){C(A[B])}}function _Widget(A){this.wf=A;this.baseUrl=A.base_url;this.rootDIV="";this.init();if(!_jw_0(this.baseUrl)){this.baseUrl=""}}_Widget.prototype={init:function(){var B=this;var A=B.wf;var C=A.base_css_prefs;B.hoverStyle=(C.link_class||!_jw_0(C.link_hover_style))?"":C.link_hover_style},_v0:function(B,A,E){var C=this;var D=C.wf.base_css_prefs;if(A){B.setAttribute((document.all?"className":"class"),A)}else{if(E){if(B.style.setAttribute){B.style.setAttribute("cssText",E);if((B.tagName=="A")&&C.hoverStyle){B.onmouseover=function(){this.style.setAttribute("cssText",E+";"+C.hoverStyle)};B.onmouseout=function(){this.style.setAttribute("cssText",E)}}}else{B.setAttribute("style",E);if((B.tagName=="A")&&C.hoverStyle){B.onmouseover=function(){this.setAttribute("style",E+";"+C.hoverStyle)};B.onmouseout=function(){this.setAttribute("style",E)}}}}else{if((B.tagName=="A")&&(D.link_style||D.link_class)){C._v0(B,D.link_class,D.link_style)}}}},_v1:function(D,B,C){var A=document.createElement(D);this._v0(A,B,C);return A},_v2:function(str,dataObj){function fetchExprValue(w,d,vRef){return eval(vRef.substring(1,vRef.length-1).replace(/\$util\./g,"w.helpers.").replace(/\$/g,"d"))}var widget=this;var widgetFormat=this.wf;var refs=str.match(/\{.*?\}/g);if(refs){_jw_1(refs,function(arrayElt){str=str.replace(arrayElt,fetchExprValue(widget,dataObj,arrayElt))})}return str},_v3:function(B,K,J,E,L,G){var F=this;var I=F.wf.base_css_prefs;var H=F.baseUrl;if(!E){E=document.createTextNode(K)}else{if(E.tagName=="IMG"){var A=(L&&L.src)?F._v2(L.src,B):H;if(A.indexOf("http://")==-1){A=H+A}E.src=A;E.alt=K}else{if(E.tagName!="A"){if(G){E.innerHTML=K}}else{var C=(L&&L.url)?F._v2(L.url,B):H;if(C.indexOf("http://")==-1){C=H+C}E.href=C;E.target=I.link_target;if(G){var D=(L&&L.text)?L.text:K;E.innerHTML=F._v2(D,B)}if(!L.clazz&&!L.style){F._v0(E,I.link_class,I.link_style)}}}}return E},_v4:function(B,K,L){var I=this;var E="";var A="";var J=_jw_0(L.how)?L.how:[];var H=J.length;for(var G=0;G<H;G++){var F;var D=J[G];var C;if(D.elt=="dom_tree"){C=I._v5(D.root_elt,B,D);this._v3(B,"",[],C,D,false)}else{C=this._v1(D.elt,D.clazz,D.style);F=(G==(H-1));this._v3(B,K,L,C,D,F)}if(!E){E=C}else{A.appendChild(C)}A=C}if(H==0){E=this._v3(B,K,L,"",D,true)}return E},_v6:function(A,B){if(B){if(B.substring(0,1)=="\n"){A.appendChild(document.createElement("br"));B=B.substring(1)}if(B){A.appendChild(document.createTextNode(B))}}},_v7:function(C,F,E){var G=this;var D=_jw_0(F.what)?F.what:"";if(_jw_0(F.if_true)){var H=G._v2(F.if_true,C);if(H=="undefined"||!H){return }}if(D){var A=G._v2(D,C);if(!A){return }}if(F.prefix){G._v6(E,F.prefix)}var B=G._v4(C,A,F);if(B){E.appendChild(B)}if(F.suffix){G._v6(E,F.suffix)}},_v8:function(D,A,B){var C=this;_jw_1(A,function(E){C._v7(D,E,B)})},_v5:function(C,A,B){var D=this._v1(C,B.clazz,B.style);this._v8(A,B.dom_nodes,D);return D},_v9:function(sectionFormat){var secData=eval(sectionFormat.data);if(sectionFormat.loop){var secDIV=this._v1("div","","");var count=0;var numReqdItems=sectionFormat.num_items;for(var i=0;i<secData.length;i++){if((count==numReqdItems)){break}secDIV.appendChild(this._v5("div",secData[i],sectionFormat));count++}return secDIV}else{return this._v5("div",secData,sectionFormat)}},_v10:function(){var D=this;var C=D.baseUrl;var A=D.wf;var E=A.base_css_prefs;var B=D._v1("div",E.clazz,E.style);_jw_1(A.sections,function(F){B.appendChild(D._v9(A[F]))});D.rootDIV=B;return B},installOver:function(A){A.parentNode.replaceChild(this._v10(),A)},refresh:function(){this.installOver(this.rootDIV)},helpers:{_v11:function(A,D,B,C){if(!A||(A.length<=D)){return A}else{A=A.substring(0,D);var E=A.lastIndexOf(C);if(E>B){A=A.substring(0,E)}else{if(C!=" "){E=A.lastIndexOf(" ");if(E>B){A=A.substring(0,E)}}}return A+" ..."}},_v12:function(B,A){return this._v11(B,A,A-15," ")},trimString:function(B,A){return(!A)?B:this._v12(B,A)},formatDate:function(E,F,L,G){var B=["January","February","March","April","May","June","July","August","September","October","November","December"];function A(N,M){M=String(M).replace(/^0/,"");N.m=M;N.mm=M<10?"0"+M:M;N.MM=B[M-1];N.M=B[M-1].substr(0,3)}function I(M,N){N=String(N).replace(/^0/,"");M.d=N;M.dd=N<10?"0"+N:N}if(!L||!G){return E}var C=L.split(F);var H=E.split(F);var K={};for(i=0;i<C.length;i++){K[C[i]]=H[i]}if(K.m||K.mm){A(K,K.m?K.m:K.mm)}else{if(K.MM){for(i=0;i<12;i++){if(B[i]==K.MM){A(K,i+1);break}}}else{if(K.M){for(i=0;i<12;i++){if(B[i].substr(0,3)==K.M){A(K,i+1);break}}}}}I(K,K.d?K.d:K.dd);var J=["y","dd","d","mm","m","MM","M"];var D=G;for(i=0;i<J.length;i++){D=D.replace(J[i],K[J[i]])}return D}}};