From e290ff15da7283d532030d8039f70cb61f103a2f Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Thu, 16 Aug 2012 21:18:37 +0200 Subject: [PATCH] Restructured the files --- index.html | 8 +- interface.css => interface/interface.css | 4 +- interface.js => interface/interface.js | 0 jsoneditor-min.js | 107 ----------------- demo.html => jsoneditor/examples/demo.html | 4 +- {img => jsoneditor/img}/colors.txt | 0 {img => jsoneditor/img}/export.sh | 0 {img => jsoneditor/img}/jsoneditor-icons.png | Bin {img => jsoneditor/img}/jsoneditor-icons.svg | 0 jsoneditor/jsoneditor-min.js | 109 ++++++++++++++++++ jsoneditor.css => jsoneditor/jsoneditor.css | 0 jsoneditor.js => jsoneditor/jsoneditor.js | 0 todo.txt => misc/todo.txt | 0 index_no_ads.html => test.html | 8 +- couchdbeditor.html => test/couchdbeditor.html | 6 +- tools/built.sh | 2 +- tools/minify.sh | 4 +- 17 files changed, 127 insertions(+), 125 deletions(-) rename interface.css => interface/interface.css (93%) rename interface.js => interface/interface.js (100%) delete mode 100644 jsoneditor-min.js rename demo.html => jsoneditor/examples/demo.html (87%) rename {img => jsoneditor/img}/colors.txt (100%) rename {img => jsoneditor/img}/export.sh (100%) rename {img => jsoneditor/img}/jsoneditor-icons.png (100%) rename {img => jsoneditor/img}/jsoneditor-icons.svg (100%) create mode 100644 jsoneditor/jsoneditor-min.js rename jsoneditor.css => jsoneditor/jsoneditor.css (100%) rename jsoneditor.js => jsoneditor/jsoneditor.js (100%) rename todo.txt => misc/todo.txt (100%) rename index_no_ads.html => test.html (94%) rename couchdbeditor.html => test/couchdbeditor.html (92%) diff --git a/index.html b/index.html index a85d988..cbb1f55 100644 --- a/index.html +++ b/index.html @@ -44,14 +44,14 @@ - - + + - - + + diff --git a/interface.css b/interface/interface.css similarity index 93% rename from interface.css rename to interface/interface.css index 5a2cba5..a945dce 100644 --- a/interface.css +++ b/interface/interface.css @@ -142,9 +142,9 @@ div.convert-right, div.convert-left { } div.convert-right { - background: url('img/jsoneditor-icons.png') -168px 0; + background: url('../jsoneditor/img/jsoneditor-icons.png') -168px 0; } div.convert-left { - background: url('img/jsoneditor-icons.png') -192px 0; + background: url('../jsoneditor/img/jsoneditor-icons.png') -192px 0; } diff --git a/interface.js b/interface/interface.js similarity index 100% rename from interface.js rename to interface/interface.js diff --git a/jsoneditor-min.js b/jsoneditor-min.js deleted file mode 100644 index 487a957..0000000 --- a/jsoneditor-min.js +++ /dev/null @@ -1,107 +0,0 @@ -/* - - 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-08-16 -*/ -if(!Array.prototype.indexOf)Array.prototype.indexOf=function(a){for(var b=0;b3)b.scrollTop+=a/3,c.animateTimeout=setTimeout(e,50)};e()}};JSONEditor.Node=function(a){this.dom={};this.expanded=!1;a&&a instanceof Object?(this.setField(a.field,a.fieldEditable),this.setValue(a.value)):(this.setField(),this.setValue())}; -JSONEditor.Node.prototype.setParent=function(a){this.parent=a};JSONEditor.Node.prototype.getParent=function(){return this.parent};JSONEditor.Node.prototype.getEditor=function(){return this.parent?this.parent.getEditor():void 0};JSONEditor.Node.prototype.setField=function(a,b){this.field=a;this.fieldEditable=b==!0};JSONEditor.Node.prototype.getField=function(){if(this.field===void 0)this.field=this._getDomField();return this.field}; -JSONEditor.Node.prototype.setValue=function(a){var b=this.childs;if(b)for(;b.length;)this.removeChild(b[0]);this.type=this._getType(a);if(this.type=="array"){this.childs=[];for(var c=0,b=a.length;cb+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";a.title="Move field (drag and drop)";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.appendChild(e);g.onmousedown=function(b){return function(){a.callback(b)}}(d.value);b.appendChild(g)}document.body.appendChild(b);a.node.setHighlight(!0);JSONEditor.freezeHighlight=!0;var h=JSONEditor.Events.addEventListener(document,"mousedown",function(){JSONEditor.freezeHighlight=!1;a.node.setHighlight(!1);document.body.removeChild(b);JSONEditor.Events.removeEventListener(document,"mousedown",h)}),i=JSONEditor.Events.addEventListener(document, -"mousewheel",function(){JSONEditor.freezeHighlight=!1;a.node.setHighlight(!1);document.body.removeChild(b);JSONEditor.Events.removeEventListener(document,"mousewheel",i)})};JSONEditor.Node.prototype.getAppend=function(){if(!this.append)this.append=new JSONEditor.AppendNode,this.append.setParent(this);return this.append.getDom()}; -JSONEditor.Node.prototype._createDomRemoveButton=function(){if(this.parent&&(this.parent.type=="array"||this.parent.type=="object")){var a=document.createElement("button");a.className="jsoneditor-remove";a.title="Remove field (including all its childs)";return a}}; -JSONEditor.Node.prototype._createDomDuplicateButton=function(){if(this.parent&&(this.parent.type=="array"||this.parent.type=="object")){var a=document.createElement("button");a.className="jsoneditor-duplicate";a.title="Duplicate field (including all childs)";return a}};JSONEditor.Node.prototype._getType=function(a){return a instanceof Array?"array":a instanceof Object?"object":typeof a=="string"&&typeof this._stringCast(a)!="string"?"string":"auto"}; -JSONEditor.Node.prototype._stringCast=function(a){var b=a.toLowerCase(),c=Number(a),d=parseFloat(a);return a==""?"":b=="null"?null:b=="true"?!0:b=="false"?!1:!isNaN(c)&&!isNaN(d)?c:a};JSONEditor.Node.prototype._escape=function(a){a=String(a).replace(//g,">").replace(/ /g,"  ").replace(/^ /," ").replace(/ $/," ");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.onkeydown=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;JSONEditor.Events.addEventListener(this.frame,"focus",b,!0);JSONEditor.Events.addEventListener(this.frame,"blur",b,!0);this.frame.onfocusin=b;this.frame.onfocusout=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);this.tdMenu=c=document.createElement("td");c.className="jsoneditor-menu"; -d.appendChild(c);d=document.createElement("button");d.innerHTML="Expand All";d.title="Expand all fields";d.onclick=function(){a.expandAll()};c.appendChild(d);d=document.createElement("button");d.innerHTML="Collapse All";d.title="Collapse all fields";d.onclick=function(){a.collapseAll()};c.appendChild(d);if(this.options.enableSearch)this.searchBox=new JSONEditor.SearchBox(this,c);this.frame.appendChild(this.head)}; -JSONEditor.prototype._createTable=function(){var a=document.createElement("div");a.className="jsoneditor-content-outer";this.contentOuter=a;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.SearchBox=function(a,b){var c=this;this.editor=a;this.timeout=void 0;this.delay=200;this.lastText=void 0;this.dom={};this.dom.container=b;var d=document.createElement("table");this.dom.table=d;d.className="jsoneditor-search";b.appendChild(d);var f=document.createElement("tbody");this.dom.tbody=f;d.appendChild(f);d=document.createElement("tr");f.appendChild(d);f=document.createElement("td");f.className="jsoneditor-search";d.appendChild(f);var e=document.createElement("div");this.dom.results= -e;e.className="jsoneditor-search-results";f.appendChild(e);f=document.createElement("td");f.className="jsoneditor-search";d.appendChild(f);d=document.createElement("div");this.dom.input=d;d.className="jsoneditor-search";d.title="Search fields and values";f.appendChild(d);f=document.createElement("table");f.className="jsoneditor-search-input";d.appendChild(f);e=document.createElement("tbody");f.appendChild(e);d=document.createElement("tr");e.appendChild(d);e=document.createElement("button");e.className= -"jsoneditor-search-refresh";f=document.createElement("td");f.appendChild(e);d.appendChild(f);e=document.createElement("input");this.dom.search=e;e.className="jsoneditor-search";e.oninput=function(a){c.onDelayedSearch(a)};e.onchange=function(a){c.onSearch(a)};e.onkeydown=function(a){c.onKeyDown(a)};e.onkeyup=function(a){c.onKeyUp(a)};f=document.createElement("td");f.appendChild(e);d.appendChild(f);e=document.createElement("button");e.title="Next result (Enter)";e.className="jsoneditor-search-next"; -e.onclick=function(){c.next()};f=document.createElement("td");f.appendChild(e);d.appendChild(f);e=document.createElement("button");e.title="Previous result (Shift+Enter)";e.className="jsoneditor-search-previous";e.onclick=function(){c.previous()};f=document.createElement("td");f.appendChild(e);d.appendChild(f)};JSONEditor.SearchBox.prototype.next=function(){if(this.results!=void 0){var a=this.resultIndex!=void 0?this.resultIndex+1:0;a>this.results.length-1&&(a=0);this.setActiveResult(a)}}; -JSONEditor.SearchBox.prototype.previous=function(){if(this.results!=void 0){var a=this.results.length-1,b=this.resultIndex!=void 0?this.resultIndex-1:a;b<0&&(b=a);this.setActiveResult(b)}}; -JSONEditor.SearchBox.prototype.setActiveResult=function(a){if(this.activeResult){var b=this.activeResult.node;this.activeResult.elem=="field"?delete b.searchFieldActive:delete b.searchValueActive;b.updateDom()}!this.results||!this.results[a]?this.activeResult=this.resultIndex=void 0:(this.resultIndex=a,a=this.results[this.resultIndex].node,this.results[this.resultIndex].elem=="field"?a.searchFieldActive=!0:a.searchValueActive=!0,this.activeResult=this.results[this.resultIndex],a.updateDom(),a.scrollTo())}; -JSONEditor.SearchBox.prototype.focusActiveResult=function(){this.activeResult||this.next();this.activeResult&&this.activeResult.node.focus(this.activeResult.elem)};JSONEditor.SearchBox.prototype.clearDelay=function(){this.timeout!=void 0&&(clearTimeout(this.timeout),delete this.timeout)};JSONEditor.SearchBox.prototype.onDelayedSearch=function(){this.clearDelay();var a=this;this.timeout=setTimeout(function(b){a.onSearch(b)},this.delay)}; -JSONEditor.SearchBox.prototype.onSearch=function(a,b){this.clearDelay();var c=this.dom.search.value,c=c.length>0?c:void 0;if(c!=this.lastText||b)if(this.lastText=c,this.results=editor.search(c),this.setActiveResult(void 0),c!=void 0)switch(c=this.results.length,c){case 0:this.dom.results.innerHTML="no results";break;case 1:this.dom.results.innerHTML="1 result";break;default:this.dom.results.innerHTML=c+" results"}else this.dom.results.innerHTML=""}; -JSONEditor.SearchBox.prototype.onKeyDown=function(a){var a=a||window.event,b=a.which||a.keyCode;if(b==27)this.dom.search.value="",this.onSearch(a),JSONEditor.Events.preventDefault(a),JSONEditor.Events.stopPropagation(a);else if(b==13){if(a.ctrlKey)this.onSearch(a,!0);else a.shiftKey?this.previous():this.next();JSONEditor.Events.preventDefault(a);JSONEditor.Events.stopPropagation(a)}};JSONEditor.SearchBox.prototype.onKeyUp=function(a){var a=a||window.event,b=a.which||a.keyCode;if(b!=27&&b!=13)this.onDelayedSearch(a)}; -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,c=document.body;a!=null&&a!=c;)b+=a.offsetLeft,b-=a.scrollLeft,a=a.offsetParent;return b};JSONEditor.getAbsoluteTop=function(a){for(var b=0,c=document.body;a!=null&&a!=c;)b+=a.offsetTop,b-=a.scrollTop,a=a.offsetParent;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=0;e--){var g=f[e];g.specified==!0&&d.removeAttribute(g.name)}JSONEditor.stripFormatting(d)}}; -JSONEditor.setEndOfContentEditable=function(a){var b;document.createRange?(b=document.createRange(),b.selectNodeContents(a),b.collapse(!1),a=window.getSelection(),a.removeAllRanges(),a.addRange(b)):document.selection&&(b=document.body.createTextRange(),b.moveToElementText(a),b.collapse(!1),b.select())};JSONEditor.getInternetExplorerVersion=function(){var a=-1;navigator.appName=="Microsoft Internet Explorer"&&/MSIE ([0-9]{1,}[.0-9]{0,})/.exec(navigator.userAgent)!=null&&(a=parseFloat(RegExp.$1));return a}; -JSONEditor.ieVersion=JSONEditor.getInternetExplorerVersion(); diff --git a/demo.html b/jsoneditor/examples/demo.html similarity index 87% rename from demo.html rename to jsoneditor/examples/demo.html index 84bb4b8..71dc1f7 100644 --- a/demo.html +++ b/jsoneditor/examples/demo.html @@ -1,8 +1,8 @@ - - + +

diff --git a/img/colors.txt b/jsoneditor/img/colors.txt similarity index 100% rename from img/colors.txt rename to jsoneditor/img/colors.txt diff --git a/img/export.sh b/jsoneditor/img/export.sh similarity index 100% rename from img/export.sh rename to jsoneditor/img/export.sh diff --git a/img/jsoneditor-icons.png b/jsoneditor/img/jsoneditor-icons.png similarity index 100% rename from img/jsoneditor-icons.png rename to jsoneditor/img/jsoneditor-icons.png diff --git a/img/jsoneditor-icons.svg b/jsoneditor/img/jsoneditor-icons.svg similarity index 100% rename from img/jsoneditor-icons.svg rename to jsoneditor/img/jsoneditor-icons.svg diff --git a/jsoneditor/jsoneditor-min.js b/jsoneditor/jsoneditor-min.js new file mode 100644 index 0000000..a85644c --- /dev/null +++ b/jsoneditor/jsoneditor-min.js @@ -0,0 +1,109 @@ +/* + + 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-08-16 +*/ +Array.prototype.indexOf||(Array.prototype.indexOf=function(a){for(var b=0;b3){b.scrollTop=b.scrollTop+a/3;c.animateTimeout=setTimeout(g,50)}};g()}}; +JSONEditor.Node=function(a){this.dom={};this.expanded=false;if(a&&a instanceof Object){this.setField(a.field,a.fieldEditable);this.setValue(a.value)}else{this.setField();this.setValue()}};JSONEditor.Node.prototype.setParent=function(a){this.parent=a};JSONEditor.Node.prototype.getParent=function(){return this.parent};JSONEditor.Node.prototype.getEditor=function(){return this.parent?this.parent.getEditor():void 0};JSONEditor.Node.prototype.setField=function(a,b){this.field=a;this.fieldEditable=b==true}; +JSONEditor.Node.prototype.getField=function(){if(this.field===void 0)this.field=this._getDomField();return this.field}; +JSONEditor.Node.prototype.setValue=function(a){var b=this.childs;if(b)for(;b.length;)this.removeChild(b[0]);this.type=this._getType(a);if(this.type=="array"){this.childs=[];for(var c=0,b=a.length;cb+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(false);if(this.mousemove){JSONEditor.Events.removeEventListener(document,"mousemove",this.mousemove);delete this.mousemove}if(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";a.title="Move field (drag and drop)";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.appendChild(e);g.onmousedown=function(b){return function(){a.callback(b)}}(d.value);b.appendChild(g)}document.body.appendChild(b);a.node.setHighlight(true);JSONEditor.freezeHighlight=true;var h=JSONEditor.Events.addEventListener(document,"mousedown",function(){JSONEditor.freezeHighlight=false;a.node.setHighlight(false);document.body.removeChild(b);JSONEditor.Events.removeEventListener(document,"mousedown",h)}),i=JSONEditor.Events.addEventListener(document, +"mousewheel",function(){JSONEditor.freezeHighlight=false;a.node.setHighlight(false);document.body.removeChild(b);JSONEditor.Events.removeEventListener(document,"mousewheel",i)})};JSONEditor.Node.prototype.getAppend=function(){if(!this.append){this.append=new JSONEditor.AppendNode;this.append.setParent(this)}return this.append.getDom()}; +JSONEditor.Node.prototype._createDomRemoveButton=function(){if(this.parent&&(this.parent.type=="array"||this.parent.type=="object")){var a=document.createElement("button");a.className="jsoneditor-remove";a.title="Remove field (including all its childs)";return a}}; +JSONEditor.Node.prototype._createDomDuplicateButton=function(){if(this.parent&&(this.parent.type=="array"||this.parent.type=="object")){var a=document.createElement("button");a.className="jsoneditor-duplicate";a.title="Duplicate field (including all childs)";return a}};JSONEditor.Node.prototype._getType=function(a){return a instanceof Array?"array":a instanceof Object?"object":typeof a=="string"&&typeof this._stringCast(a)!="string"?"string":"auto"}; +JSONEditor.Node.prototype._stringCast=function(a){var b=a.toLowerCase(),c=Number(a),d=parseFloat(a);return a==""?"":b=="null"?null:b=="true"?true:b=="false"?false:!isNaN(c)&&!isNaN(d)?c:a};JSONEditor.Node.prototype._escape=function(a){a=String(a).replace(//g,">").replace(/ /g,"  ").replace(/^ /," ").replace(/ $/," ");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(false);a.focus();break;case "mouseover":this.parent.setHighlight(true);break;case "mouseout":this.parent.setHighlight(false)}}; +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.onkeydown=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;JSONEditor.Events.addEventListener(this.frame,"focus",b,true);JSONEditor.Events.addEventListener(this.frame,"blur",b,true);this.frame.onfocusin=b;this.frame.onfocusout=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);this.tdMenu=c=document.createElement("td");c.className="jsoneditor-menu"; +d.appendChild(c);d=document.createElement("button");d.innerHTML="Expand All";d.title="Expand all fields";d.onclick=function(){a.expandAll()};c.appendChild(d);d=document.createElement("button");d.innerHTML="Collapse All";d.title="Collapse all fields";d.onclick=function(){a.collapseAll()};c.appendChild(d);if(this.options.enableSearch)this.searchBox=new JSONEditor.SearchBox(this,c);this.frame.appendChild(this.head)}; +JSONEditor.prototype._createTable=function(){var a=document.createElement("div");a.className="jsoneditor-content-outer";this.contentOuter=a;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=false;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;if(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.SearchBox=function(a,b){var c=this;this.editor=a;this.timeout=void 0;this.delay=200;this.lastText=void 0;this.dom={};this.dom.container=b;var d=document.createElement("table");this.dom.table=d;d.className="jsoneditor-search";b.appendChild(d);var f=document.createElement("tbody");this.dom.tbody=f;d.appendChild(f);d=document.createElement("tr");f.appendChild(d);f=document.createElement("td");f.className="jsoneditor-search";d.appendChild(f);var e=document.createElement("div");this.dom.results= +e;e.className="jsoneditor-search-results";f.appendChild(e);f=document.createElement("td");f.className="jsoneditor-search";d.appendChild(f);d=document.createElement("div");this.dom.input=d;d.className="jsoneditor-search";d.title="Search fields and values";f.appendChild(d);f=document.createElement("table");f.className="jsoneditor-search-input";d.appendChild(f);e=document.createElement("tbody");f.appendChild(e);d=document.createElement("tr");e.appendChild(d);e=document.createElement("button");e.className= +"jsoneditor-search-refresh";f=document.createElement("td");f.appendChild(e);d.appendChild(f);var g=document.createElement("input");this.dom.search=g;g.className="jsoneditor-search";g.oninput=function(a){c.onDelayedSearch(a)};g.onchange=function(a){c.onSearch(a)};g.onkeydown=function(a){c.onKeyDown(a)};g.onkeyup=function(a){c.onKeyUp(a)};e.onclick=function(){g.select()};f=document.createElement("td");f.appendChild(g);d.appendChild(f);e=document.createElement("button");e.title="Next result (Enter)"; +e.className="jsoneditor-search-next";e.onclick=function(){c.next()};f=document.createElement("td");f.appendChild(e);d.appendChild(f);e=document.createElement("button");e.title="Previous result (Shift+Enter)";e.className="jsoneditor-search-previous";e.onclick=function(){c.previous()};f=document.createElement("td");f.appendChild(e);d.appendChild(f)}; +JSONEditor.SearchBox.prototype.next=function(){if(this.results!=void 0){var a=this.resultIndex!=void 0?this.resultIndex+1:0;a>this.results.length-1&&(a=0);this.setActiveResult(a)}};JSONEditor.SearchBox.prototype.previous=function(){if(this.results!=void 0){var a=this.results.length-1,b=this.resultIndex!=void 0?this.resultIndex-1:a;b<0&&(b=a);this.setActiveResult(b)}}; +JSONEditor.SearchBox.prototype.setActiveResult=function(a){if(this.activeResult){var b=this.activeResult.node;this.activeResult.elem=="field"?delete b.searchFieldActive:delete b.searchValueActive;b.updateDom()}if(!this.results||!this.results[a])this.activeResult=this.resultIndex=void 0;else{this.resultIndex=a;a=this.results[this.resultIndex].node;this.results[this.resultIndex].elem=="field"?a.searchFieldActive=true:a.searchValueActive=true;this.activeResult=this.results[this.resultIndex];a.updateDom(); +a.scrollTo()}};JSONEditor.SearchBox.prototype.focusActiveResult=function(){this.activeResult||this.next();this.activeResult&&this.activeResult.node.focus(this.activeResult.elem)};JSONEditor.SearchBox.prototype.clearDelay=function(){if(this.timeout!=void 0){clearTimeout(this.timeout);delete this.timeout}};JSONEditor.SearchBox.prototype.onDelayedSearch=function(){this.clearDelay();var a=this;this.timeout=setTimeout(function(b){a.onSearch(b)},this.delay)}; +JSONEditor.SearchBox.prototype.onSearch=function(a,b){this.clearDelay();var c=this.dom.search.value,c=c.length>0?c:void 0;if(c!=this.lastText||b){this.lastText=c;this.results=editor.search(c);this.setActiveResult(void 0);if(c!=void 0){c=this.results.length;switch(c){case 0:this.dom.results.innerHTML="no results";break;case 1:this.dom.results.innerHTML="1 result";break;default:this.dom.results.innerHTML=c+" results"}}else this.dom.results.innerHTML=""}}; +JSONEditor.SearchBox.prototype.onKeyDown=function(a){var a=a||window.event,b=a.which||a.keyCode;if(b==27){this.dom.search.value="";this.onSearch(a);alert(1);JSONEditor.Events.preventDefault(a);JSONEditor.Events.stopPropagation(a)}else if(b==13){if(a.ctrlKey)this.onSearch(a,true);else a.shiftKey?this.previous():this.next();JSONEditor.Events.preventDefault(a);JSONEditor.Events.stopPropagation(a)}}; +JSONEditor.SearchBox.prototype.onKeyUp=function(a){var a=a||window.event,b=a.which||a.keyCode;if(b!=27&&b!=13)this.onDelayedSearch(a)};JSONEditor.Events={};JSONEditor.Events.addEventListener=function(a,b,c,d){if(a.addEventListener){d===void 0&&(d=false);b==="mousewheel"&&navigator.userAgent.indexOf("Firefox")>=0&&(b="DOMMouseScroll");a.addEventListener(b,c,d);return c}d=function(){return c.call(a,window.event)};a.attachEvent("on"+b,d);return d}; +JSONEditor.Events.removeEventListener=function(a,b,c,d){if(a.removeEventListener){d===void 0&&(d=false);b==="mousewheel"&&navigator.userAgent.indexOf("Firefox")>=0&&(b="DOMMouseScroll");a.removeEventListener(b,c,d)}else a.detachEvent("on"+b,c)};JSONEditor.Events.stopPropagation=function(a){if(!a)a=window.event;a.stopPropagation?a.stopPropagation():a.cancelBubble=true};JSONEditor.Events.preventDefault=function(a){if(!a)a=window.event;a.preventDefault?a.preventDefault():a.returnValue=false}; +JSONEditor.getAbsoluteLeft=function(a){for(var b=0,c=document.body;a!=null&&a!=c;){b=b+a.offsetLeft;b=b-a.scrollLeft;a=a.offsetParent}return b};JSONEditor.getAbsoluteTop=function(a){for(var b=0,c=document.body;a!=null&&a!=c;){b=b+a.offsetTop;b=b-a.scrollTop;a=a.offsetParent}return b};JSONEditor.addClassName=function(a,b){var c=a.className;if(c.indexOf(b)==-1)a.className=c+(" "+b)}; +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=0;e--){var g=f[e];g.specified==true&&d.removeAttribute(g.name)}JSONEditor.stripFormatting(d)}}; +JSONEditor.setEndOfContentEditable=function(a){var b;if(document.createRange){b=document.createRange();b.selectNodeContents(a);b.collapse(false);a=window.getSelection();a.removeAllRanges();a.addRange(b)}else if(document.selection){b=document.body.createTextRange();b.moveToElementText(a);b.collapse(false);b.select()}}; +JSONEditor.getInternetExplorerVersion=function(){var a=-1;navigator.appName=="Microsoft Internet Explorer"&&/MSIE ([0-9]{1,}[.0-9]{0,})/.exec(navigator.userAgent)!=null&&(a=parseFloat(RegExp.$1));return a};JSONEditor.ieVersion=JSONEditor.getInternetExplorerVersion(); diff --git a/jsoneditor.css b/jsoneditor/jsoneditor.css similarity index 100% rename from jsoneditor.css rename to jsoneditor/jsoneditor.css diff --git a/jsoneditor.js b/jsoneditor/jsoneditor.js similarity index 100% rename from jsoneditor.js rename to jsoneditor/jsoneditor.js diff --git a/todo.txt b/misc/todo.txt similarity index 100% rename from todo.txt rename to misc/todo.txt diff --git a/index_no_ads.html b/test.html similarity index 94% rename from index_no_ads.html rename to test.html index adc7685..d374ca8 100644 --- a/index_no_ads.html +++ b/test.html @@ -43,14 +43,14 @@ - - + + - - + + diff --git a/couchdbeditor.html b/test/couchdbeditor.html similarity index 92% rename from couchdbeditor.html rename to test/couchdbeditor.html index 9d4459f..a44e24f 100644 --- a/couchdbeditor.html +++ b/test/couchdbeditor.html @@ -7,11 +7,11 @@ - + - - + +