Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

JSHint tweaks

  • Loading branch information...
commit ef7022e207493353351139c7676ec4f1b7d1e65e 1 parent 0d2a853
@mckamey authored
Showing with 262 additions and 255 deletions.
  1. +165 −160 jsonml-dom.js
  2. +30 −29 jsonml-jbst.js
  3. +67 −66 jsonml2.js
View
325 jsonml-dom.js
@@ -11,192 +11,197 @@
var JsonML = JsonML || {};
-/*JsonML*/ JsonML.parseDOM = function(/*DOM*/ elem, /*function*/ filter) {
- if (!elem || !elem.nodeType) {
- // free references
- return (elem = null);
- }
-
- function addChildren(/*DOM*/ elem, /*function*/ filter, /*JsonML*/ jml) {
- if (elem.hasChildNodes()) {
- for (var i=0; i<elem.childNodes.length; i++) {
- var child = elem.childNodes[i];
- child = JsonML.parseDOM(child, filter);
- if (child) {
- jml.push(child);
- }
- }
- return true;
+(function(JsonML){
+ 'use strict';
+
+ /*JsonML*/ JsonML.parseDOM = function(/*DOM*/ elem, /*function*/ filter) {
+ if (!elem || !elem.nodeType) {
+ // free references
+ return (elem = null);
}
- return false;
- }
-
- var i, jml;
- switch (elem.nodeType) {
- case 1: // element
- case 9: // document
- case 11: // documentFragment
- jml = [elem.tagName||""];
-
- var attr = elem.attributes,
- props = {},
- hasAttrib = false;
-
- for (i=0; attr && i<attr.length; i++) {
- if (attr[i].specified) {
- if (attr[i].name === "style") {
- props.style = elem.style.cssText || attr[i].value;
- } else if ("string" === typeof attr[i].value) {
- props[attr[i].name] = attr[i].value;
+
+ function addChildren(/*DOM*/ elem, /*function*/ filter, /*JsonML*/ jml) {
+ if (elem.hasChildNodes()) {
+ for (var i=0; i<elem.childNodes.length; i++) {
+ var child = elem.childNodes[i];
+ child = JsonML.parseDOM(child, filter);
+ if (child) {
+ jml.push(child);
}
- hasAttrib = true;
}
+ return true;
}
- if (hasAttrib) {
- jml.push(props);
- }
+ return false;
+ }
- var child;
- switch (jml[0].toLowerCase()) {
- case "frame":
- case "iframe":
- try {
- if ("undefined" !== typeof elem.contentDocument) {
- // W3C
- child = elem.contentDocument;
- } else if ("undefined" !== typeof elem.contentWindow) {
- // Microsoft
- child = elem.contentWindow.document;
- } else if ("undefined" !== typeof elem.document) {
- // deprecated
- child = elem.document;
+ var i, jml;
+ switch (elem.nodeType) {
+ case 1: // element
+ case 9: // document
+ case 11: // documentFragment
+ jml = [elem.tagName||''];
+
+ var attr = elem.attributes,
+ props = {},
+ hasAttrib = false;
+
+ for (i=0; attr && i<attr.length; i++) {
+ if (attr[i].specified) {
+ if (attr[i].name === 'style') {
+ props.style = elem.style.cssText || attr[i].value;
+ } else if ('string' === typeof attr[i].value) {
+ props[attr[i].name] = attr[i].value;
}
+ hasAttrib = true;
+ }
+ }
+ if (hasAttrib) {
+ jml.push(props);
+ }
- child = JsonML.parseDOM(child, filter);
- if (child) {
- jml.push(child);
- }
- } catch (ex) {}
- break;
- case "style":
- child = elem.styleSheet && elem.styleSheet.cssText;
- if (child && "string" === typeof child) {
- // unwrap comment blocks
- child = child.replace("<!--", "").replace("-->", "");
- jml.push(child);
- } else if (elem.hasChildNodes()) {
- for (i=0; i<elem.childNodes.length; i++) {
- child = elem.childNodes[i];
+ var child;
+ switch (jml[0].toLowerCase()) {
+ case 'frame':
+ case 'iframe':
+ try {
+ if ('undefined' !== typeof elem.contentDocument) {
+ // W3C
+ child = elem.contentDocument;
+ } else if ('undefined' !== typeof elem.contentWindow) {
+ // Microsoft
+ child = elem.contentWindow.document;
+ } else if ('undefined' !== typeof elem.document) {
+ // deprecated
+ child = elem.document;
+ }
+
child = JsonML.parseDOM(child, filter);
- if (child && "string" === typeof child) {
- // unwrap comment blocks
- child = child.replace("<!--", "").replace("-->", "");
+ if (child) {
jml.push(child);
}
+ } catch (ex) {}
+ break;
+ case 'style':
+ child = elem.styleSheet && elem.styleSheet.cssText;
+ if (child && 'string' === typeof child) {
+ // unwrap comment blocks
+ child = child.replace('<!--', '').replace('-->', '');
+ jml.push(child);
+ } else if (elem.hasChildNodes()) {
+ for (i=0; i<elem.childNodes.length; i++) {
+ child = elem.childNodes[i];
+ child = JsonML.parseDOM(child, filter);
+ if (child && 'string' === typeof child) {
+ // unwrap comment blocks
+ child = child.replace('<!--', '').replace('-->', '');
+ jml.push(child);
+ }
+ }
}
- }
- break;
- case "input":
- addChildren(elem, filter, jml);
- child = (elem.type !== "password") && elem.value;
- if (child) {
- if (!hasAttrib) {
- // need to add an attribute object
- jml.shift();
- props = {};
- jml.unshift(props);
- jml.unshift(elem.tagName||"");
+ break;
+ case 'input':
+ addChildren(elem, filter, jml);
+ child = (elem.type !== 'password') && elem.value;
+ if (child) {
+ if (!hasAttrib) {
+ // need to add an attribute object
+ jml.shift();
+ props = {};
+ jml.unshift(props);
+ jml.unshift(elem.tagName||'');
+ }
+ props.value = child;
}
- props.value = child;
- }
- break;
- case "textarea":
- if (!addChildren(elem, filter, jml)) {
- child = elem.value || elem.innerHTML;
- if (child && "string" === typeof child) {
- jml.push(child);
+ break;
+ case 'textarea':
+ if (!addChildren(elem, filter, jml)) {
+ child = elem.value || elem.innerHTML;
+ if (child && 'string' === typeof child) {
+ jml.push(child);
+ }
}
- }
- break;
- default:
- addChildren(elem, filter, jml);
- break;
- }
-
- // filter result
- if ("function" === typeof filter) {
- jml = filter(jml, elem);
- }
+ break;
+ default:
+ addChildren(elem, filter, jml);
+ break;
+ }
- // free references
- elem = null;
- return jml;
- case 3: // text node
- case 4: // CDATA node
- var str = String(elem.nodeValue);
- // free references
- elem = null;
- return str;
- case 10: // doctype
- jml = ["!"];
+ // filter result
+ if ('function' === typeof filter) {
+ jml = filter(jml, elem);
+ }
- var type = ["DOCTYPE", (elem.name || "html").toLowerCase()];
+ // free references
+ elem = null;
+ return jml;
+ case 3: // text node
+ case 4: // CDATA node
+ var str = String(elem.nodeValue);
+ // free references
+ elem = null;
+ return str;
+ case 10: // doctype
+ jml = ['!'];
- if (elem.publicId) {
- type.push("PUBLIC", '"' + elem.publicId + '"');
- }
+ var type = ['DOCTYPE', (elem.name || 'html').toLowerCase()];
- if (elem.systemId) {
- type.push('"' + elem.systemId + '"');
- }
+ if (elem.publicId) {
+ type.push('PUBLIC', '"' + elem.publicId + '"');
+ }
- jml.push(type.join(" "));
+ if (elem.systemId) {
+ type.push('"' + elem.systemId + '"');
+ }
- // filter result
- if ("function" === typeof filter) {
- jml = filter(jml, elem);
- }
+ jml.push(type.join(' '));
+
+ // filter result
+ if ('function' === typeof filter) {
+ jml = filter(jml, elem);
+ }
- // free references
- elem = null;
- return jml;
- case 8: // comment node
- if ((elem.nodeValue||"").indexOf("DOCTYPE") !== 0) {
// free references
elem = null;
- return null;
- }
+ return jml;
+ case 8: // comment node
+ if ((elem.nodeValue||'').indexOf('DOCTYPE') !== 0) {
+ // free references
+ elem = null;
+ return null;
+ }
- jml = ["!",
- elem.nodeValue];
+ jml = ['!',
+ elem.nodeValue];
- // filter result
- if ("function" === typeof filter) {
- jml = filter(jml, elem);
- }
+ // filter result
+ if ('function' === typeof filter) {
+ jml = filter(jml, elem);
+ }
- // free references
- elem = null;
- return jml;
- default: // etc.
- // free references
- return (elem = null);
- }
-};
+ // free references
+ elem = null;
+ return jml;
+ default: // etc.
+ // free references
+ return (elem = null);
+ }
+ };
-/*JsonML*/ JsonML.parseHTML = function(/*string*/ html, /*function*/ filter) {
- var elem = document.createElement("div");
- elem.innerHTML = html;
- var jml = JsonML.parseDOM(elem, filter);
+ /*JsonML*/ JsonML.parseHTML = function(/*string*/ html, /*function*/ filter) {
+ var elem = document.createElement('div');
+ elem.innerHTML = html;
+ var jml = JsonML.parseDOM(elem, filter);
- // free references
- elem = null;
+ // free references
+ elem = null;
+
+ if (jml.length === 2) {
+ return jml[1];
+ }
- if (jml.length === 2) {
- return jml[1];
- }
+ // make wrapper a document fragment
+ jml[0] = '';
+ return jml;
+ };
- // make wrapper a document fragment
- jml[0] = "";
- return jml;
-};
+})(JsonML);
View
59 jsonml-jbst.js
@@ -29,7 +29,7 @@
JsonML.BST.onerror = function(ex) {
// access the current context via this.data, this.index, etc.
// display custom inline error messages
- return "["+ex+"]";
+ return '['+ex+']';
};
// implement onbound event to perform custom processing of elements after binding
@@ -46,7 +46,7 @@
// access the current context via this.data, this.index, etc.
// watch elements as they are added
if (window.console) {
- console.log(JsonML.getTagName(parent)+" > "+JsonML.getTagName(child));
+ console.log(JsonML.getTagName(parent)+' > '+JsonML.getTagName(child));
}
};
*/
@@ -55,10 +55,11 @@
var JsonML = JsonML || {};
JsonML.BST = (function(){
+ 'use strict';
- var SHOW = "jbst:visible",
- INIT = "jbst:oninit",
- LOAD = "jbst:onload";
+ var SHOW = 'jbst:visible',
+ INIT = 'jbst:oninit',
+ LOAD = 'jbst:onload';
// ensures attribute key contains method or is removed
// attr: attribute object
@@ -67,7 +68,7 @@ JsonML.BST = (function(){
var method = attr[key] || null;
if (method) {
// ensure is method
- if ("function" !== typeof method) {
+ if ('function' !== typeof method) {
try {
/*jslint evil:true */
method = new Function(String(method));
@@ -88,7 +89,7 @@ JsonML.BST = (function(){
// default onerror handler, override JsonML.BST.onerror to change
/*JsonML*/ function onError(/*Error*/ ex) {
- return "["+ex+"]";
+ return '['+ex+']';
}
// retrieve and remove method
@@ -113,14 +114,14 @@ JsonML.BST = (function(){
// execute and remove jbst:oninit method
var method = popMethod(elem, INIT);
- if ("function" === typeof method) {
+ if ('function' === typeof method) {
// execute in context of element
method.call(elem);
}
// execute and remove jbst:onload method
method = popMethod(elem, LOAD);
- if ("function" === typeof method) {
+ if ('function' === typeof method) {
// queue up to execute after insertion into parentNode
setTimeout(function() {
// execute in context of element
@@ -147,12 +148,12 @@ JsonML.BST = (function(){
try {
// setup context for code block
- self.data = ("undefined" !== typeof data) ? data : null;
+ self.data = ('undefined' !== typeof data) ? data : null;
self.index = isFinite(index) ? Number(index) : NaN;
self.count = isFinite(count) ? Number(count) : NaN;
- self.args = ("undefined" !== typeof args) ? args : null;
+ self.args = ('undefined' !== typeof args) ? args : null;
- // execute node in the context of self as "this", passing in any parameters
+ // execute node in the context of self as 'this', passing in any parameters
return method.apply(self, methodArgs || []);
} finally {
@@ -166,8 +167,8 @@ JsonML.BST = (function(){
/* ctor */
function JBST(/*JsonML*/ jbst) {
- if ("undefined" === typeof jbst) {
- throw new Error("JBST tree is undefined");
+ if ('undefined' === typeof jbst) {
+ throw new Error('JBST tree is undefined');
}
var self = this,
@@ -188,12 +189,12 @@ JsonML.BST = (function(){
if (node) {
var output;
- if ("function" === typeof node) {
+ if ('function' === typeof node) {
output = callContext(self, data, index, count, args, node);
if (output instanceof JBST) {
// allow returned JBSTs to recursively bind
- // useful for creating "switcher" template methods
+ // useful for creating 'switcher' template methods
return output.dataBind(data, index, count, args);
}
@@ -202,8 +203,8 @@ JsonML.BST = (function(){
}
if (node instanceof Array) {
- var onBound = ("function" === typeof JsonML.BST.onbound) && JsonML.BST.onbound,
- onAppend = ("function" === typeof JsonML.BST.onappend) && JsonML.BST.onappend,
+ var onBound = ('function' === typeof JsonML.BST.onbound) && JsonML.BST.onbound,
+ onAppend = ('function' === typeof JsonML.BST.onappend) && JsonML.BST.onappend,
appendCB = onAppend && function(parent, child) {
callContext(self, data, index, count, args, onAppend, [parent, child]);
};
@@ -227,11 +228,11 @@ JsonML.BST = (function(){
if (JsonML.hasAttributes(output)) {
// visibility JBST command
var visible = output[1][SHOW];
- if ("undefined" !== typeof visible) {
+ if ('undefined' !== typeof visible) {
// cull any false-y values
if (!visible) {
// suppress rendering of entire subtree
- return "";
+ return '';
}
// remove attribute
delete output[1][SHOW];
@@ -248,14 +249,14 @@ JsonML.BST = (function(){
return output;
}
- if ("object" === typeof node) {
+ if ('object' === typeof node) {
output = {};
// process each property in template node
for (var property in node) {
if (node.hasOwnProperty(property)) {
// evaluate property's value
var value = dataBind(node[property], data, index, count, args);
- if ("undefined" !== typeof value && value !== null) {
+ if ('undefined' !== typeof value && value !== null) {
output[property] = value;
}
}
@@ -270,10 +271,10 @@ JsonML.BST = (function(){
} catch (ex) {
try {
// handle error with complete context
- var err = ("function" === typeof JsonML.BST.onerror) ? JsonML.BST.onerror : onError;
+ var err = ('function' === typeof JsonML.BST.onerror) ? JsonML.BST.onerror : onError;
return callContext(self, data, index, count, args, err, [ex]);
} catch (ex2) {
- return "["+ex2+"]";
+ return '['+ex2+']';
}
}
}
@@ -281,7 +282,7 @@ JsonML.BST = (function(){
/*JsonML*/ function iterate(/*JsonML*/ node, /*object*/ data, /*int*/ index, /*int*/ count, /*object*/ args) {
if (data instanceof Array) {
// create a document fragment to hold list
- var output = [""];
+ var output = [''];
count = data.length;
for (var i=0; i<count; i++) {
@@ -316,7 +317,7 @@ JsonML.BST = (function(){
// replaces a DOM element with result from binding
/*void*/ self.replace = function(/*DOM*/ elem, /*object*/ data, /*int*/ index, /*int*/ count, /*object*/ args) {
- if ("string" === typeof elem) {
+ if ('string' === typeof elem) {
elem = document.getElementById(elem);
}
@@ -330,7 +331,7 @@ JsonML.BST = (function(){
// displace a DOM element with result from binding JsonML+BST node bound within this context
/*void*/ self.displace = function(/*DOM*/ elem, /*JsonML*/ node, /*object*/ data, /*int*/ index, /*int*/ count, /*object*/ args) {
- if ("string" === typeof elem) {
+ if ('string' === typeof elem) {
elem = document.getElementById(elem);
}
@@ -348,12 +349,12 @@ JsonML.BST = (function(){
// patches a DOM element with JsonML+BST node bound within this context
/*void*/ self.patch = function(/*DOM*/ elem, /*JsonML*/ node, /*object*/ data, /*int*/ index, /*int*/ count, /*object*/ args) {
- if ("string" === typeof elem) {
+ if ('string' === typeof elem) {
elem = document.getElementById(elem);
}
if (elem) {
- var jml = [""];
+ var jml = [''];
appendChild(jml, dataBind(node, data, index, count, args));
JsonML.patch(elem, jml, filter);
}
View
133 jsonml2.js
@@ -32,19 +32,19 @@
// handlers, or bind to a custom component.
var myUI = JsonML.parse(myUITemplate, function (elem) {
- if (elem.className.indexOf("Remove-Me") >= 0) {
+ if (elem.className.indexOf('Remove-Me') >= 0) {
// this will remove from resulting DOM tree
return null;
}
- if (elem.tagName && elem.tagName.toLowerCase() === "a" &&
- elem.className.indexOf("External-Link") >= 0) {
- // this is the equivalent of target="_blank"
+ if (elem.tagName && elem.tagName.toLowerCase() === 'a' &&
+ elem.className.indexOf('External-Link') >= 0) {
+ // this is the equivalent of target='_blank'
elem.onclick = function(evt) {
window.open(elem.href); return false;
};
- } else if (elem.className.indexOf("Fancy-Widgit") >= 0) {
+ } else if (elem.className.indexOf('Fancy-Widgit') >= 0) {
// bind to a custom component
FancyWidgit.bindDOM(elem);
}
@@ -54,7 +54,7 @@
// Implement onerror to handle any runtime errors while binding:
JsonML.onerror = function (ex, jml, filter) {
// display inline error message
- return document.createTextNode("["+ex+"]");
+ return document.createTextNode('['+ex+']');
};
Utility methods for manipulating JsonML elements:
@@ -92,28 +92,29 @@
var JsonML = JsonML || {};
-(function() {
+(function(JsonML) {
+ 'use strict';
//attribute name mapping
var ATTRMAP = {
- rowspan : "rowSpan",
- colspan : "colSpan",
- cellpadding : "cellPadding",
- cellspacing : "cellSpacing",
- tabindex : "tabIndex",
- accesskey : "accessKey",
- hidefocus : "hideFocus",
- usemap : "useMap",
- maxlength : "maxLength",
- readonly : "readOnly",
- contenteditable : "contentEditable"
+ rowspan : 'rowSpan',
+ colspan : 'colSpan',
+ cellpadding : 'cellPadding',
+ cellspacing : 'cellSpacing',
+ tabindex : 'tabIndex',
+ accesskey : 'accessKey',
+ hidefocus : 'hideFocus',
+ usemap : 'useMap',
+ maxlength : 'maxLength',
+ readonly : 'readOnly',
+ contenteditable : 'contentEditable'
// can add more attributes here as needed
},
// attribute duplicates
ATTRDUP = {
- enctype : "encoding",
- onscroll : "DOMMouseScroll"
+ enctype : 'encoding',
+ onscroll : 'DOMMouseScroll'
// can add more attributes here as needed
},
@@ -122,19 +123,19 @@ var JsonML = JsonML || {};
var evts = {};
while (names.length) {
var evt = names.shift();
- evts["on"+evt.toLowerCase()] = evt;
+ evts['on'+evt.toLowerCase()] = evt;
}
return evts;
- })("blur,change,click,dblclick,error,focus,keydown,keypress,keyup,load,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,resize,scroll,select,submit,unload".split(','));
+ })('blur,change,click,dblclick,error,focus,keydown,keypress,keyup,load,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,resize,scroll,select,submit,unload'.split(','));
/*void*/ function addHandler(/*DOM*/ elem, /*string*/ name, /*function*/ handler) {
- if ("string" === typeof handler) {
+ if ('string' === typeof handler) {
/*jslint evil:true */
- handler = new Function("event", handler);
+ handler = new Function('event', handler);
/*jslint evil:false */
}
- if ("function" !== typeof handler) {
+ if ('function' !== typeof handler) {
return;
}
@@ -145,7 +146,7 @@ var JsonML = JsonML || {};
if (attr.name && document.attachEvent) {
try {
// IE fix for not being able to programatically change the name attribute
- var alt = document.createElement("<"+elem.tagName+" name='"+attr.name+"'>");
+ var alt = document.createElement('<'+elem.tagName+' name="'+attr.name+'">');
// fix for Opera 8.5 and Netscape 7.1 creating malformed elements
if (elem.tagName === alt.tagName) {
elem = alt;
@@ -158,15 +159,15 @@ var JsonML = JsonML || {};
if (attr.hasOwnProperty(name)) {
// attributeValue
var value = attr[name];
- if (name && value !== null && "undefined" !== typeof value) {
+ if (name && value !== null && 'undefined' !== typeof value) {
name = ATTRMAP[name.toLowerCase()] || name;
- if (name === "style") {
- if ("undefined" !== typeof elem.style.cssText) {
+ if (name === 'style') {
+ if ('undefined' !== typeof elem.style.cssText) {
elem.style.cssText = value;
} else {
elem.style = value;
}
- } else if (name === "class") {
+ } else if (name === 'class') {
elem.className = value;
} else if (EVTS[name]) {
addHandler(elem, name, value);
@@ -175,7 +176,7 @@ var JsonML = JsonML || {};
if (ATTRDUP[name]) {
addHandler(elem, ATTRDUP[name], value);
}
- } else if ("string" === typeof value || "number" === typeof value || "boolean" === typeof value) {
+ } else if ('string' === typeof value || 'number' === typeof value || 'boolean' === typeof value) {
elem.setAttribute(name, value);
// also set duplicated attributes
@@ -200,7 +201,7 @@ var JsonML = JsonML || {};
/*void*/ function appendChild(/*DOM*/ elem, /*DOM*/ child) {
if (child) {
- if (elem.tagName && elem.tagName.toLowerCase() === "table" && elem.tBodies) {
+ if (elem.tagName && elem.tagName.toLowerCase() === 'table' && elem.tBodies) {
if (!child.tagName) {
// must unwrap documentFragment for tables
if (child.nodeType === 11) {
@@ -212,24 +213,24 @@ var JsonML = JsonML || {};
}
// in IE must explicitly nest TRs in TBODY
var childTag = child.tagName.toLowerCase();// child tagName
- if (childTag && childTag !== "tbody" && childTag !== "thead") {
+ if (childTag && childTag !== 'tbody' && childTag !== 'thead') {
// insert in last tbody
var tBody = elem.tBodies.length > 0 ? elem.tBodies[elem.tBodies.length-1] : null;
if (!tBody) {
- tBody = document.createElement(childTag === "th" ? "thead" : "tbody");
+ tBody = document.createElement(childTag === 'th' ? 'thead' : 'tbody');
elem.appendChild(tBody);
}
tBody.appendChild(child);
} else if (elem.canHaveChildren !== false) {
elem.appendChild(child);
}
- } else if (elem.tagName && elem.tagName.toLowerCase() === "style" && document.createStyleSheet) {
+ } else if (elem.tagName && elem.tagName.toLowerCase() === 'style' && document.createStyleSheet) {
// IE requires this interface for styles
elem.cssText = child;
} else if (elem.canHaveChildren !== false) {
elem.appendChild(child);
- } else if (elem.tagName && elem.tagName.toLowerCase() === "object" &&
- child.tagName && child.tagName.toLowerCase() === "param") {
+ } else if (elem.tagName && elem.tagName.toLowerCase() === 'object' &&
+ child.tagName && child.tagName.toLowerCase() === 'param') {
// IE-only path
try {
elem.appendChild(child);
@@ -261,7 +262,7 @@ var JsonML = JsonML || {};
}
/*DOM*/ function hydrate(/*string*/ value) {
- var wrapper = document.createElement("div");
+ var wrapper = document.createElement('div');
wrapper.innerHTML = value;
// trim extraneous whitespace
@@ -275,7 +276,7 @@ var JsonML = JsonML || {};
// create a document fragment to hold elements
var frag = document.createDocumentFragment ?
document.createDocumentFragment() :
- document.createElement("");
+ document.createElement('');
while (wrapper.firstChild) {
frag.appendChild(wrapper.firstChild);
@@ -293,7 +294,7 @@ var JsonML = JsonML || {};
// default error handler
/*DOM*/ function onError(/*Error*/ ex, /*JsonML*/ jml, /*function*/ filter) {
- return document.createTextNode("["+ex+"]");
+ return document.createTextNode('['+ex+']');
}
/* override this to perform custom error handling during binding */
@@ -302,12 +303,12 @@ var JsonML = JsonML || {};
/*DOM*/ function patch(/*DOM*/ elem, /*JsonML*/ jml, /*function*/ filter) {
for (var i=1; i<jml.length; i++) {
- if (jml[i] instanceof Array || "string" === typeof jml[i]) {
+ if (jml[i] instanceof Array || 'string' === typeof jml[i]) {
// append children
appendChild(elem, JsonML.parse(jml[i], filter));
} else if (jml[i] instanceof Unparsed) {
appendChild(elem, hydrate(jml[i].value));
- } else if ("object" === typeof jml[i] && jml[i] !== null && elem.nodeType === 1) {
+ } else if ('object' === typeof jml[i] && jml[i] !== null && elem.nodeType === 1) {
// add attributes
elem = addAttributes(elem, jml[i]);
}
@@ -321,14 +322,14 @@ var JsonML = JsonML || {};
if (!jml) {
return null;
}
- if ("string" === typeof jml) {
+ if ('string' === typeof jml) {
return document.createTextNode(jml);
}
if (jml instanceof Unparsed) {
return hydrate(jml.value);
}
if (!JsonML.isElement(jml)) {
- throw new SyntaxError("invalid JsonML");
+ throw new SyntaxError('invalid JsonML');
}
var tagName = jml[0]; // tagName
@@ -337,7 +338,7 @@ var JsonML = JsonML || {};
// create a document fragment to hold elements
var frag = document.createDocumentFragment ?
document.createDocumentFragment() :
- document.createElement("");
+ document.createElement('');
for (var i=1; i<jml.length; i++) {
appendChild(frag, JsonML.parse(jml[i], filter));
}
@@ -352,7 +353,7 @@ var JsonML = JsonML || {};
return frag;
}
- if (tagName.toLowerCase() === "style" && document.createStyleSheet) {
+ if (tagName.toLowerCase() === 'style' && document.createStyleSheet) {
// IE requires this interface for styles
JsonML.patch(document.createStyleSheet(), jml, filter);
// in IE styles are effective immediately
@@ -363,14 +364,14 @@ var JsonML = JsonML || {};
// trim extraneous whitespace
trimWhitespace(elem);
- return (elem && "function" === typeof filter) ? filter(elem) : elem;
+ return (elem && 'function' === typeof filter) ? filter(elem) : elem;
} catch (ex) {
try {
// handle error with complete context
- var err = ("function" === typeof JsonML.onerror) ? JsonML.onerror : onError;
+ var err = ('function' === typeof JsonML.onerror) ? JsonML.onerror : onError;
return err(ex, jml, filter);
} catch (ex2) {
- return document.createTextNode("["+ex2+"]");
+ return document.createTextNode('['+ex2+']');
}
}
};
@@ -383,24 +384,24 @@ var JsonML = JsonML || {};
/* Utility Methods -------------------------*/
/*bool*/ JsonML.isElement = function(/*JsonML*/ jml) {
- return (jml instanceof Array) && ("string" === typeof jml[0]);
+ return (jml instanceof Array) && ('string' === typeof jml[0]);
};
/*bool*/ JsonML.isFragment = function(/*JsonML*/ jml) {
- return (jml instanceof Array) && (jml[0] === "");
+ return (jml instanceof Array) && (jml[0] === '');
};
/*string*/ JsonML.getTagName = function(/*JsonML*/ jml) {
- return jml[0] || "";
+ return jml[0] || '';
};
/*bool*/ JsonML.isAttributes = function(/*JsonML*/ jml) {
- return !!jml && ("object" === typeof jml) && !(jml instanceof Array);
+ return !!jml && ('object' === typeof jml) && !(jml instanceof Array);
};
/*bool*/ JsonML.hasAttributes = function(/*JsonML*/ jml) {
if (!JsonML.isElement(jml)) {
- throw new SyntaxError("invalid JsonML");
+ throw new SyntaxError('invalid JsonML');
}
return JsonML.isAttributes(jml[1]);
@@ -419,20 +420,20 @@ var JsonML = JsonML || {};
var name = jml.shift();
var attr = {};
jml.unshift(attr);
- jml.unshift(name||"");
+ jml.unshift(name||'');
return attr;
};
/*void*/ JsonML.addAttributes = function(/*JsonML*/ jml, /*object*/ attr) {
if (!JsonML.isElement(jml) || !JsonML.isAttributes(attr)) {
- throw new SyntaxError("invalid JsonML");
+ throw new SyntaxError('invalid JsonML');
}
if (!JsonML.isAttributes(jml[1])) {
// just insert attributes
var name = jml.shift();
jml.unshift(attr);
- jml.unshift(name||"");
+ jml.unshift(name||'');
return;
}
@@ -457,7 +458,7 @@ var JsonML = JsonML || {};
};
/*void*/ JsonML.appendChild = function(/*JsonML*/ parent, /*array|object|string*/ child) {
- if (child instanceof Array && child[0] === "") {
+ if (child instanceof Array && child[0] === '') {
// result was multiple JsonML sub-trees (i.e. documentFragment)
child.shift();// remove fragment ident
@@ -465,13 +466,13 @@ var JsonML = JsonML || {};
while (child.length) {
JsonML.appendChild(parent, child.shift(), arguments[2]);
}
- } else if (child && "object" === typeof child) {
+ } else if (child && 'object' === typeof child) {
if (child instanceof Array) {
if (!JsonML.isElement(parent) || !JsonML.isElement(child)) {
- throw new SyntaxError("invalid JsonML");
+ throw new SyntaxError('invalid JsonML');
}
- if ("function" === typeof arguments[2]) {
+ if ('function' === typeof arguments[2]) {
// onAppend callback for JBST use
arguments[2](parent, child);
}
@@ -480,7 +481,7 @@ var JsonML = JsonML || {};
parent.push(child);
} else if (child instanceof Unparsed) {
if (!JsonML.isElement(parent)) {
- throw new SyntaxError("invalid JsonML");
+ throw new SyntaxError('invalid JsonML');
}
// result was a JsonML node
@@ -489,16 +490,16 @@ var JsonML = JsonML || {};
// result was JsonML attributes
JsonML.addAttributes(parent, child);
}
- } else if ("undefined" !== typeof child && child !== null) {
+ } else if ('undefined' !== typeof child && child !== null) {
if (!(parent instanceof Array)) {
- throw new SyntaxError("invalid JsonML");
+ throw new SyntaxError('invalid JsonML');
}
// must convert to string or JsonML will discard
child = String(child);
// skip processing empty string literals
- if (child && parent.length > 1 && "string" === typeof parent[parent.length-1]) {
+ if (child && parent.length > 1 && 'string' === typeof parent[parent.length-1]) {
// combine strings
parent[parent.length-1] += child;
} else if (child || !parent.length) {
@@ -516,4 +517,4 @@ var JsonML = JsonML || {};
jml.slice(1);
};
-})();
+})(JsonML);
Please sign in to comment.
Something went wrong with that request. Please try again.