jsoneditor/jsoneditor.min.js

31 lines
62 KiB
JavaScript
Raw Normal View History

/*!
* jsoneditor.js
*
* @brief
* JSONEditor is a web-based tool to view, edit, and format JSON.
* It shows data a clear, editable treeview.
*
* Supported browsers: Chrome, Firefox, Safari, Opera, Internet Explorer 8+
*
* @license
* 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-2014 Jos de Jong, http://jsoneditoronline.org
*
* @author Jos de Jong, <wjosdejong@gmail.com>
* @version 3.0.0-SNAPSHOT
2014-05-30 16:33:11 +08:00
* @date 2014-05-30
2013-05-04 05:26:09 +08:00
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):"object"==typeof exports?exports.JSONEditor=t():e.JSONEditor=t()}(this,function(){return function(e){function t(o){if(i[o])return i[o].exports;var n=i[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var i={};return t.m=e,t.c=i,t.p="",t(0)}([function(e,t,i){var o,n;o=[i(1),i(2),i(3)],n=function(e,t,i){function o(e,t,n){if(!(this instanceof o))throw new Error('JSONEditor constructor called without "new".');var s=i.getInternetExplorerVersion();if(-1!=s&&9>s)throw new Error("Unsupported browser, IE9 or newer required. Please install the newest version of your browser.");arguments.length&&this._create(e,t,n)}return o.modes={},o.prototype._create=function(e,t,i){this.container=e,this.options=t||{},this.json=i||{};var o=this.options.mode||"tree";this.setMode(o)},o.prototype._delete=function(){},o.prototype.set=function(e){this.json=e},o.prototype.get=function(){return this.json},o.prototype.setText=function(e){this.json=i.parse(e)},o.prototype.getText=function(){return JSON.stringify(this.json)},o.prototype.setName=function(e){this.options||(this.options={}),this.options.name=e},o.prototype.getName=function(){return this.options&&this.options.name},o.prototype.setMode=function(e){var t,n,s=this.container,r=i.extend({},this.options);r.mode=e;var a=o.modes[e];if(!a)throw new Error('Unknown mode "'+r.mode+'"');try{if("text"==a.data?(n=this.getName(),t=this.getText(),this._delete(),i.clear(this),i.extend(this,a.editor.prototype),this._create(s,r),this.setName(n),this.setText(t)):(n=this.getName(),t=this.get(),this._delete(),i.clear(this),i.extend(this,a.editor.prototype),this._create(s,r),this.setName(n),this.set(t)),"function"==typeof a.load)try{a.load.call(this)}catch(d){}}catch(d){this._onError(d)}},o.prototype._onError=function(e){if("function"==typeof this.onError&&(i.log("WARNING: JSONEditor.onError is deprecated. Use options.error instead."),this.onError(e)),!this.options||"function"!=typeof this.options.error)throw e;this.options.error(e)},o.registerModes=function(e){for(var t in e)if(e.hasOwnProperty(t)){if(t in o.modes)throw new Error('Mode "'+t+'" already registered');o.modes[t]=e[t]}},o.registerModes(e.modes),o.registerModes(t.modes),o}.apply(null,o),!(void 0!==n&&(e.exports=n))},function(e,t,i){var o,n;o=[i(5),i(6),i(7),i(8),i(4),i(3)],n=function(e,t,i,o,n,s){function r(e,t,i){if(!(this instanceof r))throw new Error('TreeEditor constructor called without "new".');this._create(e,t,i)}return r.prototype._create=function(i,o,n){if(!i)throw new Error("No container element provided.");this.container=i,this.dom={},this.highlighter=new e,this.selection=void 0,this._setOptions(o),this.options.history&&!this.mode.view&&(this.history=new t(this)),this._createFrame(),this._createTable(),this.set(n||{})},r.prototype._delete=function(){this.frame&&this.container&&this.frame.parentNode==this.container&&this.container.removeChild(this.frame)},r.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]);this.mode={edit:"view"!=this.options.mode&&"form"!=this.options.mode,view:"view"==this.options.mode,form:"form"==this.options.mode}},r.focusNode=void 0,r.prototype.set=function(e,t){if(t&&(s.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 r=!1;this.node.expand(r),this.content.appendChild(this.table)}this.history&&this.history.clear()},r.prototype.get=function(){return r.focusNode&&r.focusNode.blur(),this.node?this.node.getValue():void 0},r.prototype.getText=function(){return JSON.stringify(this.get())},r.prototype.setText=function(e){this.set(s.parse(e))},r.prototype.setName=function(e){this.options.name=e,this.node&&this.node.updateField(this.o
}}},o.select=function(e){setTimeout(function(){i.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,void 0==e.field&&(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&&"array"!=this.type&&"object"!=this.type&&(this.valueInnerText=i.getInnerText(this.dom.value)),void 0!=this.valueInnerText)try{var t;if("string"==this.type)t=this._unescapeHTML(this.valueInnerText);else{var o=this._unescapeHTML(this.valueInnerText);t=this._stringCast(o)}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(s){if(this.value=void 0,1!=e)throw s}},o.prototype._updateDomValue=function(){var e=this.dom.value;if(e){var t=this.value,o="auto"==this.type?i.type(t):this.type,n="string"==o&&i.isUrl(t),s="";s=n&&!this.editor.mode.edit?"":"string"==o?"green":"number"==o?"red":"boolean"==o?"darkorange":this._hasChilds()?"":null===t?"#004ED0":"black",e.style.color=s;var r=""==String(this.value)&&"array"!=this.type&&"object"!=this.type;if(r?i.addClassName(e,"empty"):i.removeClassName(e,"empty"),n?i.addClassName(e,"url"):i.removeClassName(e,"url"),"array"==o||"object"==o){var a=this.childs?this.childs.length:0;e.title=this.type+" containing "+a+" items"}else"string"==o&&i.isUrl(t)?this.editor.mode.edit&&(e.title="Ctrl+Click or Ctrl+Enter to open url in new window"):e.title="";this.searchValueActive?i.addClassName(e,"highlight-active"):i.removeClassName(e,"highlight-active"),this.searchValue?i.addClassName(e,"highlight"):i.removeClassName(e,"highlight"),i.stripFormatting(e)}},o.prototype._updateDomField=function(){var e=this.dom.field;if(e){var t=""==String(this.field)&&"array"!=this.parent.type;t?i.addClassName(e,"empty"):i.removeClassName(e,"empty"),this.searchFieldActive?i.addClassName(e,"highlight-active"):i.removeClassName(e,"highlight-active"),this.searchField?i.addClassName(e,"highlight"):i.removeClassName(e,"highlight"),i.stripFormatting(e)}},o.prototype._getDomField=function(e){if(this.dom.field&&this.fieldEditable&&(this.fieldInnerText=i.getInnerText(this.dom.field)),void 0!=this.fieldInnerText)try{var t=this._unescapeHTML(this.fieldInnerText);if(t!==this.field){var o=this.field;this.field=t,this.editor._onAction("editField",{node:this,oldValue:o,newValue:t,oldSelection:this.editor.selection,newSelecti
//# sourceMappingURL=jsoneditor.map