12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- /** This file is part of jsMotif
- Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).*
- All rights reserved.
- Contact: Nokia Corporation marek.krysiuk@nokia.com
- You may use this file under the terms of the BSD license as follows:
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- var jsMotif=jsMotif||{};
- jsMotif.dom=function(){function g(a){return f.getElementById(a)}function b(a){return typeof a==="string"?g(a):a}function h(a,c){for(var b in c)if(c.hasOwnProperty(b))b==="class"?a.className=c[b]:a[b]=c[b];return a}function i(a,c){var f=b(a);f&&f.appendChild(c)}function e(a,c,b){c="_"+c+"Handlers";a&&(a[c]=a[c]||[],a[c].push(b));return!0}function d(a){var a=a||window.event,c=a.relatedTarget;if(!c)if(a.type==="mouseout")c=a.toElement;else if(a.type==="mouseover")c=a.fromElement;return c}function j(a,
- c){for(;c&&c!==a;)c=c.parentNode;return c===a}function c(a,c){return function(b){var f=d(b);j(a,f)||c(b)}}var f=document;return{byId:g,create:function(a,c,b){a=f.createElement(a);a=h(a,c);b&&typeof b==="object"&&b.appendChild?a.appendChild(b):typeof b==="string"&&a.appendChild(f.createTextNode(b));return a},createFragment:function(){return f.createDocumentFragment()},append:i,addEvent:function(a,f,d,p){var a=b(a),n;if(a&&(a.addEventListener?n=function(a,m,f,d){if(a=b(a))if(d=typeof d!=="undefined"?
- d:!1,m==="mouseenter"||m==="mouseleave"){var k=m==="mouseenter"?"mouseover":"mouseout",f=c(a,f);a.addEventListener(k,f,d);e(a,m,f)}else e(a,m,f),a.addEventListener(m,f,d),m==="mousewheel"&&a.addEventListener("DOMMouseScroll",f,d);return f}:a.attachEvent&&(n=function(a,c,f){var d=b(a);if(d){var k=function(){f.call(a,window.event,arguments)};e(d,c,k);d.attachEvent("on"+c,k);return k}}),n))return jsMotif.dom.addEvent=n,n(a,f,d,p)},hide:function(){for(var a,c,f=arguments.length;f--;)if(a=b(arguments[f]))c=
- a.style.display,a._lastDisplay=c!=="none"?c:"",a.style.display="none"},show:function(){for(var a,c=arguments.length;c--;)if(a=b(arguments[c]))a.style.display=a._lastDisplay||""},stopPropagation:function(a){a=a||window.event;a.cancelBubble=!0;a.stopPropagation&&a.stopPropagation()},extendNodeAttributes:h,isContainedWithin:j,getMouseRelatedTarget:d,getEventSource:function(a){a=a||window.event;return a.target||a.srcElement},preventDefault:function(a){a=a||window.event;a.returnValue=!1;a.preventDefault&&
- a.preventDefault()},elem:b,remove:function(a){(a=b(a))&&a.parentNode&&a.parentNode.removeChild(a)},moveChildNodes:function(a,c){for(var b=c.firstChild;b;)i(a,b),b=c.firstChild}}}();jsMotif.comm={};
- jsMotif.comm.jsonParse=function(){var g,b,h={'"':'"',"\\":"\\","/":"/",b:"\u0008",f:"\u000c",n:"\n",r:"\r",t:"\t"},i,e=function(a){throw{name:"SyntaxError",message:a,at:g,text:i};},d=function(a){a&&a!==b&&e("Expected '"+a+"' instead of '"+b+"'");b=i.charAt(g);g+=1;return b},j=function(){var a;a="";b==="-"&&(a="-",d("-"));for(;b>="0"&&b<="9";)a+=b,d();if(b===".")for(a+=".";d()&&b>="0"&&b<="9";)a+=b;if(b==="e"||b==="E"){a+=b;d();if(b==="-"||b==="+")a+=b,d();for(;b>="0"&&b<="9";)a+=b,d()}a=+a;if(isFinite(a))return a;
- else e("Bad number")},c=function(){var a,c,f="",l;if(b==='"')for(;d();)if(b==='"')return d(),f;else if(b==="\\")if(d(),b==="u"){for(c=l=0;c<4;c+=1){a=parseInt(d(),16);if(!isFinite(a))break;l=l*16+a}f+=String.fromCharCode(l)}else if(typeof h[b]==="string")f+=h[b];else break;else f+=b;e("Bad string")},f=function(){for(;b&&b<=" ";)d()},a=function(){switch(b){case "t":return d("t"),d("r"),d("u"),d("e"),!0;case "f":return d("f"),d("a"),d("l"),d("s"),d("e"),!1;case "n":return d("n"),d("u"),d("l"),d("l"),
- null}e("Unexpected '"+b+"'")},o;o=function(){f();switch(b){case "{":var k;a:{var g,n={};if(b==="{"){d("{");f();if(b==="}"){d("}");k=n;break a}for(;b;){g=c();f();d(":");Object.hasOwnProperty.call(n,g)&&e('Duplicate key "'+g+'"');n[g]=o();f();if(b==="}"){d("}");k=n;break a}d(",");f()}}e("Bad object")}return k;case "[":a:{k=[];if(b==="["){d("[");f();if(b==="]"){d("]");g=k;break a}for(;b;){k.push(o());f();if(b==="]"){d("]");g=k;break a}d(",");f()}}e("Bad array")}return g;case '"':return c();case "-":return j();
- default:return b>="0"&&b<="9"?j():a()}};return function(a,c){var d;i=a;g=0;b=" ";d=o();f();b&&e("Syntax error");return typeof c==="function"?function m(a,b){var f,d,e=a[b];if(e&&typeof e==="object")for(f in e)Object.prototype.hasOwnProperty.call(e,f)&&(d=m(e,f),d!==void 0?e[f]=d:delete e[f]);return c.call(a,b,e)}({"":d},""):d}}();
- jsMotif.comm.xhttp=function(){var g=window.JSON?window.JSON.parse:jsMotif.comm.jsonParse;return{getJson:function(b,h,i){var i=i||{},e=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),d=i.headers||{};e.timeout=i.timeout||4E3;e.open("GET",b);e.setRequestHeader("Accept","application/json");e.setRequestHeader("Content-Type","application/json");if(d)for(var j in d)d.hasOwnProperty(j)&&e.setRequestHeader(j,d[j]);e.ontimeout=function(){h({},"timeout")};e.onreadystatechange=
- function(){if(e.readyState===4){var c={},b=e.status,a=e.responseText;b===200&&(c=g(a));h(c,b===200?"ok":"error")}};e.send()}}}();
- jsMotif.comm.jsonp=function(){function g(b){b=h.create("script",{src:b,type:"text/javascript"});b.onload=function(){h.remove(this)};b.onreadystatechange=function(){this.readyState==="loaded"&&h.remove(this)};h.append(document.body,b)}function b(b,g){var c=jsMotif.comm,f="handle"+ ++i,a=setTimeout(function(){b({},"timeout");c.jsonp[f]=function(){};setTimeout(function(){delete jsMotif.comm.jsonp[f]},5E3)},g||e);c.jsonp[f]=function(c){clearTimeout(a);b(c,"ok");delete jsMotif.comm.jsonp[f]};return f}
- var h=jsMotif.dom,i=100,e=4E3;return{getJson:function(d,e,c){e=b(e,c?c.timeout:"");d=d.replace("{CB_FN}",["jsMotif.comm.jsonp",e].join("."));g(d)}}}();jsMotif.errors={LVL:{log:3,warn:2,critical:1},MSG:{undefData:"Undefined data",undefModule:"Undefined module",wrongSrcNode:"This node type cannot have src attribute",reqRelNotFound:"Cannot found required rel %s1 in %s2 module"}};
- jsMotif.selector=function(){function g(c){return c.replace(/(^\s+)|(\s+$)/g,"")}function b(c){var b=-1,a,e,k,h,i;if(c[0]==="!")i=d["!"],k=g(c.substr(1,c.length));else{for(var l in d)d.hasOwnProperty(l)&&(e=c.lastIndexOf(l),e>b&&(b=e,a=l));b!==-1&&(i=d[a],h=g(c.substr(b,c.length).split(a)[1]).replace(/(^\')|(^\")|(\'$)|(\"$)/g,""),k=a!=="!"?g(c.substr(0,b)):h)}return{valuePath:k,toValue:h,action:i}}function h(c,b){var a=b.join("");a!==""&&(c=c[a]);return c}function i(c){c=(typeof c==="string"?c:"").replace(/([\]\)\.]+)\./g,
- function(c,a){return a?a+"":c});j[c.charAt(c.length-1)]||(c+=".");return c}function e(c,b){for(var a=this,d=[],e=[],c=i(c),g=0,h=c.length;g<h;g++){var l=c.charAt(g);j[l]?a=j[l](a,d,e,l):d.push(l);if(!a)return b}return a}var d={"==":function(c,b){return c==b},"!=":function(c,b){return c?c!=b:!1},">":function(c,b){return c>b},"<":function(c,b){return c<b},">=":function(b,f){return b>=f},"<=":function(b,f){return b<=f},"!":function(b){return!b}},j={".":function(b,f,a,d){if(a.length)f.push(d);else{if(b instanceof
- Array){for(var a=0,d=b.length,e=[];a<d;a++)e.push(h(b[a],f));b=e}else b=h(b,f);f.splice(0,f.length)}return b},"(":function(b){return b},")":function(b,f,a,d){if(a.length)return f.push(d),b;else if(f=f.join(""),typeof b[f]==="function")return b[f]()},"[":function(b,d,a,e){a.length?d.push(e):(b=h(b,d),d.splice(0,d.length));a.push(e);return b},"]":function(c,d,a,g){a.pop();if(a.length)d.push(g);else{a=d.join("");if(isNaN(a)){for(var a=b(a),g=[],h=0,i=c.length;h<i;h++){var j=c[h],l=e.call(j,a.valuePath);
- a.action(l,a.toValue)&&g.push(j)}c=g}else a!==""&&(c=c[parseInt(a,10)]);d.splice(0,d.length)}return c}};return{resolveCondition:function(c){var d;if(d=e.call(this,c,!1))return d;else if(c=b(c),c.action)return d=e.call(this,c.valuePath),c.action(d,c.toValue)},getData:e}}();
- jsMotif.Template=function(){var g=jsMotif.errors,b=jsMotif.dom,h=jsMotif.selector,i=function(b,a,c,d){var l;d&&(a=decodeURI(a));a=a&&"{"===a.charAt(0)&&"}"===a.charAt(a.length-1)?a.substr(1).substr(0,a.length-2):!1;if(!1!==a)return d=h.resolveCondition.call(c,a),typeof d==="undefined"&&(l=(a=a.match(/(\S+)\(\)/))?a[1]:void 0,a=l,d=a&&this.predefinedFunctions[a]?this.predefinedFunctions[a].call(b,c):d),d},e=function(a,b,c,d){var f=this;return b.replace(/(\{[^\{\}]+\})/g,function(b,m){var e=i.call(f,
- a,m,c,d);return e?e:""})},d=function(a,c,d){return(c=e.call(this,a,c,d))?(c instanceof Array&&(c=c.join(", ")),a.innerHTML=c):(b.hide(a),!1)},j=function(a,b,c){b=e.call(this,a,b,c,!0);c=a.nodeName.toLowerCase();if(typeof b==="string")c==="a"||c==="link"?a.href=b:a.src=b;return b},c=function(a,b,c){(b=e.call(this,a,b,c,!0))&&a.setAttribute("href","mailto:"+b);return b},f=function(a,c,d){if(!i.call(this,a,c,d))return b.hide(a),!1},a=function(a,c,d){c=i.call(this,a,c,d);if(c instanceof Array&&c.length!==
- 0){d=b.createFragment();b.moveChildNodes(d,a);for(var f=0,e=c.length;f<e;f++){c[f]._index=f+1;var g=a,h=c[f],j=d.cloneNode(!0);this.renderObject(j,h);b.append(g,j)}}else b.hide(a);return!1},o=function(a,c){var d=b.byId(c);d&&(b.moveChildNodes(a,d.cloneNode(!0)),a.removeAttribute("tpl"))},k=function(a,c,d){var c=this.eventMap[c],f=function(a,b,c){return function(d){a.handler.call(b,c,d)}};if(c)for(var e=0,g=c.length;e<g;e++){var h=c[e];h&&h.name&&typeof h.handler==="function"&&b.addEvent(a,h.name,
- f(h,a,d))}},p=function(e){this.targetElem=b.elem(e.targetNode)||b.elem(e.template);this.mapping=[];var m=b.elem(e.template);this.templateBody=m?m.innerHTML:e.template;this.debug=e.debug||0;this.predefinedFunctions=e.functions||{};this.attributes=[];this.registerAttr("tpl",o);this.registerAttr("if",f);this.registerAttr("each",a);this.registerAttr("fill",d);this.registerAttr("url",j);this.registerAttr("rel",k);this.registerAttr("mailto",c);this.eventMap={};this.addEventMap(e.events);e=b.create("div",
- {});e.innerHTML=this.templateBody;this.fragment=b.createFragment();b.moveChildNodes(this.fragment,e)},n=function(a){for(var a=a.childNodes,b,c,d=0,e=a.length;d<e;d++)b=a[d],b.nodeName!=="#text"&&b.nodeName!=="#comment"&&((c=b.getAttribute("rel"))&&(this[c]=b),b.hasChildNodes()&&n.call(this,b))};p.prototype={render:function(a,c,d){this.jsonObject=a;if(c=c?b.elem(c):this.targetElem){if(!d)c.innerHTML="";d=this.fragment.cloneNode(!0);this.renderObject(d,a);b.append(c,d);this.targetElem=c}else this.errorLog(g.LVL.critical,
- g.MSG.noTargetNode,this)},fetch:function(a){this.jsonObject=a;var c=b.create("div",{}),d=this.fragment.cloneNode(!0);this.renderObject(d,a);b.append(c,d);return c.innerHTML},registerAttr:function(a,b){this.attributes.push({name:a,handler:b})},addEvent:function(a,b,c){a&&b&&c&&(this.eventMap[a]||(this.eventMap[a]=[]),this.eventMap[a].push({name:b,handler:c}))},addEventMap:function(a){if(a&&a instanceof Array)for(var b=0,c=a.length;b<c;b++){var d=a[b];this.addEvent(d.rel,d.name,d.handler)}},getRelMap:function(a){var b=
- {};n.call(b,a);return b},renderObject:function(a,b){var c=a.childNodes,d=0,e=0,f,g,h,i;if(a.getAttribute){d=0;for(e=this.attributes.length;d<e;d++)if(g=this.attributes[d],h=g.name,f=a.getAttribute(h))f=g.handler.call(this,a,f,b),i!==!1&&(i=f),h!=="rel"&&h!=="tpl"&&h!=="src"&&h!=="href"&&a.removeAttribute(h)}if(!1===i)return!1;d=0;for(e=c.length;d<e;d++)h=c[d],h.nodeName!=="#text"&&h.nodeName!=="#comment"&&this.renderObject(h,b)},errorLog:function(a){var b=Array.prototype.slice.call(arguments,1);if(this.debug>=
- a&&"object"===typeof window.console){if(a===g.LVL.log)return window.console.log.apply(window.console,b);if(a===g.LVL.warn)return window.console.warn.apply(window.console,b);if(a===g.LVL.critical)return window.console.error.apply(window.console,b)}}};return p}();jsMotif.Template.prototype.renderJSON=function(g,b,h){var i=this,e=jsMotif.comm,e=b&&b.reqType==="jsonp"?e.jsonp:e.xhttp;typeof g==="string"?e.getJson(g,function(d,e){if(b&&b.onData)b.onData(d,e);i.render(d,h)},b):i.render(g,h)};
|