From a8d26fd113f482bcf1d7bab3b6038efcc38549ed Mon Sep 17 00:00:00 2001 From: josdejong Date: Sat, 4 May 2013 11:26:40 +0200 Subject: [PATCH] Improved error handling --- HISTORY.md | 1 + app/web/app.js | 31 +++++- jsoneditor-min.js | 4 +- jsoneditor.js | 215 ++++++++++++++++++++---------------- jsoneditor/js/history.js | 4 +- jsoneditor/js/jsoneditor.js | 82 +++++++++----- jsoneditor/js/node.js | 4 +- jsoneditor/js/texteditor.js | 62 +++++++---- jsoneditor/js/treeeditor.js | 12 +- jsoneditor/js/util.js | 51 +++------ 10 files changed, 272 insertions(+), 194 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 2486222..96d4d8c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,6 +6,7 @@ http://jsoneditoronline.org - Unified JSONFormatter and JSONEditor in one editor with a switchable mode. - Urls are navigable now. +- Improved error and log handling. - Added jsoneditor to npm and bower. diff --git a/app/web/app.js b/app/web/app.js index e2f2ab4..31e31ed 100644 --- a/app/web/app.js +++ b/app/web/app.js @@ -43,7 +43,7 @@ app.CodeToTree = function() { treeEditor.set(codeEditor.get()); } catch (err) { - app.notify.showError(err); + app.notify.showError(app.formatError(err)); } }; @@ -55,7 +55,7 @@ app.treeToCode = function () { codeEditor.set(treeEditor.get()); } catch (err) { - app.notify.showError(err); + app.notify.showError(app.formatError(err)); } }; @@ -103,12 +103,12 @@ app.load = function() { mode: 'code', change: function () { app.lastChanged = codeEditor; + }, + error: function (err) { + app.notify.showError(app.formatError(err)); } }); codeEditor.set(json); - codeEditor.onError = function (err) { - app.notify.showError(err); - }; // tree editor container = document.getElementById("treeEditor"); @@ -116,6 +116,9 @@ app.load = function() { mode: 'tree', change: function () { app.lastChanged = treeEditor; + }, + error: function (err) { + app.notify.showError(app.formatError(err)); } }); treeEditor.set(json); @@ -212,7 +215,7 @@ app.openCallback = function (err, data) { } catch (err) { treeEditor.set({}); - app.notify.showError(err); + app.notify.showError(app.formatError(err)); } } } @@ -267,6 +270,22 @@ app.saveFile = function () { }); }; +/** + * Format a JSON parse/stringify error as HTML + * @param {Error} err + * @returns {string} + */ +app.formatError = function (err) { + var message = '
' + err.toString() + '
'; + if (typeof(jsonlint) != 'undefined') { + message += + '' + + 'validated by jsonlint' + + ''; + } + return message; +}; + /** * Clear the current file */ diff --git a/jsoneditor-min.js b/jsoneditor-min.js index aa69054..be6e989 100644 --- a/jsoneditor-min.js +++ b/jsoneditor-min.js @@ -30,5 +30,5 @@ * @version 2.2.0-SNAPSHOT * @date 2013-05-04 */ -(function(){function e(t,i,n){if(!(this instanceof e))throw new Error('JSONEditor constructor called without "new".');arguments.length&&this._create(t,i,n)}function t(e,i,n){if(!(this instanceof t))throw new Error('TreeEditor constructor called without "new".');this._create(e,i,n)}function i(e,t,n){if(!(this instanceof i))throw new Error('TextEditor constructor called without "new".');this._create(e,t,n)}function n(e,t){this.editor=e,this.dom={},this.expanded=!1,t&&t instanceof Object?(this.setField(t.field,t.fieldEditable),this.setValue(t.value,t.type)):(this.setField(""),this.setValue(null))}function o(e){this.editor=e,this.dom={}}function s(e,t){function i(e,t,o){o.forEach(function(o){if(o.type=="separator"){var s=document.createElement("div");s.className="separator",a=document.createElement("li"),a.appendChild(s),e.appendChild(a)}else{var r={},a=document.createElement("li");e.appendChild(a);var l=document.createElement("button");if(l.className=o.className,r.button=l,o.title&&(l.title=o.title),o.click&&(l.onclick=function(){n.hide(),o.click()}),a.appendChild(l),o.submenu){var d=document.createElement("div");d.className="icon",l.appendChild(d),l.appendChild(document.createTextNode(o.text));var h;if(o.click){l.className+=" default";var c=document.createElement("button");r.buttonExpand=c,c.className="expand",c.innerHTML='
',a.appendChild(c),o.submenuTitle&&(c.title=o.submenuTitle),h=c}else{var u=document.createElement("div");u.className="expand",l.appendChild(u),h=l}h.onclick=function(){n._onExpandItem(r),h.focus()};var p=[];r.subItems=p;var m=document.createElement("ul");r.ul=m,m.className="menu",m.style.height="0",a.appendChild(m),i(m,p,o.submenu)}else l.innerHTML='
'+o.text;t.push(r)}})}this.dom={};var n=this,o=this.dom;this.anchor=void 0,this.items=e,this.eventListeners={},this.selection=void 0,this.visibleSubmenu=void 0,this.onClose=t?t.close:void 0;var s=document.createElement("div");s.className="jsoneditor-contextmenu",o.menu=s;var r=document.createElement("ul");r.className="menu",s.appendChild(r),o.list=r,o.items=[];var a=document.createElement("button");o.focusButton=a;var l=document.createElement("li");l.style.overflow="hidden",l.style.height="0",l.appendChild(a),r.appendChild(l),i(r,this.dom.items,e),this.maxHeight=0,e.forEach(function(t){var i=(e.length+(t.submenu?t.submenu.length:0))*24;n.maxHeight=Math.max(n.maxHeight,i)})}function r(e){this.editor=e,this.clear(),this.actions={editField:{undo:function(e){e.node.updateField(e.oldValue)},redo:function(e){e.node.updateField(e.newValue)}},editValue:{undo:function(e){e.node.updateValue(e.oldValue)},redo:function(e){e.node.updateValue(e.newValue)}},appendNode:{undo:function(e){e.parent.removeChild(e.node)},redo:function(e){e.parent.appendChild(e.node)}},insertBeforeNode:{undo:function(e){e.parent.removeChild(e.node)},redo:function(e){e.parent.insertBefore(e.node,e.beforeNode)}},insertAfterNode:{undo:function(e){e.parent.removeChild(e.node)},redo:function(e){e.parent.insertAfter(e.node,e.afterNode)}},removeNode:{undo:function(e){var t=e.parent,i=t.childs[e.index]||t.append;t.insertBefore(e.node,i)},redo:function(e){e.parent.removeChild(e.node)}},duplicateNode:{undo:function(e){e.parent.removeChild(e.clone)},redo:function(e){e.parent.insertAfter(e.clone,e.node)}},changeType:{undo:function(e){e.node.changeType(e.oldType)},redo:function(e){e.node.changeType(e.newType)}},moveNode:{undo:function(e){e.startParent.moveTo(e.node,e.startIndex)},redo:function(e){e.endParent.moveTo(e.node,e.endIndex)}},sort:{undo:function(e){var t=e.node;t.hideChilds(),t.sort=e.oldSort,t.childs=e.oldChilds,t.showChilds()},redo:function(e){var t=e.node;t.hideChilds(),t.sort=e.newSort,t.childs=e.newChilds,t.showChilds()}}}}function a(e,t){var i=this;this.editor=e,this.timeout=void 0,this.delay=200,this.lastText=void 0,this.dom={},this.dom.container=t;var n=document.createElement("table");this.dom.table=n,n.className="search",t.appendChild(n);var o=document.createElement("tbody");this.dom.tbody=o,n.appendChild(o);var s=document.createElement("tr");o.appendChild(s);var r=document.createElement("td");s.appendChild(r);var a=document.createElement("div");this.dom.results=a,a.className="results",r.appendChild(a),r=document.createElement("td"),s.appendChild(r);var l=document.createElement("div");this.dom.input=l,l.className="frame",l.title="Search fields and values",r.appendChild(l);var d=document.createElement("table");l.appendChild(d);var h=document.createElement("tbody");d.appendChild(h),s=document.createElement("tr"),h.appendChild(s);var c=document.createElement("button");c.className="refresh",r=document.createElement("td"),r.appendChild(c),s.appendChild(r);var u=document.createElement("input");this.dom.search=u,u.oninput=function(e){i._onDelayedSearch(e)},u.onchange=function(e){i._onSearch(e)},u.onkeydown=function(e){i._onKeyDown(e)},u.onkeyup=function(e){i._onKeyUp(e)},c.onclick=function(){u.select()},r=document.createElement("td"),r.appendChild(u),s.appendChild(r);var p=document.createElement("button");p.title="Next result (Enter)",p.className="next",p.onclick=function(){i.next()},r=document.createElement("td"),r.appendChild(p),s.appendChild(r);var m=document.createElement("button");m.title="Previous result (Shift+Enter)",m.className="previous",m.onclick=function(){i.previous()},r=document.createElement("td"),r.appendChild(m),s.appendChild(r)}function l(){this.locked=!1}e.modes={},e.prototype._create=function(e,t,i){this.container=e,this.options=t||{},this.json=i||{};var n=this.options.mode||"tree";this.setMode(n)},e.prototype._delete=function(){},e.prototype.set=function(e){this.json=e},e.prototype.get=function(){return this.json},e.prototype.setText=function(e){this.json=util.parse(e)},e.prototype.getText=function(){return JSON.stringify(this.json)},e.prototype.setName=function(e){this.options||(this.options={}),this.options.name=e},e.prototype.getName=function(){return this.options&&this.options.name},e.prototype.setMode=function(t){var i,n,o=this.container,s=util.extend({},this.options);s.mode=t;var r=e.modes[t];if(!r)throw new Error('Unknown mode "'+s.mode+'"');r.data=="text"?(n=this.getName(),i=this.getText(),this._delete(),util.clear(this),util.extend(this,r.editor.prototype),this._create(o,s),this.setName(n),this.setText(i)):(n=this.getName(),i=this.get(),this._delete(),util.clear(this),util.extend(this,r.editor.prototype),this._create(o,s),this.setName(n),this.set(i)),typeof r.load=="function"&&r.load.call(this)},t.prototype._create=function(e,t,i){if("undefined"==typeof JSON)throw new Error("Your browser does not support JSON. \n\nPlease install the newest version of your browser.\n(all modern browsers support JSON).");if(!e)throw new Error("No container element provided.");this.container=e,this.dom={},this.highlighter=new l,this.selection=void 0,this._setOptions(t),this.options.history&&!this.mode.view&&(this.history=new r(this)),this._createFrame(),this._createTable(),this.set(i||{})},t.prototype._delete=function(){this.frame&&this.container&&this.frame.parentNode==this.container&&this.container.removeChild(this.frame)},t.prototype._setOptions=function(e){if(this.options={search:!0,history:!0,mode:"tree",name:void 0},e){for(var t in e)e.hasOwnProperty(t)&&(this.options[t]=e[t]);e.enableSearch&&(this.options.search=e.enableSearch,console.log('WARNING: Option "enableSearch" is deprecated. Use "search" instead.')),e.enableHistory&&(this.options.history=e.enableHistory,console.log('WARNING: Option "enableHistory" is deprecated. Use "history" instead.')),e.mode=="editor"&&(this.options.mode="tree",console.log('WARNING: Mode "editor" is deprecated. Use "tree" instead.')),e.mode=="viewer"&&(this.options.mode="view",console.log('WARNING: Mode "viewer" is deprecated. Use "view" instead.'))}this.mode={edit:this.options.mode!="view"&&this.options.mode!="form",view:this.options.mode=="view",form:this.options.mode=="form"}},t.focusNode=void 0,t.prototype.set=function(e,t){if(t&&(console.log('Warning: second parameter "name" is deprecated. Use setName(name) instead.'),this.options.name=t),e instanceof Function||void 0===e)this.clear();else{this.content.removeChild(this.table);var i={field:this.options.name,value:e},o=new n(this,i);this._setRoot(o);var s=!1;this.node.expand(s),this.content.appendChild(this.table)}this.history&&this.history.clear()},t.prototype.get=function(){return t.focusNode&&t.focusNode.blur(),this.node?this.node.getValue():void 0},t.prototype.getText=function(){return JSON.stringify(this.get())},t.prototype.setText=function(e){this.set(util.parse(e))},t.prototype.setName=function(e){this.options.name=e,this.node&&this.node.updateField(this.options.name)},t.prototype.getName=function(){return this.options.name},t.prototype.clear=function(){this.node&&(this.node.collapse(),this.tbody.removeChild(this.node.getDom()),delete this.node)},t.prototype._setRoot=function(e){this.clear(),this.node=e,this.tbody.appendChild(e.getDom())},t.prototype.search=function(e){var t;return this.node?(this.content.removeChild(this.table),t=this.node.search(e),this.content.appendChild(this.table)):t=[],t},t.prototype.expandAll=function(){this.node&&(this.content.removeChild(this.table),this.node.expand(),this.content.appendChild(this.table))},t.prototype.collapseAll=function(){this.node&&(this.content.removeChild(this.table),this.node.collapse(),this.content.appendChild(this.table))},t.prototype._onAction=function(e,t){if(this.history&&this.history.add(e,t),this.options.change)try{this.options.change()}catch(i){console.log("Error in change callback: ",i)}},t.prototype.startAutoScroll=function(e){var t=this,i=this.content,n=util.getAbsoluteTop(i),o=i.clientHeight,s=n+o,r=24,a=50;this.autoScrollStep=n+r>e&&i.scrollTop>0?(n+r-e)/3:e>s-r&&o+i.scrollTop3?(i.scrollTop+=o/3,n.animateCallback=t,n.animateTimeout=setTimeout(a,50)):(t&&t(!0),i.scrollTop=r,delete n.animateTimeout,delete n.animateCallback)};a()}else t&&t(!1)},t.prototype._createFrame=function(){this.frame=document.createElement("div"),this.frame.className="jsoneditor",this.container.appendChild(this.frame);var e=this,t=function(t){e._onEvent(t)};this.frame.onclick=function(e){e=e||window.event;var i=e.target||e.srcElement;t(e),i.nodeName=="BUTTON"&&util.preventDefault(e)},this.frame.oninput=t,this.frame.onchange=t,this.frame.onkeydown=t,this.frame.onkeyup=t,this.frame.oncut=t,this.frame.onpaste=t,this.frame.onmousedown=t,this.frame.onmouseup=t,this.frame.onmouseover=t,this.frame.onmouseout=t,util.addEventListener(this.frame,"focus",t,!0),util.addEventListener(this.frame,"blur",t,!0),this.frame.onfocusin=t,this.frame.onfocusout=t,this.menu=document.createElement("div"),this.menu.className="menu",this.frame.appendChild(this.menu);var i=document.createElement("button");i.className="expand-all",i.title="Expand all fields",i.onclick=function(){e.expandAll()},this.menu.appendChild(i);var n=document.createElement("button");if(n.title="Collapse all fields",n.className="collapse-all",n.onclick=function(){e.collapseAll()},this.menu.appendChild(n),this.history){var o=document.createElement("span");o.innerHTML=" ",this.menu.appendChild(o);var s=document.createElement("button");s.className="undo",s.title="Undo last action (Ctrl+Z)",s.onclick=function(){e._onUndo()},this.menu.appendChild(s),this.dom.undo=s;var r=document.createElement("button");r.className="redo",r.title="Redo (Ctrl+Shift+Z)",r.onclick=function(){e._onRedo()},this.menu.appendChild(r),this.dom.redo=r,this.history.onChange=function(){s.disabled=!e.history.canUndo(),r.disabled=!e.history.canRedo()},this.history.onChange()}this.options.search&&(this.searchBox=new a(this,this.menu))},t.prototype._onUndo=function(){this.history&&(this.history.undo(),this.options.change&&this.options.change())},t.prototype._onRedo=function(){this.history&&(this.history.redo(),this.options.change&&this.options.change())},t.prototype._onEvent=function(e){e=e||window.event;var i=e.target||e.srcElement;e.type=="keydown"&&this._onKeyDown(e),e.type=="focus"&&(t.domFocus=i);var o=n.getNodeFromTarget(i);o&&o.onEvent(e)},t.prototype._onKeyDown=function(e){var i=e.which||e.keyCode,n=e.ctrlKey,o=e.shiftKey,s=!1;if(9==i&&setTimeout(function(){util.selectContentEditable(t.domFocus)},0),this.searchBox)if(n&&70==i)this.searchBox.dom.search.focus(),this.searchBox.dom.search.select(),s=!0;else if(114==i||n&&71==i){var r=!0;o?this.searchBox.previous(r):this.searchBox.next(r),s=!0}this.history&&(n&&!o&&90==i?(this._onUndo(),s=!0):n&&o&&90==i&&(this._onRedo(),s=!0)),s&&(util.preventDefault(e),util.stopPropagation(e))},t.prototype._createTable=function(){var e=document.createElement("div");e.className="outer",this.contentOuter=e,this.content=document.createElement("div"),this.content.className="content",e.appendChild(this.content),this.table=document.createElement("table"),this.table.className="content",this.content.appendChild(this.table);var t=util.getInternetExplorerVersion();8==t&&(this.content.style.overflow="scroll");var i;this.colgroupContent=document.createElement("colgroup"),this.mode.edit&&(i=document.createElement("col"),i.width="24px",this.colgroupContent.appendChild(i)),i=document.createElement("col"),i.width="24px",this.colgroupContent.appendChild(i),i=document.createElement("col"),this.colgroupContent.appendChild(i),this.table.appendChild(this.colgroupContent),this.tbody=document.createElement("tbody"),this.table.appendChild(this.tbody),this.frame.appendChild(e)},e.modes.tree={editor:t,data:"json"},e.modes.view={editor:t,data:"json"},e.modes.form={editor:t,data:"json"},e.modes.editor={editor:t,data:"json"},e.modes.viewer={editor:t,data:"json"},i.prototype._create=function(e,t,i){if("undefined"==typeof JSON)throw new Error("Your browser does not support JSON. \n\nPlease install the newest version of your browser.\n(all modern browsers support JSON).");t=t||{},t.indentation&&(this.indentation=Number(t.indentation)),this.mode=t.mode=="code"?"code":"text",this.mode=="code"&&("undefined"==typeof ace&&(this.mode="text",console.log("WARNING: Cannot load code editor, Ace library not loaded. Falling back to plain text editor")),util.getInternetExplorerVersion()==8&&(this.mode="text",console.log("WARNING: Cannot load code editor, Ace is not supported on IE8. Falling back to plain text editor")));var n=this;this.container=e,this.editor=void 0,this.textarea=void 0,this.indentation=4,this.width=e.clientWidth,this.height=e.clientHeight,this.frame=document.createElement("div"),this.frame.className="jsoneditor",this.frame.onclick=function(e){util.preventDefault(e)},this.menu=document.createElement("div"),this.menu.className="menu",this.frame.appendChild(this.menu);var o=document.createElement("button");o.className="format",o.title="Format JSON data, with proper indentation and line feeds",this.menu.appendChild(o),o.onclick=function(){n.format()};var s=document.createElement("button");if(s.className="compact",s.title="Compact JSON data, remove all whitespaces",this.menu.appendChild(s),s.onclick=function(){n.compact()},this.content=document.createElement("div"),this.content.className="outer",this.frame.appendChild(this.content),this.container.appendChild(this.frame),this.mode=="code"){this.editorDom=document.createElement("div"),this.editorDom.style.height="100%",this.editorDom.style.width="100%",this.content.appendChild(this.editorDom);var r=ace.edit(this.editorDom);r.setTheme("ace/theme/jsoneditor"),r.setShowPrintMargin(!1),r.setFontSize(13),r.getSession().setMode("ace/mode/json"),r.getSession().setUseSoftTabs(!0),r.getSession().setUseWrapMode(!0),this.editor=r;var a=document.createElement("a");a.appendChild(document.createTextNode("powered by ace")),a.href="http://ace.ajax.org",a.target="_blank",a.className="poweredBy",a.onclick=function(){window.open(a.href,a.target)},this.menu.appendChild(a),t.change&&r.on("change",function(){t.change()})}else{var l=document.createElement("textarea");l.className="content",l.spellcheck=!1,this.content.appendChild(l),this.textarea=l,t.change&&(this.textarea.oninput===null?this.textarea.oninput=function(){t.change()}:this.textarea.onchange=function(){t.change()})}"string"==typeof i?this.setText(i):this.set(i)},i.prototype._delete=function(){this.frame&&this.container&&this.frame.parentNode==this.container&&this.container.removeChild(this.frame)},i.prototype.onError=function(){},i.prototype.compact=function(){try{var e=util.parse(this.getText());this.setText(JSON.stringify(e))}catch(t){this.onError(t)}},i.prototype.format=function(){try{var e=util.parse(this.getText());this.setText(JSON.stringify(e,null,this.indentation))}catch(t){this.onError(t)}},i.prototype.focus=function(){this.textarea&&this.textarea.focus(),this.editor&&this.editor.focus()},i.prototype.resize=function(){if(this.editor){var e=!1;this.editor.resize(e)}},i.prototype.set=function(e){this.setText(JSON.stringify(e,null,this.indentation))},i.prototype.get=function(){return util.parse(this.getText())},i.prototype.getText=function(){return this.textarea?this.textarea.value:this.editor?this.editor.getValue():""},i.prototype.setText=function(e){this.textarea&&(this.textarea.value=e),this.editor&&this.editor.setValue(e,-1)},e.modes.text={editor:i,data:"text",load:i.prototype.format},e.modes.code={editor:i,data:"text",load:i.prototype.format},n.prototype.setParent=function(e){this.parent=e},n.prototype.setField=function(e,t){this.field=e,this.fieldEditable=1==t},n.prototype.getField=function(){return this.field===void 0&&this._getDomField(),this.field},n.prototype.setValue=function(e,t){var i,o,s=this.childs;if(s)for(;s.length;)this.removeChild(s[0]);if(this.type=this._getType(e),t&&t!=this.type){if("string"!=t||this.type!="auto")throw new Error('Type mismatch: cannot cast value of type "'+this.type+' to the specified type "'+t+'"');this.type=t}if(this.type=="array"){this.childs=[];for(var r=0,a=e.length;a>r;r++)i=e[r],void 0===i||i instanceof Function||(o=new n(this.editor,{value:i}),this.appendChild(o));this.value=""}else if(this.type=="object"){this.childs=[];for(var l in e)e.hasOwnProperty(l)&&(i=e[l],void 0===i||i instanceof Function||(o=new n(this.editor,{field:l,value:i}),this.appendChild(o)));this.value=""}else this.childs=void 0,this.value=e},n.prototype.getValue=function(){if(this.type=="array"){var e=[];return this.childs.forEach(function(t){e.push(t.getValue())}),e}if(this.type=="object"){var t={};return this.childs.forEach(function(e){t[e.getField()]=e.getValue()}),t}return this.value===void 0&&this._getDomValue(),this.value},n.prototype.getLevel=function(){return this.parent?this.parent.getLevel()+1:0},n.prototype.clone=function(){var e=new n(this.editor);if(e.type=this.type,e.field=this.field,e.fieldInnerText=this.fieldInnerText,e.fieldEditable=this.fieldEditable,e.value=this.value,e.valueInnerText=this.valueInnerText,e.expanded=this.expanded,this.childs){var t=[];this.childs.forEach(function(i){var n=i.clone();n.setParent(e),t.push(n)}),e.childs=t}else e.childs=void 0;return e},n.prototype.expand=function(e){this.childs&&(this.expanded=!0,this.dom.expand&&(this.dom.expand.className="expanded"),this.showChilds(),0!=e&&this.childs.forEach(function(t){t.expand(e)}))},n.prototype.collapse=function(e){this.childs&&(this.hideChilds(),0!=e&&this.childs.forEach(function(t){t.collapse(e)}),this.dom.expand&&(this.dom.expand.className="collapsed"),this.expanded=!1)},n.prototype.showChilds=function(){var e=this.childs;if(e&&this.expanded){var t=this.dom.tr,i=t?t.parentNode:void 0;if(i){var n=this.getAppend(),o=t.nextSibling;o?i.insertBefore(n,o):i.appendChild(n),this.childs.forEach(function(e){i.insertBefore(e.getDom(),n),e.showChilds()})}}},n.prototype.hide=function(){var e=this.dom.tr,t=e?e.parentNode:void 0;t&&t.removeChild(e),this.hideChilds()},n.prototype.hideChilds=function(){var e=this.childs;if(e&&this.expanded){var t=this.getAppend();t.parentNode&&t.parentNode.removeChild(t),this.childs.forEach(function(e){e.hide()})}},n.prototype.appendChild=function(e){if(this._hasChilds()){if(e.setParent(this),e.fieldEditable=this.type=="object",this.type=="array"&&(e.index=this.childs.length),this.childs.push(e),this.expanded){var t=e.getDom(),i=this.getAppend(),n=i?i.parentNode:void 0;i&&n&&n.insertBefore(t,i),e.showChilds()}this.updateDom({updateIndexes:!0}),e.updateDom({recurse:!0})}},n.prototype.moveBefore=function(e,t){if(this._hasChilds()){var i=this.dom.tr?this.dom.tr.parentNode:void 0;if(i){var n=document.createElement("tr");n.style.height=i.clientHeight+"px",i.appendChild(n)}e.parent&&e.parent.removeChild(e),t instanceof o?this.appendChild(e):this.insertBefore(e,t),i&&i.removeChild(n)}},n.prototype.moveTo=function(e,t){if(e.parent==this){var i=this.childs.indexOf(e);t>i&&t++}var n=this.childs[t]||this.append;this.moveBefore(e,n)},n.prototype.insertBefore=function(e,t){if(this._hasChilds()){if(t==this.append)e.setParent(this),e.fieldEditable=this.type=="object",this.childs.push(e);else{var i=this.childs.indexOf(t);if(-1==i)throw new Error("Node not found");e.setParent(this),e.fieldEditable=this.type=="object",this.childs.splice(i,0,e)}if(this.expanded){var n=e.getDom(),o=t.getDom(),s=o?o.parentNode:void 0;o&&s&&s.insertBefore(n,o),e.showChilds()}this.updateDom({updateIndexes:!0}),e.updateDom({recurse:!0})}},n.prototype.insertAfter=function(e,t){if(this._hasChilds()){var i=this.childs.indexOf(t),n=this.childs[i+1];n?this.insertBefore(e,n):this.appendChild(e)}},n.prototype.search=function(e){var t,i=[],n=e?e.toLowerCase():void 0;if(delete this.searchField,delete this.searchValue,this.field!=void 0){var o=String(this.field).toLowerCase();t=o.indexOf(n),-1!=t&&(this.searchField=!0,i.push({node:this,elem:"field"})),this._updateDomField()}if(this._hasChilds()){if(this.childs){var s=[];this.childs.forEach(function(t){s=s.concat(t.search(e))}),i=i.concat(s)}if(void 0!=n){var r=!1;s.length==0?this.collapse(r):this.expand(r)}}else{if(this.value!=void 0){var a=String(this.value).toLowerCase();t=a.indexOf(n),-1!=t&&(this.searchValue=!0,i.push({node:this,elem:"value"}))}this._updateDomValue()}return i},n.prototype.scrollTo=function(e){if(!this.dom.tr||!this.dom.tr.parentNode)for(var t=this.parent,i=!1;t;)t.expand(i),t=t.parent;this.dom.tr&&this.dom.tr.parentNode&&this.editor.scrollTo(this.dom.tr.offsetTop,e)},n.focusElement=void 0,n.prototype.focus=function(e){if(n.focusElement=e,this.dom.tr&&this.dom.tr.parentNode){var t=this.dom;switch(e){case"drag":t.drag?t.drag.focus():t.menu.focus();break;case"menu":t.menu.focus();break;case"expand":this._hasChilds()?t.expand.focus():t.field&&this.fieldEditable?(t.field.focus(),util.selectContentEditable(t.field)):t.value&&!this._hasChilds()?(t.value.focus(),util.selectContentEditable(t.value)):t.menu.focus();break;case"field":t.field&&this.fieldEditable?(t.field.focus(),util.selectContentEditable(t.field)):t.value&&!this._hasChilds()?(t.value.focus(),util.selectContentEditable(t.value)):this._hasChilds()?t.expand.focus():t.menu.focus();break;case"value":default:t.value&&!this._hasChilds()?(t.value.focus(),util.selectContentEditable(t.value)):t.field&&this.fieldEditable?(t.field.focus(),util.selectContentEditable(t.field)):this._hasChilds()?t.expand.focus():t.menu.focus()}}},n.select=function(e){setTimeout(function(){util.selectContentEditable(e)},0)},n.prototype.blur=function(){this._getDomValue(!1),this._getDomField(!1)},n.prototype._duplicate=function(e){var t=e.clone();return this.insertAfter(t,e),t},n.prototype.containsNode=function(e){if(this==e)return!0;var t=this.childs;if(t)for(var i=0,n=t.length;n>i;i++)if(t[i].containsNode(e))return!0;return!1},n.prototype._move=function(e,t){if(e!=t){if(e.containsNode(this))throw new Error("Cannot move a field into a child of itself");e.parent&&e.parent.removeChild(e);var i=e.clone();e.clearDom(),t?this.insertBefore(i,t):this.appendChild(i)}},n.prototype.removeChild=function(e){if(this.childs){var t=this.childs.indexOf(e);if(-1!=t){e.hide(),delete e.searchField,delete e.searchValue;var i=this.childs.splice(t,1)[0];return this.updateDom({updateIndexes:!0}),i}}return void 0},n.prototype._remove=function(e){this.removeChild(e)},n.prototype.changeType=function(e){var t=this.type;if(t!=e){if("string"!=e&&"auto"!=e||"string"!=t&&"auto"!=t){var i,n=this.dom.tr?this.dom.tr.parentNode:void 0;i=this.expanded?this.getAppend():this.getDom();var o=i&&i.parentNode?i.nextSibling:void 0;this.hide(),this.clearDom(),this.type=e,"object"==e?(this.childs||(this.childs=[]),this.childs.forEach(function(e){e.clearDom(),delete e.index,e.fieldEditable=!0,e.field==void 0&&(e.field="")}),("string"==t||"auto"==t)&&(this.expanded=!0)):"array"==e?(this.childs||(this.childs=[]),this.childs.forEach(function(e,t){e.clearDom(),e.fieldEditable=!1,e.index=t}),("string"==t||"auto"==t)&&(this.expanded=!0)):this.expanded=!1,n&&(o?n.insertBefore(this.getDom(),o):n.appendChild(this.getDom())),this.showChilds()}else this.type=e;("auto"==e||"string"==e)&&(this.value="string"==e?String(this.value):this._stringCast(String(this.value)),this.focus()),this.updateDom({updateIndexes:!0})}},n.prototype._getDomValue=function(e){if(this.dom.value&&this.type!="array"&&this.type!="object"&&(this.valueInnerText=util.getInnerText(this.dom.value)),this.valueInnerText!=void 0)try{var t;if(this.type=="string")t=this._unescapeHTML(this.valueInnerText);else{var i=this._unescapeHTML(this.valueInnerText);t=this._stringCast(i)}if(t!==this.value){var n=this.value;this.value=t,this.editor._onAction("editValue",{node:this,oldValue:n,newValue:t,oldSelection:this.editor.selection,newSelection:this.editor.getSelection()})}}catch(o){if(this.value=void 0,1!=e)throw o}},n.prototype._updateDomValue=function(){var e=this.dom.value;if(e){var t=this.value,i=this.type=="auto"?typeof t:this.type,n="string"==i&&util.isUrl(t),o="";o=n&&!this.editor.mode.edit?"":"string"==i?"green":"number"==i?"red":"boolean"==i?"orange":this._hasChilds()?"":null===t?"#004ED0":"black",e.style.color=o;var s=String(this.value)==""&&this.type!="array"&&this.type!="object";if(s?util.addClassName(e,"empty"):util.removeClassName(e,"empty"),n?util.addClassName(e,"url"):util.removeClassName(e,"url"),"array"==i||"object"==i){var r=this.childs?this.childs.length:0;e.title=this.type+" containing "+r+" items"}else"string"==i&&util.isUrl(t)?this.editor.mode.edit&&(e.title="Ctrl+Click or Ctrl+Enter to open url in new window"):e.title="";this.searchValueActive?util.addClassName(e,"highlight-active"):util.removeClassName(e,"highlight-active"),this.searchValue?util.addClassName(e,"highlight"):util.removeClassName(e,"highlight"),util.stripFormatting(e)}},n.prototype._updateDomField=function(){var e=this.dom.field;if(e){var t=String(this.field)==""&&this.parent.type!="array";t?util.addClassName(e,"empty"):util.removeClassName(e,"empty"),this.searchFieldActive?util.addClassName(e,"highlight-active"):util.removeClassName(e,"highlight-active"),this.searchField?util.addClassName(e,"highlight"):util.removeClassName(e,"highlight"),util.stripFormatting(e)}},n.prototype._getDomField=function(e){if(this.dom.field&&this.fieldEditable&&(this.fieldInnerText=util.getInnerText(this.dom.field)),this.fieldInnerText!=void 0)try{var t=this._unescapeHTML(this.fieldInnerText);if(t!==this.field){var i=this.field;this.field=t,this.editor._onAction("editField",{node:this,oldValue:i,newValue:t,oldSelection:this.editor.selection,newSelection:this.editor.getSelection()})}}catch(n){if(this.field=void 0,1!=e)throw n}},n.prototype.clearDom=function(){this.dom={}},n.prototype.getDom=function(){var e=this.dom;if(e.tr)return e.tr;if(e.tr=document.createElement("tr"),e.tr.node=this,this.editor.mode.edit){var t=document.createElement("td");if(this.parent){var i=document.createElement("button");e.drag=i,i.className="dragarea",i.title="Drag to move this field (Alt+Shift+Arrows)",t.appendChild(i)}e.tr.appendChild(t);var n=document.createElement("td"),o=document.createElement("button");e.menu=o,o.className="contextmenu",o.title="Click to open the actions menu (Ctrl+M)",n.appendChild(e.menu),e.tr.appendChild(n)}var s=document.createElement("td");return e.tr.appendChild(s),e.tree=this._createDomTree(),s.appendChild(e.tree),this.updateDom({updateIndexes:!0}),e.tr},n.prototype._onDragStart=function(e){e=e||window.event;var t=this;this.mousemove||(this.mousemove=util.addEventListener(document,"mousemove",function(e){t._onDrag(e)})),this.mouseup||(this.mouseup=util.addEventListener(document,"mouseup",function(e){t._onDragEnd(e)})),this.editor.highlighter.lock(),this.drag={oldCursor:document.body.style.cursor,startParent:this.parent,startIndex:this.parent.childs.indexOf(this),mouseX:util.getMouseX(e),level:this.getLevel()},document.body.style.cursor="move",util.preventDefault(e)},n.prototype._onDrag=function(e){e=e||window.event;var t,i,s,r,a,l,d,h,c,u,p,m,f,v,g=util.getMouseY(e),y=util.getMouseX(e),x=!1;if(t=this.dom.tr,c=util.getAbsoluteTop(t),m=t.offsetHeight,c>g){i=t;do i=i.previousSibling,d=n.getNodeFromTarget(i),u=i?util.getAbsoluteTop(i):0;while(i&&u>g);d&&!d.parent&&(d=void 0),d||(l=t.parentNode.firstChild,i=l?l.nextSibling:void 0,d=n.getNodeFromTarget(i),d==this&&(d=void 0)),d&&(i=d.dom.tr,u=i?util.getAbsoluteTop(i):0,g>u+m&&(d=void 0)),d&&(d.parent.moveBefore(this,d),x=!0)}else if(a=this.expanded&&this.append?this.append.getDom():this.dom.tr,r=a?a.nextSibling:void 0){p=util.getAbsoluteTop(r),s=r;do h=n.getNodeFromTarget(s),s&&(f=s.nextSibling?util.getAbsoluteTop(s.nextSibling):0,v=s?f-p:0,h.parent.childs.length==1&&h.parent.childs[0]==this&&(c+=23)),s=s.nextSibling;while(s&&g>c+v);if(h&&h.parent){var b=y-this.drag.mouseX,C=Math.round(b/24/2),N=this.drag.level+C,E=h.getLevel();for(i=h.dom.tr.previousSibling;N>E&&i;){if(d=n.getNodeFromTarget(i),d==this||d._isChildOf(this));else{if(!(d instanceof o))break;var _=d.parent.childs;if(!(_.length>1||_.length==1&&_[0]!=this))break;h=n.getNodeFromTarget(i),E=h.getLevel()}i=i.previousSibling}a.nextSibling!=h.dom.tr&&(h.parent.moveBefore(this,h),x=!0)}}x&&(this.drag.mouseX=y,this.drag.level=this.getLevel()),this.editor.startAutoScroll(g),util.preventDefault(e)},n.prototype._onDragEnd=function(e){e=e||window.event;var t={node:this,startParent:this.drag.startParent,startIndex:this.drag.startIndex,endParent:this.parent,endIndex:this.parent.childs.indexOf(this)};(t.startParent!=t.endParent||t.startIndex!=t.endIndex)&&this.editor._onAction("moveNode",t),document.body.style.cursor=this.drag.oldCursor,this.editor.highlighter.unlock(),delete this.drag,this.mousemove&&(util.removeEventListener(document,"mousemove",this.mousemove),delete this.mousemove),this.mouseup&&(util.removeEventListener(document,"mouseup",this.mouseup),delete this.mouseup),this.editor.stopAutoScroll(),util.preventDefault(e)},n.prototype._isChildOf=function(e){for(var t=this.parent;t;){if(t==e)return!0;t=t.parent}return!1},n.prototype._createDomField=function(){return document.createElement("div")},n.prototype.setHighlight=function(e){this.dom.tr&&(this.dom.tr.className=e?"highlight":"",this.append&&this.append.setHighlight(e),this.childs&&this.childs.forEach(function(t){t.setHighlight(e) -}))},n.prototype.updateValue=function(e){this.value=e,this.updateDom()},n.prototype.updateField=function(e){this.field=e,this.updateDom()},n.prototype.updateDom=function(e){var t=this.dom.tree;t&&(t.style.marginLeft=this.getLevel()*24+"px");var i=this.dom.field;if(i){this.fieldEditable==1?(i.contentEditable=this.editor.mode.edit,i.spellcheck=!1,i.className="field"):i.className="readonly";var n;n=this.index!=void 0?this.index:this.field!=void 0?this.field:this._hasChilds()?this.type:"",i.innerHTML=this._escapeHTML(n)}var o=this.dom.value;if(o){var s=this.childs?this.childs.length:0;o.innerHTML=this.type=="array"?"["+s+"]":this.type=="object"?"{"+s+"}":this._escapeHTML(this.value)}this._updateDomField(),this._updateDomValue(),e&&e.updateIndexes==1&&this._updateDomIndexes(),e&&e.recurse==1&&this.childs&&this.childs.forEach(function(t){t.updateDom(e)}),this.append&&this.append.updateDom()},n.prototype._updateDomIndexes=function(){var e=this.dom.value,t=this.childs;e&&t&&(this.type=="array"?t.forEach(function(e,t){e.index=t;var i=e.dom.field;i&&(i.innerHTML=t)}):this.type=="object"&&t.forEach(function(e){e.index!=void 0&&(delete e.index,e.field==void 0&&(e.field=""))}))},n.prototype._createDomValue=function(){var e;return this.type=="array"?(e=document.createElement("div"),e.className="readonly",e.innerHTML="[...]"):this.type=="object"?(e=document.createElement("div"),e.className="readonly",e.innerHTML="{...}"):!this.editor.mode.edit&&util.isUrl(this.value)?(e=document.createElement("a"),e.className="value",e.href=this.value,e.target="_blank",e.innerHTML=this._escapeHTML(this.value)):(e=document.createElement("div"),e.contentEditable=!this.editor.mode.view,e.spellcheck=!1,e.className="value",e.innerHTML=this._escapeHTML(this.value)),e},n.prototype._createDomExpandButton=function(){var e=document.createElement("button");return this._hasChilds()?(e.className=this.expanded?"expanded":"collapsed",e.title="Click to expand/collapse this field (Ctrl+E). \nCtrl+Click to expand/collapse including all childs."):(e.className="invisible",e.title=""),e},n.prototype._createDomTree=function(){var e=this.dom,t=document.createElement("table"),i=document.createElement("tbody");t.style.borderCollapse="collapse",t.appendChild(i);var n=document.createElement("tr");i.appendChild(n);var o=document.createElement("td");o.className="tree",n.appendChild(o),e.expand=this._createDomExpandButton(),o.appendChild(e.expand),e.tdExpand=o;var s=document.createElement("td");s.className="tree",n.appendChild(s),e.field=this._createDomField(),s.appendChild(e.field),e.tdField=s;var r=document.createElement("td");r.className="tree",n.appendChild(r),this.type!="object"&&this.type!="array"&&(r.appendChild(document.createTextNode(":")),r.className="separator"),e.tdSeparator=r;var a=document.createElement("td");return a.className="tree",n.appendChild(a),e.value=this._createDomValue(),a.appendChild(e.value),e.tdValue=a,t},n.prototype.onEvent=function(e){var t,i=e.type,n=e.target||e.srcElement,o=this.dom,s=this,r=this._hasChilds();if((n==o.drag||n==o.menu)&&("mouseover"==i?this.editor.highlighter.highlight(this):"mouseout"==i&&this.editor.highlighter.unhighlight()),"mousedown"==i&&n==o.drag&&this._onDragStart(e),"click"==i&&n==o.menu){var a=s.editor.highlighter;a.highlight(s),a.lock(),util.addClassName(o.menu,"selected"),this.showContextMenu(o.menu,function(){util.removeClassName(o.menu,"selected"),a.unlock(),a.unhighlight()})}if("click"==i&&n==o.expand&&r){var l=e.ctrlKey;this._onExpand(l)}var d=o.value;if(n==d)switch(i){case"focus":t=this;break;case"blur":case"change":this._getDomValue(!0),this._updateDomValue(),this.value&&(d.innerHTML=this._escapeHTML(this.value));break;case"input":this._getDomValue(!0),this._updateDomValue();break;case"keydown":case"mousedown":this.editor.selection=this.editor.getSelection();break;case"click":e.ctrlKey&&this.editor.mode.edit&&util.isUrl(this.value)&&window.open(this.value,"_blank");break;case"keyup":this._getDomValue(!0),this._updateDomValue();break;case"cut":case"paste":setTimeout(function(){s._getDomValue(!0),s._updateDomValue()},1)}var h=o.field;if(n==h)switch(i){case"focus":t=this;break;case"blur":case"change":this._getDomField(!0),this._updateDomField(),this.field&&(h.innerHTML=this._escapeHTML(this.field));break;case"input":this._getDomField(!0),this._updateDomField();break;case"keydown":case"mousedown":this.editor.selection=this.editor.getSelection();break;case"keyup":this._getDomField(!0),this._updateDomField();break;case"cut":case"paste":setTimeout(function(){s._getDomField(!0),s._updateDomField()},1)}var c=o.tree;if(n==c.parentNode)switch(i){case"click":var u=e.offsetX!=void 0?e.offsetX<(this.getLevel()+1)*24:util.getMouseX(e)n[i]?t:e[i]/g,">").replace(/ /g,"  ").replace(/^ /," ").replace(/ $/," "),i=JSON.stringify(t);return i.substring(1,i.length-1)},n.prototype._unescapeHTML=function(e){var t='"'+this._escapeJSON(e)+'"',i=util.parse(t);return i.replace(/</g,"<").replace(/>/g,">").replace(/ /g," ")},n.prototype._escapeJSON=function(e){for(var t="",i=0,n=e.length;n>i;){var o=e.charAt(i);"\n"==o?t+="\\n":"\\"==o?(t+=o,i++,o=e.charAt(i),'"\\/bfnrtu'.indexOf(o)==-1&&(t+="\\"),t+=o):t+='"'==o?'\\"':o,i++}return t},o.prototype=new n,o.prototype.getDom=function(){var e=this.dom;if(e.tr)return e.tr;var t=document.createElement("tr");if(t.node=this,e.tr=t,this.editor.mode.edit){e.tdDrag=document.createElement("td");var i=document.createElement("td");e.tdMenu=i;var n=document.createElement("button");n.className="contextmenu",n.title="Click to open the actions menu (Ctrl+M)",e.menu=n,i.appendChild(e.menu)}var o=document.createElement("td"),s=document.createElement("div");return s.innerHTML="(empty)",s.className="readonly",o.appendChild(s),e.td=o,e.text=s,this.updateDom(),t},o.prototype.updateDom=function(){var e=this.dom,t=e.td;t&&(t.style.paddingLeft=this.getLevel()*24+26+"px");var i=e.text;i&&(i.innerHTML="(empty "+this.parent.type+")");var n=e.tr;this.isVisible()?e.tr.firstChild||(e.tdDrag&&n.appendChild(e.tdDrag),e.tdMenu&&n.appendChild(e.tdMenu),n.appendChild(t)):e.tr.firstChild&&(e.tdDrag&&n.removeChild(e.tdDrag),e.tdMenu&&n.removeChild(e.tdMenu),n.removeChild(t))},o.prototype.isVisible=function(){return this.parent.childs.length==0},o.prototype.showContextMenu=function(e,t){var i=this,o=n.TYPE_TITLES,r=[{text:"Append",title:"Append a new field with type 'auto' (Ctrl+Shift+Ins)",submenuTitle:"Select the type of the field to be appended",className:"insert",click:function(){i._onAppend("","","auto")},submenu:[{text:"Auto",className:"type-auto",title:o.auto,click:function(){i._onAppend("","","auto")}},{text:"Array",className:"type-array",title:o.array,click:function(){i._onAppend("",[])}},{text:"Object",className:"type-object",title:o.object,click:function(){i._onAppend("",{})}},{text:"String",className:"type-string",title:o.string,click:function(){i._onAppend("","","string")}}]}],a=new s(r,{close:t});a.show(e)},o.prototype.onEvent=function(e){var t=e.type,i=e.target||e.srcElement,n=this.dom,o=n.menu;if(i==o&&("mouseover"==t?this.editor.highlighter.highlight(this.parent):"mouseout"==t&&this.editor.highlighter.unhighlight()),"click"==t&&i==n.menu){var s=this.editor.highlighter;s.highlight(this.parent),s.lock(),util.addClassName(n.menu,"selected"),this.showContextMenu(n.menu,function(){util.removeClassName(n.menu,"selected"),s.unlock(),s.unhighlight()})}"keydown"==t&&this.onKeyDown(e)},s.prototype._getVisibleButtons=function(){var e=[],t=this;return this.dom.items.forEach(function(i){e.push(i.button),i.buttonExpand&&e.push(i.buttonExpand),i.subItems&&i==t.expandedItem&&i.subItems.forEach(function(t){e.push(t.button),t.buttonExpand&&e.push(t.buttonExpand)})}),e},s.visibleMenu=void 0,s.prototype.show=function(e){this.hide();var t=util.getWindowHeight(),i=e.offsetHeight,n=this.maxHeight,o=util.getAbsoluteLeft(e),r=util.getAbsoluteTop(e);t>r+i+n?(this.dom.menu.style.left=o+"px",this.dom.menu.style.top=r+i+"px",this.dom.menu.style.bottom=""):(this.dom.menu.style.left=o+"px",this.dom.menu.style.top="",this.dom.menu.style.bottom=t-r+"px"),document.body.appendChild(this.dom.menu);var a=this,l=this.dom.list;this.eventListeners.mousedown=util.addEventListener(document,"mousedown",function(e){e=e||window.event;var t=e.target||e.srcElement;t==l||a._isChildOf(t,l)||(a.hide(),util.stopPropagation(e),util.preventDefault(e))}),this.eventListeners.mousewheel=util.addEventListener(document,"mousewheel",function(){util.stopPropagation(event),util.preventDefault(event)}),this.eventListeners.keydown=util.addEventListener(document,"keydown",function(e){a._onKeyDown(e)}),this.selection=util.getSelection(),this.anchor=e,setTimeout(function(){a.dom.focusButton.focus()},0),s.visibleMenu&&s.visibleMenu.hide(),s.visibleMenu=this},s.prototype.hide=function(){this.dom.menu.parentNode&&(this.dom.menu.parentNode.removeChild(this.dom.menu),this.onClose&&this.onClose());for(var e in this.eventListeners)if(this.eventListeners.hasOwnProperty(e)){var t=this.eventListeners[e];t&&util.removeEventListener(document,e,t),delete this.eventListeners[e]}s.visibleMenu==this&&(s.visibleMenu=void 0)},s.prototype._onExpandItem=function(e){var t=this,i=e==this.expandedItem,n=this.expandedItem;if(n&&(n.ul.style.height="0",n.ul.style.padding="",setTimeout(function(){t.expandedItem!=n&&(n.ul.style.display="",util.removeClassName(n.ul.parentNode,"selected"))},300),this.expandedItem=void 0),!i){var o=e.ul;o.style.display="block",o.clientHeight,setTimeout(function(){t.expandedItem==e&&(o.style.height=o.childNodes.length*24+"px",o.style.padding="5px 10px")},0),util.addClassName(o.parentNode,"selected"),this.expandedItem=e}},s.prototype._onKeyDown=function(e){e=e||window.event;var t,i,n,o,s=e.target||e.srcElement,r=e.which||e.keyCode,a=!1;27==r?(this.selection&&util.setSelection(this.selection),this.anchor&&this.anchor.focus(),this.hide(),a=!0):9==r?e.shiftKey?(t=this._getVisibleButtons(),i=t.indexOf(s),0==i&&(t[t.length-1].focus(),a=!0)):(t=this._getVisibleButtons(),i=t.indexOf(s),i==t.length-1&&(t[0].focus(),a=!0)):37==r?(s.className=="expand"&&(t=this._getVisibleButtons(),i=t.indexOf(s),n=t[i-1],n&&n.focus()),a=!0):38==r?(t=this._getVisibleButtons(),i=t.indexOf(s),n=t[i-1],n&&n.className=="expand"&&(n=t[i-2]),n||(n=t[t.length-1]),n&&n.focus(),a=!0):39==r?(t=this._getVisibleButtons(),i=t.indexOf(s),o=t[i+1],o&&o.className=="expand"&&o.focus(),a=!0):40==r&&(t=this._getVisibleButtons(),i=t.indexOf(s),o=t[i+1],o&&o.className=="expand"&&(o=t[i+2]),o||(o=t[0]),o&&(o.focus(),a=!0),a=!0),a&&(util.stopPropagation(e),util.preventDefault(e))},s.prototype._isChildOf=function(e,t){for(var i=e.parentNode;i;){if(i==t)return!0;i=i.parentNode}return!1},r.prototype.onChange=function(){},r.prototype.add=function(e,t){this.index++,this.history[this.index]={action:e,params:t,timestamp:new Date},this.index=0},r.prototype.canRedo=function(){return this.indexthis.results.length-1&&(t=0),this._setActiveResult(t,e)}},a.prototype.previous=function(e){if(this.results!=void 0){var t=this.results.length-1,i=this.resultIndex!=void 0?this.resultIndex-1:t;0>i&&(i=t),this._setActiveResult(i,e)}},a.prototype._setActiveResult=function(e,t){if(this.activeResult){var i=this.activeResult.node,n=this.activeResult.elem;"field"==n?delete i.searchFieldActive:delete i.searchValueActive,i.updateDom()}if(!this.results||!this.results[e])return this.resultIndex=void 0,this.activeResult=void 0,void 0;this.resultIndex=e;var o=this.results[this.resultIndex].node,s=this.results[this.resultIndex].elem;"field"==s?o.searchFieldActive=!0:o.searchValueActive=!0,this.activeResult=this.results[this.resultIndex],o.updateDom(),o.scrollTo(function(){t&&o.focus(s)})},a.prototype._clearDelay=function(){this.timeout!=void 0&&(clearTimeout(this.timeout),delete this.timeout)},a.prototype._onDelayedSearch=function(){this._clearDelay();var e=this;this.timeout=setTimeout(function(t){e._onSearch(t)},this.delay)},a.prototype._onSearch=function(e,t){this._clearDelay();var i=this.dom.search.value,n=i.length>0?i:void 0;if(n!=this.lastText||t)if(this.lastText=n,this.results=this.editor.search(n),this._setActiveResult(void 0),void 0!=n){var o=this.results.length;switch(o){case 0:this.dom.results.innerHTML="no results";break;case 1:this.dom.results.innerHTML="1 result";break;default:this.dom.results.innerHTML=o+" results"}}else this.dom.results.innerHTML=""},a.prototype._onKeyDown=function(e){e=e||window.event;var t=e.which||e.keyCode;27==t?(this.dom.search.value="",this._onSearch(e),util.preventDefault(e),util.stopPropagation(e)):13==t&&(e.ctrlKey?this._onSearch(e,!0):e.shiftKey?this.previous():this.next(),util.preventDefault(e),util.stopPropagation(e))},a.prototype._onKeyUp=function(e){e=e||window.event;var t=e.which||e.keyCode;27!=t&&13!=t&&this._onDelayedSearch(e)},l.prototype.highlight=function(e){this.locked||(this.node!=e&&(this.node&&this.node.setHighlight(!1),this.node=e,this.node.setHighlight(!0)),this._cancelUnhighlight())},l.prototype.unhighlight=function(){if(!this.locked){var e=this;this.node&&(this._cancelUnhighlight(),this.unhighlightTimer=setTimeout(function(){e.node.setHighlight(!1),e.node=void 0,e.unhighlightTimer=void 0},0))}},l.prototype._cancelUnhighlight=function(){this.unhighlightTimer&&(clearTimeout(this.unhighlightTimer),this.unhighlightTimer=void 0)},l.prototype.lock=function(){this.locked=!0},l.prototype.unlock=function(){this.locked=!1},util={},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var t=0;ti;++i)e.call(t||this,this[i],i,this)}),"undefined"==typeof console&&(console={log:function(){}}),util.parse=function(e){try{return JSON.parse(e)}catch(t){var i=util.validate(e)||t;throw new Error(i)}},util.validate=function(e){var t=void 0;try{"undefined"!=typeof jsonlint?jsonlint.parse(e):JSON.parse(e)}catch(i){t='
'+i.toString()+"
","undefined"!=typeof jsonlint&&(t+='validated by jsonlint')}return t},util.extend=function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);return e},util.clear=function(e){for(var t in e)e.hasOwnProperty(t)&&delete e[t];return e};var d=/^https?:\/\/\S+$/;util.isUrl=function(e){return("string"==typeof e||e instanceof String)&&d.test(e)},util.getAbsoluteLeft=function(e){for(var t=e.offsetLeft,i=document.body,n=e.offsetParent;null!=n&&e!=i;)t+=n.offsetLeft,t-=n.scrollLeft,n=n.offsetParent;return t},util.getAbsoluteTop=function(e){for(var t=e.offsetTop,i=document.body,n=e.offsetParent;null!=n&&n!=i;)t+=n.offsetTop,t-=n.scrollTop,n=n.offsetParent;return t},util.getMouseY=function(e){var t;return t="pageY"in e?e.pageY:e.clientY+document.documentElement.scrollTop},util.getMouseX=function(e){var t;return t="pageX"in e?e.pageX:e.clientX+document.documentElement.scrollLeft},util.getWindowHeight=function(){return"innerHeight"in window?window.innerHeight:Math.max(document.body.clientHeight,document.documentElement.clientHeight)},util.addClassName=function(e,t){var i=e.className.split(" ");i.indexOf(t)==-1&&(i.push(t),e.className=i.join(" "))},util.removeClassName=function(e,t){var i=e.className.split(" "),n=i.indexOf(t);-1!=n&&(i.splice(n,1),e.className=i.join(" "))},util.stripFormatting=function(e){for(var t=e.childNodes,i=0,n=t.length;n>i;i++){var o=t[i];o.style&&o.removeAttribute("style");var s=o.attributes;if(s)for(var r=s.length-1;r>=0;r--){var a=s[r];a.specified==1&&o.removeAttribute(a.name)}util.stripFormatting(o)}},util.setEndOfContentEditable=function(e){var t,i;document.createRange?(t=document.createRange(),t.selectNodeContents(e),t.collapse(!1),i=window.getSelection(),i.removeAllRanges(),i.addRange(t)):document.selection&&(t=document.body.createTextRange(),t.moveToElementText(e),t.collapse(!1),t.select())},util.selectContentEditable=function(e){if(e&&e.nodeName=="DIV"){var t,i;window.getSelection&&document.createRange?(i=document.createRange(),i.selectNodeContents(e),t=window.getSelection(),t.removeAllRanges(),t.addRange(i)):document.body.createTextRange&&(i=document.body.createTextRange(),i.moveToElementText(e),i.select())}},util.getSelection=function(){if(window.getSelection){var e=window.getSelection();if(e.getRangeAt&&e.rangeCount)return e.getRangeAt(0)}else if(document.selection&&document.selection.createRange)return document.selection.createRange();return null},util.setSelection=function(e){if(e)if(window.getSelection){var t=window.getSelection();t.removeAllRanges(),t.addRange(e)}else document.selection&&e.select&&e.select()},util.getSelectionOffset=function(){var e=util.getSelection();return e&&"startOffset"in e&&"endOffset"in e&&e.startContainer&&e.startContainer==e.endContainer?{startOffset:e.startOffset,endOffset:e.endOffset,container:e.startContainer.parentNode}:null},util.setSelectionOffset=function(e){if(document.createRange&&window.getSelection){var t=window.getSelection();if(t){var i=document.createRange();i.setStart(e.container.firstChild,e.startOffset),i.setEnd(e.container.firstChild,e.endOffset),util.setSelection(i)}}},util.getInnerText=function(e,t){var i=void 0==t;if(i&&(t={text:"",flush:function(){var e=this.text;return this.text="",e},set:function(e){this.text=e}}),e.nodeValue)return t.flush()+e.nodeValue;if(e.hasChildNodes()){for(var n=e.childNodes,o="",s=0,r=n.length;r>s;s++){var a=n[s];if(a.nodeName=="DIV"||a.nodeName=="P"){var l=n[s-1],d=l?l.nodeName:void 0;d&&"DIV"!=d&&"P"!=d&&"BR"!=d&&(o+="\n",t.flush()),o+=util.getInnerText(a,t),t.set("\n")}else a.nodeName=="BR"?(o+=t.flush(),t.set("\n")):o+=util.getInnerText(a,t)}return o}return e.nodeName=="P"&&util.getInternetExplorerVersion()!=-1?t.flush():""},util.getInternetExplorerVersion=function(){if(-1==h){var e=-1;if(navigator.appName=="Microsoft Internet Explorer"){var t=navigator.userAgent,i=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");i.exec(t)!=null&&(e=parseFloat(RegExp.$1))}h=e}return h};var h=-1;util.addEventListener=function(e,t,i,n){if(e.addEventListener)return void 0===n&&(n=!1),"mousewheel"===t&&navigator.userAgent.indexOf("Firefox")>=0&&(t="DOMMouseScroll"),e.addEventListener(t,i,n),i;var o=function(){return i.call(e,window.event)};return e.attachEvent("on"+t,o),o},util.removeEventListener=function(e,t,i,n){e.removeEventListener?(void 0===n&&(n=!1),"mousewheel"===t&&navigator.userAgent.indexOf("Firefox")>=0&&(t="DOMMouseScroll"),e.removeEventListener(t,i,n)):e.detachEvent("on"+t,i)},util.stopPropagation=function(e){e||(e=window.event),e.stopPropagation?e.stopPropagation():e.cancelBubble=!0},util.preventDefault=function(e){e||(e=window.event),e.preventDefault?e.preventDefault():e.returnValue=!1};var c={JSONEditor:e,JSONFormatter:function(){throw new Error('JSONFormatter is deprecated. Use JSONEditor with mode "text" or "code" instead')},util:util},u=function(){var e=document.getElementsByTagName("script"),t=e[e.length-1].src.split("?")[0],i=t.substring(0,t.length-2)+"css",n=document.createElement("link");n.type="text/css",n.rel="stylesheet",n.href=i,document.getElementsByTagName("head")[0].appendChild(n)};"undefined"!=typeof module&&"undefined"!=typeof exports&&(u(),module.exports=exports=c),"undefined"!=typeof require&&"undefined"!=typeof define?define(function(){return u(),c}):window.jsoneditor=c})(); \ No newline at end of file +(function(){function e(t,i,o){if(!(this instanceof e))throw new Error('JSONEditor constructor called without "new".');arguments.length&&this._create(t,i,o)}function t(e,i,o){if(!(this instanceof t))throw new Error('TreeEditor constructor called without "new".');this._create(e,i,o)}function i(e,t,o){if(!(this instanceof i))throw new Error('TextEditor constructor called without "new".');this._create(e,t,o)}function o(e,t){this.editor=e,this.dom={},this.expanded=!1,t&&t instanceof Object?(this.setField(t.field,t.fieldEditable),this.setValue(t.value,t.type)):(this.setField(""),this.setValue(null))}function n(e){this.editor=e,this.dom={}}function s(e,t){function i(e,t,n){n.forEach(function(n){if(n.type=="separator"){var s=document.createElement("div");s.className="separator",a=document.createElement("li"),a.appendChild(s),e.appendChild(a)}else{var r={},a=document.createElement("li");e.appendChild(a);var l=document.createElement("button");if(l.className=n.className,r.button=l,n.title&&(l.title=n.title),n.click&&(l.onclick=function(){o.hide(),n.click()}),a.appendChild(l),n.submenu){var d=document.createElement("div");d.className="icon",l.appendChild(d),l.appendChild(document.createTextNode(n.text));var h;if(n.click){l.className+=" default";var c=document.createElement("button");r.buttonExpand=c,c.className="expand",c.innerHTML='
',a.appendChild(c),n.submenuTitle&&(c.title=n.submenuTitle),h=c}else{var u=document.createElement("div");u.className="expand",l.appendChild(u),h=l}h.onclick=function(){o._onExpandItem(r),h.focus()};var p=[];r.subItems=p;var f=document.createElement("ul");r.ul=f,f.className="menu",f.style.height="0",a.appendChild(f),i(f,p,n.submenu)}else l.innerHTML='
'+n.text;t.push(r)}})}this.dom={};var o=this,n=this.dom;this.anchor=void 0,this.items=e,this.eventListeners={},this.selection=void 0,this.visibleSubmenu=void 0,this.onClose=t?t.close:void 0;var s=document.createElement("div");s.className="jsoneditor-contextmenu",n.menu=s;var r=document.createElement("ul");r.className="menu",s.appendChild(r),n.list=r,n.items=[];var a=document.createElement("button");n.focusButton=a;var l=document.createElement("li");l.style.overflow="hidden",l.style.height="0",l.appendChild(a),r.appendChild(l),i(r,this.dom.items,e),this.maxHeight=0,e.forEach(function(t){var i=(e.length+(t.submenu?t.submenu.length:0))*24;o.maxHeight=Math.max(o.maxHeight,i)})}function r(e){this.editor=e,this.clear(),this.actions={editField:{undo:function(e){e.node.updateField(e.oldValue)},redo:function(e){e.node.updateField(e.newValue)}},editValue:{undo:function(e){e.node.updateValue(e.oldValue)},redo:function(e){e.node.updateValue(e.newValue)}},appendNode:{undo:function(e){e.parent.removeChild(e.node)},redo:function(e){e.parent.appendChild(e.node)}},insertBeforeNode:{undo:function(e){e.parent.removeChild(e.node)},redo:function(e){e.parent.insertBefore(e.node,e.beforeNode)}},insertAfterNode:{undo:function(e){e.parent.removeChild(e.node)},redo:function(e){e.parent.insertAfter(e.node,e.afterNode)}},removeNode:{undo:function(e){var t=e.parent,i=t.childs[e.index]||t.append;t.insertBefore(e.node,i)},redo:function(e){e.parent.removeChild(e.node)}},duplicateNode:{undo:function(e){e.parent.removeChild(e.clone)},redo:function(e){e.parent.insertAfter(e.clone,e.node)}},changeType:{undo:function(e){e.node.changeType(e.oldType)},redo:function(e){e.node.changeType(e.newType)}},moveNode:{undo:function(e){e.startParent.moveTo(e.node,e.startIndex)},redo:function(e){e.endParent.moveTo(e.node,e.endIndex)}},sort:{undo:function(e){var t=e.node;t.hideChilds(),t.sort=e.oldSort,t.childs=e.oldChilds,t.showChilds()},redo:function(e){var t=e.node;t.hideChilds(),t.sort=e.newSort,t.childs=e.newChilds,t.showChilds()}}}}function a(e,t){var i=this;this.editor=e,this.timeout=void 0,this.delay=200,this.lastText=void 0,this.dom={},this.dom.container=t;var o=document.createElement("table");this.dom.table=o,o.className="search",t.appendChild(o);var n=document.createElement("tbody");this.dom.tbody=n,o.appendChild(n);var s=document.createElement("tr");n.appendChild(s);var r=document.createElement("td");s.appendChild(r);var a=document.createElement("div");this.dom.results=a,a.className="results",r.appendChild(a),r=document.createElement("td"),s.appendChild(r);var l=document.createElement("div");this.dom.input=l,l.className="frame",l.title="Search fields and values",r.appendChild(l);var d=document.createElement("table");l.appendChild(d);var h=document.createElement("tbody");d.appendChild(h),s=document.createElement("tr"),h.appendChild(s);var c=document.createElement("button");c.className="refresh",r=document.createElement("td"),r.appendChild(c),s.appendChild(r);var u=document.createElement("input");this.dom.search=u,u.oninput=function(e){i._onDelayedSearch(e)},u.onchange=function(e){i._onSearch(e)},u.onkeydown=function(e){i._onKeyDown(e)},u.onkeyup=function(e){i._onKeyUp(e)},c.onclick=function(){u.select()},r=document.createElement("td"),r.appendChild(u),s.appendChild(r);var p=document.createElement("button");p.title="Next result (Enter)",p.className="next",p.onclick=function(){i.next()},r=document.createElement("td"),r.appendChild(p),s.appendChild(r);var f=document.createElement("button");f.title="Previous result (Shift+Enter)",f.className="previous",f.onclick=function(){i.previous()},r=document.createElement("td"),r.appendChild(f),s.appendChild(r)}function l(){this.locked=!1}e.modes={},e.prototype._create=function(e,t,i){this.container=e,this.options=t||{},this.json=i||{};var o=this.options.mode||"tree";this.setMode(o)},e.prototype._delete=function(){},e.prototype.set=function(e){this.json=e},e.prototype.get=function(){return this.json},e.prototype.setText=function(e){this.json=util.parse(e)},e.prototype.getText=function(){return JSON.stringify(this.json)},e.prototype.setName=function(e){this.options||(this.options={}),this.options.name=e},e.prototype.getName=function(){return this.options&&this.options.name},e.prototype.setMode=function(t){var i,o,n=this.container,s=util.extend({},this.options);s.mode=t;var r=e.modes[t];if(!r)throw new Error('Unknown mode "'+s.mode+'"');try{if(r.data=="text"?(o=this.getName(),i=this.getText(),this._delete(),util.clear(this),util.extend(this,r.editor.prototype),this._create(n,s),this.setName(o),this.setText(i)):(o=this.getName(),i=this.get(),this._delete(),util.clear(this),util.extend(this,r.editor.prototype),this._create(n,s),this.setName(o),this.set(i)),typeof r.load=="function")try{r.load.call(this)}catch(a){}}catch(a){this._onError(a)}},e.prototype._onError=function(e){if(typeof this.onError=="function"&&(util.log("WARNING: JSONEditor.onError is deprecated. Use options.error instead."),this.onError(e)),typeof this.options.error!="function")throw e;this.options.error(e)},t.prototype._create=function(e,t,i){if("undefined"==typeof JSON)throw new Error("Your browser does not support JSON. \n\nPlease install the newest version of your browser.\n(all modern browsers support JSON).");if(!e)throw new Error("No container element provided.");this.container=e,this.dom={},this.highlighter=new l,this.selection=void 0,this._setOptions(t),this.options.history&&!this.mode.view&&(this.history=new r(this)),this._createFrame(),this._createTable(),this.set(i||{})},t.prototype._delete=function(){this.frame&&this.container&&this.frame.parentNode==this.container&&this.container.removeChild(this.frame)},t.prototype._setOptions=function(e){if(this.options={search:!0,history:!0,mode:"tree",name:void 0},e){for(var t in e)e.hasOwnProperty(t)&&(this.options[t]=e[t]);e.enableSearch&&(this.options.search=e.enableSearch,util.log('WARNING: Option "enableSearch" is deprecated. Use "search" instead.')),e.enableHistory&&(this.options.history=e.enableHistory,util.log('WARNING: Option "enableHistory" is deprecated. Use "history" instead.')),e.mode=="editor"&&(this.options.mode="tree",util.log('WARNING: Mode "editor" is deprecated. Use "tree" instead.')),e.mode=="viewer"&&(this.options.mode="view",util.log('WARNING: Mode "viewer" is deprecated. Use "view" instead.'))}this.mode={edit:this.options.mode!="view"&&this.options.mode!="form",view:this.options.mode=="view",form:this.options.mode=="form"}},t.focusNode=void 0,t.prototype.set=function(e,t){if(t&&(util.log('Warning: second parameter "name" is deprecated. Use setName(name) instead.'),this.options.name=t),e instanceof Function||void 0===e)this.clear();else{this.content.removeChild(this.table);var i={field:this.options.name,value:e},n=new o(this,i);this._setRoot(n);var s=!1;this.node.expand(s),this.content.appendChild(this.table)}this.history&&this.history.clear()},t.prototype.get=function(){return t.focusNode&&t.focusNode.blur(),this.node?this.node.getValue():void 0},t.prototype.getText=function(){return JSON.stringify(this.get())},t.prototype.setText=function(e){this.set(util.parse(e))},t.prototype.setName=function(e){this.options.name=e,this.node&&this.node.updateField(this.options.name)},t.prototype.getName=function(){return this.options.name},t.prototype.clear=function(){this.node&&(this.node.collapse(),this.tbody.removeChild(this.node.getDom()),delete this.node)},t.prototype._setRoot=function(e){this.clear(),this.node=e,this.tbody.appendChild(e.getDom())},t.prototype.search=function(e){var t;return this.node?(this.content.removeChild(this.table),t=this.node.search(e),this.content.appendChild(this.table)):t=[],t},t.prototype.expandAll=function(){this.node&&(this.content.removeChild(this.table),this.node.expand(),this.content.appendChild(this.table))},t.prototype.collapseAll=function(){this.node&&(this.content.removeChild(this.table),this.node.collapse(),this.content.appendChild(this.table))},t.prototype._onAction=function(e,t){if(this.history&&this.history.add(e,t),this.options.change)try{this.options.change()}catch(i){util.log("Error in change callback: ",i)}},t.prototype.startAutoScroll=function(e){var t=this,i=this.content,o=util.getAbsoluteTop(i),n=i.clientHeight,s=o+n,r=24,a=50;this.autoScrollStep=o+r>e&&i.scrollTop>0?(o+r-e)/3:e>s-r&&n+i.scrollTop3?(i.scrollTop+=n/3,o.animateCallback=t,o.animateTimeout=setTimeout(a,50)):(t&&t(!0),i.scrollTop=r,delete o.animateTimeout,delete o.animateCallback)};a()}else t&&t(!1)},t.prototype._createFrame=function(){this.frame=document.createElement("div"),this.frame.className="jsoneditor",this.container.appendChild(this.frame);var e=this,t=function(t){e._onEvent(t)};this.frame.onclick=function(e){e=e||window.event;var i=e.target||e.srcElement;t(e),i.nodeName=="BUTTON"&&util.preventDefault(e)},this.frame.oninput=t,this.frame.onchange=t,this.frame.onkeydown=t,this.frame.onkeyup=t,this.frame.oncut=t,this.frame.onpaste=t,this.frame.onmousedown=t,this.frame.onmouseup=t,this.frame.onmouseover=t,this.frame.onmouseout=t,util.addEventListener(this.frame,"focus",t,!0),util.addEventListener(this.frame,"blur",t,!0),this.frame.onfocusin=t,this.frame.onfocusout=t,this.menu=document.createElement("div"),this.menu.className="menu",this.frame.appendChild(this.menu);var i=document.createElement("button");i.className="expand-all",i.title="Expand all fields",i.onclick=function(){e.expandAll()},this.menu.appendChild(i);var o=document.createElement("button");if(o.title="Collapse all fields",o.className="collapse-all",o.onclick=function(){e.collapseAll()},this.menu.appendChild(o),this.history){var n=document.createElement("span");n.innerHTML=" ",this.menu.appendChild(n);var s=document.createElement("button");s.className="undo",s.title="Undo last action (Ctrl+Z)",s.onclick=function(){e._onUndo()},this.menu.appendChild(s),this.dom.undo=s;var r=document.createElement("button");r.className="redo",r.title="Redo (Ctrl+Shift+Z)",r.onclick=function(){e._onRedo()},this.menu.appendChild(r),this.dom.redo=r,this.history.onChange=function(){s.disabled=!e.history.canUndo(),r.disabled=!e.history.canRedo()},this.history.onChange()}this.options.search&&(this.searchBox=new a(this,this.menu))},t.prototype._onUndo=function(){this.history&&(this.history.undo(),this.options.change&&this.options.change())},t.prototype._onRedo=function(){this.history&&(this.history.redo(),this.options.change&&this.options.change())},t.prototype._onEvent=function(e){e=e||window.event;var i=e.target||e.srcElement;e.type=="keydown"&&this._onKeyDown(e),e.type=="focus"&&(t.domFocus=i);var n=o.getNodeFromTarget(i);n&&n.onEvent(e)},t.prototype._onKeyDown=function(e){var i=e.which||e.keyCode,o=e.ctrlKey,n=e.shiftKey,s=!1;if(9==i&&setTimeout(function(){util.selectContentEditable(t.domFocus)},0),this.searchBox)if(o&&70==i)this.searchBox.dom.search.focus(),this.searchBox.dom.search.select(),s=!0;else if(114==i||o&&71==i){var r=!0;n?this.searchBox.previous(r):this.searchBox.next(r),s=!0}this.history&&(o&&!n&&90==i?(this._onUndo(),s=!0):o&&n&&90==i&&(this._onRedo(),s=!0)),s&&(util.preventDefault(e),util.stopPropagation(e))},t.prototype._createTable=function(){var e=document.createElement("div");e.className="outer",this.contentOuter=e,this.content=document.createElement("div"),this.content.className="content",e.appendChild(this.content),this.table=document.createElement("table"),this.table.className="content",this.content.appendChild(this.table);var t=util.getInternetExplorerVersion();8==t&&(this.content.style.overflow="scroll");var i;this.colgroupContent=document.createElement("colgroup"),this.mode.edit&&(i=document.createElement("col"),i.width="24px",this.colgroupContent.appendChild(i)),i=document.createElement("col"),i.width="24px",this.colgroupContent.appendChild(i),i=document.createElement("col"),this.colgroupContent.appendChild(i),this.table.appendChild(this.colgroupContent),this.tbody=document.createElement("tbody"),this.table.appendChild(this.tbody),this.frame.appendChild(e)},e.modes.tree={editor:t,data:"json"},e.modes.view={editor:t,data:"json"},e.modes.form={editor:t,data:"json"},e.modes.editor={editor:t,data:"json"},e.modes.viewer={editor:t,data:"json"},i.prototype._create=function(e,t,i){if("undefined"==typeof JSON)throw new Error("Your browser does not support JSON. \n\nPlease install the newest version of your browser.\n(all modern browsers support JSON).");t=t||{},t.indentation&&(this.indentation=Number(t.indentation)),this.options=t,this.mode=t.mode=="code"?"code":"text",this.mode=="code"&&("undefined"==typeof ace&&(this.mode="text",util.log("WARNING: Cannot load code editor, Ace library not loaded. Falling back to plain text editor")),util.getInternetExplorerVersion()==8&&(this.mode="text",util.log("WARNING: Cannot load code editor, Ace is not supported on IE8. Falling back to plain text editor")));var o=this;this.container=e,this.editor=void 0,this.textarea=void 0,this.indentation=4,this.width=e.clientWidth,this.height=e.clientHeight,this.frame=document.createElement("div"),this.frame.className="jsoneditor",this.frame.onclick=function(e){util.preventDefault(e)},this.menu=document.createElement("div"),this.menu.className="menu",this.frame.appendChild(this.menu);var n=document.createElement("button");n.className="format",n.title="Format JSON data, with proper indentation and line feeds",this.menu.appendChild(n),n.onclick=function(){try{o.format()}catch(e){o._onError(e)}};var s=document.createElement("button");if(s.className="compact",s.title="Compact JSON data, remove all whitespaces",this.menu.appendChild(s),s.onclick=function(){try{o.compact()}catch(e){o._onError(e)}},this.content=document.createElement("div"),this.content.className="outer",this.frame.appendChild(this.content),this.container.appendChild(this.frame),this.mode=="code"){this.editorDom=document.createElement("div"),this.editorDom.style.height="100%",this.editorDom.style.width="100%",this.content.appendChild(this.editorDom);var r=ace.edit(this.editorDom);r.setTheme("ace/theme/jsoneditor"),r.setShowPrintMargin(!1),r.setFontSize(13),r.getSession().setMode("ace/mode/json"),r.getSession().setUseSoftTabs(!0),r.getSession().setUseWrapMode(!0),this.editor=r;var a=document.createElement("a");a.appendChild(document.createTextNode("powered by ace")),a.href="http://ace.ajax.org",a.target="_blank",a.className="poweredBy",a.onclick=function(){window.open(a.href,a.target)},this.menu.appendChild(a),t.change&&r.on("change",function(){t.change()})}else{var l=document.createElement("textarea");l.className="content",l.spellcheck=!1,this.content.appendChild(l),this.textarea=l,t.change&&(this.textarea.oninput===null?this.textarea.oninput=function(){t.change()}:this.textarea.onchange=function(){t.change()})}"string"==typeof i?this.setText(i):this.set(i)},i.prototype._delete=function(){this.frame&&this.container&&this.frame.parentNode==this.container&&this.container.removeChild(this.frame)},i.prototype._onError=function(e){if(typeof this.onError=="function"&&(util.log("WARNING: JSONEditor.onError is deprecated. Use options.error instead."),this.onError(e)),typeof this.options.error!="function")throw e;this.options.error(e)},i.prototype.compact=function(){var e=util.parse(this.getText());this.setText(JSON.stringify(e))},i.prototype.format=function(){var e=util.parse(this.getText());this.setText(JSON.stringify(e,null,this.indentation))},i.prototype.focus=function(){this.textarea&&this.textarea.focus(),this.editor&&this.editor.focus()},i.prototype.resize=function(){if(this.editor){var e=!1;this.editor.resize(e)}},i.prototype.set=function(e){this.setText(JSON.stringify(e,null,this.indentation))},i.prototype.get=function(){return util.parse(this.getText())},i.prototype.getText=function(){return this.textarea?this.textarea.value:this.editor?this.editor.getValue():""},i.prototype.setText=function(e){this.textarea&&(this.textarea.value=e),this.editor&&this.editor.setValue(e,-1)},e.modes.text={editor:i,data:"text",load:i.prototype.format},e.modes.code={editor:i,data:"text",load:i.prototype.format},o.prototype.setParent=function(e){this.parent=e},o.prototype.setField=function(e,t){this.field=e,this.fieldEditable=1==t},o.prototype.getField=function(){return this.field===void 0&&this._getDomField(),this.field},o.prototype.setValue=function(e,t){var i,n,s=this.childs;if(s)for(;s.length;)this.removeChild(s[0]);if(this.type=this._getType(e),t&&t!=this.type){if("string"!=t||this.type!="auto")throw new Error('Type mismatch: cannot cast value of type "'+this.type+' to the specified type "'+t+'"');this.type=t}if(this.type=="array"){this.childs=[];for(var r=0,a=e.length;a>r;r++)i=e[r],void 0===i||i instanceof Function||(n=new o(this.editor,{value:i}),this.appendChild(n));this.value=""}else if(this.type=="object"){this.childs=[];for(var l in e)e.hasOwnProperty(l)&&(i=e[l],void 0===i||i instanceof Function||(n=new o(this.editor,{field:l,value:i}),this.appendChild(n)));this.value=""}else this.childs=void 0,this.value=e},o.prototype.getValue=function(){if(this.type=="array"){var e=[];return this.childs.forEach(function(t){e.push(t.getValue())}),e}if(this.type=="object"){var t={};return this.childs.forEach(function(e){t[e.getField()]=e.getValue()}),t}return this.value===void 0&&this._getDomValue(),this.value},o.prototype.getLevel=function(){return this.parent?this.parent.getLevel()+1:0},o.prototype.clone=function(){var e=new o(this.editor);if(e.type=this.type,e.field=this.field,e.fieldInnerText=this.fieldInnerText,e.fieldEditable=this.fieldEditable,e.value=this.value,e.valueInnerText=this.valueInnerText,e.expanded=this.expanded,this.childs){var t=[];this.childs.forEach(function(i){var o=i.clone();o.setParent(e),t.push(o)}),e.childs=t}else e.childs=void 0;return e},o.prototype.expand=function(e){this.childs&&(this.expanded=!0,this.dom.expand&&(this.dom.expand.className="expanded"),this.showChilds(),0!=e&&this.childs.forEach(function(t){t.expand(e)}))},o.prototype.collapse=function(e){this.childs&&(this.hideChilds(),0!=e&&this.childs.forEach(function(t){t.collapse(e)}),this.dom.expand&&(this.dom.expand.className="collapsed"),this.expanded=!1)},o.prototype.showChilds=function(){var e=this.childs;if(e&&this.expanded){var t=this.dom.tr,i=t?t.parentNode:void 0;if(i){var o=this.getAppend(),n=t.nextSibling;n?i.insertBefore(o,n):i.appendChild(o),this.childs.forEach(function(e){i.insertBefore(e.getDom(),o),e.showChilds()})}}},o.prototype.hide=function(){var e=this.dom.tr,t=e?e.parentNode:void 0;t&&t.removeChild(e),this.hideChilds()},o.prototype.hideChilds=function(){var e=this.childs;if(e&&this.expanded){var t=this.getAppend();t.parentNode&&t.parentNode.removeChild(t),this.childs.forEach(function(e){e.hide()})}},o.prototype.appendChild=function(e){if(this._hasChilds()){if(e.setParent(this),e.fieldEditable=this.type=="object",this.type=="array"&&(e.index=this.childs.length),this.childs.push(e),this.expanded){var t=e.getDom(),i=this.getAppend(),o=i?i.parentNode:void 0;i&&o&&o.insertBefore(t,i),e.showChilds()}this.updateDom({updateIndexes:!0}),e.updateDom({recurse:!0})}},o.prototype.moveBefore=function(e,t){if(this._hasChilds()){var i=this.dom.tr?this.dom.tr.parentNode:void 0;if(i){var o=document.createElement("tr");o.style.height=i.clientHeight+"px",i.appendChild(o)}e.parent&&e.parent.removeChild(e),t instanceof n?this.appendChild(e):this.insertBefore(e,t),i&&i.removeChild(o)}},o.prototype.moveTo=function(e,t){if(e.parent==this){var i=this.childs.indexOf(e);t>i&&t++}var o=this.childs[t]||this.append;this.moveBefore(e,o)},o.prototype.insertBefore=function(e,t){if(this._hasChilds()){if(t==this.append)e.setParent(this),e.fieldEditable=this.type=="object",this.childs.push(e);else{var i=this.childs.indexOf(t);if(-1==i)throw new Error("Node not found");e.setParent(this),e.fieldEditable=this.type=="object",this.childs.splice(i,0,e)}if(this.expanded){var o=e.getDom(),n=t.getDom(),s=n?n.parentNode:void 0;n&&s&&s.insertBefore(o,n),e.showChilds()}this.updateDom({updateIndexes:!0}),e.updateDom({recurse:!0})}},o.prototype.insertAfter=function(e,t){if(this._hasChilds()){var i=this.childs.indexOf(t),o=this.childs[i+1];o?this.insertBefore(e,o):this.appendChild(e)}},o.prototype.search=function(e){var t,i=[],o=e?e.toLowerCase():void 0;if(delete this.searchField,delete this.searchValue,this.field!=void 0){var n=String(this.field).toLowerCase();t=n.indexOf(o),-1!=t&&(this.searchField=!0,i.push({node:this,elem:"field"})),this._updateDomField()}if(this._hasChilds()){if(this.childs){var s=[];this.childs.forEach(function(t){s=s.concat(t.search(e))}),i=i.concat(s)}if(void 0!=o){var r=!1;s.length==0?this.collapse(r):this.expand(r)}}else{if(this.value!=void 0){var a=String(this.value).toLowerCase();t=a.indexOf(o),-1!=t&&(this.searchValue=!0,i.push({node:this,elem:"value"}))}this._updateDomValue()}return i},o.prototype.scrollTo=function(e){if(!this.dom.tr||!this.dom.tr.parentNode)for(var t=this.parent,i=!1;t;)t.expand(i),t=t.parent;this.dom.tr&&this.dom.tr.parentNode&&this.editor.scrollTo(this.dom.tr.offsetTop,e)},o.focusElement=void 0,o.prototype.focus=function(e){if(o.focusElement=e,this.dom.tr&&this.dom.tr.parentNode){var t=this.dom;switch(e){case"drag":t.drag?t.drag.focus():t.menu.focus();break;case"menu":t.menu.focus();break;case"expand":this._hasChilds()?t.expand.focus():t.field&&this.fieldEditable?(t.field.focus(),util.selectContentEditable(t.field)):t.value&&!this._hasChilds()?(t.value.focus(),util.selectContentEditable(t.value)):t.menu.focus();break;case"field":t.field&&this.fieldEditable?(t.field.focus(),util.selectContentEditable(t.field)):t.value&&!this._hasChilds()?(t.value.focus(),util.selectContentEditable(t.value)):this._hasChilds()?t.expand.focus():t.menu.focus();break;case"value":default:t.value&&!this._hasChilds()?(t.value.focus(),util.selectContentEditable(t.value)):t.field&&this.fieldEditable?(t.field.focus(),util.selectContentEditable(t.field)):this._hasChilds()?t.expand.focus():t.menu.focus()}}},o.select=function(e){setTimeout(function(){util.selectContentEditable(e)},0)},o.prototype.blur=function(){this._getDomValue(!1),this._getDomField(!1)},o.prototype._duplicate=function(e){var t=e.clone();return this.insertAfter(t,e),t},o.prototype.containsNode=function(e){if(this==e)return!0;var t=this.childs;if(t)for(var i=0,o=t.length;o>i;i++)if(t[i].containsNode(e))return!0;return!1},o.prototype._move=function(e,t){if(e!=t){if(e.containsNode(this))throw new Error("Cannot move a field into a child of itself");e.parent&&e.parent.removeChild(e);var i=e.clone();e.clearDom(),t?this.insertBefore(i,t):this.appendChild(i)}},o.prototype.removeChild=function(e){if(this.childs){var t=this.childs.indexOf(e);if(-1!=t){e.hide(),delete e.searchField,delete e.searchValue;var i=this.childs.splice(t,1)[0];return this.updateDom({updateIndexes:!0}),i}}return void 0},o.prototype._remove=function(e){this.removeChild(e)},o.prototype.changeType=function(e){var t=this.type;if(t!=e){if("string"!=e&&"auto"!=e||"string"!=t&&"auto"!=t){var i,o=this.dom.tr?this.dom.tr.parentNode:void 0;i=this.expanded?this.getAppend():this.getDom();var n=i&&i.parentNode?i.nextSibling:void 0;this.hide(),this.clearDom(),this.type=e,"object"==e?(this.childs||(this.childs=[]),this.childs.forEach(function(e){e.clearDom(),delete e.index,e.fieldEditable=!0,e.field==void 0&&(e.field="")}),("string"==t||"auto"==t)&&(this.expanded=!0)):"array"==e?(this.childs||(this.childs=[]),this.childs.forEach(function(e,t){e.clearDom(),e.fieldEditable=!1,e.index=t}),("string"==t||"auto"==t)&&(this.expanded=!0)):this.expanded=!1,o&&(n?o.insertBefore(this.getDom(),n):o.appendChild(this.getDom())),this.showChilds()}else this.type=e;("auto"==e||"string"==e)&&(this.value="string"==e?String(this.value):this._stringCast(String(this.value)),this.focus()),this.updateDom({updateIndexes:!0})}},o.prototype._getDomValue=function(e){if(this.dom.value&&this.type!="array"&&this.type!="object"&&(this.valueInnerText=util.getInnerText(this.dom.value)),this.valueInnerText!=void 0)try{var t;if(this.type=="string")t=this._unescapeHTML(this.valueInnerText);else{var i=this._unescapeHTML(this.valueInnerText);t=this._stringCast(i)}if(t!==this.value){var o=this.value;this.value=t,this.editor._onAction("editValue",{node:this,oldValue:o,newValue:t,oldSelection:this.editor.selection,newSelection:this.editor.getSelection()})}}catch(n){if(this.value=void 0,1!=e)throw n}},o.prototype._updateDomValue=function(){var e=this.dom.value;if(e){var t=this.value,i=this.type=="auto"?typeof t:this.type,o="string"==i&&util.isUrl(t),n="";n=o&&!this.editor.mode.edit?"":"string"==i?"green":"number"==i?"red":"boolean"==i?"orange":this._hasChilds()?"":null===t?"#004ED0":"black",e.style.color=n;var s=String(this.value)==""&&this.type!="array"&&this.type!="object";if(s?util.addClassName(e,"empty"):util.removeClassName(e,"empty"),o?util.addClassName(e,"url"):util.removeClassName(e,"url"),"array"==i||"object"==i){var r=this.childs?this.childs.length:0;e.title=this.type+" containing "+r+" items"}else"string"==i&&util.isUrl(t)?this.editor.mode.edit&&(e.title="Ctrl+Click or Ctrl+Enter to open url in new window"):e.title="";this.searchValueActive?util.addClassName(e,"highlight-active"):util.removeClassName(e,"highlight-active"),this.searchValue?util.addClassName(e,"highlight"):util.removeClassName(e,"highlight"),util.stripFormatting(e)}},o.prototype._updateDomField=function(){var e=this.dom.field;if(e){var t=String(this.field)==""&&this.parent.type!="array";t?util.addClassName(e,"empty"):util.removeClassName(e,"empty"),this.searchFieldActive?util.addClassName(e,"highlight-active"):util.removeClassName(e,"highlight-active"),this.searchField?util.addClassName(e,"highlight"):util.removeClassName(e,"highlight"),util.stripFormatting(e)}},o.prototype._getDomField=function(e){if(this.dom.field&&this.fieldEditable&&(this.fieldInnerText=util.getInnerText(this.dom.field)),this.fieldInnerText!=void 0)try{var t=this._unescapeHTML(this.fieldInnerText);if(t!==this.field){var i=this.field;this.field=t,this.editor._onAction("editField",{node:this,oldValue:i,newValue:t,oldSelection:this.editor.selection,newSelection:this.editor.getSelection()})}}catch(o){if(this.field=void 0,1!=e)throw o}},o.prototype.clearDom=function(){this.dom={}},o.prototype.getDom=function(){var e=this.dom;if(e.tr)return e.tr;if(e.tr=document.createElement("tr"),e.tr.node=this,this.editor.mode.edit){var t=document.createElement("td");if(this.parent){var i=document.createElement("button");e.drag=i,i.className="dragarea",i.title="Drag to move this field (Alt+Shift+Arrows)",t.appendChild(i)}e.tr.appendChild(t);var o=document.createElement("td"),n=document.createElement("button");e.menu=n,n.className="contextmenu",n.title="Click to open the actions menu (Ctrl+M)",o.appendChild(e.menu),e.tr.appendChild(o)}var s=document.createElement("td");return e.tr.appendChild(s),e.tree=this._createDomTree(),s.appendChild(e.tree),this.updateDom({updateIndexes:!0}),e.tr},o.prototype._onDragStart=function(e){e=e||window.event;var t=this;this.mousemove||(this.mousemove=util.addEventListener(document,"mousemove",function(e){t._onDrag(e)})),this.mouseup||(this.mouseup=util.addEventListener(document,"mouseup",function(e){t._onDragEnd(e)})),this.editor.highlighter.lock(),this.drag={oldCursor:document.body.style.cursor,startParent:this.parent,startIndex:this.parent.childs.indexOf(this),mouseX:util.getMouseX(e),level:this.getLevel()},document.body.style.cursor="move",util.preventDefault(e)},o.prototype._onDrag=function(e){e=e||window.event;var t,i,s,r,a,l,d,h,c,u,p,f,m,v,g=util.getMouseY(e),y=util.getMouseX(e),x=!1;if(t=this.dom.tr,c=util.getAbsoluteTop(t),f=t.offsetHeight,c>g){i=t;do i=i.previousSibling,d=o.getNodeFromTarget(i),u=i?util.getAbsoluteTop(i):0;while(i&&u>g);d&&!d.parent&&(d=void 0),d||(l=t.parentNode.firstChild,i=l?l.nextSibling:void 0,d=o.getNodeFromTarget(i),d==this&&(d=void 0)),d&&(i=d.dom.tr,u=i?util.getAbsoluteTop(i):0,g>u+f&&(d=void 0)),d&&(d.parent.moveBefore(this,d),x=!0)}else if(a=this.expanded&&this.append?this.append.getDom():this.dom.tr,r=a?a.nextSibling:void 0){p=util.getAbsoluteTop(r),s=r;do h=o.getNodeFromTarget(s),s&&(m=s.nextSibling?util.getAbsoluteTop(s.nextSibling):0,v=s?m-p:0,h.parent.childs.length==1&&h.parent.childs[0]==this&&(c+=23)),s=s.nextSibling;while(s&&g>c+v);if(h&&h.parent){var b=y-this.drag.mouseX,C=Math.round(b/24/2),N=this.drag.level+C,E=h.getLevel();for(i=h.dom.tr.previousSibling;N>E&&i;){if(d=o.getNodeFromTarget(i),d==this||d._isChildOf(this));else{if(!(d instanceof n))break;var _=d.parent.childs;if(!(_.length>1||_.length==1&&_[0]!=this))break;h=o.getNodeFromTarget(i),E=h.getLevel()}i=i.previousSibling}a.nextSibling!=h.dom.tr&&(h.parent.moveBefore(this,h),x=!0)}}x&&(this.drag.mouseX=y,this.drag.level=this.getLevel()),this.editor.startAutoScroll(g),util.preventDefault(e)},o.prototype._onDragEnd=function(e){e=e||window.event;var t={node:this,startParent:this.drag.startParent,startIndex:this.drag.startIndex,endParent:this.parent,endIndex:this.parent.childs.indexOf(this)};(t.startParent!=t.endParent||t.startIndex!=t.endIndex)&&this.editor._onAction("moveNode",t),document.body.style.cursor=this.drag.oldCursor,this.editor.highlighter.unlock(),delete this.drag,this.mousemove&&(util.removeEventListener(document,"mousemove",this.mousemove),delete this.mousemove),this.mouseup&&(util.removeEventListener(document,"mouseup",this.mouseup),delete this.mouseup),this.editor.stopAutoScroll(),util.preventDefault(e) +},o.prototype._isChildOf=function(e){for(var t=this.parent;t;){if(t==e)return!0;t=t.parent}return!1},o.prototype._createDomField=function(){return document.createElement("div")},o.prototype.setHighlight=function(e){this.dom.tr&&(this.dom.tr.className=e?"highlight":"",this.append&&this.append.setHighlight(e),this.childs&&this.childs.forEach(function(t){t.setHighlight(e)}))},o.prototype.updateValue=function(e){this.value=e,this.updateDom()},o.prototype.updateField=function(e){this.field=e,this.updateDom()},o.prototype.updateDom=function(e){var t=this.dom.tree;t&&(t.style.marginLeft=this.getLevel()*24+"px");var i=this.dom.field;if(i){this.fieldEditable==1?(i.contentEditable=this.editor.mode.edit,i.spellcheck=!1,i.className="field"):i.className="readonly";var o;o=this.index!=void 0?this.index:this.field!=void 0?this.field:this._hasChilds()?this.type:"",i.innerHTML=this._escapeHTML(o)}var n=this.dom.value;if(n){var s=this.childs?this.childs.length:0;n.innerHTML=this.type=="array"?"["+s+"]":this.type=="object"?"{"+s+"}":this._escapeHTML(this.value)}this._updateDomField(),this._updateDomValue(),e&&e.updateIndexes==1&&this._updateDomIndexes(),e&&e.recurse==1&&this.childs&&this.childs.forEach(function(t){t.updateDom(e)}),this.append&&this.append.updateDom()},o.prototype._updateDomIndexes=function(){var e=this.dom.value,t=this.childs;e&&t&&(this.type=="array"?t.forEach(function(e,t){e.index=t;var i=e.dom.field;i&&(i.innerHTML=t)}):this.type=="object"&&t.forEach(function(e){e.index!=void 0&&(delete e.index,e.field==void 0&&(e.field=""))}))},o.prototype._createDomValue=function(){var e;return this.type=="array"?(e=document.createElement("div"),e.className="readonly",e.innerHTML="[...]"):this.type=="object"?(e=document.createElement("div"),e.className="readonly",e.innerHTML="{...}"):!this.editor.mode.edit&&util.isUrl(this.value)?(e=document.createElement("a"),e.className="value",e.href=this.value,e.target="_blank",e.innerHTML=this._escapeHTML(this.value)):(e=document.createElement("div"),e.contentEditable=!this.editor.mode.view,e.spellcheck=!1,e.className="value",e.innerHTML=this._escapeHTML(this.value)),e},o.prototype._createDomExpandButton=function(){var e=document.createElement("button");return this._hasChilds()?(e.className=this.expanded?"expanded":"collapsed",e.title="Click to expand/collapse this field (Ctrl+E). \nCtrl+Click to expand/collapse including all childs."):(e.className="invisible",e.title=""),e},o.prototype._createDomTree=function(){var e=this.dom,t=document.createElement("table"),i=document.createElement("tbody");t.style.borderCollapse="collapse",t.appendChild(i);var o=document.createElement("tr");i.appendChild(o);var n=document.createElement("td");n.className="tree",o.appendChild(n),e.expand=this._createDomExpandButton(),n.appendChild(e.expand),e.tdExpand=n;var s=document.createElement("td");s.className="tree",o.appendChild(s),e.field=this._createDomField(),s.appendChild(e.field),e.tdField=s;var r=document.createElement("td");r.className="tree",o.appendChild(r),this.type!="object"&&this.type!="array"&&(r.appendChild(document.createTextNode(":")),r.className="separator"),e.tdSeparator=r;var a=document.createElement("td");return a.className="tree",o.appendChild(a),e.value=this._createDomValue(),a.appendChild(e.value),e.tdValue=a,t},o.prototype.onEvent=function(e){var t,i=e.type,o=e.target||e.srcElement,n=this.dom,s=this,r=this._hasChilds();if((o==n.drag||o==n.menu)&&("mouseover"==i?this.editor.highlighter.highlight(this):"mouseout"==i&&this.editor.highlighter.unhighlight()),"mousedown"==i&&o==n.drag&&this._onDragStart(e),"click"==i&&o==n.menu){var a=s.editor.highlighter;a.highlight(s),a.lock(),util.addClassName(n.menu,"selected"),this.showContextMenu(n.menu,function(){util.removeClassName(n.menu,"selected"),a.unlock(),a.unhighlight()})}if("click"==i&&o==n.expand&&r){var l=e.ctrlKey;this._onExpand(l)}var d=n.value;if(o==d)switch(i){case"focus":t=this;break;case"blur":case"change":this._getDomValue(!0),this._updateDomValue(),this.value&&(d.innerHTML=this._escapeHTML(this.value));break;case"input":this._getDomValue(!0),this._updateDomValue();break;case"keydown":case"mousedown":this.editor.selection=this.editor.getSelection();break;case"click":e.ctrlKey&&this.editor.mode.edit&&util.isUrl(this.value)&&window.open(this.value,"_blank");break;case"keyup":this._getDomValue(!0),this._updateDomValue();break;case"cut":case"paste":setTimeout(function(){s._getDomValue(!0),s._updateDomValue()},1)}var h=n.field;if(o==h)switch(i){case"focus":t=this;break;case"blur":case"change":this._getDomField(!0),this._updateDomField(),this.field&&(h.innerHTML=this._escapeHTML(this.field));break;case"input":this._getDomField(!0),this._updateDomField();break;case"keydown":case"mousedown":this.editor.selection=this.editor.getSelection();break;case"keyup":this._getDomField(!0),this._updateDomField();break;case"cut":case"paste":setTimeout(function(){s._getDomField(!0),s._updateDomField()},1)}var c=n.tree;if(o==c.parentNode)switch(i){case"click":var u=e.offsetX!=void 0?e.offsetX<(this.getLevel()+1)*24:util.getMouseX(e)o[i]?t:e[i]/g,">").replace(/ /g,"  ").replace(/^ /," ").replace(/ $/," "),i=JSON.stringify(t);return i.substring(1,i.length-1)},o.prototype._unescapeHTML=function(e){var t='"'+this._escapeJSON(e)+'"',i=util.parse(t);return i.replace(/</g,"<").replace(/>/g,">").replace(/ /g," ")},o.prototype._escapeJSON=function(e){for(var t="",i=0,o=e.length;o>i;){var n=e.charAt(i);"\n"==n?t+="\\n":"\\"==n?(t+=n,i++,n=e.charAt(i),'"\\/bfnrtu'.indexOf(n)==-1&&(t+="\\"),t+=n):t+='"'==n?'\\"':n,i++}return t},n.prototype=new o,n.prototype.getDom=function(){var e=this.dom;if(e.tr)return e.tr;var t=document.createElement("tr");if(t.node=this,e.tr=t,this.editor.mode.edit){e.tdDrag=document.createElement("td");var i=document.createElement("td");e.tdMenu=i;var o=document.createElement("button");o.className="contextmenu",o.title="Click to open the actions menu (Ctrl+M)",e.menu=o,i.appendChild(e.menu)}var n=document.createElement("td"),s=document.createElement("div");return s.innerHTML="(empty)",s.className="readonly",n.appendChild(s),e.td=n,e.text=s,this.updateDom(),t},n.prototype.updateDom=function(){var e=this.dom,t=e.td;t&&(t.style.paddingLeft=this.getLevel()*24+26+"px");var i=e.text;i&&(i.innerHTML="(empty "+this.parent.type+")");var o=e.tr;this.isVisible()?e.tr.firstChild||(e.tdDrag&&o.appendChild(e.tdDrag),e.tdMenu&&o.appendChild(e.tdMenu),o.appendChild(t)):e.tr.firstChild&&(e.tdDrag&&o.removeChild(e.tdDrag),e.tdMenu&&o.removeChild(e.tdMenu),o.removeChild(t))},n.prototype.isVisible=function(){return this.parent.childs.length==0},n.prototype.showContextMenu=function(e,t){var i=this,n=o.TYPE_TITLES,r=[{text:"Append",title:"Append a new field with type 'auto' (Ctrl+Shift+Ins)",submenuTitle:"Select the type of the field to be appended",className:"insert",click:function(){i._onAppend("","","auto")},submenu:[{text:"Auto",className:"type-auto",title:n.auto,click:function(){i._onAppend("","","auto")}},{text:"Array",className:"type-array",title:n.array,click:function(){i._onAppend("",[])}},{text:"Object",className:"type-object",title:n.object,click:function(){i._onAppend("",{})}},{text:"String",className:"type-string",title:n.string,click:function(){i._onAppend("","","string")}}]}],a=new s(r,{close:t});a.show(e)},n.prototype.onEvent=function(e){var t=e.type,i=e.target||e.srcElement,o=this.dom,n=o.menu;if(i==n&&("mouseover"==t?this.editor.highlighter.highlight(this.parent):"mouseout"==t&&this.editor.highlighter.unhighlight()),"click"==t&&i==o.menu){var s=this.editor.highlighter;s.highlight(this.parent),s.lock(),util.addClassName(o.menu,"selected"),this.showContextMenu(o.menu,function(){util.removeClassName(o.menu,"selected"),s.unlock(),s.unhighlight()})}"keydown"==t&&this.onKeyDown(e)},s.prototype._getVisibleButtons=function(){var e=[],t=this;return this.dom.items.forEach(function(i){e.push(i.button),i.buttonExpand&&e.push(i.buttonExpand),i.subItems&&i==t.expandedItem&&i.subItems.forEach(function(t){e.push(t.button),t.buttonExpand&&e.push(t.buttonExpand)})}),e},s.visibleMenu=void 0,s.prototype.show=function(e){this.hide();var t=util.getWindowHeight(),i=e.offsetHeight,o=this.maxHeight,n=util.getAbsoluteLeft(e),r=util.getAbsoluteTop(e);t>r+i+o?(this.dom.menu.style.left=n+"px",this.dom.menu.style.top=r+i+"px",this.dom.menu.style.bottom=""):(this.dom.menu.style.left=n+"px",this.dom.menu.style.top="",this.dom.menu.style.bottom=t-r+"px"),document.body.appendChild(this.dom.menu);var a=this,l=this.dom.list;this.eventListeners.mousedown=util.addEventListener(document,"mousedown",function(e){e=e||window.event;var t=e.target||e.srcElement;t==l||a._isChildOf(t,l)||(a.hide(),util.stopPropagation(e),util.preventDefault(e))}),this.eventListeners.mousewheel=util.addEventListener(document,"mousewheel",function(){util.stopPropagation(event),util.preventDefault(event)}),this.eventListeners.keydown=util.addEventListener(document,"keydown",function(e){a._onKeyDown(e)}),this.selection=util.getSelection(),this.anchor=e,setTimeout(function(){a.dom.focusButton.focus()},0),s.visibleMenu&&s.visibleMenu.hide(),s.visibleMenu=this},s.prototype.hide=function(){this.dom.menu.parentNode&&(this.dom.menu.parentNode.removeChild(this.dom.menu),this.onClose&&this.onClose());for(var e in this.eventListeners)if(this.eventListeners.hasOwnProperty(e)){var t=this.eventListeners[e];t&&util.removeEventListener(document,e,t),delete this.eventListeners[e]}s.visibleMenu==this&&(s.visibleMenu=void 0)},s.prototype._onExpandItem=function(e){var t=this,i=e==this.expandedItem,o=this.expandedItem;if(o&&(o.ul.style.height="0",o.ul.style.padding="",setTimeout(function(){t.expandedItem!=o&&(o.ul.style.display="",util.removeClassName(o.ul.parentNode,"selected"))},300),this.expandedItem=void 0),!i){var n=e.ul;n.style.display="block",n.clientHeight,setTimeout(function(){t.expandedItem==e&&(n.style.height=n.childNodes.length*24+"px",n.style.padding="5px 10px")},0),util.addClassName(n.parentNode,"selected"),this.expandedItem=e}},s.prototype._onKeyDown=function(e){e=e||window.event;var t,i,o,n,s=e.target||e.srcElement,r=e.which||e.keyCode,a=!1;27==r?(this.selection&&util.setSelection(this.selection),this.anchor&&this.anchor.focus(),this.hide(),a=!0):9==r?e.shiftKey?(t=this._getVisibleButtons(),i=t.indexOf(s),0==i&&(t[t.length-1].focus(),a=!0)):(t=this._getVisibleButtons(),i=t.indexOf(s),i==t.length-1&&(t[0].focus(),a=!0)):37==r?(s.className=="expand"&&(t=this._getVisibleButtons(),i=t.indexOf(s),o=t[i-1],o&&o.focus()),a=!0):38==r?(t=this._getVisibleButtons(),i=t.indexOf(s),o=t[i-1],o&&o.className=="expand"&&(o=t[i-2]),o||(o=t[t.length-1]),o&&o.focus(),a=!0):39==r?(t=this._getVisibleButtons(),i=t.indexOf(s),n=t[i+1],n&&n.className=="expand"&&n.focus(),a=!0):40==r&&(t=this._getVisibleButtons(),i=t.indexOf(s),n=t[i+1],n&&n.className=="expand"&&(n=t[i+2]),n||(n=t[0]),n&&(n.focus(),a=!0),a=!0),a&&(util.stopPropagation(e),util.preventDefault(e))},s.prototype._isChildOf=function(e,t){for(var i=e.parentNode;i;){if(i==t)return!0;i=i.parentNode}return!1},r.prototype.onChange=function(){},r.prototype.add=function(e,t){this.index++,this.history[this.index]={action:e,params:t,timestamp:new Date},this.index=0},r.prototype.canRedo=function(){return this.indexthis.results.length-1&&(t=0),this._setActiveResult(t,e)}},a.prototype.previous=function(e){if(this.results!=void 0){var t=this.results.length-1,i=this.resultIndex!=void 0?this.resultIndex-1:t;0>i&&(i=t),this._setActiveResult(i,e)}},a.prototype._setActiveResult=function(e,t){if(this.activeResult){var i=this.activeResult.node,o=this.activeResult.elem;"field"==o?delete i.searchFieldActive:delete i.searchValueActive,i.updateDom()}if(!this.results||!this.results[e])return this.resultIndex=void 0,this.activeResult=void 0,void 0;this.resultIndex=e;var n=this.results[this.resultIndex].node,s=this.results[this.resultIndex].elem;"field"==s?n.searchFieldActive=!0:n.searchValueActive=!0,this.activeResult=this.results[this.resultIndex],n.updateDom(),n.scrollTo(function(){t&&n.focus(s)})},a.prototype._clearDelay=function(){this.timeout!=void 0&&(clearTimeout(this.timeout),delete this.timeout)},a.prototype._onDelayedSearch=function(){this._clearDelay();var e=this;this.timeout=setTimeout(function(t){e._onSearch(t)},this.delay)},a.prototype._onSearch=function(e,t){this._clearDelay();var i=this.dom.search.value,o=i.length>0?i:void 0;if(o!=this.lastText||t)if(this.lastText=o,this.results=this.editor.search(o),this._setActiveResult(void 0),void 0!=o){var n=this.results.length;switch(n){case 0:this.dom.results.innerHTML="no results";break;case 1:this.dom.results.innerHTML="1 result";break;default:this.dom.results.innerHTML=n+" results"}}else this.dom.results.innerHTML=""},a.prototype._onKeyDown=function(e){e=e||window.event;var t=e.which||e.keyCode;27==t?(this.dom.search.value="",this._onSearch(e),util.preventDefault(e),util.stopPropagation(e)):13==t&&(e.ctrlKey?this._onSearch(e,!0):e.shiftKey?this.previous():this.next(),util.preventDefault(e),util.stopPropagation(e))},a.prototype._onKeyUp=function(e){e=e||window.event;var t=e.which||e.keyCode;27!=t&&13!=t&&this._onDelayedSearch(e)},l.prototype.highlight=function(e){this.locked||(this.node!=e&&(this.node&&this.node.setHighlight(!1),this.node=e,this.node.setHighlight(!0)),this._cancelUnhighlight())},l.prototype.unhighlight=function(){if(!this.locked){var e=this;this.node&&(this._cancelUnhighlight(),this.unhighlightTimer=setTimeout(function(){e.node.setHighlight(!1),e.node=void 0,e.unhighlightTimer=void 0},0))}},l.prototype._cancelUnhighlight=function(){this.unhighlightTimer&&(clearTimeout(this.unhighlightTimer),this.unhighlightTimer=void 0)},l.prototype.lock=function(){this.locked=!0},l.prototype.unlock=function(){this.locked=!1},util={},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var t=0;ti;++i)e.call(t||this,this[i],i,this)}),util.parse=function(e){try{return JSON.parse(e)}catch(t){throw util.validate(e),t}},util.validate=function(e){"undefined"!=typeof jsonlint?jsonlint.parse(e):JSON.parse(e)},util.extend=function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);return e},util.clear=function(e){for(var t in e)e.hasOwnProperty(t)&&delete e[t];return e},util.log=function(){console&&typeof console.log=="function"&&console.log.apply(console,arguments)};var d=/^https?:\/\/\S+$/;util.isUrl=function(e){return("string"==typeof e||e instanceof String)&&d.test(e)},util.getAbsoluteLeft=function(e){for(var t=e.offsetLeft,i=document.body,o=e.offsetParent;null!=o&&e!=i;)t+=o.offsetLeft,t-=o.scrollLeft,o=o.offsetParent;return t},util.getAbsoluteTop=function(e){for(var t=e.offsetTop,i=document.body,o=e.offsetParent;null!=o&&o!=i;)t+=o.offsetTop,t-=o.scrollTop,o=o.offsetParent;return t},util.getMouseY=function(e){var t;return t="pageY"in e?e.pageY:e.clientY+document.documentElement.scrollTop},util.getMouseX=function(e){var t;return t="pageX"in e?e.pageX:e.clientX+document.documentElement.scrollLeft},util.getWindowHeight=function(){return"innerHeight"in window?window.innerHeight:Math.max(document.body.clientHeight,document.documentElement.clientHeight)},util.addClassName=function(e,t){var i=e.className.split(" ");i.indexOf(t)==-1&&(i.push(t),e.className=i.join(" "))},util.removeClassName=function(e,t){var i=e.className.split(" "),o=i.indexOf(t);-1!=o&&(i.splice(o,1),e.className=i.join(" "))},util.stripFormatting=function(e){for(var t=e.childNodes,i=0,o=t.length;o>i;i++){var n=t[i];n.style&&n.removeAttribute("style");var s=n.attributes;if(s)for(var r=s.length-1;r>=0;r--){var a=s[r];a.specified==1&&n.removeAttribute(a.name)}util.stripFormatting(n)}},util.setEndOfContentEditable=function(e){var t,i;document.createRange?(t=document.createRange(),t.selectNodeContents(e),t.collapse(!1),i=window.getSelection(),i.removeAllRanges(),i.addRange(t)):document.selection&&(t=document.body.createTextRange(),t.moveToElementText(e),t.collapse(!1),t.select())},util.selectContentEditable=function(e){if(e&&e.nodeName=="DIV"){var t,i;window.getSelection&&document.createRange?(i=document.createRange(),i.selectNodeContents(e),t=window.getSelection(),t.removeAllRanges(),t.addRange(i)):document.body.createTextRange&&(i=document.body.createTextRange(),i.moveToElementText(e),i.select())}},util.getSelection=function(){if(window.getSelection){var e=window.getSelection();if(e.getRangeAt&&e.rangeCount)return e.getRangeAt(0)}else if(document.selection&&document.selection.createRange)return document.selection.createRange();return null},util.setSelection=function(e){if(e)if(window.getSelection){var t=window.getSelection();t.removeAllRanges(),t.addRange(e)}else document.selection&&e.select&&e.select()},util.getSelectionOffset=function(){var e=util.getSelection();return e&&"startOffset"in e&&"endOffset"in e&&e.startContainer&&e.startContainer==e.endContainer?{startOffset:e.startOffset,endOffset:e.endOffset,container:e.startContainer.parentNode}:null},util.setSelectionOffset=function(e){if(document.createRange&&window.getSelection){var t=window.getSelection();if(t){var i=document.createRange();i.setStart(e.container.firstChild,e.startOffset),i.setEnd(e.container.firstChild,e.endOffset),util.setSelection(i)}}},util.getInnerText=function(e,t){var i=void 0==t;if(i&&(t={text:"",flush:function(){var e=this.text;return this.text="",e},set:function(e){this.text=e}}),e.nodeValue)return t.flush()+e.nodeValue;if(e.hasChildNodes()){for(var o=e.childNodes,n="",s=0,r=o.length;r>s;s++){var a=o[s];if(a.nodeName=="DIV"||a.nodeName=="P"){var l=o[s-1],d=l?l.nodeName:void 0;d&&"DIV"!=d&&"P"!=d&&"BR"!=d&&(n+="\n",t.flush()),n+=util.getInnerText(a,t),t.set("\n")}else a.nodeName=="BR"?(n+=t.flush(),t.set("\n")):n+=util.getInnerText(a,t)}return n}return e.nodeName=="P"&&util.getInternetExplorerVersion()!=-1?t.flush():""},util.getInternetExplorerVersion=function(){if(-1==h){var e=-1;if(navigator.appName=="Microsoft Internet Explorer"){var t=navigator.userAgent,i=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");i.exec(t)!=null&&(e=parseFloat(RegExp.$1))}h=e}return h};var h=-1;util.addEventListener=function(e,t,i,o){if(e.addEventListener)return void 0===o&&(o=!1),"mousewheel"===t&&navigator.userAgent.indexOf("Firefox")>=0&&(t="DOMMouseScroll"),e.addEventListener(t,i,o),i;var n=function(){return i.call(e,window.event)};return e.attachEvent("on"+t,n),n},util.removeEventListener=function(e,t,i,o){e.removeEventListener?(void 0===o&&(o=!1),"mousewheel"===t&&navigator.userAgent.indexOf("Firefox")>=0&&(t="DOMMouseScroll"),e.removeEventListener(t,i,o)):e.detachEvent("on"+t,i)},util.stopPropagation=function(e){e||(e=window.event),e.stopPropagation?e.stopPropagation():e.cancelBubble=!0},util.preventDefault=function(e){e||(e=window.event),e.preventDefault?e.preventDefault():e.returnValue=!1};var c={JSONEditor:e,JSONFormatter:function(){throw new Error('JSONFormatter is deprecated. Use JSONEditor with mode "text" or "code" instead')},util:util},u=function(){var e=document.getElementsByTagName("script"),t=e[e.length-1].src.split("?")[0],i=t.substring(0,t.length-2)+"css",o=document.createElement("link");o.type="text/css",o.rel="stylesheet",o.href=i,document.getElementsByTagName("head")[0].appendChild(o)};"undefined"!=typeof module&&"undefined"!=typeof exports&&(u(),module.exports=exports=c),"undefined"!=typeof require&&"undefined"!=typeof define?define(function(){return u(),c}):window.jsoneditor=c})(); \ No newline at end of file diff --git a/jsoneditor.js b/jsoneditor.js index 94e1562..84f5f10 100644 --- a/jsoneditor.js +++ b/jsoneditor.js @@ -173,35 +173,43 @@ JSONEditor.prototype.setMode = function (mode) { options.mode = mode; var config = JSONEditor.modes[mode]; if (config) { - if (config.data == 'text') { - // text - name = this.getName(); - data = this.getText(); + try { + if (config.data == 'text') { + // text + name = this.getName(); + data = this.getText(); - this._delete(); - util.clear(this); - util.extend(this, config.editor.prototype); - this._create(container, options); + this._delete(); + util.clear(this); + util.extend(this, config.editor.prototype); + this._create(container, options); - this.setName(name); - this.setText(data); + this.setName(name); + this.setText(data); + } + else { + // json + name = this.getName(); + data = this.get(); + + this._delete(); + util.clear(this); + util.extend(this, config.editor.prototype); + this._create(container, options); + + this.setName(name); + this.set(data); + } + + if (typeof config.load === 'function') { + try { + config.load.call(this); + } + catch (err) {} + } } - else { - // json - name = this.getName(); - data = this.get(); - - this._delete(); - util.clear(this); - util.extend(this, config.editor.prototype); - this._create(container, options); - - this.setName(name); - this.set(data); - } - - if (typeof config.load === 'function') { - config.load.call(this); + catch (err) { + this._onError(err); } } else { @@ -209,6 +217,28 @@ JSONEditor.prototype.setMode = function (mode) { } }; +/** + * Throw an error. If an error callback is configured in options.error, this + * callback will be invoked. Else, a regular error is thrown. + * @param {Error} err + * @private + */ +JSONEditor.prototype._onError = function(err) { + // TODO: onError is deprecated since version 2.2.0. cleanup some day + if (typeof this.onError === 'function') { + util.log('WARNING: JSONEditor.onError is deprecated. ' + + 'Use options.error instead.'); + this.onError(err); + } + + if (typeof this.options.error === 'function') { + this.options.error(err); + } + else { + throw err; + } +}; + /** * @constructor TreeEditor * @param {Element} container Container element @@ -303,22 +333,22 @@ TreeEditor.prototype._setOptions = function (options) { if (options['enableSearch']) { // deprecated since version 1.6.0, 2012-11-03 this.options.search = options['enableSearch']; - console.log('WARNING: Option "enableSearch" is deprecated. Use "search" instead.'); + util.log('WARNING: Option "enableSearch" is deprecated. Use "search" instead.'); } if (options['enableHistory']) { // deprecated since version 1.6.0, 2012-11-03 this.options.history = options['enableHistory']; - console.log('WARNING: Option "enableHistory" is deprecated. Use "history" instead.'); + util.log('WARNING: Option "enableHistory" is deprecated. Use "history" instead.'); } if (options['mode'] == 'editor') { // deprecated since version 2.2.0, 2013-04-30 this.options.mode = 'tree'; - console.log('WARNING: Mode "editor" is deprecated. Use "tree" instead.'); + util.log('WARNING: Mode "editor" is deprecated. Use "tree" instead.'); } if (options['mode'] == 'viewer') { // deprecated since version 2.2.0, 2013-04-30 this.options.mode = 'view'; - console.log('WARNING: Mode "viewer" is deprecated. Use "view" instead.'); + util.log('WARNING: Mode "viewer" is deprecated. Use "view" instead.'); } } @@ -343,7 +373,7 @@ TreeEditor.prototype.set = function (json, name) { // adjust field name for root node if (name) { // TODO: deprecated since version 2.2.0. Cleanup some day. - console.log('Warning: second parameter "name" is deprecated. ' + + util.log('Warning: second parameter "name" is deprecated. ' + 'Use setName(name) instead.'); this.options.name = name; } @@ -528,7 +558,7 @@ TreeEditor.prototype._onAction = function (action, params) { this.options.change(); } catch (err) { - console.log('Error in change callback: ', err); + util.log('Error in change callback: ', err); } } }; @@ -1023,17 +1053,18 @@ TextEditor.prototype._create = function (container, options, json) { if (options.indentation) { this.indentation = Number(options.indentation); } + this.options = options; this.mode = (options.mode == 'code') ? 'code' : 'text'; if (this.mode == 'code') { // verify whether Ace editor is available and supported if (typeof ace === 'undefined') { this.mode = 'text'; - console.log('WARNING: Cannot load code editor, Ace library not loaded. ' + + util.log('WARNING: Cannot load code editor, Ace library not loaded. ' + 'Falling back to plain text editor'); } if (util.getInternetExplorerVersion() == 8) { this.mode = 'text'; - console.log('WARNING: Cannot load code editor, Ace is not supported on IE8. ' + + util.log('WARNING: Cannot load code editor, Ace is not supported on IE8. ' + 'Falling back to plain text editor'); } } @@ -1067,7 +1098,12 @@ TextEditor.prototype._create = function (container, options, json) { //buttonFormat.className = 'jsoneditor-button'; this.menu.appendChild(buttonFormat); buttonFormat.onclick = function () { - me.format(); + try { + me.format(); + } + catch (err) { + me._onError(err); + } }; // create compact button @@ -1078,7 +1114,13 @@ TextEditor.prototype._create = function (container, options, json) { //buttonCompact.className = 'jsoneditor-button'; this.menu.appendChild(buttonCompact); buttonCompact.onclick = function () { - me.compact(); + try { + me.compact(); + } + catch (err) { + me._onError(err); + } + }; this.content = document.createElement('div'); @@ -1166,39 +1208,41 @@ TextEditor.prototype._delete = function () { }; /** - * This method is executed on error. - * It can be overwritten for each instance of the TextEditor - * @param {String} err + * Throw an error. If an error callback is configured in options.error, this + * callback will be invoked. Else, a regular error is thrown. + * @param {Error} err + * @private */ -// TODO: replace with an options.error -TextEditor.prototype.onError = function(err) { - // action should be implemented for the instance +TextEditor.prototype._onError = function(err) { + // TODO: onError is deprecated since version 2.2.0. cleanup some day + if (typeof this.onError === 'function') { + util.log('WARNING: JSONEditor.onError is deprecated. ' + + 'Use options.error instead.'); + this.onError(err); + } + + if (typeof this.options.error === 'function') { + this.options.error(err); + } + else { + throw err; + } }; /** * Compact the code in the formatter */ TextEditor.prototype.compact = function () { - try { - var json = util.parse(this.getText()); - this.setText(JSON.stringify(json)); - } - catch (err) { - this.onError(err); - } + var json = util.parse(this.getText()); + this.setText(JSON.stringify(json)); }; /** * Format the code in the formatter */ TextEditor.prototype.format = function () { - try { - var json = util.parse(this.getText()); - this.setText(JSON.stringify(json, null, this.indentation)); - } - catch (err) { - this.onError(err); - } + var json = util.parse(this.getText()); + this.setText(JSON.stringify(json, null, this.indentation)); }; /** @@ -1409,7 +1453,7 @@ Node.prototype.setValue = function(value, type) { if (typeof(value) == 'string') { var escValue = JSON.stringify(value); this.value = escValue.substring(1, escValue.length - 1); - console.log('check', value, this.value); + util.log('check', value, this.value); } else { this.value = value; @@ -3179,7 +3223,7 @@ Node.prototype.onKeyDown = function (event) { var handled = false; var prevNode, nextNode, nextDom, nextDom2; - // console.log(ctrlKey, keynum, event.charCode); // TODO: cleanup + // util.log(ctrlKey, keynum, event.charCode); // TODO: cleanup if (keynum == 13) { // Enter if (target == this.dom.value) { if (!this.editor.mode.edit || event.ctrlKey) { @@ -4979,7 +5023,7 @@ History.prototype.undo = function () { } } else { - console.log('Error: unknown action "' + obj.action + '"'); + util.log('Error: unknown action "' + obj.action + '"'); } } this.index--; @@ -5006,7 +5050,7 @@ History.prototype.redo = function () { } } else { - console.log('Error: unknown action "' + obj.action + '"'); + util.log('Error: unknown action "' + obj.action + '"'); } } @@ -5415,13 +5459,6 @@ if (!Array.prototype.forEach) { } } -// Old browsers do not have a console, so create a fake one in that case. -if (typeof console === 'undefined') { - console = { - log: function () {} - }; -} - /** * Parse JSON using the parser built-in in the browser. * On exception, the jsonString is validated and a detailed error is thrown. @@ -5432,9 +5469,9 @@ util.parse = function (jsonString) { return JSON.parse(jsonString); } catch (err) { - // get a detailed error message using validate - var message = util.validate(jsonString) || err; - throw new Error(message); + // try to throw a more detailed error message using validate + util.validate(jsonString); + throw err; } }; @@ -5443,33 +5480,15 @@ util.parse = function (jsonString) { * This method uses JSONLint to validate the String. If JSONLint is not * available, the built-in JSON parser of the browser is used. * @param {String} jsonString String with an (invalid) JSON object - * @return {String | undefined} Returns undefined when the string is valid JSON, - * returns a string with an error message when - * the data is invalid. This message is HTML - * formatted. + * @throws Error */ util.validate = function (jsonString) { - var message = undefined; - - try { - if (typeof(jsonlint) != 'undefined') { - jsonlint.parse(jsonString); - } - else { - JSON.parse(jsonString); - } + if (typeof(jsonlint) != 'undefined') { + jsonlint.parse(jsonString); } - catch (err) { - message = '
' + err.toString() + '
'; - if (typeof(jsonlint) != 'undefined') { - message += - '' + - 'validated by jsonlint' + - ''; - } + else { + JSON.parse(jsonString); } - - return message; }; /** @@ -5501,6 +5520,16 @@ util.clear = function (a) { return a; }; +/** + * Output text to the console, if console is available + * @param {...*} args + */ +util.log = function(args) { + if (console && typeof console.log === 'function') { + console.log.apply(console, arguments); + } +}; + /** * Test whether a text contains a url (matches when a string starts * with 'http://*' or 'https://*' and has no whitespace characters) diff --git a/jsoneditor/js/history.js b/jsoneditor/js/history.js index ac93be7..0876f72 100644 --- a/jsoneditor/js/history.js +++ b/jsoneditor/js/history.js @@ -181,7 +181,7 @@ History.prototype.undo = function () { } } else { - console.log('Error: unknown action "' + obj.action + '"'); + util.log('Error: unknown action "' + obj.action + '"'); } } this.index--; @@ -208,7 +208,7 @@ History.prototype.redo = function () { } } else { - console.log('Error: unknown action "' + obj.action + '"'); + util.log('Error: unknown action "' + obj.action + '"'); } } diff --git a/jsoneditor/js/jsoneditor.js b/jsoneditor/js/jsoneditor.js index 5cd2966..a8920f7 100644 --- a/jsoneditor/js/jsoneditor.js +++ b/jsoneditor/js/jsoneditor.js @@ -139,38 +139,68 @@ JSONEditor.prototype.setMode = function (mode) { options.mode = mode; var config = JSONEditor.modes[mode]; if (config) { - if (config.data == 'text') { - // text - name = this.getName(); - data = this.getText(); + try { + if (config.data == 'text') { + // text + name = this.getName(); + data = this.getText(); - this._delete(); - util.clear(this); - util.extend(this, config.editor.prototype); - this._create(container, options); + this._delete(); + util.clear(this); + util.extend(this, config.editor.prototype); + this._create(container, options); - this.setName(name); - this.setText(data); + this.setName(name); + this.setText(data); + } + else { + // json + name = this.getName(); + data = this.get(); + + this._delete(); + util.clear(this); + util.extend(this, config.editor.prototype); + this._create(container, options); + + this.setName(name); + this.set(data); + } + + if (typeof config.load === 'function') { + try { + config.load.call(this); + } + catch (err) {} + } } - else { - // json - name = this.getName(); - data = this.get(); - - this._delete(); - util.clear(this); - util.extend(this, config.editor.prototype); - this._create(container, options); - - this.setName(name); - this.set(data); - } - - if (typeof config.load === 'function') { - config.load.call(this); + catch (err) { + this._onError(err); } } else { throw new Error('Unknown mode "' + options.mode + '"'); } }; + +/** + * Throw an error. If an error callback is configured in options.error, this + * callback will be invoked. Else, a regular error is thrown. + * @param {Error} err + * @private + */ +JSONEditor.prototype._onError = function(err) { + // TODO: onError is deprecated since version 2.2.0. cleanup some day + if (typeof this.onError === 'function') { + util.log('WARNING: JSONEditor.onError is deprecated. ' + + 'Use options.error instead.'); + this.onError(err); + } + + if (typeof this.options.error === 'function') { + this.options.error(err); + } + else { + throw err; + } +}; diff --git a/jsoneditor/js/node.js b/jsoneditor/js/node.js index 9b410b4..a4740bb 100644 --- a/jsoneditor/js/node.js +++ b/jsoneditor/js/node.js @@ -129,7 +129,7 @@ Node.prototype.setValue = function(value, type) { if (typeof(value) == 'string') { var escValue = JSON.stringify(value); this.value = escValue.substring(1, escValue.length - 1); - console.log('check', value, this.value); + util.log('check', value, this.value); } else { this.value = value; @@ -1899,7 +1899,7 @@ Node.prototype.onKeyDown = function (event) { var handled = false; var prevNode, nextNode, nextDom, nextDom2; - // console.log(ctrlKey, keynum, event.charCode); // TODO: cleanup + // util.log(ctrlKey, keynum, event.charCode); // TODO: cleanup if (keynum == 13) { // Enter if (target == this.dom.value) { if (!this.editor.mode.edit || event.ctrlKey) { diff --git a/jsoneditor/js/texteditor.js b/jsoneditor/js/texteditor.js index 5b60604..786304a 100644 --- a/jsoneditor/js/texteditor.js +++ b/jsoneditor/js/texteditor.js @@ -41,17 +41,18 @@ TextEditor.prototype._create = function (container, options, json) { if (options.indentation) { this.indentation = Number(options.indentation); } + this.options = options; this.mode = (options.mode == 'code') ? 'code' : 'text'; if (this.mode == 'code') { // verify whether Ace editor is available and supported if (typeof ace === 'undefined') { this.mode = 'text'; - console.log('WARNING: Cannot load code editor, Ace library not loaded. ' + + util.log('WARNING: Cannot load code editor, Ace library not loaded. ' + 'Falling back to plain text editor'); } if (util.getInternetExplorerVersion() == 8) { this.mode = 'text'; - console.log('WARNING: Cannot load code editor, Ace is not supported on IE8. ' + + util.log('WARNING: Cannot load code editor, Ace is not supported on IE8. ' + 'Falling back to plain text editor'); } } @@ -85,7 +86,12 @@ TextEditor.prototype._create = function (container, options, json) { //buttonFormat.className = 'jsoneditor-button'; this.menu.appendChild(buttonFormat); buttonFormat.onclick = function () { - me.format(); + try { + me.format(); + } + catch (err) { + me._onError(err); + } }; // create compact button @@ -96,7 +102,13 @@ TextEditor.prototype._create = function (container, options, json) { //buttonCompact.className = 'jsoneditor-button'; this.menu.appendChild(buttonCompact); buttonCompact.onclick = function () { - me.compact(); + try { + me.compact(); + } + catch (err) { + me._onError(err); + } + }; this.content = document.createElement('div'); @@ -184,39 +196,41 @@ TextEditor.prototype._delete = function () { }; /** - * This method is executed on error. - * It can be overwritten for each instance of the TextEditor - * @param {String} err + * Throw an error. If an error callback is configured in options.error, this + * callback will be invoked. Else, a regular error is thrown. + * @param {Error} err + * @private */ -// TODO: replace with an options.error -TextEditor.prototype.onError = function(err) { - // action should be implemented for the instance +TextEditor.prototype._onError = function(err) { + // TODO: onError is deprecated since version 2.2.0. cleanup some day + if (typeof this.onError === 'function') { + util.log('WARNING: JSONEditor.onError is deprecated. ' + + 'Use options.error instead.'); + this.onError(err); + } + + if (typeof this.options.error === 'function') { + this.options.error(err); + } + else { + throw err; + } }; /** * Compact the code in the formatter */ TextEditor.prototype.compact = function () { - try { - var json = util.parse(this.getText()); - this.setText(JSON.stringify(json)); - } - catch (err) { - this.onError(err); - } + var json = util.parse(this.getText()); + this.setText(JSON.stringify(json)); }; /** * Format the code in the formatter */ TextEditor.prototype.format = function () { - try { - var json = util.parse(this.getText()); - this.setText(JSON.stringify(json, null, this.indentation)); - } - catch (err) { - this.onError(err); - } + var json = util.parse(this.getText()); + this.setText(JSON.stringify(json, null, this.indentation)); }; /** diff --git a/jsoneditor/js/treeeditor.js b/jsoneditor/js/treeeditor.js index 0ce0145..4dbbc43 100644 --- a/jsoneditor/js/treeeditor.js +++ b/jsoneditor/js/treeeditor.js @@ -92,22 +92,22 @@ TreeEditor.prototype._setOptions = function (options) { if (options['enableSearch']) { // deprecated since version 1.6.0, 2012-11-03 this.options.search = options['enableSearch']; - console.log('WARNING: Option "enableSearch" is deprecated. Use "search" instead.'); + util.log('WARNING: Option "enableSearch" is deprecated. Use "search" instead.'); } if (options['enableHistory']) { // deprecated since version 1.6.0, 2012-11-03 this.options.history = options['enableHistory']; - console.log('WARNING: Option "enableHistory" is deprecated. Use "history" instead.'); + util.log('WARNING: Option "enableHistory" is deprecated. Use "history" instead.'); } if (options['mode'] == 'editor') { // deprecated since version 2.2.0, 2013-04-30 this.options.mode = 'tree'; - console.log('WARNING: Mode "editor" is deprecated. Use "tree" instead.'); + util.log('WARNING: Mode "editor" is deprecated. Use "tree" instead.'); } if (options['mode'] == 'viewer') { // deprecated since version 2.2.0, 2013-04-30 this.options.mode = 'view'; - console.log('WARNING: Mode "viewer" is deprecated. Use "view" instead.'); + util.log('WARNING: Mode "viewer" is deprecated. Use "view" instead.'); } } @@ -132,7 +132,7 @@ TreeEditor.prototype.set = function (json, name) { // adjust field name for root node if (name) { // TODO: deprecated since version 2.2.0. Cleanup some day. - console.log('Warning: second parameter "name" is deprecated. ' + + util.log('Warning: second parameter "name" is deprecated. ' + 'Use setName(name) instead.'); this.options.name = name; } @@ -317,7 +317,7 @@ TreeEditor.prototype._onAction = function (action, params) { this.options.change(); } catch (err) { - console.log('Error in change callback: ', err); + util.log('Error in change callback: ', err); } } }; diff --git a/jsoneditor/js/util.js b/jsoneditor/js/util.js index 1b98d76..826358c 100644 --- a/jsoneditor/js/util.js +++ b/jsoneditor/js/util.js @@ -26,13 +26,6 @@ if (!Array.prototype.forEach) { } } -// Old browsers do not have a console, so create a fake one in that case. -if (typeof console === 'undefined') { - console = { - log: function () {} - }; -} - /** * Parse JSON using the parser built-in in the browser. * On exception, the jsonString is validated and a detailed error is thrown. @@ -43,9 +36,9 @@ util.parse = function (jsonString) { return JSON.parse(jsonString); } catch (err) { - // get a detailed error message using validate - var message = util.validate(jsonString) || err; - throw new Error(message); + // try to throw a more detailed error message using validate + util.validate(jsonString); + throw err; } }; @@ -54,33 +47,15 @@ util.parse = function (jsonString) { * This method uses JSONLint to validate the String. If JSONLint is not * available, the built-in JSON parser of the browser is used. * @param {String} jsonString String with an (invalid) JSON object - * @return {String | undefined} Returns undefined when the string is valid JSON, - * returns a string with an error message when - * the data is invalid. This message is HTML - * formatted. + * @throws Error */ util.validate = function (jsonString) { - var message = undefined; - - try { - if (typeof(jsonlint) != 'undefined') { - jsonlint.parse(jsonString); - } - else { - JSON.parse(jsonString); - } + if (typeof(jsonlint) != 'undefined') { + jsonlint.parse(jsonString); } - catch (err) { - message = '
' + err.toString() + '
'; - if (typeof(jsonlint) != 'undefined') { - message += - '' + - 'validated by jsonlint' + - ''; - } + else { + JSON.parse(jsonString); } - - return message; }; /** @@ -112,6 +87,16 @@ util.clear = function (a) { return a; }; +/** + * Output text to the console, if console is available + * @param {...*} args + */ +util.log = function(args) { + if (console && typeof console.log === 'function') { + console.log.apply(console, arguments); + } +}; + /** * Test whether a text contains a url (matches when a string starts * with 'http://*' or 'https://*' and has no whitespace characters)