/* This json editor is open sourced with the intention to use the editor as a component in your own application. Not to just copy and monetize the editor as it is. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Copyright (c) 2011-2012 Jos de Jong, http://jsoneditoronline.org @author Jos de Jong, @date 2012-05-30 */ if(!Array.prototype.indexOf)Array.prototype.indexOf=function(a){for(var b=0;bb+d&&(e=void 0);e&&e.parent&&e.parent.moveBefore(this,e)}else if(e=(d=this.expanded&& this.append?this.append.getDom():this.dom.tr)?d.nextSibling:void 0){for(var d=JSONEditor.getAbsoluteTop(e),b=void 0,e=e.nextSibling,g=JSONEditor.getAbsoluteTop(e),g=e?g-d:0;e&&f>c+g;)b=JSONEditor.getNodeFromTarget(e),e=e.nextSibling,g=JSONEditor.getAbsoluteTop(e),g=e?g-d:0;b&&b.parent&&b.parent.moveBefore(this,b)}JSONEditor.Events.preventDefault(a)}; JSONEditor.Node.prototype._onDragEnd=function(a){a=a||window.event;document.body.style.cursor=this.oldCursor;delete JSONEditor.freezeHighlight;delete this.oldCursor;this.setHighlight(!1);this.mousemove&&(JSONEditor.Events.removeEventListener(document,"mousemove",this.mousemove),delete this.mousemove);this.mouseup&&(JSONEditor.Events.removeEventListener(document,"mouseup",this.mouseup),delete this.mouseup);JSONEditor.Events.preventDefault(a)}; JSONEditor.Node.prototype._createDomDragArea=function(){if(this.parent){var a=document.createElement("button");a.className="jsoneditor-dragarea";return a}};JSONEditor.Node.prototype._createDomField=function(){return document.createElement("div")}; JSONEditor.Node.prototype.setHighlight=function(a){if(!JSONEditor.freezeHighlight&&this.dom.tr){this.dom.tr.className="jsoneditor-tr"+(a?" jsoneditor-tr-highlight":"");this.append&&this.append.setHighlight(a);var b=this.childs;if(b)for(var c=0,d=b.length;c0?a:0,f=c.length;a0?a:0;for(f=c.length;a/g,">").replace(/ /g,"  ");a=JSON.stringify(a);return a.substring(1,a.length-1)};JSONEditor.Node.prototype._unescape=function(a){return JSON.parse('"'+a+'"').replace(/</g,"<").replace(/>/g,">").replace(/ /g," ")}; JSONEditor.Node.prototype._stripHTML=function(a){return a.replace(/<(?:.|\n)*?>/gm,"")};JSONEditor.AppendNode=function(){this.dom={}};JSONEditor.AppendNode.prototype=new JSONEditor.Node; JSONEditor.AppendNode.prototype.getDom=function(){function a(a){var b=document.createElement("td");b.className=a||"";return b}if(this.dom.tr)return this.dom.tr;var b=document.createElement("tr");b.appendChild(a("jsoneditor-td"));b.node=this;var c=document.createElement("td");b.appendChild(c);c.className="jsoneditor-td";var d=document.createElement("button");d.className="jsoneditor-append";d.title="Append a field";this.dom.append=d;c.appendChild(d);b.appendChild(a("jsoneditor-td jsoneditor-td-edit")); b.appendChild(a("jsoneditor-td jsoneditor-td-edit"));b.appendChild(a("jsoneditor-td jsoneditor-td-edit"));this.dom.tr=b;this.dom.td=c;this.updateDom();return b};JSONEditor.AppendNode.prototype.updateDom=function(){var a=this.dom.td;if(a)a.style.paddingLeft=this.getLevel()*24+26+"px"}; JSONEditor.AppendNode.prototype.onEvent=function(a){var b=a.type;if((a.target||a.srcElement)==this.dom.append)switch(b){case "click":a=new JSONEditor.Node({field:"field",value:"value"});this.parent.appendChild(a);this.parent.setHighlight(!1);a.focus();break;case "mouseover":this.parent.setHighlight(!0);break;case "mouseout":this.parent.setHighlight(!1)}}; JSONEditor.prototype._createFrame=function(){this.container.innerHTML="";this.frame=document.createElement("div");this.frame.className="jsoneditor-frame";this.container.appendChild(this.frame);var a=this,b=function(a){var a=a||window.event,b=JSONEditor.getNodeFromTarget(a.target||a.srcElement);if(b)b.onEvent(a)};this.frame.onclick=function(a){b(a);JSONEditor.Events.preventDefault(a)};this.frame.onchange=b;this.frame.onfocus=b;this.frame.onblur=b;this.frame.onkeyup=b;this.frame.oncut=b;this.frame.onpaste= b;this.frame.onmousedown=b;this.frame.onmouseup=b;this.frame.onmouseover=b;this.frame.onmouseout=b;this.head=document.createElement("table");this.head.className="jsoneditor-menu";var c=document.createElement("tbody");this.head.appendChild(c);var d=document.createElement("tr");c.appendChild(d);c=document.createElement("td");c.className="jsoneditor-menu";d.appendChild(c);d=document.createElement("button");d.innerHTML="Expand All";d.onclick=function(){a.expandAll()};c.appendChild(d);d=document.createElement("button"); d.innerHTML="Collapse All";d.onclick=function(){a.collapseAll()};c.appendChild(d);this.frame.appendChild(this.head)}; JSONEditor.prototype._createTable=function(){var a=document.createElement("div");a.className="jsoneditor-content-outer";this.content=document.createElement("div");this.content.className="jsoneditor-content";a.appendChild(this.content);this.table=document.createElement("table");this.table.className="jsoneditor-table";this.content.appendChild(this.table);if(JSONEditor.getInternetExplorerVersion()==8)this.content.style.overflow="scroll";var b;this.colgroupContent=document.createElement("colgroup");b= document.createElement("col");b.width="24px";this.colgroupContent.appendChild(b);b=document.createElement("col");this.colgroupContent.appendChild(b);b=document.createElement("col");b.width="24px";this.colgroupContent.appendChild(b);b=document.createElement("col");b.width="24px";this.colgroupContent.appendChild(b);b=document.createElement("col");b.width="24px";this.colgroupContent.appendChild(b);this.table.appendChild(this.colgroupContent);this.tbody=document.createElement("tbody");this.table.appendChild(this.tbody); this.frame.appendChild(a)};JSONEditor.getNodeFromTarget=function(a){for(;a;){if(a.node)return a.node;a=a.parentNode}}; JSONFormatter=function(a){if(!JSON)throw Error("Your browser does not support JSON. \n\nPlease install the newest version of your browser.\n(all modern browsers support JSON).");this.container=a;this.width=a.clientWidth;this.height=a.clientHeight;this.frame=document.createElement("div");this.frame.className="jsoneditor-frame";this.frame.onclick=function(a){JSONEditor.Events.preventDefault(a)};this.head=document.createElement("table");this.head.className="jsoneditor-menu";a=document.createElement("tbody"); this.head.appendChild(a);var b=document.createElement("tr");a.appendChild(b);a=document.createElement("td");a.className="jsoneditor-menu";b.appendChild(a);b=document.createElement("button");b.innerHTML="Format";b.title="Format JSON data, with proper indentation and line feeds";b.className="jsoneditor-button";a.appendChild(b);var c=document.createElement("button");c.innerHTML="Compact";c.title="Compact JSON data, remove all whitespaces";c.className="jsoneditor-button";a.appendChild(c);this.frame.appendChild(this.head); this.content=document.createElement("div");this.content.className="jsonformatter-content";this.frame.appendChild(this.content);this.textarea=document.createElement("textarea");this.textarea.className="jsonformatter-textarea";this.textarea.spellcheck=!1;this.content.appendChild(this.textarea);var d=this.textarea,f=this;b.onclick=function(){try{d.value=JSON.stringify(JSON.parse(d.value),null," ")}catch(a){f.onError(a)}};c.onclick=function(){try{d.value=JSON.stringify(JSON.parse(d.value))}catch(a){f.onError(a)}}; this.container.appendChild(this.frame)};JSONFormatter.prototype.onError=function(){};JSONFormatter.prototype._checkChange=function(){var a=this.textarea.value;if(a!=this.lastContent&&(this.lastContent=a,this.onChangeCallback))this.onChangeCallback()};JSONFormatter.prototype.set=function(a){this.textarea.value=JSON.stringify(a,null," ")};JSONFormatter.prototype.get=function(){return JSON.parse(this.textarea.value)};JSONEditor.Events={}; JSONEditor.Events.addEventListener=function(a,b,c,d){return a.addEventListener?(d===void 0&&(d=!1),b==="mousewheel"&&navigator.userAgent.indexOf("Firefox")>=0&&(b="DOMMouseScroll"),a.addEventListener(b,c,d),c):(d=function(){return c.call(a,window.event)},a.attachEvent("on"+b,d),d)}; JSONEditor.Events.removeEventListener=function(a,b,c,d){a.removeEventListener?(d===void 0&&(d=!1),b==="mousewheel"&&navigator.userAgent.indexOf("Firefox")>=0&&(b="DOMMouseScroll"),a.removeEventListener(b,c,d)):a.detachEvent("on"+b,c)};JSONEditor.Events.stopPropagation=function(a){if(!a)a=window.event;a.stopPropagation?a.stopPropagation():a.cancelBubble=!0};JSONEditor.Events.preventDefault=function(a){if(!a)a=window.event;a.preventDefault?a.preventDefault():a.returnValue=!1}; JSONEditor.getAbsoluteLeft=function(a){for(var b=0;a!=null;)b+=a.offsetLeft,b-=a.scrollLeft,a=a.offsetParent;!document.body.scrollLeft&&window.pageXOffset&&(b-=window.pageXOffset);return b};JSONEditor.getAbsoluteTop=function(a){for(var b=0;a!=null;)b+=a.offsetTop,b-=a.scrollTop,a=a.offsetParent;!document.body.scrollTop&&window.pageYOffset&&(b-=window.pageYOffset);return b};JSONEditor.addClassName=function(a,b){var c=a.className;if(c.indexOf(b)==-1)c+=" "+b,a.className=c}; JSONEditor.removeClassName=function(a,b){var c=a.className;if(c.indexOf(b)!=-1)c=c.replace(b,""),c=c.replace(/ /g,""),a.className=c};JSONEditor.stripFormatting=function(a){for(var a=a.childNodes,b=0,c=a.length;b