From 6d3a50780cfb1cde4b734f2925f96d530a71ceea Mon Sep 17 00:00:00 2001 From: josdejong Date: Sat, 4 May 2013 12:42:54 +0200 Subject: [PATCH] Released version 2.2.0 --- HISTORY.md | 4 ++-- Jakefile.js | 5 ++--- README.md | 15 +++++++-------- app/web/doc/index.html | 1 + component.json | 2 +- jsoneditor-min.js | 2 +- jsoneditor.js | 2 +- package.json | 2 +- 8 files changed, 16 insertions(+), 17 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 96d4d8c..e33ae8b 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,12 +2,12 @@ http://jsoneditoronline.org -## not yet released, version 2.2.0 +## 2013-05-04, version 2.2.0 - 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. +- Added jsoneditor to package managers npm and bower. ## 2013-03-11, version 2.1.1 diff --git a/Jakefile.js b/Jakefile.js index 2d12d35..0b701f2 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -136,6 +136,7 @@ task('zip', ['build', 'minify'], {async: true}, function () { JSONEDITOR_CSS_MIN, 'img/*.*', 'lib/**/*.*', + 'docs/**/*.*', 'examples/**/*.*' ]); var files = filelist.toArray(); @@ -166,7 +167,6 @@ task('webapp', ['build', 'minify'], function () { var webAppLib = webApp + 'lib/'; var webAppAce = webAppLib + 'ace/'; var webAppImg = webApp + 'img/'; - var webAppDoc = webApp + 'doc/'; var appJs = webApp + 'app.js'; var appCss = webApp + 'app.css'; var appCssMin = webApp + 'app-min.css'; @@ -181,7 +181,6 @@ task('webapp', ['build', 'minify'], function () { jake.mkdirP(webAppLib + 'jsoneditor/img/'); jake.mkdirP(webAppLib + 'jsonlint/'); jake.mkdirP(webAppImg); - jake.mkdirP(webAppDoc); // concatenate the javascript files concat({ @@ -234,7 +233,7 @@ task('webapp', ['build', 'minify'], function () { jake.cpR(webAppSrc + 'googlea47c4a0b36d11021.html', webApp); jake.cpR(webAppSrc + 'img/logo.png', webAppImg); jake.cpR(webAppSrc + 'img/header_background.png', webAppImg); - jake.cpR(webAppSrc + 'doc/', webAppDoc); + jake.cpR(webAppSrc + 'doc/', webApp); // update date and verison in index.html replacePlaceholders(webApp + 'index.html'); diff --git a/README.md b/README.md index 3ee2c6c..02ae71b 100644 --- a/README.md +++ b/README.md @@ -83,21 +83,20 @@ download: ### Documentation -Documentation: [https://github.com/josdejong/jsoneditor/tree/master/docs](https://github.com/josdejong/jsoneditor/tree/master/docs) - -Example code: [https://github.com/josdejong/jsoneditor/tree/master/examples](https://github.com/josdejong/jsoneditor/tree/master/examples) - -Source code: [https://github.com/josdejong/jsoneditor](https://github.com/josdejong/jsoneditor) +- Docs: [https://github.com/josdejong/jsoneditor/tree/master/docs](https://github.com/josdejong/jsoneditor/tree/master/docs) +- Examples: [https://github.com/josdejong/jsoneditor/tree/master/examples](https://github.com/josdejong/jsoneditor/tree/master/examples) +- Source: [https://github.com/josdejong/jsoneditor](https://github.com/josdejong/jsoneditor) +- History: [https://github.com/josdejong/jsoneditor/blob/master/HISTORY.md](https://github.com/josdejong/jsoneditor/blob/master/HISTORY.md) ### Build -The code of the JSON Editor is located in the folder `src`. +The code of the JSON Editor is located in the folder `jsoneditor`. The code for the web application in `app/web`. To build the library from sourcecode, run jake in the root of the project. This will generate the files `jsoneditor.js`, -`jsoneditor.css`, etc., and will create a folder `build` containing the -zipped library and the built web application. +`jsoneditor.css`, and minified versions, and will create a folder `build` +containing the zipped library and the built web application. diff --git a/app/web/doc/index.html b/app/web/doc/index.html index 3f9717b..bade264 100644 --- a/app/web/doc/index.html +++ b/app/web/doc/index.html @@ -183,6 +183,7 @@ Ctrl+DDuplicate field Ctrl+DelRemove field + Ctrl+EnterOpen link when on a field containing an url Ctrl+InsInsert a new field with type auto Ctrl+Shift+InsAppend a new field with type auto Ctrl+EExpand or collapse field diff --git a/component.json b/component.json index 2b39dfd..3600ff3 100644 --- a/component.json +++ b/component.json @@ -1,6 +1,6 @@ { "name": "jsoneditor", - "version": "2.2.0-SNAPSHOT", + "version": "2.2.0", "description": "A web-based tool to view, edit and format JSON", "tags": [ "json", diff --git a/jsoneditor-min.js b/jsoneditor-min.js index be6e989..1cac51f 100644 --- a/jsoneditor-min.js +++ b/jsoneditor-min.js @@ -27,7 +27,7 @@ * Copyright (c) 2011-2013 Jos de Jong, http://jsoneditoronline.org * * @author Jos de Jong, - * @version 2.2.0-SNAPSHOT + * @version 2.2.0 * @date 2013-05-04 */ (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) diff --git a/jsoneditor.js b/jsoneditor.js index 84f5f10..72aa61a 100644 --- a/jsoneditor.js +++ b/jsoneditor.js @@ -27,7 +27,7 @@ * Copyright (c) 2011-2013 Jos de Jong, http://jsoneditoronline.org * * @author Jos de Jong, - * @version 2.2.0-SNAPSHOT + * @version 2.2.0 * @date 2013-05-04 */ (function () { diff --git a/package.json b/package.json index 4a40b8c..f9cc9ed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jsoneditor", - "version": "2.2.0-SNAPSHOT", + "version": "2.2.0", "description": "A web-based tool to view, edit and format JSON", "tags": [ "json",