Actualización
This commit is contained in:
132
plugin/mindmap/edit-mindmap/vendor/js/kampfer/ajax.js
vendored
Normal file
132
plugin/mindmap/edit-mindmap/vendor/js/kampfer/ajax.js
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
kampfer.provide('ajax');
|
||||
|
||||
/**
|
||||
* @Author l.w.kampfer@gmail.com
|
||||
* @Name AJAX工具函数
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
(function( window, kampfer ) {
|
||||
//XHR构造函数
|
||||
var _XHRFactories = [
|
||||
function() { return new XMLHttpRequest(); },
|
||||
function() { return new window.ActiveXObject('Microsoft.XMLHTTP'); }
|
||||
];
|
||||
|
||||
//默认设置
|
||||
var _defaultSettings = {
|
||||
url : '',
|
||||
method : 'GET',
|
||||
async : true,
|
||||
parameters : {},
|
||||
timeout : 10000,
|
||||
ontimeout : function() {},
|
||||
onerror : function() {},
|
||||
onsuccess : function() {},
|
||||
onbeforesend : function() {},
|
||||
context : null,
|
||||
headers : {}
|
||||
};
|
||||
|
||||
var responceTypes = {
|
||||
xml : /xml/,
|
||||
json : /json/,
|
||||
//html : /html/,
|
||||
javascript : /javascript/
|
||||
};
|
||||
|
||||
//将对象序列化为字符串
|
||||
function _encodeFormData( data ) {
|
||||
var pairs = [],
|
||||
regSpace = /%20/g;
|
||||
for( var name in data ) {
|
||||
var value = data[name].toString();
|
||||
//使用encodeURIComponent对名值对进行编码
|
||||
var pair = encodeURIComponent( name ).replace( regSpace, '+' ) + '=' +
|
||||
encodeURIComponent( value ).replace( regSpace, '+' );
|
||||
pairs.push( pair );
|
||||
}
|
||||
return pairs.join( '&' );
|
||||
}
|
||||
|
||||
//区别对待返回类型
|
||||
function _getResponse( request ) {
|
||||
var contentType = request.getResponseHeader('Content-Type');
|
||||
if( responceTypes.xml.test( contentType ) ) {
|
||||
return request.responseXML;
|
||||
}else if( responceTypes.json.test( contentType ) || responceTypes.javascript.test( contentType ) ) {
|
||||
return eval( '(' + request.responseText + ')' );
|
||||
}else{
|
||||
return request.responseText;
|
||||
}
|
||||
}
|
||||
|
||||
//创建新的XMLHttpRequest对象
|
||||
function _createNewXHR() {
|
||||
for( var i = 0, l = _XHRFactories.length; i < l; i++ ) {
|
||||
try {
|
||||
_XHRFactories[i]();
|
||||
_createNewXHR = _XHRFactories[i];
|
||||
break;
|
||||
} catch( e ) {
|
||||
//consle.log( ' XHR not supported' );
|
||||
}
|
||||
}
|
||||
return _createNewXHR();
|
||||
}
|
||||
|
||||
var ajax = function( options ) {
|
||||
var newXHR = _createNewXHR(),
|
||||
timer,
|
||||
url,
|
||||
parameters;
|
||||
options = kampfer.extend( {}, _defaultSettings, options );
|
||||
//设置执行上下文
|
||||
if( !options.context ) {
|
||||
options.context = newXHR;
|
||||
}
|
||||
if( options.ontimeout ) {
|
||||
//闭包
|
||||
timer = setTimeout( function(){
|
||||
newXHR.abort();
|
||||
if ( options.ontimeout ) {
|
||||
options.ontimeout.call( options.context, options );
|
||||
}
|
||||
}, options.timeout );
|
||||
}
|
||||
newXHR.onreadystatechange = function() {
|
||||
if( newXHR.readyState === 4 ) {
|
||||
if( timer ) {
|
||||
clearTimeout( timer );
|
||||
}
|
||||
if( newXHR.status === 200 ) {
|
||||
options.onsuccess.call( options.context, _getResponse( newXHR ) );
|
||||
} else {
|
||||
if( options.onerror ) {
|
||||
options.onerror.call( options.context, newXHR );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
url = options.url;
|
||||
parameters = options.parameters && _encodeFormData( options.parameters );
|
||||
if( options.method.toUpperCase() === 'GET' ) {
|
||||
if( options.parameters ) {
|
||||
url += '?' + parameters + '&_=' + ( +new Date() );
|
||||
}
|
||||
newXHR.open( 'GET', url, options.async );
|
||||
options.onbeforesend && options.onbeforesend.call( options.context, newXHR );
|
||||
newXHR.send( null );
|
||||
} else if( options.method.toUpperCase() === 'POST' ) {
|
||||
newXHR.open( 'POST', url, options.async );
|
||||
options.onbeforesend && options.onbeforesend.call( options.context, newXHR );
|
||||
newXHR.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
|
||||
newXHR.send( parameters );
|
||||
}
|
||||
};
|
||||
|
||||
kampfer.extend( kampfer, {
|
||||
ajax : ajax
|
||||
});
|
||||
|
||||
})( window, kampfer );
|
||||
466
plugin/mindmap/edit-mindmap/vendor/js/kampfer/base.js
vendored
Normal file
466
plugin/mindmap/edit-mindmap/vendor/js/kampfer/base.js
vendored
Normal file
@@ -0,0 +1,466 @@
|
||||
/*
|
||||
* @Author : l.w.kampfer@gmail.com
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
/**
|
||||
* @define {boolean} Overridden to true by the compiler when --closure_pass
|
||||
* or --mark_as_compiled is specified.
|
||||
*/
|
||||
var COMPILED = false;
|
||||
|
||||
|
||||
/**
|
||||
* @define {object} 定义命名空间kampfer。
|
||||
* 所有需要公开的属性和方法都被将绑定在kampfer上。最后将检查全局变量,
|
||||
* 并把kampfer绑定到全局变量上
|
||||
*/
|
||||
var kampfer = {};
|
||||
|
||||
|
||||
/**
|
||||
* @define {object} 保存一个对全局对象的引用。
|
||||
* 一般情况下global指向window对象。
|
||||
*/
|
||||
kampfer.global = this;
|
||||
|
||||
|
||||
/**
|
||||
* @define {string} base.js的路径
|
||||
* 在异步加载js文件的时候,也会作为初始目录使用
|
||||
*/
|
||||
kampfer.basePath = '';
|
||||
|
||||
|
||||
/**
|
||||
* 用于保存所有被隐式声明的命名空间,此对象的属性名就是命名空间的名字
|
||||
* @type {object}
|
||||
*/
|
||||
kampfer.implicitNamespaces = {};
|
||||
|
||||
|
||||
/**
|
||||
* 判断给定的命名空间是否已经初始化。判断条件如下:
|
||||
* 1.命名空间没有被隐性的声明(不在_implicitNamespaces中)
|
||||
* 2.命名空间非空
|
||||
* 以上两个条件同时满足时,说明命名空间已被注册,方法返回true
|
||||
* @param ns{string} 命名空间的名字
|
||||
* @return {boolean} 已经被注册过,则为true;反之为false
|
||||
* @private
|
||||
*/
|
||||
kampfer.isProvided = function(name) {
|
||||
return !kampfer.implicitNamespaces[name] && !!kampfer.getPropertyByName(name);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 通过名字找到指定对象上的某个属性的值
|
||||
* @param name{string} 命名空间的名字
|
||||
* @param obj{object} 目标对象,将在这个对象上查找给定的名字空间。
|
||||
* @return {*}
|
||||
*/
|
||||
kampfer.getPropertyByName = function( name, obj ) {
|
||||
var namespace = name.split('.'),
|
||||
cur = obj || kampfer;
|
||||
for( var part; (part = namespace.shift()); ) {
|
||||
if( kampfer.isDefAndNotNull( cur[part] ) ) {
|
||||
cur = cur[part];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return cur;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 根据给定的名字空间创建一个对象结构(object structure),
|
||||
* 保证已经存在的名字空间不会被覆盖重写。
|
||||
* @param name{string} 命名空间名字
|
||||
* @param value{*} 暴露在名字空间最后的对象
|
||||
* @param objectToExportTo{object} 命名空间的宿主对象。默认为kampfer.global
|
||||
*/
|
||||
kampfer.exportPath = function(name, value, objectToExportTo) {
|
||||
|
||||
var cur = objectToExportTo || kampfer.global,
|
||||
namespace = name.split('.');
|
||||
|
||||
for( var part; (part = namespace.shift()); ) {
|
||||
if( !namespace.length && kampfer.isDefAndNotNull(value) ) {
|
||||
cur[part] = value;
|
||||
} else if( cur[part] ) {
|
||||
cur = cur[part];
|
||||
} else {
|
||||
cur = cur[part] = {};
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 声明命名空间。此方法将kampfer作为根节点,所有新声明的命名空间都将被绑定在kampfer上。
|
||||
* 构造新命名空间的过程中可能会产生隐性的命名空间,provide方法将会将隐性的名字空间保存在
|
||||
* implicitNamespaces属性中。打包程序将通过扫描provide,在deps文件中生成一条关于本文件
|
||||
* 依赖关系的记录。
|
||||
* @param name{string} 命名空间的名字。
|
||||
*/
|
||||
kampfer.provide = function(name) {
|
||||
|
||||
//if(!COMPILED) {
|
||||
|
||||
if( kampfer.isProvided(name) ) {
|
||||
throw Error('Namespace "' + name + '" already declared.');
|
||||
}
|
||||
|
||||
delete kampfer.implicitNamespaces[name];
|
||||
|
||||
var namespace = name;
|
||||
while( (namespace = namespace.substring( 0, namespace.lastIndexOf('.') )) ) {
|
||||
if( kampfer.getPropertyByName(namespace) ) {
|
||||
break;
|
||||
} else {
|
||||
kampfer.implicitNamespaces[namespace] = true;
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
kampfer.exportPath(name, null, kampfer);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 定义文件所依赖的模块。打包程序将通过扫描require,在deps文件中生成一条关于本文件
|
||||
* 依赖关系的记录。合并程序也会扫描require来合并文件。
|
||||
* @TODO 将来会配合后台,在服务器端读取require来合并js文件。
|
||||
* @param name{string} 依赖的模块名
|
||||
*/
|
||||
kampfer.require = function(name) {
|
||||
|
||||
if( !COMPILED ) {
|
||||
if ( !name || kampfer.isProvided(name) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var path = kampfer._getPathFromDeps(name);
|
||||
if (path) {
|
||||
kampfer._included[path] = true;
|
||||
kampfer._writeScripts();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 在kampfer上添加js文件依赖关系的记录。
|
||||
* @param path{string} 文件的储存路径
|
||||
* @param names{array} 文件定义的模块列表
|
||||
* @param requires{array} 文件依赖的模块列表
|
||||
*/
|
||||
kampfer.addDependency = function( path, provides, requires ) {
|
||||
|
||||
if( !COMPILED ) {
|
||||
|
||||
var provide, require, deps;
|
||||
path = path.replace(/\\/g, '/');
|
||||
deps = kampfer._dependencies;
|
||||
|
||||
for( var i = 0; (provide = provides[i]); i++) {
|
||||
deps.nameToPath[provide] = path;
|
||||
if (!(path in deps.pathToNames)) {
|
||||
deps.pathToNames[path] = {};
|
||||
}
|
||||
deps.pathToNames[path][provide] = true;
|
||||
}
|
||||
|
||||
for( var j = 0; (require = requires[j]); j++) {
|
||||
if (!(path in deps.requires)) {
|
||||
deps.requires[path] = {};
|
||||
}
|
||||
deps.requires[path][require] = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
if(!COMPILED) {
|
||||
|
||||
/**
|
||||
* 通过模块名从kampfer保存的依赖性列表中获得真实文件路径
|
||||
* @param name{string} 模块的名称
|
||||
* @return {string} 模块的真实路径地址
|
||||
* @private
|
||||
*/
|
||||
kampfer._getPathFromDeps = function(name) {
|
||||
if( name in kampfer._dependencies.nameToPath ) {
|
||||
return kampfer._dependencies.nameToPath[name];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 决定添加script标签方式,默认使用document.write。
|
||||
* 记录已经加载的js。
|
||||
* @param src{string} js的完整路径
|
||||
* @private
|
||||
*/
|
||||
kampfer._importScript = function(src) {
|
||||
var _importScript = kampfer._writeScriptTag;
|
||||
if(!kampfer._dependencies.written[src] && _importScript(src)) {
|
||||
kampfer._dependencies.written[src] = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 对依赖关系进行拓扑排序,决定js文件正确的输出顺序,并异步的加载js文件
|
||||
* 详细算法:http://en.wikipedia.org/wiki/Topological_sorting
|
||||
* @private
|
||||
*/
|
||||
kampfer._writeScripts = function() {
|
||||
|
||||
var scripts = [],
|
||||
seenScript = {},
|
||||
deps = kampfer._dependencies;
|
||||
|
||||
function visitNode(path) {
|
||||
if( path in deps.written ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果已经访问过次节点
|
||||
if( path in deps.visited ) {
|
||||
if( !(path in seenScript) ) {
|
||||
seenScript[path] = true;
|
||||
scripts.push(path);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
deps.visited[path] = true;
|
||||
|
||||
if (path in deps.requires) {
|
||||
for (var requireName in deps.requires[path]) {
|
||||
// 如果依赖的模块已经注册(假设它已经被正确的加载),那么将不会再加载该模块。
|
||||
if (!kampfer.isProvided(requireName)) {
|
||||
if (requireName in deps.nameToPath) {
|
||||
visitNode(deps.nameToPath[requireName]);
|
||||
} else {
|
||||
throw Error('Undefined nameToPath for ' + requireName ' in ' + path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!(path in seenScript)) {
|
||||
seenScript[path] = true;
|
||||
scripts.push(path);
|
||||
}
|
||||
}
|
||||
|
||||
for( var path in kampfer._included ) {
|
||||
if( !deps.written[path] ) {
|
||||
visitNode(path);
|
||||
}
|
||||
}
|
||||
|
||||
for( var i = 0; i < scripts.length; i++ ) {
|
||||
if ( scripts[i] ) {
|
||||
kampfer._importScript( kampfer.basePath + scripts[i] );
|
||||
} else {
|
||||
throw Error('Undefined script input');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 使用document.write的方式输出script标签,异步的引入js
|
||||
* TODO 改用标准的DOM插入方法来添加script标签,而不使用document.write方法
|
||||
* @param src{string} js文件的url
|
||||
* @return {boolean} 成功返回true,失败返回false
|
||||
* @private
|
||||
*/
|
||||
kampfer._writeScriptTag = function(src) {
|
||||
var doc = kampfer.global.document;
|
||||
doc.write('<script type="text/javascript" src="' + src + '"></' + 'script>');
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
kampfer._findBasePath = function() {
|
||||
|
||||
var doc = kampfer.global.document,
|
||||
scripts = doc.getElementsByTagName('script');
|
||||
|
||||
for (var i = scripts.length - 1; i >= 0; --i) {
|
||||
|
||||
var src = scripts[i].src,
|
||||
qmark = src.lastIndexOf('?'),
|
||||
l = (qmark === -1 ? src.length : qmark);
|
||||
|
||||
if (src.substr(l - 7, 7) == 'base.js') {
|
||||
kampfer.basePath = src.substr(0, l - 7);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
kampfer._dependencies = {
|
||||
pathToNames: {}, // 1 to many
|
||||
nameToPath: {}, // 1 to 1
|
||||
requires: {}, // 1 to many
|
||||
visited: {}, // 避免在拓扑排序时循环访问同一个节点。访问过的节点将保存在这里
|
||||
written: {} // 记录已经被加载到页面的js文件名
|
||||
};
|
||||
|
||||
kampfer._included = {};
|
||||
|
||||
|
||||
kampfer._findBasePath();
|
||||
|
||||
kampfer._importScript( kampfer.basePath + 'deps.js' );
|
||||
|
||||
}
|
||||
|
||||
|
||||
kampfer.isDef = function(val) {
|
||||
return val !== undefined;
|
||||
};
|
||||
|
||||
|
||||
kampfer.isDefAndNotNull = function(val) {
|
||||
return val != null;
|
||||
};
|
||||
|
||||
|
||||
var _toString = Object.prototype.toString;
|
||||
|
||||
kampfer.type = function(value) {
|
||||
return value == null ?
|
||||
String(value) :
|
||||
_class2type[ _toString.call(value) ] || 'object';
|
||||
};
|
||||
|
||||
kampfer.isArray = function(val) {
|
||||
return kampfer.type(val) === 'array';
|
||||
};
|
||||
|
||||
kampfer.isObject = function(val) {
|
||||
return kampfer.type(val) === 'object';
|
||||
};
|
||||
|
||||
|
||||
kampfer.isEmptyObject = function(val) {
|
||||
if( kampfer.type(val) !== 'object' ) {
|
||||
return;
|
||||
}
|
||||
for( var name in val ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
kampfer.isWindow = function(obj) {
|
||||
if(obj === this.global) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
kampfer.each = function( array, fn, thisObj ) {
|
||||
for( var i = 0, len = (array && array.length) || 0; i < len; ++i ) {
|
||||
|
||||
if( i in array ) {
|
||||
fn.call( thisObj || kampfer.global, i, array[i], array );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
kampfer.extend = function() {
|
||||
|
||||
var src, target, name, len, i, deep, copyFrom, copyTo, clone;
|
||||
i = 1;
|
||||
len = arguments.length;
|
||||
deep = false;
|
||||
target = arguments[0] || {};
|
||||
|
||||
|
||||
if( typeof target === 'boolean' ) {
|
||||
deep = target;
|
||||
i = 2;
|
||||
target = arguments[1] || {};
|
||||
}
|
||||
|
||||
if( i === len ) {
|
||||
target = this;
|
||||
--i;
|
||||
}
|
||||
|
||||
for( ; i < len; i++ ) {
|
||||
src = arguments[i];
|
||||
if( src !== null ) {
|
||||
for( name in src ) {
|
||||
copyFrom = src[name];
|
||||
copyTo = target[name];
|
||||
|
||||
if( copyTo === copyFrom ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( deep && copyFrom && ( kampfer.isArray(copyFrom) ||
|
||||
kampfer.isObject(copyFrom) ) ) {
|
||||
if( kampfer.isArray(copyFrom) ) {
|
||||
clone = copyTo && kampfer.isArray(copyTo) ? copyTo : [];
|
||||
} else if( kampfer.isObject(copyFrom) ) {
|
||||
clone = copyTo && kampfer.isObject(copyTo) ? copyTo : {};
|
||||
}
|
||||
target[name] = kampfer.extend( deep, clone, copyFrom );
|
||||
|
||||
} else if( copyFrom !== undefined ) {
|
||||
target[name] = copyFrom;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
|
||||
};
|
||||
|
||||
kampfer.emptyFn = function() {};
|
||||
|
||||
kampfer.now = function() {
|
||||
return +new Date();
|
||||
};
|
||||
|
||||
kampfer.expando = 'kampfer' + kampfer.now();
|
||||
|
||||
var _class2type = {};
|
||||
|
||||
kampfer.each( "Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
|
||||
_class2type[ "[object " + name + "]" ] = name.toLowerCase();
|
||||
});
|
||||
|
||||
if( kampfer.type( kampfer.global.kampfer ) != 'undefined' ) {
|
||||
kampfer._kampfer = kampfer.global.kampfer;
|
||||
}
|
||||
if( kampfer.type( kampfer.global.k ) != 'undefined' ) {
|
||||
kampfer._k = kampfer.global.k;
|
||||
}
|
||||
kampfer.global.kampfer = kampfer.global.k = kampfer;
|
||||
|
||||
})();
|
||||
31
plugin/mindmap/edit-mindmap/vendor/js/kampfer/class.js
vendored
Normal file
31
plugin/mindmap/edit-mindmap/vendor/js/kampfer/class.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
kampfer.provide('Class');
|
||||
|
||||
kampfer.Class = function() {};
|
||||
|
||||
kampfer.Class.initializing = false;
|
||||
|
||||
kampfer.Class.extend = function(props) {
|
||||
var Class = function() {
|
||||
if(!kampfer.Class.initializing && this.initializer) {
|
||||
this.initializer.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
kampfer.Class.initializing = true;
|
||||
// this === 构造函数。
|
||||
//能否直接使用this.prototype考虑使用this.prototype。
|
||||
var prototype = new this();
|
||||
kampfer.Class.initializing = false;
|
||||
|
||||
prototype = kampfer.extend(prototype, props);
|
||||
|
||||
Class.prototype = prototype;
|
||||
|
||||
Class.prototype.constructor = Class;
|
||||
|
||||
Class.superClass = this.prototype;
|
||||
|
||||
Class.extend = kampfer.Class.extend;
|
||||
|
||||
return Class;
|
||||
};
|
||||
31
plugin/mindmap/edit-mindmap/vendor/js/kampfer/class/class.js
vendored
Normal file
31
plugin/mindmap/edit-mindmap/vendor/js/kampfer/class/class.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
kampfer.provide('Class');
|
||||
|
||||
kampfer.Class = function() {};
|
||||
|
||||
kampfer.Class.initializing = false;
|
||||
|
||||
kampfer.Class.extend = function(props) {
|
||||
var Class = function() {
|
||||
if(!kampfer.Class.initializing && this.initializer) {
|
||||
this.initializer.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
kampfer.Class.initializing = true;
|
||||
// this === 构造函数。
|
||||
//能否直接使用this.prototype考虑使用this.prototype。
|
||||
var prototype = new this();
|
||||
kampfer.Class.initializing = false;
|
||||
|
||||
prototype = kampfer.extend(prototype, props);
|
||||
|
||||
Class.prototype = prototype;
|
||||
|
||||
Class.prototype.constructor = Class;
|
||||
|
||||
Class.superClass = this.prototype;
|
||||
|
||||
Class.extend = kampfer.Class.extend;
|
||||
|
||||
return Class;
|
||||
};
|
||||
198
plugin/mindmap/edit-mindmap/vendor/js/kampfer/class/composition.js
vendored
Normal file
198
plugin/mindmap/edit-mindmap/vendor/js/kampfer/class/composition.js
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
kampfer.require('events.EventTarget');
|
||||
|
||||
kampfer.provide('class.Composition');
|
||||
|
||||
kampfer.class.Composition = kampfer.events.EventTarget.extend({
|
||||
_id : null,
|
||||
|
||||
_parent : null,
|
||||
|
||||
//array
|
||||
//_children必须与_childrenIndex同步
|
||||
//懒加载
|
||||
_children : null,
|
||||
|
||||
//object
|
||||
//_childrenIndex必须与_children同步
|
||||
//懒加载
|
||||
_childrenIndex : null,
|
||||
|
||||
//递归调用子节点的指定方法
|
||||
//实现composition模式的关键方法之一
|
||||
walk : function(method) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
this.forEachChild(function(child, i) {
|
||||
if( kampfer.type(child[method]) === 'function' ) {
|
||||
child[method].apply(child, args);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getId : function() {
|
||||
return this._id ||
|
||||
( this._id = kampfer.Composition.generateUniqueId() );
|
||||
},
|
||||
|
||||
setId : function(id) {
|
||||
if(this._parent && this._parent._childrenIndex) {
|
||||
delete this._parent._childrenIndex[this._id];
|
||||
this._parent._childrenIndex[id] = this;
|
||||
}
|
||||
|
||||
this._id = id;
|
||||
},
|
||||
|
||||
getParent : function() {
|
||||
return this._parent;
|
||||
},
|
||||
|
||||
setParent : function(parent) {
|
||||
//新的parent不为空时,必须是component实例
|
||||
if( parent && !(parent instanceof kampfer.UIComponent) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
//新的parent不能是对象自己
|
||||
if(parent === this) {
|
||||
return;
|
||||
}
|
||||
|
||||
//对象已经是另一个对象的child,那么必须先调用removeChild之后再调用setParent
|
||||
//对象不可能同时是另外两个对象的child
|
||||
if( parent && this._parent && this._id &&
|
||||
this._parent.getChild(this._id) && parent !== this._parent ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._parent = parent;
|
||||
this.setParentEventTarget(parent);
|
||||
|
||||
//对象不是新parent的child,那么将child添加到parnet的子列表中
|
||||
//因为addchild方法会检查_parent属性,所以必须在设置完_parent属性后才能执行添加操作
|
||||
//closure没有这一步, 它的setParent方法只保证child的parent属性正确,
|
||||
//但不保证child一定在parnet的子节点列表中
|
||||
if( parent && !parent.getChild(this._id) ) {
|
||||
parent.addChild(this);
|
||||
}
|
||||
},
|
||||
|
||||
addChild : function(child, render) {
|
||||
this.addChildAt(child, this.getChildCount(), render);
|
||||
},
|
||||
|
||||
addChildAt : function(child, index, render) {
|
||||
if( !(child instanceof kampfer.UIComponent) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(index < 0 || index > this.getChildCount() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!this._children || !this._childrenIndex) {
|
||||
this._children = [];
|
||||
this._childrenIndex = {};
|
||||
}
|
||||
|
||||
if( child.getParent() === this ) {
|
||||
//删除_children中保存的child引用
|
||||
//避免_children中保存多个child引用
|
||||
for(var i = 0, c; (c = this._children[i]); i++) {
|
||||
if(c === child) {
|
||||
this._children.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
this._childrenIndex[child.getId()] = child;
|
||||
this._children.splice(index, 0, child);
|
||||
|
||||
//closure没有这一步, 它的addChildAt方法只保证child在parent的子节点列表中,
|
||||
//不保证child的parent一定是this. 这里我尝试增加这种确定性.
|
||||
if(child._parent !== this) {
|
||||
child.setParent(this);
|
||||
}
|
||||
},
|
||||
|
||||
getChild : function(id) {
|
||||
if(id && this._childrenIndex) {
|
||||
return this._childrenIndex[id];
|
||||
}
|
||||
},
|
||||
|
||||
getChildAt : function(index) {
|
||||
if(this._children) {
|
||||
return this._children[index];
|
||||
}
|
||||
},
|
||||
|
||||
removeChild : function(child) {
|
||||
if(child) {
|
||||
var id;
|
||||
if( kampfer.type(child) === 'string' ) {
|
||||
id = child;
|
||||
child = this.getChild(id);
|
||||
} else {
|
||||
id = child.getId();
|
||||
}
|
||||
|
||||
for(var i = 0, c; (c = this._children[i]); i++) {
|
||||
if(c === child) {
|
||||
this._children.splice(i, 1);
|
||||
}
|
||||
}
|
||||
delete this._childrenIndex[id];
|
||||
|
||||
child.setParent(null);
|
||||
}
|
||||
|
||||
return child;
|
||||
},
|
||||
|
||||
removeChildAt : function(index) {
|
||||
this.remochild( this.getChildAt(index) );
|
||||
},
|
||||
|
||||
forEachChild : function(callback, context) {
|
||||
if(!this._children) {
|
||||
return;
|
||||
}
|
||||
for(var i = 0, child; (child = this._children[i]); i++) {
|
||||
if( calllback.call(context || child, child, i) === false ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
indexOfChild : function(child) {
|
||||
this.forEachChild(function(c, i) {
|
||||
if(c === child) {
|
||||
return i;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getChildCount : function() {
|
||||
if(this._children) {
|
||||
return this._children.length;
|
||||
}
|
||||
},
|
||||
|
||||
dispose : function() {
|
||||
kampfer.Composition.superClass.dispose.call(this);
|
||||
delete this._parent;
|
||||
delete this._children;
|
||||
delete this._childrenIndex;
|
||||
}
|
||||
});
|
||||
|
||||
kampfer.Composition.generateUniqueId = function() {
|
||||
var guid = "";
|
||||
for(var i = 1; i <= 32; i++) {
|
||||
var n = Math.floor(Math.random() * 16.0).toString(16);
|
||||
guid += n;
|
||||
if((i == 8) || (i == 12) || (i == 16) || (i == 20)) {
|
||||
guid += "-";
|
||||
}
|
||||
}
|
||||
return guid;
|
||||
};
|
||||
94
plugin/mindmap/edit-mindmap/vendor/js/kampfer/class/dialog.js
vendored
Normal file
94
plugin/mindmap/edit-mindmap/vendor/js/kampfer/class/dialog.js
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
kampfer.require('class.UIComponent');
|
||||
kampfer.require('dom');
|
||||
|
||||
kampfer.provide('Dialog');
|
||||
|
||||
kampfer.Dialog = kampfer.class.UIComponent.extend({
|
||||
initializer : function() {},
|
||||
|
||||
createDom : function() {
|
||||
kampfer.Dialog.superClass.createDom.call(this);
|
||||
var element = this.getElement();
|
||||
|
||||
//header
|
||||
this._headerElement = document.createElement('div');
|
||||
//title
|
||||
this._titleElement = document.createElement('h3');
|
||||
//close
|
||||
var closeButton = document.createElement('button');
|
||||
//body
|
||||
this._bodyElement = document.createElement('div');
|
||||
//footer
|
||||
this._footerElement = document.createElement('div');
|
||||
|
||||
this._headerElement.appendChild(closeButton);
|
||||
this._headerElement.appendChild(this._titleElement);
|
||||
element.appendChild(this._headerElement);
|
||||
element.appendChild(this._bodyElement);
|
||||
element.appendChild(this._footerElement);
|
||||
|
||||
kampfer.dom.addClass(this._element, 'modal');
|
||||
kampfer.dom.addClass(this._headerElement, 'modal-header');
|
||||
kampfer.dom.addClass(this._bodyElement, 'modal-body');
|
||||
kampfer.dom.addClass(this._footerElement, 'modal-footer');
|
||||
kampfer.dom.addClass(closeButton, 'close');
|
||||
|
||||
closeButton.innerHTML = 'x';
|
||||
closeButton.setAttribute('data-action', 'close');
|
||||
|
||||
if(!this._buttons) {
|
||||
this._footerElement.style.display = 'none';
|
||||
} else {
|
||||
for(var i = this._buttons.length - 1, buttonElment; (buttonElement = this._buttons[i]); i--) {
|
||||
kampfer.dom.addClass(buttonElement, 'btn');
|
||||
if(i === 0) {
|
||||
kampfer.dom.addClass(buttonElement, 'btn-primary');
|
||||
}
|
||||
this._footerElement.appendChild(buttonElement);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
setContent : function(html) {
|
||||
this._bodyElement.innerHTML = html;
|
||||
},
|
||||
|
||||
getContent : function(html) {
|
||||
return this._bodyElement.innerHTML;
|
||||
},
|
||||
|
||||
setTitle : function(title) {
|
||||
this._titleElement.innerHTML = title;
|
||||
},
|
||||
|
||||
//modal居中.但是bootstrap貌似直接定死了modal的宽度然后用样式居中.
|
||||
reposition : function() {
|
||||
var winWidth = Math.max(document.documentElement.offsetWidth, document.body.offsetWidth),
|
||||
winHeight = Math.max(document.documentElement.offsetHeight, document.body.offsetHeight);
|
||||
|
||||
this._element.style.left = kampfer.dom.scrollLeft(window) + winWidth / 2 -
|
||||
this._element.offsetWidth / 2 + 'px';
|
||||
this._element.style.top = kampfer.dom.scrollTop(window) + winHeight / 2 -
|
||||
this._element.offsetHeight / 2 + 'px';
|
||||
},
|
||||
|
||||
show : function() {
|
||||
if(!this._element) {
|
||||
this.render();
|
||||
}
|
||||
this._element.style.display = '';
|
||||
},
|
||||
|
||||
hide : function() {
|
||||
this._element.style.display = 'none';
|
||||
},
|
||||
|
||||
dispose : function() {
|
||||
kampfer.Dialog.superClass.dispose.call(this);
|
||||
delete this._titleElement;
|
||||
delete this._headerElement;
|
||||
delete this._bodyElement;
|
||||
delete this._buttons;
|
||||
delete this._footerElement;
|
||||
}
|
||||
});
|
||||
43
plugin/mindmap/edit-mindmap/vendor/js/kampfer/class/eventtarget.js
vendored
Normal file
43
plugin/mindmap/edit-mindmap/vendor/js/kampfer/class/eventtarget.js
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
kampfer.require('events');
|
||||
kampfer.require('Class');
|
||||
|
||||
kampfer.provide('events.EventTarget');
|
||||
|
||||
/*
|
||||
* 所有需要实现自定义事件的类都必须继承EventTarget类。
|
||||
*/
|
||||
|
||||
kampfer.events.EventTarget = kampfer.Class.extend({
|
||||
|
||||
_parentNode : null,
|
||||
|
||||
addListener : function(type, listener, context) {
|
||||
k.events.addListener(this, type, listener, context);
|
||||
},
|
||||
|
||||
removeListener : function(type, listener) {
|
||||
k.events.removeListener(this, type, listener);
|
||||
},
|
||||
|
||||
dispatch : function(type) {
|
||||
if(type) {
|
||||
var args = Array.prototype.slice.apply(arguments);
|
||||
args.unshift(this);
|
||||
k.events.dispatch.apply(null, args);
|
||||
}
|
||||
},
|
||||
|
||||
getParentEventTarget : function() {
|
||||
return this._parentNode;
|
||||
},
|
||||
|
||||
setParentEventTarget : function(obj) {
|
||||
this._parentNode = obj;
|
||||
},
|
||||
|
||||
dispose : function() {
|
||||
this._parentNode = null;
|
||||
k.events.removeListener(this);
|
||||
}
|
||||
|
||||
});
|
||||
150
plugin/mindmap/edit-mindmap/vendor/js/kampfer/class/uicomponent.js
vendored
Normal file
150
plugin/mindmap/edit-mindmap/vendor/js/kampfer/class/uicomponent.js
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
kampfer.require('class.Composition');
|
||||
kampfer.require('events');
|
||||
|
||||
kampfer.provide('class.UIComponent');
|
||||
|
||||
kampfer.class.UIComponent = kampfer.class.Composition.extend({
|
||||
_element : null,
|
||||
|
||||
_inDocument : false,
|
||||
|
||||
/**
|
||||
* @type {object}
|
||||
*/
|
||||
events : null,
|
||||
|
||||
isInDocument : function() {
|
||||
return this._inDocument;
|
||||
},
|
||||
|
||||
setElement : function() {
|
||||
this._element = element;
|
||||
},
|
||||
|
||||
getElement : function() {
|
||||
return this._element;
|
||||
},
|
||||
|
||||
createDom : function() {
|
||||
this._element = document.createElement('div');
|
||||
return this._element;
|
||||
},
|
||||
|
||||
//component有两种初始化的方式:
|
||||
//1.动态生成
|
||||
//2.传入已有dom,component解析
|
||||
//decorate方法就是针对第二种方式处理解析和预处理逻辑
|
||||
decorate : function(element) {},
|
||||
|
||||
enterDocument : function() {
|
||||
this._inDocument = true;
|
||||
|
||||
var that = this;
|
||||
if(this.events) {
|
||||
for(var attr in this.events) {
|
||||
kampfer.events.addListener(this._element, attr, this._transition, this);
|
||||
}
|
||||
}
|
||||
|
||||
this.walk('enterDocument');
|
||||
},
|
||||
|
||||
_transition : function(event) {
|
||||
var element = event.target,
|
||||
handlers = this.events[event.type],
|
||||
action = element.getAttribute('data-action');
|
||||
|
||||
while( !action && (element = element.parentNode) ) {
|
||||
if(element.getAttribute) {
|
||||
action = element.getAttribute('data-action');
|
||||
}
|
||||
}
|
||||
|
||||
if( !action || !handlers || !(action in handlers) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.target = element;
|
||||
|
||||
if(typeof handlers[action] === 'string') {
|
||||
handlers = handlers[action].split(' ');
|
||||
for(var i = 0, handle; (handle = handlers[i]); i++) {
|
||||
if( this[handle] && this[handle](event) === false ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if(typeof handlers[action] === 'function') {
|
||||
handlers[action].call(this, event);
|
||||
}
|
||||
},
|
||||
|
||||
exitDocument : function() {
|
||||
this._inDocument = true;
|
||||
|
||||
kampfer.events.removeListener(this._element);
|
||||
|
||||
this.walk('exitDocument');
|
||||
},
|
||||
|
||||
render : function(parentElement, beforeNode) {
|
||||
if(this._inDocument) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!this._element) {
|
||||
this.createDom();
|
||||
}
|
||||
|
||||
if(parentElement) {
|
||||
parentElement.insertBefore(this._element, beforeNode || null);
|
||||
} else {
|
||||
document.body.appendChild(this._element);
|
||||
}
|
||||
|
||||
//父component存在,但是它不在document中,那么子component不进入document
|
||||
if( !this._parent || this._parent.isInDocument() ) {
|
||||
this.enterDocument();
|
||||
}
|
||||
},
|
||||
|
||||
addChild : function(child, render) {
|
||||
this.addChildAt(child, this.getChildCount(), render);
|
||||
},
|
||||
|
||||
addChildAt : function(child, index, render) {
|
||||
kampfer.UIComponent.superClass.addChildAt.call(this, child, index);
|
||||
|
||||
if( child._inDocument && this._inDocument && child.getParent() === this ) {
|
||||
var parentElement = this.getElement();
|
||||
parentElement.insertBefore( child.getElement(),
|
||||
(parentElement.childNodes[index] || null) );
|
||||
} else if(render) {
|
||||
if (!this._element) {
|
||||
this.createDom();
|
||||
}
|
||||
var sibling = this.getChildAt(index + 1);
|
||||
child.render_(this.getElement(), sibling ? sibling._element : null);
|
||||
}
|
||||
},
|
||||
|
||||
removeChild : function(child, unrender) {
|
||||
kampfer.UIComponent.superClass.removeChild.call(this, child);
|
||||
|
||||
if(unrender) {
|
||||
child.exitDocument();
|
||||
if( child._element ) {
|
||||
child._element.parentNode.removeChild(child._element);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
removeChildAt : function(index, unrender) {
|
||||
this.remochild( this.getChildAt(index), unrender );
|
||||
},
|
||||
|
||||
dispose : function() {
|
||||
kampfer.UIComponent.superClass.dispose.call(this);
|
||||
this.exitDocument();
|
||||
delete this._element;
|
||||
}
|
||||
});
|
||||
255
plugin/mindmap/edit-mindmap/vendor/js/kampfer/data.js
vendored
Normal file
255
plugin/mindmap/edit-mindmap/vendor/js/kampfer/data.js
vendored
Normal file
@@ -0,0 +1,255 @@
|
||||
/*global kampfer*/
|
||||
|
||||
/**
|
||||
* 为对象管理数据
|
||||
* @module data
|
||||
* https://github.com/jquery/jquery/blob/master/src/data.js
|
||||
*/
|
||||
|
||||
kampfer.require('browser.support');
|
||||
|
||||
kampfer.provide('data');
|
||||
|
||||
//kampfer的数据缓存
|
||||
kampfer.data.cache = {};
|
||||
|
||||
//用于标记缓存的id
|
||||
kampfer.data.cacheId = 0;
|
||||
|
||||
//不能设置自定义属性的HTML tag名单
|
||||
kampfer.data.noData = {
|
||||
"embed": true,
|
||||
//object标签的clsid为以下值时可以设置自定义属性,
|
||||
//其他情况object也不能设置自定义属性
|
||||
"object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
|
||||
"applet": true
|
||||
};
|
||||
|
||||
/*
|
||||
* 判断对象是否能够设置自定义属性。所有plain object都能设置自定义属性,
|
||||
* 而html dom中:embed/applet无法设置,obeject只有当clsid为特定值时可以设置。
|
||||
* @param {object||html dom}elem
|
||||
* @return {boolean}
|
||||
*/
|
||||
kampfer.data.acceptData = function(elem) {
|
||||
if(kampfer.type(elem) === 'object') {
|
||||
if(elem.nodeName) {
|
||||
var match = kampfer.data.noData[ elem.nodeName.toLowerCase() ];
|
||||
if( match ) {
|
||||
return !(match === true || elem.getAttribute('classid') !== match);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* 判断数据对象是否为空。必须区分两种情况:
|
||||
* 1。用户的数据对象 所有用户的数据都储存在数据对象的data属性中。
|
||||
* 2。kampfer的数据对象 kampfer的数据会被直接储存在数据对象中。
|
||||
* @param {plain object}obj 这个对象一般取自kampfer.data.cache[expando]
|
||||
* 或者elem[expando]
|
||||
* @return {boolean}
|
||||
*/
|
||||
kampfer.data.isEmptyDataObj = function(obj) {
|
||||
for(var name in obj) {
|
||||
//检查用户定义的data(即cache.data)
|
||||
if( name === 'data' && kampfer.isEmptyObject(obj[name]) ) {
|
||||
continue;
|
||||
}
|
||||
if( name !== 'toJSON' ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
//判断对象是否储存了数据。此方法先取到elem的数据对象,
|
||||
//再调用kampfer.data.isEmptyDataObj判断对象是否为空
|
||||
kampfer.data.hasData = function(elem) {
|
||||
elem = elem.nodeType ?
|
||||
kampfer.data.cache[ elem[kampfer.expando] ] :
|
||||
elem[kampfer.expando];
|
||||
return !!elem && !kampfer.data.isEmptyDataObj(elem);
|
||||
};
|
||||
|
||||
/*
|
||||
* 写缓存. 只接受key-value形式的参数.
|
||||
* @param {object||html dom}elem
|
||||
* @param {string}name
|
||||
* @param {*}value
|
||||
* @param {boolean}internal
|
||||
* @return
|
||||
*/
|
||||
kampfer.data.setData = function(elem, name, value, internal) {
|
||||
if( !kampfer.data.acceptData(elem) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var expando = kampfer.expando,
|
||||
isNode = !!elem.nodeType,
|
||||
cache = isNode ? kampfer.data.cache : elem,
|
||||
cacheId = isNode ? elem[expando] : elem[expando] && expando,
|
||||
thisCache;
|
||||
|
||||
// 设置cacheId
|
||||
if(!cacheId) {
|
||||
if(isNode) {
|
||||
elem[expando] = cacheId = ++kampfer.data.cacheId;
|
||||
} else {
|
||||
cacheId = expando;
|
||||
}
|
||||
}
|
||||
|
||||
// 取得cache object
|
||||
if(!cache[cacheId]) {
|
||||
cache[cacheId] = {};
|
||||
}
|
||||
thisCache = cache[cacheId];
|
||||
// 区分内部调用和客户调用时数据的储存位置
|
||||
if(!internal) {
|
||||
if(!thisCache.data) {
|
||||
thisCache.data = {};
|
||||
}
|
||||
thisCache = thisCache.data;
|
||||
}
|
||||
|
||||
// 不做判断,直接覆盖旧值
|
||||
if(kampfer.type(name) === 'object') {
|
||||
thisCache = kampfer.extend(thisCache, name);
|
||||
} else if(value !== undefined) {
|
||||
thisCache[name] = value;
|
||||
}
|
||||
|
||||
return thisCache;
|
||||
};
|
||||
|
||||
/*
|
||||
* 读缓存。如果不提供name,直接返回整个cache。
|
||||
* @param {object||html dom}elem
|
||||
* @param {string}name option
|
||||
* @param {boolean}internal option
|
||||
* @return {*}
|
||||
*/
|
||||
kampfer.data.getData = function(elem, name, internal) {
|
||||
if( !kampfer.data.acceptData(elem) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var expando = kampfer.expando,
|
||||
isNode = !!elem.nodeType,
|
||||
cache = isNode ? kampfer.data.cache : elem,
|
||||
cacheId = isNode ? elem[expando] : elem[expando] && expando,
|
||||
hasName = kampfer.type(name) !== 'boolean' && name !== undefined,
|
||||
thisCache, ret;
|
||||
|
||||
if(!cacheId || !cache[cacheId]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!hasName) {
|
||||
internal = name;
|
||||
}
|
||||
|
||||
thisCache = cache[cacheId];
|
||||
if(!internal) {
|
||||
thisCache = thisCache.data || {};
|
||||
}
|
||||
|
||||
if(hasName) {
|
||||
ret = thisCache[name];
|
||||
} else {
|
||||
ret = thisCache;
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
/*
|
||||
* 删除缓存。如果不提供name,不执行任何操作。
|
||||
* @param {object||html dom}elem
|
||||
* @param {string}name
|
||||
* @param {boolean}internal option
|
||||
* @return void
|
||||
*/
|
||||
kampfer.data.removeData = function(elem, name, internal) {
|
||||
if( !kampfer.data.acceptData(elem) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var expando = kampfer.expando,
|
||||
isNode = !!elem.nodeType,
|
||||
cache = isNode ? kampfer.data.cache : elem,
|
||||
cacheId = isNode ? elem[expando] : elem[expando] && expando,
|
||||
hasName = kampfer.type(name) !== 'bool' && name !== undefined,
|
||||
thisCache;
|
||||
|
||||
if(!cacheId || !cache[cacheId] ||!hasName) {
|
||||
return;
|
||||
}
|
||||
|
||||
thisCache = cache[cacheId];
|
||||
if(!internal) {
|
||||
thisCache = thisCache.data;
|
||||
}
|
||||
|
||||
if(thisCache) {
|
||||
if(kampfer.type(name) !== 'array') {
|
||||
if(name in thisCache) {
|
||||
name = [name];
|
||||
}
|
||||
}
|
||||
for(var i = 0, n; n = name[i]; i++) {
|
||||
delete thisCache[n];
|
||||
}
|
||||
if( !kampfer.data.isEmptyDataObj(thisCache) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(!internal) {
|
||||
delete cache[cacheId].data;
|
||||
if( !kampfer.data.isEmptyDataObj( cache[cacheId] ) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 清空数据cache
|
||||
// as window.nodeType === undefined, so when elem === window isNode === false
|
||||
if ( kampfer.browser.support.deleteExpando || !cache.setInterval ) {
|
||||
delete cache[cacheId];
|
||||
} else {
|
||||
cache[cacheId] = null;
|
||||
}
|
||||
|
||||
// 清除html dom的expando
|
||||
if(isNode) {
|
||||
// IE does not allow us to delete expando properties from nodes,
|
||||
// nor does it have a removeAttribute function on Document nodes;
|
||||
// we must handle all of these cases
|
||||
if ( kampfer.browser.support.deleteExpando ) {
|
||||
delete elem[ expando ];
|
||||
} else if ( elem.removeAttribute ) {
|
||||
elem.removeAttribute( expando );
|
||||
} else {
|
||||
elem[ expando ] = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//kampfer内部调用
|
||||
kampfer.data.setDataInternal = function(elem, name, value) {
|
||||
kampfer.data.setData(elem, name, value, true);
|
||||
};
|
||||
|
||||
//kampfer内部调用
|
||||
kampfer.data.getDataInternal = function(elem, name) {
|
||||
return kampfer.data.getData(elem, name, true);
|
||||
};
|
||||
|
||||
//kampfer内部调用
|
||||
kampfer.data.removeDataInternal = function(elem, name) {
|
||||
kampfer.data.removeData(elem, name, true);
|
||||
};
|
||||
7
plugin/mindmap/edit-mindmap/vendor/js/kampfer/deps.js
vendored
Normal file
7
plugin/mindmap/edit-mindmap/vendor/js/kampfer/deps.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
kampfer.addDependency('ajax.js', ['ajax'], []);
|
||||
kampfer.addDependency('base.js', [], []);
|
||||
kampfer.addDependency('class.js', ['Class'], []);
|
||||
kampfer.addDependency('data.js', ['data'], ['browser.support']);
|
||||
kampfer.addDependency('events.js', ['events','events.Event','events.Listener'], ['data']);
|
||||
kampfer.addDependency('eventtarget.js', ['events.EventTarget'], ['events','Class']);
|
||||
kampfer.addDependency('support.js', ['browser.support'], []);
|
||||
165
plugin/mindmap/edit-mindmap/vendor/js/kampfer/dom.js
vendored
Normal file
165
plugin/mindmap/edit-mindmap/vendor/js/kampfer/dom.js
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
/*global kampfer*/
|
||||
kampfer.provide('dom');
|
||||
|
||||
kampfer.dom.create = function(name) {
|
||||
return kampfer.global.document.createElement(name);
|
||||
};
|
||||
|
||||
kampfer.dom.addClass = function(elem, value) {
|
||||
|
||||
var classNames, i, l,
|
||||
setClass, c, cl;
|
||||
|
||||
if ( value && typeof value === "string" ) {
|
||||
classNames = value.split( /\s+/ );
|
||||
|
||||
if ( elem.nodeType === 1 ) {
|
||||
if ( !elem.className && classNames.length === 1 ) {
|
||||
elem.className = value;
|
||||
|
||||
} else {
|
||||
setClass = " " + elem.className + " ";
|
||||
|
||||
for ( c = 0, cl = classNames.length; c < cl; c++ ) {
|
||||
if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) {
|
||||
setClass += classNames[ c ] + " ";
|
||||
}
|
||||
}
|
||||
elem.className = setClass.trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
kampfer.dom.removeClass = function(elem, value) {
|
||||
|
||||
var classNames, i, l, className, c, cl;
|
||||
|
||||
if ( (value && typeof value === "string") || value === undefined ) {
|
||||
classNames = ( value || "" ).split( /\s+/ );
|
||||
|
||||
if ( elem.nodeType === 1 && elem.className ) {
|
||||
if ( value ) {
|
||||
className = (" " + elem.className + " ").replace( /[\n\t\r]/g, " " );
|
||||
for ( c = 0, cl = classNames.length; c < cl; c++ ) {
|
||||
className = className.replace(" " + classNames[ c ] + " ", " ");
|
||||
}
|
||||
//elem.className = kampfer.string.trim( className );
|
||||
elem.className = className.trim();
|
||||
} else {
|
||||
elem.className = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
kampfer.dom.getComputedStyle = function(element, property) {
|
||||
var doc = kampfer.global.document;
|
||||
if(doc.defaultView && doc.defaultView.getComputedStyle) {
|
||||
var styles = doc.defaultView.getComputedStyle(element, null);
|
||||
if(styles) {
|
||||
// element.style[..] is undefined for browser specific styles
|
||||
// as 'filter'.
|
||||
return styles[property] || styles.getPropertyValue(property);
|
||||
}
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
|
||||
//for IE
|
||||
kampfer.dom.getCascadedStyle = function(element, style) {
|
||||
return element.currentStyle ? element.currentStyle[style] : null;
|
||||
};
|
||||
|
||||
|
||||
kampfer.dom.getStyle = function(element, style) {
|
||||
return kampfer.dom.getComputedStyle(element, style) ||
|
||||
kampfer.dom.getCascadedStyle(element, style) ||
|
||||
element.style[style];
|
||||
};
|
||||
|
||||
|
||||
//需要输入正确的javascript格式名
|
||||
//TODO 处理样式名
|
||||
kampfer.dom.setStyle = function(element, name, value) {
|
||||
if( kampfer.isDefAndNotNull(value) &&
|
||||
kampfer.type(name) === 'string' ) {
|
||||
element.style[name] = value;
|
||||
} else if( kampfer.isObject(name) ) {
|
||||
for(var attr in name) {
|
||||
kampfer.dom.setStyle(element, attr, name[attr]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// http://code.jquery.com/jquery-1.8.3.js
|
||||
kampfer.dom.getWindow = function(elem) {
|
||||
return kampfer.isWindow(elem) ?
|
||||
elem :
|
||||
elem.nodeType === 9 ?
|
||||
elem.defaultView || elem.parentWindow :
|
||||
false;
|
||||
};
|
||||
|
||||
|
||||
// http://code.jquery.com/jquery-1.8.3.js
|
||||
kampfer.dom.scrollLeft = function(elem, val) {
|
||||
var win = kampfer.dom.getWindow( elem ),
|
||||
prop = 'pageXOffset',
|
||||
method = 'scrollLeft';
|
||||
|
||||
if ( val === undefined ) {
|
||||
return win ? (prop in win) ? win[ prop ] :
|
||||
win.document.documentElement[ method ] :
|
||||
elem[ method ];
|
||||
}
|
||||
|
||||
if ( win ) {
|
||||
win.scrollTo( val, kampfer.dom.scrollTop( win ));
|
||||
} else {
|
||||
elem[ method ] = val;
|
||||
}
|
||||
};
|
||||
|
||||
// http://code.jquery.com/jquery-1.8.3.js
|
||||
kampfer.dom.scrollTop = function(elem, val) {
|
||||
var win = kampfer.dom.getWindow( elem ),
|
||||
prop = 'pageYOffset',
|
||||
method = 'scrollTop';
|
||||
|
||||
if ( val === undefined ) {
|
||||
return win ? (prop in win) ? win[ prop ] :
|
||||
win.document.documentElement[ method ] :
|
||||
elem[ method ];
|
||||
}
|
||||
|
||||
if ( win ) {
|
||||
win.scrollTo( kampfer.dom.scrollLeft( win ), val);
|
||||
} else {
|
||||
elem[ method ] = val;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//http://www.cnblogs.com/rubylouvre/archive/2011/05/30/1583523.html
|
||||
kampfer.dom.contains = function(parent, child) {
|
||||
if(parent.compareDocumentPosition) {
|
||||
return parent === child || !!(parent.compareDocumentPosition(child) & 16);
|
||||
}
|
||||
|
||||
if(parent.contains && child.nodeType === 1) {
|
||||
return parent.contains(child) && parent !== child;
|
||||
}
|
||||
|
||||
while( (child = child.parentNode) ) {
|
||||
if(child === parent) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
468
plugin/mindmap/edit-mindmap/vendor/js/kampfer/events.js
vendored
Normal file
468
plugin/mindmap/edit-mindmap/vendor/js/kampfer/events.js
vendored
Normal file
@@ -0,0 +1,468 @@
|
||||
/*global kampfer*/
|
||||
kampfer.require('data');
|
||||
|
||||
kampfer.provide('events');
|
||||
kampfer.provide('events.Event');
|
||||
kampfer.provide('events.Listener');
|
||||
|
||||
|
||||
/*
|
||||
* 包裹浏览器event对象,提供统一的、跨浏览器的接口。
|
||||
* 新的对象将包含以下接口:
|
||||
* - type {string} 事件种类
|
||||
* - target {object} 触发事件的对象
|
||||
* - relatedTarget {object} 鼠标事件mouseover和mouseout的修正
|
||||
* - currentTarget {object}
|
||||
* - stopPropagation {function} 阻止冒泡
|
||||
* - preventDefault {function} 阻止默认行为
|
||||
* - dispose {function}
|
||||
* - which {number}
|
||||
* - pageX/pageY {number}
|
||||
*/
|
||||
kampfer.events.Event = function(src, props) {
|
||||
var srcType = kampfer.type(src);
|
||||
|
||||
if(srcType === 'object' && src.type) {
|
||||
this.src = src;
|
||||
this.type = src.type;
|
||||
} else if(srcType === 'string') {
|
||||
this.type = src;
|
||||
}
|
||||
|
||||
if(kampfer.type(props) === 'object') {
|
||||
kampfer.extend(this, props);
|
||||
}
|
||||
|
||||
this.isImmediatePropagationStopped = false;
|
||||
this.propagationStopped = false;
|
||||
this.isDefaultPrevented = false;
|
||||
|
||||
this[kampfer.expando] = true;
|
||||
};
|
||||
|
||||
kampfer.events.Event.prototype = {
|
||||
constructor : kampfer.events.Event,
|
||||
|
||||
//停止冒泡
|
||||
stopPropagation : function() {
|
||||
//触发事件时,需要读取propagationStopped,判断冒泡是否取消。
|
||||
this.propagationStopped = true;
|
||||
|
||||
var e = this.src;
|
||||
if(!e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(e.stopPropagation) {
|
||||
e.stopPropagation();
|
||||
} else {
|
||||
e.cancelBubble = true;
|
||||
}
|
||||
},
|
||||
|
||||
//立即停止冒泡
|
||||
stopImmediatePropagation : function() {
|
||||
this.isImmediatePropagationStopped = true;
|
||||
this.stopPropagation();
|
||||
},
|
||||
|
||||
//阻止默认行为
|
||||
preventDefault : function() {
|
||||
this.isDefaultPrevented = true;
|
||||
|
||||
var e = this.src;
|
||||
if(!e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.preventDefault) {
|
||||
e.preventDefault();
|
||||
} else {
|
||||
e.returnValue = false;
|
||||
}
|
||||
},
|
||||
|
||||
dispose : function() {
|
||||
delete this.src;
|
||||
}
|
||||
};
|
||||
|
||||
//所有事件对象都拥有下面的属性
|
||||
kampfer.events.Event.props = 'altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which'.split(' ');
|
||||
|
||||
//键盘事件对象拥有下面的属性
|
||||
kampfer.events.Event.keyProps = 'char charCode key keyCode'.split(' ');
|
||||
|
||||
//鼠标事件对象拥有下面的属性
|
||||
kampfer.events.Event.mouseProps = 'button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement'.split(' ');
|
||||
|
||||
|
||||
/*
|
||||
* 修复event,处理兼容性问题
|
||||
* @param {object||string}event
|
||||
* @return {object} 修复的event对象
|
||||
*/
|
||||
kampfer.events.fixEvent = function(event) {
|
||||
if( event[kampfer.expando] ) {
|
||||
return event;
|
||||
}
|
||||
|
||||
var oriEvent = event;
|
||||
|
||||
event = new kampfer.events.Event(oriEvent);
|
||||
|
||||
kampfer.each(kampfer.events.Event.props, function(i, prop) {
|
||||
event[prop] = oriEvent[prop];
|
||||
});
|
||||
|
||||
if(!event.target) {
|
||||
event.target = oriEvent.srcElement || document;
|
||||
}
|
||||
|
||||
// Target should not be a text node (jQuery bugs#504, Safari)
|
||||
if(event.target.nodeType === 3) {
|
||||
event.target = event.target.parentNode;
|
||||
}
|
||||
|
||||
event.currentTarget = null;
|
||||
|
||||
// ie不支持metaKey, 设置值为false
|
||||
event.metaKey = !!event.metaKey;
|
||||
|
||||
//修复鼠标事件之前必须保证event.target存在
|
||||
if( kampfer.events.isKeyEvent(event.type) ) {
|
||||
kampfer.events.fixKeyEvent(event, oriEvent);
|
||||
} else {
|
||||
kampfer.events.fixMouseEvent(event, oriEvent);
|
||||
}
|
||||
|
||||
return event;
|
||||
};
|
||||
|
||||
//判断事件是否为键盘事件
|
||||
kampfer.events.isKeyEvent = function(type) {
|
||||
return /^key/.test(type);
|
||||
};
|
||||
|
||||
//判断事件是否为鼠标事件
|
||||
kampfer.events.isMouseEvent = function(type) {
|
||||
return /^(?:mouse|contextmenu)|click/.test(type);
|
||||
};
|
||||
|
||||
//修复鼠标键盘对象
|
||||
kampfer.events.fixKeyEvent = function(event, oriEvent) {
|
||||
kampfer.each(kampfer.events.Event.keyProps, function(i, prop) {
|
||||
event[prop] = oriEvent[prop];
|
||||
});
|
||||
|
||||
// Add which for key events
|
||||
if ( event.which == null ) {
|
||||
event.which = oriEvent.charCode != null ? oriEvent.charCode : oriEvent.keyCode;
|
||||
}
|
||||
|
||||
return event;
|
||||
};
|
||||
|
||||
//修复鼠标事件对象
|
||||
kampfer.events.fixMouseEvent = function(event, oriEvent) {
|
||||
kampfer.each(kampfer.events.Event.mouseProps, function(i, prop) {
|
||||
event[prop] = oriEvent[prop];
|
||||
});
|
||||
|
||||
var eventDoc, doc, body,
|
||||
button = oriEvent.button,
|
||||
fromElement = oriEvent.fromElement;
|
||||
|
||||
// Calculate pageX/Y if missing and clientX/Y available
|
||||
if ( event.pageX == null && oriEvent.clientX != null ) {
|
||||
eventDoc = event.target.ownerDocument || document;
|
||||
doc = eventDoc.documentElement;
|
||||
body = eventDoc.body;
|
||||
|
||||
event.pageX = oriEvent.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) -
|
||||
( doc && doc.clientLeft || body && body.clientLeft || 0 );
|
||||
event.pageY = oriEvent.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) -
|
||||
( doc && doc.clientTop || body && body.clientTop || 0 );
|
||||
}
|
||||
|
||||
// Add relatedTarget, if necessary
|
||||
if ( !event.relatedTarget && fromElement ) {
|
||||
event.relatedTarget = fromElement === event.target ? oriEvent.toElement : fromElement;
|
||||
}
|
||||
|
||||
// Add which for click: 1 === left; 2 === middle; 3 === right
|
||||
// Note: button is not normalized, so don't use it
|
||||
if ( !event.which && button !== undefined ) {
|
||||
event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
|
||||
}
|
||||
|
||||
return event;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* 生成handler的一个包裹对象,记录一些额外信息,并且生成一个唯一的key值
|
||||
* @param {function}handler
|
||||
* @param {string}type
|
||||
* @param {object}scope
|
||||
*/
|
||||
kampfer.events.Listener = function(listener, eventType, context) {
|
||||
this.listener = listener;
|
||||
this.eventType = eventType;
|
||||
this.context = context;
|
||||
this.key = kampfer.events.Listener.key++;
|
||||
};
|
||||
|
||||
//销毁对象中指向其他对象的引用
|
||||
kampfer.events.Listener.prototype.dispose = function() {
|
||||
this.listener = null;
|
||||
this.context = null;
|
||||
};
|
||||
|
||||
kampfer.events.Listener.key = 0;
|
||||
|
||||
|
||||
/*
|
||||
* 添加事件
|
||||
* @param {object}elem
|
||||
* @param {string||array}eventType
|
||||
* @param {function}listener
|
||||
* @param {object}context
|
||||
*/
|
||||
kampfer.events.addListener = function(elem, eventType, listener, context) {
|
||||
// filter commet and text node
|
||||
// nor undefined eventType or listener
|
||||
if( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !eventType ||
|
||||
kampfer.type(listener) !== 'function' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var type = kampfer.type(eventType);
|
||||
|
||||
if( type === 'array' ) {
|
||||
for(var i = 0, e; e = eventType[i]; i++) {
|
||||
kampfer.events.addListener(elem, e, listener, context);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if( type === 'string') {
|
||||
var listenerObj = new kampfer.events.Listener(listener, eventType, context || elem);
|
||||
|
||||
var events = kampfer.data.getDataInternal(elem, 'events');
|
||||
if(!events) {
|
||||
events = {};
|
||||
kampfer.data.setDataInternal(elem, 'events', events);
|
||||
}
|
||||
|
||||
if(!events.proxy) {
|
||||
events.proxy = function(e) {
|
||||
if(kampfer.events.triggered !== e.type) {
|
||||
return kampfer.events.dispatchEvent.apply(events.proxy.elem, arguments);
|
||||
}
|
||||
};
|
||||
events.proxy.elem = elem;
|
||||
}
|
||||
|
||||
if(!events.listeners) {
|
||||
events.listeners = {};
|
||||
}
|
||||
|
||||
if(!events.listeners[eventType]) {
|
||||
events.listeners[eventType] = [];
|
||||
|
||||
//events.listeners[eventType]不存在说明没有绑定过此事件
|
||||
if(elem.addEventListener) {
|
||||
elem.addEventListener(eventType, events.proxy, false);
|
||||
} else if(elem.attachEvent) {
|
||||
elem.attachEvent('on' + eventType, events.proxy);
|
||||
}
|
||||
}
|
||||
|
||||
events.listeners[eventType].push(listenerObj);
|
||||
}
|
||||
|
||||
// fix ie memory leak
|
||||
elem = null;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* 删除事件。此方法用于删除绑定在某类事件下的全部操作。
|
||||
* @param {object}elem
|
||||
* @param {string}eventType
|
||||
*/
|
||||
kampfer.events.removeListener = function(elem, eventType, listener) {
|
||||
var events = kampfer.data.getDataInternal(elem, 'events');
|
||||
|
||||
if( !events || !events.listeners ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var type = kampfer.type(eventType);
|
||||
|
||||
if(type === 'array') {
|
||||
for(var i = 0; type = eventType[0]; i++) {
|
||||
kampfer.events.removeListener(elem, type, listener);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(type === 'undefined') {
|
||||
for(type in events.listeners) {
|
||||
kampfer.events.removeListener(elem, type, listener);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(type === 'string') {
|
||||
for(var i = 0, l; l = events.listeners[eventType][i]; i++) {
|
||||
if( !listener || (l.eventType === eventType && l.listener === listener) ) {
|
||||
// 注意splice会改变数组长度以及元素对应的下标
|
||||
events.listeners[eventType].splice(i--, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if(!events.listeners[eventType].length) {
|
||||
if(elem.removeEventListener) {
|
||||
elem.removeEventListener(eventType, events.proxy, false);
|
||||
} else if(elem.detachEvent) {
|
||||
elem.detachEvent('on' + eventType, events.proxy);
|
||||
}
|
||||
delete events.listeners[eventType];
|
||||
}
|
||||
|
||||
if( kampfer.isEmptyObject(events.listeners) ) {
|
||||
delete events.listeners;
|
||||
delete events.proxy;
|
||||
kampfer.data.removeDataInternal(elem, 'events');
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* 触发对象的指定事件
|
||||
* @param {object}elem
|
||||
* @param {string||array}eventType
|
||||
*/
|
||||
kampfer.events.dispatch = function(elem, event) {
|
||||
if(elem.nodeType === 3 || elem.nodeType === 8 || !event) {
|
||||
return;
|
||||
}
|
||||
|
||||
var eventType = event.type || event,
|
||||
args = Array.prototype.slice.call(arguments),
|
||||
bubblePath = [],
|
||||
onType = 'on' + eventType;
|
||||
|
||||
if(typeof event === 'object') {
|
||||
if( !event[kampfer.expando] ) {
|
||||
event = new kampfer.events.Event(eventType, event);
|
||||
}
|
||||
} else {
|
||||
event = new kampfer.events.Event(event);
|
||||
}
|
||||
|
||||
args = Array.prototype.slice.call(arguments, 2);
|
||||
args.unshift(event);
|
||||
|
||||
// event.target始终指向事件的起点对象
|
||||
if(!event.target) {
|
||||
event.target = elem;
|
||||
}
|
||||
|
||||
//建立冒泡的dom树路径
|
||||
for(var cur = elem; cur; cur = cur.parentNode) {
|
||||
bubblePath.push(cur);
|
||||
}
|
||||
//W3C标准中事件冒泡的终点时document,而jQuery.trigger会冒泡到window
|
||||
//这里有必要跟jQuery一样吗????
|
||||
//冒泡的最后一站始终是window对象
|
||||
if( cur === (elem.ownerDocument || document) ) {
|
||||
bubblePath.push(elem.defaultView || elem.parentWindow || window);
|
||||
}
|
||||
|
||||
for(i = 0; cur = !event.propagationStopped && bubblePath[i]; i++) {
|
||||
|
||||
var eventsObj = kampfer.data.getDataInternal(cur, 'events');
|
||||
|
||||
if( !eventsObj || !eventsObj.listeners[eventType] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 冒泡的每一阶段currentTarget都不同
|
||||
event.currentTarget = cur;
|
||||
|
||||
// 执行kampfer绑定的事件处理函数
|
||||
var proxy = eventsObj.proxy;
|
||||
proxy.apply(cur, args);
|
||||
|
||||
// 执行使用行内方式绑定的事件处理函数
|
||||
proxy = cur[onType];
|
||||
if(proxy && proxy.apply(cur, args) === false) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 触发浏览器default action
|
||||
if(!event.isDefaultPrevented && !kampfer.isWindow(elem) && elem[eventType]) {
|
||||
var old = elem[onType];
|
||||
if(old) {
|
||||
elem[onType] = null;
|
||||
}
|
||||
|
||||
kampfer.events.triggered = eventType;
|
||||
try {
|
||||
elem[eventType]();
|
||||
} catch(e) {}
|
||||
delete kampfer.events.triggered;
|
||||
|
||||
if(old) {
|
||||
elem[onType] = old;
|
||||
}
|
||||
}
|
||||
|
||||
return event.result;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 正确的将一个事件派发给所有相关对象
|
||||
*/
|
||||
kampfer.events.dispatchEvent = function(event) {
|
||||
event = kampfer.events.fixEvent(event);
|
||||
|
||||
// ie6/7/8不支持event.currentTarget 于是无法使用解决this的问题
|
||||
var eventsObj = kampfer.data.getDataInternal(this, 'events'),
|
||||
listeners = eventsObj && eventsObj.listeners[event.type],
|
||||
args = Array.prototype.slice.call(arguments);
|
||||
|
||||
if(!listeners) {
|
||||
return;
|
||||
}
|
||||
|
||||
// fix currentTarget in ie6/7/8
|
||||
event.currentTarget = this;
|
||||
|
||||
for(var i = 0, l; l = listeners[i]; i++) {
|
||||
event.result = l.listener.apply(l.context, args);
|
||||
if(event.result === false) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
if(event.isImmediatePropagationStopped) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// for beforeunload on firefox
|
||||
if(event.result !== undefined && event.src) {
|
||||
event.src.returnValue = event.result;
|
||||
}
|
||||
|
||||
return event.result;
|
||||
};
|
||||
43
plugin/mindmap/edit-mindmap/vendor/js/kampfer/eventtarget.js
vendored
Normal file
43
plugin/mindmap/edit-mindmap/vendor/js/kampfer/eventtarget.js
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
kampfer.require('events');
|
||||
kampfer.require('Class');
|
||||
|
||||
kampfer.provide('events.EventTarget');
|
||||
|
||||
/*
|
||||
* 所有需要实现自定义事件的类都必须继承EventTarget类。
|
||||
*/
|
||||
|
||||
kampfer.events.EventTarget = kampfer.Class.extend({
|
||||
|
||||
parentNode : null,
|
||||
|
||||
addListener : function(type, listener, context) {
|
||||
k.events.addListener(this, type, listener, context);
|
||||
},
|
||||
|
||||
removeListener : function(type, listener) {
|
||||
k.events.removeListener(this, type, listener);
|
||||
},
|
||||
|
||||
dispatch : function(type) {
|
||||
if(type) {
|
||||
var args = Array.prototype.slice.apply(arguments);
|
||||
args.unshift(this);
|
||||
k.events.dispatch.apply(null, args);
|
||||
}
|
||||
},
|
||||
|
||||
getParentEventTarget : function() {
|
||||
return this.parentNode;
|
||||
},
|
||||
|
||||
setParentEventTarget : function(obj) {
|
||||
this.parentNode = obj;
|
||||
},
|
||||
|
||||
dispose : function() {
|
||||
this.parentNode = null;
|
||||
k.events.removeListener(this);
|
||||
}
|
||||
|
||||
});
|
||||
981
plugin/mindmap/edit-mindmap/vendor/js/kampfer/helper/es5-shim.js
vendored
Normal file
981
plugin/mindmap/edit-mindmap/vendor/js/kampfer/helper/es5-shim.js
vendored
Normal file
@@ -0,0 +1,981 @@
|
||||
// Copyright 2009-2012 by contributors, MIT License
|
||||
// vim: ts=4 sts=4 sw=4 expandtab
|
||||
|
||||
// Module systems magic dance
|
||||
(function (definition) {
|
||||
// RequireJS
|
||||
if (typeof define == "function") {
|
||||
define(definition);
|
||||
// YUI3
|
||||
} else if (typeof YUI == "function") {
|
||||
YUI.add("es5", definition);
|
||||
// CommonJS and <script>
|
||||
} else {
|
||||
definition();
|
||||
}
|
||||
})(function () {
|
||||
|
||||
/**
|
||||
* Brings an environment as close to ECMAScript 5 compliance
|
||||
* as is possible with the facilities of erstwhile engines.
|
||||
*
|
||||
* Annotated ES5: http://es5.github.com/ (specific links below)
|
||||
* ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
|
||||
* Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
|
||||
*/
|
||||
|
||||
//
|
||||
// Function
|
||||
// ========
|
||||
//
|
||||
|
||||
// ES-5 15.3.4.5
|
||||
// http://es5.github.com/#x15.3.4.5
|
||||
|
||||
function Empty() {}
|
||||
|
||||
if (!Function.prototype.bind) {
|
||||
Function.prototype.bind = function bind(that) { // .length is 1
|
||||
// 1. Let Target be the this value.
|
||||
var target = this;
|
||||
// 2. If IsCallable(Target) is false, throw a TypeError exception.
|
||||
if (typeof target != "function") {
|
||||
throw new TypeError("Function.prototype.bind called on incompatible " + target);
|
||||
}
|
||||
// 3. Let A be a new (possibly empty) internal list of all of the
|
||||
// argument values provided after thisArg (arg1, arg2 etc), in order.
|
||||
// XXX slicedArgs will stand in for "A" if used
|
||||
var args = slice.call(arguments, 1); // for normal call
|
||||
// 4. Let F be a new native ECMAScript object.
|
||||
// 11. Set the [[Prototype]] internal property of F to the standard
|
||||
// built-in Function prototype object as specified in 15.3.3.1.
|
||||
// 12. Set the [[Call]] internal property of F as described in
|
||||
// 15.3.4.5.1.
|
||||
// 13. Set the [[Construct]] internal property of F as described in
|
||||
// 15.3.4.5.2.
|
||||
// 14. Set the [[HasInstance]] internal property of F as described in
|
||||
// 15.3.4.5.3.
|
||||
var bound = function () {
|
||||
|
||||
if (this instanceof bound) {
|
||||
// 15.3.4.5.2 [[Construct]]
|
||||
// When the [[Construct]] internal method of a function object,
|
||||
// F that was created using the bind function is called with a
|
||||
// list of arguments ExtraArgs, the following steps are taken:
|
||||
// 1. Let target be the value of F's [[TargetFunction]]
|
||||
// internal property.
|
||||
// 2. If target has no [[Construct]] internal method, a
|
||||
// TypeError exception is thrown.
|
||||
// 3. Let boundArgs be the value of F's [[BoundArgs]] internal
|
||||
// property.
|
||||
// 4. Let args be a new list containing the same values as the
|
||||
// list boundArgs in the same order followed by the same
|
||||
// values as the list ExtraArgs in the same order.
|
||||
// 5. Return the result of calling the [[Construct]] internal
|
||||
// method of target providing args as the arguments.
|
||||
|
||||
var result = target.apply(
|
||||
this,
|
||||
args.concat(slice.call(arguments))
|
||||
);
|
||||
if (Object(result) === result) {
|
||||
return result;
|
||||
}
|
||||
return this;
|
||||
|
||||
} else {
|
||||
// 15.3.4.5.1 [[Call]]
|
||||
// When the [[Call]] internal method of a function object, F,
|
||||
// which was created using the bind function is called with a
|
||||
// this value and a list of arguments ExtraArgs, the following
|
||||
// steps are taken:
|
||||
// 1. Let boundArgs be the value of F's [[BoundArgs]] internal
|
||||
// property.
|
||||
// 2. Let boundThis be the value of F's [[BoundThis]] internal
|
||||
// property.
|
||||
// 3. Let target be the value of F's [[TargetFunction]] internal
|
||||
// property.
|
||||
// 4. Let args be a new list containing the same values as the
|
||||
// list boundArgs in the same order followed by the same
|
||||
// values as the list ExtraArgs in the same order.
|
||||
// 5. Return the result of calling the [[Call]] internal method
|
||||
// of target providing boundThis as the this value and
|
||||
// providing args as the arguments.
|
||||
|
||||
// equiv: target.call(this, ...boundArgs, ...args)
|
||||
return target.apply(
|
||||
that,
|
||||
args.concat(slice.call(arguments))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
if(target.prototype) {
|
||||
Empty.prototype = target.prototype;
|
||||
bound.prototype = new Empty();
|
||||
// Clean up dangling references.
|
||||
Empty.prototype = null;
|
||||
}
|
||||
// XXX bound.length is never writable, so don't even try
|
||||
//
|
||||
// 15. If the [[Class]] internal property of Target is "Function", then
|
||||
// a. Let L be the length property of Target minus the length of A.
|
||||
// b. Set the length own property of F to either 0 or L, whichever is
|
||||
// larger.
|
||||
// 16. Else set the length own property of F to 0.
|
||||
// 17. Set the attributes of the length own property of F to the values
|
||||
// specified in 15.3.5.1.
|
||||
|
||||
// TODO
|
||||
// 18. Set the [[Extensible]] internal property of F to true.
|
||||
|
||||
// TODO
|
||||
// 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
|
||||
// 20. Call the [[DefineOwnProperty]] internal method of F with
|
||||
// arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
|
||||
// thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
|
||||
// false.
|
||||
// 21. Call the [[DefineOwnProperty]] internal method of F with
|
||||
// arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
|
||||
// [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
|
||||
// and false.
|
||||
|
||||
// TODO
|
||||
// NOTE Function objects created using Function.prototype.bind do not
|
||||
// have a prototype property or the [[Code]], [[FormalParameters]], and
|
||||
// [[Scope]] internal properties.
|
||||
// XXX can't delete prototype in pure-js.
|
||||
|
||||
// 22. Return F.
|
||||
return bound;
|
||||
};
|
||||
}
|
||||
|
||||
// Shortcut to an often accessed properties, in order to avoid multiple
|
||||
// dereference that costs universally.
|
||||
// _Please note: Shortcuts are defined after `Function.prototype.bind` as we
|
||||
// us it in defining shortcuts.
|
||||
var call = Function.prototype.call;
|
||||
var prototypeOfArray = Array.prototype;
|
||||
var prototypeOfObject = Object.prototype;
|
||||
var slice = prototypeOfArray.slice;
|
||||
// Having a toString local variable name breaks in Opera so use _toString.
|
||||
var _toString = call.bind(prototypeOfObject.toString);
|
||||
var owns = call.bind(prototypeOfObject.hasOwnProperty);
|
||||
|
||||
// If JS engine supports accessors creating shortcuts.
|
||||
var defineGetter;
|
||||
var defineSetter;
|
||||
var lookupGetter;
|
||||
var lookupSetter;
|
||||
var supportsAccessors;
|
||||
if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
|
||||
defineGetter = call.bind(prototypeOfObject.__defineGetter__);
|
||||
defineSetter = call.bind(prototypeOfObject.__defineSetter__);
|
||||
lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
|
||||
lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
|
||||
}
|
||||
|
||||
//
|
||||
// Array
|
||||
// =====
|
||||
//
|
||||
|
||||
// ES5 15.4.4.12
|
||||
// http://es5.github.com/#x15.4.4.12
|
||||
// Default value for second param
|
||||
// [bugfix, ielt9, old browsers]
|
||||
// IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12"
|
||||
if ([1,2].splice(0).length != 2) {
|
||||
var array_splice = Array.prototype.splice;
|
||||
Array.prototype.splice = function(start, deleteCount) {
|
||||
if (!arguments.length) {
|
||||
return [];
|
||||
} else {
|
||||
return array_splice.apply(this, [
|
||||
start === void 0 ? 0 : start,
|
||||
deleteCount === void 0 ? (this.length - start) : deleteCount
|
||||
].concat(slice.call(arguments, 2)))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// ES5 15.4.4.12
|
||||
// http://es5.github.com/#x15.4.4.13
|
||||
// Return len+argCount.
|
||||
// [bugfix, ielt8]
|
||||
// IE < 8 bug: [].unshift(0) == undefined but should be "1"
|
||||
if ([].unshift(0) != 1) {
|
||||
var array_unshift = Array.prototype.unshift;
|
||||
Array.prototype.unshift = function() {
|
||||
array_unshift.apply(this, arguments);
|
||||
return this.length;
|
||||
};
|
||||
}
|
||||
|
||||
// ES5 15.4.3.2
|
||||
// http://es5.github.com/#x15.4.3.2
|
||||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
|
||||
if (!Array.isArray) {
|
||||
Array.isArray = function isArray(obj) {
|
||||
return _toString(obj) == "[object Array]";
|
||||
};
|
||||
}
|
||||
|
||||
// The IsCallable() check in the Array functions
|
||||
// has been replaced with a strict check on the
|
||||
// internal class of the object to trap cases where
|
||||
// the provided function was actually a regular
|
||||
// expression literal, which in V8 and
|
||||
// JavaScriptCore is a typeof "function". Only in
|
||||
// V8 are regular expression literals permitted as
|
||||
// reduce parameters, so it is desirable in the
|
||||
// general case for the shim to match the more
|
||||
// strict and common behavior of rejecting regular
|
||||
// expressions.
|
||||
|
||||
// ES5 15.4.4.18
|
||||
// http://es5.github.com/#x15.4.4.18
|
||||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
|
||||
|
||||
// Check failure of by-index access of string characters (IE < 9)
|
||||
// and failure of `0 in boxedString` (Rhino)
|
||||
var boxedString = Object("a"),
|
||||
splitString = boxedString[0] != "a" || !(0 in boxedString);
|
||||
|
||||
if (!Array.prototype.forEach) {
|
||||
Array.prototype.forEach = function forEach(fun /*, thisp*/) {
|
||||
var object = toObject(this),
|
||||
self = splitString && _toString(this) == "[object String]" ?
|
||||
this.split("") :
|
||||
object,
|
||||
thisp = arguments[1],
|
||||
i = -1,
|
||||
length = self.length >>> 0;
|
||||
|
||||
// If no callback function or if callback is not a callable function
|
||||
if (_toString(fun) != "[object Function]") {
|
||||
throw new TypeError(); // TODO message
|
||||
}
|
||||
|
||||
while (++i < length) {
|
||||
if (i in self) {
|
||||
// Invoke the callback function with call, passing arguments:
|
||||
// context, property value, property key, thisArg object
|
||||
// context
|
||||
fun.call(thisp, self[i], i, object);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// ES5 15.4.4.19
|
||||
// http://es5.github.com/#x15.4.4.19
|
||||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
|
||||
if (!Array.prototype.map) {
|
||||
Array.prototype.map = function map(fun /*, thisp*/) {
|
||||
var object = toObject(this),
|
||||
self = splitString && _toString(this) == "[object String]" ?
|
||||
this.split("") :
|
||||
object,
|
||||
length = self.length >>> 0,
|
||||
result = Array(length),
|
||||
thisp = arguments[1];
|
||||
|
||||
// If no callback function or if callback is not a callable function
|
||||
if (_toString(fun) != "[object Function]") {
|
||||
throw new TypeError(fun + " is not a function");
|
||||
}
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
if (i in self)
|
||||
result[i] = fun.call(thisp, self[i], i, object);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
// ES5 15.4.4.20
|
||||
// http://es5.github.com/#x15.4.4.20
|
||||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
|
||||
if (!Array.prototype.filter) {
|
||||
Array.prototype.filter = function filter(fun /*, thisp */) {
|
||||
var object = toObject(this),
|
||||
self = splitString && _toString(this) == "[object String]" ?
|
||||
this.split("") :
|
||||
object,
|
||||
length = self.length >>> 0,
|
||||
result = [],
|
||||
value,
|
||||
thisp = arguments[1];
|
||||
|
||||
// If no callback function or if callback is not a callable function
|
||||
if (_toString(fun) != "[object Function]") {
|
||||
throw new TypeError(fun + " is not a function");
|
||||
}
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
if (i in self) {
|
||||
value = self[i];
|
||||
if (fun.call(thisp, value, i, object)) {
|
||||
result.push(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
// ES5 15.4.4.16
|
||||
// http://es5.github.com/#x15.4.4.16
|
||||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
|
||||
if (!Array.prototype.every) {
|
||||
Array.prototype.every = function every(fun /*, thisp */) {
|
||||
var object = toObject(this),
|
||||
self = splitString && _toString(this) == "[object String]" ?
|
||||
this.split("") :
|
||||
object,
|
||||
length = self.length >>> 0,
|
||||
thisp = arguments[1];
|
||||
|
||||
// If no callback function or if callback is not a callable function
|
||||
if (_toString(fun) != "[object Function]") {
|
||||
throw new TypeError(fun + " is not a function");
|
||||
}
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
if (i in self && !fun.call(thisp, self[i], i, object)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
// ES5 15.4.4.17
|
||||
// http://es5.github.com/#x15.4.4.17
|
||||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
|
||||
if (!Array.prototype.some) {
|
||||
Array.prototype.some = function some(fun /*, thisp */) {
|
||||
var object = toObject(this),
|
||||
self = splitString && _toString(this) == "[object String]" ?
|
||||
this.split("") :
|
||||
object,
|
||||
length = self.length >>> 0,
|
||||
thisp = arguments[1];
|
||||
|
||||
// If no callback function or if callback is not a callable function
|
||||
if (_toString(fun) != "[object Function]") {
|
||||
throw new TypeError(fun + " is not a function");
|
||||
}
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
if (i in self && fun.call(thisp, self[i], i, object)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
// ES5 15.4.4.21
|
||||
// http://es5.github.com/#x15.4.4.21
|
||||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
|
||||
if (!Array.prototype.reduce) {
|
||||
Array.prototype.reduce = function reduce(fun /*, initial*/) {
|
||||
var object = toObject(this),
|
||||
self = splitString && _toString(this) == "[object String]" ?
|
||||
this.split("") :
|
||||
object,
|
||||
length = self.length >>> 0;
|
||||
|
||||
// If no callback function or if callback is not a callable function
|
||||
if (_toString(fun) != "[object Function]") {
|
||||
throw new TypeError(fun + " is not a function");
|
||||
}
|
||||
|
||||
// no value to return if no initial value and an empty array
|
||||
if (!length && arguments.length == 1) {
|
||||
throw new TypeError("reduce of empty array with no initial value");
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
var result;
|
||||
if (arguments.length >= 2) {
|
||||
result = arguments[1];
|
||||
} else {
|
||||
do {
|
||||
if (i in self) {
|
||||
result = self[i++];
|
||||
break;
|
||||
}
|
||||
|
||||
// if array contains no values, no initial value to return
|
||||
if (++i >= length) {
|
||||
throw new TypeError("reduce of empty array with no initial value");
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
for (; i < length; i++) {
|
||||
if (i in self) {
|
||||
result = fun.call(void 0, result, self[i], i, object);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
// ES5 15.4.4.22
|
||||
// http://es5.github.com/#x15.4.4.22
|
||||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
|
||||
if (!Array.prototype.reduceRight) {
|
||||
Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
|
||||
var object = toObject(this),
|
||||
self = splitString && _toString(this) == "[object String]" ?
|
||||
this.split("") :
|
||||
object,
|
||||
length = self.length >>> 0;
|
||||
|
||||
// If no callback function or if callback is not a callable function
|
||||
if (_toString(fun) != "[object Function]") {
|
||||
throw new TypeError(fun + " is not a function");
|
||||
}
|
||||
|
||||
// no value to return if no initial value, empty array
|
||||
if (!length && arguments.length == 1) {
|
||||
throw new TypeError("reduceRight of empty array with no initial value");
|
||||
}
|
||||
|
||||
var result, i = length - 1;
|
||||
if (arguments.length >= 2) {
|
||||
result = arguments[1];
|
||||
} else {
|
||||
do {
|
||||
if (i in self) {
|
||||
result = self[i--];
|
||||
break;
|
||||
}
|
||||
|
||||
// if array contains no values, no initial value to return
|
||||
if (--i < 0) {
|
||||
throw new TypeError("reduceRight of empty array with no initial value");
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
do {
|
||||
if (i in this) {
|
||||
result = fun.call(void 0, result, self[i], i, object);
|
||||
}
|
||||
} while (i--);
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
// ES5 15.4.4.14
|
||||
// http://es5.github.com/#x15.4.4.14
|
||||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
|
||||
if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
|
||||
Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
|
||||
var self = splitString && _toString(this) == "[object String]" ?
|
||||
this.split("") :
|
||||
toObject(this),
|
||||
length = self.length >>> 0;
|
||||
|
||||
if (!length) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
if (arguments.length > 1) {
|
||||
i = toInteger(arguments[1]);
|
||||
}
|
||||
|
||||
// handle negative indices
|
||||
i = i >= 0 ? i : Math.max(0, length + i);
|
||||
for (; i < length; i++) {
|
||||
if (i in self && self[i] === sought) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
|
||||
// ES5 15.4.4.15
|
||||
// http://es5.github.com/#x15.4.4.15
|
||||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
|
||||
if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
|
||||
Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
|
||||
var self = splitString && _toString(this) == "[object String]" ?
|
||||
this.split("") :
|
||||
toObject(this),
|
||||
length = self.length >>> 0;
|
||||
|
||||
if (!length) {
|
||||
return -1;
|
||||
}
|
||||
var i = length - 1;
|
||||
if (arguments.length > 1) {
|
||||
i = Math.min(i, toInteger(arguments[1]));
|
||||
}
|
||||
// handle negative indices
|
||||
i = i >= 0 ? i : length - Math.abs(i);
|
||||
for (; i >= 0; i--) {
|
||||
if (i in self && sought === self[i]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
// Object
|
||||
// ======
|
||||
//
|
||||
|
||||
// ES5 15.2.3.14
|
||||
// http://es5.github.com/#x15.2.3.14
|
||||
if (!Object.keys) {
|
||||
// http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
|
||||
var hasDontEnumBug = true,
|
||||
dontEnums = [
|
||||
"toString",
|
||||
"toLocaleString",
|
||||
"valueOf",
|
||||
"hasOwnProperty",
|
||||
"isPrototypeOf",
|
||||
"propertyIsEnumerable",
|
||||
"constructor"
|
||||
],
|
||||
dontEnumsLength = dontEnums.length;
|
||||
|
||||
for (var key in {"toString": null}) {
|
||||
hasDontEnumBug = false;
|
||||
}
|
||||
|
||||
Object.keys = function keys(object) {
|
||||
|
||||
if (
|
||||
(typeof object != "object" && typeof object != "function") ||
|
||||
object === null
|
||||
) {
|
||||
throw new TypeError("Object.keys called on a non-object");
|
||||
}
|
||||
|
||||
var keys = [];
|
||||
for (var name in object) {
|
||||
if (owns(object, name)) {
|
||||
keys.push(name);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasDontEnumBug) {
|
||||
for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
|
||||
var dontEnum = dontEnums[i];
|
||||
if (owns(object, dontEnum)) {
|
||||
keys.push(dontEnum);
|
||||
}
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Date
|
||||
// ====
|
||||
//
|
||||
|
||||
// ES5 15.9.5.43
|
||||
// http://es5.github.com/#x15.9.5.43
|
||||
// This function returns a String value represent the instance in time
|
||||
// represented by this Date object. The format of the String is the Date Time
|
||||
// string format defined in 15.9.1.15. All fields are present in the String.
|
||||
// The time zone is always UTC, denoted by the suffix Z. If the time value of
|
||||
// this object is not a finite Number a RangeError exception is thrown.
|
||||
var negativeDate = -62198755200000,
|
||||
negativeYearString = "-000001";
|
||||
if (
|
||||
!Date.prototype.toISOString ||
|
||||
(new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1)
|
||||
) {
|
||||
Date.prototype.toISOString = function toISOString() {
|
||||
var result, length, value, year, month;
|
||||
if (!isFinite(this)) {
|
||||
throw new RangeError("Date.prototype.toISOString called on non-finite value.");
|
||||
}
|
||||
|
||||
year = this.getUTCFullYear();
|
||||
|
||||
month = this.getUTCMonth();
|
||||
// see https://github.com/kriskowal/es5-shim/issues/111
|
||||
year += Math.floor(month / 12);
|
||||
month = (month % 12 + 12) % 12;
|
||||
|
||||
// the date time string format is specified in 15.9.1.15.
|
||||
result = [month + 1, this.getUTCDate(),
|
||||
this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
|
||||
year = (
|
||||
(year < 0 ? "-" : (year > 9999 ? "+" : "")) +
|
||||
("00000" + Math.abs(year))
|
||||
.slice(0 <= year && year <= 9999 ? -4 : -6)
|
||||
);
|
||||
|
||||
length = result.length;
|
||||
while (length--) {
|
||||
value = result[length];
|
||||
// pad months, days, hours, minutes, and seconds to have two
|
||||
// digits.
|
||||
if (value < 10) {
|
||||
result[length] = "0" + value;
|
||||
}
|
||||
}
|
||||
// pad milliseconds to have three digits.
|
||||
return (
|
||||
year + "-" + result.slice(0, 2).join("-") +
|
||||
"T" + result.slice(2).join(":") + "." +
|
||||
("000" + this.getUTCMilliseconds()).slice(-3) + "Z"
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// ES5 15.9.5.44
|
||||
// http://es5.github.com/#x15.9.5.44
|
||||
// This function provides a String representation of a Date object for use by
|
||||
// JSON.stringify (15.12.3).
|
||||
var dateToJSONIsSupported = false;
|
||||
try {
|
||||
dateToJSONIsSupported = (
|
||||
Date.prototype.toJSON &&
|
||||
new Date(NaN).toJSON() === null &&
|
||||
new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1 &&
|
||||
Date.prototype.toJSON.call({ // generic
|
||||
toISOString: function () {
|
||||
return true;
|
||||
}
|
||||
})
|
||||
);
|
||||
} catch (e) {
|
||||
}
|
||||
if (!dateToJSONIsSupported) {
|
||||
Date.prototype.toJSON = function toJSON(key) {
|
||||
// When the toJSON method is called with argument key, the following
|
||||
// steps are taken:
|
||||
|
||||
// 1. Let O be the result of calling ToObject, giving it the this
|
||||
// value as its argument.
|
||||
// 2. Let tv be toPrimitive(O, hint Number).
|
||||
var o = Object(this),
|
||||
tv = toPrimitive(o),
|
||||
toISO;
|
||||
// 3. If tv is a Number and is not finite, return null.
|
||||
if (typeof tv === "number" && !isFinite(tv)) {
|
||||
return null;
|
||||
}
|
||||
// 4. Let toISO be the result of calling the [[Get]] internal method of
|
||||
// O with argument "toISOString".
|
||||
toISO = o.toISOString;
|
||||
// 5. If IsCallable(toISO) is false, throw a TypeError exception.
|
||||
if (typeof toISO != "function") {
|
||||
throw new TypeError("toISOString property is not callable");
|
||||
}
|
||||
// 6. Return the result of calling the [[Call]] internal method of
|
||||
// toISO with O as the this value and an empty argument list.
|
||||
return toISO.call(o);
|
||||
|
||||
// NOTE 1 The argument is ignored.
|
||||
|
||||
// NOTE 2 The toJSON function is intentionally generic; it does not
|
||||
// require that its this value be a Date object. Therefore, it can be
|
||||
// transferred to other kinds of objects for use as a method. However,
|
||||
// it does require that any such object have a toISOString method. An
|
||||
// object is free to use the argument key to filter its
|
||||
// stringification.
|
||||
};
|
||||
}
|
||||
|
||||
// ES5 15.9.4.2
|
||||
// http://es5.github.com/#x15.9.4.2
|
||||
// based on work shared by Daniel Friesen (dantman)
|
||||
// http://gist.github.com/303249
|
||||
if (!Date.parse || "Date.parse is buggy") {
|
||||
// XXX global assignment won't work in embeddings that use
|
||||
// an alternate object for the context.
|
||||
Date = (function(NativeDate) {
|
||||
|
||||
// Date.length === 7
|
||||
function Date(Y, M, D, h, m, s, ms) {
|
||||
var length = arguments.length;
|
||||
if (this instanceof NativeDate) {
|
||||
var date = length == 1 && String(Y) === Y ? // isString(Y)
|
||||
// We explicitly pass it through parse:
|
||||
new NativeDate(Date.parse(Y)) :
|
||||
// We have to manually make calls depending on argument
|
||||
// length here
|
||||
length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
|
||||
length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
|
||||
length >= 5 ? new NativeDate(Y, M, D, h, m) :
|
||||
length >= 4 ? new NativeDate(Y, M, D, h) :
|
||||
length >= 3 ? new NativeDate(Y, M, D) :
|
||||
length >= 2 ? new NativeDate(Y, M) :
|
||||
length >= 1 ? new NativeDate(Y) :
|
||||
new NativeDate();
|
||||
// Prevent mixups with unfixed Date object
|
||||
date.constructor = Date;
|
||||
return date;
|
||||
}
|
||||
return NativeDate.apply(this, arguments);
|
||||
};
|
||||
|
||||
// 15.9.1.15 Date Time String Format.
|
||||
var isoDateExpression = new RegExp("^" +
|
||||
"(\\d{4}|[\+\-]\\d{6})" + // four-digit year capture or sign +
|
||||
// 6-digit extended year
|
||||
"(?:-(\\d{2})" + // optional month capture
|
||||
"(?:-(\\d{2})" + // optional day capture
|
||||
"(?:" + // capture hours:minutes:seconds.milliseconds
|
||||
"T(\\d{2})" + // hours capture
|
||||
":(\\d{2})" + // minutes capture
|
||||
"(?:" + // optional :seconds.milliseconds
|
||||
":(\\d{2})" + // seconds capture
|
||||
"(?:\\.(\\d{3}))?" + // milliseconds capture
|
||||
")?" +
|
||||
"(" + // capture UTC offset component
|
||||
"Z|" + // UTC capture
|
||||
"(?:" + // offset specifier +/-hours:minutes
|
||||
"([-+])" + // sign capture
|
||||
"(\\d{2})" + // hours offset capture
|
||||
":(\\d{2})" + // minutes offset capture
|
||||
")" +
|
||||
")?)?)?)?" +
|
||||
"$");
|
||||
|
||||
var months = [
|
||||
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
|
||||
];
|
||||
|
||||
function dayFromMonth(year, month) {
|
||||
var t = month > 1 ? 1 : 0;
|
||||
return (
|
||||
months[month] +
|
||||
Math.floor((year - 1969 + t) / 4) -
|
||||
Math.floor((year - 1901 + t) / 100) +
|
||||
Math.floor((year - 1601 + t) / 400) +
|
||||
365 * (year - 1970)
|
||||
);
|
||||
}
|
||||
|
||||
// Copy any custom methods a 3rd party library may have added
|
||||
for (var key in NativeDate) {
|
||||
Date[key] = NativeDate[key];
|
||||
}
|
||||
|
||||
// Copy "native" methods explicitly; they may be non-enumerable
|
||||
Date.now = NativeDate.now;
|
||||
Date.UTC = NativeDate.UTC;
|
||||
Date.prototype = NativeDate.prototype;
|
||||
Date.prototype.constructor = Date;
|
||||
|
||||
// Upgrade Date.parse to handle simplified ISO 8601 strings
|
||||
Date.parse = function parse(string) {
|
||||
var match = isoDateExpression.exec(string);
|
||||
if (match) {
|
||||
// parse months, days, hours, minutes, seconds, and milliseconds
|
||||
// provide default values if necessary
|
||||
// parse the UTC offset component
|
||||
var year = Number(match[1]),
|
||||
month = Number(match[2] || 1) - 1,
|
||||
day = Number(match[3] || 1) - 1,
|
||||
hour = Number(match[4] || 0),
|
||||
minute = Number(match[5] || 0),
|
||||
second = Number(match[6] || 0),
|
||||
millisecond = Number(match[7] || 0),
|
||||
// When time zone is missed, local offset should be used
|
||||
// (ES 5.1 bug)
|
||||
// see https://bugs.ecmascript.org/show_bug.cgi?id=112
|
||||
offset = !match[4] || match[8] ?
|
||||
0 : Number(new NativeDate(1970, 0)),
|
||||
signOffset = match[9] === "-" ? 1 : -1,
|
||||
hourOffset = Number(match[10] || 0),
|
||||
minuteOffset = Number(match[11] || 0),
|
||||
result;
|
||||
if (
|
||||
hour < (
|
||||
minute > 0 || second > 0 || millisecond > 0 ?
|
||||
24 : 25
|
||||
) &&
|
||||
minute < 60 && second < 60 && millisecond < 1000 &&
|
||||
month > -1 && month < 12 && hourOffset < 24 &&
|
||||
minuteOffset < 60 && // detect invalid offsets
|
||||
day > -1 &&
|
||||
day < (
|
||||
dayFromMonth(year, month + 1) -
|
||||
dayFromMonth(year, month)
|
||||
)
|
||||
) {
|
||||
result = (
|
||||
(dayFromMonth(year, month) + day) * 24 +
|
||||
hour +
|
||||
hourOffset * signOffset
|
||||
) * 60;
|
||||
result = (
|
||||
(result + minute + minuteOffset * signOffset) * 60 +
|
||||
second
|
||||
) * 1000 + millisecond + offset;
|
||||
if (-8.64e15 <= result && result <= 8.64e15) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return NaN;
|
||||
}
|
||||
return NativeDate.parse.apply(this, arguments);
|
||||
};
|
||||
|
||||
return Date;
|
||||
})(Date);
|
||||
}
|
||||
|
||||
// ES5 15.9.4.4
|
||||
// http://es5.github.com/#x15.9.4.4
|
||||
if (!Date.now) {
|
||||
Date.now = function now() {
|
||||
return new Date().getTime();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// String
|
||||
// ======
|
||||
//
|
||||
|
||||
|
||||
// ES5 15.5.4.14
|
||||
// http://es5.github.com/#x15.5.4.14
|
||||
// [bugfix, chrome]
|
||||
// If separator is undefined, then the result array contains just one String,
|
||||
// which is the this value (converted to a String). If limit is not undefined,
|
||||
// then the output array is truncated so that it contains no more than limit
|
||||
// elements.
|
||||
// "0".split(undefined, 0) -> []
|
||||
if("0".split(void 0, 0).length) {
|
||||
var string_split = String.prototype.split;
|
||||
String.prototype.split = function(separator, limit) {
|
||||
if(separator === void 0 && limit === 0)return [];
|
||||
return string_split.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
// ECMA-262, 3rd B.2.3
|
||||
// Note an ECMAScript standart, although ECMAScript 3rd Edition has a
|
||||
// non-normative section suggesting uniform semantics and it should be
|
||||
// normalized across all browsers
|
||||
// [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
|
||||
if("".substr && "0b".substr(-1) !== "b") {
|
||||
var string_substr = String.prototype.substr;
|
||||
/**
|
||||
* Get the substring of a string
|
||||
* @param {integer} start where to start the substring
|
||||
* @param {integer} length how many characters to return
|
||||
* @return {string}
|
||||
*/
|
||||
String.prototype.substr = function(start, length) {
|
||||
return string_substr.call(
|
||||
this,
|
||||
start < 0 ? ((start = this.length + start) < 0 ? 0 : start) : start,
|
||||
length
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ES5 15.5.4.20
|
||||
// http://es5.github.com/#x15.5.4.20
|
||||
var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
|
||||
"\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
|
||||
"\u2029\uFEFF";
|
||||
if (!String.prototype.trim || ws.trim()) {
|
||||
// http://blog.stevenlevithan.com/archives/faster-trim-javascript
|
||||
// http://perfectionkills.com/whitespace-deviations/
|
||||
ws = "[" + ws + "]";
|
||||
var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
|
||||
trimEndRegexp = new RegExp(ws + ws + "*$");
|
||||
String.prototype.trim = function trim() {
|
||||
if (this === undefined || this === null) {
|
||||
throw new TypeError("can't convert "+this+" to object");
|
||||
}
|
||||
return String(this)
|
||||
.replace(trimBeginRegexp, "")
|
||||
.replace(trimEndRegexp, "");
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
// Util
|
||||
// ======
|
||||
//
|
||||
|
||||
// ES5 9.4
|
||||
// http://es5.github.com/#x9.4
|
||||
// http://jsperf.com/to-integer
|
||||
|
||||
function toInteger(n) {
|
||||
n = +n;
|
||||
if (n !== n) { // isNaN
|
||||
n = 0;
|
||||
} else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
|
||||
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
function isPrimitive(input) {
|
||||
var type = typeof input;
|
||||
return (
|
||||
input === null ||
|
||||
type === "undefined" ||
|
||||
type === "boolean" ||
|
||||
type === "number" ||
|
||||
type === "string"
|
||||
);
|
||||
}
|
||||
|
||||
function toPrimitive(input) {
|
||||
var val, valueOf, toString;
|
||||
if (isPrimitive(input)) {
|
||||
return input;
|
||||
}
|
||||
valueOf = input.valueOf;
|
||||
if (typeof valueOf === "function") {
|
||||
val = valueOf.call(input);
|
||||
if (isPrimitive(val)) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
toString = input.toString;
|
||||
if (typeof toString === "function") {
|
||||
val = toString.call(input);
|
||||
if (isPrimitive(val)) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
throw new TypeError();
|
||||
}
|
||||
|
||||
// ES5 9.9
|
||||
// http://es5.github.com/#x9.9
|
||||
var toObject = function (o) {
|
||||
if (o == null) { // this matches both null and undefined
|
||||
throw new TypeError("can't convert "+o+" to object");
|
||||
}
|
||||
return Object(o);
|
||||
};
|
||||
|
||||
});
|
||||
488
plugin/mindmap/edit-mindmap/vendor/js/kampfer/helper/json2.js
vendored
Normal file
488
plugin/mindmap/edit-mindmap/vendor/js/kampfer/helper/json2.js
vendored
Normal file
@@ -0,0 +1,488 @@
|
||||
/*
|
||||
json2.js
|
||||
2012-10-08
|
||||
|
||||
Public Domain.
|
||||
|
||||
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
||||
|
||||
See http://www.JSON.org/js.html
|
||||
|
||||
|
||||
This code should be minified before deployment.
|
||||
See http://javascript.crockford.com/jsmin.html
|
||||
|
||||
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
||||
NOT CONTROL.
|
||||
|
||||
|
||||
This file creates a global JSON object containing two methods: stringify
|
||||
and parse.
|
||||
|
||||
JSON.stringify(value, replacer, space)
|
||||
value any JavaScript value, usually an object or array.
|
||||
|
||||
replacer an optional parameter that determines how object
|
||||
values are stringified for objects. It can be a
|
||||
function or an array of strings.
|
||||
|
||||
space an optional parameter that specifies the indentation
|
||||
of nested structures. If it is omitted, the text will
|
||||
be packed without extra whitespace. If it is a number,
|
||||
it will specify the number of spaces to indent at each
|
||||
level. If it is a string (such as '\t' or ' '),
|
||||
it contains the characters used to indent at each level.
|
||||
|
||||
This method produces a JSON text from a JavaScript value.
|
||||
|
||||
When an object value is found, if the object contains a toJSON
|
||||
method, its toJSON method will be called and the result will be
|
||||
stringified. A toJSON method does not serialize: it returns the
|
||||
value represented by the name/value pair that should be serialized,
|
||||
or undefined if nothing should be serialized. The toJSON method
|
||||
will be passed the key associated with the value, and this will be
|
||||
bound to the value
|
||||
|
||||
For example, this would serialize Dates as ISO strings.
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
return this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z';
|
||||
};
|
||||
|
||||
You can provide an optional replacer method. It will be passed the
|
||||
key and value of each member, with this bound to the containing
|
||||
object. The value that is returned from your method will be
|
||||
serialized. If your method returns undefined, then the member will
|
||||
be excluded from the serialization.
|
||||
|
||||
If the replacer parameter is an array of strings, then it will be
|
||||
used to select the members to be serialized. It filters the results
|
||||
such that only members with keys listed in the replacer array are
|
||||
stringified.
|
||||
|
||||
Values that do not have JSON representations, such as undefined or
|
||||
functions, will not be serialized. Such values in objects will be
|
||||
dropped; in arrays they will be replaced with null. You can use
|
||||
a replacer function to replace those with JSON values.
|
||||
JSON.stringify(undefined) returns undefined.
|
||||
|
||||
The optional space parameter produces a stringification of the
|
||||
value that is filled with line breaks and indentation to make it
|
||||
easier to read.
|
||||
|
||||
If the space parameter is a non-empty string, then that string will
|
||||
be used for indentation. If the space parameter is a number, then
|
||||
the indentation will be that many spaces.
|
||||
|
||||
Example:
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
||||
// text is '["e",{"pluribus":"unum"}]'
|
||||
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
||||
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
||||
|
||||
text = JSON.stringify([new Date()], function (key, value) {
|
||||
return this[key] instanceof Date ?
|
||||
'Date(' + this[key] + ')' : value;
|
||||
});
|
||||
// text is '["Date(---current time---)"]'
|
||||
|
||||
|
||||
JSON.parse(text, reviver)
|
||||
This method parses a JSON text to produce an object or array.
|
||||
It can throw a SyntaxError exception.
|
||||
|
||||
The optional reviver parameter is a function that can filter and
|
||||
transform the results. It receives each of the keys and values,
|
||||
and its return value is used instead of the original value.
|
||||
If it returns what it received, then the structure is not modified.
|
||||
If it returns undefined then the member is deleted.
|
||||
|
||||
Example:
|
||||
|
||||
// Parse the text. Values that look like ISO date strings will
|
||||
// be converted to Date objects.
|
||||
|
||||
myData = JSON.parse(text, function (key, value) {
|
||||
var a;
|
||||
if (typeof value === 'string') {
|
||||
a =
|
||||
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
||||
if (a) {
|
||||
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
||||
+a[5], +a[6]));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
||||
var d;
|
||||
if (typeof value === 'string' &&
|
||||
value.slice(0, 5) === 'Date(' &&
|
||||
value.slice(-1) === ')') {
|
||||
d = new Date(value.slice(5, -1));
|
||||
if (d) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
|
||||
This is a reference implementation. You are free to copy, modify, or
|
||||
redistribute.
|
||||
*/
|
||||
|
||||
/*jslint evil: true, regexp: true */
|
||||
|
||||
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
||||
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
||||
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
||||
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
||||
test, toJSON, toString, valueOf
|
||||
*/
|
||||
|
||||
|
||||
// Create a JSON object only if one does not already exist. We create the
|
||||
// methods in a closure to avoid creating global variables.
|
||||
|
||||
if (typeof JSON !== 'object') {
|
||||
JSON = {};
|
||||
}
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
if (typeof Date.prototype.toJSON !== 'function') {
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
|
||||
return isFinite(this.valueOf())
|
||||
? this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z'
|
||||
: null;
|
||||
};
|
||||
|
||||
String.prototype.toJSON =
|
||||
Number.prototype.toJSON =
|
||||
Boolean.prototype.toJSON = function (key) {
|
||||
return this.valueOf();
|
||||
};
|
||||
}
|
||||
|
||||
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
gap,
|
||||
indent,
|
||||
meta = { // table of character substitutions
|
||||
'\b': '\\b',
|
||||
'\t': '\\t',
|
||||
'\n': '\\n',
|
||||
'\f': '\\f',
|
||||
'\r': '\\r',
|
||||
'"' : '\\"',
|
||||
'\\': '\\\\'
|
||||
},
|
||||
rep;
|
||||
|
||||
|
||||
function quote(string) {
|
||||
|
||||
// If the string contains no control characters, no quote characters, and no
|
||||
// backslash characters, then we can safely slap some quotes around it.
|
||||
// Otherwise we must also replace the offending characters with safe escape
|
||||
// sequences.
|
||||
|
||||
escapable.lastIndex = 0;
|
||||
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
|
||||
var c = meta[a];
|
||||
return typeof c === 'string'
|
||||
? c
|
||||
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
}) + '"' : '"' + string + '"';
|
||||
}
|
||||
|
||||
|
||||
function str(key, holder) {
|
||||
|
||||
// Produce a string from holder[key].
|
||||
|
||||
var i, // The loop counter.
|
||||
k, // The member key.
|
||||
v, // The member value.
|
||||
length,
|
||||
mind = gap,
|
||||
partial,
|
||||
value = holder[key];
|
||||
|
||||
// If the value has a toJSON method, call it to obtain a replacement value.
|
||||
|
||||
if (value && typeof value === 'object' &&
|
||||
typeof value.toJSON === 'function') {
|
||||
value = value.toJSON(key);
|
||||
}
|
||||
|
||||
// If we were called with a replacer function, then call the replacer to
|
||||
// obtain a replacement value.
|
||||
|
||||
if (typeof rep === 'function') {
|
||||
value = rep.call(holder, key, value);
|
||||
}
|
||||
|
||||
// What happens next depends on the value's type.
|
||||
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
return quote(value);
|
||||
|
||||
case 'number':
|
||||
|
||||
// JSON numbers must be finite. Encode non-finite numbers as null.
|
||||
|
||||
return isFinite(value) ? String(value) : 'null';
|
||||
|
||||
case 'boolean':
|
||||
case 'null':
|
||||
|
||||
// If the value is a boolean or null, convert it to a string. Note:
|
||||
// typeof null does not produce 'null'. The case is included here in
|
||||
// the remote chance that this gets fixed someday.
|
||||
|
||||
return String(value);
|
||||
|
||||
// If the type is 'object', we might be dealing with an object or an array or
|
||||
// null.
|
||||
|
||||
case 'object':
|
||||
|
||||
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
||||
// so watch out for that case.
|
||||
|
||||
if (!value) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
// Make an array to hold the partial results of stringifying this object value.
|
||||
|
||||
gap += indent;
|
||||
partial = [];
|
||||
|
||||
// Is the value an array?
|
||||
|
||||
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
||||
|
||||
// The value is an array. Stringify every element. Use null as a placeholder
|
||||
// for non-JSON values.
|
||||
|
||||
length = value.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
partial[i] = str(i, value) || 'null';
|
||||
}
|
||||
|
||||
// Join all of the elements together, separated with commas, and wrap them in
|
||||
// brackets.
|
||||
|
||||
v = partial.length === 0
|
||||
? '[]'
|
||||
: gap
|
||||
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
|
||||
: '[' + partial.join(',') + ']';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
|
||||
// If the replacer is an array, use it to select the members to be stringified.
|
||||
|
||||
if (rep && typeof rep === 'object') {
|
||||
length = rep.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
if (typeof rep[i] === 'string') {
|
||||
k = rep[i];
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// Otherwise, iterate through all of the keys in the object.
|
||||
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Join all of the member texts together, separated with commas,
|
||||
// and wrap them in braces.
|
||||
|
||||
v = partial.length === 0
|
||||
? '{}'
|
||||
: gap
|
||||
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
|
||||
: '{' + partial.join(',') + '}';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
// If the JSON object does not yet have a stringify method, give it one.
|
||||
|
||||
if (typeof JSON.stringify !== 'function') {
|
||||
JSON.stringify = function (value, replacer, space) {
|
||||
|
||||
// The stringify method takes a value and an optional replacer, and an optional
|
||||
// space parameter, and returns a JSON text. The replacer can be a function
|
||||
// that can replace values, or an array of strings that will select the keys.
|
||||
// A default replacer method can be provided. Use of the space parameter can
|
||||
// produce text that is more easily readable.
|
||||
|
||||
var i;
|
||||
gap = '';
|
||||
indent = '';
|
||||
|
||||
// If the space parameter is a number, make an indent string containing that
|
||||
// many spaces.
|
||||
|
||||
if (typeof space === 'number') {
|
||||
for (i = 0; i < space; i += 1) {
|
||||
indent += ' ';
|
||||
}
|
||||
|
||||
// If the space parameter is a string, it will be used as the indent string.
|
||||
|
||||
} else if (typeof space === 'string') {
|
||||
indent = space;
|
||||
}
|
||||
|
||||
// If there is a replacer, it must be a function or an array.
|
||||
// Otherwise, throw an error.
|
||||
|
||||
rep = replacer;
|
||||
if (replacer && typeof replacer !== 'function' &&
|
||||
(typeof replacer !== 'object' ||
|
||||
typeof replacer.length !== 'number')) {
|
||||
throw new Error('JSON.stringify');
|
||||
}
|
||||
|
||||
// Make a fake root object containing our value under the key of ''.
|
||||
// Return the result of stringifying the value.
|
||||
|
||||
return str('', {'': value});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// If the JSON object does not yet have a parse method, give it one.
|
||||
|
||||
if (typeof JSON.parse !== 'function') {
|
||||
JSON.parse = function (text, reviver) {
|
||||
|
||||
// The parse method takes a text and an optional reviver function, and returns
|
||||
// a JavaScript value if the text is a valid JSON text.
|
||||
|
||||
var j;
|
||||
|
||||
function walk(holder, key) {
|
||||
|
||||
// The walk method is used to recursively walk the resulting structure so
|
||||
// that modifications can be made.
|
||||
|
||||
var k, v, value = holder[key];
|
||||
if (value && typeof value === 'object') {
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = walk(value, k);
|
||||
if (v !== undefined) {
|
||||
value[k] = v;
|
||||
} else {
|
||||
delete value[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return reviver.call(holder, key, value);
|
||||
}
|
||||
|
||||
|
||||
// Parsing happens in four stages. In the first stage, we replace certain
|
||||
// Unicode characters with escape sequences. JavaScript handles many characters
|
||||
// incorrectly, either silently deleting them, or treating them as line endings.
|
||||
|
||||
text = String(text);
|
||||
cx.lastIndex = 0;
|
||||
if (cx.test(text)) {
|
||||
text = text.replace(cx, function (a) {
|
||||
return '\\u' +
|
||||
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
}
|
||||
|
||||
// In the second stage, we run the text against regular expressions that look
|
||||
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
||||
// because they can cause invocation, and '=' because it can cause mutation.
|
||||
// But just to be safe, we want to reject all unexpected forms.
|
||||
|
||||
// We split the second stage into 4 regexp operations in order to work around
|
||||
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
||||
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
||||
// replace all simple value tokens with ']' characters. Third, we delete all
|
||||
// open brackets that follow a colon or comma or that begin the text. Finally,
|
||||
// we look to see that the remaining characters are only whitespace or ']' or
|
||||
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
||||
|
||||
if (/^[\],:{}\s]*$/
|
||||
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
||||
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
||||
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
||||
|
||||
// In the third stage we use the eval function to compile the text into a
|
||||
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
||||
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
||||
// in parens to eliminate the ambiguity.
|
||||
|
||||
j = eval('(' + text + ')');
|
||||
|
||||
// In the optional fourth stage, we recursively walk the new structure, passing
|
||||
// each name/value pair to a reviver function for possible transformation.
|
||||
|
||||
return typeof reviver === 'function'
|
||||
? walk({'': j}, '')
|
||||
: j;
|
||||
}
|
||||
|
||||
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
||||
|
||||
throw new SyntaxError('JSON.parse');
|
||||
};
|
||||
}
|
||||
}());
|
||||
|
||||
kampfer.provide('JSON');
|
||||
18
plugin/mindmap/edit-mindmap/vendor/js/kampfer/support.js
vendored
Normal file
18
plugin/mindmap/edit-mindmap/vendor/js/kampfer/support.js
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 用于检测浏览器的功能特性
|
||||
* @module support.js
|
||||
* @author l.w.kampfer@gmail.com
|
||||
*/
|
||||
|
||||
kampfer.provide('browser.support');
|
||||
|
||||
kampfer.browser.support.deleteExpando = (function() {
|
||||
var div = document.createElement('div');
|
||||
|
||||
try{
|
||||
delete div.test;
|
||||
return true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user