Reworked the source code to commonjs modules
This commit is contained in:
parent
abc3ac3625
commit
c18145f503
149
jsoneditor.js
149
jsoneditor.js
|
@ -24,7 +24,7 @@
|
||||||
*
|
*
|
||||||
* @author Jos de Jong, <wjosdejong@gmail.com>
|
* @author Jos de Jong, <wjosdejong@gmail.com>
|
||||||
* @version 3.2.0
|
* @version 3.2.0
|
||||||
* @date 2015-01-25
|
* @date 2015-02-27
|
||||||
*/
|
*/
|
||||||
(function webpackUniversalModuleDefinition(root, factory) {
|
(function webpackUniversalModuleDefinition(root, factory) {
|
||||||
if(typeof exports === 'object' && typeof module === 'object')
|
if(typeof exports === 'object' && typeof module === 'object')
|
||||||
|
@ -82,7 +82,9 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
/* 0 */
|
/* 0 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(1), __webpack_require__(2), __webpack_require__(3)], __WEBPACK_AMD_DEFINE_RESULT__ = function (treemode, textmode, util) {
|
var treemode = __webpack_require__(1);
|
||||||
|
var textmode = __webpack_require__(2);
|
||||||
|
var util = __webpack_require__(3);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor JSONEditor
|
* @constructor JSONEditor
|
||||||
|
@ -341,14 +343,19 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
JSONEditor.registerMode(treemode);
|
JSONEditor.registerMode(treemode);
|
||||||
JSONEditor.registerMode(textmode);
|
JSONEditor.registerMode(textmode);
|
||||||
|
|
||||||
return JSONEditor;
|
module.exports = JSONEditor;
|
||||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 1 */
|
/* 1 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(4), __webpack_require__(5), __webpack_require__(6), __webpack_require__(7), __webpack_require__(8), __webpack_require__(3)], __WEBPACK_AMD_DEFINE_RESULT__ = function (Highlighter, History, SearchBox, Node, modeswitcher, util) {
|
var Highlighter = __webpack_require__(4);
|
||||||
|
var History = __webpack_require__(5);
|
||||||
|
var SearchBox = __webpack_require__(6);
|
||||||
|
var Node = __webpack_require__(7);
|
||||||
|
var modeswitcher = __webpack_require__(8);
|
||||||
|
var util = __webpack_require__(3);
|
||||||
|
|
||||||
// create a mixin with the functions for tree mode
|
// create a mixin with the functions for tree mode
|
||||||
var treemode = {};
|
var treemode = {};
|
||||||
|
@ -1043,7 +1050,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
};
|
};
|
||||||
|
|
||||||
// define modes
|
// define modes
|
||||||
return [
|
module.exports = [
|
||||||
{
|
{
|
||||||
mode: 'tree',
|
mode: 'tree',
|
||||||
mixin: treemode,
|
mixin: treemode,
|
||||||
|
@ -1060,14 +1067,13 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
data: 'json'
|
data: 'json'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 2 */
|
/* 2 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(8), __webpack_require__(3)], __WEBPACK_AMD_DEFINE_RESULT__ = function (modeswitcher, util) {
|
var modeswitcher = __webpack_require__(8);
|
||||||
|
var util = __webpack_require__(3);
|
||||||
|
|
||||||
// create a mixin with the functions for text mode
|
// create a mixin with the functions for text mode
|
||||||
var textmode = {};
|
var textmode = {};
|
||||||
|
@ -1387,7 +1393,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
};
|
};
|
||||||
|
|
||||||
// define modes
|
// define modes
|
||||||
return [
|
module.exports = [
|
||||||
{
|
{
|
||||||
mode: 'text',
|
mode: 'text',
|
||||||
mixin: textmode,
|
mixin: textmode,
|
||||||
|
@ -1401,31 +1407,25 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
load: textmode.format
|
load: textmode.format
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 3 */
|
/* 3 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function () {
|
|
||||||
|
|
||||||
// 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
|
||||||
* @return {JSON} json
|
* @return {JSON} json
|
||||||
*/
|
*/
|
||||||
util.parse = function parse(jsonString) {
|
exports.parse = function parse(jsonString) {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(jsonString);
|
return JSON.parse(jsonString);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
// try to throw a more detailed error message using validate
|
// try to throw a more detailed error message using validate
|
||||||
util.validate(jsonString);
|
exports.validate(jsonString);
|
||||||
|
|
||||||
// rethrow the original error
|
// rethrow the original error
|
||||||
throw err;
|
throw err;
|
||||||
|
@ -1440,7 +1440,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* @param {string} jsString
|
* @param {string} jsString
|
||||||
* @returns {string} json
|
* @returns {string} json
|
||||||
*/
|
*/
|
||||||
util.sanitize = function (jsString) {
|
exports.sanitize = function (jsString) {
|
||||||
// escape all single and double quotes inside strings
|
// escape all single and double quotes inside strings
|
||||||
var chars = [];
|
var chars = [];
|
||||||
var inString = false;
|
var inString = false;
|
||||||
|
@ -1491,7 +1491,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* @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) {
|
exports.validate = function validate(jsonString) {
|
||||||
if (typeof(jsonlint) != 'undefined') {
|
if (typeof(jsonlint) != 'undefined') {
|
||||||
jsonlint.parse(jsonString);
|
jsonlint.parse(jsonString);
|
||||||
}
|
}
|
||||||
|
@ -1506,7 +1506,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* @param {Object} b
|
* @param {Object} b
|
||||||
* @return {Object} a
|
* @return {Object} a
|
||||||
*/
|
*/
|
||||||
util.extend = function extend(a, b) {
|
exports.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];
|
||||||
|
@ -1520,7 +1520,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* @param {Object} a
|
* @param {Object} a
|
||||||
* @return {Object} a
|
* @return {Object} a
|
||||||
*/
|
*/
|
||||||
util.clear = function clear (a) {
|
exports.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];
|
||||||
|
@ -1533,7 +1533,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* 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) {
|
exports.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);
|
||||||
}
|
}
|
||||||
|
@ -1544,7 +1544,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* @param {*} object
|
* @param {*} object
|
||||||
* @return {String} type
|
* @return {String} type
|
||||||
*/
|
*/
|
||||||
util.type = function type (object) {
|
exports.type = function type (object) {
|
||||||
if (object === null) {
|
if (object === null) {
|
||||||
return 'null';
|
return 'null';
|
||||||
}
|
}
|
||||||
|
@ -1563,7 +1563,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
if ((object instanceof RegExp) || (typeof object === 'regexp')) {
|
if ((object instanceof RegExp) || (typeof object === 'regexp')) {
|
||||||
return 'regexp';
|
return 'regexp';
|
||||||
}
|
}
|
||||||
if (util.isArray(object)) {
|
if (exports.isArray(object)) {
|
||||||
return 'array';
|
return 'array';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1576,7 +1576,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* @param {String} text
|
* @param {String} text
|
||||||
*/
|
*/
|
||||||
var isUrlRegex = /^https?:\/\/\S+$/;
|
var isUrlRegex = /^https?:\/\/\S+$/;
|
||||||
util.isUrl = function isUrl (text) {
|
exports.isUrl = function isUrl (text) {
|
||||||
return (typeof text == 'string' || text instanceof String) &&
|
return (typeof text == 'string' || text instanceof String) &&
|
||||||
isUrlRegex.test(text);
|
isUrlRegex.test(text);
|
||||||
};
|
};
|
||||||
|
@ -1586,7 +1586,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* @param {*} obj
|
* @param {*} obj
|
||||||
* @returns {boolean} returns true when obj is an array
|
* @returns {boolean} returns true when obj is an array
|
||||||
*/
|
*/
|
||||||
util.isArray = function (obj) {
|
exports.isArray = function (obj) {
|
||||||
return Object.prototype.toString.call(obj) === '[object Array]';
|
return Object.prototype.toString.call(obj) === '[object Array]';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1596,7 +1596,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* @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) {
|
exports.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;
|
||||||
};
|
};
|
||||||
|
@ -1607,7 +1607,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* @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) {
|
exports.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;
|
||||||
};
|
};
|
||||||
|
@ -1617,7 +1617,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* @param {Element} elem
|
* @param {Element} elem
|
||||||
* @param {String} className
|
* @param {String} className
|
||||||
*/
|
*/
|
||||||
util.addClassName = function addClassName(elem, className) {
|
exports.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
|
||||||
|
@ -1630,7 +1630,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* @param {Element} elem
|
* @param {Element} elem
|
||||||
* @param {String} className
|
* @param {String} className
|
||||||
*/
|
*/
|
||||||
util.removeClassName = function removeClassName(elem, className) {
|
exports.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) {
|
||||||
|
@ -1644,7 +1644,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* 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) {
|
exports.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];
|
||||||
|
@ -1667,7 +1667,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
}
|
}
|
||||||
|
|
||||||
// recursively strip childs
|
// recursively strip childs
|
||||||
util.stripFormatting(child);
|
exports.stripFormatting(child);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1678,7 +1678,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* 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) {
|
exports.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)
|
||||||
|
@ -1695,7 +1695,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* 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) {
|
exports.selectContentEditable = function selectContentEditable(contentEditableElement) {
|
||||||
if (!contentEditableElement || contentEditableElement.nodeName != 'DIV') {
|
if (!contentEditableElement || contentEditableElement.nodeName != 'DIV') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1715,7 +1715,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* 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() {
|
exports.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) {
|
||||||
|
@ -1730,7 +1730,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* 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) {
|
exports.setSelection = function setSelection(range) {
|
||||||
if (range) {
|
if (range) {
|
||||||
if (window.getSelection) {
|
if (window.getSelection) {
|
||||||
var sel = window.getSelection();
|
var sel = window.getSelection();
|
||||||
|
@ -1749,8 +1749,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* 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() {
|
exports.getSelectionOffset = function getSelectionOffset() {
|
||||||
var range = util.getSelection();
|
var range = exports.getSelection();
|
||||||
|
|
||||||
if (range && 'startOffset' in range && 'endOffset' in range &&
|
if (range && 'startOffset' in range && 'endOffset' in range &&
|
||||||
range.startContainer && (range.startContainer == range.endContainer)) {
|
range.startContainer && (range.startContainer == range.endContainer)) {
|
||||||
|
@ -1771,7 +1771,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* {Number} startOffset
|
* {Number} startOffset
|
||||||
* {Number} endOffset
|
* {Number} endOffset
|
||||||
*/
|
*/
|
||||||
util.setSelectionOffset = function setSelectionOffset(params) {
|
exports.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) {
|
||||||
|
@ -1781,7 +1781,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
range.setStart(params.container.firstChild, params.startOffset);
|
range.setStart(params.container.firstChild, params.startOffset);
|
||||||
range.setEnd(params.container.firstChild, params.endOffset);
|
range.setEnd(params.container.firstChild, params.endOffset);
|
||||||
|
|
||||||
util.setSelection(range);
|
exports.setSelection(range);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1792,7 +1792,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* @param {Object} [buffer]
|
* @param {Object} [buffer]
|
||||||
* @return {String} innerText
|
* @return {String} innerText
|
||||||
*/
|
*/
|
||||||
util.getInnerText = function getInnerText(element, buffer) {
|
exports.getInnerText = function getInnerText(element, buffer) {
|
||||||
var first = (buffer == undefined);
|
var first = (buffer == undefined);
|
||||||
if (first) {
|
if (first) {
|
||||||
buffer = {
|
buffer = {
|
||||||
|
@ -1828,7 +1828,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
innerText += '\n';
|
innerText += '\n';
|
||||||
buffer.flush();
|
buffer.flush();
|
||||||
}
|
}
|
||||||
innerText += util.getInnerText(child, buffer);
|
innerText += exports.getInnerText(child, buffer);
|
||||||
buffer.set('\n');
|
buffer.set('\n');
|
||||||
}
|
}
|
||||||
else if (child.nodeName == 'BR') {
|
else if (child.nodeName == 'BR') {
|
||||||
|
@ -1836,14 +1836,14 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
buffer.set('\n');
|
buffer.set('\n');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
innerText += util.getInnerText(child, buffer);
|
innerText += exports.getInnerText(child, buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return innerText;
|
return innerText;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (element.nodeName == 'P' && util.getInternetExplorerVersion() != -1) {
|
if (element.nodeName == 'P' && exports.getInternetExplorerVersion() != -1) {
|
||||||
// On Internet Explorer, a <p> with hasChildNodes()==false is
|
// On Internet Explorer, a <p> with hasChildNodes()==false is
|
||||||
// rendered with a new line. Note that a <p> with
|
// rendered with a new line. Note that a <p> with
|
||||||
// hasChildNodes()==true is rendered without a new line
|
// hasChildNodes()==true is rendered without a new line
|
||||||
|
@ -1863,7 +1863,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* 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() {
|
exports.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')
|
||||||
|
@ -1885,7 +1885,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* Test whether the current browser is Firefox
|
* Test whether the current browser is Firefox
|
||||||
* @returns {boolean} isFirefox
|
* @returns {boolean} isFirefox
|
||||||
*/
|
*/
|
||||||
util.isFirefox = function isFirefox () {
|
exports.isFirefox = function isFirefox () {
|
||||||
return (navigator.userAgent.indexOf("Firefox") != -1);
|
return (navigator.userAgent.indexOf("Firefox") != -1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1905,12 +1905,12 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* @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) {
|
exports.addEventListener = function addEventListener(element, action, listener, useCapture) {
|
||||||
if (element.addEventListener) {
|
if (element.addEventListener) {
|
||||||
if (useCapture === undefined)
|
if (useCapture === undefined)
|
||||||
useCapture = false;
|
useCapture = false;
|
||||||
|
|
||||||
if (action === "mousewheel" && util.isFirefox()) {
|
if (action === "mousewheel" && exports.isFirefox()) {
|
||||||
action = "DOMMouseScroll"; // For Firefox
|
action = "DOMMouseScroll"; // For Firefox
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1933,12 +1933,12 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
* @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) {
|
exports.removeEventListener = function removeEventListener(element, action, listener, useCapture) {
|
||||||
if (element.removeEventListener) {
|
if (element.removeEventListener) {
|
||||||
if (useCapture === undefined)
|
if (useCapture === undefined)
|
||||||
useCapture = false;
|
useCapture = false;
|
||||||
|
|
||||||
if (action === "mousewheel" && util.isFirefox()) {
|
if (action === "mousewheel" && exports.isFirefox()) {
|
||||||
action = "DOMMouseScroll"; // For Firefox
|
action = "DOMMouseScroll"; // For Firefox
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1949,15 +1949,11 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return util;
|
|
||||||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 4 */
|
/* 4 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = 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.
|
||||||
|
@ -2041,14 +2037,14 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
this.locked = false;
|
this.locked = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
return Highlighter;
|
module.exports = Highlighter;
|
||||||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 5 */
|
/* 5 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(3)], __WEBPACK_AMD_DEFINE_RESULT__ = function (util) {
|
var util = __webpack_require__(3);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor History
|
* @constructor History
|
||||||
|
@ -2269,16 +2265,13 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return History;
|
module.exports = History;
|
||||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 6 */
|
/* 6 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function () {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor SearchBox
|
* @constructor SearchBox
|
||||||
* Create a search box in given HTML container
|
* Create a search box in given HTML container
|
||||||
|
@ -2566,17 +2559,16 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return SearchBox;
|
module.exports = SearchBox;
|
||||||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 7 */
|
/* 7 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(9), __webpack_require__(10), __webpack_require__(3)], __WEBPACK_AMD_DEFINE_RESULT__ = function (ContextMenu, appendNodeFactory, util) {
|
var ContextMenu = __webpack_require__(9);
|
||||||
|
var appendNodeFactory = __webpack_require__(10);
|
||||||
|
var util = __webpack_require__(3);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor Node
|
* @constructor Node
|
||||||
|
@ -5502,14 +5494,14 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
// TODO: find a nicer solution to resolve this circular dependency between Node and AppendNode
|
// TODO: find a nicer solution to resolve this circular dependency between Node and AppendNode
|
||||||
var AppendNode = appendNodeFactory(Node);
|
var AppendNode = appendNodeFactory(Node);
|
||||||
|
|
||||||
return Node;
|
module.exports = Node;
|
||||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 8 */
|
/* 8 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(9)], __WEBPACK_AMD_DEFINE_RESULT__ = function (ContextMenu) {
|
var ContextMenu = __webpack_require__(9);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a select box to be used in the editor menu's, which allows to switch mode
|
* Create a select box to be used in the editor menu's, which allows to switch mode
|
||||||
|
@ -5608,17 +5600,14 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
exports.create = createModeSwitcher;
|
||||||
create: createModeSwitcher
|
|
||||||
}
|
|
||||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 9 */
|
/* 9 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(3)], __WEBPACK_AMD_DEFINE_RESULT__ = function (util) {
|
var util = __webpack_require__(3);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A context menu
|
* A context menu
|
||||||
|
@ -6060,15 +6049,15 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
return ContextMenu;
|
module.exports = ContextMenu;
|
||||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
/* 10 */
|
/* 10 */
|
||||||
/***/ function(module, exports, __webpack_require__) {
|
/***/ function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(9), __webpack_require__(3)], __WEBPACK_AMD_DEFINE_RESULT__ = function (ContextMenu, util) {
|
var util = __webpack_require__(3);
|
||||||
|
var ContextMenu = __webpack_require__(9);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A factory function to create an AppendNode, which depends on a Node
|
* A factory function to create an AppendNode, which depends on a Node
|
||||||
|
@ -6292,9 +6281,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||||
return AppendNode;
|
return AppendNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the factory function
|
module.exports = appendNodeFactory;
|
||||||
return appendNodeFactory;
|
|
||||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }
|
/***/ }
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
||||||
define(['./util'], function (util) {
|
var util = require('./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
|
||||||
|
@ -9,7 +9,7 @@ define(['./util'], function (util) {
|
||||||
* 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;
|
||||||
|
@ -142,14 +142,14 @@ define(['./util'], function (util) {
|
||||||
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) {
|
||||||
|
@ -169,16 +169,16 @@ define(['./util'], function (util) {
|
||||||
});
|
});
|
||||||
|
|
||||||
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
|
||||||
|
@ -242,12 +242,12 @@ define(['./util'], function (util) {
|
||||||
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);
|
||||||
|
@ -271,15 +271,15 @@ define(['./util'], function (util) {
|
||||||
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);
|
||||||
|
|
||||||
|
@ -311,14 +311,14 @@ define(['./util'], function (util) {
|
||||||
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;
|
||||||
|
@ -420,15 +420,15 @@ define(['./util'], function (util) {
|
||||||
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) {
|
||||||
|
@ -438,7 +438,6 @@ define(['./util'], function (util) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
return ContextMenu;
|
module.exports = ContextMenu;
|
||||||
});
|
|
||||||
|
|
|
@ -1,19 +1,17 @@
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -31,13 +29,13 @@ define(function () {
|
||||||
|
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
|
@ -55,33 +53,32 @@ define(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;
|
module.exports = Highlighter;
|
||||||
});
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
define(['./util'], function (util) {
|
var util = require('./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();
|
||||||
|
|
||||||
|
@ -105,15 +105,15 @@ define(['./util'], function (util) {
|
||||||
// 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",
|
||||||
|
@ -124,7 +124,7 @@ define(['./util'], function (util) {
|
||||||
* 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,
|
||||||
|
@ -139,39 +139,39 @@ define(['./util'], function (util) {
|
||||||
|
|
||||||
// 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) {
|
||||||
|
@ -191,12 +191,12 @@ define(['./util'], function (util) {
|
||||||
// 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++;
|
||||||
|
|
||||||
|
@ -217,7 +217,6 @@ define(['./util'], function (util) {
|
||||||
// fire onchange event
|
// fire onchange event
|
||||||
this.onChange();
|
this.onChange();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return History;
|
module.exports = History;
|
||||||
});
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
define(['./treemode', './textmode', './util'], function (treemode, textmode, util) {
|
var treemode = require('./treemode');
|
||||||
|
var textmode = require('./textmode');
|
||||||
|
var util = require('./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:
|
||||||
|
@ -26,7 +28,7 @@ define(['./treemode', './textmode', './util'], function (treemode, textmode, uti
|
||||||
* 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".');
|
||||||
}
|
}
|
||||||
|
@ -41,9 +43,9 @@ define(['./treemode', './textmode', './util'], function (treemode, textmode, uti
|
||||||
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: {
|
||||||
|
@ -58,88 +60,88 @@ define(['./treemode', './textmode', './util'], function (treemode, textmode, uti
|
||||||
*
|
*
|
||||||
* @type { Object.<String, {mixin: Object, data: String} > }
|
* @type { Object.<String, {mixin: 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,
|
||||||
|
@ -175,15 +177,15 @@ define(['./treemode', './textmode', './util'], function (treemode, textmode, uti
|
||||||
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. ' +
|
||||||
|
@ -197,9 +199,9 @@ define(['./treemode', './textmode', './util'], function (treemode, textmode, uti
|
||||||
else {
|
else {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a plugin with one ore multiple modes for the JSON Editor.
|
* Register a plugin with one ore multiple modes for the JSON Editor.
|
||||||
*
|
*
|
||||||
* A mode is described as an object with properties:
|
* A mode is described as an object with properties:
|
||||||
|
@ -218,7 +220,7 @@ define(['./treemode', './textmode', './util'], function (treemode, textmode, uti
|
||||||
*
|
*
|
||||||
* @param {Object | Array} mode A mode object or an array with multiple mode objects.
|
* @param {Object | Array} mode A mode object or an array with multiple mode objects.
|
||||||
*/
|
*/
|
||||||
JSONEditor.registerMode = function (mode) {
|
JSONEditor.registerMode = function (mode) {
|
||||||
var i, prop;
|
var i, prop;
|
||||||
|
|
||||||
if (util.isArray(mode)) {
|
if (util.isArray(mode)) {
|
||||||
|
@ -251,11 +253,10 @@ define(['./treemode', './textmode', './util'], function (treemode, textmode, uti
|
||||||
|
|
||||||
JSONEditor.modes[name] = mode;
|
JSONEditor.modes[name] = mode;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// register tree and text modes
|
// register tree and text modes
|
||||||
JSONEditor.registerMode(treemode);
|
JSONEditor.registerMode(treemode);
|
||||||
JSONEditor.registerMode(textmode);
|
JSONEditor.registerMode(textmode);
|
||||||
|
|
||||||
return JSONEditor;
|
module.exports = JSONEditor;
|
||||||
});
|
|
||||||
|
|
473
src/js/Node.js
473
src/js/Node.js
File diff suppressed because it is too large
Load Diff
|
@ -1,13 +1,11 @@
|
||||||
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;
|
||||||
|
@ -99,14 +97,14 @@ define(function () {
|
||||||
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) {
|
||||||
|
@ -114,14 +112,14 @@ define(function () {
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
@ -130,16 +128,16 @@ define(function () {
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
@ -180,26 +178,26 @@ define(function () {
|
||||||
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();
|
||||||
|
@ -208,9 +206,9 @@ define(function () {
|
||||||
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
|
||||||
|
@ -218,7 +216,7 @@ define(function () {
|
||||||
* 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;
|
||||||
|
@ -242,14 +240,14 @@ define(function () {
|
||||||
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
|
||||||
|
@ -273,21 +271,18 @@ define(function () {
|
||||||
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;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = SearchBox;
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
define(['./ContextMenu', './util'], function (ContextMenu, util) {
|
var util = require('./util');
|
||||||
|
var ContextMenu = require('./ContextMenu');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A factory function to create an AppendNode, which depends on a Node
|
* A factory function to create an AppendNode, which depends on a Node
|
||||||
* @param {Node} Node
|
* @param {Node} Node
|
||||||
*/
|
*/
|
||||||
function appendNodeFactory(Node) {
|
function appendNodeFactory(Node) {
|
||||||
/**
|
/**
|
||||||
* @constructor AppendNode
|
* @constructor AppendNode
|
||||||
* @extends Node
|
* @extends Node
|
||||||
|
@ -220,8 +221,6 @@ define(['./ContextMenu', './util'], function (ContextMenu, util) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return AppendNode;
|
return AppendNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the factory function
|
module.exports = appendNodeFactory;
|
||||||
return appendNodeFactory;
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
define(['./ContextMenu'], function (ContextMenu) {
|
var ContextMenu = require('./ContextMenu');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a select box to be used in the editor menu's, which allows to switch mode
|
* Create a select box to be used in the editor menu's, which allows to switch mode
|
||||||
* @param {Object} editor
|
* @param {Object} 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 createModeSwitcher(editor, modes, current) {
|
function createModeSwitcher(editor, modes, current) {
|
||||||
// TODO: decouple mode switcher from editor
|
// TODO: decouple mode switcher from editor
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,9 +95,6 @@ define(['./ContextMenu'], function (ContextMenu) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
exports.create = createModeSwitcher;
|
||||||
create: createModeSwitcher
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
|
|
||||||
// module exports
|
|
||||||
var jsoneditor = {
|
|
||||||
'JSONEditor': JSONEditor,
|
|
||||||
'util': util
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* load jsoneditor.css
|
|
||||||
*/
|
|
||||||
var loadCss = function () {
|
|
||||||
// find the script named 'jsoneditor.js' or 'jsoneditor.min.js' or
|
|
||||||
// 'jsoneditor.min.js', and use its path to find the css file to be
|
|
||||||
// loaded.
|
|
||||||
var scripts = document.getElementsByTagName('script');
|
|
||||||
for (var s = 0; s < scripts.length; s++) {
|
|
||||||
var src = scripts[s].src;
|
|
||||||
if (/(^|\/)jsoneditor([-\.]min)?.js$/.test(src)) {
|
|
||||||
var jsFile = src.split('?')[0];
|
|
||||||
var cssFile = jsFile.substring(0, jsFile.length - 2) + 'css';
|
|
||||||
|
|
||||||
// load css file
|
|
||||||
var link = document.createElement('link');
|
|
||||||
link.type = 'text/css';
|
|
||||||
link.rel = 'stylesheet';
|
|
||||||
link.href = cssFile;
|
|
||||||
document.getElementsByTagName('head')[0].appendChild(link);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CommonJS module exports
|
|
||||||
*/
|
|
||||||
if (typeof(module) != 'undefined' && typeof(exports) != 'undefined') {
|
|
||||||
loadCss();
|
|
||||||
module.exports = exports = jsoneditor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AMD module exports
|
|
||||||
*/
|
|
||||||
if (typeof(require) != 'undefined' && typeof(define) != 'undefined') {
|
|
||||||
loadCss();
|
|
||||||
define(function () {
|
|
||||||
return jsoneditor;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// attach the module to the window, load as a regular javascript file
|
|
||||||
window['jsoneditor'] = jsoneditor;
|
|
||||||
}
|
|
|
@ -1,9 +1,10 @@
|
||||||
define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
var modeswitcher = require('./modeswitcher');
|
||||||
|
var util = require('./util');
|
||||||
|
|
||||||
// create a mixin with the functions for text mode
|
// create a mixin with the functions for text mode
|
||||||
var textmode = {};
|
var textmode = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a text editor
|
* Create a text editor
|
||||||
* @param {Element} container
|
* @param {Element} container
|
||||||
* @param {Object} [options] Object with options. available options:
|
* @param {Object} [options] Object with options. available options:
|
||||||
|
@ -16,7 +17,7 @@ define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
||||||
* triggered on change
|
* triggered on change
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
textmode.create = function (container, options) {
|
textmode.create = function (container, options) {
|
||||||
// read options
|
// read options
|
||||||
options = options || {};
|
options = options || {};
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
@ -160,14 +161,14 @@ define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event handler for keydown. Handles shortcut keys
|
* Event handler for keydown. Handles shortcut keys
|
||||||
* @param {Event} event
|
* @param {Event} event
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
textmode._onKeyDown = function (event) {
|
textmode._onKeyDown = function (event) {
|
||||||
var keynum = event.which || event.keyCode;
|
var keynum = event.which || event.keyCode;
|
||||||
var handled = false;
|
var handled = false;
|
||||||
|
|
||||||
|
@ -185,25 +186,25 @@ define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detach the editor from the DOM
|
* Detach the editor from the DOM
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
textmode._delete = function () {
|
textmode._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
|
||||||
*/
|
*/
|
||||||
textmode._onError = function(err) {
|
textmode._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. ' +
|
||||||
|
@ -217,61 +218,61 @@ define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
||||||
else {
|
else {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compact the code in the formatter
|
* Compact the code in the formatter
|
||||||
*/
|
*/
|
||||||
textmode.compact = function () {
|
textmode.compact = function () {
|
||||||
var json = this.get();
|
var json = this.get();
|
||||||
var text = JSON.stringify(json);
|
var text = JSON.stringify(json);
|
||||||
this.setText(text);
|
this.setText(text);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format the code in the formatter
|
* Format the code in the formatter
|
||||||
*/
|
*/
|
||||||
textmode.format = function () {
|
textmode.format = function () {
|
||||||
var json = this.get();
|
var json = this.get();
|
||||||
var text = JSON.stringify(json, null, this.indentation);
|
var text = JSON.stringify(json, null, this.indentation);
|
||||||
this.setText(text);
|
this.setText(text);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set focus to the formatter
|
* Set focus to the formatter
|
||||||
*/
|
*/
|
||||||
textmode.focus = function () {
|
textmode.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
|
||||||
*/
|
*/
|
||||||
textmode.resize = function () {
|
textmode.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
|
||||||
*/
|
*/
|
||||||
textmode.set = function(json) {
|
textmode.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
|
||||||
*/
|
*/
|
||||||
textmode.get = function() {
|
textmode.get = function() {
|
||||||
var text = this.getText();
|
var text = this.getText();
|
||||||
var json;
|
var json;
|
||||||
|
|
||||||
|
@ -288,13 +289,13 @@ define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the text contents of the editor
|
* Get the text contents of the editor
|
||||||
* @return {String} jsonText
|
* @return {String} jsonText
|
||||||
*/
|
*/
|
||||||
textmode.getText = function() {
|
textmode.getText = function() {
|
||||||
if (this.textarea) {
|
if (this.textarea) {
|
||||||
return this.textarea.value;
|
return this.textarea.value;
|
||||||
}
|
}
|
||||||
|
@ -302,23 +303,23 @@ define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
||||||
return this.editor.getValue();
|
return this.editor.getValue();
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the text contents of the editor
|
* Set the text contents of the editor
|
||||||
* @param {String} jsonText
|
* @param {String} jsonText
|
||||||
*/
|
*/
|
||||||
textmode.setText = function(jsonText) {
|
textmode.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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// define modes
|
// define modes
|
||||||
return [
|
module.exports = [
|
||||||
{
|
{
|
||||||
mode: 'text',
|
mode: 'text',
|
||||||
mixin: textmode,
|
mixin: textmode,
|
||||||
|
@ -331,5 +332,4 @@ define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
||||||
data: 'text',
|
data: 'text',
|
||||||
load: textmode.format
|
load: textmode.format
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
});
|
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher', './util'],
|
var Highlighter = require('./Highlighter');
|
||||||
function (Highlighter, History, SearchBox, Node, modeswitcher, util) {
|
var History = require('./History');
|
||||||
|
var SearchBox = require('./SearchBox');
|
||||||
|
var Node = require('./Node');
|
||||||
|
var modeswitcher = require('./modeswitcher');
|
||||||
|
var util = require('./util');
|
||||||
|
|
||||||
// create a mixin with the functions for tree mode
|
// create a mixin with the functions for tree mode
|
||||||
var treemode = {};
|
var treemode = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a tree editor
|
* Create a tree editor
|
||||||
* @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:
|
||||||
|
@ -20,7 +24,7 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
* {String} name Field name for the root node.
|
* {String} name Field name for the root node.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
treemode.create = function (container, options) {
|
treemode.create = function (container, options) {
|
||||||
if (!container) {
|
if (!container) {
|
||||||
throw new Error('No container element provided.');
|
throw new Error('No container element provided.');
|
||||||
}
|
}
|
||||||
|
@ -37,24 +41,24 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
|
|
||||||
this._createFrame();
|
this._createFrame();
|
||||||
this._createTable();
|
this._createTable();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detach the editor from the DOM
|
* Detach the editor from the DOM
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
treemode._delete = function () {
|
treemode._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
|
||||||
*/
|
*/
|
||||||
treemode._setOptions = function (options) {
|
treemode._setOptions = function (options) {
|
||||||
this.options = {
|
this.options = {
|
||||||
search: true,
|
search: true,
|
||||||
history: true,
|
history: true,
|
||||||
|
@ -70,21 +74,21 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// node currently being edited
|
// node currently being edited
|
||||||
var focusNode = undefined;
|
var focusNode = undefined;
|
||||||
|
|
||||||
// dom having focus
|
// dom having focus
|
||||||
var domFocus = null;
|
var domFocus = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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).
|
||||||
*/
|
*/
|
||||||
treemode.set = function (json, name) {
|
treemode.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.
|
||||||
|
@ -119,13 +123,13 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
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
|
||||||
*/
|
*/
|
||||||
treemode.get = function () {
|
treemode.get = function () {
|
||||||
// remove focus from currently edited node
|
// remove focus from currently edited node
|
||||||
if (focusNode) {
|
if (focusNode) {
|
||||||
focusNode.blur();
|
focusNode.blur();
|
||||||
|
@ -137,69 +141,69 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
else {
|
else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the text contents of the editor
|
* Get the text contents of the editor
|
||||||
* @return {String} jsonText
|
* @return {String} jsonText
|
||||||
*/
|
*/
|
||||||
treemode.getText = function() {
|
treemode.getText = function() {
|
||||||
return JSON.stringify(this.get());
|
return JSON.stringify(this.get());
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the text contents of the editor
|
* Set the text contents of the editor
|
||||||
* @param {String} jsonText
|
* @param {String} jsonText
|
||||||
*/
|
*/
|
||||||
treemode.setText = function(jsonText) {
|
treemode.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
|
||||||
*/
|
*/
|
||||||
treemode.setName = function (name) {
|
treemode.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
|
||||||
*/
|
*/
|
||||||
treemode.getName = function () {
|
treemode.getName = function () {
|
||||||
return this.options.name;
|
return this.options.name;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the root node from the editor
|
* Remove the root node from the editor
|
||||||
*/
|
*/
|
||||||
treemode.clear = function () {
|
treemode.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
|
||||||
*/
|
*/
|
||||||
treemode._setRoot = function (node) {
|
treemode._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.
|
||||||
|
@ -211,7 +215,7 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
* the result is found ('field' or
|
* the result is found ('field' or
|
||||||
* 'value')
|
* 'value')
|
||||||
*/
|
*/
|
||||||
treemode.search = function (text) {
|
treemode.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
|
||||||
|
@ -223,31 +227,31 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expand all nodes
|
* Expand all nodes
|
||||||
*/
|
*/
|
||||||
treemode.expandAll = function () {
|
treemode.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
|
||||||
*/
|
*/
|
||||||
treemode.collapseAll = function () {
|
treemode.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",
|
||||||
|
@ -261,7 +265,7 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
* needed to undo or redo the action.
|
* needed to undo or redo the action.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
treemode._onAction = function (action, params) {
|
treemode._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);
|
||||||
|
@ -276,14 +280,14 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
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
|
||||||
*/
|
*/
|
||||||
treemode.startAutoScroll = function (mouseY) {
|
treemode.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);
|
||||||
|
@ -318,12 +322,12 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
else {
|
else {
|
||||||
this.stopAutoScroll();
|
this.stopAutoScroll();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop auto scrolling. Only applicable when scrolling
|
* Stop auto scrolling. Only applicable when scrolling
|
||||||
*/
|
*/
|
||||||
treemode.stopAutoScroll = function () {
|
treemode.stopAutoScroll = function () {
|
||||||
if (this.autoScrollTimer) {
|
if (this.autoScrollTimer) {
|
||||||
clearTimeout(this.autoScrollTimer);
|
clearTimeout(this.autoScrollTimer);
|
||||||
delete this.autoScrollTimer;
|
delete this.autoScrollTimer;
|
||||||
|
@ -331,10 +335,10 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
if (this.autoScrollStep) {
|
if (this.autoScrollStep) {
|
||||||
delete this.autoScrollStep;
|
delete this.autoScrollStep;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the focus to an element in the editor, set text selection, and
|
* Set the focus to an element in the editor, set text selection, and
|
||||||
* set scroll position.
|
* set scroll position.
|
||||||
* @param {Object} selection An object containing fields:
|
* @param {Object} selection An object containing fields:
|
||||||
|
@ -343,7 +347,7 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
* {Range | TextRange} range A text selection
|
* {Range | TextRange} range A text selection
|
||||||
* {Number} scrollTop Scroll position
|
* {Number} scrollTop Scroll position
|
||||||
*/
|
*/
|
||||||
treemode.setSelection = function (selection) {
|
treemode.setSelection = function (selection) {
|
||||||
if (!selection) {
|
if (!selection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -358,9 +362,9 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
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
|
||||||
|
@ -368,15 +372,15 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
* {Range | TextRange} range A text selection
|
* {Range | TextRange} range A text selection
|
||||||
* {Number} scrollTop Scroll position
|
* {Number} scrollTop Scroll position
|
||||||
*/
|
*/
|
||||||
treemode.getSelection = function () {
|
treemode.getSelection = function () {
|
||||||
return {
|
return {
|
||||||
dom: domFocus,
|
dom: 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
|
||||||
|
@ -385,7 +389,7 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
* when animation is finished, or false
|
* when animation is finished, or false
|
||||||
* when not.
|
* when not.
|
||||||
*/
|
*/
|
||||||
treemode.scrollTo = function (top, callback) {
|
treemode.scrollTo = function (top, callback) {
|
||||||
var content = this.content;
|
var content = this.content;
|
||||||
if (content) {
|
if (content) {
|
||||||
var editor = this;
|
var editor = this;
|
||||||
|
@ -430,13 +434,13 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
callback(false);
|
callback(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create main frame
|
* Create main frame
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
treemode._createFrame = function () {
|
treemode._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';
|
||||||
|
@ -540,13 +544,13 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
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
|
||||||
*/
|
*/
|
||||||
treemode._onUndo = function () {
|
treemode._onUndo = function () {
|
||||||
if (this.history) {
|
if (this.history) {
|
||||||
// undo last action
|
// undo last action
|
||||||
this.history.undo();
|
this.history.undo();
|
||||||
|
@ -556,13 +560,13 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
this.options.change();
|
this.options.change();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a redo action
|
* Perform a redo action
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
treemode._onRedo = function () {
|
treemode._onRedo = function () {
|
||||||
if (this.history) {
|
if (this.history) {
|
||||||
// redo last action
|
// redo last action
|
||||||
this.history.redo();
|
this.history.redo();
|
||||||
|
@ -572,14 +576,14 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
this.options.change();
|
this.options.change();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event handler
|
* Event handler
|
||||||
* @param event
|
* @param event
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
treemode._onEvent = function (event) {
|
treemode._onEvent = function (event) {
|
||||||
var target = event.target;
|
var target = event.target;
|
||||||
|
|
||||||
if (event.type == 'keydown') {
|
if (event.type == 'keydown') {
|
||||||
|
@ -594,14 +598,14 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
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
|
||||||
*/
|
*/
|
||||||
treemode._onKeyDown = function (event) {
|
treemode._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;
|
||||||
|
@ -652,13 +656,13 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create main table
|
* Create main table
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
treemode._createTable = function () {
|
treemode._createTable = function () {
|
||||||
var contentOuter = document.createElement('div');
|
var contentOuter = document.createElement('div');
|
||||||
contentOuter.className = 'outer';
|
contentOuter.className = 'outer';
|
||||||
this.contentOuter = contentOuter;
|
this.contentOuter = contentOuter;
|
||||||
|
@ -691,10 +695,10 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
this.table.appendChild(this.tbody);
|
this.table.appendChild(this.tbody);
|
||||||
|
|
||||||
this.frame.appendChild(contentOuter);
|
this.frame.appendChild(contentOuter);
|
||||||
};
|
};
|
||||||
|
|
||||||
// define modes
|
// define modes
|
||||||
return [
|
module.exports = [
|
||||||
{
|
{
|
||||||
mode: 'tree',
|
mode: 'tree',
|
||||||
mixin: treemode,
|
mixin: treemode,
|
||||||
|
@ -710,5 +714,4 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
||||||
mixin: treemode,
|
mixin: treemode,
|
||||||
data: 'json'
|
data: 'json'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
});
|
|
184
src/js/util.js
184
src/js/util.js
|
@ -1,28 +1,23 @@
|
||||||
define(function () {
|
/**
|
||||||
|
|
||||||
// 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
|
||||||
* @return {JSON} json
|
* @return {JSON} json
|
||||||
*/
|
*/
|
||||||
util.parse = function parse(jsonString) {
|
exports.parse = function parse(jsonString) {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(jsonString);
|
return JSON.parse(jsonString);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
// try to throw a more detailed error message using validate
|
// try to throw a more detailed error message using validate
|
||||||
util.validate(jsonString);
|
exports.validate(jsonString);
|
||||||
|
|
||||||
// rethrow the original error
|
// rethrow the original error
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitize a JSON-like string containing. For example changes JavaScript
|
* Sanitize a JSON-like string containing. For example changes JavaScript
|
||||||
* notation into JSON notation.
|
* notation into JSON notation.
|
||||||
* This function for example changes a string like "{a: 2, 'b': {c: 'd'}"
|
* This function for example changes a string like "{a: 2, 'b': {c: 'd'}"
|
||||||
|
@ -30,7 +25,7 @@ define(function () {
|
||||||
* @param {string} jsString
|
* @param {string} jsString
|
||||||
* @returns {string} json
|
* @returns {string} json
|
||||||
*/
|
*/
|
||||||
util.sanitize = function (jsString) {
|
exports.sanitize = function (jsString) {
|
||||||
// escape all single and double quotes inside strings
|
// escape all single and double quotes inside strings
|
||||||
var chars = [];
|
var chars = [];
|
||||||
var inString = false;
|
var inString = false;
|
||||||
|
@ -72,69 +67,69 @@ define(function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
return jsonString;
|
return jsonString;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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) {
|
exports.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) {
|
exports.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) {
|
exports.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) {
|
exports.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) {
|
exports.type = function type (object) {
|
||||||
if (object === null) {
|
if (object === null) {
|
||||||
return 'null';
|
return 'null';
|
||||||
}
|
}
|
||||||
|
@ -153,88 +148,88 @@ define(function () {
|
||||||
if ((object instanceof RegExp) || (typeof object === 'regexp')) {
|
if ((object instanceof RegExp) || (typeof object === 'regexp')) {
|
||||||
return 'regexp';
|
return 'regexp';
|
||||||
}
|
}
|
||||||
if (util.isArray(object)) {
|
if (exports.isArray(object)) {
|
||||||
return 'array';
|
return 'array';
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
exports.isUrl = function isUrl (text) {
|
||||||
return (typeof text == 'string' || text instanceof String) &&
|
return (typeof text == 'string' || text instanceof String) &&
|
||||||
isUrlRegex.test(text);
|
isUrlRegex.test(text);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tes whether given object is an Array
|
* Tes whether given object is an Array
|
||||||
* @param {*} obj
|
* @param {*} obj
|
||||||
* @returns {boolean} returns true when obj is an array
|
* @returns {boolean} returns true when obj is an array
|
||||||
*/
|
*/
|
||||||
util.isArray = function (obj) {
|
exports.isArray = function (obj) {
|
||||||
return Object.prototype.toString.call(obj) === '[object Array]';
|
return Object.prototype.toString.call(obj) === '[object Array]';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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) {
|
exports.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) {
|
exports.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) {
|
exports.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) {
|
exports.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) {
|
exports.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];
|
||||||
|
@ -257,18 +252,18 @@ define(function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
// recursively strip childs
|
// recursively strip childs
|
||||||
util.stripFormatting(child);
|
exports.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) {
|
exports.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)
|
||||||
|
@ -278,14 +273,14 @@ define(function () {
|
||||||
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) {
|
exports.selectContentEditable = function selectContentEditable(contentEditableElement) {
|
||||||
if (!contentEditableElement || contentEditableElement.nodeName != 'DIV') {
|
if (!contentEditableElement || contentEditableElement.nodeName != 'DIV') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -298,14 +293,14 @@ define(function () {
|
||||||
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() {
|
exports.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) {
|
||||||
|
@ -313,14 +308,14 @@ define(function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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) {
|
exports.setSelection = function setSelection(range) {
|
||||||
if (range) {
|
if (range) {
|
||||||
if (window.getSelection) {
|
if (window.getSelection) {
|
||||||
var sel = window.getSelection();
|
var sel = window.getSelection();
|
||||||
|
@ -328,9 +323,9 @@ define(function () {
|
||||||
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
|
||||||
|
@ -339,8 +334,8 @@ define(function () {
|
||||||
* 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() {
|
exports.getSelectionOffset = function getSelectionOffset() {
|
||||||
var range = util.getSelection();
|
var range = exports.getSelection();
|
||||||
|
|
||||||
if (range && 'startOffset' in range && 'endOffset' in range &&
|
if (range && 'startOffset' in range && 'endOffset' in range &&
|
||||||
range.startContainer && (range.startContainer == range.endContainer)) {
|
range.startContainer && (range.startContainer == range.endContainer)) {
|
||||||
|
@ -352,16 +347,16 @@ define(function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
exports.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) {
|
||||||
|
@ -371,18 +366,18 @@ define(function () {
|
||||||
range.setStart(params.container.firstChild, params.startOffset);
|
range.setStart(params.container.firstChild, params.startOffset);
|
||||||
range.setEnd(params.container.firstChild, params.endOffset);
|
range.setEnd(params.container.firstChild, params.endOffset);
|
||||||
|
|
||||||
util.setSelection(range);
|
exports.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) {
|
exports.getInnerText = function getInnerText(element, buffer) {
|
||||||
var first = (buffer == undefined);
|
var first = (buffer == undefined);
|
||||||
if (first) {
|
if (first) {
|
||||||
buffer = {
|
buffer = {
|
||||||
|
@ -418,7 +413,7 @@ define(function () {
|
||||||
innerText += '\n';
|
innerText += '\n';
|
||||||
buffer.flush();
|
buffer.flush();
|
||||||
}
|
}
|
||||||
innerText += util.getInnerText(child, buffer);
|
innerText += exports.getInnerText(child, buffer);
|
||||||
buffer.set('\n');
|
buffer.set('\n');
|
||||||
}
|
}
|
||||||
else if (child.nodeName == 'BR') {
|
else if (child.nodeName == 'BR') {
|
||||||
|
@ -426,14 +421,14 @@ define(function () {
|
||||||
buffer.set('\n');
|
buffer.set('\n');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
innerText += util.getInnerText(child, buffer);
|
innerText += exports.getInnerText(child, buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return innerText;
|
return innerText;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (element.nodeName == 'P' && util.getInternetExplorerVersion() != -1) {
|
if (element.nodeName == 'P' && exports.getInternetExplorerVersion() != -1) {
|
||||||
// On Internet Explorer, a <p> with hasChildNodes()==false is
|
// On Internet Explorer, a <p> with hasChildNodes()==false is
|
||||||
// rendered with a new line. Note that a <p> with
|
// rendered with a new line. Note that a <p> with
|
||||||
// hasChildNodes()==true is rendered without a new line
|
// hasChildNodes()==true is rendered without a new line
|
||||||
|
@ -445,15 +440,15 @@ define(function () {
|
||||||
|
|
||||||
// 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() {
|
exports.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')
|
||||||
|
@ -469,24 +464,24 @@ define(function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 () {
|
exports.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",
|
||||||
|
@ -495,12 +490,12 @@ define(function () {
|
||||||
* @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) {
|
exports.addEventListener = function addEventListener(element, action, listener, useCapture) {
|
||||||
if (element.addEventListener) {
|
if (element.addEventListener) {
|
||||||
if (useCapture === undefined)
|
if (useCapture === undefined)
|
||||||
useCapture = false;
|
useCapture = false;
|
||||||
|
|
||||||
if (action === "mousewheel" && util.isFirefox()) {
|
if (action === "mousewheel" && exports.isFirefox()) {
|
||||||
action = "DOMMouseScroll"; // For Firefox
|
action = "DOMMouseScroll"; // For Firefox
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,21 +509,21 @@ define(function () {
|
||||||
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) {
|
exports.removeEventListener = function removeEventListener(element, action, listener, useCapture) {
|
||||||
if (element.removeEventListener) {
|
if (element.removeEventListener) {
|
||||||
if (useCapture === undefined)
|
if (useCapture === undefined)
|
||||||
useCapture = false;
|
useCapture = false;
|
||||||
|
|
||||||
if (action === "mousewheel" && util.isFirefox()) {
|
if (action === "mousewheel" && exports.isFirefox()) {
|
||||||
action = "DOMMouseScroll"; // For Firefox
|
action = "DOMMouseScroll"; // For Firefox
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,7 +532,4 @@ define(function () {
|
||||||
// Old IE browsers
|
// Old IE browsers
|
||||||
element.detachEvent("on" + action, listener);
|
element.detachEvent("on" + action, listener);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return util;
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in New Issue