Refactored JSONEditor sourcecode to AMD modules
This commit is contained in:
parent
6eea2b6335
commit
d6da7f548e
|
@ -5,6 +5,8 @@ http://jsoneditoronline.org
|
||||||
|
|
||||||
## not yet released, version 3.0.0
|
## not yet released, version 3.0.0
|
||||||
|
|
||||||
|
- Editor must be loaded as `new JSONEditor(...)` instead of
|
||||||
|
`new jsoneditor.JSONEditor(...)`.
|
||||||
- Large code reorganization.
|
- Large code reorganization.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ download:
|
||||||
<script type="text/javascript" >
|
<script type="text/javascript" >
|
||||||
// create the editor
|
// create the editor
|
||||||
var container = document.getElementById("jsoneditor");
|
var container = document.getElementById("jsoneditor");
|
||||||
var editor = new jsoneditor.JSONEditor(container);
|
var editor = new JSONEditor(container);
|
||||||
|
|
||||||
// set json
|
// set json
|
||||||
var json = {
|
var json = {
|
||||||
|
|
|
@ -52,7 +52,7 @@ Constructs a new JSONEditor.
|
||||||
|
|
||||||
*Returns:*
|
*Returns:*
|
||||||
|
|
||||||
- `{jsoneditor.JSONEditor} editor`
|
- `{JSONEditor} editor`
|
||||||
New instance of a JSONEditor.
|
New instance of a JSONEditor.
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ var options = {
|
||||||
"mode": "tree",
|
"mode": "tree",
|
||||||
"search": true
|
"search": true
|
||||||
};
|
};
|
||||||
var editor = new jsoneditor.JSONEditor (container, options);
|
var editor = new JSONEditor (container, options);
|
||||||
var json = {
|
var json = {
|
||||||
"Array": [1, 2, 3],
|
"Array": [1, 2, 3],
|
||||||
"Boolean": true,
|
"Boolean": true,
|
||||||
|
@ -155,7 +155,7 @@ var options = {
|
||||||
"mode": "text",
|
"mode": "text",
|
||||||
"indentation": 2
|
"indentation": 2
|
||||||
};
|
};
|
||||||
var editor = new jsoneditor.JSONEditor (container, options);
|
var editor = new JSONEditor (container, options);
|
||||||
var json = {
|
var json = {
|
||||||
"Array": [1, 2, 3],
|
"Array": [1, 2, 3],
|
||||||
"Boolean": true,
|
"Boolean": true,
|
||||||
|
|
|
@ -65,7 +65,7 @@ var container = document.getElementById("jsoneditor");
|
||||||
var options = {
|
var options = {
|
||||||
mode: 'tree'
|
mode: 'tree'
|
||||||
};
|
};
|
||||||
var editor = new jsoneditor.JSONEditor(container, options);
|
var editor = new JSONEditor(container, options);
|
||||||
```
|
```
|
||||||
|
|
||||||
To set JSON data in the editor:
|
To set JSON data in the editor:
|
||||||
|
@ -108,7 +108,7 @@ var json = editor.get();
|
||||||
<script type="text/javascript" >
|
<script type="text/javascript" >
|
||||||
// create the editor
|
// create the editor
|
||||||
var container = document.getElementById("jsoneditor");
|
var container = document.getElementById("jsoneditor");
|
||||||
var editor = new jsoneditor.JSONEditor(container);
|
var editor = new JSONEditor(container);
|
||||||
|
|
||||||
// set json
|
// set json
|
||||||
function setJSON () {
|
function setJSON () {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<title>JSONEditor | Basic usage</title>
|
||||||
<link rel="stylesheet" type="text/css" href="../jsoneditor.css">
|
<link rel="stylesheet" type="text/css" href="../jsoneditor.css">
|
||||||
<script type="text/javascript" src="../jsoneditor.js"></script>
|
<script type="text/javascript" src="../jsoneditor.js"></script>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
@ -20,7 +21,7 @@
|
||||||
<script type="text/javascript" >
|
<script type="text/javascript" >
|
||||||
// create the editor
|
// create the editor
|
||||||
var container = document.getElementById('jsoneditor');
|
var container = document.getElementById('jsoneditor');
|
||||||
var editor = new jsoneditor.JSONEditor(container);
|
var editor = new JSONEditor(container);
|
||||||
|
|
||||||
// set json
|
// set json
|
||||||
document.getElementById('setJSON').onclick = function () {
|
document.getElementById('setJSON').onclick = function () {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<title>JSONEditor | Viewer</title>
|
||||||
<link rel="stylesheet" type="text/css" href="../jsoneditor.css">
|
<link rel="stylesheet" type="text/css" href="../jsoneditor.css">
|
||||||
<script type="text/javascript" src="../jsoneditor.js"></script>
|
<script type="text/javascript" src="../jsoneditor.js"></script>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
@ -34,7 +35,7 @@
|
||||||
'string': 'Hello World'
|
'string': 'Hello World'
|
||||||
};
|
};
|
||||||
|
|
||||||
var editor = new jsoneditor.JSONEditor(container, options, json);
|
var editor = new JSONEditor(container, options, json);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<title>JSONEditor | Switch mode</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||||
|
|
||||||
<!-- json editor -->
|
<!-- json editor -->
|
||||||
|
@ -61,7 +62,7 @@
|
||||||
"string": "Hello World"
|
"string": "Hello World"
|
||||||
};
|
};
|
||||||
|
|
||||||
var editor = new jsoneditor.JSONEditor(container, options, json);
|
var editor = new JSONEditor(container, options, json);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<title>JSONEditor | Require.js demo</title>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
#jsoneditor {
|
#jsoneditor {
|
||||||
width: 500px;
|
width: 500px;
|
||||||
height: 500px;
|
height: 500px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<link rel="stylesheet" type="text/css" href="../../jsoneditor.css">
|
||||||
<script data-main="scripts/main" src="scripts/require.js"></script>
|
<script data-main="scripts/main" src="scripts/require.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
var module = '../../../jsoneditor';
|
var module = '../../../jsoneditor';
|
||||||
require([module], function (jsoneditor) {
|
require([module], function (JSONEditor) {
|
||||||
// create the editor
|
// create the editor
|
||||||
var container = document.getElementById('jsoneditor');
|
var container = document.getElementById('jsoneditor');
|
||||||
var editor = new jsoneditor.JSONEditor(container);
|
var editor = new JSONEditor(container);
|
||||||
|
|
||||||
// set json
|
// set json
|
||||||
document.getElementById('setJSON').onclick = function () {
|
document.getElementById('setJSON').onclick = function () {
|
||||||
|
|
|
@ -1,35 +1,36 @@
|
||||||
/*
|
/*
|
||||||
RequireJS 2.1.2 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
|
RequireJS 2.1.13 Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
|
||||||
Available via the MIT or new BSD license.
|
Available via the MIT or new BSD license.
|
||||||
see: http://github.com/jrburke/requirejs for details
|
see: http://github.com/jrburke/requirejs for details
|
||||||
*/
|
*/
|
||||||
var requirejs,require,define;
|
var requirejs,require,define;
|
||||||
(function(Y){function H(b){return"[object Function]"===L.call(b)}function I(b){return"[object Array]"===L.call(b)}function x(b,c){if(b){var d;for(d=0;d<b.length&&(!b[d]||!c(b[d],d,b));d+=1);}}function M(b,c){if(b){var d;for(d=b.length-1;-1<d&&(!b[d]||!c(b[d],d,b));d-=1);}}function r(b,c){return da.call(b,c)}function i(b,c){return r(b,c)&&b[c]}function E(b,c){for(var d in b)if(r(b,d)&&c(b[d],d))break}function Q(b,c,d,i){c&&E(c,function(c,h){if(d||!r(b,h))i&&"string"!==typeof c?(b[h]||(b[h]={}),Q(b[h],
|
(function(ba){function G(b){return"[object Function]"===K.call(b)}function H(b){return"[object Array]"===K.call(b)}function v(b,c){if(b){var d;for(d=0;d<b.length&&(!b[d]||!c(b[d],d,b));d+=1);}}function T(b,c){if(b){var d;for(d=b.length-1;-1<d&&(!b[d]||!c(b[d],d,b));d-=1);}}function t(b,c){return fa.call(b,c)}function m(b,c){return t(b,c)&&b[c]}function B(b,c){for(var d in b)if(t(b,d)&&c(b[d],d))break}function U(b,c,d,e){c&&B(c,function(c,g){if(d||!t(b,g))e&&"object"===typeof c&&c&&!H(c)&&!G(c)&&!(c instanceof
|
||||||
c,d,i)):b[h]=c});return b}function t(b,c){return function(){return c.apply(b,arguments)}}function Z(b){if(!b)return b;var c=Y;x(b.split("."),function(b){c=c[b]});return c}function J(b,c,d,i){c=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);c.requireType=b;c.requireModules=i;d&&(c.originalError=d);return c}function ea(b){function c(a,g,v){var e,n,b,c,d,j,f,h=g&&g.split("/");e=h;var l=m.map,k=l&&l["*"];if(a&&"."===a.charAt(0))if(g){e=i(m.pkgs,g)?h=[g]:h.slice(0,h.length-1);g=a=e.concat(a.split("/"));
|
RegExp)?(b[g]||(b[g]={}),U(b[g],c,d,e)):b[g]=c});return b}function u(b,c){return function(){return c.apply(b,arguments)}}function ca(b){throw b;}function da(b){if(!b)return b;var c=ba;v(b.split("."),function(b){c=c[b]});return c}function C(b,c,d,e){c=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);c.requireType=b;c.requireModules=e;d&&(c.originalError=d);return c}function ga(b){function c(a,k,b){var f,l,c,d,e,g,i,p,k=k&&k.split("/"),h=j.map,n=h&&h["*"];if(a){a=a.split("/");l=a.length-1;j.nodeIdCompat&&
|
||||||
for(e=0;g[e];e+=1)if(n=g[e],"."===n)g.splice(e,1),e-=1;else if(".."===n)if(1===e&&(".."===g[2]||".."===g[0]))break;else 0<e&&(g.splice(e-1,2),e-=2);e=i(m.pkgs,g=a[0]);a=a.join("/");e&&a===g+"/"+e.main&&(a=g)}else 0===a.indexOf("./")&&(a=a.substring(2));if(v&&(h||k)&&l){g=a.split("/");for(e=g.length;0<e;e-=1){b=g.slice(0,e).join("/");if(h)for(n=h.length;0<n;n-=1)if(v=i(l,h.slice(0,n).join("/")))if(v=i(v,b)){c=v;d=e;break}if(c)break;!j&&(k&&i(k,b))&&(j=i(k,b),f=e)}!c&&j&&(c=j,d=f);c&&(g.splice(0,d,
|
Q.test(a[l])&&(a[l]=a[l].replace(Q,""));"."===a[0].charAt(0)&&k&&(l=k.slice(0,k.length-1),a=l.concat(a));l=a;for(c=0;c<l.length;c++)if(d=l[c],"."===d)l.splice(c,1),c-=1;else if(".."===d&&!(0===c||1==c&&".."===l[2]||".."===l[c-1])&&0<c)l.splice(c-1,2),c-=2;a=a.join("/")}if(b&&h&&(k||n)){l=a.split("/");c=l.length;a:for(;0<c;c-=1){e=l.slice(0,c).join("/");if(k)for(d=k.length;0<d;d-=1)if(b=m(h,k.slice(0,d).join("/")))if(b=m(b,e)){f=b;g=c;break a}!i&&(n&&m(n,e))&&(i=m(n,e),p=c)}!f&&i&&(f=i,g=p);f&&(l.splice(0,
|
||||||
c),a=g.join("/"))}return a}function d(a){z&&x(document.getElementsByTagName("script"),function(g){if(g.getAttribute("data-requiremodule")===a&&g.getAttribute("data-requirecontext")===j.contextName)return g.parentNode.removeChild(g),!0})}function y(a){var g=i(m.paths,a);if(g&&I(g)&&1<g.length)return d(a),g.shift(),j.require.undef(a),j.require([a]),!0}function f(a){var g,b=a?a.indexOf("!"):-1;-1<b&&(g=a.substring(0,b),a=a.substring(b+1,a.length));return[g,a]}function h(a,g,b,e){var n,u,d=null,h=g?g.name:
|
g,f),a=l.join("/"))}return(f=m(j.pkgs,a))?f:a}function d(a){z&&v(document.getElementsByTagName("script"),function(k){if(k.getAttribute("data-requiremodule")===a&&k.getAttribute("data-requirecontext")===i.contextName)return k.parentNode.removeChild(k),!0})}function e(a){var k=m(j.paths,a);if(k&&H(k)&&1<k.length)return k.shift(),i.require.undef(a),i.makeRequire(null,{skipMap:!0})([a]),!0}function n(a){var k,c=a?a.indexOf("!"):-1;-1<c&&(k=a.substring(0,c),a=a.substring(c+1,a.length));return[k,a]}function p(a,
|
||||||
null,l=a,m=!0,k="";a||(m=!1,a="_@r"+(L+=1));a=f(a);d=a[0];a=a[1];d&&(d=c(d,h,e),u=i(p,d));a&&(d?k=u&&u.normalize?u.normalize(a,function(a){return c(a,h,e)}):c(a,h,e):(k=c(a,h,e),a=f(k),d=a[0],k=a[1],b=!0,n=j.nameToUrl(k)));b=d&&!u&&!b?"_unnormalized"+(M+=1):"";return{prefix:d,name:k,parentMap:g,unnormalized:!!b,url:n,originalName:l,isDefine:m,id:(d?d+"!"+k:k)+b}}function q(a){var g=a.id,b=i(k,g);b||(b=k[g]=new j.Module(a));return b}function s(a,g,b){var e=a.id,n=i(k,e);if(r(p,e)&&(!n||n.defineEmitComplete))"defined"===
|
k,b,f){var l,d,e=null,g=k?k.name:null,j=a,p=!0,h="";a||(p=!1,a="_@r"+(K+=1));a=n(a);e=a[0];a=a[1];e&&(e=c(e,g,f),d=m(r,e));a&&(e?h=d&&d.normalize?d.normalize(a,function(a){return c(a,g,f)}):c(a,g,f):(h=c(a,g,f),a=n(h),e=a[0],h=a[1],b=!0,l=i.nameToUrl(h)));b=e&&!d&&!b?"_unnormalized"+(O+=1):"";return{prefix:e,name:h,parentMap:k,unnormalized:!!b,url:l,originalName:j,isDefine:p,id:(e?e+"!"+h:h)+b}}function s(a){var k=a.id,b=m(h,k);b||(b=h[k]=new i.Module(a));return b}function q(a,k,b){var f=a.id,c=m(h,
|
||||||
g&&b(p[e]);else q(a).on(g,b)}function C(a,g){var b=a.requireModules,e=!1;if(g)g(a);else if(x(b,function(g){if(g=i(k,g))g.error=a,g.events.error&&(e=!0,g.emit("error",a))}),!e)l.onError(a)}function w(){R.length&&(fa.apply(F,[F.length-1,0].concat(R)),R=[])}function A(a,g,b){var e=a.map.id;a.error?a.emit("error",a.error):(g[e]=!0,x(a.depMaps,function(e,c){var d=e.id,h=i(k,d);h&&(!a.depMatched[c]&&!b[d])&&(i(g,d)?(a.defineDep(c,p[d]),a.check()):A(h,g,b))}),b[e]=!0)}function B(){var a,g,b,e,n=(b=1E3*m.waitSeconds)&&
|
f);if(t(r,f)&&(!c||c.defineEmitComplete))"defined"===k&&b(r[f]);else if(c=s(a),c.error&&"error"===k)b(c.error);else c.on(k,b)}function w(a,b){var c=a.requireModules,f=!1;if(b)b(a);else if(v(c,function(b){if(b=m(h,b))b.error=a,b.events.error&&(f=!0,b.emit("error",a))}),!f)g.onError(a)}function x(){R.length&&(ha.apply(A,[A.length,0].concat(R)),R=[])}function y(a){delete h[a];delete V[a]}function F(a,b,c){var f=a.map.id;a.error?a.emit("error",a.error):(b[f]=!0,v(a.depMaps,function(f,d){var e=f.id,g=
|
||||||
j.startTime+b<(new Date).getTime(),c=[],h=[],f=!1,l=!0;if(!T){T=!0;E(k,function(b){a=b.map;g=a.id;if(b.enabled&&(a.isDefine||h.push(b),!b.error))if(!b.inited&&n)y(g)?f=e=!0:(c.push(g),d(g));else if(!b.inited&&(b.fetched&&a.isDefine)&&(f=!0,!a.prefix))return l=!1});if(n&&c.length)return b=J("timeout","Load timeout for modules: "+c,null,c),b.contextName=j.contextName,C(b);l&&x(h,function(a){A(a,{},{})});if((!n||e)&&f)if((z||$)&&!U)U=setTimeout(function(){U=0;B()},50);T=!1}}function D(a){r(p,a[0])||
|
m(h,e);g&&(!a.depMatched[d]&&!c[e])&&(m(b,e)?(a.defineDep(d,r[e]),a.check()):F(g,b,c))}),c[f]=!0)}function D(){var a,b,c=(a=1E3*j.waitSeconds)&&i.startTime+a<(new Date).getTime(),f=[],l=[],g=!1,h=!0;if(!W){W=!0;B(V,function(a){var i=a.map,j=i.id;if(a.enabled&&(i.isDefine||l.push(a),!a.error))if(!a.inited&&c)e(j)?g=b=!0:(f.push(j),d(j));else if(!a.inited&&(a.fetched&&i.isDefine)&&(g=!0,!i.prefix))return h=!1});if(c&&f.length)return a=C("timeout","Load timeout for modules: "+f,null,f),a.contextName=
|
||||||
q(h(a[0],null,!0)).init(a[1],a[2])}function G(a){var a=a.currentTarget||a.srcElement,b=j.onScriptLoad;a.detachEvent&&!V?a.detachEvent("onreadystatechange",b):a.removeEventListener("load",b,!1);b=j.onScriptError;(!a.detachEvent||V)&&a.removeEventListener("error",b,!1);return{node:a,id:a&&a.getAttribute("data-requiremodule")}}function K(){var a;for(w();F.length;){a=F.shift();if(null===a[0])return C(J("mismatch","Mismatched anonymous define() module: "+a[a.length-1]));D(a)}}var T,W,j,N,U,m={waitSeconds:7,
|
i.contextName,w(a);h&&v(l,function(a){F(a,{},{})});if((!c||b)&&g)if((z||ea)&&!X)X=setTimeout(function(){X=0;D()},50);W=!1}}function E(a){t(r,a[0])||s(p(a[0],null,!0)).init(a[1],a[2])}function I(a){var a=a.currentTarget||a.srcElement,b=i.onScriptLoad;a.detachEvent&&!Y?a.detachEvent("onreadystatechange",b):a.removeEventListener("load",b,!1);b=i.onScriptError;(!a.detachEvent||Y)&&a.removeEventListener("error",b,!1);return{node:a,id:a&&a.getAttribute("data-requiremodule")}}function J(){var a;for(x();A.length;){a=
|
||||||
baseUrl:"./",paths:{},pkgs:{},shim:{},map:{},config:{}},k={},X={},F=[],p={},S={},L=1,M=1;N={require:function(a){return a.require?a.require:a.require=j.makeRequire(a.map)},exports:function(a){a.usingExports=!0;if(a.map.isDefine)return a.exports?a.exports:a.exports=p[a.map.id]={}},module:function(a){return a.module?a.module:a.module={id:a.map.id,uri:a.map.url,config:function(){return m.config&&i(m.config,a.map.id)||{}},exports:p[a.map.id]}}};W=function(a){this.events=i(X,a.id)||{};this.map=a;this.shim=
|
A.shift();if(null===a[0])return w(C("mismatch","Mismatched anonymous define() module: "+a[a.length-1]));E(a)}}var W,Z,i,L,X,j={waitSeconds:7,baseUrl:"./",paths:{},bundles:{},pkgs:{},shim:{},config:{}},h={},V={},$={},A=[],r={},S={},aa={},K=1,O=1;L={require:function(a){return a.require?a.require:a.require=i.makeRequire(a.map)},exports:function(a){a.usingExports=!0;if(a.map.isDefine)return a.exports?r[a.map.id]=a.exports:a.exports=r[a.map.id]={}},module:function(a){return a.module?a.module:a.module=
|
||||||
i(m.shim,a.id);this.depExports=[];this.depMaps=[];this.depMatched=[];this.pluginMaps={};this.depCount=0};W.prototype={init:function(a,b,c,e){e=e||{};if(!this.inited){this.factory=b;if(c)this.on("error",c);else this.events.error&&(c=t(this,function(a){this.emit("error",a)}));this.depMaps=a&&a.slice(0);this.errback=c;this.inited=!0;this.ignore=e.ignore;e.enabled||this.enabled?this.enable():this.check()}},defineDep:function(a,b){this.depMatched[a]||(this.depMatched[a]=!0,this.depCount-=1,this.depExports[a]=
|
{id:a.map.id,uri:a.map.url,config:function(){return m(j.config,a.map.id)||{}},exports:a.exports||(a.exports={})}}};Z=function(a){this.events=m($,a.id)||{};this.map=a;this.shim=m(j.shim,a.id);this.depExports=[];this.depMaps=[];this.depMatched=[];this.pluginMaps={};this.depCount=0};Z.prototype={init:function(a,b,c,f){f=f||{};if(!this.inited){this.factory=b;if(c)this.on("error",c);else this.events.error&&(c=u(this,function(a){this.emit("error",a)}));this.depMaps=a&&a.slice(0);this.errback=c;this.inited=
|
||||||
b)},fetch:function(){if(!this.fetched){this.fetched=!0;j.startTime=(new Date).getTime();var a=this.map;if(this.shim)j.makeRequire(this.map,{enableBuildCallback:!0})(this.shim.deps||[],t(this,function(){return a.prefix?this.callPlugin():this.load()}));else return a.prefix?this.callPlugin():this.load()}},load:function(){var a=this.map.url;S[a]||(S[a]=!0,j.load(this.map.id,a))},check:function(){if(this.enabled&&!this.enabling){var a,b,c=this.map.id;b=this.depExports;var e=this.exports,n=this.factory;
|
!0;this.ignore=f.ignore;f.enabled||this.enabled?this.enable():this.check()}},defineDep:function(a,b){this.depMatched[a]||(this.depMatched[a]=!0,this.depCount-=1,this.depExports[a]=b)},fetch:function(){if(!this.fetched){this.fetched=!0;i.startTime=(new Date).getTime();var a=this.map;if(this.shim)i.makeRequire(this.map,{enableBuildCallback:!0})(this.shim.deps||[],u(this,function(){return a.prefix?this.callPlugin():this.load()}));else return a.prefix?this.callPlugin():this.load()}},load:function(){var a=
|
||||||
if(this.inited)if(this.error)this.emit("error",this.error);else{if(!this.defining){this.defining=!0;if(1>this.depCount&&!this.defined){if(H(n)){if(this.events.error)try{e=j.execCb(c,n,b,e)}catch(d){a=d}else e=j.execCb(c,n,b,e);this.map.isDefine&&((b=this.module)&&void 0!==b.exports&&b.exports!==this.exports?e=b.exports:void 0===e&&this.usingExports&&(e=this.exports));if(a)return a.requireMap=this.map,a.requireModules=[this.map.id],a.requireType="define",C(this.error=a)}else e=n;this.exports=e;if(this.map.isDefine&&
|
this.map.url;S[a]||(S[a]=!0,i.load(this.map.id,a))},check:function(){if(this.enabled&&!this.enabling){var a,b,c=this.map.id;b=this.depExports;var f=this.exports,l=this.factory;if(this.inited)if(this.error)this.emit("error",this.error);else{if(!this.defining){this.defining=!0;if(1>this.depCount&&!this.defined){if(G(l)){if(this.events.error&&this.map.isDefine||g.onError!==ca)try{f=i.execCb(c,l,b,f)}catch(d){a=d}else f=i.execCb(c,l,b,f);this.map.isDefine&&void 0===f&&((b=this.module)?f=b.exports:this.usingExports&&
|
||||||
!this.ignore&&(p[c]=e,l.onResourceLoad))l.onResourceLoad(j,this.map,this.depMaps);delete k[c];this.defined=!0}this.defining=!1;this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=!0)}}else this.fetch()}},callPlugin:function(){var a=this.map,b=a.id,d=h(a.prefix);this.depMaps.push(d);s(d,"defined",t(this,function(e){var n,d;d=this.map.name;var v=this.map.parentMap?this.map.parentMap.name:null,f=j.makeRequire(a.parentMap,{enableBuildCallback:!0,
|
(f=this.exports));if(a)return a.requireMap=this.map,a.requireModules=this.map.isDefine?[this.map.id]:null,a.requireType=this.map.isDefine?"define":"require",w(this.error=a)}else f=l;this.exports=f;if(this.map.isDefine&&!this.ignore&&(r[c]=f,g.onResourceLoad))g.onResourceLoad(i,this.map,this.depMaps);y(c);this.defined=!0}this.defining=!1;this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=!0)}}else this.fetch()}},callPlugin:function(){var a=
|
||||||
skipMap:!0});if(this.map.unnormalized){if(e.normalize&&(d=e.normalize(d,function(a){return c(a,v,!0)})||""),e=h(a.prefix+"!"+d,this.map.parentMap),s(e,"defined",t(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),d=i(k,e.id)){this.depMaps.push(e);if(this.events.error)d.on("error",t(this,function(a){this.emit("error",a)}));d.enable()}}else n=t(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),n.error=t(this,function(a){this.inited=!0;this.error=
|
this.map,b=a.id,d=p(a.prefix);this.depMaps.push(d);q(d,"defined",u(this,function(f){var l,d;d=m(aa,this.map.id);var e=this.map.name,P=this.map.parentMap?this.map.parentMap.name:null,n=i.makeRequire(a.parentMap,{enableBuildCallback:!0});if(this.map.unnormalized){if(f.normalize&&(e=f.normalize(e,function(a){return c(a,P,!0)})||""),f=p(a.prefix+"!"+e,this.map.parentMap),q(f,"defined",u(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),d=m(h,f.id)){this.depMaps.push(f);
|
||||||
a;a.requireModules=[b];E(k,function(a){0===a.map.id.indexOf(b+"_unnormalized")&&delete k[a.map.id]});C(a)}),n.fromText=t(this,function(e,c){var d=a.name,u=h(d),v=O;c&&(e=c);v&&(O=!1);q(u);r(m.config,b)&&(m.config[d]=m.config[b]);try{l.exec(e)}catch(k){throw Error("fromText eval for "+d+" failed: "+k);}v&&(O=!0);this.depMaps.push(u);j.completeLoad(d);f([d],n)}),e.load(a.name,f,n,m)}));j.enable(d,this);this.pluginMaps[d.id]=d},enable:function(){this.enabling=this.enabled=!0;x(this.depMaps,t(this,function(a,
|
if(this.events.error)d.on("error",u(this,function(a){this.emit("error",a)}));d.enable()}}else d?(this.map.url=i.nameToUrl(d),this.load()):(l=u(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),l.error=u(this,function(a){this.inited=!0;this.error=a;a.requireModules=[b];B(h,function(a){0===a.map.id.indexOf(b+"_unnormalized")&&y(a.map.id)});w(a)}),l.fromText=u(this,function(f,c){var d=a.name,e=p(d),P=M;c&&(f=c);P&&(M=!1);s(e);t(j.config,b)&&(j.config[d]=j.config[b]);try{g.exec(f)}catch(h){return w(C("fromtexteval",
|
||||||
b){var c,e;if("string"===typeof a){a=h(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap);this.depMaps[b]=a;if(c=i(N,a.id)){this.depExports[b]=c(this);return}this.depCount+=1;s(a,"defined",t(this,function(a){this.defineDep(b,a);this.check()}));this.errback&&s(a,"error",this.errback)}c=a.id;e=k[c];!r(N,c)&&(e&&!e.enabled)&&j.enable(a,this)}));E(this.pluginMaps,t(this,function(a){var b=i(k,a.id);b&&!b.enabled&&j.enable(a,this)}));this.enabling=!1;this.check()},on:function(a,b){var c=
|
"fromText eval for "+b+" failed: "+h,h,[b]))}P&&(M=!0);this.depMaps.push(e);i.completeLoad(d);n([d],l)}),f.load(a.name,n,l,j))}));i.enable(d,this);this.pluginMaps[d.id]=d},enable:function(){V[this.map.id]=this;this.enabling=this.enabled=!0;v(this.depMaps,u(this,function(a,b){var c,f;if("string"===typeof a){a=p(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap);this.depMaps[b]=a;if(c=m(L,a.id)){this.depExports[b]=c(this);return}this.depCount+=1;q(a,"defined",u(this,function(a){this.defineDep(b,
|
||||||
this.events[a];c||(c=this.events[a]=[]);c.push(b)},emit:function(a,b){x(this.events[a],function(a){a(b)});"error"===a&&delete this.events[a]}};j={config:m,contextName:b,registry:k,defined:p,urlFetched:S,defQueue:F,Module:W,makeModuleMap:h,nextTick:l.nextTick,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=m.pkgs,c=m.shim,e={paths:!0,config:!0,map:!0};E(a,function(a,b){e[b]?"map"===b?Q(m[b],a,!0,!0):Q(m[b],a,!0):m[b]=a});a.shim&&(E(a.shim,function(a,
|
a);this.check()}));this.errback&&q(a,"error",u(this,this.errback))}c=a.id;f=h[c];!t(L,c)&&(f&&!f.enabled)&&i.enable(a,this)}));B(this.pluginMaps,u(this,function(a){var b=m(h,a.id);b&&!b.enabled&&i.enable(a,this)}));this.enabling=!1;this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]);c.push(b)},emit:function(a,b){v(this.events[a],function(a){a(b)});"error"===a&&delete this.events[a]}};i={config:j,contextName:b,registry:h,defined:r,urlFetched:S,defQueue:A,Module:Z,makeModuleMap:p,
|
||||||
b){I(a)&&(a={deps:a});if((a.exports||a.init)&&!a.exportsFn)a.exportsFn=j.makeShimExports(a);c[b]=a}),m.shim=c);a.packages&&(x(a.packages,function(a){a="string"===typeof a?{name:a}:a;b[a.name]={name:a.name,location:a.location||a.name,main:(a.main||"main").replace(ga,"").replace(aa,"")}}),m.pkgs=b);E(k,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=h(b))});if(a.deps||a.callback)j.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;a.init&&(b=a.init.apply(Y,arguments));
|
nextTick:g.nextTick,onError:w,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=j.shim,c={paths:!0,bundles:!0,config:!0,map:!0};B(a,function(a,b){c[b]?(j[b]||(j[b]={}),U(j[b],a,!0,!0)):j[b]=a});a.bundles&&B(a.bundles,function(a,b){v(a,function(a){a!==b&&(aa[a]=b)})});a.shim&&(B(a.shim,function(a,c){H(a)&&(a={deps:a});if((a.exports||a.init)&&!a.exportsFn)a.exportsFn=i.makeShimExports(a);b[c]=a}),j.shim=b);a.packages&&v(a.packages,function(a){var b,
|
||||||
return b||a.exports&&Z(a.exports)}},makeRequire:function(a,d){function f(e,c,u){var i,m;d.enableBuildCallback&&(c&&H(c))&&(c.__requireJsBuild=!0);if("string"===typeof e){if(H(c))return C(J("requireargs","Invalid require call"),u);if(a&&r(N,e))return N[e](k[a.id]);if(l.get)return l.get(j,e,a);i=h(e,a,!1,!0);i=i.id;return!r(p,i)?C(J("notloaded",'Module name "'+i+'" has not been loaded yet for context: '+b+(a?"":". Use require([])"))):p[i]}K();j.nextTick(function(){K();m=q(h(null,a));m.skipMap=d.skipMap;
|
a="string"===typeof a?{name:a}:a;b=a.name;a.location&&(j.paths[b]=a.location);j.pkgs[b]=a.name+"/"+(a.main||"main").replace(ia,"").replace(Q,"")});B(h,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=p(b))});if(a.deps||a.callback)i.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;a.init&&(b=a.init.apply(ba,arguments));return b||a.exports&&da(a.exports)}},makeRequire:function(a,e){function j(c,d,m){var n,q;e.enableBuildCallback&&(d&&G(d))&&(d.__requireJsBuild=
|
||||||
m.init(e,c,u,{enabled:!0});B()});return f}d=d||{};Q(f,{isBrowser:z,toUrl:function(b){var d=b.lastIndexOf("."),g=null;-1!==d&&(g=b.substring(d,b.length),b=b.substring(0,d));return j.nameToUrl(c(b,a&&a.id,!0),g)},defined:function(b){return r(p,h(b,a,!1,!0).id)},specified:function(b){b=h(b,a,!1,!0).id;return r(p,b)||r(k,b)}});a||(f.undef=function(b){w();var c=h(b,a,!0),d=i(k,b);delete p[b];delete S[c.url];delete X[b];d&&(d.events.defined&&(X[b]=d.events),delete k[b])});return f},enable:function(a){i(k,
|
!0);if("string"===typeof c){if(G(d))return w(C("requireargs","Invalid require call"),m);if(a&&t(L,c))return L[c](h[a.id]);if(g.get)return g.get(i,c,a,j);n=p(c,a,!1,!0);n=n.id;return!t(r,n)?w(C("notloaded",'Module name "'+n+'" has not been loaded yet for context: '+b+(a?"":". Use require([])"))):r[n]}J();i.nextTick(function(){J();q=s(p(null,a));q.skipMap=e.skipMap;q.init(c,d,m,{enabled:!0});D()});return j}e=e||{};U(j,{isBrowser:z,toUrl:function(b){var d,e=b.lastIndexOf("."),k=b.split("/")[0];if(-1!==
|
||||||
a.id)&&q(a).enable()},completeLoad:function(a){var b,c,d=i(m.shim,a)||{},h=d.exports;for(w();F.length;){c=F.shift();if(null===c[0]){c[0]=a;if(b)break;b=!0}else c[0]===a&&(b=!0);D(c)}c=i(k,a);if(!b&&!r(p,a)&&c&&!c.inited){if(m.enforceDefine&&(!h||!Z(h)))return y(a)?void 0:C(J("nodefine","No define call for "+a,null,[a]));D([a,d.deps||[],d.exportsFn])}B()},nameToUrl:function(a,b){var c,d,h,f,j,k;if(l.jsExtRegExp.test(a))f=a+(b||"");else{c=m.paths;d=m.pkgs;f=a.split("/");for(j=f.length;0<j;j-=1)if(k=
|
e&&(!("."===k||".."===k)||1<e))d=b.substring(e,b.length),b=b.substring(0,e);return i.nameToUrl(c(b,a&&a.id,!0),d,!0)},defined:function(b){return t(r,p(b,a,!1,!0).id)},specified:function(b){b=p(b,a,!1,!0).id;return t(r,b)||t(h,b)}});a||(j.undef=function(b){x();var c=p(b,a,!0),e=m(h,b);d(b);delete r[b];delete S[c.url];delete $[b];T(A,function(a,c){a[0]===b&&A.splice(c,1)});e&&(e.events.defined&&($[b]=e.events),y(b))});return j},enable:function(a){m(h,a.id)&&s(a).enable()},completeLoad:function(a){var b,
|
||||||
f.slice(0,j).join("/"),h=i(d,k),k=i(c,k)){I(k)&&(k=k[0]);f.splice(0,j,k);break}else if(h){c=a===h.name?h.location+"/"+h.main:h.location;f.splice(0,j,c);break}f=f.join("/");f+=b||(/\?/.test(f)?"":".js");f=("/"===f.charAt(0)||f.match(/^[\w\+\.\-]+:/)?"":m.baseUrl)+f}return m.urlArgs?f+((-1===f.indexOf("?")?"?":"&")+m.urlArgs):f},load:function(a,b){l.load(j,a,b)},execCb:function(a,b,c,d){return b.apply(d,c)},onScriptLoad:function(a){if("load"===a.type||ha.test((a.currentTarget||a.srcElement).readyState))P=
|
c,d=m(j.shim,a)||{},g=d.exports;for(x();A.length;){c=A.shift();if(null===c[0]){c[0]=a;if(b)break;b=!0}else c[0]===a&&(b=!0);E(c)}c=m(h,a);if(!b&&!t(r,a)&&c&&!c.inited){if(j.enforceDefine&&(!g||!da(g)))return e(a)?void 0:w(C("nodefine","No define call for "+a,null,[a]));E([a,d.deps||[],d.exportsFn])}D()},nameToUrl:function(a,b,c){var d,e,h;(d=m(j.pkgs,a))&&(a=d);if(d=m(aa,a))return i.nameToUrl(d,b,c);if(g.jsExtRegExp.test(a))d=a+(b||"");else{d=j.paths;a=a.split("/");for(e=a.length;0<e;e-=1)if(h=a.slice(0,
|
||||||
null,a=G(a),j.completeLoad(a.id)},onScriptError:function(a){var b=G(a);if(!y(b.id))return C(J("scripterror","Script error",a,[b.id]))}};j.require=j.makeRequire();return j}var l,w,A,D,s,G,P,K,ba,ca,ia=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,ja=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,aa=/\.js$/,ga=/^\.\//;w=Object.prototype;var L=w.toString,da=w.hasOwnProperty,fa=Array.prototype.splice,z=!!("undefined"!==typeof window&&navigator&&document),$=!z&&"undefined"!==typeof importScripts,ha=z&&
|
e).join("/"),h=m(d,h)){H(h)&&(h=h[0]);a.splice(0,e,h);break}d=a.join("/");d+=b||(/^data\:|\?/.test(d)||c?"":".js");d=("/"===d.charAt(0)||d.match(/^[\w\+\.\-]+:/)?"":j.baseUrl)+d}return j.urlArgs?d+((-1===d.indexOf("?")?"?":"&")+j.urlArgs):d},load:function(a,b){g.load(i,a,b)},execCb:function(a,b,c,d){return b.apply(d,c)},onScriptLoad:function(a){if("load"===a.type||ja.test((a.currentTarget||a.srcElement).readyState))N=null,a=I(a),i.completeLoad(a.id)},onScriptError:function(a){var b=I(a);if(!e(b.id))return w(C("scripterror",
|
||||||
"PLAYSTATION 3"===navigator.platform?/^complete$/:/^(complete|loaded)$/,V="undefined"!==typeof opera&&"[object Opera]"===opera.toString(),B={},q={},R=[],O=!1;if("undefined"===typeof define){if("undefined"!==typeof requirejs){if(H(requirejs))return;q=requirejs;requirejs=void 0}"undefined"!==typeof require&&!H(require)&&(q=require,require=void 0);l=requirejs=function(b,c,d,y){var f,h="_";!I(b)&&"string"!==typeof b&&(f=b,I(c)?(b=c,c=d,d=y):b=[]);f&&f.context&&(h=f.context);(y=i(B,h))||(y=B[h]=l.s.newContext(h));
|
"Script error for: "+b.id,a,[b.id]))}};i.require=i.makeRequire();return i}var g,x,y,D,I,E,N,J,s,O,ka=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,la=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,Q=/\.js$/,ia=/^\.\//;x=Object.prototype;var K=x.toString,fa=x.hasOwnProperty,ha=Array.prototype.splice,z=!!("undefined"!==typeof window&&"undefined"!==typeof navigator&&window.document),ea=!z&&"undefined"!==typeof importScripts,ja=z&&"PLAYSTATION 3"===navigator.platform?/^complete$/:/^(complete|loaded)$/,
|
||||||
f&&y.configure(f);return y.require(b,c,d)};l.config=function(b){return l(b)};l.nextTick="undefined"!==typeof setTimeout?function(b){setTimeout(b,4)}:function(b){b()};require||(require=l);l.version="2.1.2";l.jsExtRegExp=/^\/|:|\?|\.js$/;l.isBrowser=z;w=l.s={contexts:B,newContext:ea};l({});x(["toUrl","undef","defined","specified"],function(b){l[b]=function(){var c=B._;return c.require[b].apply(c,arguments)}});if(z&&(A=w.head=document.getElementsByTagName("head")[0],D=document.getElementsByTagName("base")[0]))A=
|
Y="undefined"!==typeof opera&&"[object Opera]"===opera.toString(),F={},q={},R=[],M=!1;if("undefined"===typeof define){if("undefined"!==typeof requirejs){if(G(requirejs))return;q=requirejs;requirejs=void 0}"undefined"!==typeof require&&!G(require)&&(q=require,require=void 0);g=requirejs=function(b,c,d,e){var n,p="_";!H(b)&&"string"!==typeof b&&(n=b,H(c)?(b=c,c=d,d=e):b=[]);n&&n.context&&(p=n.context);(e=m(F,p))||(e=F[p]=g.s.newContext(p));n&&e.configure(n);return e.require(b,c,d)};g.config=function(b){return g(b)};
|
||||||
w.head=D.parentNode;l.onError=function(b){throw b;};l.load=function(b,c,d){var i=b&&b.config||{},f;if(z)return f=i.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script"),f.type=i.scriptType||"text/javascript",f.charset="utf-8",f.async=!0,f.setAttribute("data-requirecontext",b.contextName),f.setAttribute("data-requiremodule",c),f.attachEvent&&!(f.attachEvent.toString&&0>f.attachEvent.toString().indexOf("[native code"))&&!V?(O=!0,f.attachEvent("onreadystatechange",
|
g.nextTick="undefined"!==typeof setTimeout?function(b){setTimeout(b,4)}:function(b){b()};require||(require=g);g.version="2.1.13";g.jsExtRegExp=/^\/|:|\?|\.js$/;g.isBrowser=z;x=g.s={contexts:F,newContext:ga};g({});v(["toUrl","undef","defined","specified"],function(b){g[b]=function(){var c=F._;return c.require[b].apply(c,arguments)}});if(z&&(y=x.head=document.getElementsByTagName("head")[0],D=document.getElementsByTagName("base")[0]))y=x.head=D.parentNode;g.onError=ca;g.createNode=function(b){var c=
|
||||||
b.onScriptLoad)):(f.addEventListener("load",b.onScriptLoad,!1),f.addEventListener("error",b.onScriptError,!1)),f.src=d,K=f,D?A.insertBefore(f,D):A.appendChild(f),K=null,f;$&&(importScripts(d),b.completeLoad(c))};z&&M(document.getElementsByTagName("script"),function(b){A||(A=b.parentNode);if(s=b.getAttribute("data-main"))return q.baseUrl||(G=s.split("/"),ba=G.pop(),ca=G.length?G.join("/")+"/":"./",q.baseUrl=ca,s=ba),s=s.replace(aa,""),q.deps=q.deps?q.deps.concat(s):[s],!0});define=function(b,c,d){var i,
|
b.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script");c.type=b.scriptType||"text/javascript";c.charset="utf-8";c.async=!0;return c};g.load=function(b,c,d){var e=b&&b.config||{};if(z)return e=g.createNode(e,c,d),e.setAttribute("data-requirecontext",b.contextName),e.setAttribute("data-requiremodule",c),e.attachEvent&&!(e.attachEvent.toString&&0>e.attachEvent.toString().indexOf("[native code"))&&!Y?(M=!0,e.attachEvent("onreadystatechange",b.onScriptLoad)):
|
||||||
f;"string"!==typeof b&&(d=c,c=b,b=null);I(c)||(d=c,c=[]);!c.length&&H(d)&&d.length&&(d.toString().replace(ia,"").replace(ja,function(b,d){c.push(d)}),c=(1===d.length?["require"]:["require","exports","module"]).concat(c));if(O){if(!(i=K))P&&"interactive"===P.readyState||M(document.getElementsByTagName("script"),function(b){if("interactive"===b.readyState)return P=b}),i=P;i&&(b||(b=i.getAttribute("data-requiremodule")),f=B[i.getAttribute("data-requirecontext")])}(f?f.defQueue:R).push([b,c,d])};define.amd=
|
(e.addEventListener("load",b.onScriptLoad,!1),e.addEventListener("error",b.onScriptError,!1)),e.src=d,J=e,D?y.insertBefore(e,D):y.appendChild(e),J=null,e;if(ea)try{importScripts(d),b.completeLoad(c)}catch(m){b.onError(C("importscripts","importScripts failed for "+c+" at "+d,m,[c]))}};z&&!q.skipDataMain&&T(document.getElementsByTagName("script"),function(b){y||(y=b.parentNode);if(I=b.getAttribute("data-main"))return s=I,q.baseUrl||(E=s.split("/"),s=E.pop(),O=E.length?E.join("/")+"/":"./",q.baseUrl=
|
||||||
{jQuery:!0};l.exec=function(b){return eval(b)};l(q)}})(this);
|
O),s=s.replace(Q,""),g.jsExtRegExp.test(s)&&(s=I),q.deps=q.deps?q.deps.concat(s):[s],!0});define=function(b,c,d){var e,g;"string"!==typeof b&&(d=c,c=b,b=null);H(c)||(d=c,c=null);!c&&G(d)&&(c=[],d.length&&(d.toString().replace(ka,"").replace(la,function(b,d){c.push(d)}),c=(1===d.length?["require"]:["require","exports","module"]).concat(c)));if(M){if(!(e=J))N&&"interactive"===N.readyState||T(document.getElementsByTagName("script"),function(b){if("interactive"===b.readyState)return N=b}),e=N;e&&(b||
|
||||||
|
(b=e.getAttribute("data-requiremodule")),g=F[e.getAttribute("data-requirecontext")])}(g?g.defQueue:R).push([b,c,d])};define.amd={jQuery:!0};g.exec=function(b){return eval(b)};g(q)}})(this);
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
var fs = require('fs'),
|
||||||
|
gulp = require('gulp'),
|
||||||
|
gutil = require('gulp-util'),
|
||||||
|
webpack = require('webpack'),
|
||||||
|
uglify = require('uglify-js');
|
||||||
|
|
||||||
|
var ENTRY = './src/js/JSONEditor.js',
|
||||||
|
HEADER = './src/js/header.js',
|
||||||
|
FILE = 'jsoneditor.js',
|
||||||
|
FILE_MIN = 'jsoneditor.min.js',
|
||||||
|
FILE_MAP = 'jsoneditor.map',
|
||||||
|
DIST = './',
|
||||||
|
JSONEDITOR_JS = DIST + FILE,
|
||||||
|
JSONEDITOR_MIN_JS = DIST + FILE_MIN,
|
||||||
|
JSONEDITOR_MAP_JS = DIST + FILE_MAP;
|
||||||
|
|
||||||
|
// generate banner with today's date and correct version
|
||||||
|
function createBanner() {
|
||||||
|
var today = gutil.date(new Date(), 'yyyy-mm-dd'); // today, formatted as yyyy-mm-dd
|
||||||
|
var version = require('./package.json').version; // math.js version
|
||||||
|
|
||||||
|
return String(fs.readFileSync(HEADER))
|
||||||
|
.replace('@@date', today)
|
||||||
|
.replace('@@version', version);
|
||||||
|
}
|
||||||
|
|
||||||
|
var bannerPlugin = new webpack.BannerPlugin(createBanner(), {
|
||||||
|
entryOnly: true,
|
||||||
|
raw: true
|
||||||
|
});
|
||||||
|
|
||||||
|
var webpackConfig = {
|
||||||
|
entry: ENTRY,
|
||||||
|
output: {
|
||||||
|
library: 'JSONEditor',
|
||||||
|
libraryTarget: 'umd',
|
||||||
|
path: DIST,
|
||||||
|
filename: FILE
|
||||||
|
},
|
||||||
|
plugins: [ bannerPlugin ],
|
||||||
|
cache: true
|
||||||
|
};
|
||||||
|
|
||||||
|
var uglifyConfig = {
|
||||||
|
outSourceMap: FILE_MAP,
|
||||||
|
output: {
|
||||||
|
comments: /@license/
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// create a single instance of the compiler to allow caching
|
||||||
|
var compiler = webpack(webpackConfig);
|
||||||
|
|
||||||
|
gulp.task('bundle', function (cb) {
|
||||||
|
// update the banner contents (has a date in it which should stay up to date)
|
||||||
|
bannerPlugin.banner = createBanner();
|
||||||
|
|
||||||
|
compiler.run(function (err, stats) {
|
||||||
|
if (err) {
|
||||||
|
gutil.log(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
gutil.log('bundled ' + JSONEDITOR_JS);
|
||||||
|
|
||||||
|
// TODO: bundle css
|
||||||
|
|
||||||
|
// TODO: bundle and minify assets
|
||||||
|
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('minify', ['bundle'], function () {
|
||||||
|
var result = uglify.minify([JSONEDITOR_JS], uglifyConfig);
|
||||||
|
|
||||||
|
fs.writeFileSync(JSONEDITOR_MIN_JS, result.code + '\n//# sourceMappingURL=' + FILE_MAP);
|
||||||
|
fs.writeFileSync(JSONEDITOR_MAP_JS, result.map);
|
||||||
|
|
||||||
|
gutil.log('Minified ' + JSONEDITOR_MIN_JS);
|
||||||
|
gutil.log('Mapped ' + JSONEDITOR_MAP_JS);
|
||||||
|
|
||||||
|
// TODO: minify css
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// The default task (called when you run `gulp`)
|
||||||
|
gulp.task('default', ['bundle', 'minify']);
|
3747
jsoneditor.js
3747
jsoneditor.js
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -17,7 +17,7 @@
|
||||||
},
|
},
|
||||||
"bugs": "https://github.com/josdejong/jsoneditor/issues",
|
"bugs": "https://github.com/josdejong/jsoneditor/issues",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "jake"
|
"build": "gulp"
|
||||||
},
|
},
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -25,6 +25,10 @@
|
||||||
"jake-utils": "latest",
|
"jake-utils": "latest",
|
||||||
"archiver": "latest",
|
"archiver": "latest",
|
||||||
"clean-css": "latest",
|
"clean-css": "latest",
|
||||||
|
"gulp": "latest",
|
||||||
|
"gulp-util": "latest",
|
||||||
|
"webpack": "latest",
|
||||||
|
"uglify-js": "latest",
|
||||||
"jsonlint": "latest",
|
"jsonlint": "latest",
|
||||||
"ace": "git://github.com/ajaxorg/ace.git"
|
"ace": "git://github.com/ajaxorg/ace.git"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,211 +0,0 @@
|
||||||
/**
|
|
||||||
* @constructor AppendNode
|
|
||||||
* @extends Node
|
|
||||||
* @param {TreeEditor} editor
|
|
||||||
* Create a new AppendNode. This is a special node which is created at the
|
|
||||||
* end of the list with childs for an object or array
|
|
||||||
*/
|
|
||||||
function AppendNode (editor) {
|
|
||||||
/** @type {TreeEditor} */
|
|
||||||
this.editor = editor;
|
|
||||||
this.dom = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
AppendNode.prototype = new Node();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a table row with an append button.
|
|
||||||
* @return {Element} dom TR element
|
|
||||||
*/
|
|
||||||
AppendNode.prototype.getDom = function () {
|
|
||||||
// TODO: implement a new solution for the append node
|
|
||||||
var dom = this.dom;
|
|
||||||
|
|
||||||
if (dom.tr) {
|
|
||||||
return dom.tr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// a row for the append button
|
|
||||||
var trAppend = document.createElement('tr');
|
|
||||||
trAppend.node = this;
|
|
||||||
dom.tr = trAppend;
|
|
||||||
|
|
||||||
// TODO: consistent naming
|
|
||||||
|
|
||||||
if (this.editor.mode.edit) {
|
|
||||||
// a cell for the dragarea column
|
|
||||||
dom.tdDrag = document.createElement('td');
|
|
||||||
|
|
||||||
// create context menu
|
|
||||||
var tdMenu = document.createElement('td');
|
|
||||||
dom.tdMenu = tdMenu;
|
|
||||||
var menu = document.createElement('button');
|
|
||||||
menu.className = 'contextmenu';
|
|
||||||
menu.title = 'Click to open the actions menu (Ctrl+M)';
|
|
||||||
dom.menu = menu;
|
|
||||||
tdMenu.appendChild(dom.menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
// a cell for the contents (showing text 'empty')
|
|
||||||
var tdAppend = document.createElement('td');
|
|
||||||
var domText = document.createElement('div');
|
|
||||||
domText.innerHTML = '(empty)';
|
|
||||||
domText.className = 'readonly';
|
|
||||||
tdAppend.appendChild(domText);
|
|
||||||
dom.td = tdAppend;
|
|
||||||
dom.text = domText;
|
|
||||||
|
|
||||||
this.updateDom();
|
|
||||||
|
|
||||||
return trAppend;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the HTML dom of the Node
|
|
||||||
*/
|
|
||||||
AppendNode.prototype.updateDom = function () {
|
|
||||||
var dom = this.dom;
|
|
||||||
var tdAppend = dom.td;
|
|
||||||
if (tdAppend) {
|
|
||||||
tdAppend.style.paddingLeft = (this.getLevel() * 24 + 26) + 'px';
|
|
||||||
// TODO: not so nice hard coded offset
|
|
||||||
}
|
|
||||||
|
|
||||||
var domText = dom.text;
|
|
||||||
if (domText) {
|
|
||||||
domText.innerHTML = '(empty ' + this.parent.type + ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
// attach or detach the contents of the append node:
|
|
||||||
// hide when the parent has childs, show when the parent has no childs
|
|
||||||
var trAppend = dom.tr;
|
|
||||||
if (!this.isVisible()) {
|
|
||||||
if (dom.tr.firstChild) {
|
|
||||||
if (dom.tdDrag) {
|
|
||||||
trAppend.removeChild(dom.tdDrag);
|
|
||||||
}
|
|
||||||
if (dom.tdMenu) {
|
|
||||||
trAppend.removeChild(dom.tdMenu);
|
|
||||||
}
|
|
||||||
trAppend.removeChild(tdAppend);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!dom.tr.firstChild) {
|
|
||||||
if (dom.tdDrag) {
|
|
||||||
trAppend.appendChild(dom.tdDrag);
|
|
||||||
}
|
|
||||||
if (dom.tdMenu) {
|
|
||||||
trAppend.appendChild(dom.tdMenu);
|
|
||||||
}
|
|
||||||
trAppend.appendChild(tdAppend);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether the AppendNode is currently visible.
|
|
||||||
* the AppendNode is visible when its parent has no childs (i.e. is empty).
|
|
||||||
* @return {boolean} isVisible
|
|
||||||
*/
|
|
||||||
AppendNode.prototype.isVisible = function () {
|
|
||||||
return (this.parent.childs.length == 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show a contextmenu for this node
|
|
||||||
* @param {HTMLElement} anchor The element to attach the menu to.
|
|
||||||
* @param {function} [onClose] Callback method called when the context menu
|
|
||||||
* is being closed.
|
|
||||||
*/
|
|
||||||
AppendNode.prototype.showContextMenu = function (anchor, onClose) {
|
|
||||||
var node = this;
|
|
||||||
var titles = Node.TYPE_TITLES;
|
|
||||||
var items = [
|
|
||||||
// create append button
|
|
||||||
{
|
|
||||||
'text': 'Append',
|
|
||||||
'title': 'Append a new field with type \'auto\' (Ctrl+Shift+Ins)',
|
|
||||||
'submenuTitle': 'Select the type of the field to be appended',
|
|
||||||
'className': 'insert',
|
|
||||||
'click': function () {
|
|
||||||
node._onAppend('', '', 'auto');
|
|
||||||
},
|
|
||||||
'submenu': [
|
|
||||||
{
|
|
||||||
'text': 'Auto',
|
|
||||||
'className': 'type-auto',
|
|
||||||
'title': titles.auto,
|
|
||||||
'click': function () {
|
|
||||||
node._onAppend('', '', 'auto');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'text': 'Array',
|
|
||||||
'className': 'type-array',
|
|
||||||
'title': titles.array,
|
|
||||||
'click': function () {
|
|
||||||
node._onAppend('', []);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'text': 'Object',
|
|
||||||
'className': 'type-object',
|
|
||||||
'title': titles.object,
|
|
||||||
'click': function () {
|
|
||||||
node._onAppend('', {});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'text': 'String',
|
|
||||||
'className': 'type-string',
|
|
||||||
'title': titles.string,
|
|
||||||
'click': function () {
|
|
||||||
node._onAppend('', '', 'string');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
var menu = new ContextMenu(items, {close: onClose});
|
|
||||||
menu.show(anchor);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle an event. The event is catched centrally by the editor
|
|
||||||
* @param {Event} event
|
|
||||||
*/
|
|
||||||
AppendNode.prototype.onEvent = function (event) {
|
|
||||||
var type = event.type;
|
|
||||||
var target = event.target || event.srcElement;
|
|
||||||
var dom = this.dom;
|
|
||||||
|
|
||||||
// highlight the append nodes parent
|
|
||||||
var menu = dom.menu;
|
|
||||||
if (target == menu) {
|
|
||||||
if (type == 'mouseover') {
|
|
||||||
this.editor.highlighter.highlight(this.parent);
|
|
||||||
}
|
|
||||||
else if (type == 'mouseout') {
|
|
||||||
this.editor.highlighter.unhighlight();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// context menu events
|
|
||||||
if (type == 'click' && target == dom.menu) {
|
|
||||||
var highlighter = this.editor.highlighter;
|
|
||||||
highlighter.highlight(this.parent);
|
|
||||||
highlighter.lock();
|
|
||||||
util.addClassName(dom.menu, 'selected');
|
|
||||||
this.showContextMenu(dom.menu, function () {
|
|
||||||
util.removeClassName(dom.menu, 'selected');
|
|
||||||
highlighter.unlock();
|
|
||||||
highlighter.unhighlight();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == 'keydown') {
|
|
||||||
this.onKeyDown(event);
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,4 +1,6 @@
|
||||||
/**
|
define(['./util'], function (util) {
|
||||||
|
|
||||||
|
/**
|
||||||
* A context menu
|
* A context menu
|
||||||
* @param {Object[]} items Array containing the menu structure
|
* @param {Object[]} items Array containing the menu structure
|
||||||
* TODO: describe structure
|
* TODO: describe structure
|
||||||
|
@ -7,7 +9,7 @@
|
||||||
* context menu is being closed.
|
* context menu is being closed.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function ContextMenu (items, options) {
|
function ContextMenu (items, options) {
|
||||||
this.dom = {};
|
this.dom = {};
|
||||||
|
|
||||||
var me = this;
|
var me = this;
|
||||||
|
@ -140,14 +142,14 @@ function ContextMenu (items, options) {
|
||||||
var height = (items.length + (item.submenu ? item.submenu.length : 0)) * 24;
|
var height = (items.length + (item.submenu ? item.submenu.length : 0)) * 24;
|
||||||
me.maxHeight = Math.max(me.maxHeight, height);
|
me.maxHeight = Math.max(me.maxHeight, height);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the currently visible buttons
|
* Get the currently visible buttons
|
||||||
* @return {Array.<HTMLElement>} buttons
|
* @return {Array.<HTMLElement>} buttons
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ContextMenu.prototype._getVisibleButtons = function () {
|
ContextMenu.prototype._getVisibleButtons = function () {
|
||||||
var buttons = [];
|
var buttons = [];
|
||||||
var me = this;
|
var me = this;
|
||||||
this.dom.items.forEach(function (item) {
|
this.dom.items.forEach(function (item) {
|
||||||
|
@ -167,16 +169,16 @@ ContextMenu.prototype._getVisibleButtons = function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
return buttons;
|
return buttons;
|
||||||
};
|
};
|
||||||
|
|
||||||
// currently displayed context menu, a singleton. We may only have one visible context menu
|
// currently displayed context menu, a singleton. We may only have one visible context menu
|
||||||
ContextMenu.visibleMenu = undefined;
|
ContextMenu.visibleMenu = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach the menu to an anchor
|
* Attach the menu to an anchor
|
||||||
* @param {HTMLElement} anchor
|
* @param {HTMLElement} anchor
|
||||||
*/
|
*/
|
||||||
ContextMenu.prototype.show = function (anchor) {
|
ContextMenu.prototype.show = function (anchor) {
|
||||||
this.hide();
|
this.hide();
|
||||||
|
|
||||||
// calculate whether the menu fits below the anchor
|
// calculate whether the menu fits below the anchor
|
||||||
|
@ -240,12 +242,12 @@ ContextMenu.prototype.show = function (anchor) {
|
||||||
ContextMenu.visibleMenu.hide();
|
ContextMenu.visibleMenu.hide();
|
||||||
}
|
}
|
||||||
ContextMenu.visibleMenu = this;
|
ContextMenu.visibleMenu = this;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hide the context menu if visible
|
* Hide the context menu if visible
|
||||||
*/
|
*/
|
||||||
ContextMenu.prototype.hide = function () {
|
ContextMenu.prototype.hide = function () {
|
||||||
// remove the menu from the DOM
|
// remove the menu from the DOM
|
||||||
if (this.dom.menu.parentNode) {
|
if (this.dom.menu.parentNode) {
|
||||||
this.dom.menu.parentNode.removeChild(this.dom.menu);
|
this.dom.menu.parentNode.removeChild(this.dom.menu);
|
||||||
|
@ -269,15 +271,15 @@ ContextMenu.prototype.hide = function () {
|
||||||
if (ContextMenu.visibleMenu == this) {
|
if (ContextMenu.visibleMenu == this) {
|
||||||
ContextMenu.visibleMenu = undefined;
|
ContextMenu.visibleMenu = undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expand a submenu
|
* Expand a submenu
|
||||||
* Any currently expanded submenu will be hided.
|
* Any currently expanded submenu will be hided.
|
||||||
* @param {Object} domItem
|
* @param {Object} domItem
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ContextMenu.prototype._onExpandItem = function (domItem) {
|
ContextMenu.prototype._onExpandItem = function (domItem) {
|
||||||
var me = this;
|
var me = this;
|
||||||
var alreadyVisible = (domItem == this.expandedItem);
|
var alreadyVisible = (domItem == this.expandedItem);
|
||||||
|
|
||||||
|
@ -309,14 +311,14 @@ ContextMenu.prototype._onExpandItem = function (domItem) {
|
||||||
util.addClassName(ul.parentNode, 'selected');
|
util.addClassName(ul.parentNode, 'selected');
|
||||||
this.expandedItem = domItem;
|
this.expandedItem = domItem;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle onkeydown event
|
* Handle onkeydown event
|
||||||
* @param {Event} event
|
* @param {Event} event
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ContextMenu.prototype._onKeyDown = function (event) {
|
ContextMenu.prototype._onKeyDown = function (event) {
|
||||||
var target = event.target;
|
var target = event.target;
|
||||||
var keynum = event.which;
|
var keynum = event.which;
|
||||||
var handled = false;
|
var handled = false;
|
||||||
|
@ -418,15 +420,15 @@ ContextMenu.prototype._onKeyDown = function (event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if an element is a child of a parent element.
|
* Test if an element is a child of a parent element.
|
||||||
* @param {Element} child
|
* @param {Element} child
|
||||||
* @param {Element} parent
|
* @param {Element} parent
|
||||||
* @return {boolean} isChild
|
* @return {boolean} isChild
|
||||||
*/
|
*/
|
||||||
ContextMenu.prototype._isChildOf = function (child, parent) {
|
ContextMenu.prototype._isChildOf = function (child, parent) {
|
||||||
var e = child.parentNode;
|
var e = child.parentNode;
|
||||||
while (e) {
|
while (e) {
|
||||||
if (e == parent) {
|
if (e == parent) {
|
||||||
|
@ -436,5 +438,7 @@ ContextMenu.prototype._isChildOf = function (child, parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return ContextMenu;
|
||||||
|
});
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
/**
|
define(function () {
|
||||||
|
|
||||||
|
/**
|
||||||
* The highlighter can highlight/unhighlight a node, and
|
* The highlighter can highlight/unhighlight a node, and
|
||||||
* animate the visibility of a context menu.
|
* animate the visibility of a context menu.
|
||||||
* @constructor Highlighter
|
* @constructor Highlighter
|
||||||
*/
|
*/
|
||||||
function Highlighter () {
|
function Highlighter () {
|
||||||
this.locked = false;
|
this.locked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hightlight given node and its childs
|
* Hightlight given node and its childs
|
||||||
* @param {Node} node
|
* @param {Node} node
|
||||||
*/
|
*/
|
||||||
Highlighter.prototype.highlight = function (node) {
|
Highlighter.prototype.highlight = function (node) {
|
||||||
if (this.locked) {
|
if (this.locked) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -29,13 +31,13 @@ Highlighter.prototype.highlight = function (node) {
|
||||||
|
|
||||||
// cancel any current timeout
|
// cancel any current timeout
|
||||||
this._cancelUnhighlight();
|
this._cancelUnhighlight();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unhighlight currently highlighted node.
|
* Unhighlight currently highlighted node.
|
||||||
* Will be done after a delay
|
* Will be done after a delay
|
||||||
*/
|
*/
|
||||||
Highlighter.prototype.unhighlight = function () {
|
Highlighter.prototype.unhighlight = function () {
|
||||||
if (this.locked) {
|
if (this.locked) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -53,30 +55,33 @@ Highlighter.prototype.unhighlight = function () {
|
||||||
me.unhighlightTimer = undefined;
|
me.unhighlightTimer = undefined;
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel an unhighlight action (if before the timeout of the unhighlight action)
|
* Cancel an unhighlight action (if before the timeout of the unhighlight action)
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
Highlighter.prototype._cancelUnhighlight = function () {
|
Highlighter.prototype._cancelUnhighlight = function () {
|
||||||
if (this.unhighlightTimer) {
|
if (this.unhighlightTimer) {
|
||||||
clearTimeout(this.unhighlightTimer);
|
clearTimeout(this.unhighlightTimer);
|
||||||
this.unhighlightTimer = undefined;
|
this.unhighlightTimer = undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lock highlighting or unhighlighting nodes.
|
* Lock highlighting or unhighlighting nodes.
|
||||||
* methods highlight and unhighlight do not work while locked.
|
* methods highlight and unhighlight do not work while locked.
|
||||||
*/
|
*/
|
||||||
Highlighter.prototype.lock = function () {
|
Highlighter.prototype.lock = function () {
|
||||||
this.locked = true;
|
this.locked = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlock highlighting or unhighlighting nodes
|
* Unlock highlighting or unhighlighting nodes
|
||||||
*/
|
*/
|
||||||
Highlighter.prototype.unlock = function () {
|
Highlighter.prototype.unlock = function () {
|
||||||
this.locked = false;
|
this.locked = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return Highlighter;
|
||||||
|
});
|
|
@ -1,9 +1,11 @@
|
||||||
/**
|
define(['./util'], function (util) {
|
||||||
|
|
||||||
|
/**
|
||||||
* @constructor History
|
* @constructor History
|
||||||
* Store action history, enables undo and redo
|
* Store action history, enables undo and redo
|
||||||
* @param {JSONEditor} editor
|
* @param {JSONEditor} editor
|
||||||
*/
|
*/
|
||||||
function History (editor) {
|
function History (editor) {
|
||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
this.clear();
|
this.clear();
|
||||||
|
|
||||||
|
@ -103,15 +105,15 @@ function History (editor) {
|
||||||
// TODO: restore the original caret position and selection with each undo
|
// TODO: restore the original caret position and selection with each undo
|
||||||
// TODO: implement history for actions "expand", "collapse", "scroll", "setDocument"
|
// TODO: implement history for actions "expand", "collapse", "scroll", "setDocument"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The method onChange is executed when the History is changed, and can
|
* The method onChange is executed when the History is changed, and can
|
||||||
* be overloaded.
|
* be overloaded.
|
||||||
*/
|
*/
|
||||||
History.prototype.onChange = function () {};
|
History.prototype.onChange = function () {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new action to the history
|
* Add a new action to the history
|
||||||
* @param {String} action The executed action. Available actions: "editField",
|
* @param {String} action The executed action. Available actions: "editField",
|
||||||
* "editValue", "changeType", "appendNode",
|
* "editValue", "changeType", "appendNode",
|
||||||
|
@ -122,7 +124,7 @@ History.prototype.onChange = function () {};
|
||||||
* value are provided). params contains all information
|
* value are provided). params contains all information
|
||||||
* needed to undo or redo the action.
|
* needed to undo or redo the action.
|
||||||
*/
|
*/
|
||||||
History.prototype.add = function (action, params) {
|
History.prototype.add = function (action, params) {
|
||||||
this.index++;
|
this.index++;
|
||||||
this.history[this.index] = {
|
this.history[this.index] = {
|
||||||
'action': action,
|
'action': action,
|
||||||
|
@ -137,39 +139,39 @@ History.prototype.add = function (action, params) {
|
||||||
|
|
||||||
// fire onchange event
|
// fire onchange event
|
||||||
this.onChange();
|
this.onChange();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear history
|
* Clear history
|
||||||
*/
|
*/
|
||||||
History.prototype.clear = function () {
|
History.prototype.clear = function () {
|
||||||
this.history = [];
|
this.history = [];
|
||||||
this.index = -1;
|
this.index = -1;
|
||||||
|
|
||||||
// fire onchange event
|
// fire onchange event
|
||||||
this.onChange();
|
this.onChange();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if there is an action available for undo
|
* Check if there is an action available for undo
|
||||||
* @return {Boolean} canUndo
|
* @return {Boolean} canUndo
|
||||||
*/
|
*/
|
||||||
History.prototype.canUndo = function () {
|
History.prototype.canUndo = function () {
|
||||||
return (this.index >= 0);
|
return (this.index >= 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if there is an action available for redo
|
* Check if there is an action available for redo
|
||||||
* @return {Boolean} canRedo
|
* @return {Boolean} canRedo
|
||||||
*/
|
*/
|
||||||
History.prototype.canRedo = function () {
|
History.prototype.canRedo = function () {
|
||||||
return (this.index < this.history.length - 1);
|
return (this.index < this.history.length - 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undo the last action
|
* Undo the last action
|
||||||
*/
|
*/
|
||||||
History.prototype.undo = function () {
|
History.prototype.undo = function () {
|
||||||
if (this.canUndo()) {
|
if (this.canUndo()) {
|
||||||
var obj = this.history[this.index];
|
var obj = this.history[this.index];
|
||||||
if (obj) {
|
if (obj) {
|
||||||
|
@ -189,12 +191,12 @@ History.prototype.undo = function () {
|
||||||
// fire onchange event
|
// fire onchange event
|
||||||
this.onChange();
|
this.onChange();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redo the last action
|
* Redo the last action
|
||||||
*/
|
*/
|
||||||
History.prototype.redo = function () {
|
History.prototype.redo = function () {
|
||||||
if (this.canRedo()) {
|
if (this.canRedo()) {
|
||||||
this.index++;
|
this.index++;
|
||||||
|
|
||||||
|
@ -215,4 +217,7 @@ History.prototype.redo = function () {
|
||||||
// fire onchange event
|
// fire onchange event
|
||||||
this.onChange();
|
this.onChange();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return History;
|
||||||
|
});
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
/**
|
define(['./TreeEditor', './TextEditor', './util'], function (TreeEditor, TextEditor, util) {
|
||||||
|
|
||||||
|
/**
|
||||||
* @constructor JSONEditor
|
* @constructor JSONEditor
|
||||||
* @param {Element} container Container element
|
* @param {Element} container Container element
|
||||||
* @param {Object} [options] Object with options. available options:
|
* @param {Object} [options] Object with options. available options:
|
||||||
|
@ -24,7 +26,7 @@
|
||||||
* modes 'text' and 'code'
|
* modes 'text' and 'code'
|
||||||
* @param {Object | undefined} json JSON object
|
* @param {Object | undefined} json JSON object
|
||||||
*/
|
*/
|
||||||
function JSONEditor (container, options, json) {
|
function JSONEditor (container, options, json) {
|
||||||
if (!(this instanceof JSONEditor)) {
|
if (!(this instanceof JSONEditor)) {
|
||||||
throw new Error('JSONEditor constructor called without "new".');
|
throw new Error('JSONEditor constructor called without "new".');
|
||||||
}
|
}
|
||||||
|
@ -39,9 +41,9 @@ function JSONEditor (container, options, json) {
|
||||||
if (arguments.length) {
|
if (arguments.length) {
|
||||||
this._create(container, options, json);
|
this._create(container, options, json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration for all registered modes. Example:
|
* Configuration for all registered modes. Example:
|
||||||
* {
|
* {
|
||||||
* tree: {
|
* tree: {
|
||||||
|
@ -56,88 +58,88 @@ function JSONEditor (container, options, json) {
|
||||||
*
|
*
|
||||||
* @type { Object.<String, {editor: Object, data: String} > }
|
* @type { Object.<String, {editor: Object, data: String} > }
|
||||||
*/
|
*/
|
||||||
JSONEditor.modes = {};
|
JSONEditor.modes = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the JSONEditor
|
* Create the JSONEditor
|
||||||
* @param {Element} container Container element
|
* @param {Element} container Container element
|
||||||
* @param {Object} [options] See description in constructor
|
* @param {Object} [options] See description in constructor
|
||||||
* @param {Object | undefined} json JSON object
|
* @param {Object | undefined} json JSON object
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
JSONEditor.prototype._create = function (container, options, json) {
|
JSONEditor.prototype._create = function (container, options, json) {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.options = options || {};
|
this.options = options || {};
|
||||||
this.json = json || {};
|
this.json = json || {};
|
||||||
|
|
||||||
var mode = this.options.mode || 'tree';
|
var mode = this.options.mode || 'tree';
|
||||||
this.setMode(mode);
|
this.setMode(mode);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detach the editor from the DOM
|
* Detach the editor from the DOM
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
JSONEditor.prototype._delete = function () {};
|
JSONEditor.prototype._delete = function () {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set JSON object in editor
|
* Set JSON object in editor
|
||||||
* @param {Object | undefined} json JSON data
|
* @param {Object | undefined} json JSON data
|
||||||
*/
|
*/
|
||||||
JSONEditor.prototype.set = function (json) {
|
JSONEditor.prototype.set = function (json) {
|
||||||
this.json = json;
|
this.json = json;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get JSON from the editor
|
* Get JSON from the editor
|
||||||
* @returns {Object} json
|
* @returns {Object} json
|
||||||
*/
|
*/
|
||||||
JSONEditor.prototype.get = function () {
|
JSONEditor.prototype.get = function () {
|
||||||
return this.json;
|
return this.json;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set string containing JSON for the editor
|
* Set string containing JSON for the editor
|
||||||
* @param {String | undefined} jsonText
|
* @param {String | undefined} jsonText
|
||||||
*/
|
*/
|
||||||
JSONEditor.prototype.setText = function (jsonText) {
|
JSONEditor.prototype.setText = function (jsonText) {
|
||||||
this.json = util.parse(jsonText);
|
this.json = util.parse(jsonText);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get stringified JSON contents from the editor
|
* Get stringified JSON contents from the editor
|
||||||
* @returns {String} jsonText
|
* @returns {String} jsonText
|
||||||
*/
|
*/
|
||||||
JSONEditor.prototype.getText = function () {
|
JSONEditor.prototype.getText = function () {
|
||||||
return JSON.stringify(this.json);
|
return JSON.stringify(this.json);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a field name for the root node.
|
* Set a field name for the root node.
|
||||||
* @param {String | undefined} name
|
* @param {String | undefined} name
|
||||||
*/
|
*/
|
||||||
JSONEditor.prototype.setName = function (name) {
|
JSONEditor.prototype.setName = function (name) {
|
||||||
if (!this.options) {
|
if (!this.options) {
|
||||||
this.options = {};
|
this.options = {};
|
||||||
}
|
}
|
||||||
this.options.name = name;
|
this.options.name = name;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the field name for the root node.
|
* Get the field name for the root node.
|
||||||
* @return {String | undefined} name
|
* @return {String | undefined} name
|
||||||
*/
|
*/
|
||||||
JSONEditor.prototype.getName = function () {
|
JSONEditor.prototype.getName = function () {
|
||||||
return this.options && this.options.name;
|
return this.options && this.options.name;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the mode of the editor.
|
* Change the mode of the editor.
|
||||||
* JSONEditor will be extended with all methods needed for the chosen mode.
|
* JSONEditor will be extended with all methods needed for the chosen mode.
|
||||||
* @param {String} mode Available modes: 'tree' (default), 'view', 'form',
|
* @param {String} mode Available modes: 'tree' (default), 'view', 'form',
|
||||||
* 'text', and 'code'.
|
* 'text', and 'code'.
|
||||||
*/
|
*/
|
||||||
JSONEditor.prototype.setMode = function (mode) {
|
JSONEditor.prototype.setMode = function (mode) {
|
||||||
var container = this.container,
|
var container = this.container,
|
||||||
options = util.extend({}, this.options),
|
options = util.extend({}, this.options),
|
||||||
data,
|
data,
|
||||||
|
@ -188,15 +190,15 @@ JSONEditor.prototype.setMode = function (mode) {
|
||||||
else {
|
else {
|
||||||
throw new Error('Unknown mode "' + options.mode + '"');
|
throw new Error('Unknown mode "' + options.mode + '"');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throw an error. If an error callback is configured in options.error, this
|
* Throw an error. If an error callback is configured in options.error, this
|
||||||
* callback will be invoked. Else, a regular error is thrown.
|
* callback will be invoked. Else, a regular error is thrown.
|
||||||
* @param {Error} err
|
* @param {Error} err
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
JSONEditor.prototype._onError = function(err) {
|
JSONEditor.prototype._onError = function(err) {
|
||||||
// TODO: onError is deprecated since version 2.2.0. cleanup some day
|
// TODO: onError is deprecated since version 2.2.0. cleanup some day
|
||||||
if (typeof this.onError === 'function') {
|
if (typeof this.onError === 'function') {
|
||||||
util.log('WARNING: JSONEditor.onError is deprecated. ' +
|
util.log('WARNING: JSONEditor.onError is deprecated. ' +
|
||||||
|
@ -210,4 +212,29 @@ JSONEditor.prototype._onError = function(err) {
|
||||||
else {
|
else {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register modes for the JSON Editor
|
||||||
|
* TODO: describe the mode format
|
||||||
|
* @param {Object} modes An object with the mode names as keys, and an object
|
||||||
|
* defining the mode as value
|
||||||
|
*/
|
||||||
|
JSONEditor.registerModes = function (modes) {
|
||||||
|
for (var mode in modes) {
|
||||||
|
if (modes.hasOwnProperty(mode)) {
|
||||||
|
if (mode in JSONEditor.modes) {
|
||||||
|
throw new Error('Mode "' + mode + '" already registered');
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONEditor.modes[mode] = modes[mode];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// register TreeEditor and TextEditor
|
||||||
|
JSONEditor.registerModes(TreeEditor.modes);
|
||||||
|
JSONEditor.registerModes(TextEditor.modes);
|
||||||
|
|
||||||
|
return JSONEditor;
|
||||||
|
});
|
458
src/js/Node.js
458
src/js/Node.js
File diff suppressed because it is too large
Load Diff
|
@ -1,11 +1,13 @@
|
||||||
/**
|
define(function () {
|
||||||
|
|
||||||
|
/**
|
||||||
* @constructor SearchBox
|
* @constructor SearchBox
|
||||||
* Create a search box in given HTML container
|
* Create a search box in given HTML container
|
||||||
* @param {JSONEditor} editor The JSON Editor to attach to
|
* @param {JSONEditor} editor The JSON Editor to attach to
|
||||||
* @param {Element} container HTML container element of where to
|
* @param {Element} container HTML container element of where to
|
||||||
* create the search box
|
* create the search box
|
||||||
*/
|
*/
|
||||||
function SearchBox (editor, container) {
|
function SearchBox (editor, container) {
|
||||||
var searchBox = this;
|
var searchBox = this;
|
||||||
|
|
||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
|
@ -97,14 +99,14 @@ function SearchBox (editor, container) {
|
||||||
td = document.createElement('td');
|
td = document.createElement('td');
|
||||||
td.appendChild(searchPrevious);
|
td.appendChild(searchPrevious);
|
||||||
tr.appendChild(td);
|
tr.appendChild(td);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Go to the next search result
|
* Go to the next search result
|
||||||
* @param {boolean} [focus] If true, focus will be set to the next result
|
* @param {boolean} [focus] If true, focus will be set to the next result
|
||||||
* focus is false by default.
|
* focus is false by default.
|
||||||
*/
|
*/
|
||||||
SearchBox.prototype.next = function(focus) {
|
SearchBox.prototype.next = function(focus) {
|
||||||
if (this.results != undefined) {
|
if (this.results != undefined) {
|
||||||
var index = (this.resultIndex != undefined) ? this.resultIndex + 1 : 0;
|
var index = (this.resultIndex != undefined) ? this.resultIndex + 1 : 0;
|
||||||
if (index > this.results.length - 1) {
|
if (index > this.results.length - 1) {
|
||||||
|
@ -112,14 +114,14 @@ SearchBox.prototype.next = function(focus) {
|
||||||
}
|
}
|
||||||
this._setActiveResult(index, focus);
|
this._setActiveResult(index, focus);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Go to the prevous search result
|
* Go to the prevous search result
|
||||||
* @param {boolean} [focus] If true, focus will be set to the next result
|
* @param {boolean} [focus] If true, focus will be set to the next result
|
||||||
* focus is false by default.
|
* focus is false by default.
|
||||||
*/
|
*/
|
||||||
SearchBox.prototype.previous = function(focus) {
|
SearchBox.prototype.previous = function(focus) {
|
||||||
if (this.results != undefined) {
|
if (this.results != undefined) {
|
||||||
var max = this.results.length - 1;
|
var max = this.results.length - 1;
|
||||||
var index = (this.resultIndex != undefined) ? this.resultIndex - 1 : max;
|
var index = (this.resultIndex != undefined) ? this.resultIndex - 1 : max;
|
||||||
|
@ -128,16 +130,16 @@ SearchBox.prototype.previous = function(focus) {
|
||||||
}
|
}
|
||||||
this._setActiveResult(index, focus);
|
this._setActiveResult(index, focus);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set new value for the current active result
|
* Set new value for the current active result
|
||||||
* @param {Number} index
|
* @param {Number} index
|
||||||
* @param {boolean} [focus] If true, focus will be set to the next result.
|
* @param {boolean} [focus] If true, focus will be set to the next result.
|
||||||
* focus is false by default.
|
* focus is false by default.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
SearchBox.prototype._setActiveResult = function(index, focus) {
|
SearchBox.prototype._setActiveResult = function(index, focus) {
|
||||||
// de-activate current active result
|
// de-activate current active result
|
||||||
if (this.activeResult) {
|
if (this.activeResult) {
|
||||||
var prevNode = this.activeResult.node;
|
var prevNode = this.activeResult.node;
|
||||||
|
@ -178,26 +180,26 @@ SearchBox.prototype._setActiveResult = function(index, focus) {
|
||||||
node.focus(elem);
|
node.focus(elem);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel any running onDelayedSearch.
|
* Cancel any running onDelayedSearch.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
SearchBox.prototype._clearDelay = function() {
|
SearchBox.prototype._clearDelay = function() {
|
||||||
if (this.timeout != undefined) {
|
if (this.timeout != undefined) {
|
||||||
clearTimeout(this.timeout);
|
clearTimeout(this.timeout);
|
||||||
delete this.timeout;
|
delete this.timeout;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a timer to execute a search after a short delay.
|
* Start a timer to execute a search after a short delay.
|
||||||
* Used for reducing the number of searches while typing.
|
* Used for reducing the number of searches while typing.
|
||||||
* @param {Event} event
|
* @param {Event} event
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
SearchBox.prototype._onDelayedSearch = function (event) {
|
SearchBox.prototype._onDelayedSearch = function (event) {
|
||||||
// execute the search after a short delay (reduces the number of
|
// execute the search after a short delay (reduces the number of
|
||||||
// search actions while typing in the search text box)
|
// search actions while typing in the search text box)
|
||||||
this._clearDelay();
|
this._clearDelay();
|
||||||
|
@ -206,9 +208,9 @@ SearchBox.prototype._onDelayedSearch = function (event) {
|
||||||
searchBox._onSearch(event);
|
searchBox._onSearch(event);
|
||||||
},
|
},
|
||||||
this.delay);
|
this.delay);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle onSearch event
|
* Handle onSearch event
|
||||||
* @param {Event} event
|
* @param {Event} event
|
||||||
* @param {boolean} [forceSearch] If true, search will be executed again even
|
* @param {boolean} [forceSearch] If true, search will be executed again even
|
||||||
|
@ -216,7 +218,7 @@ SearchBox.prototype._onDelayedSearch = function (event) {
|
||||||
* Default is false.
|
* Default is false.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
SearchBox.prototype._onSearch = function (event, forceSearch) {
|
SearchBox.prototype._onSearch = function (event, forceSearch) {
|
||||||
this._clearDelay();
|
this._clearDelay();
|
||||||
|
|
||||||
var value = this.dom.search.value;
|
var value = this.dom.search.value;
|
||||||
|
@ -240,14 +242,14 @@ SearchBox.prototype._onSearch = function (event, forceSearch) {
|
||||||
this.dom.results.innerHTML = '';
|
this.dom.results.innerHTML = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle onKeyDown event in the input box
|
* Handle onKeyDown event in the input box
|
||||||
* @param {Event} event
|
* @param {Event} event
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
SearchBox.prototype._onKeyDown = function (event) {
|
SearchBox.prototype._onKeyDown = function (event) {
|
||||||
var keynum = event.which;
|
var keynum = event.which;
|
||||||
if (keynum == 27) { // ESC
|
if (keynum == 27) { // ESC
|
||||||
this.dom.search.value = ''; // clear search
|
this.dom.search.value = ''; // clear search
|
||||||
|
@ -271,16 +273,21 @@ SearchBox.prototype._onKeyDown = function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle onKeyUp event in the input box
|
* Handle onKeyUp event in the input box
|
||||||
* @param {Event} event
|
* @param {Event} event
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
SearchBox.prototype._onKeyUp = function (event) {
|
SearchBox.prototype._onKeyUp = function (event) {
|
||||||
var keynum = event.keyCode;
|
var keynum = event.keyCode;
|
||||||
if (keynum != 27 && keynum != 13) { // !show and !Enter
|
if (keynum != 27 && keynum != 13) { // !show and !Enter
|
||||||
this._onDelayedSearch(event); // For IE 9
|
this._onDelayedSearch(event); // For IE 9
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return SearchBox;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
/**
|
define(['./modebox', './util'], function (modebox, util) {
|
||||||
|
|
||||||
|
/**
|
||||||
* Create a TextEditor and attach it to given container
|
* Create a TextEditor and attach it to given container
|
||||||
* @constructor TextEditor
|
* @constructor TextEditor
|
||||||
* @param {Element} container
|
* @param {Element} container
|
||||||
|
@ -12,15 +14,15 @@
|
||||||
* triggered on change
|
* triggered on change
|
||||||
* @param {JSON | String} [json] initial contents of the formatter
|
* @param {JSON | String} [json] initial contents of the formatter
|
||||||
*/
|
*/
|
||||||
function TextEditor(container, options, json) {
|
function TextEditor(container, options, json) {
|
||||||
if (!(this instanceof TextEditor)) {
|
if (!(this instanceof TextEditor)) {
|
||||||
throw new Error('TextEditor constructor called without "new".');
|
throw new Error('TextEditor constructor called without "new".');
|
||||||
}
|
}
|
||||||
|
|
||||||
this._create(container, options, json);
|
this._create(container, options, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a TextEditor and attach it to given container
|
* Create a TextEditor and attach it to given container
|
||||||
* @constructor TextEditor
|
* @constructor TextEditor
|
||||||
* @param {Element} container
|
* @param {Element} container
|
||||||
|
@ -28,7 +30,7 @@ function TextEditor(container, options, json) {
|
||||||
* @param {JSON | String} [json] initial contents of the formatter
|
* @param {JSON | String} [json] initial contents of the formatter
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
TextEditor.prototype._create = function (container, options, json) {
|
TextEditor.prototype._create = function (container, options, json) {
|
||||||
// read options
|
// read options
|
||||||
options = options || {};
|
options = options || {};
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
@ -99,7 +101,7 @@ TextEditor.prototype._create = function (container, options, json) {
|
||||||
|
|
||||||
// create mode box
|
// create mode box
|
||||||
if (this.options && this.options.modes && this.options.modes.length) {
|
if (this.options && this.options.modes && this.options.modes.length) {
|
||||||
var modeBox = createModeBox(this, this.options.modes, this.options.mode);
|
var modeBox = modebox.create(this, this.options.modes, this.options.mode);
|
||||||
this.menu.appendChild(modeBox);
|
this.menu.appendChild(modeBox);
|
||||||
this.dom.modeBox = modeBox;
|
this.dom.modeBox = modeBox;
|
||||||
}
|
}
|
||||||
|
@ -177,25 +179,25 @@ TextEditor.prototype._create = function (container, options, json) {
|
||||||
else {
|
else {
|
||||||
this.set(json);
|
this.set(json);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detach the editor from the DOM
|
* Detach the editor from the DOM
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
TextEditor.prototype._delete = function () {
|
TextEditor.prototype._delete = function () {
|
||||||
if (this.frame && this.container && this.frame.parentNode == this.container) {
|
if (this.frame && this.container && this.frame.parentNode == this.container) {
|
||||||
this.container.removeChild(this.frame);
|
this.container.removeChild(this.frame);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throw an error. If an error callback is configured in options.error, this
|
* Throw an error. If an error callback is configured in options.error, this
|
||||||
* callback will be invoked. Else, a regular error is thrown.
|
* callback will be invoked. Else, a regular error is thrown.
|
||||||
* @param {Error} err
|
* @param {Error} err
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
TextEditor.prototype._onError = function(err) {
|
TextEditor.prototype._onError = function(err) {
|
||||||
// TODO: onError is deprecated since version 2.2.0. cleanup some day
|
// TODO: onError is deprecated since version 2.2.0. cleanup some day
|
||||||
if (typeof this.onError === 'function') {
|
if (typeof this.onError === 'function') {
|
||||||
util.log('WARNING: JSONEditor.onError is deprecated. ' +
|
util.log('WARNING: JSONEditor.onError is deprecated. ' +
|
||||||
|
@ -209,67 +211,67 @@ TextEditor.prototype._onError = function(err) {
|
||||||
else {
|
else {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compact the code in the formatter
|
* Compact the code in the formatter
|
||||||
*/
|
*/
|
||||||
TextEditor.prototype.compact = function () {
|
TextEditor.prototype.compact = function () {
|
||||||
var json = util.parse(this.getText());
|
var json = util.parse(this.getText());
|
||||||
this.setText(JSON.stringify(json));
|
this.setText(JSON.stringify(json));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format the code in the formatter
|
* Format the code in the formatter
|
||||||
*/
|
*/
|
||||||
TextEditor.prototype.format = function () {
|
TextEditor.prototype.format = function () {
|
||||||
var json = util.parse(this.getText());
|
var json = util.parse(this.getText());
|
||||||
this.setText(JSON.stringify(json, null, this.indentation));
|
this.setText(JSON.stringify(json, null, this.indentation));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set focus to the formatter
|
* Set focus to the formatter
|
||||||
*/
|
*/
|
||||||
TextEditor.prototype.focus = function () {
|
TextEditor.prototype.focus = function () {
|
||||||
if (this.textarea) {
|
if (this.textarea) {
|
||||||
this.textarea.focus();
|
this.textarea.focus();
|
||||||
}
|
}
|
||||||
if (this.editor) {
|
if (this.editor) {
|
||||||
this.editor.focus();
|
this.editor.focus();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resize the formatter
|
* Resize the formatter
|
||||||
*/
|
*/
|
||||||
TextEditor.prototype.resize = function () {
|
TextEditor.prototype.resize = function () {
|
||||||
if (this.editor) {
|
if (this.editor) {
|
||||||
var force = false;
|
var force = false;
|
||||||
this.editor.resize(force);
|
this.editor.resize(force);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set json data in the formatter
|
* Set json data in the formatter
|
||||||
* @param {Object} json
|
* @param {Object} json
|
||||||
*/
|
*/
|
||||||
TextEditor.prototype.set = function(json) {
|
TextEditor.prototype.set = function(json) {
|
||||||
this.setText(JSON.stringify(json, null, this.indentation));
|
this.setText(JSON.stringify(json, null, this.indentation));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get json data from the formatter
|
* Get json data from the formatter
|
||||||
* @return {Object} json
|
* @return {Object} json
|
||||||
*/
|
*/
|
||||||
TextEditor.prototype.get = function() {
|
TextEditor.prototype.get = function() {
|
||||||
return util.parse(this.getText());
|
return util.parse(this.getText());
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the text contents of the TextEditor
|
* Get the text contents of the TextEditor
|
||||||
* @return {String} jsonText
|
* @return {String} jsonText
|
||||||
*/
|
*/
|
||||||
TextEditor.prototype.getText = function() {
|
TextEditor.prototype.getText = function() {
|
||||||
if (this.textarea) {
|
if (this.textarea) {
|
||||||
return this.textarea.value;
|
return this.textarea.value;
|
||||||
}
|
}
|
||||||
|
@ -277,29 +279,34 @@ TextEditor.prototype.getText = function() {
|
||||||
return this.editor.getValue();
|
return this.editor.getValue();
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the text contents of the TextEditor
|
* Set the text contents of the TextEditor
|
||||||
* @param {String} jsonText
|
* @param {String} jsonText
|
||||||
*/
|
*/
|
||||||
TextEditor.prototype.setText = function(jsonText) {
|
TextEditor.prototype.setText = function(jsonText) {
|
||||||
if (this.textarea) {
|
if (this.textarea) {
|
||||||
this.textarea.value = jsonText;
|
this.textarea.value = jsonText;
|
||||||
}
|
}
|
||||||
if (this.editor) {
|
if (this.editor) {
|
||||||
this.editor.setValue(jsonText, -1);
|
this.editor.setValue(jsonText, -1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// register modes at the JSONEditor
|
// define modes
|
||||||
JSONEditor.modes.text = {
|
TextEditor.modes = {
|
||||||
|
text: {
|
||||||
editor: TextEditor,
|
editor: TextEditor,
|
||||||
data: 'text',
|
data: 'text',
|
||||||
load: TextEditor.prototype.format
|
load: TextEditor.prototype.format
|
||||||
};
|
},
|
||||||
JSONEditor.modes.code = {
|
code: {
|
||||||
editor: TextEditor,
|
editor: TextEditor,
|
||||||
data: 'text',
|
data: 'text',
|
||||||
load: TextEditor.prototype.format
|
load: TextEditor.prototype.format
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return TextEditor;
|
||||||
|
});
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
/**
|
define(['./Highlighter', './History', './SearchBox', './Node', './modebox', './util'],
|
||||||
|
function (Highlighter, History, SearchBox, Node, modebox, util) {
|
||||||
|
|
||||||
|
/**
|
||||||
* @constructor TreeEditor
|
* @constructor TreeEditor
|
||||||
* @param {Element} container Container element
|
* @param {Element} container Container element
|
||||||
* @param {Object} [options] Object with options. available options:
|
* @param {Object} [options] Object with options. available options:
|
||||||
|
@ -14,22 +17,22 @@
|
||||||
* {String} name Field name for the root node.
|
* {String} name Field name for the root node.
|
||||||
* @param {Object | undefined} json JSON object
|
* @param {Object | undefined} json JSON object
|
||||||
*/
|
*/
|
||||||
function TreeEditor(container, options, json) {
|
function TreeEditor(container, options, json) {
|
||||||
if (!(this instanceof TreeEditor)) {
|
if (!(this instanceof TreeEditor)) {
|
||||||
throw new Error('TreeEditor constructor called without "new".');
|
throw new Error('TreeEditor constructor called without "new".');
|
||||||
}
|
}
|
||||||
|
|
||||||
this._create(container, options, json);
|
this._create(container, options, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the TreeEditor
|
* Create the TreeEditor
|
||||||
* @param {Element} container Container element
|
* @param {Element} container Container element
|
||||||
* @param {Object} [options] See description in constructor
|
* @param {Object} [options] See description in constructor
|
||||||
* @param {Object | undefined} json JSON object
|
* @param {Object | undefined} json JSON object
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype._create = function (container, options, json) {
|
TreeEditor.prototype._create = function (container, options, json) {
|
||||||
if (!container) {
|
if (!container) {
|
||||||
throw new Error('No container element provided.');
|
throw new Error('No container element provided.');
|
||||||
}
|
}
|
||||||
|
@ -48,24 +51,24 @@ TreeEditor.prototype._create = function (container, options, json) {
|
||||||
this._createTable();
|
this._createTable();
|
||||||
|
|
||||||
this.set(json || {});
|
this.set(json || {});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detach the editor from the DOM
|
* Detach the editor from the DOM
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype._delete = function () {
|
TreeEditor.prototype._delete = function () {
|
||||||
if (this.frame && this.container && this.frame.parentNode == this.container) {
|
if (this.frame && this.container && this.frame.parentNode == this.container) {
|
||||||
this.container.removeChild(this.frame);
|
this.container.removeChild(this.frame);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize and set default options
|
* Initialize and set default options
|
||||||
* @param {Object} [options] See description in constructor
|
* @param {Object} [options] See description in constructor
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype._setOptions = function (options) {
|
TreeEditor.prototype._setOptions = function (options) {
|
||||||
this.options = {
|
this.options = {
|
||||||
search: true,
|
search: true,
|
||||||
history: true,
|
history: true,
|
||||||
|
@ -80,28 +83,6 @@ TreeEditor.prototype._setOptions = function (options) {
|
||||||
this.options[prop] = options[prop];
|
this.options[prop] = options[prop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for deprecated options
|
|
||||||
if (options['enableSearch']) {
|
|
||||||
// deprecated since version 1.6.0, 2012-11-03
|
|
||||||
this.options.search = options['enableSearch'];
|
|
||||||
util.log('WARNING: Option "enableSearch" is deprecated. Use "search" instead.');
|
|
||||||
}
|
|
||||||
if (options['enableHistory']) {
|
|
||||||
// deprecated since version 1.6.0, 2012-11-03
|
|
||||||
this.options.history = options['enableHistory'];
|
|
||||||
util.log('WARNING: Option "enableHistory" is deprecated. Use "history" instead.');
|
|
||||||
}
|
|
||||||
if (options['mode'] == 'editor') {
|
|
||||||
// deprecated since version 2.2.0, 2013-04-30
|
|
||||||
this.options.mode = 'tree';
|
|
||||||
util.log('WARNING: Mode "editor" is deprecated. Use "tree" instead.');
|
|
||||||
}
|
|
||||||
if (options['mode'] == 'viewer') {
|
|
||||||
// deprecated since version 2.2.0, 2013-04-30
|
|
||||||
this.options.mode = 'view';
|
|
||||||
util.log('WARNING: Mode "viewer" is deprecated. Use "view" instead.');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// interpret the mode options
|
// interpret the mode options
|
||||||
|
@ -110,18 +91,18 @@ TreeEditor.prototype._setOptions = function (options) {
|
||||||
view: (this.options.mode == 'view'),
|
view: (this.options.mode == 'view'),
|
||||||
form: (this.options.mode == 'form')
|
form: (this.options.mode == 'form')
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// node currently being edited
|
// node currently being edited
|
||||||
TreeEditor.focusNode = undefined;
|
TreeEditor.focusNode = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set JSON object in editor
|
* Set JSON object in editor
|
||||||
* @param {Object | undefined} json JSON data
|
* @param {Object | undefined} json JSON data
|
||||||
* @param {String} [name] Optional field name for the root node.
|
* @param {String} [name] Optional field name for the root node.
|
||||||
* Can also be set using setName(name).
|
* Can also be set using setName(name).
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.set = function (json, name) {
|
TreeEditor.prototype.set = function (json, name) {
|
||||||
// adjust field name for root node
|
// adjust field name for root node
|
||||||
if (name) {
|
if (name) {
|
||||||
// TODO: deprecated since version 2.2.0. Cleanup some day.
|
// TODO: deprecated since version 2.2.0. Cleanup some day.
|
||||||
|
@ -156,13 +137,13 @@ TreeEditor.prototype.set = function (json, name) {
|
||||||
if (this.history) {
|
if (this.history) {
|
||||||
this.history.clear();
|
this.history.clear();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get JSON object from editor
|
* Get JSON object from editor
|
||||||
* @return {Object | undefined} json
|
* @return {Object | undefined} json
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.get = function () {
|
TreeEditor.prototype.get = function () {
|
||||||
// remove focus from currently edited node
|
// remove focus from currently edited node
|
||||||
if (TreeEditor.focusNode) {
|
if (TreeEditor.focusNode) {
|
||||||
TreeEditor.focusNode.blur();
|
TreeEditor.focusNode.blur();
|
||||||
|
@ -174,69 +155,69 @@ TreeEditor.prototype.get = function () {
|
||||||
else {
|
else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the text contents of the TreeEditor
|
* Get the text contents of the TreeEditor
|
||||||
* @return {String} jsonText
|
* @return {String} jsonText
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.getText = function() {
|
TreeEditor.prototype.getText = function() {
|
||||||
return JSON.stringify(this.get());
|
return JSON.stringify(this.get());
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the text contents of the TreeEditor
|
* Set the text contents of the TreeEditor
|
||||||
* @param {String} jsonText
|
* @param {String} jsonText
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.setText = function(jsonText) {
|
TreeEditor.prototype.setText = function(jsonText) {
|
||||||
this.set(util.parse(jsonText));
|
this.set(util.parse(jsonText));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a field name for the root node.
|
* Set a field name for the root node.
|
||||||
* @param {String | undefined} name
|
* @param {String | undefined} name
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.setName = function (name) {
|
TreeEditor.prototype.setName = function (name) {
|
||||||
this.options.name = name;
|
this.options.name = name;
|
||||||
if (this.node) {
|
if (this.node) {
|
||||||
this.node.updateField(this.options.name);
|
this.node.updateField(this.options.name);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the field name for the root node.
|
* Get the field name for the root node.
|
||||||
* @return {String | undefined} name
|
* @return {String | undefined} name
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.getName = function () {
|
TreeEditor.prototype.getName = function () {
|
||||||
return this.options.name;
|
return this.options.name;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the root node from the editor
|
* Remove the root node from the editor
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.clear = function () {
|
TreeEditor.prototype.clear = function () {
|
||||||
if (this.node) {
|
if (this.node) {
|
||||||
this.node.collapse();
|
this.node.collapse();
|
||||||
this.tbody.removeChild(this.node.getDom());
|
this.tbody.removeChild(this.node.getDom());
|
||||||
delete this.node;
|
delete this.node;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the root node for the json editor
|
* Set the root node for the json editor
|
||||||
* @param {Node} node
|
* @param {Node} node
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype._setRoot = function (node) {
|
TreeEditor.prototype._setRoot = function (node) {
|
||||||
this.clear();
|
this.clear();
|
||||||
|
|
||||||
this.node = node;
|
this.node = node;
|
||||||
|
|
||||||
// append to the dom
|
// append to the dom
|
||||||
this.tbody.appendChild(node.getDom());
|
this.tbody.appendChild(node.getDom());
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search text in all nodes
|
* Search text in all nodes
|
||||||
* The nodes will be expanded when the text is found one of its childs,
|
* The nodes will be expanded when the text is found one of its childs,
|
||||||
* else it will be collapsed. Searches are case insensitive.
|
* else it will be collapsed. Searches are case insensitive.
|
||||||
|
@ -248,7 +229,7 @@ TreeEditor.prototype._setRoot = function (node) {
|
||||||
* the result is found ('field' or
|
* the result is found ('field' or
|
||||||
* 'value')
|
* 'value')
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.search = function (text) {
|
TreeEditor.prototype.search = function (text) {
|
||||||
var results;
|
var results;
|
||||||
if (this.node) {
|
if (this.node) {
|
||||||
this.content.removeChild(this.table); // Take the table offline
|
this.content.removeChild(this.table); // Take the table offline
|
||||||
|
@ -260,31 +241,31 @@ TreeEditor.prototype.search = function (text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expand all nodes
|
* Expand all nodes
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.expandAll = function () {
|
TreeEditor.prototype.expandAll = function () {
|
||||||
if (this.node) {
|
if (this.node) {
|
||||||
this.content.removeChild(this.table); // Take the table offline
|
this.content.removeChild(this.table); // Take the table offline
|
||||||
this.node.expand();
|
this.node.expand();
|
||||||
this.content.appendChild(this.table); // Put the table online again
|
this.content.appendChild(this.table); // Put the table online again
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collapse all nodes
|
* Collapse all nodes
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.collapseAll = function () {
|
TreeEditor.prototype.collapseAll = function () {
|
||||||
if (this.node) {
|
if (this.node) {
|
||||||
this.content.removeChild(this.table); // Take the table offline
|
this.content.removeChild(this.table); // Take the table offline
|
||||||
this.node.collapse();
|
this.node.collapse();
|
||||||
this.content.appendChild(this.table); // Put the table online again
|
this.content.appendChild(this.table); // Put the table online again
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The method onChange is called whenever a field or value is changed, created,
|
* The method onChange is called whenever a field or value is changed, created,
|
||||||
* deleted, duplicated, etc.
|
* deleted, duplicated, etc.
|
||||||
* @param {String} action Change action. Available values: "editField",
|
* @param {String} action Change action. Available values: "editField",
|
||||||
|
@ -298,7 +279,7 @@ TreeEditor.prototype.collapseAll = function () {
|
||||||
* needed to undo or redo the action.
|
* needed to undo or redo the action.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype._onAction = function (action, params) {
|
TreeEditor.prototype._onAction = function (action, params) {
|
||||||
// add an action to the history
|
// add an action to the history
|
||||||
if (this.history) {
|
if (this.history) {
|
||||||
this.history.add(action, params);
|
this.history.add(action, params);
|
||||||
|
@ -313,14 +294,14 @@ TreeEditor.prototype._onAction = function (action, params) {
|
||||||
util.log('Error in change callback: ', err);
|
util.log('Error in change callback: ', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start autoscrolling when given mouse position is above the top of the
|
* Start autoscrolling when given mouse position is above the top of the
|
||||||
* editor contents, or below the bottom.
|
* editor contents, or below the bottom.
|
||||||
* @param {Number} mouseY Absolute mouse position in pixels
|
* @param {Number} mouseY Absolute mouse position in pixels
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.startAutoScroll = function (mouseY) {
|
TreeEditor.prototype.startAutoScroll = function (mouseY) {
|
||||||
var me = this;
|
var me = this;
|
||||||
var content = this.content;
|
var content = this.content;
|
||||||
var top = util.getAbsoluteTop(content);
|
var top = util.getAbsoluteTop(content);
|
||||||
|
@ -355,12 +336,12 @@ TreeEditor.prototype.startAutoScroll = function (mouseY) {
|
||||||
else {
|
else {
|
||||||
this.stopAutoScroll();
|
this.stopAutoScroll();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop auto scrolling. Only applicable when scrolling
|
* Stop auto scrolling. Only applicable when scrolling
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.stopAutoScroll = function () {
|
TreeEditor.prototype.stopAutoScroll = function () {
|
||||||
if (this.autoScrollTimer) {
|
if (this.autoScrollTimer) {
|
||||||
clearTimeout(this.autoScrollTimer);
|
clearTimeout(this.autoScrollTimer);
|
||||||
delete this.autoScrollTimer;
|
delete this.autoScrollTimer;
|
||||||
|
@ -368,10 +349,10 @@ TreeEditor.prototype.stopAutoScroll = function () {
|
||||||
if (this.autoScrollStep) {
|
if (this.autoScrollStep) {
|
||||||
delete this.autoScrollStep;
|
delete this.autoScrollStep;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the focus to an element in the TreeEditor, set text selection, and
|
* Set the focus to an element in the TreeEditor, set text selection, and
|
||||||
* set scroll position.
|
* set scroll position.
|
||||||
* @param {Object} selection An object containing fields:
|
* @param {Object} selection An object containing fields:
|
||||||
|
@ -380,7 +361,7 @@ TreeEditor.prototype.stopAutoScroll = function () {
|
||||||
* {Range | TextRange} range A text selection
|
* {Range | TextRange} range A text selection
|
||||||
* {Number} scrollTop Scroll position
|
* {Number} scrollTop Scroll position
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.setSelection = function (selection) {
|
TreeEditor.prototype.setSelection = function (selection) {
|
||||||
if (!selection) {
|
if (!selection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -395,9 +376,9 @@ TreeEditor.prototype.setSelection = function (selection) {
|
||||||
if (selection.dom) {
|
if (selection.dom) {
|
||||||
selection.dom.focus();
|
selection.dom.focus();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current focus
|
* Get the current focus
|
||||||
* @return {Object} selection An object containing fields:
|
* @return {Object} selection An object containing fields:
|
||||||
* {Element | undefined} dom The dom element
|
* {Element | undefined} dom The dom element
|
||||||
|
@ -405,15 +386,15 @@ TreeEditor.prototype.setSelection = function (selection) {
|
||||||
* {Range | TextRange} range A text selection
|
* {Range | TextRange} range A text selection
|
||||||
* {Number} scrollTop Scroll position
|
* {Number} scrollTop Scroll position
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.getSelection = function () {
|
TreeEditor.prototype.getSelection = function () {
|
||||||
return {
|
return {
|
||||||
dom: TreeEditor.domFocus,
|
dom: TreeEditor.domFocus,
|
||||||
scrollTop: this.content ? this.content.scrollTop : 0,
|
scrollTop: this.content ? this.content.scrollTop : 0,
|
||||||
range: util.getSelectionOffset()
|
range: util.getSelectionOffset()
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adjust the scroll position such that given top position is shown at 1/4
|
* Adjust the scroll position such that given top position is shown at 1/4
|
||||||
* of the window height.
|
* of the window height.
|
||||||
* @param {Number} top
|
* @param {Number} top
|
||||||
|
@ -422,7 +403,7 @@ TreeEditor.prototype.getSelection = function () {
|
||||||
* when animation is finished, or false
|
* when animation is finished, or false
|
||||||
* when not.
|
* when not.
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype.scrollTo = function (top, callback) {
|
TreeEditor.prototype.scrollTo = function (top, callback) {
|
||||||
var content = this.content;
|
var content = this.content;
|
||||||
if (content) {
|
if (content) {
|
||||||
var editor = this;
|
var editor = this;
|
||||||
|
@ -467,13 +448,13 @@ TreeEditor.prototype.scrollTo = function (top, callback) {
|
||||||
callback(false);
|
callback(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create main frame
|
* Create main frame
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype._createFrame = function () {
|
TreeEditor.prototype._createFrame = function () {
|
||||||
// create the frame
|
// create the frame
|
||||||
this.frame = document.createElement('div');
|
this.frame = document.createElement('div');
|
||||||
this.frame.className = 'jsoneditor';
|
this.frame.className = 'jsoneditor';
|
||||||
|
@ -481,9 +462,9 @@ TreeEditor.prototype._createFrame = function () {
|
||||||
|
|
||||||
// create one global event listener to handle all events from all nodes
|
// create one global event listener to handle all events from all nodes
|
||||||
var editor = this;
|
var editor = this;
|
||||||
var onEvent = function (event) {
|
function onEvent(event) {
|
||||||
editor._onEvent(event);
|
editor._onEvent(event);
|
||||||
};
|
}
|
||||||
this.frame.onclick = function (event) {
|
this.frame.onclick = function (event) {
|
||||||
var target = event.target;// || event.srcElement;
|
var target = event.target;// || event.srcElement;
|
||||||
|
|
||||||
|
@ -568,7 +549,7 @@ TreeEditor.prototype._createFrame = function () {
|
||||||
|
|
||||||
// create mode box
|
// create mode box
|
||||||
if (this.options && this.options.modes && this.options.modes.length) {
|
if (this.options && this.options.modes && this.options.modes.length) {
|
||||||
var modeBox = createModeBox(this, this.options.modes, this.options.mode);
|
var modeBox = modebox.create(this, this.options.modes, this.options.mode);
|
||||||
this.menu.appendChild(modeBox);
|
this.menu.appendChild(modeBox);
|
||||||
this.dom.modeBox = modeBox;
|
this.dom.modeBox = modeBox;
|
||||||
}
|
}
|
||||||
|
@ -577,13 +558,13 @@ TreeEditor.prototype._createFrame = function () {
|
||||||
if (this.options.search) {
|
if (this.options.search) {
|
||||||
this.searchBox = new SearchBox(this, this.menu);
|
this.searchBox = new SearchBox(this, this.menu);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform an undo action
|
* Perform an undo action
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype._onUndo = function () {
|
TreeEditor.prototype._onUndo = function () {
|
||||||
if (this.history) {
|
if (this.history) {
|
||||||
// undo last action
|
// undo last action
|
||||||
this.history.undo();
|
this.history.undo();
|
||||||
|
@ -593,13 +574,13 @@ TreeEditor.prototype._onUndo = function () {
|
||||||
this.options.change();
|
this.options.change();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a redo action
|
* Perform a redo action
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype._onRedo = function () {
|
TreeEditor.prototype._onRedo = function () {
|
||||||
if (this.history) {
|
if (this.history) {
|
||||||
// redo last action
|
// redo last action
|
||||||
this.history.redo();
|
this.history.redo();
|
||||||
|
@ -609,14 +590,14 @@ TreeEditor.prototype._onRedo = function () {
|
||||||
this.options.change();
|
this.options.change();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event handler
|
* Event handler
|
||||||
* @param event
|
* @param event
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype._onEvent = function (event) {
|
TreeEditor.prototype._onEvent = function (event) {
|
||||||
var target = event.target;
|
var target = event.target;
|
||||||
|
|
||||||
if (event.type == 'keydown') {
|
if (event.type == 'keydown') {
|
||||||
|
@ -631,14 +612,14 @@ TreeEditor.prototype._onEvent = function (event) {
|
||||||
if (node) {
|
if (node) {
|
||||||
node.onEvent(event);
|
node.onEvent(event);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event handler for keydown. Handles shortcut keys
|
* Event handler for keydown. Handles shortcut keys
|
||||||
* @param {Event} event
|
* @param {Event} event
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype._onKeyDown = function (event) {
|
TreeEditor.prototype._onKeyDown = function (event) {
|
||||||
var keynum = event.which || event.keyCode;
|
var keynum = event.which || event.keyCode;
|
||||||
var ctrlKey = event.ctrlKey;
|
var ctrlKey = event.ctrlKey;
|
||||||
var shiftKey = event.shiftKey;
|
var shiftKey = event.shiftKey;
|
||||||
|
@ -689,13 +670,13 @@ TreeEditor.prototype._onKeyDown = function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create main table
|
* Create main table
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
TreeEditor.prototype._createTable = function () {
|
TreeEditor.prototype._createTable = function () {
|
||||||
var contentOuter = document.createElement('div');
|
var contentOuter = document.createElement('div');
|
||||||
contentOuter.className = 'outer';
|
contentOuter.className = 'outer';
|
||||||
this.contentOuter = contentOuter;
|
this.contentOuter = contentOuter;
|
||||||
|
@ -728,27 +709,23 @@ TreeEditor.prototype._createTable = function () {
|
||||||
this.table.appendChild(this.tbody);
|
this.table.appendChild(this.tbody);
|
||||||
|
|
||||||
this.frame.appendChild(contentOuter);
|
this.frame.appendChild(contentOuter);
|
||||||
};
|
};
|
||||||
|
|
||||||
// register modes at the JSONEditor
|
// define modes
|
||||||
JSONEditor.modes.tree = {
|
TreeEditor.modes = {
|
||||||
|
tree: {
|
||||||
editor: TreeEditor,
|
editor: TreeEditor,
|
||||||
data: 'json'
|
data: 'json'
|
||||||
};
|
},
|
||||||
JSONEditor.modes.view = {
|
view: {
|
||||||
editor: TreeEditor,
|
editor: TreeEditor,
|
||||||
data: 'json'
|
data: 'json'
|
||||||
};
|
},
|
||||||
JSONEditor.modes.form = {
|
form: {
|
||||||
editor: TreeEditor,
|
editor: TreeEditor,
|
||||||
data: 'json'
|
data: 'json'
|
||||||
};
|
}
|
||||||
// Deprecated modes (deprecated since version 2.2.0)
|
};
|
||||||
JSONEditor.modes.editor = {
|
|
||||||
editor: TreeEditor,
|
return TreeEditor;
|
||||||
data: 'json'
|
});
|
||||||
};
|
|
||||||
JSONEditor.modes.viewer = {
|
|
||||||
editor: TreeEditor,
|
|
||||||
data: 'json'
|
|
||||||
};
|
|
||||||
|
|
|
@ -0,0 +1,225 @@
|
||||||
|
define(['./util'], function (util) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A factory function to create an AppendNode, which depends on a Node
|
||||||
|
* @param {Node} Node
|
||||||
|
*/
|
||||||
|
function appendNodeFactory(Node) {
|
||||||
|
/**
|
||||||
|
* @constructor AppendNode
|
||||||
|
* @extends Node
|
||||||
|
* @param {TreeEditor} editor
|
||||||
|
* Create a new AppendNode. This is a special node which is created at the
|
||||||
|
* end of the list with childs for an object or array
|
||||||
|
*/
|
||||||
|
function AppendNode (editor) {
|
||||||
|
/** @type {TreeEditor} */
|
||||||
|
this.editor = editor;
|
||||||
|
this.dom = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
AppendNode.prototype = new Node();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a table row with an append button.
|
||||||
|
* @return {Element} dom TR element
|
||||||
|
*/
|
||||||
|
AppendNode.prototype.getDom = function () {
|
||||||
|
// TODO: implement a new solution for the append node
|
||||||
|
var dom = this.dom;
|
||||||
|
|
||||||
|
if (dom.tr) {
|
||||||
|
return dom.tr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// a row for the append button
|
||||||
|
var trAppend = document.createElement('tr');
|
||||||
|
trAppend.node = this;
|
||||||
|
dom.tr = trAppend;
|
||||||
|
|
||||||
|
// TODO: consistent naming
|
||||||
|
|
||||||
|
if (this.editor.mode.edit) {
|
||||||
|
// a cell for the dragarea column
|
||||||
|
dom.tdDrag = document.createElement('td');
|
||||||
|
|
||||||
|
// create context menu
|
||||||
|
var tdMenu = document.createElement('td');
|
||||||
|
dom.tdMenu = tdMenu;
|
||||||
|
var menu = document.createElement('button');
|
||||||
|
menu.className = 'contextmenu';
|
||||||
|
menu.title = 'Click to open the actions menu (Ctrl+M)';
|
||||||
|
dom.menu = menu;
|
||||||
|
tdMenu.appendChild(dom.menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
// a cell for the contents (showing text 'empty')
|
||||||
|
var tdAppend = document.createElement('td');
|
||||||
|
var domText = document.createElement('div');
|
||||||
|
domText.innerHTML = '(empty)';
|
||||||
|
domText.className = 'readonly';
|
||||||
|
tdAppend.appendChild(domText);
|
||||||
|
dom.td = tdAppend;
|
||||||
|
dom.text = domText;
|
||||||
|
|
||||||
|
this.updateDom();
|
||||||
|
|
||||||
|
return trAppend;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the HTML dom of the Node
|
||||||
|
*/
|
||||||
|
AppendNode.prototype.updateDom = function () {
|
||||||
|
var dom = this.dom;
|
||||||
|
var tdAppend = dom.td;
|
||||||
|
if (tdAppend) {
|
||||||
|
tdAppend.style.paddingLeft = (this.getLevel() * 24 + 26) + 'px';
|
||||||
|
// TODO: not so nice hard coded offset
|
||||||
|
}
|
||||||
|
|
||||||
|
var domText = dom.text;
|
||||||
|
if (domText) {
|
||||||
|
domText.innerHTML = '(empty ' + this.parent.type + ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
// attach or detach the contents of the append node:
|
||||||
|
// hide when the parent has childs, show when the parent has no childs
|
||||||
|
var trAppend = dom.tr;
|
||||||
|
if (!this.isVisible()) {
|
||||||
|
if (dom.tr.firstChild) {
|
||||||
|
if (dom.tdDrag) {
|
||||||
|
trAppend.removeChild(dom.tdDrag);
|
||||||
|
}
|
||||||
|
if (dom.tdMenu) {
|
||||||
|
trAppend.removeChild(dom.tdMenu);
|
||||||
|
}
|
||||||
|
trAppend.removeChild(tdAppend);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!dom.tr.firstChild) {
|
||||||
|
if (dom.tdDrag) {
|
||||||
|
trAppend.appendChild(dom.tdDrag);
|
||||||
|
}
|
||||||
|
if (dom.tdMenu) {
|
||||||
|
trAppend.appendChild(dom.tdMenu);
|
||||||
|
}
|
||||||
|
trAppend.appendChild(tdAppend);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the AppendNode is currently visible.
|
||||||
|
* the AppendNode is visible when its parent has no childs (i.e. is empty).
|
||||||
|
* @return {boolean} isVisible
|
||||||
|
*/
|
||||||
|
AppendNode.prototype.isVisible = function () {
|
||||||
|
return (this.parent.childs.length == 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show a contextmenu for this node
|
||||||
|
* @param {HTMLElement} anchor The element to attach the menu to.
|
||||||
|
* @param {function} [onClose] Callback method called when the context menu
|
||||||
|
* is being closed.
|
||||||
|
*/
|
||||||
|
AppendNode.prototype.showContextMenu = function (anchor, onClose) {
|
||||||
|
var node = this;
|
||||||
|
var titles = Node.TYPE_TITLES;
|
||||||
|
var items = [
|
||||||
|
// create append button
|
||||||
|
{
|
||||||
|
'text': 'Append',
|
||||||
|
'title': 'Append a new field with type \'auto\' (Ctrl+Shift+Ins)',
|
||||||
|
'submenuTitle': 'Select the type of the field to be appended',
|
||||||
|
'className': 'insert',
|
||||||
|
'click': function () {
|
||||||
|
node._onAppend('', '', 'auto');
|
||||||
|
},
|
||||||
|
'submenu': [
|
||||||
|
{
|
||||||
|
'text': 'Auto',
|
||||||
|
'className': 'type-auto',
|
||||||
|
'title': titles.auto,
|
||||||
|
'click': function () {
|
||||||
|
node._onAppend('', '', 'auto');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'text': 'Array',
|
||||||
|
'className': 'type-array',
|
||||||
|
'title': titles.array,
|
||||||
|
'click': function () {
|
||||||
|
node._onAppend('', []);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'text': 'Object',
|
||||||
|
'className': 'type-object',
|
||||||
|
'title': titles.object,
|
||||||
|
'click': function () {
|
||||||
|
node._onAppend('', {});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'text': 'String',
|
||||||
|
'className': 'type-string',
|
||||||
|
'title': titles.string,
|
||||||
|
'click': function () {
|
||||||
|
node._onAppend('', '', 'string');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
var menu = new ContextMenu(items, {close: onClose});
|
||||||
|
menu.show(anchor);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an event. The event is catched centrally by the editor
|
||||||
|
* @param {Event} event
|
||||||
|
*/
|
||||||
|
AppendNode.prototype.onEvent = function (event) {
|
||||||
|
var type = event.type;
|
||||||
|
var target = event.target || event.srcElement;
|
||||||
|
var dom = this.dom;
|
||||||
|
|
||||||
|
// highlight the append nodes parent
|
||||||
|
var menu = dom.menu;
|
||||||
|
if (target == menu) {
|
||||||
|
if (type == 'mouseover') {
|
||||||
|
this.editor.highlighter.highlight(this.parent);
|
||||||
|
}
|
||||||
|
else if (type == 'mouseout') {
|
||||||
|
this.editor.highlighter.unhighlight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// context menu events
|
||||||
|
if (type == 'click' && target == dom.menu) {
|
||||||
|
var highlighter = this.editor.highlighter;
|
||||||
|
highlighter.highlight(this.parent);
|
||||||
|
highlighter.lock();
|
||||||
|
util.addClassName(dom.menu, 'selected');
|
||||||
|
this.showContextMenu(dom.menu, function () {
|
||||||
|
util.removeClassName(dom.menu, 'selected');
|
||||||
|
highlighter.unlock();
|
||||||
|
highlighter.unhighlight();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == 'keydown') {
|
||||||
|
this.onKeyDown(event);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return AppendNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the factory function
|
||||||
|
return appendNodeFactory;
|
||||||
|
});
|
|
@ -20,7 +20,7 @@
|
||||||
* License for the specific language governing permissions and limitations under
|
* License for the specific language governing permissions and limitations under
|
||||||
* the License.
|
* the License.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2011-2013 Jos de Jong, http://jsoneditoronline.org
|
* Copyright (c) 2011-2014 Jos de Jong, http://jsoneditoronline.org
|
||||||
*
|
*
|
||||||
* @author Jos de Jong, <wjosdejong@gmail.com>
|
* @author Jos de Jong, <wjosdejong@gmail.com>
|
||||||
* @version @@version
|
* @version @@version
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
/**
|
define(['./ContextMenu'], function (ContextMenu) {
|
||||||
* create a mode box to be used in the editor menu's
|
|
||||||
|
/**
|
||||||
|
* Create a mode box to be used in the editor menu's
|
||||||
* @param {JSONEditor} editor
|
* @param {JSONEditor} editor
|
||||||
* @param {String[]} modes Available modes: 'code', 'form', 'text', 'tree', 'view'
|
* @param {String[]} modes Available modes: 'code', 'form', 'text', 'tree', 'view'
|
||||||
* @param {String} current Available modes: 'code', 'form', 'text', 'tree', 'view'
|
* @param {String} current Available modes: 'code', 'form', 'text', 'tree', 'view'
|
||||||
* @returns {HTMLElement} box
|
* @returns {HTMLElement} box
|
||||||
*/
|
*/
|
||||||
function createModeBox(editor, modes, current) {
|
function createModeBox(editor, modes, current) {
|
||||||
/**
|
/**
|
||||||
* Switch the mode of the editor
|
* Switch the mode of the editor
|
||||||
* @param {String} mode
|
* @param {String} mode
|
||||||
|
@ -91,4 +93,9 @@ function createModeBox(editor, modes, current) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
create: createModeBox
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
@ -2,10 +2,6 @@
|
||||||
// module exports
|
// module exports
|
||||||
var jsoneditor = {
|
var jsoneditor = {
|
||||||
'JSONEditor': JSONEditor,
|
'JSONEditor': JSONEditor,
|
||||||
'JSONFormatter': function () {
|
|
||||||
throw new Error('JSONFormatter is deprecated. ' +
|
|
||||||
'Use JSONEditor with mode "text" or "code" instead');
|
|
||||||
},
|
|
||||||
'util': util
|
'util': util
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
153
src/js/util.js
153
src/js/util.js
|
@ -1,12 +1,14 @@
|
||||||
// create namespace
|
define(function () {
|
||||||
util = {};
|
|
||||||
|
|
||||||
/**
|
// create namespace
|
||||||
|
var util = {};
|
||||||
|
|
||||||
|
/**
|
||||||
* Parse JSON using the parser built-in in the browser.
|
* Parse JSON using the parser built-in in the browser.
|
||||||
* On exception, the jsonString is validated and a detailed error is thrown.
|
* On exception, the jsonString is validated and a detailed error is thrown.
|
||||||
* @param {String} jsonString
|
* @param {String} jsonString
|
||||||
*/
|
*/
|
||||||
util.parse = function parse(jsonString) {
|
util.parse = function parse(jsonString) {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(jsonString);
|
return JSON.parse(jsonString);
|
||||||
}
|
}
|
||||||
|
@ -15,69 +17,69 @@ util.parse = function parse(jsonString) {
|
||||||
util.validate(jsonString);
|
util.validate(jsonString);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate a string containing a JSON object
|
* Validate a string containing a JSON object
|
||||||
* This method uses JSONLint to validate the String. If JSONLint is not
|
* This method uses JSONLint to validate the String. If JSONLint is not
|
||||||
* available, the built-in JSON parser of the browser is used.
|
* available, the built-in JSON parser of the browser is used.
|
||||||
* @param {String} jsonString String with an (invalid) JSON object
|
* @param {String} jsonString String with an (invalid) JSON object
|
||||||
* @throws Error
|
* @throws Error
|
||||||
*/
|
*/
|
||||||
util.validate = function validate(jsonString) {
|
util.validate = function validate(jsonString) {
|
||||||
if (typeof(jsonlint) != 'undefined') {
|
if (typeof(jsonlint) != 'undefined') {
|
||||||
jsonlint.parse(jsonString);
|
jsonlint.parse(jsonString);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JSON.parse(jsonString);
|
JSON.parse(jsonString);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extend object a with the properties of object b
|
* Extend object a with the properties of object b
|
||||||
* @param {Object} a
|
* @param {Object} a
|
||||||
* @param {Object} b
|
* @param {Object} b
|
||||||
* @return {Object} a
|
* @return {Object} a
|
||||||
*/
|
*/
|
||||||
util.extend = function extend(a, b) {
|
util.extend = function extend(a, b) {
|
||||||
for (var prop in b) {
|
for (var prop in b) {
|
||||||
if (b.hasOwnProperty(prop)) {
|
if (b.hasOwnProperty(prop)) {
|
||||||
a[prop] = b[prop];
|
a[prop] = b[prop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all properties from object a
|
* Remove all properties from object a
|
||||||
* @param {Object} a
|
* @param {Object} a
|
||||||
* @return {Object} a
|
* @return {Object} a
|
||||||
*/
|
*/
|
||||||
util.clear = function clear (a) {
|
util.clear = function clear (a) {
|
||||||
for (var prop in a) {
|
for (var prop in a) {
|
||||||
if (a.hasOwnProperty(prop)) {
|
if (a.hasOwnProperty(prop)) {
|
||||||
delete a[prop];
|
delete a[prop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output text to the console, if console is available
|
* Output text to the console, if console is available
|
||||||
* @param {...*} args
|
* @param {...*} args
|
||||||
*/
|
*/
|
||||||
util.log = function log (args) {
|
util.log = function log (args) {
|
||||||
if (typeof console !== 'undefined' && typeof console.log === 'function') {
|
if (typeof console !== 'undefined' && typeof console.log === 'function') {
|
||||||
console.log.apply(console, arguments);
|
console.log.apply(console, arguments);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type of an object
|
* Get the type of an object
|
||||||
* @param {*} object
|
* @param {*} object
|
||||||
* @return {String} type
|
* @return {String} type
|
||||||
*/
|
*/
|
||||||
util.type = function type (object) {
|
util.type = function type (object) {
|
||||||
if (object === null) {
|
if (object === null) {
|
||||||
return 'null';
|
return 'null';
|
||||||
}
|
}
|
||||||
|
@ -101,74 +103,74 @@ util.type = function type (object) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'object';
|
return 'object';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether a text contains a url (matches when a string starts
|
* Test whether a text contains a url (matches when a string starts
|
||||||
* with 'http://*' or 'https://*' and has no whitespace characters)
|
* with 'http://*' or 'https://*' and has no whitespace characters)
|
||||||
* @param {String} text
|
* @param {String} text
|
||||||
*/
|
*/
|
||||||
var isUrlRegex = /^https?:\/\/\S+$/;
|
var isUrlRegex = /^https?:\/\/\S+$/;
|
||||||
util.isUrl = function isUrl (text) {
|
util.isUrl = function isUrl (text) {
|
||||||
return (typeof text == 'string' || text instanceof String) &&
|
return (typeof text == 'string' || text instanceof String) &&
|
||||||
isUrlRegex.test(text);
|
isUrlRegex.test(text);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the absolute left value of a DOM element
|
* Retrieve the absolute left value of a DOM element
|
||||||
* @param {Element} elem A dom element, for example a div
|
* @param {Element} elem A dom element, for example a div
|
||||||
* @return {Number} left The absolute left position of this element
|
* @return {Number} left The absolute left position of this element
|
||||||
* in the browser page.
|
* in the browser page.
|
||||||
*/
|
*/
|
||||||
util.getAbsoluteLeft = function getAbsoluteLeft(elem) {
|
util.getAbsoluteLeft = function getAbsoluteLeft(elem) {
|
||||||
var rect = elem.getBoundingClientRect();
|
var rect = elem.getBoundingClientRect();
|
||||||
return rect.left + window.pageXOffset || document.scrollLeft || 0;
|
return rect.left + window.pageXOffset || document.scrollLeft || 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the absolute top value of a DOM element
|
* Retrieve the absolute top value of a DOM element
|
||||||
* @param {Element} elem A dom element, for example a div
|
* @param {Element} elem A dom element, for example a div
|
||||||
* @return {Number} top The absolute top position of this element
|
* @return {Number} top The absolute top position of this element
|
||||||
* in the browser page.
|
* in the browser page.
|
||||||
*/
|
*/
|
||||||
util.getAbsoluteTop = function getAbsoluteTop(elem) {
|
util.getAbsoluteTop = function getAbsoluteTop(elem) {
|
||||||
var rect = elem.getBoundingClientRect();
|
var rect = elem.getBoundingClientRect();
|
||||||
return rect.top + window.pageYOffset || document.scrollTop || 0;
|
return rect.top + window.pageYOffset || document.scrollTop || 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add a className to the given elements style
|
* add a className to the given elements style
|
||||||
* @param {Element} elem
|
* @param {Element} elem
|
||||||
* @param {String} className
|
* @param {String} className
|
||||||
*/
|
*/
|
||||||
util.addClassName = function addClassName(elem, className) {
|
util.addClassName = function addClassName(elem, className) {
|
||||||
var classes = elem.className.split(' ');
|
var classes = elem.className.split(' ');
|
||||||
if (classes.indexOf(className) == -1) {
|
if (classes.indexOf(className) == -1) {
|
||||||
classes.push(className); // add the class to the array
|
classes.push(className); // add the class to the array
|
||||||
elem.className = classes.join(' ');
|
elem.className = classes.join(' ');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add a className to the given elements style
|
* add a className to the given elements style
|
||||||
* @param {Element} elem
|
* @param {Element} elem
|
||||||
* @param {String} className
|
* @param {String} className
|
||||||
*/
|
*/
|
||||||
util.removeClassName = function removeClassName(elem, className) {
|
util.removeClassName = function removeClassName(elem, className) {
|
||||||
var classes = elem.className.split(' ');
|
var classes = elem.className.split(' ');
|
||||||
var index = classes.indexOf(className);
|
var index = classes.indexOf(className);
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
classes.splice(index, 1); // remove the class from the array
|
classes.splice(index, 1); // remove the class from the array
|
||||||
elem.className = classes.join(' ');
|
elem.className = classes.join(' ');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strip the formatting from the contents of a div
|
* Strip the formatting from the contents of a div
|
||||||
* the formatting from the div itself is not stripped, only from its childs.
|
* the formatting from the div itself is not stripped, only from its childs.
|
||||||
* @param {Element} divElement
|
* @param {Element} divElement
|
||||||
*/
|
*/
|
||||||
util.stripFormatting = function stripFormatting(divElement) {
|
util.stripFormatting = function stripFormatting(divElement) {
|
||||||
var childs = divElement.childNodes;
|
var childs = divElement.childNodes;
|
||||||
for (var i = 0, iMax = childs.length; i < iMax; i++) {
|
for (var i = 0, iMax = childs.length; i < iMax; i++) {
|
||||||
var child = childs[i];
|
var child = childs[i];
|
||||||
|
@ -193,16 +195,16 @@ util.stripFormatting = function stripFormatting(divElement) {
|
||||||
// recursively strip childs
|
// recursively strip childs
|
||||||
util.stripFormatting(child);
|
util.stripFormatting(child);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set focus to the end of an editable div
|
* Set focus to the end of an editable div
|
||||||
* code from Nico Burns
|
* code from Nico Burns
|
||||||
* http://stackoverflow.com/users/140293/nico-burns
|
* http://stackoverflow.com/users/140293/nico-burns
|
||||||
* http://stackoverflow.com/questions/1125292/how-to-move-cursor-to-end-of-contenteditable-entity
|
* http://stackoverflow.com/questions/1125292/how-to-move-cursor-to-end-of-contenteditable-entity
|
||||||
* @param {Element} contentEditableElement A content editable div
|
* @param {Element} contentEditableElement A content editable div
|
||||||
*/
|
*/
|
||||||
util.setEndOfContentEditable = function setEndOfContentEditable(contentEditableElement) {
|
util.setEndOfContentEditable = function setEndOfContentEditable(contentEditableElement) {
|
||||||
var range, selection;
|
var range, selection;
|
||||||
if(document.createRange) {
|
if(document.createRange) {
|
||||||
range = document.createRange();//Create a range (a range is a like the selection but invisible)
|
range = document.createRange();//Create a range (a range is a like the selection but invisible)
|
||||||
|
@ -212,14 +214,14 @@ util.setEndOfContentEditable = function setEndOfContentEditable(contentEditableE
|
||||||
selection.removeAllRanges();//remove any selections already made
|
selection.removeAllRanges();//remove any selections already made
|
||||||
selection.addRange(range);//make the range you have just created the visible selection
|
selection.addRange(range);//make the range you have just created the visible selection
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select all text of a content editable div.
|
* Select all text of a content editable div.
|
||||||
* http://stackoverflow.com/a/3806004/1262753
|
* http://stackoverflow.com/a/3806004/1262753
|
||||||
* @param {Element} contentEditableElement A content editable div
|
* @param {Element} contentEditableElement A content editable div
|
||||||
*/
|
*/
|
||||||
util.selectContentEditable = function selectContentEditable(contentEditableElement) {
|
util.selectContentEditable = function selectContentEditable(contentEditableElement) {
|
||||||
if (!contentEditableElement || contentEditableElement.nodeName != 'DIV') {
|
if (!contentEditableElement || contentEditableElement.nodeName != 'DIV') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -232,14 +234,14 @@ util.selectContentEditable = function selectContentEditable(contentEditableEleme
|
||||||
sel.removeAllRanges();
|
sel.removeAllRanges();
|
||||||
sel.addRange(range);
|
sel.addRange(range);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get text selection
|
* Get text selection
|
||||||
* http://stackoverflow.com/questions/4687808/contenteditable-selected-text-save-and-restore
|
* http://stackoverflow.com/questions/4687808/contenteditable-selected-text-save-and-restore
|
||||||
* @return {Range | TextRange | null} range
|
* @return {Range | TextRange | null} range
|
||||||
*/
|
*/
|
||||||
util.getSelection = function getSelection() {
|
util.getSelection = function getSelection() {
|
||||||
if (window.getSelection) {
|
if (window.getSelection) {
|
||||||
var sel = window.getSelection();
|
var sel = window.getSelection();
|
||||||
if (sel.getRangeAt && sel.rangeCount) {
|
if (sel.getRangeAt && sel.rangeCount) {
|
||||||
|
@ -247,14 +249,14 @@ util.getSelection = function getSelection() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set text selection
|
* Set text selection
|
||||||
* http://stackoverflow.com/questions/4687808/contenteditable-selected-text-save-and-restore
|
* http://stackoverflow.com/questions/4687808/contenteditable-selected-text-save-and-restore
|
||||||
* @param {Range | TextRange | null} range
|
* @param {Range | TextRange | null} range
|
||||||
*/
|
*/
|
||||||
util.setSelection = function setSelection(range) {
|
util.setSelection = function setSelection(range) {
|
||||||
if (range) {
|
if (range) {
|
||||||
if (window.getSelection) {
|
if (window.getSelection) {
|
||||||
var sel = window.getSelection();
|
var sel = window.getSelection();
|
||||||
|
@ -262,9 +264,9 @@ util.setSelection = function setSelection(range) {
|
||||||
sel.addRange(range);
|
sel.addRange(range);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get selected text range
|
* Get selected text range
|
||||||
* @return {Object} params object containing parameters:
|
* @return {Object} params object containing parameters:
|
||||||
* {Number} startOffset
|
* {Number} startOffset
|
||||||
|
@ -273,7 +275,7 @@ util.setSelection = function setSelection(range) {
|
||||||
* selected text element
|
* selected text element
|
||||||
* Returns null if no text selection is found
|
* Returns null if no text selection is found
|
||||||
*/
|
*/
|
||||||
util.getSelectionOffset = function getSelectionOffset() {
|
util.getSelectionOffset = function getSelectionOffset() {
|
||||||
var range = util.getSelection();
|
var range = util.getSelection();
|
||||||
|
|
||||||
if (range && 'startOffset' in range && 'endOffset' in range &&
|
if (range && 'startOffset' in range && 'endOffset' in range &&
|
||||||
|
@ -286,16 +288,16 @@ util.getSelectionOffset = function getSelectionOffset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set selected text range in given element
|
* Set selected text range in given element
|
||||||
* @param {Object} params An object containing:
|
* @param {Object} params An object containing:
|
||||||
* {Element} container
|
* {Element} container
|
||||||
* {Number} startOffset
|
* {Number} startOffset
|
||||||
* {Number} endOffset
|
* {Number} endOffset
|
||||||
*/
|
*/
|
||||||
util.setSelectionOffset = function setSelectionOffset(params) {
|
util.setSelectionOffset = function setSelectionOffset(params) {
|
||||||
if (document.createRange && window.getSelection) {
|
if (document.createRange && window.getSelection) {
|
||||||
var selection = window.getSelection();
|
var selection = window.getSelection();
|
||||||
if(selection) {
|
if(selection) {
|
||||||
|
@ -308,15 +310,15 @@ util.setSelectionOffset = function setSelectionOffset(params) {
|
||||||
util.setSelection(range);
|
util.setSelection(range);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the inner text of an HTML element (for example a div element)
|
* Get the inner text of an HTML element (for example a div element)
|
||||||
* @param {Element} element
|
* @param {Element} element
|
||||||
* @param {Object} [buffer]
|
* @param {Object} [buffer]
|
||||||
* @return {String} innerText
|
* @return {String} innerText
|
||||||
*/
|
*/
|
||||||
util.getInnerText = function getInnerText(element, buffer) {
|
util.getInnerText = function getInnerText(element, buffer) {
|
||||||
var first = (buffer == undefined);
|
var first = (buffer == undefined);
|
||||||
if (first) {
|
if (first) {
|
||||||
buffer = {
|
buffer = {
|
||||||
|
@ -379,15 +381,15 @@ util.getInnerText = function getInnerText(element, buffer) {
|
||||||
|
|
||||||
// br or unknown
|
// br or unknown
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the version of Internet Explorer or a -1
|
* Returns the version of Internet Explorer or a -1
|
||||||
* (indicating the use of another browser).
|
* (indicating the use of another browser).
|
||||||
* Source: http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx
|
* Source: http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx
|
||||||
* @return {Number} Internet Explorer version, or -1 in case of an other browser
|
* @return {Number} Internet Explorer version, or -1 in case of an other browser
|
||||||
*/
|
*/
|
||||||
util.getInternetExplorerVersion = function getInternetExplorerVersion() {
|
util.getInternetExplorerVersion = function getInternetExplorerVersion() {
|
||||||
if (_ieVersion == -1) {
|
if (_ieVersion == -1) {
|
||||||
var rv = -1; // Return value assumes failure.
|
var rv = -1; // Return value assumes failure.
|
||||||
if (navigator.appName == 'Microsoft Internet Explorer')
|
if (navigator.appName == 'Microsoft Internet Explorer')
|
||||||
|
@ -403,24 +405,24 @@ util.getInternetExplorerVersion = function getInternetExplorerVersion() {
|
||||||
}
|
}
|
||||||
|
|
||||||
return _ieVersion;
|
return _ieVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether the current browser is Firefox
|
* Test whether the current browser is Firefox
|
||||||
* @returns {boolean} isFirefox
|
* @returns {boolean} isFirefox
|
||||||
*/
|
*/
|
||||||
util.isFirefox = function isFirefox () {
|
util.isFirefox = function isFirefox () {
|
||||||
return (navigator.userAgent.indexOf("Firefox") != -1);
|
return (navigator.userAgent.indexOf("Firefox") != -1);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cached internet explorer version
|
* cached internet explorer version
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
var _ieVersion = -1;
|
var _ieVersion = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add and event listener. Works for all browsers
|
* Add and event listener. Works for all browsers
|
||||||
* @param {Element} element An html element
|
* @param {Element} element An html element
|
||||||
* @param {string} action The action, for example "click",
|
* @param {string} action The action, for example "click",
|
||||||
|
@ -429,7 +431,7 @@ var _ieVersion = -1;
|
||||||
* @param {boolean} [useCapture] false by default
|
* @param {boolean} [useCapture] false by default
|
||||||
* @return {function} the created event listener
|
* @return {function} the created event listener
|
||||||
*/
|
*/
|
||||||
util.addEventListener = function addEventListener(element, action, listener, useCapture) {
|
util.addEventListener = function addEventListener(element, action, listener, useCapture) {
|
||||||
if (element.addEventListener) {
|
if (element.addEventListener) {
|
||||||
if (useCapture === undefined)
|
if (useCapture === undefined)
|
||||||
useCapture = false;
|
useCapture = false;
|
||||||
|
@ -448,16 +450,16 @@ util.addEventListener = function addEventListener(element, action, listener, use
|
||||||
element.attachEvent("on" + action, f);
|
element.attachEvent("on" + action, f);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an event listener from an element
|
* Remove an event listener from an element
|
||||||
* @param {Element} element An html dom element
|
* @param {Element} element An html dom element
|
||||||
* @param {string} action The name of the event, for example "mousedown"
|
* @param {string} action The name of the event, for example "mousedown"
|
||||||
* @param {function} listener The listener function
|
* @param {function} listener The listener function
|
||||||
* @param {boolean} [useCapture] false by default
|
* @param {boolean} [useCapture] false by default
|
||||||
*/
|
*/
|
||||||
util.removeEventListener = function removeEventListener(element, action, listener, useCapture) {
|
util.removeEventListener = function removeEventListener(element, action, listener, useCapture) {
|
||||||
if (element.removeEventListener) {
|
if (element.removeEventListener) {
|
||||||
if (useCapture === undefined)
|
if (useCapture === undefined)
|
||||||
useCapture = false;
|
useCapture = false;
|
||||||
|
@ -471,4 +473,7 @@ util.removeEventListener = function removeEventListener(element, action, listene
|
||||||
// Old IE browsers
|
// Old IE browsers
|
||||||
element.detachEvent("on" + action, listener);
|
element.detachEvent("on" + action, listener);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return util;
|
||||||
|
});
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
var container = document.getElementById('jsoneditor');
|
var container = document.getElementById('jsoneditor');
|
||||||
editor = (container);
|
editor = new JSONEditor(container);
|
||||||
|
|
||||||
document.getElementById('url').focus();
|
document.getElementById('url').focus();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
RequireJS 2.1.13 Copyright (c) 2010-2014, The Dojo Foundation All Rights Reserved.
|
||||||
|
Available via the MIT or new BSD license.
|
||||||
|
see: http://github.com/jrburke/requirejs for details
|
||||||
|
*/
|
||||||
|
var requirejs,require,define;
|
||||||
|
(function(ba){function G(b){return"[object Function]"===K.call(b)}function H(b){return"[object Array]"===K.call(b)}function v(b,c){if(b){var d;for(d=0;d<b.length&&(!b[d]||!c(b[d],d,b));d+=1);}}function T(b,c){if(b){var d;for(d=b.length-1;-1<d&&(!b[d]||!c(b[d],d,b));d-=1);}}function t(b,c){return fa.call(b,c)}function m(b,c){return t(b,c)&&b[c]}function B(b,c){for(var d in b)if(t(b,d)&&c(b[d],d))break}function U(b,c,d,e){c&&B(c,function(c,g){if(d||!t(b,g))e&&"object"===typeof c&&c&&!H(c)&&!G(c)&&!(c instanceof
|
||||||
|
RegExp)?(b[g]||(b[g]={}),U(b[g],c,d,e)):b[g]=c});return b}function u(b,c){return function(){return c.apply(b,arguments)}}function ca(b){throw b;}function da(b){if(!b)return b;var c=ba;v(b.split("."),function(b){c=c[b]});return c}function C(b,c,d,e){c=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);c.requireType=b;c.requireModules=e;d&&(c.originalError=d);return c}function ga(b){function c(a,k,b){var f,l,c,d,e,g,i,p,k=k&&k.split("/"),h=j.map,n=h&&h["*"];if(a){a=a.split("/");l=a.length-1;j.nodeIdCompat&&
|
||||||
|
Q.test(a[l])&&(a[l]=a[l].replace(Q,""));"."===a[0].charAt(0)&&k&&(l=k.slice(0,k.length-1),a=l.concat(a));l=a;for(c=0;c<l.length;c++)if(d=l[c],"."===d)l.splice(c,1),c-=1;else if(".."===d&&!(0===c||1==c&&".."===l[2]||".."===l[c-1])&&0<c)l.splice(c-1,2),c-=2;a=a.join("/")}if(b&&h&&(k||n)){l=a.split("/");c=l.length;a:for(;0<c;c-=1){e=l.slice(0,c).join("/");if(k)for(d=k.length;0<d;d-=1)if(b=m(h,k.slice(0,d).join("/")))if(b=m(b,e)){f=b;g=c;break a}!i&&(n&&m(n,e))&&(i=m(n,e),p=c)}!f&&i&&(f=i,g=p);f&&(l.splice(0,
|
||||||
|
g,f),a=l.join("/"))}return(f=m(j.pkgs,a))?f:a}function d(a){z&&v(document.getElementsByTagName("script"),function(k){if(k.getAttribute("data-requiremodule")===a&&k.getAttribute("data-requirecontext")===i.contextName)return k.parentNode.removeChild(k),!0})}function e(a){var k=m(j.paths,a);if(k&&H(k)&&1<k.length)return k.shift(),i.require.undef(a),i.makeRequire(null,{skipMap:!0})([a]),!0}function n(a){var k,c=a?a.indexOf("!"):-1;-1<c&&(k=a.substring(0,c),a=a.substring(c+1,a.length));return[k,a]}function p(a,
|
||||||
|
k,b,f){var l,d,e=null,g=k?k.name:null,j=a,p=!0,h="";a||(p=!1,a="_@r"+(K+=1));a=n(a);e=a[0];a=a[1];e&&(e=c(e,g,f),d=m(r,e));a&&(e?h=d&&d.normalize?d.normalize(a,function(a){return c(a,g,f)}):c(a,g,f):(h=c(a,g,f),a=n(h),e=a[0],h=a[1],b=!0,l=i.nameToUrl(h)));b=e&&!d&&!b?"_unnormalized"+(O+=1):"";return{prefix:e,name:h,parentMap:k,unnormalized:!!b,url:l,originalName:j,isDefine:p,id:(e?e+"!"+h:h)+b}}function s(a){var k=a.id,b=m(h,k);b||(b=h[k]=new i.Module(a));return b}function q(a,k,b){var f=a.id,c=m(h,
|
||||||
|
f);if(t(r,f)&&(!c||c.defineEmitComplete))"defined"===k&&b(r[f]);else if(c=s(a),c.error&&"error"===k)b(c.error);else c.on(k,b)}function w(a,b){var c=a.requireModules,f=!1;if(b)b(a);else if(v(c,function(b){if(b=m(h,b))b.error=a,b.events.error&&(f=!0,b.emit("error",a))}),!f)g.onError(a)}function x(){R.length&&(ha.apply(A,[A.length,0].concat(R)),R=[])}function y(a){delete h[a];delete V[a]}function F(a,b,c){var f=a.map.id;a.error?a.emit("error",a.error):(b[f]=!0,v(a.depMaps,function(f,d){var e=f.id,g=
|
||||||
|
m(h,e);g&&(!a.depMatched[d]&&!c[e])&&(m(b,e)?(a.defineDep(d,r[e]),a.check()):F(g,b,c))}),c[f]=!0)}function D(){var a,b,c=(a=1E3*j.waitSeconds)&&i.startTime+a<(new Date).getTime(),f=[],l=[],g=!1,h=!0;if(!W){W=!0;B(V,function(a){var i=a.map,j=i.id;if(a.enabled&&(i.isDefine||l.push(a),!a.error))if(!a.inited&&c)e(j)?g=b=!0:(f.push(j),d(j));else if(!a.inited&&(a.fetched&&i.isDefine)&&(g=!0,!i.prefix))return h=!1});if(c&&f.length)return a=C("timeout","Load timeout for modules: "+f,null,f),a.contextName=
|
||||||
|
i.contextName,w(a);h&&v(l,function(a){F(a,{},{})});if((!c||b)&&g)if((z||ea)&&!X)X=setTimeout(function(){X=0;D()},50);W=!1}}function E(a){t(r,a[0])||s(p(a[0],null,!0)).init(a[1],a[2])}function I(a){var a=a.currentTarget||a.srcElement,b=i.onScriptLoad;a.detachEvent&&!Y?a.detachEvent("onreadystatechange",b):a.removeEventListener("load",b,!1);b=i.onScriptError;(!a.detachEvent||Y)&&a.removeEventListener("error",b,!1);return{node:a,id:a&&a.getAttribute("data-requiremodule")}}function J(){var a;for(x();A.length;){a=
|
||||||
|
A.shift();if(null===a[0])return w(C("mismatch","Mismatched anonymous define() module: "+a[a.length-1]));E(a)}}var W,Z,i,L,X,j={waitSeconds:7,baseUrl:"./",paths:{},bundles:{},pkgs:{},shim:{},config:{}},h={},V={},$={},A=[],r={},S={},aa={},K=1,O=1;L={require:function(a){return a.require?a.require:a.require=i.makeRequire(a.map)},exports:function(a){a.usingExports=!0;if(a.map.isDefine)return a.exports?r[a.map.id]=a.exports:a.exports=r[a.map.id]={}},module:function(a){return a.module?a.module:a.module=
|
||||||
|
{id:a.map.id,uri:a.map.url,config:function(){return m(j.config,a.map.id)||{}},exports:a.exports||(a.exports={})}}};Z=function(a){this.events=m($,a.id)||{};this.map=a;this.shim=m(j.shim,a.id);this.depExports=[];this.depMaps=[];this.depMatched=[];this.pluginMaps={};this.depCount=0};Z.prototype={init:function(a,b,c,f){f=f||{};if(!this.inited){this.factory=b;if(c)this.on("error",c);else this.events.error&&(c=u(this,function(a){this.emit("error",a)}));this.depMaps=a&&a.slice(0);this.errback=c;this.inited=
|
||||||
|
!0;this.ignore=f.ignore;f.enabled||this.enabled?this.enable():this.check()}},defineDep:function(a,b){this.depMatched[a]||(this.depMatched[a]=!0,this.depCount-=1,this.depExports[a]=b)},fetch:function(){if(!this.fetched){this.fetched=!0;i.startTime=(new Date).getTime();var a=this.map;if(this.shim)i.makeRequire(this.map,{enableBuildCallback:!0})(this.shim.deps||[],u(this,function(){return a.prefix?this.callPlugin():this.load()}));else return a.prefix?this.callPlugin():this.load()}},load:function(){var a=
|
||||||
|
this.map.url;S[a]||(S[a]=!0,i.load(this.map.id,a))},check:function(){if(this.enabled&&!this.enabling){var a,b,c=this.map.id;b=this.depExports;var f=this.exports,l=this.factory;if(this.inited)if(this.error)this.emit("error",this.error);else{if(!this.defining){this.defining=!0;if(1>this.depCount&&!this.defined){if(G(l)){if(this.events.error&&this.map.isDefine||g.onError!==ca)try{f=i.execCb(c,l,b,f)}catch(d){a=d}else f=i.execCb(c,l,b,f);this.map.isDefine&&void 0===f&&((b=this.module)?f=b.exports:this.usingExports&&
|
||||||
|
(f=this.exports));if(a)return a.requireMap=this.map,a.requireModules=this.map.isDefine?[this.map.id]:null,a.requireType=this.map.isDefine?"define":"require",w(this.error=a)}else f=l;this.exports=f;if(this.map.isDefine&&!this.ignore&&(r[c]=f,g.onResourceLoad))g.onResourceLoad(i,this.map,this.depMaps);y(c);this.defined=!0}this.defining=!1;this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=!0)}}else this.fetch()}},callPlugin:function(){var a=
|
||||||
|
this.map,b=a.id,d=p(a.prefix);this.depMaps.push(d);q(d,"defined",u(this,function(f){var l,d;d=m(aa,this.map.id);var e=this.map.name,P=this.map.parentMap?this.map.parentMap.name:null,n=i.makeRequire(a.parentMap,{enableBuildCallback:!0});if(this.map.unnormalized){if(f.normalize&&(e=f.normalize(e,function(a){return c(a,P,!0)})||""),f=p(a.prefix+"!"+e,this.map.parentMap),q(f,"defined",u(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),d=m(h,f.id)){this.depMaps.push(f);
|
||||||
|
if(this.events.error)d.on("error",u(this,function(a){this.emit("error",a)}));d.enable()}}else d?(this.map.url=i.nameToUrl(d),this.load()):(l=u(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),l.error=u(this,function(a){this.inited=!0;this.error=a;a.requireModules=[b];B(h,function(a){0===a.map.id.indexOf(b+"_unnormalized")&&y(a.map.id)});w(a)}),l.fromText=u(this,function(f,c){var d=a.name,e=p(d),P=M;c&&(f=c);P&&(M=!1);s(e);t(j.config,b)&&(j.config[d]=j.config[b]);try{g.exec(f)}catch(h){return w(C("fromtexteval",
|
||||||
|
"fromText eval for "+b+" failed: "+h,h,[b]))}P&&(M=!0);this.depMaps.push(e);i.completeLoad(d);n([d],l)}),f.load(a.name,n,l,j))}));i.enable(d,this);this.pluginMaps[d.id]=d},enable:function(){V[this.map.id]=this;this.enabling=this.enabled=!0;v(this.depMaps,u(this,function(a,b){var c,f;if("string"===typeof a){a=p(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap);this.depMaps[b]=a;if(c=m(L,a.id)){this.depExports[b]=c(this);return}this.depCount+=1;q(a,"defined",u(this,function(a){this.defineDep(b,
|
||||||
|
a);this.check()}));this.errback&&q(a,"error",u(this,this.errback))}c=a.id;f=h[c];!t(L,c)&&(f&&!f.enabled)&&i.enable(a,this)}));B(this.pluginMaps,u(this,function(a){var b=m(h,a.id);b&&!b.enabled&&i.enable(a,this)}));this.enabling=!1;this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]);c.push(b)},emit:function(a,b){v(this.events[a],function(a){a(b)});"error"===a&&delete this.events[a]}};i={config:j,contextName:b,registry:h,defined:r,urlFetched:S,defQueue:A,Module:Z,makeModuleMap:p,
|
||||||
|
nextTick:g.nextTick,onError:w,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=j.shim,c={paths:!0,bundles:!0,config:!0,map:!0};B(a,function(a,b){c[b]?(j[b]||(j[b]={}),U(j[b],a,!0,!0)):j[b]=a});a.bundles&&B(a.bundles,function(a,b){v(a,function(a){a!==b&&(aa[a]=b)})});a.shim&&(B(a.shim,function(a,c){H(a)&&(a={deps:a});if((a.exports||a.init)&&!a.exportsFn)a.exportsFn=i.makeShimExports(a);b[c]=a}),j.shim=b);a.packages&&v(a.packages,function(a){var b,
|
||||||
|
a="string"===typeof a?{name:a}:a;b=a.name;a.location&&(j.paths[b]=a.location);j.pkgs[b]=a.name+"/"+(a.main||"main").replace(ia,"").replace(Q,"")});B(h,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=p(b))});if(a.deps||a.callback)i.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;a.init&&(b=a.init.apply(ba,arguments));return b||a.exports&&da(a.exports)}},makeRequire:function(a,e){function j(c,d,m){var n,q;e.enableBuildCallback&&(d&&G(d))&&(d.__requireJsBuild=
|
||||||
|
!0);if("string"===typeof c){if(G(d))return w(C("requireargs","Invalid require call"),m);if(a&&t(L,c))return L[c](h[a.id]);if(g.get)return g.get(i,c,a,j);n=p(c,a,!1,!0);n=n.id;return!t(r,n)?w(C("notloaded",'Module name "'+n+'" has not been loaded yet for context: '+b+(a?"":". Use require([])"))):r[n]}J();i.nextTick(function(){J();q=s(p(null,a));q.skipMap=e.skipMap;q.init(c,d,m,{enabled:!0});D()});return j}e=e||{};U(j,{isBrowser:z,toUrl:function(b){var d,e=b.lastIndexOf("."),k=b.split("/")[0];if(-1!==
|
||||||
|
e&&(!("."===k||".."===k)||1<e))d=b.substring(e,b.length),b=b.substring(0,e);return i.nameToUrl(c(b,a&&a.id,!0),d,!0)},defined:function(b){return t(r,p(b,a,!1,!0).id)},specified:function(b){b=p(b,a,!1,!0).id;return t(r,b)||t(h,b)}});a||(j.undef=function(b){x();var c=p(b,a,!0),e=m(h,b);d(b);delete r[b];delete S[c.url];delete $[b];T(A,function(a,c){a[0]===b&&A.splice(c,1)});e&&(e.events.defined&&($[b]=e.events),y(b))});return j},enable:function(a){m(h,a.id)&&s(a).enable()},completeLoad:function(a){var b,
|
||||||
|
c,d=m(j.shim,a)||{},g=d.exports;for(x();A.length;){c=A.shift();if(null===c[0]){c[0]=a;if(b)break;b=!0}else c[0]===a&&(b=!0);E(c)}c=m(h,a);if(!b&&!t(r,a)&&c&&!c.inited){if(j.enforceDefine&&(!g||!da(g)))return e(a)?void 0:w(C("nodefine","No define call for "+a,null,[a]));E([a,d.deps||[],d.exportsFn])}D()},nameToUrl:function(a,b,c){var d,e,h;(d=m(j.pkgs,a))&&(a=d);if(d=m(aa,a))return i.nameToUrl(d,b,c);if(g.jsExtRegExp.test(a))d=a+(b||"");else{d=j.paths;a=a.split("/");for(e=a.length;0<e;e-=1)if(h=a.slice(0,
|
||||||
|
e).join("/"),h=m(d,h)){H(h)&&(h=h[0]);a.splice(0,e,h);break}d=a.join("/");d+=b||(/^data\:|\?/.test(d)||c?"":".js");d=("/"===d.charAt(0)||d.match(/^[\w\+\.\-]+:/)?"":j.baseUrl)+d}return j.urlArgs?d+((-1===d.indexOf("?")?"?":"&")+j.urlArgs):d},load:function(a,b){g.load(i,a,b)},execCb:function(a,b,c,d){return b.apply(d,c)},onScriptLoad:function(a){if("load"===a.type||ja.test((a.currentTarget||a.srcElement).readyState))N=null,a=I(a),i.completeLoad(a.id)},onScriptError:function(a){var b=I(a);if(!e(b.id))return w(C("scripterror",
|
||||||
|
"Script error for: "+b.id,a,[b.id]))}};i.require=i.makeRequire();return i}var g,x,y,D,I,E,N,J,s,O,ka=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,la=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,Q=/\.js$/,ia=/^\.\//;x=Object.prototype;var K=x.toString,fa=x.hasOwnProperty,ha=Array.prototype.splice,z=!!("undefined"!==typeof window&&"undefined"!==typeof navigator&&window.document),ea=!z&&"undefined"!==typeof importScripts,ja=z&&"PLAYSTATION 3"===navigator.platform?/^complete$/:/^(complete|loaded)$/,
|
||||||
|
Y="undefined"!==typeof opera&&"[object Opera]"===opera.toString(),F={},q={},R=[],M=!1;if("undefined"===typeof define){if("undefined"!==typeof requirejs){if(G(requirejs))return;q=requirejs;requirejs=void 0}"undefined"!==typeof require&&!G(require)&&(q=require,require=void 0);g=requirejs=function(b,c,d,e){var n,p="_";!H(b)&&"string"!==typeof b&&(n=b,H(c)?(b=c,c=d,d=e):b=[]);n&&n.context&&(p=n.context);(e=m(F,p))||(e=F[p]=g.s.newContext(p));n&&e.configure(n);return e.require(b,c,d)};g.config=function(b){return g(b)};
|
||||||
|
g.nextTick="undefined"!==typeof setTimeout?function(b){setTimeout(b,4)}:function(b){b()};require||(require=g);g.version="2.1.13";g.jsExtRegExp=/^\/|:|\?|\.js$/;g.isBrowser=z;x=g.s={contexts:F,newContext:ga};g({});v(["toUrl","undef","defined","specified"],function(b){g[b]=function(){var c=F._;return c.require[b].apply(c,arguments)}});if(z&&(y=x.head=document.getElementsByTagName("head")[0],D=document.getElementsByTagName("base")[0]))y=x.head=D.parentNode;g.onError=ca;g.createNode=function(b){var c=
|
||||||
|
b.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script");c.type=b.scriptType||"text/javascript";c.charset="utf-8";c.async=!0;return c};g.load=function(b,c,d){var e=b&&b.config||{};if(z)return e=g.createNode(e,c,d),e.setAttribute("data-requirecontext",b.contextName),e.setAttribute("data-requiremodule",c),e.attachEvent&&!(e.attachEvent.toString&&0>e.attachEvent.toString().indexOf("[native code"))&&!Y?(M=!0,e.attachEvent("onreadystatechange",b.onScriptLoad)):
|
||||||
|
(e.addEventListener("load",b.onScriptLoad,!1),e.addEventListener("error",b.onScriptError,!1)),e.src=d,J=e,D?y.insertBefore(e,D):y.appendChild(e),J=null,e;if(ea)try{importScripts(d),b.completeLoad(c)}catch(m){b.onError(C("importscripts","importScripts failed for "+c+" at "+d,m,[c]))}};z&&!q.skipDataMain&&T(document.getElementsByTagName("script"),function(b){y||(y=b.parentNode);if(I=b.getAttribute("data-main"))return s=I,q.baseUrl||(E=s.split("/"),s=E.pop(),O=E.length?E.join("/")+"/":"./",q.baseUrl=
|
||||||
|
O),s=s.replace(Q,""),g.jsExtRegExp.test(s)&&(s=I),q.deps=q.deps?q.deps.concat(s):[s],!0});define=function(b,c,d){var e,g;"string"!==typeof b&&(d=c,c=b,b=null);H(c)||(d=c,c=null);!c&&G(d)&&(c=[],d.length&&(d.toString().replace(ka,"").replace(la,function(b,d){c.push(d)}),c=(1===d.length?["require"]:["require","exports","module"]).concat(c)));if(M){if(!(e=J))N&&"interactive"===N.readyState||T(document.getElementsByTagName("script"),function(b){if("interactive"===b.readyState)return N=b}),e=N;e&&(b||
|
||||||
|
(b=e.getAttribute("data-requiremodule")),g=F[e.getAttribute("data-requirecontext")])}(g?g.defQueue:R).push([b,c,d])};define.amd={jQuery:!0};g.exec=function(b){return eval(b)};g(q)}})(this);
|
|
@ -3,9 +3,22 @@
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||||
|
|
||||||
|
<!-- require.js -->
|
||||||
|
<script src="require.js"></script>
|
||||||
|
<script>
|
||||||
|
require.config({
|
||||||
|
packages: [
|
||||||
|
{
|
||||||
|
name: 'JSONEditor',
|
||||||
|
location: '../src/js/',
|
||||||
|
main: 'JSONEditor'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
<!-- json editor -->
|
<!-- json editor -->
|
||||||
<link rel="stylesheet" type="text/css" href="../jsoneditor.css">
|
<link rel="stylesheet" type="text/css" href="../jsoneditor.css">
|
||||||
<script type="text/javascript" src="../jsoneditor.js"></script>
|
|
||||||
|
|
||||||
<!-- ace editor -->
|
<!-- ace editor -->
|
||||||
<script type="text/javascript" src="../node_modules/ace/build/src-min/ace.js"></script>
|
<script type="text/javascript" src="../node_modules/ace/build/src-min/ace.js"></script>
|
||||||
|
@ -43,9 +56,12 @@
|
||||||
<div id="jsoneditor"></div>
|
<div id="jsoneditor"></div>
|
||||||
|
|
||||||
<script type="text/javascript" >
|
<script type="text/javascript" >
|
||||||
var container = document.getElementById('jsoneditor');
|
var container, options, json, editor;
|
||||||
|
|
||||||
var options = {
|
require(['JSONEditor'], function (JSONEditor) {
|
||||||
|
container = document.getElementById('jsoneditor');
|
||||||
|
|
||||||
|
options = {
|
||||||
mode: 'tree',
|
mode: 'tree',
|
||||||
modes: ['code', 'form', 'text', 'tree', 'view'], // allowed modes
|
modes: ['code', 'form', 'text', 'tree', 'view'], // allowed modes
|
||||||
error: function (err) {
|
error: function (err) {
|
||||||
|
@ -53,7 +69,7 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var json = {
|
json = {
|
||||||
"array": [1, 2, 3],
|
"array": [1, 2, 3],
|
||||||
"boolean": true,
|
"boolean": true,
|
||||||
"null": null,
|
"null": null,
|
||||||
|
@ -62,7 +78,8 @@
|
||||||
"string": "Hello World"
|
"string": "Hello World"
|
||||||
};
|
};
|
||||||
|
|
||||||
var editor = new jsoneditor.JSONEditor(container, options, json);
|
editor = new JSONEditor(container, options, json);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||||
|
|
||||||
|
<!-- json editor -->
|
||||||
|
<script type="text/javascript" src="../jsoneditor.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="../jsoneditor.css">
|
||||||
|
|
||||||
|
<!-- ace editor -->
|
||||||
|
<script type="text/javascript" src="../node_modules/ace/build/src-min/ace.js"></script>
|
||||||
|
<script type="text/javascript" src="../src/js/ace/theme-jsoneditor.js"></script>
|
||||||
|
|
||||||
|
<!-- json lint -->
|
||||||
|
<script type="text/javascript" src="../node_modules/jsonlint/lib/jsonlint.js"></script>
|
||||||
|
|
||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
font: 10.5pt arial;
|
||||||
|
color: #4d4d4d;
|
||||||
|
line-height: 150%;
|
||||||
|
width: 500px;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
#jsoneditor {
|
||||||
|
width: 500px;
|
||||||
|
height: 500px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Switch editor mode using the mode box.
|
||||||
|
Note that the mode can be changed programmatically as well using the method
|
||||||
|
<code>editor.setMode(mode)</code>, try it in the console of your browser.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div id="jsoneditor"></div>
|
||||||
|
|
||||||
|
<script type="text/javascript" >
|
||||||
|
var container, options, json, editor;
|
||||||
|
|
||||||
|
container = document.getElementById('jsoneditor');
|
||||||
|
|
||||||
|
options = {
|
||||||
|
mode: 'tree',
|
||||||
|
modes: ['code', 'form', 'text', 'tree', 'view'], // allowed modes
|
||||||
|
error: function (err) {
|
||||||
|
alert(err.toString());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
json = {
|
||||||
|
"array": [1, 2, 3],
|
||||||
|
"boolean": true,
|
||||||
|
"null": null,
|
||||||
|
"number": 123,
|
||||||
|
"object": {"a": "b", "c": "d"},
|
||||||
|
"string": "Hello World"
|
||||||
|
};
|
||||||
|
|
||||||
|
editor = new JSONEditor(container, options, json);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue