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>
|
||||
* @version 3.2.0
|
||||
* @date 2015-01-25
|
||||
* @date 2015-02-27
|
||||
*/
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
|
@ -82,7 +82,9 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
/* 0 */
|
||||
/***/ 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
|
||||
|
@ -341,14 +343,19 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
JSONEditor.registerMode(treemode);
|
||||
JSONEditor.registerMode(textmode);
|
||||
|
||||
return JSONEditor;
|
||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
||||
module.exports = JSONEditor;
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 1 */
|
||||
/***/ 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
|
||||
var treemode = {};
|
||||
|
@ -1043,7 +1050,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
};
|
||||
|
||||
// define modes
|
||||
return [
|
||||
module.exports = [
|
||||
{
|
||||
mode: 'tree',
|
||||
mixin: treemode,
|
||||
|
@ -1060,14 +1067,13 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
data: 'json'
|
||||
}
|
||||
];
|
||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 2 */
|
||||
/***/ 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
|
||||
var textmode = {};
|
||||
|
@ -1387,7 +1393,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
};
|
||||
|
||||
// define modes
|
||||
return [
|
||||
module.exports = [
|
||||
{
|
||||
mode: 'text',
|
||||
mixin: textmode,
|
||||
|
@ -1401,31 +1407,25 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
load: textmode.format
|
||||
}
|
||||
];
|
||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 3 */
|
||||
/***/ 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.
|
||||
* On exception, the jsonString is validated and a detailed error is thrown.
|
||||
* @param {String} jsonString
|
||||
* @return {JSON} json
|
||||
*/
|
||||
util.parse = function parse(jsonString) {
|
||||
exports.parse = function parse(jsonString) {
|
||||
try {
|
||||
return JSON.parse(jsonString);
|
||||
}
|
||||
catch (err) {
|
||||
// try to throw a more detailed error message using validate
|
||||
util.validate(jsonString);
|
||||
exports.validate(jsonString);
|
||||
|
||||
// rethrow the original error
|
||||
throw err;
|
||||
|
@ -1440,7 +1440,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* @param {string} jsString
|
||||
* @returns {string} json
|
||||
*/
|
||||
util.sanitize = function (jsString) {
|
||||
exports.sanitize = function (jsString) {
|
||||
// escape all single and double quotes inside strings
|
||||
var chars = [];
|
||||
var inString = false;
|
||||
|
@ -1491,7 +1491,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* @param {String} jsonString String with an (invalid) JSON object
|
||||
* @throws Error
|
||||
*/
|
||||
util.validate = function validate(jsonString) {
|
||||
exports.validate = function validate(jsonString) {
|
||||
if (typeof(jsonlint) != 'undefined') {
|
||||
jsonlint.parse(jsonString);
|
||||
}
|
||||
|
@ -1506,7 +1506,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* @param {Object} b
|
||||
* @return {Object} a
|
||||
*/
|
||||
util.extend = function extend(a, b) {
|
||||
exports.extend = function extend(a, b) {
|
||||
for (var prop in b) {
|
||||
if (b.hasOwnProperty(prop)) {
|
||||
a[prop] = b[prop];
|
||||
|
@ -1520,7 +1520,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* @param {Object} a
|
||||
* @return {Object} a
|
||||
*/
|
||||
util.clear = function clear (a) {
|
||||
exports.clear = function clear (a) {
|
||||
for (var prop in a) {
|
||||
if (a.hasOwnProperty(prop)) {
|
||||
delete a[prop];
|
||||
|
@ -1533,7 +1533,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* Output text to the console, if console is available
|
||||
* @param {...*} args
|
||||
*/
|
||||
util.log = function log (args) {
|
||||
exports.log = function log (args) {
|
||||
if (typeof console !== 'undefined' && typeof console.log === 'function') {
|
||||
console.log.apply(console, arguments);
|
||||
}
|
||||
|
@ -1544,7 +1544,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* @param {*} object
|
||||
* @return {String} type
|
||||
*/
|
||||
util.type = function type (object) {
|
||||
exports.type = function type (object) {
|
||||
if (object === null) {
|
||||
return 'null';
|
||||
}
|
||||
|
@ -1563,7 +1563,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
if ((object instanceof RegExp) || (typeof object === 'regexp')) {
|
||||
return 'regexp';
|
||||
}
|
||||
if (util.isArray(object)) {
|
||||
if (exports.isArray(object)) {
|
||||
return 'array';
|
||||
}
|
||||
|
||||
|
@ -1576,7 +1576,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* @param {String} text
|
||||
*/
|
||||
var isUrlRegex = /^https?:\/\/\S+$/;
|
||||
util.isUrl = function isUrl (text) {
|
||||
exports.isUrl = function isUrl (text) {
|
||||
return (typeof text == 'string' || text instanceof String) &&
|
||||
isUrlRegex.test(text);
|
||||
};
|
||||
|
@ -1586,7 +1586,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* @param {*} obj
|
||||
* @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]';
|
||||
};
|
||||
|
||||
|
@ -1596,7 +1596,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* @return {Number} left The absolute left position of this element
|
||||
* in the browser page.
|
||||
*/
|
||||
util.getAbsoluteLeft = function getAbsoluteLeft(elem) {
|
||||
exports.getAbsoluteLeft = function getAbsoluteLeft(elem) {
|
||||
var rect = elem.getBoundingClientRect();
|
||||
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
|
||||
* in the browser page.
|
||||
*/
|
||||
util.getAbsoluteTop = function getAbsoluteTop(elem) {
|
||||
exports.getAbsoluteTop = function getAbsoluteTop(elem) {
|
||||
var rect = elem.getBoundingClientRect();
|
||||
return rect.top + window.pageYOffset || document.scrollTop || 0;
|
||||
};
|
||||
|
@ -1617,7 +1617,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* @param {Element} elem
|
||||
* @param {String} className
|
||||
*/
|
||||
util.addClassName = function addClassName(elem, className) {
|
||||
exports.addClassName = function addClassName(elem, className) {
|
||||
var classes = elem.className.split(' ');
|
||||
if (classes.indexOf(className) == -1) {
|
||||
classes.push(className); // add the class to the array
|
||||
|
@ -1630,7 +1630,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* @param {Element} elem
|
||||
* @param {String} className
|
||||
*/
|
||||
util.removeClassName = function removeClassName(elem, className) {
|
||||
exports.removeClassName = function removeClassName(elem, className) {
|
||||
var classes = elem.className.split(' ');
|
||||
var index = classes.indexOf(className);
|
||||
if (index != -1) {
|
||||
|
@ -1644,7 +1644,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* the formatting from the div itself is not stripped, only from its childs.
|
||||
* @param {Element} divElement
|
||||
*/
|
||||
util.stripFormatting = function stripFormatting(divElement) {
|
||||
exports.stripFormatting = function stripFormatting(divElement) {
|
||||
var childs = divElement.childNodes;
|
||||
for (var i = 0, iMax = childs.length; i < iMax; i++) {
|
||||
var child = childs[i];
|
||||
|
@ -1667,7 +1667,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
}
|
||||
|
||||
// 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
|
||||
* @param {Element} contentEditableElement A content editable div
|
||||
*/
|
||||
util.setEndOfContentEditable = function setEndOfContentEditable(contentEditableElement) {
|
||||
exports.setEndOfContentEditable = function setEndOfContentEditable(contentEditableElement) {
|
||||
var range, selection;
|
||||
if(document.createRange) {
|
||||
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
|
||||
* @param {Element} contentEditableElement A content editable div
|
||||
*/
|
||||
util.selectContentEditable = function selectContentEditable(contentEditableElement) {
|
||||
exports.selectContentEditable = function selectContentEditable(contentEditableElement) {
|
||||
if (!contentEditableElement || contentEditableElement.nodeName != 'DIV') {
|
||||
return;
|
||||
}
|
||||
|
@ -1715,7 +1715,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* http://stackoverflow.com/questions/4687808/contenteditable-selected-text-save-and-restore
|
||||
* @return {Range | TextRange | null} range
|
||||
*/
|
||||
util.getSelection = function getSelection() {
|
||||
exports.getSelection = function getSelection() {
|
||||
if (window.getSelection) {
|
||||
var sel = window.getSelection();
|
||||
if (sel.getRangeAt && sel.rangeCount) {
|
||||
|
@ -1730,7 +1730,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* http://stackoverflow.com/questions/4687808/contenteditable-selected-text-save-and-restore
|
||||
* @param {Range | TextRange | null} range
|
||||
*/
|
||||
util.setSelection = function setSelection(range) {
|
||||
exports.setSelection = function setSelection(range) {
|
||||
if (range) {
|
||||
if (window.getSelection) {
|
||||
var sel = window.getSelection();
|
||||
|
@ -1749,8 +1749,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* selected text element
|
||||
* Returns null if no text selection is found
|
||||
*/
|
||||
util.getSelectionOffset = function getSelectionOffset() {
|
||||
var range = util.getSelection();
|
||||
exports.getSelectionOffset = function getSelectionOffset() {
|
||||
var range = exports.getSelection();
|
||||
|
||||
if (range && 'startOffset' in range && 'endOffset' in range &&
|
||||
range.startContainer && (range.startContainer == range.endContainer)) {
|
||||
|
@ -1771,7 +1771,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* {Number} startOffset
|
||||
* {Number} endOffset
|
||||
*/
|
||||
util.setSelectionOffset = function setSelectionOffset(params) {
|
||||
exports.setSelectionOffset = function setSelectionOffset(params) {
|
||||
if (document.createRange && window.getSelection) {
|
||||
var selection = window.getSelection();
|
||||
if(selection) {
|
||||
|
@ -1781,7 +1781,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
range.setStart(params.container.firstChild, params.startOffset);
|
||||
range.setEnd(params.container.firstChild, params.endOffset);
|
||||
|
||||
util.setSelection(range);
|
||||
exports.setSelection(range);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1792,7 +1792,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* @param {Object} [buffer]
|
||||
* @return {String} innerText
|
||||
*/
|
||||
util.getInnerText = function getInnerText(element, buffer) {
|
||||
exports.getInnerText = function getInnerText(element, buffer) {
|
||||
var first = (buffer == undefined);
|
||||
if (first) {
|
||||
buffer = {
|
||||
|
@ -1828,7 +1828,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
innerText += '\n';
|
||||
buffer.flush();
|
||||
}
|
||||
innerText += util.getInnerText(child, buffer);
|
||||
innerText += exports.getInnerText(child, buffer);
|
||||
buffer.set('\n');
|
||||
}
|
||||
else if (child.nodeName == 'BR') {
|
||||
|
@ -1836,14 +1836,14 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
buffer.set('\n');
|
||||
}
|
||||
else {
|
||||
innerText += util.getInnerText(child, buffer);
|
||||
innerText += exports.getInnerText(child, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
return innerText;
|
||||
}
|
||||
else {
|
||||
if (element.nodeName == 'P' && util.getInternetExplorerVersion() != -1) {
|
||||
if (element.nodeName == 'P' && exports.getInternetExplorerVersion() != -1) {
|
||||
// On Internet Explorer, a <p> with hasChildNodes()==false is
|
||||
// rendered with a new line. Note that a <p> with
|
||||
// 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
|
||||
* @return {Number} Internet Explorer version, or -1 in case of an other browser
|
||||
*/
|
||||
util.getInternetExplorerVersion = function getInternetExplorerVersion() {
|
||||
exports.getInternetExplorerVersion = function getInternetExplorerVersion() {
|
||||
if (_ieVersion == -1) {
|
||||
var rv = -1; // Return value assumes failure.
|
||||
if (navigator.appName == 'Microsoft Internet Explorer')
|
||||
|
@ -1885,7 +1885,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* Test whether the current browser is Firefox
|
||||
* @returns {boolean} isFirefox
|
||||
*/
|
||||
util.isFirefox = function isFirefox () {
|
||||
exports.isFirefox = function isFirefox () {
|
||||
return (navigator.userAgent.indexOf("Firefox") != -1);
|
||||
};
|
||||
|
||||
|
@ -1905,12 +1905,12 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* @param {boolean} [useCapture] false by default
|
||||
* @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 (useCapture === undefined)
|
||||
useCapture = false;
|
||||
|
||||
if (action === "mousewheel" && util.isFirefox()) {
|
||||
if (action === "mousewheel" && exports.isFirefox()) {
|
||||
action = "DOMMouseScroll"; // For Firefox
|
||||
}
|
||||
|
||||
|
@ -1933,12 +1933,12 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
* @param {function} listener The listener function
|
||||
* @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 (useCapture === undefined)
|
||||
useCapture = false;
|
||||
|
||||
if (action === "mousewheel" && util.isFirefox()) {
|
||||
if (action === "mousewheel" && exports.isFirefox()) {
|
||||
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 */
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function () {
|
||||
|
||||
/**
|
||||
* The highlighter can highlight/unhighlight a node, and
|
||||
* animate the visibility of a context menu.
|
||||
|
@ -2041,14 +2037,14 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
this.locked = false;
|
||||
};
|
||||
|
||||
return Highlighter;
|
||||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
||||
module.exports = Highlighter;
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 5 */
|
||||
/***/ 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
|
||||
|
@ -2269,16 +2265,13 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
}
|
||||
};
|
||||
|
||||
return History;
|
||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
||||
module.exports = History;
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 6 */
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function () {
|
||||
|
||||
/**
|
||||
* @constructor SearchBox
|
||||
* Create a search box in given HTML container
|
||||
|
@ -2566,17 +2559,16 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
}
|
||||
};
|
||||
|
||||
return SearchBox;
|
||||
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
||||
|
||||
|
||||
module.exports = SearchBox;
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 7 */
|
||||
/***/ 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
|
||||
|
@ -5502,14 +5494,14 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
// TODO: find a nicer solution to resolve this circular dependency between Node and AppendNode
|
||||
var AppendNode = appendNodeFactory(Node);
|
||||
|
||||
return Node;
|
||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
||||
module.exports = Node;
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 8 */
|
||||
/***/ 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
|
||||
|
@ -5608,17 +5600,14 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
return box;
|
||||
}
|
||||
|
||||
return {
|
||||
create: createModeSwitcher
|
||||
}
|
||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
||||
exports.create = createModeSwitcher;
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 9 */
|
||||
/***/ 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
|
||||
|
@ -6060,15 +6049,15 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
return false;
|
||||
};
|
||||
|
||||
return ContextMenu;
|
||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
||||
module.exports = ContextMenu;
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 10 */
|
||||
/***/ 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
|
||||
|
@ -6292,9 +6281,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
return AppendNode;
|
||||
}
|
||||
|
||||
// return the factory function
|
||||
return appendNodeFactory;
|
||||
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
||||
module.exports = appendNodeFactory;
|
||||
|
||||
|
||||
/***/ }
|
||||
|
|
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
|
||||
* @param {Object[]} items Array containing the menu structure
|
||||
* TODO: describe structure
|
||||
|
@ -9,7 +9,7 @@ define(['./util'], function (util) {
|
|||
* context menu is being closed.
|
||||
* @constructor
|
||||
*/
|
||||
function ContextMenu (items, options) {
|
||||
function ContextMenu (items, options) {
|
||||
this.dom = {};
|
||||
|
||||
var me = this;
|
||||
|
@ -142,14 +142,14 @@ define(['./util'], function (util) {
|
|||
var height = (items.length + (item.submenu ? item.submenu.length : 0)) * 24;
|
||||
me.maxHeight = Math.max(me.maxHeight, height);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get the currently visible buttons
|
||||
* @return {Array.<HTMLElement>} buttons
|
||||
* @private
|
||||
*/
|
||||
ContextMenu.prototype._getVisibleButtons = function () {
|
||||
ContextMenu.prototype._getVisibleButtons = function () {
|
||||
var buttons = [];
|
||||
var me = this;
|
||||
this.dom.items.forEach(function (item) {
|
||||
|
@ -169,16 +169,16 @@ define(['./util'], function (util) {
|
|||
});
|
||||
|
||||
return buttons;
|
||||
};
|
||||
};
|
||||
|
||||
// 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
|
||||
* @param {HTMLElement} anchor
|
||||
*/
|
||||
ContextMenu.prototype.show = function (anchor) {
|
||||
ContextMenu.prototype.show = function (anchor) {
|
||||
this.hide();
|
||||
|
||||
// calculate whether the menu fits below the anchor
|
||||
|
@ -242,12 +242,12 @@ define(['./util'], function (util) {
|
|||
ContextMenu.visibleMenu.hide();
|
||||
}
|
||||
ContextMenu.visibleMenu = this;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Hide the context menu if visible
|
||||
*/
|
||||
ContextMenu.prototype.hide = function () {
|
||||
ContextMenu.prototype.hide = function () {
|
||||
// remove the menu from the DOM
|
||||
if (this.dom.menu.parentNode) {
|
||||
this.dom.menu.parentNode.removeChild(this.dom.menu);
|
||||
|
@ -271,15 +271,15 @@ define(['./util'], function (util) {
|
|||
if (ContextMenu.visibleMenu == this) {
|
||||
ContextMenu.visibleMenu = undefined;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Expand a submenu
|
||||
* Any currently expanded submenu will be hided.
|
||||
* @param {Object} domItem
|
||||
* @private
|
||||
*/
|
||||
ContextMenu.prototype._onExpandItem = function (domItem) {
|
||||
ContextMenu.prototype._onExpandItem = function (domItem) {
|
||||
var me = this;
|
||||
var alreadyVisible = (domItem == this.expandedItem);
|
||||
|
||||
|
@ -311,14 +311,14 @@ define(['./util'], function (util) {
|
|||
util.addClassName(ul.parentNode, 'selected');
|
||||
this.expandedItem = domItem;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Handle onkeydown event
|
||||
* @param {Event} event
|
||||
* @private
|
||||
*/
|
||||
ContextMenu.prototype._onKeyDown = function (event) {
|
||||
ContextMenu.prototype._onKeyDown = function (event) {
|
||||
var target = event.target;
|
||||
var keynum = event.which;
|
||||
var handled = false;
|
||||
|
@ -420,15 +420,15 @@ define(['./util'], function (util) {
|
|||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test if an element is a child of a parent element.
|
||||
* @param {Element} child
|
||||
* @param {Element} parent
|
||||
* @return {boolean} isChild
|
||||
*/
|
||||
ContextMenu.prototype._isChildOf = function (child, parent) {
|
||||
ContextMenu.prototype._isChildOf = function (child, parent) {
|
||||
var e = child.parentNode;
|
||||
while (e) {
|
||||
if (e == parent) {
|
||||
|
@ -438,7 +438,6 @@ define(['./util'], function (util) {
|
|||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
return ContextMenu;
|
||||
});
|
||||
module.exports = ContextMenu;
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
define(function () {
|
||||
|
||||
/**
|
||||
/**
|
||||
* The highlighter can highlight/unhighlight a node, and
|
||||
* animate the visibility of a context menu.
|
||||
* @constructor Highlighter
|
||||
*/
|
||||
function Highlighter () {
|
||||
function Highlighter () {
|
||||
this.locked = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Hightlight given node and its childs
|
||||
* @param {Node} node
|
||||
*/
|
||||
Highlighter.prototype.highlight = function (node) {
|
||||
Highlighter.prototype.highlight = function (node) {
|
||||
if (this.locked) {
|
||||
return;
|
||||
}
|
||||
|
@ -31,13 +29,13 @@ define(function () {
|
|||
|
||||
// cancel any current timeout
|
||||
this._cancelUnhighlight();
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Unhighlight currently highlighted node.
|
||||
* Will be done after a delay
|
||||
*/
|
||||
Highlighter.prototype.unhighlight = function () {
|
||||
Highlighter.prototype.unhighlight = function () {
|
||||
if (this.locked) {
|
||||
return;
|
||||
}
|
||||
|
@ -55,33 +53,32 @@ define(function () {
|
|||
me.unhighlightTimer = undefined;
|
||||
}, 0);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Cancel an unhighlight action (if before the timeout of the unhighlight action)
|
||||
* @private
|
||||
*/
|
||||
Highlighter.prototype._cancelUnhighlight = function () {
|
||||
Highlighter.prototype._cancelUnhighlight = function () {
|
||||
if (this.unhighlightTimer) {
|
||||
clearTimeout(this.unhighlightTimer);
|
||||
this.unhighlightTimer = undefined;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Lock highlighting or unhighlighting nodes.
|
||||
* methods highlight and unhighlight do not work while locked.
|
||||
*/
|
||||
Highlighter.prototype.lock = function () {
|
||||
Highlighter.prototype.lock = function () {
|
||||
this.locked = true;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Unlock highlighting or unhighlighting nodes
|
||||
*/
|
||||
Highlighter.prototype.unlock = function () {
|
||||
Highlighter.prototype.unlock = function () {
|
||||
this.locked = false;
|
||||
};
|
||||
};
|
||||
|
||||
return Highlighter;
|
||||
});
|
||||
module.exports = Highlighter;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
define(['./util'], function (util) {
|
||||
var util = require('./util');
|
||||
|
||||
/**
|
||||
/**
|
||||
* @constructor History
|
||||
* Store action history, enables undo and redo
|
||||
* @param {JSONEditor} editor
|
||||
*/
|
||||
function History (editor) {
|
||||
function History (editor) {
|
||||
this.editor = editor;
|
||||
this.clear();
|
||||
|
||||
|
@ -105,15 +105,15 @@ define(['./util'], function (util) {
|
|||
// TODO: restore the original caret position and selection with each undo
|
||||
// TODO: implement history for actions "expand", "collapse", "scroll", "setDocument"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* The method onChange is executed when the History is changed, and can
|
||||
* be overloaded.
|
||||
*/
|
||||
History.prototype.onChange = function () {};
|
||||
History.prototype.onChange = function () {};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add a new action to the history
|
||||
* @param {String} action The executed action. Available actions: "editField",
|
||||
* "editValue", "changeType", "appendNode",
|
||||
|
@ -124,7 +124,7 @@ define(['./util'], function (util) {
|
|||
* value are provided). params contains all information
|
||||
* needed to undo or redo the action.
|
||||
*/
|
||||
History.prototype.add = function (action, params) {
|
||||
History.prototype.add = function (action, params) {
|
||||
this.index++;
|
||||
this.history[this.index] = {
|
||||
'action': action,
|
||||
|
@ -139,39 +139,39 @@ define(['./util'], function (util) {
|
|||
|
||||
// fire onchange event
|
||||
this.onChange();
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Clear history
|
||||
*/
|
||||
History.prototype.clear = function () {
|
||||
History.prototype.clear = function () {
|
||||
this.history = [];
|
||||
this.index = -1;
|
||||
|
||||
// fire onchange event
|
||||
this.onChange();
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Check if there is an action available for undo
|
||||
* @return {Boolean} canUndo
|
||||
*/
|
||||
History.prototype.canUndo = function () {
|
||||
History.prototype.canUndo = function () {
|
||||
return (this.index >= 0);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Check if there is an action available for redo
|
||||
* @return {Boolean} canRedo
|
||||
*/
|
||||
History.prototype.canRedo = function () {
|
||||
History.prototype.canRedo = function () {
|
||||
return (this.index < this.history.length - 1);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Undo the last action
|
||||
*/
|
||||
History.prototype.undo = function () {
|
||||
History.prototype.undo = function () {
|
||||
if (this.canUndo()) {
|
||||
var obj = this.history[this.index];
|
||||
if (obj) {
|
||||
|
@ -191,12 +191,12 @@ define(['./util'], function (util) {
|
|||
// fire onchange event
|
||||
this.onChange();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Redo the last action
|
||||
*/
|
||||
History.prototype.redo = function () {
|
||||
History.prototype.redo = function () {
|
||||
if (this.canRedo()) {
|
||||
this.index++;
|
||||
|
||||
|
@ -217,7 +217,6 @@ define(['./util'], function (util) {
|
|||
// fire onchange event
|
||||
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
|
||||
* @param {Element} container Container element
|
||||
* @param {Object} [options] Object with options. available options:
|
||||
|
@ -26,7 +28,7 @@ define(['./treemode', './textmode', './util'], function (treemode, textmode, uti
|
|||
* modes 'text' and 'code'
|
||||
* @param {Object | undefined} json JSON object
|
||||
*/
|
||||
function JSONEditor (container, options, json) {
|
||||
function JSONEditor (container, options, json) {
|
||||
if (!(this instanceof JSONEditor)) {
|
||||
throw new Error('JSONEditor constructor called without "new".');
|
||||
}
|
||||
|
@ -41,9 +43,9 @@ define(['./treemode', './textmode', './util'], function (treemode, textmode, uti
|
|||
if (arguments.length) {
|
||||
this._create(container, options, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Configuration for all registered modes. Example:
|
||||
* {
|
||||
* tree: {
|
||||
|
@ -58,88 +60,88 @@ define(['./treemode', './textmode', './util'], function (treemode, textmode, uti
|
|||
*
|
||||
* @type { Object.<String, {mixin: Object, data: String} > }
|
||||
*/
|
||||
JSONEditor.modes = {};
|
||||
JSONEditor.modes = {};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create the JSONEditor
|
||||
* @param {Element} container Container element
|
||||
* @param {Object} [options] See description in constructor
|
||||
* @param {Object | undefined} json JSON object
|
||||
* @private
|
||||
*/
|
||||
JSONEditor.prototype._create = function (container, options, json) {
|
||||
JSONEditor.prototype._create = function (container, options, json) {
|
||||
this.container = container;
|
||||
this.options = options || {};
|
||||
this.json = json || {};
|
||||
|
||||
var mode = this.options.mode || 'tree';
|
||||
this.setMode(mode);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Detach the editor from the DOM
|
||||
* @private
|
||||
*/
|
||||
JSONEditor.prototype._delete = function () {};
|
||||
JSONEditor.prototype._delete = function () {};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set JSON object in editor
|
||||
* @param {Object | undefined} json JSON data
|
||||
*/
|
||||
JSONEditor.prototype.set = function (json) {
|
||||
JSONEditor.prototype.set = function (json) {
|
||||
this.json = json;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get JSON from the editor
|
||||
* @returns {Object} json
|
||||
*/
|
||||
JSONEditor.prototype.get = function () {
|
||||
JSONEditor.prototype.get = function () {
|
||||
return this.json;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set string containing JSON for the editor
|
||||
* @param {String | undefined} jsonText
|
||||
*/
|
||||
JSONEditor.prototype.setText = function (jsonText) {
|
||||
JSONEditor.prototype.setText = function (jsonText) {
|
||||
this.json = util.parse(jsonText);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get stringified JSON contents from the editor
|
||||
* @returns {String} jsonText
|
||||
*/
|
||||
JSONEditor.prototype.getText = function () {
|
||||
JSONEditor.prototype.getText = function () {
|
||||
return JSON.stringify(this.json);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set a field name for the root node.
|
||||
* @param {String | undefined} name
|
||||
*/
|
||||
JSONEditor.prototype.setName = function (name) {
|
||||
JSONEditor.prototype.setName = function (name) {
|
||||
if (!this.options) {
|
||||
this.options = {};
|
||||
}
|
||||
this.options.name = name;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get the field name for the root node.
|
||||
* @return {String | undefined} name
|
||||
*/
|
||||
JSONEditor.prototype.getName = function () {
|
||||
JSONEditor.prototype.getName = function () {
|
||||
return this.options && this.options.name;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Change the mode of the editor.
|
||||
* JSONEditor will be extended with all methods needed for the chosen mode.
|
||||
* @param {String} mode Available modes: 'tree' (default), 'view', 'form',
|
||||
* 'text', and 'code'.
|
||||
*/
|
||||
JSONEditor.prototype.setMode = function (mode) {
|
||||
JSONEditor.prototype.setMode = function (mode) {
|
||||
var container = this.container,
|
||||
options = util.extend({}, this.options),
|
||||
data,
|
||||
|
@ -175,15 +177,15 @@ define(['./treemode', './textmode', './util'], function (treemode, textmode, uti
|
|||
else {
|
||||
throw new Error('Unknown mode "' + options.mode + '"');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Throw an error. If an error callback is configured in options.error, this
|
||||
* callback will be invoked. Else, a regular error is thrown.
|
||||
* @param {Error} err
|
||||
* @private
|
||||
*/
|
||||
JSONEditor.prototype._onError = function(err) {
|
||||
JSONEditor.prototype._onError = function(err) {
|
||||
// TODO: onError is deprecated since version 2.2.0. cleanup some day
|
||||
if (typeof this.onError === 'function') {
|
||||
util.log('WARNING: JSONEditor.onError is deprecated. ' +
|
||||
|
@ -197,9 +199,9 @@ define(['./treemode', './textmode', './util'], function (treemode, textmode, uti
|
|||
else {
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Register a plugin with one ore multiple modes for the JSON Editor.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
JSONEditor.registerMode = function (mode) {
|
||||
JSONEditor.registerMode = function (mode) {
|
||||
var i, prop;
|
||||
|
||||
if (util.isArray(mode)) {
|
||||
|
@ -251,11 +253,10 @@ define(['./treemode', './textmode', './util'], function (treemode, textmode, uti
|
|||
|
||||
JSONEditor.modes[name] = mode;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// register tree and text modes
|
||||
JSONEditor.registerMode(treemode);
|
||||
JSONEditor.registerMode(textmode);
|
||||
// register tree and text modes
|
||||
JSONEditor.registerMode(treemode);
|
||||
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
|
||||
* Create a search box in given HTML container
|
||||
* @param {JSONEditor} editor The JSON Editor to attach to
|
||||
* @param {Element} container HTML container element of where to
|
||||
* create the search box
|
||||
*/
|
||||
function SearchBox (editor, container) {
|
||||
function SearchBox (editor, container) {
|
||||
var searchBox = this;
|
||||
|
||||
this.editor = editor;
|
||||
|
@ -99,14 +97,14 @@ define(function () {
|
|||
td = document.createElement('td');
|
||||
td.appendChild(searchPrevious);
|
||||
tr.appendChild(td);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Go to the next search result
|
||||
* @param {boolean} [focus] If true, focus will be set to the next result
|
||||
* focus is false by default.
|
||||
*/
|
||||
SearchBox.prototype.next = function(focus) {
|
||||
SearchBox.prototype.next = function(focus) {
|
||||
if (this.results != undefined) {
|
||||
var index = (this.resultIndex != undefined) ? this.resultIndex + 1 : 0;
|
||||
if (index > this.results.length - 1) {
|
||||
|
@ -114,14 +112,14 @@ define(function () {
|
|||
}
|
||||
this._setActiveResult(index, focus);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Go to the prevous search result
|
||||
* @param {boolean} [focus] If true, focus will be set to the next result
|
||||
* focus is false by default.
|
||||
*/
|
||||
SearchBox.prototype.previous = function(focus) {
|
||||
SearchBox.prototype.previous = function(focus) {
|
||||
if (this.results != undefined) {
|
||||
var max = this.results.length - 1;
|
||||
var index = (this.resultIndex != undefined) ? this.resultIndex - 1 : max;
|
||||
|
@ -130,16 +128,16 @@ define(function () {
|
|||
}
|
||||
this._setActiveResult(index, focus);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set new value for the current active result
|
||||
* @param {Number} index
|
||||
* @param {boolean} [focus] If true, focus will be set to the next result.
|
||||
* focus is false by default.
|
||||
* @private
|
||||
*/
|
||||
SearchBox.prototype._setActiveResult = function(index, focus) {
|
||||
SearchBox.prototype._setActiveResult = function(index, focus) {
|
||||
// de-activate current active result
|
||||
if (this.activeResult) {
|
||||
var prevNode = this.activeResult.node;
|
||||
|
@ -180,26 +178,26 @@ define(function () {
|
|||
node.focus(elem);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Cancel any running onDelayedSearch.
|
||||
* @private
|
||||
*/
|
||||
SearchBox.prototype._clearDelay = function() {
|
||||
SearchBox.prototype._clearDelay = function() {
|
||||
if (this.timeout != undefined) {
|
||||
clearTimeout(this.timeout);
|
||||
delete this.timeout;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Start a timer to execute a search after a short delay.
|
||||
* Used for reducing the number of searches while typing.
|
||||
* @param {Event} event
|
||||
* @private
|
||||
*/
|
||||
SearchBox.prototype._onDelayedSearch = function (event) {
|
||||
SearchBox.prototype._onDelayedSearch = function (event) {
|
||||
// execute the search after a short delay (reduces the number of
|
||||
// search actions while typing in the search text box)
|
||||
this._clearDelay();
|
||||
|
@ -208,9 +206,9 @@ define(function () {
|
|||
searchBox._onSearch(event);
|
||||
},
|
||||
this.delay);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Handle onSearch event
|
||||
* @param {Event} event
|
||||
* @param {boolean} [forceSearch] If true, search will be executed again even
|
||||
|
@ -218,7 +216,7 @@ define(function () {
|
|||
* Default is false.
|
||||
* @private
|
||||
*/
|
||||
SearchBox.prototype._onSearch = function (event, forceSearch) {
|
||||
SearchBox.prototype._onSearch = function (event, forceSearch) {
|
||||
this._clearDelay();
|
||||
|
||||
var value = this.dom.search.value;
|
||||
|
@ -242,14 +240,14 @@ define(function () {
|
|||
this.dom.results.innerHTML = '';
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Handle onKeyDown event in the input box
|
||||
* @param {Event} event
|
||||
* @private
|
||||
*/
|
||||
SearchBox.prototype._onKeyDown = function (event) {
|
||||
SearchBox.prototype._onKeyDown = function (event) {
|
||||
var keynum = event.which;
|
||||
if (keynum == 27) { // ESC
|
||||
this.dom.search.value = ''; // clear search
|
||||
|
@ -273,21 +271,18 @@ define(function () {
|
|||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Handle onKeyUp event in the input box
|
||||
* @param {Event} event
|
||||
* @private
|
||||
*/
|
||||
SearchBox.prototype._onKeyUp = function (event) {
|
||||
SearchBox.prototype._onKeyUp = function (event) {
|
||||
var keynum = event.keyCode;
|
||||
if (keynum != 27 && keynum != 13) { // !show and !Enter
|
||||
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
|
||||
* @param {Node} Node
|
||||
*/
|
||||
function appendNodeFactory(Node) {
|
||||
function appendNodeFactory(Node) {
|
||||
/**
|
||||
* @constructor AppendNode
|
||||
* @extends Node
|
||||
|
@ -220,8 +221,6 @@ define(['./ContextMenu', './util'], function (ContextMenu, util) {
|
|||
};
|
||||
|
||||
return AppendNode;
|
||||
}
|
||||
}
|
||||
|
||||
// return the factory function
|
||||
return appendNodeFactory;
|
||||
});
|
||||
module.exports = 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
|
||||
* @param {Object} editor
|
||||
* @param {String[]} modes Available modes: 'code', 'form', 'text', 'tree', 'view'
|
||||
* @param {String} current Available modes: 'code', 'form', 'text', 'tree', 'view'
|
||||
* @returns {HTMLElement} box
|
||||
*/
|
||||
function createModeSwitcher(editor, modes, current) {
|
||||
function createModeSwitcher(editor, modes, current) {
|
||||
// TODO: decouple mode switcher from editor
|
||||
|
||||
/**
|
||||
|
@ -95,9 +95,6 @@ define(['./ContextMenu'], function (ContextMenu) {
|
|||
};
|
||||
|
||||
return box;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
create: createModeSwitcher
|
||||
}
|
||||
});
|
||||
exports.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
|
||||
var textmode = {};
|
||||
// create a mixin with the functions for text mode
|
||||
var textmode = {};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create a text editor
|
||||
* @param {Element} container
|
||||
* @param {Object} [options] Object with options. available options:
|
||||
|
@ -16,7 +17,7 @@ define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
|||
* triggered on change
|
||||
* @private
|
||||
*/
|
||||
textmode.create = function (container, options) {
|
||||
textmode.create = function (container, options) {
|
||||
// read options
|
||||
options = options || {};
|
||||
this.options = options;
|
||||
|
@ -160,14 +161,14 @@ define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
|||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Event handler for keydown. Handles shortcut keys
|
||||
* @param {Event} event
|
||||
* @private
|
||||
*/
|
||||
textmode._onKeyDown = function (event) {
|
||||
textmode._onKeyDown = function (event) {
|
||||
var keynum = event.which || event.keyCode;
|
||||
var handled = false;
|
||||
|
||||
|
@ -185,25 +186,25 @@ define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
|||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Detach the editor from the DOM
|
||||
* @private
|
||||
*/
|
||||
textmode._delete = function () {
|
||||
textmode._delete = function () {
|
||||
if (this.frame && this.container && this.frame.parentNode == this.container) {
|
||||
this.container.removeChild(this.frame);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Throw an error. If an error callback is configured in options.error, this
|
||||
* callback will be invoked. Else, a regular error is thrown.
|
||||
* @param {Error} err
|
||||
* @private
|
||||
*/
|
||||
textmode._onError = function(err) {
|
||||
textmode._onError = function(err) {
|
||||
// TODO: onError is deprecated since version 2.2.0. cleanup some day
|
||||
if (typeof this.onError === 'function') {
|
||||
util.log('WARNING: JSONEditor.onError is deprecated. ' +
|
||||
|
@ -217,61 +218,61 @@ define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
|||
else {
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Compact the code in the formatter
|
||||
*/
|
||||
textmode.compact = function () {
|
||||
textmode.compact = function () {
|
||||
var json = this.get();
|
||||
var text = JSON.stringify(json);
|
||||
this.setText(text);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Format the code in the formatter
|
||||
*/
|
||||
textmode.format = function () {
|
||||
textmode.format = function () {
|
||||
var json = this.get();
|
||||
var text = JSON.stringify(json, null, this.indentation);
|
||||
this.setText(text);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set focus to the formatter
|
||||
*/
|
||||
textmode.focus = function () {
|
||||
textmode.focus = function () {
|
||||
if (this.textarea) {
|
||||
this.textarea.focus();
|
||||
}
|
||||
if (this.editor) {
|
||||
this.editor.focus();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Resize the formatter
|
||||
*/
|
||||
textmode.resize = function () {
|
||||
textmode.resize = function () {
|
||||
if (this.editor) {
|
||||
var force = false;
|
||||
this.editor.resize(force);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set json data in the formatter
|
||||
* @param {Object} json
|
||||
*/
|
||||
textmode.set = function(json) {
|
||||
textmode.set = function(json) {
|
||||
this.setText(JSON.stringify(json, null, this.indentation));
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get json data from the formatter
|
||||
* @return {Object} json
|
||||
*/
|
||||
textmode.get = function() {
|
||||
textmode.get = function() {
|
||||
var text = this.getText();
|
||||
var json;
|
||||
|
||||
|
@ -288,13 +289,13 @@ define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
|||
}
|
||||
|
||||
return json;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get the text contents of the editor
|
||||
* @return {String} jsonText
|
||||
*/
|
||||
textmode.getText = function() {
|
||||
textmode.getText = function() {
|
||||
if (this.textarea) {
|
||||
return this.textarea.value;
|
||||
}
|
||||
|
@ -302,23 +303,23 @@ define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
|||
return this.editor.getValue();
|
||||
}
|
||||
return '';
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set the text contents of the editor
|
||||
* @param {String} jsonText
|
||||
*/
|
||||
textmode.setText = function(jsonText) {
|
||||
textmode.setText = function(jsonText) {
|
||||
if (this.textarea) {
|
||||
this.textarea.value = jsonText;
|
||||
}
|
||||
if (this.editor) {
|
||||
this.editor.setValue(jsonText, -1);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// define modes
|
||||
return [
|
||||
// define modes
|
||||
module.exports = [
|
||||
{
|
||||
mode: 'text',
|
||||
mixin: textmode,
|
||||
|
@ -331,5 +332,4 @@ define(['./modeswitcher', './util'], function (modeswitcher, util) {
|
|||
data: 'text',
|
||||
load: textmode.format
|
||||
}
|
||||
];
|
||||
});
|
||||
];
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher', './util'],
|
||||
function (Highlighter, History, SearchBox, Node, modeswitcher, util) {
|
||||
var Highlighter = require('./Highlighter');
|
||||
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
|
||||
var treemode = {};
|
||||
// create a mixin with the functions for tree mode
|
||||
var treemode = {};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create a tree editor
|
||||
* @param {Element} container Container element
|
||||
* @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.
|
||||
* @private
|
||||
*/
|
||||
treemode.create = function (container, options) {
|
||||
treemode.create = function (container, options) {
|
||||
if (!container) {
|
||||
throw new Error('No container element provided.');
|
||||
}
|
||||
|
@ -37,24 +41,24 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
|
||||
this._createFrame();
|
||||
this._createTable();
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Detach the editor from the DOM
|
||||
* @private
|
||||
*/
|
||||
treemode._delete = function () {
|
||||
treemode._delete = function () {
|
||||
if (this.frame && this.container && this.frame.parentNode == this.container) {
|
||||
this.container.removeChild(this.frame);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Initialize and set default options
|
||||
* @param {Object} [options] See description in constructor
|
||||
* @private
|
||||
*/
|
||||
treemode._setOptions = function (options) {
|
||||
treemode._setOptions = function (options) {
|
||||
this.options = {
|
||||
search: true,
|
||||
history: true,
|
||||
|
@ -70,21 +74,21 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// node currently being edited
|
||||
var focusNode = undefined;
|
||||
// node currently being edited
|
||||
var focusNode = undefined;
|
||||
|
||||
// dom having focus
|
||||
var domFocus = null;
|
||||
// dom having focus
|
||||
var domFocus = null;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set JSON object in editor
|
||||
* @param {Object | undefined} json JSON data
|
||||
* @param {String} [name] Optional field name for the root node.
|
||||
* Can also be set using setName(name).
|
||||
*/
|
||||
treemode.set = function (json, name) {
|
||||
treemode.set = function (json, name) {
|
||||
// adjust field name for root node
|
||||
if (name) {
|
||||
// TODO: deprecated since version 2.2.0. Cleanup some day.
|
||||
|
@ -119,13 +123,13 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
if (this.history) {
|
||||
this.history.clear();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get JSON object from editor
|
||||
* @return {Object | undefined} json
|
||||
*/
|
||||
treemode.get = function () {
|
||||
treemode.get = function () {
|
||||
// remove focus from currently edited node
|
||||
if (focusNode) {
|
||||
focusNode.blur();
|
||||
|
@ -137,69 +141,69 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get the text contents of the editor
|
||||
* @return {String} jsonText
|
||||
*/
|
||||
treemode.getText = function() {
|
||||
treemode.getText = function() {
|
||||
return JSON.stringify(this.get());
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set the text contents of the editor
|
||||
* @param {String} jsonText
|
||||
*/
|
||||
treemode.setText = function(jsonText) {
|
||||
treemode.setText = function(jsonText) {
|
||||
this.set(util.parse(jsonText));
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set a field name for the root node.
|
||||
* @param {String | undefined} name
|
||||
*/
|
||||
treemode.setName = function (name) {
|
||||
treemode.setName = function (name) {
|
||||
this.options.name = name;
|
||||
if (this.node) {
|
||||
this.node.updateField(this.options.name);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get the field name for the root node.
|
||||
* @return {String | undefined} name
|
||||
*/
|
||||
treemode.getName = function () {
|
||||
treemode.getName = function () {
|
||||
return this.options.name;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Remove the root node from the editor
|
||||
*/
|
||||
treemode.clear = function () {
|
||||
treemode.clear = function () {
|
||||
if (this.node) {
|
||||
this.node.collapse();
|
||||
this.tbody.removeChild(this.node.getDom());
|
||||
delete this.node;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set the root node for the json editor
|
||||
* @param {Node} node
|
||||
* @private
|
||||
*/
|
||||
treemode._setRoot = function (node) {
|
||||
treemode._setRoot = function (node) {
|
||||
this.clear();
|
||||
|
||||
this.node = node;
|
||||
|
||||
// append to the dom
|
||||
this.tbody.appendChild(node.getDom());
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Search text in all nodes
|
||||
* The nodes will be expanded when the text is found one of its childs,
|
||||
* 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
|
||||
* 'value')
|
||||
*/
|
||||
treemode.search = function (text) {
|
||||
treemode.search = function (text) {
|
||||
var results;
|
||||
if (this.node) {
|
||||
this.content.removeChild(this.table); // Take the table offline
|
||||
|
@ -223,31 +227,31 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
}
|
||||
|
||||
return results;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Expand all nodes
|
||||
*/
|
||||
treemode.expandAll = function () {
|
||||
treemode.expandAll = function () {
|
||||
if (this.node) {
|
||||
this.content.removeChild(this.table); // Take the table offline
|
||||
this.node.expand();
|
||||
this.content.appendChild(this.table); // Put the table online again
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Collapse all nodes
|
||||
*/
|
||||
treemode.collapseAll = function () {
|
||||
treemode.collapseAll = function () {
|
||||
if (this.node) {
|
||||
this.content.removeChild(this.table); // Take the table offline
|
||||
this.node.collapse();
|
||||
this.content.appendChild(this.table); // Put the table online again
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* The method onChange is called whenever a field or value is changed, created,
|
||||
* deleted, duplicated, etc.
|
||||
* @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.
|
||||
* @private
|
||||
*/
|
||||
treemode._onAction = function (action, params) {
|
||||
treemode._onAction = function (action, params) {
|
||||
// add an action to the history
|
||||
if (this.history) {
|
||||
this.history.add(action, params);
|
||||
|
@ -276,14 +280,14 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
util.log('Error in change callback: ', err);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Start autoscrolling when given mouse position is above the top of the
|
||||
* editor contents, or below the bottom.
|
||||
* @param {Number} mouseY Absolute mouse position in pixels
|
||||
*/
|
||||
treemode.startAutoScroll = function (mouseY) {
|
||||
treemode.startAutoScroll = function (mouseY) {
|
||||
var me = this;
|
||||
var content = this.content;
|
||||
var top = util.getAbsoluteTop(content);
|
||||
|
@ -318,12 +322,12 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
else {
|
||||
this.stopAutoScroll();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Stop auto scrolling. Only applicable when scrolling
|
||||
*/
|
||||
treemode.stopAutoScroll = function () {
|
||||
treemode.stopAutoScroll = function () {
|
||||
if (this.autoScrollTimer) {
|
||||
clearTimeout(this.autoScrollTimer);
|
||||
delete this.autoScrollTimer;
|
||||
|
@ -331,10 +335,10 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
if (this.autoScrollStep) {
|
||||
delete this.autoScrollStep;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set the focus to an element in the editor, set text selection, and
|
||||
* set scroll position.
|
||||
* @param {Object} selection An object containing fields:
|
||||
|
@ -343,7 +347,7 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
* {Range | TextRange} range A text selection
|
||||
* {Number} scrollTop Scroll position
|
||||
*/
|
||||
treemode.setSelection = function (selection) {
|
||||
treemode.setSelection = function (selection) {
|
||||
if (!selection) {
|
||||
return;
|
||||
}
|
||||
|
@ -358,9 +362,9 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
if (selection.dom) {
|
||||
selection.dom.focus();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get the current focus
|
||||
* @return {Object} selection An object containing fields:
|
||||
* {Element | undefined} dom The dom element
|
||||
|
@ -368,15 +372,15 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
* {Range | TextRange} range A text selection
|
||||
* {Number} scrollTop Scroll position
|
||||
*/
|
||||
treemode.getSelection = function () {
|
||||
treemode.getSelection = function () {
|
||||
return {
|
||||
dom: domFocus,
|
||||
scrollTop: this.content ? this.content.scrollTop : 0,
|
||||
range: util.getSelectionOffset()
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Adjust the scroll position such that given top position is shown at 1/4
|
||||
* of the window height.
|
||||
* @param {Number} top
|
||||
|
@ -385,7 +389,7 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
* when animation is finished, or false
|
||||
* when not.
|
||||
*/
|
||||
treemode.scrollTo = function (top, callback) {
|
||||
treemode.scrollTo = function (top, callback) {
|
||||
var content = this.content;
|
||||
if (content) {
|
||||
var editor = this;
|
||||
|
@ -430,13 +434,13 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
callback(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create main frame
|
||||
* @private
|
||||
*/
|
||||
treemode._createFrame = function () {
|
||||
treemode._createFrame = function () {
|
||||
// create the frame
|
||||
this.frame = document.createElement('div');
|
||||
this.frame.className = 'jsoneditor';
|
||||
|
@ -540,13 +544,13 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
if (this.options.search) {
|
||||
this.searchBox = new SearchBox(this, this.menu);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Perform an undo action
|
||||
* @private
|
||||
*/
|
||||
treemode._onUndo = function () {
|
||||
treemode._onUndo = function () {
|
||||
if (this.history) {
|
||||
// undo last action
|
||||
this.history.undo();
|
||||
|
@ -556,13 +560,13 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
this.options.change();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Perform a redo action
|
||||
* @private
|
||||
*/
|
||||
treemode._onRedo = function () {
|
||||
treemode._onRedo = function () {
|
||||
if (this.history) {
|
||||
// redo last action
|
||||
this.history.redo();
|
||||
|
@ -572,14 +576,14 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
this.options.change();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Event handler
|
||||
* @param event
|
||||
* @private
|
||||
*/
|
||||
treemode._onEvent = function (event) {
|
||||
treemode._onEvent = function (event) {
|
||||
var target = event.target;
|
||||
|
||||
if (event.type == 'keydown') {
|
||||
|
@ -594,14 +598,14 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
if (node) {
|
||||
node.onEvent(event);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Event handler for keydown. Handles shortcut keys
|
||||
* @param {Event} event
|
||||
* @private
|
||||
*/
|
||||
treemode._onKeyDown = function (event) {
|
||||
treemode._onKeyDown = function (event) {
|
||||
var keynum = event.which || event.keyCode;
|
||||
var ctrlKey = event.ctrlKey;
|
||||
var shiftKey = event.shiftKey;
|
||||
|
@ -652,13 +656,13 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create main table
|
||||
* @private
|
||||
*/
|
||||
treemode._createTable = function () {
|
||||
treemode._createTable = function () {
|
||||
var contentOuter = document.createElement('div');
|
||||
contentOuter.className = 'outer';
|
||||
this.contentOuter = contentOuter;
|
||||
|
@ -691,10 +695,10 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
this.table.appendChild(this.tbody);
|
||||
|
||||
this.frame.appendChild(contentOuter);
|
||||
};
|
||||
};
|
||||
|
||||
// define modes
|
||||
return [
|
||||
// define modes
|
||||
module.exports = [
|
||||
{
|
||||
mode: 'tree',
|
||||
mixin: treemode,
|
||||
|
@ -710,5 +714,4 @@ define(['./Highlighter', './History', './SearchBox', './Node', './modeswitcher',
|
|||
mixin: treemode,
|
||||
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.
|
||||
* On exception, the jsonString is validated and a detailed error is thrown.
|
||||
* @param {String} jsonString
|
||||
* @return {JSON} json
|
||||
*/
|
||||
util.parse = function parse(jsonString) {
|
||||
exports.parse = function parse(jsonString) {
|
||||
try {
|
||||
return JSON.parse(jsonString);
|
||||
}
|
||||
catch (err) {
|
||||
// try to throw a more detailed error message using validate
|
||||
util.validate(jsonString);
|
||||
exports.validate(jsonString);
|
||||
|
||||
// rethrow the original error
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sanitize a JSON-like string containing. For example changes JavaScript
|
||||
* notation into JSON notation.
|
||||
* This function for example changes a string like "{a: 2, 'b': {c: 'd'}"
|
||||
|
@ -30,7 +25,7 @@ define(function () {
|
|||
* @param {string} jsString
|
||||
* @returns {string} json
|
||||
*/
|
||||
util.sanitize = function (jsString) {
|
||||
exports.sanitize = function (jsString) {
|
||||
// escape all single and double quotes inside strings
|
||||
var chars = [];
|
||||
var inString = false;
|
||||
|
@ -72,69 +67,69 @@ define(function () {
|
|||
});
|
||||
|
||||
return jsonString;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Validate a string containing a JSON object
|
||||
* This method uses JSONLint to validate the String. If JSONLint is not
|
||||
* available, the built-in JSON parser of the browser is used.
|
||||
* @param {String} jsonString String with an (invalid) JSON object
|
||||
* @throws Error
|
||||
*/
|
||||
util.validate = function validate(jsonString) {
|
||||
exports.validate = function validate(jsonString) {
|
||||
if (typeof(jsonlint) != 'undefined') {
|
||||
jsonlint.parse(jsonString);
|
||||
}
|
||||
else {
|
||||
JSON.parse(jsonString);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Extend object a with the properties of object b
|
||||
* @param {Object} a
|
||||
* @param {Object} b
|
||||
* @return {Object} a
|
||||
*/
|
||||
util.extend = function extend(a, b) {
|
||||
exports.extend = function extend(a, b) {
|
||||
for (var prop in b) {
|
||||
if (b.hasOwnProperty(prop)) {
|
||||
a[prop] = b[prop];
|
||||
}
|
||||
}
|
||||
return a;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Remove all properties from object a
|
||||
* @param {Object} a
|
||||
* @return {Object} a
|
||||
*/
|
||||
util.clear = function clear (a) {
|
||||
exports.clear = function clear (a) {
|
||||
for (var prop in a) {
|
||||
if (a.hasOwnProperty(prop)) {
|
||||
delete a[prop];
|
||||
}
|
||||
}
|
||||
return a;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Output text to the console, if console is available
|
||||
* @param {...*} args
|
||||
*/
|
||||
util.log = function log (args) {
|
||||
exports.log = function log (args) {
|
||||
if (typeof console !== 'undefined' && typeof console.log === 'function') {
|
||||
console.log.apply(console, arguments);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get the type of an object
|
||||
* @param {*} object
|
||||
* @return {String} type
|
||||
*/
|
||||
util.type = function type (object) {
|
||||
exports.type = function type (object) {
|
||||
if (object === null) {
|
||||
return 'null';
|
||||
}
|
||||
|
@ -153,88 +148,88 @@ define(function () {
|
|||
if ((object instanceof RegExp) || (typeof object === 'regexp')) {
|
||||
return 'regexp';
|
||||
}
|
||||
if (util.isArray(object)) {
|
||||
if (exports.isArray(object)) {
|
||||
return 'array';
|
||||
}
|
||||
|
||||
return 'object';
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test whether a text contains a url (matches when a string starts
|
||||
* with 'http://*' or 'https://*' and has no whitespace characters)
|
||||
* @param {String} text
|
||||
*/
|
||||
var isUrlRegex = /^https?:\/\/\S+$/;
|
||||
util.isUrl = function isUrl (text) {
|
||||
var isUrlRegex = /^https?:\/\/\S+$/;
|
||||
exports.isUrl = function isUrl (text) {
|
||||
return (typeof text == 'string' || text instanceof String) &&
|
||||
isUrlRegex.test(text);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Tes whether given object is an Array
|
||||
* @param {*} obj
|
||||
* @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]';
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Retrieve the absolute left value of a DOM element
|
||||
* @param {Element} elem A dom element, for example a div
|
||||
* @return {Number} left The absolute left position of this element
|
||||
* in the browser page.
|
||||
*/
|
||||
util.getAbsoluteLeft = function getAbsoluteLeft(elem) {
|
||||
exports.getAbsoluteLeft = function getAbsoluteLeft(elem) {
|
||||
var rect = elem.getBoundingClientRect();
|
||||
return rect.left + window.pageXOffset || document.scrollLeft || 0;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Retrieve the absolute top value of a DOM element
|
||||
* @param {Element} elem A dom element, for example a div
|
||||
* @return {Number} top The absolute top position of this element
|
||||
* in the browser page.
|
||||
*/
|
||||
util.getAbsoluteTop = function getAbsoluteTop(elem) {
|
||||
exports.getAbsoluteTop = function getAbsoluteTop(elem) {
|
||||
var rect = elem.getBoundingClientRect();
|
||||
return rect.top + window.pageYOffset || document.scrollTop || 0;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* add a className to the given elements style
|
||||
* @param {Element} elem
|
||||
* @param {String} className
|
||||
*/
|
||||
util.addClassName = function addClassName(elem, className) {
|
||||
exports.addClassName = function addClassName(elem, className) {
|
||||
var classes = elem.className.split(' ');
|
||||
if (classes.indexOf(className) == -1) {
|
||||
classes.push(className); // add the class to the array
|
||||
elem.className = classes.join(' ');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* add a className to the given elements style
|
||||
* @param {Element} elem
|
||||
* @param {String} className
|
||||
*/
|
||||
util.removeClassName = function removeClassName(elem, className) {
|
||||
exports.removeClassName = function removeClassName(elem, className) {
|
||||
var classes = elem.className.split(' ');
|
||||
var index = classes.indexOf(className);
|
||||
if (index != -1) {
|
||||
classes.splice(index, 1); // remove the class from the array
|
||||
elem.className = classes.join(' ');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Strip the formatting from the contents of a div
|
||||
* the formatting from the div itself is not stripped, only from its childs.
|
||||
* @param {Element} divElement
|
||||
*/
|
||||
util.stripFormatting = function stripFormatting(divElement) {
|
||||
exports.stripFormatting = function stripFormatting(divElement) {
|
||||
var childs = divElement.childNodes;
|
||||
for (var i = 0, iMax = childs.length; i < iMax; i++) {
|
||||
var child = childs[i];
|
||||
|
@ -257,18 +252,18 @@ define(function () {
|
|||
}
|
||||
|
||||
// recursively strip childs
|
||||
util.stripFormatting(child);
|
||||
exports.stripFormatting(child);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set focus to the end of an editable div
|
||||
* code from Nico Burns
|
||||
* http://stackoverflow.com/users/140293/nico-burns
|
||||
* http://stackoverflow.com/questions/1125292/how-to-move-cursor-to-end-of-contenteditable-entity
|
||||
* @param {Element} contentEditableElement A content editable div
|
||||
*/
|
||||
util.setEndOfContentEditable = function setEndOfContentEditable(contentEditableElement) {
|
||||
exports.setEndOfContentEditable = function setEndOfContentEditable(contentEditableElement) {
|
||||
var range, selection;
|
||||
if(document.createRange) {
|
||||
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.addRange(range);//make the range you have just created the visible selection
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Select all text of a content editable div.
|
||||
* http://stackoverflow.com/a/3806004/1262753
|
||||
* @param {Element} contentEditableElement A content editable div
|
||||
*/
|
||||
util.selectContentEditable = function selectContentEditable(contentEditableElement) {
|
||||
exports.selectContentEditable = function selectContentEditable(contentEditableElement) {
|
||||
if (!contentEditableElement || contentEditableElement.nodeName != 'DIV') {
|
||||
return;
|
||||
}
|
||||
|
@ -298,14 +293,14 @@ define(function () {
|
|||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get text selection
|
||||
* http://stackoverflow.com/questions/4687808/contenteditable-selected-text-save-and-restore
|
||||
* @return {Range | TextRange | null} range
|
||||
*/
|
||||
util.getSelection = function getSelection() {
|
||||
exports.getSelection = function getSelection() {
|
||||
if (window.getSelection) {
|
||||
var sel = window.getSelection();
|
||||
if (sel.getRangeAt && sel.rangeCount) {
|
||||
|
@ -313,14 +308,14 @@ define(function () {
|
|||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set text selection
|
||||
* http://stackoverflow.com/questions/4687808/contenteditable-selected-text-save-and-restore
|
||||
* @param {Range | TextRange | null} range
|
||||
*/
|
||||
util.setSelection = function setSelection(range) {
|
||||
exports.setSelection = function setSelection(range) {
|
||||
if (range) {
|
||||
if (window.getSelection) {
|
||||
var sel = window.getSelection();
|
||||
|
@ -328,9 +323,9 @@ define(function () {
|
|||
sel.addRange(range);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get selected text range
|
||||
* @return {Object} params object containing parameters:
|
||||
* {Number} startOffset
|
||||
|
@ -339,8 +334,8 @@ define(function () {
|
|||
* selected text element
|
||||
* Returns null if no text selection is found
|
||||
*/
|
||||
util.getSelectionOffset = function getSelectionOffset() {
|
||||
var range = util.getSelection();
|
||||
exports.getSelectionOffset = function getSelectionOffset() {
|
||||
var range = exports.getSelection();
|
||||
|
||||
if (range && 'startOffset' in range && 'endOffset' in range &&
|
||||
range.startContainer && (range.startContainer == range.endContainer)) {
|
||||
|
@ -352,16 +347,16 @@ define(function () {
|
|||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set selected text range in given element
|
||||
* @param {Object} params An object containing:
|
||||
* {Element} container
|
||||
* {Number} startOffset
|
||||
* {Number} endOffset
|
||||
*/
|
||||
util.setSelectionOffset = function setSelectionOffset(params) {
|
||||
exports.setSelectionOffset = function setSelectionOffset(params) {
|
||||
if (document.createRange && window.getSelection) {
|
||||
var selection = window.getSelection();
|
||||
if(selection) {
|
||||
|
@ -371,18 +366,18 @@ define(function () {
|
|||
range.setStart(params.container.firstChild, params.startOffset);
|
||||
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)
|
||||
* @param {Element} element
|
||||
* @param {Object} [buffer]
|
||||
* @return {String} innerText
|
||||
*/
|
||||
util.getInnerText = function getInnerText(element, buffer) {
|
||||
exports.getInnerText = function getInnerText(element, buffer) {
|
||||
var first = (buffer == undefined);
|
||||
if (first) {
|
||||
buffer = {
|
||||
|
@ -418,7 +413,7 @@ define(function () {
|
|||
innerText += '\n';
|
||||
buffer.flush();
|
||||
}
|
||||
innerText += util.getInnerText(child, buffer);
|
||||
innerText += exports.getInnerText(child, buffer);
|
||||
buffer.set('\n');
|
||||
}
|
||||
else if (child.nodeName == 'BR') {
|
||||
|
@ -426,14 +421,14 @@ define(function () {
|
|||
buffer.set('\n');
|
||||
}
|
||||
else {
|
||||
innerText += util.getInnerText(child, buffer);
|
||||
innerText += exports.getInnerText(child, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
return innerText;
|
||||
}
|
||||
else {
|
||||
if (element.nodeName == 'P' && util.getInternetExplorerVersion() != -1) {
|
||||
if (element.nodeName == 'P' && exports.getInternetExplorerVersion() != -1) {
|
||||
// On Internet Explorer, a <p> with hasChildNodes()==false is
|
||||
// rendered with a new line. Note that a <p> with
|
||||
// hasChildNodes()==true is rendered without a new line
|
||||
|
@ -445,15 +440,15 @@ define(function () {
|
|||
|
||||
// br or unknown
|
||||
return '';
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns the version of Internet Explorer or a -1
|
||||
* (indicating the use of another browser).
|
||||
* 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
|
||||
*/
|
||||
util.getInternetExplorerVersion = function getInternetExplorerVersion() {
|
||||
exports.getInternetExplorerVersion = function getInternetExplorerVersion() {
|
||||
if (_ieVersion == -1) {
|
||||
var rv = -1; // Return value assumes failure.
|
||||
if (navigator.appName == 'Microsoft Internet Explorer')
|
||||
|
@ -469,24 +464,24 @@ define(function () {
|
|||
}
|
||||
|
||||
return _ieVersion;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test whether the current browser is Firefox
|
||||
* @returns {boolean} isFirefox
|
||||
*/
|
||||
util.isFirefox = function isFirefox () {
|
||||
exports.isFirefox = function isFirefox () {
|
||||
return (navigator.userAgent.indexOf("Firefox") != -1);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* cached internet explorer version
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
var _ieVersion = -1;
|
||||
var _ieVersion = -1;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add and event listener. Works for all browsers
|
||||
* @param {Element} element An html element
|
||||
* @param {string} action The action, for example "click",
|
||||
|
@ -495,12 +490,12 @@ define(function () {
|
|||
* @param {boolean} [useCapture] false by default
|
||||
* @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 (useCapture === undefined)
|
||||
useCapture = false;
|
||||
|
||||
if (action === "mousewheel" && util.isFirefox()) {
|
||||
if (action === "mousewheel" && exports.isFirefox()) {
|
||||
action = "DOMMouseScroll"; // For Firefox
|
||||
}
|
||||
|
||||
|
@ -514,21 +509,21 @@ define(function () {
|
|||
element.attachEvent("on" + action, f);
|
||||
return f;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Remove an event listener from an element
|
||||
* @param {Element} element An html dom element
|
||||
* @param {string} action The name of the event, for example "mousedown"
|
||||
* @param {function} listener The listener function
|
||||
* @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 (useCapture === undefined)
|
||||
useCapture = false;
|
||||
|
||||
if (action === "mousewheel" && util.isFirefox()) {
|
||||
if (action === "mousewheel" && exports.isFirefox()) {
|
||||
action = "DOMMouseScroll"; // For Firefox
|
||||
}
|
||||
|
||||
|
@ -537,7 +532,4 @@ define(function () {
|
|||
// Old IE browsers
|
||||
element.detachEvent("on" + action, listener);
|
||||
}
|
||||
};
|
||||
|
||||
return util;
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue