Commits

Stephen McKamey committed 697cb62

better error handling

Comments (0)

Files changed (8)

 
 	<groupId>org.duelengine</groupId>
 	<artifactId>duel-js</artifactId>
-	<version>0.8.7</version>
+	<version>0.8.8</version>
 	<packaging>pom</packaging>
 
 	<name>DUEL Client Scripts</name>

duel-js/src/main/javascript/dom.js

 
 				if (name) {
 					if (type === NUL) {
-						value = '';
-						type = VAL;
+						// null/undefined removes attributes
+						continue;
 					}
 
 					name = ATTR_MAP[name.toLowerCase()] || name;
 						try {
 							elem[name] = value;
 
+							// also set duplicated properties
+							name = ATTR_DUP[name];
+							if (name) {
+								elem[name] = value;
+							}
+
 						} catch(ex2) {
 							if (name.toLowerCase() === 'type' && elem.tagName.toLowerCase() === 'input') {
 								// IE9 doesn't like HTML5 input types
 								continue;
-							} else {
-								throw ex2;
 							}
-						}
 
-						// also set duplicated properties
-						name = ATTR_DUP[name];
-						if (name) {
-							elem[name] = value;
+							throw new Error('DOM property '+elem.tagName+'.'+name+': '+ex2);
 						}
 
 					} else if (ATTR_BOOL[name.toLowerCase()]) {
 	}
 
 	/**
-	 * Renders an error as a text node
-	 * 
-	 * @private
-	 * @param {Error} ex The exception
-	 * @return {Node}
-	 */
-	function onErrorDOM(ex) {
-		return document.createTextNode(onError(ex));
-	}
-
-	/**
 	 * Returns result as DOM objects
 	 * 
 	 * @public
 
 		} catch (ex) {
 			// handle error with context
-			view = onErrorDOM(ex);
+			var errValue = onError(ex);
+
+			if (errValue instanceof Result) {
+				return errValue.toDOM(elem || view);
+
+			} else {
+				// render the error as a text node
+				view = document.createTextNode(''+errValue);
+			}
 		}
 
 		if (elem && elem.parentNode) {

duel-js/src/main/javascript/factory.js

 	/* factory.js --------------------*/
 
 	/**
-	 * Renders an error as text
+	 * Renders an error directly as text
 	 * 
 	 * @private
 	 * @param {Error} ex The exception
-	 * @return {string}
+	 * @return {string|Result}
 	 */
-	function onError(ex) {
-		return '['+ex+']';
-	}
+	var onError = function(ex) {
+		return '[ '+ex+' ]';
+	};
 
 	/**
 	 * Wraps a view definition with binding method
 					isFinite(count) ? count : 1,
 					isString(key) ? key : null);
 				return new Result(result);
+
 			} catch (ex) {
 				// handle error with context
-				return new Result(onError(ex));
+				var errValue = onError(ex);
+
+				if (errValue instanceof Result) {
+					return errValue;
+
+				} else {
+					// render the error as a text node
+					return new Result(''+errValue);
+				}
 			}
 		};
 
 	 * @param {string} value Markup text
 	 * @return {Markup}
 	 */
+	duel.onerror = function(value) {
+		if (isFunction(value)) {
+			onError = value;
+		}
+	};
+
+	/**
+	 * @public
+	 * @param {string} value Markup text
+	 * @return {Markup}
+	 */
 	duel.raw = function(value) {
 		return new Markup(value);
 	};

duel-js/src/main/javascript/render.js

 		if (!isString(val)) {
 			return val;
 		}
-	
-		return val.replace(/[&<>]/g,
-			function(ch) {
-				switch(ch) {
-					case '&':
-						return '&amp;';
-					case '<':
-						return '&lt;';
-					case '>':
-						return '&gt;';
-					default:
-						return ch;
-				}
-			});
+
+		var map = {
+			'&': '&amp;',
+			'<': '&lt;',
+			'>': '&gt;'
+		};
+
+		return val.replace(/[&<>]/g, function(ch) {
+			return map[ch] || ch;
+		});
 	}
 
 	/**
 		if (!isString(val)) {
 			return val;
 		}
-	
-		return val.replace(/[&<>"]/g,
-			function(ch) {
-				switch(ch) {
-					case '&':
-						return '&amp;';
-					case '<':
-						return '&lt;';
-					case '>':
-						return '&gt;';
-					case '"':
-						return '&quot;';
-					default:
-						return ch;
-				}
-			});
+
+		var map = {
+			'&': '&amp;',
+			'<': '&lt;',
+			'>': '&gt;',
+			'"': '&quot;'
+		};
+
+		return val.replace(/[&<>"]/g, function(ch) {
+			return map[ch] || ch;
+		});
 	}
 
 	/**
 								continue;
 							}
 						}
+						if (getType(val) === NUL) {
+							// null/undefined removes attributes
+							continue;
+						}
 
 						buffer.append(' ', name);
-						if (getType(val) !== NUL) {
-							// Closure Compiler type cast
-							buffer.append('="', /** @type{string} */(attrEncode(val)), '"');
-						}
+						// Closure Compiler type cast
+						buffer.append('="', /** @type{string} */(attrEncode(val)), '"');
 					}
 				}
 				i++;
 			var buffer = new Buffer();
 			renderElem(buffer, view);
 			return buffer.toString();
+
 		} catch (ex) {
 			// handle error with context
-			return onError(ex);
+			var errValue = onError(ex);
+
+			if (errValue instanceof Result) {
+				return render(errValue.value);
+
+			} else {
+				// render the error as a string
+				return (''+errValue);
+			}
 		}
 	}
 

duel-js/src/test/javascript/domTests.js

 	expected.setAttribute('data-str', '');
 	expected.setAttribute('data-num', 0);
 	expected.setAttribute('data-bool', false);
-	expected.setAttribute('data-null', '');
-	expected.setAttribute('data-undef', '');
+// 	expected.setAttribute('data-null', '');
+// 	expected.setAttribute('data-undef', '');
 	expected.appendChild(document.createTextNode('Lorem ipsum'));
 
 	same(toHTML(actual), toHTML(expected), '');

duel-js/src/test/javascript/renderTests.js

 	var actual = view().toString();
 
 	var expected = 
-		'<div data-str="" data-num="0" data-bool="false" data-null data-undef>'+
+		'<div data-str="" data-num="0" data-bool="false">'+
 		'Lorem ipsum'+
 		'</div>';
 	same(actual, expected, '');

duel-js/target/duel.js

 /*global window */
 
 /**
- * @license DUEL v0.8.7 http://duelengine.org
+ * @license DUEL v0.8.8 http://duelengine.org
  * Copyright (c)2006-2012 Stephen M. McKamey.
  * Licensed under The MIT License.
  */
 	/* factory.js --------------------*/
 
 	/**
-	 * Renders an error as text
+	 * Renders an error directly as text
 	 * 
 	 * @private
 	 * @param {Error} ex The exception
-	 * @return {string}
+	 * @return {string|Result}
 	 */
-	function onError(ex) {
-		return '['+ex+']';
-	}
+	var onError = function(ex) {
+		return '[ '+ex+' ]';
+	};
 
 	/**
 	 * Wraps a view definition with binding method
 					isFinite(count) ? count : 1,
 					isString(key) ? key : null);
 				return new Result(result);
+
 			} catch (ex) {
 				// handle error with context
-				return new Result(onError(ex));
+				var errValue = onError(ex);
+
+				if (errValue instanceof Result) {
+					return errValue;
+
+				} else {
+					// render the error as a text node
+					return new Result(''+errValue);
+				}
 			}
 		};
 
 	 * @param {string} value Markup text
 	 * @return {Markup}
 	 */
+	duel.onerror = function(value) {
+		if (isFunction(value)) {
+			onError = value;
+		}
+	};
+
+	/**
+	 * @public
+	 * @param {string} value Markup text
+	 * @return {Markup}
+	 */
 	duel.raw = function(value) {
 		return new Markup(value);
 	};
 		if (!isString(val)) {
 			return val;
 		}
-	
-		return val.replace(/[&<>]/g,
-			function(ch) {
-				switch(ch) {
-					case '&':
-						return '&amp;';
-					case '<':
-						return '&lt;';
-					case '>':
-						return '&gt;';
-					default:
-						return ch;
-				}
-			});
+
+		var map = {
+			'&': '&amp;',
+			'<': '&lt;',
+			'>': '&gt;'
+		};
+
+		return val.replace(/[&<>]/g, function(ch) {
+			return map[ch] || ch;
+		});
 	}
 
 	/**
 		if (!isString(val)) {
 			return val;
 		}
-	
-		return val.replace(/[&<>"]/g,
-			function(ch) {
-				switch(ch) {
-					case '&':
-						return '&amp;';
-					case '<':
-						return '&lt;';
-					case '>':
-						return '&gt;';
-					case '"':
-						return '&quot;';
-					default:
-						return ch;
-				}
-			});
+
+		var map = {
+			'&': '&amp;',
+			'<': '&lt;',
+			'>': '&gt;',
+			'"': '&quot;'
+		};
+
+		return val.replace(/[&<>"]/g, function(ch) {
+			return map[ch] || ch;
+		});
 	}
 
 	/**
 								continue;
 							}
 						}
+						if (getType(val) === NUL) {
+							// null/undefined removes attributes
+							continue;
+						}
 
 						buffer.append(' ', name);
-						if (getType(val) !== NUL) {
-							// Closure Compiler type cast
-							buffer.append('="', /** @type{string} */(attrEncode(val)), '"');
-						}
+						// Closure Compiler type cast
+						buffer.append('="', /** @type{string} */(attrEncode(val)), '"');
 					}
 				}
 				i++;
 			var buffer = new Buffer();
 			renderElem(buffer, view);
 			return buffer.toString();
+
 		} catch (ex) {
 			// handle error with context
-			return onError(ex);
+			var errValue = onError(ex);
+
+			if (errValue instanceof Result) {
+				return render(errValue.value);
+
+			} else {
+				// render the error as a string
+				return (''+errValue);
+			}
 		}
 	}
 
 
 				if (name) {
 					if (type === NUL) {
-						value = '';
-						type = VAL;
+						// null/undefined removes attributes
+						continue;
 					}
 
 					name = ATTR_MAP[name.toLowerCase()] || name;
 						try {
 							elem[name] = value;
 
+							// also set duplicated properties
+							name = ATTR_DUP[name];
+							if (name) {
+								elem[name] = value;
+							}
+
 						} catch(ex2) {
 							if (name.toLowerCase() === 'type' && elem.tagName.toLowerCase() === 'input') {
 								// IE9 doesn't like HTML5 input types
 								continue;
-							} else {
-								throw ex2;
 							}
-						}
 
-						// also set duplicated properties
-						name = ATTR_DUP[name];
-						if (name) {
-							elem[name] = value;
+							throw new Error('DOM property '+elem.tagName+'.'+name+': '+ex2);
 						}
 
 					} else if (ATTR_BOOL[name.toLowerCase()]) {
 	}
 
 	/**
-	 * Renders an error as a text node
-	 * 
-	 * @private
-	 * @param {Error} ex The exception
-	 * @return {Node}
-	 */
-	function onErrorDOM(ex) {
-		return document.createTextNode(onError(ex));
-	}
-
-	/**
 	 * Returns result as DOM objects
 	 * 
 	 * @public
 
 		} catch (ex) {
 			// handle error with context
-			view = onErrorDOM(ex);
+			var errValue = onError(ex);
+
+			if (errValue instanceof Result) {
+				return errValue.toDOM(elem || view);
+
+			} else {
+				// render the error as a text node
+				view = document.createTextNode(''+errValue);
+			}
 		}
 
 		if (elem && elem.parentNode) {

duel-js/target/duel.min.js

 /*
- DUEL v0.8.7 http://duelengine.org
+ DUEL v0.8.8 http://duelengine.org
  Copyright (c)2006-2012 Stephen M. McKamey.
  Licensed under The MIT License.
 */
-var duel=function(n,u,A){function x(a){this.value=a}function l(a){return"function"===typeof a}function k(a){switch(typeof a){case "object":return!a?0:y(a)?2:a instanceof x?5:a instanceof Date?4:3;case "function":return 1;case "undefined":return 0;default:return 4}}function p(){this.value=p.FAST?"":[]}function q(a){y(a)||(a=["",a]);this.value=a}function r(a,b){switch(k(b)){case 2:if(""===b[0])for(var d=1,f=b.length;d<f;d++)r(a,b[d]);else a.push(b);break;case 3:if(1===a.length)a.push(b);else if(d=a[1],
-3===k(d))for(f in b)b.hasOwnProperty(f)&&(d[f]=b[f]);else a.splice(1,0,b);break;case 4:""!==b&&(b=""+b,d=a.length-1,0<d&&4===k(a[d])?a[d]+=b:a.push(b));break;case 0:break;default:a.push(b)}}function s(a,b,d,f,c,e){var g=3===k(a[1]);if(a.length===(g?3:2))return m(a[a.length-1],b,d,f,c,e);for(var h=[""],g=g?2:1,j=a.length;g<j;g++)r(h,m(a[g],b,d,f,c,e));return h}function B(a,b,d,f,c,e){for(var g=1,h=a.length;g<h;g++){var j=a[g],i=j[1].test;if(3===k(j[1])&&i&&(l(i)&&(i=i(b,d,f,c)),!i))continue;return s(j,
-b,d,f,c,e)}return null}function K(a){return"string"!==typeof a?a:a.replace(/[&<>]/g,function(a){switch(a){case "&":return"&amp;";case "<":return"&lt;";case ">":return"&gt;";default:return a}})}function L(a){return"string"!==typeof a?a:a.replace(/[&<>"]/g,function(a){switch(a){case "&":return"&amp;";case "<":return"&lt;";case ">":return"&gt;";case '"':return"&quot;";default:return a}})}function C(a,b){var d=b[0]||"",f=b.length,c=1,e,g=M[d];if("!"===d.charAt(0))"!DOCTYPE"===b[0]?a.append("<!DOCTYPE ",
-b[1],">"):a.append("<\!--",b[1],"--\>");else{if(d){a.append("<",d);e=b[c];if(3===k(e)){for(var h in e)if(e.hasOwnProperty(h)){var j=e[h];if(D[h.toLowerCase()])if(j)j=h;else continue;a.append(" ",h);0!==k(j)&&a.append('="',L(j),'"')}c++}g&&a.append(" /");a.append(">")}for(;c<f;c++)e=b[c],y(e)?C(a,e):a.append(K(e));d&&!g&&a.append("</",d,">")}}function t(a){if(a){if("!"===a.charAt(0))return n.createComment("!"===a?"":a.substr(1)+" ")}else{if(n.createDocumentFragment)return n.createDocumentFragment();
-a=""}return"style"===a.toLowerCase()&&n.createStyleSheet?n.createStyleSheet():n.createElement(a)}function w(a,b){if(b){var d=(a.tagName||"").toLowerCase();if(8===a.nodeType)3===b.nodeType&&(a.nodeValue+=b.nodeValue);else if("table"===d&&a.tBodies)if(b.tagName)if((d=b.tagName.toLowerCase())&&"tbody"!==d&&"thead"!==d){var f=0<a.tBodies.length?a.tBodies[a.tBodies.length-1]:null;f||(f=t("th"===d?"thead":"tbody"),a.appendChild(f));f.appendChild(b)}else!1!==a.canHaveChildren&&a.appendChild(b);else{if(11===
-b.nodeType)for(;b.firstChild;)w(a,b.removeChild(b.firstChild))}else if("style"===d&&n.createStyleSheet)a.cssText=b;else if(!1!==a.canHaveChildren)a.appendChild(b);else if("object"===d&&b.tagName&&"param"===b.tagName.toLowerCase()){try{a.appendChild(b)}catch(c){}try{a.object&&(a.object[b.name]=b.value)}catch(e){}}}}function E(a,b,d){"on"===b.substr(0,2)&&(b=b.substr(2));switch(typeof d){case "function":if(a.addEventListener)a.addEventListener(b,d,!1);else if(l(window.jQuery)&&0!==k(a[b]))if(a=window.jQuery(a),
-l(a.on))a.on(b,d);else a.bind(b,d);else if(a.attachEvent&&0!==k(a[b]))a.attachEvent("on"+b,d);else{var f=a["on"+b]||a[b];a["on"+b]=a[b]=!l(f)?d:function(a){return!1!==f.call(this,a)&&!1!==d.call(this,a)}}break;case "string":a["on"+b]=new Function("event",d)}}function F(a){return!!a&&3===a.nodeType&&(!a.nodeValue||!/\S/.exec(a.nodeValue))}function G(a,b){a&&(3===a.nodeType&&b.exec(a.nodeValue))&&(a.nodeValue=a.nodeValue.replace(b,""))}function z(a){if(a){for(;F(a.firstChild);)a.removeChild(a.firstChild);
-for(G(a.firstChild,N);F(a.lastChild);)a.removeChild(a.lastChild);G(a.lastChild,O)}}function H(a,b){var d=a[b];if(d){try{delete a[b]}catch(f){try{a[b]="",a.removeAttribute(b)}catch(c){}}if(!l(d))try{d=new Function(""+d)}catch(e){d=null}}return d}function I(a){if(a){var b=H(a,"$init");b&&b.call(a);(b=H(a,"$load"))?setTimeout(function(){b.call(a);b=a=null},0):b=a=null}}function J(a,b){for(var d=1,f=b.length;d<f;d++){var c=b[d];switch(k(c)){case 2:var e=c[0],c=J(t(e),c);if("html"===e)return z(c),I(c),
-c;w(a,c);break;case 4:""!==c&&w(a,n.createTextNode(""+c));break;case 3:if(1===a.nodeType){var e=a,g=c;if(g.name&&n.attachEvent&&!e.parentNode)try{var h=t("<"+e.tagName+' name="'+g.name+'">');e.tagName===h.tagName&&(e=h)}catch(j){}c=void 0;for(c in g)if(g.hasOwnProperty(c)){var i=g[c],l=k(i);if(c)if(0===l&&(i="",l=4),c=P[c.toLowerCase()]||c,"style"===c)0!==k(e.style.cssText)?e.style.cssText=i:e.style=i;else if("on"===c.substr(0,2))E(e,c,i),(c=v[c])&&E(e,c,i);else if(!Q[c.toLowerCase()]&&(4!==l||"$"===
-c.charAt(0)||0!==k(e[c])||0!==k(e[v[c]]))){try{e[c]=i}catch(m){if("type"===c.toLowerCase()&&"input"===e.tagName.toLowerCase())continue;else throw m;}(c=v[c])&&(e[c]=i)}else D[c.toLowerCase()]?i&&(e.setAttribute(c,c),(c=v[c])&&e.setAttribute(c,c)):(e.setAttribute(c,i),(c=v[c])&&e.setAttribute(c,i))}a=e}break;case 5:e=w;g=a;i=c;c=t("div");c.innerHTML=""+i;z(c);if(1===c.childNodes.length)c=c.firstChild;else{for(i=t("");c.firstChild;)i.appendChild(c.firstChild);c=i}e(g,c)}}z(a);I(a);11===a.nodeType&&
-1===a.childNodes.length&&(a=a.firstChild);return a}x.prototype.toString=function(){return this.value};var y=Array.isArray||function(a){return a instanceof Array};p.FAST=!(u&&9>u());p.prototype.append=function(a,b,d){p.FAST?null!==a&&(this.value+=a,null!==b&&b!==A&&(this.value+=b,null!==d&&d!==A&&(this.value+=d))):this.value.push.apply(this.value,arguments)};p.prototype.clear=function(){this.value=p.FAST?"":[]};p.prototype.toString=function(){return p.FAST?this.value:this.value.join("")};var m;m=function(a,
-b,d,f,c,e){switch(k(a)){case 1:return a(b,d,f,c);case 2:var g=a[0]||"";switch(g){case "$for":a:{var h=a[1]||{},g=[""],j;if(h.hasOwnProperty("count")){j=h.count;l(j)&&(j=j(b,d,f,c));h.hasOwnProperty("data")?(h=h.data,l(h)&&(h=h(b,d,f,c))):h=b;for(b=0;b<j;b++)r(g,s(a,h,b,j,null,e))}else{if(h.hasOwnProperty("in")){var i=h["in"];l(i)&&(i=i(b,d,f,c));if(3===k(i)){h=[];for(j in i)i.hasOwnProperty(j)&&h.push(j);b=0;for(j=h.length;b<j;b++)r(g,s(a,i[h[b]],b,j,h[b],e));a=g;break a}h=i}else h=h.each,l(h)&&(h=
-h(b,d,f,c));b=k(h);if(2===b){b=0;for(j=h.length;b<j;b++)r(g,s(a,h[b],b,j,null,e))}else 0!==b&&(g=s(a,h,0,1,null,e))}a=g}return a;case "$xor":return B(a,b,d,f,c,e);case "$if":return B(["$xor",a],b,d,f,c,e);case "$call":e=a[1]||{};if(e.view){g=m(e.view,b,d,f,c);h=e.hasOwnProperty("data")?m(e.data,b,d,f,c):b;j=e.hasOwnProperty("index")?m(e.index,b,d,f,c):d;i=e.hasOwnProperty("count")?m(e.count,b,d,f,c):f;b=e.hasOwnProperty("key")?m(e.key,b,d,f,c):c;d={};for(f=a.length-1;2<=f;f--)c=a[f],e=c[1]||{},e.hasOwnProperty("name")&&
-(d[e.name]=c);a=g&&l(g.getView)?m(g.getView(),h,j,i,b,d):null}else a=null;return a;case "$part":return g=(a[1]||{}).name||"",g=e&&e.hasOwnProperty(g)?e[g]:a,s(g,b,d,f,c)}g=[g];h=1;for(j=a.length;h<j;h++)r(g,m(a[h],b,d,f,c,e));return g;case 3:e={};for(g in a)a.hasOwnProperty(g)&&(e[g]=m(a[g],b,d,f,c));return e}return a};var D={async:1,autofocus:1,checked:1,defaultchecked:1,defer:1,disabled:1,formnovalidate:1,hidden:1,indeterminate:1,ismap:1,multiple:1,novalidate:1,readonly:1,required:1,spellcheck:1,
-willvalidate:1},u=function(a){if(!l(a)||!l(a.getView)){var b=a;2!==k(b)&&(b=["",b]);a=function(a,f,c,e){try{var g=m(b,a,isFinite(f)?f:0,isFinite(c)?c:1,"string"===typeof e?e:null);return new q(g)}catch(h){return new q("["+h+"]")}};a.getView=function(){return b}}return a};u.raw=function(a){return new x(a)};var M={area:!0,base:!0,basefont:!0,br:!0,col:!0,frame:!0,hr:!0,img:!0,input:!0,isindex:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,wbr:!0};q.prototype.toString=function(){var a;var b=this.value;
-try{var d=new p;C(d,b);a=d.toString()}catch(f){a="["+f+"]"}return a};q.prototype.write=function(a){(a||n).write(""+this)};var P={accesskey:"accessKey",bgcolor:"bgColor",cellpadding:"cellPadding",cellspacing:"cellSpacing",checked:"defaultChecked","class":"className",colspan:"colSpan",contenteditable:"contentEditable",defaultchecked:"defaultChecked","for":"htmlFor",formnovalidate:"formNoValidate",hidefocus:"hideFocus",ismap:"isMap",maxlength:"maxLength",novalidate:"noValidate",readonly:"readOnly",rowspan:"rowSpan",
-spellcheck:"spellCheck",tabindex:"tabIndex",usemap:"useMap",willvalidate:"willValidate"},v={enctype:"encoding",onscroll:"DOMMouseScroll"},Q={autocapitalize:1,autocomplete:1,autocorrect:1},N=/^[\r\n]+/,O=/[\r\n]+$/;q.prototype.toDOM=function(a,b){4===k(a)&&(a=n.getElementById(a));var d;try{b&&(d=a,a=null),d=J(d||t(this.value[0]),this.value)}catch(f){d=n.createTextNode("["+f+"]")}a&&a.parentNode&&a.parentNode.replaceChild(d,a);return d};q.prototype.reload=function(){var a=n;try{var b=this.toDOM();a.replaceChild(b,
-a.documentElement);if(a.createStyleSheet){for(var d=b.firstChild;d&&"HEAD"!==(d.tagName||"");)d=d.nextSibling;for(var f=d&&d.firstChild;f;){if("LINK"===(f.tagName||""))f.href=f.href;f=f.nextSibling}}}catch(c){a=a.open("text/html"),a.write(this.toString()),a.close()}};return u}(document,window.ScriptEngineMajorVersion);
+var duel=function(n,r,B){function y(a){this.value=a}function l(a){return"function"===typeof a}function k(a){switch(typeof a){case "object":return!a?0:z(a)?2:a instanceof y?5:a instanceof Date?4:3;case "function":return 1;case "undefined":return 0;default:return 4}}function p(){this.value=p.FAST?"":[]}function q(a){z(a)||(a=["",a]);this.value=a}function s(a,b){switch(k(b)){case 2:if(""===b[0])for(var d=1,f=b.length;d<f;d++)s(a,b[d]);else a.push(b);break;case 3:if(1===a.length)a.push(b);else if(d=a[1],
+3===k(d))for(f in b)b.hasOwnProperty(f)&&(d[f]=b[f]);else a.splice(1,0,b);break;case 4:""!==b&&(b=""+b,d=a.length-1,0<d&&4===k(a[d])?a[d]+=b:a.push(b));break;case 0:break;default:a.push(b)}}function t(a,b,d,f,c,e){var g=3===k(a[1]);if(a.length===(g?3:2))return m(a[a.length-1],b,d,f,c,e);for(var h=[""],g=g?2:1,j=a.length;g<j;g++)s(h,m(a[g],b,d,f,c,e));return h}function C(a,b,d,f,c,e){for(var g=1,h=a.length;g<h;g++){var j=a[g],i=j[1].test;if(3===k(j[1])&&i&&(l(i)&&(i=i(b,d,f,c)),!i))continue;return t(j,
+b,d,f,c,e)}return null}function M(a){if("string"!==typeof a)return a;var b={"&":"&amp;","<":"&lt;",">":"&gt;"};return a.replace(/[&<>]/g,function(a){return b[a]||a})}function N(a){if("string"!==typeof a)return a;var b={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};return a.replace(/[&<>"]/g,function(a){return b[a]||a})}function D(a,b){var d=b[0]||"",f=b.length,c=1,e,g=O[d];if("!"===d.charAt(0))"!DOCTYPE"===b[0]?a.append("<!DOCTYPE ",b[1],">"):a.append("<\!--",b[1],"--\>");else{if(d){a.append("<",
+d);e=b[c];if(3===k(e)){for(var h in e)if(e.hasOwnProperty(h)){var j=e[h];if(E[h.toLowerCase()])if(j)j=h;else continue;0!==k(j)&&(a.append(" ",h),a.append('="',N(j),'"'))}c++}g&&a.append(" /");a.append(">")}for(;c<f;c++)e=b[c],z(e)?D(a,e):a.append(M(e));d&&!g&&a.append("</",d,">")}}function F(a){try{var b=new p;D(b,a);return b.toString()}catch(d){return a=w(d),a instanceof q?F(a.value):""+a}}function u(a){if(a){if("!"===a.charAt(0))return n.createComment("!"===a?"":a.substr(1)+" ")}else{if(n.createDocumentFragment)return n.createDocumentFragment();
+a=""}return"style"===a.toLowerCase()&&n.createStyleSheet?n.createStyleSheet():n.createElement(a)}function x(a,b){if(b){var d=(a.tagName||"").toLowerCase();if(8===a.nodeType)3===b.nodeType&&(a.nodeValue+=b.nodeValue);else if("table"===d&&a.tBodies)if(b.tagName)if((d=b.tagName.toLowerCase())&&"tbody"!==d&&"thead"!==d){var f=0<a.tBodies.length?a.tBodies[a.tBodies.length-1]:null;f||(f=u("th"===d?"thead":"tbody"),a.appendChild(f));f.appendChild(b)}else!1!==a.canHaveChildren&&a.appendChild(b);else{if(11===
+b.nodeType)for(;b.firstChild;)x(a,b.removeChild(b.firstChild))}else if("style"===d&&n.createStyleSheet)a.cssText=b;else if(!1!==a.canHaveChildren)a.appendChild(b);else if("object"===d&&b.tagName&&"param"===b.tagName.toLowerCase()){try{a.appendChild(b)}catch(c){}try{a.object&&(a.object[b.name]=b.value)}catch(e){}}}}function G(a,b,d){"on"===b.substr(0,2)&&(b=b.substr(2));switch(typeof d){case "function":if(a.addEventListener)a.addEventListener(b,d,!1);else if(l(window.jQuery)&&0!==k(a[b]))if(a=window.jQuery(a),
+l(a.on))a.on(b,d);else a.bind(b,d);else if(a.attachEvent&&0!==k(a[b]))a.attachEvent("on"+b,d);else{var f=a["on"+b]||a[b];a["on"+b]=a[b]=!l(f)?d:function(a){return!1!==f.call(this,a)&&!1!==d.call(this,a)}}break;case "string":a["on"+b]=new Function("event",d)}}function H(a){return!!a&&3===a.nodeType&&(!a.nodeValue||!/\S/.exec(a.nodeValue))}function I(a,b){a&&(3===a.nodeType&&b.exec(a.nodeValue))&&(a.nodeValue=a.nodeValue.replace(b,""))}function A(a){if(a){for(;H(a.firstChild);)a.removeChild(a.firstChild);
+for(I(a.firstChild,P);H(a.lastChild);)a.removeChild(a.lastChild);I(a.lastChild,Q)}}function J(a,b){var d=a[b];if(d){try{delete a[b]}catch(f){try{a[b]="",a.removeAttribute(b)}catch(c){}}if(!l(d))try{d=new Function(""+d)}catch(e){d=null}}return d}function K(a){if(a){var b=J(a,"$init");b&&b.call(a);(b=J(a,"$load"))?setTimeout(function(){b.call(a);b=a=null},0):b=a=null}}function L(a,b){for(var d=1,f=b.length;d<f;d++){var c=b[d];switch(k(c)){case 2:var e=c[0],c=L(u(e),c);if("html"===e)return A(c),K(c),
+c;x(a,c);break;case 4:""!==c&&x(a,n.createTextNode(""+c));break;case 3:if(1===a.nodeType){var e=a,g=c;if(g.name&&n.attachEvent&&!e.parentNode)try{var h=u("<"+e.tagName+' name="'+g.name+'">');e.tagName===h.tagName&&(e=h)}catch(j){}c=void 0;for(c in g)if(g.hasOwnProperty(c)){var i=g[c],l=k(i);if(c&&0!==l)if(c=R[c.toLowerCase()]||c,"style"===c)0!==k(e.style.cssText)?e.style.cssText=i:e.style=i;else if("on"===c.substr(0,2))G(e,c,i),(c=v[c])&&G(e,c,i);else if(!S[c.toLowerCase()]&&(4!==l||"$"===c.charAt(0)||
+0!==k(e[c])||0!==k(e[v[c]])))try{e[c]=i,(c=v[c])&&(e[c]=i)}catch(m){if(!("type"===c.toLowerCase()&&"input"===e.tagName.toLowerCase()))throw Error("DOM property "+e.tagName+"."+c+": "+m);}else E[c.toLowerCase()]?i&&(e.setAttribute(c,c),(c=v[c])&&e.setAttribute(c,c)):(e.setAttribute(c,i),(c=v[c])&&e.setAttribute(c,i))}a=e}break;case 5:e=x;g=a;i=c;c=u("div");c.innerHTML=""+i;A(c);if(1===c.childNodes.length)c=c.firstChild;else{for(i=u("");c.firstChild;)i.appendChild(c.firstChild);c=i}e(g,c)}}A(a);K(a);
+11===a.nodeType&&1===a.childNodes.length&&(a=a.firstChild);return a}y.prototype.toString=function(){return this.value};var z=Array.isArray||function(a){return a instanceof Array};p.FAST=!(r&&9>r());p.prototype.append=function(a,b,d){p.FAST?null!==a&&(this.value+=a,null!==b&&b!==B&&(this.value+=b,null!==d&&d!==B&&(this.value+=d))):this.value.push.apply(this.value,arguments)};p.prototype.clear=function(){this.value=p.FAST?"":[]};p.prototype.toString=function(){return p.FAST?this.value:this.value.join("")};
+var m;m=function(a,b,d,f,c,e){switch(k(a)){case 1:return a(b,d,f,c);case 2:var g=a[0]||"";switch(g){case "$for":a:{var h=a[1]||{},g=[""],j;if(h.hasOwnProperty("count")){j=h.count;l(j)&&(j=j(b,d,f,c));h.hasOwnProperty("data")?(h=h.data,l(h)&&(h=h(b,d,f,c))):h=b;for(b=0;b<j;b++)s(g,t(a,h,b,j,null,e))}else{if(h.hasOwnProperty("in")){var i=h["in"];l(i)&&(i=i(b,d,f,c));if(3===k(i)){h=[];for(j in i)i.hasOwnProperty(j)&&h.push(j);b=0;for(j=h.length;b<j;b++)s(g,t(a,i[h[b]],b,j,h[b],e));a=g;break a}h=i}else h=
+h.each,l(h)&&(h=h(b,d,f,c));b=k(h);if(2===b){b=0;for(j=h.length;b<j;b++)s(g,t(a,h[b],b,j,null,e))}else 0!==b&&(g=t(a,h,0,1,null,e))}a=g}return a;case "$xor":return C(a,b,d,f,c,e);case "$if":return C(["$xor",a],b,d,f,c,e);case "$call":e=a[1]||{};if(e.view){g=m(e.view,b,d,f,c);h=e.hasOwnProperty("data")?m(e.data,b,d,f,c):b;j=e.hasOwnProperty("index")?m(e.index,b,d,f,c):d;i=e.hasOwnProperty("count")?m(e.count,b,d,f,c):f;b=e.hasOwnProperty("key")?m(e.key,b,d,f,c):c;d={};for(f=a.length-1;2<=f;f--)c=a[f],
+e=c[1]||{},e.hasOwnProperty("name")&&(d[e.name]=c);a=g&&l(g.getView)?m(g.getView(),h,j,i,b,d):null}else a=null;return a;case "$part":return g=(a[1]||{}).name||"",g=e&&e.hasOwnProperty(g)?e[g]:a,t(g,b,d,f,c)}g=[g];h=1;for(j=a.length;h<j;h++)s(g,m(a[h],b,d,f,c,e));return g;case 3:e={};for(g in a)a.hasOwnProperty(g)&&(e[g]=m(a[g],b,d,f,c));return e}return a};var E={async:1,autofocus:1,checked:1,defaultchecked:1,defer:1,disabled:1,formnovalidate:1,hidden:1,indeterminate:1,ismap:1,multiple:1,novalidate:1,
+readonly:1,required:1,spellcheck:1,willvalidate:1},w=function(a){return"[ "+a+" ]"},r=function(a){if(!l(a)||!l(a.getView)){var b=a;2!==k(b)&&(b=["",b]);a=function(a,f,c,e){try{var g=m(b,a,isFinite(f)?f:0,isFinite(c)?c:1,"string"===typeof e?e:null);return new q(g)}catch(h){return a=w(h),a instanceof q?a:new q(""+a)}};a.getView=function(){return b}}return a};r.onerror=function(a){l(a)&&(w=a)};r.raw=function(a){return new y(a)};var O={area:!0,base:!0,basefont:!0,br:!0,col:!0,frame:!0,hr:!0,img:!0,input:!0,
+isindex:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,wbr:!0};q.prototype.toString=function(){return F(this.value)};q.prototype.write=function(a){(a||n).write(""+this)};var R={accesskey:"accessKey",bgcolor:"bgColor",cellpadding:"cellPadding",cellspacing:"cellSpacing",checked:"defaultChecked","class":"className",colspan:"colSpan",contenteditable:"contentEditable",defaultchecked:"defaultChecked","for":"htmlFor",formnovalidate:"formNoValidate",hidefocus:"hideFocus",ismap:"isMap",maxlength:"maxLength",
+novalidate:"noValidate",readonly:"readOnly",rowspan:"rowSpan",spellcheck:"spellCheck",tabindex:"tabIndex",usemap:"useMap",willvalidate:"willValidate"},v={enctype:"encoding",onscroll:"DOMMouseScroll"},S={autocapitalize:1,autocomplete:1,autocorrect:1},P=/^[\r\n]+/,Q=/[\r\n]+$/;q.prototype.toDOM=function(a,b){4===k(a)&&(a=n.getElementById(a));var d;try{b&&(d=a,a=null),d=L(d||u(this.value[0]),this.value)}catch(f){var c=w(f);if(c instanceof q)return c.toDOM(a||d);d=n.createTextNode(""+c)}a&&a.parentNode&&
+a.parentNode.replaceChild(d,a);return d};q.prototype.reload=function(){var a=n;try{var b=this.toDOM();a.replaceChild(b,a.documentElement);if(a.createStyleSheet){for(var d=b.firstChild;d&&"HEAD"!==(d.tagName||"");)d=d.nextSibling;for(var f=d&&d.firstChild;f;){if("LINK"===(f.tagName||""))f.href=f.href;f=f.nextSibling}}}catch(c){a=a.open("text/html"),a.write(this.toString()),a.close()}};return r}(document,window.ScriptEngineMajorVersion);