📄 ext.js
字号:
for(var i = 0, len = ov.length; i < len; i++) {
buf.push(k, "=", encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&");
}
} else {
buf.push(k, "=&");
}
}
}
buf.pop();
return buf.join("");
},
/**
* Takes an encoded URL and and converts it to an object. e.g. Ext.urlDecode("foo=1&bar=2"); would return {foo: 1, bar: 2} or Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", true); would return {foo: 1, bar: [2, 3, 4]}.
* @param {String} string
* @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
* @return {Object} A literal with members
*/
urlDecode : function(string, overwrite){
if(!string || !string.length){
return {};
}
var obj = {};
var pairs = string.split('&');
var pair, name, value;
for(var i = 0, len = pairs.length; i < len; i++){
pair = pairs[i].split('=');
name = decodeURIComponent(pair[0]);
value = decodeURIComponent(pair[1]);
if(overwrite !== true){
if(typeof obj[name] == "undefined"){
obj[name] = value;
}else if(typeof obj[name] == "string"){
obj[name] = [obj[name]];
obj[name].push(value);
}else{
obj[name].push(value);
}
}else{
obj[name] = value;
}
}
return obj;
},
/**
* Iterates an array calling the passed function with each item, stopping if your function returns false. If the
* passed array is not really an array, your function is called once with it.
* The supplied function is called with (Object item, Number index, Array allItems).
* @param {Array/NodeList/Mixed} array
* @param {Function} fn
* @param {Object} scope
*/
each : function(array, fn, scope){
if(!Ext.isArray(array)){
array = [array];
}
for(var i = 0, len = array.length; i < len; i++){
if(fn.call(scope || array[i], array[i], i, array) === false){ return i; };
}
},
// deprecated
combine : function(){
var as = arguments, l = as.length, r = [];
for(var i = 0; i < l; i++){
var a = as[i];
if(Ext.isArray(a)){
r = r.concat(a);
}else if(a.length !== undefined && !a.substr){
r = r.concat(Array.prototype.slice.call(a, 0));
}else{
r.push(a);
}
}
return r;
},
/**
* Escapes the passed string for use in a regular expression
* @param {String} str
* @return {String}
*/
escapeRe : function(s) {
return s.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1");
},
// internal
callback : function(cb, scope, args, delay){
if(typeof cb == "function"){
if(delay){
cb.defer(delay, scope, args || []);
}else{
cb.apply(scope, args || []);
}
}
},
/**
* Return the dom node for the passed string (id), dom node, or Ext.Element
* @param {Mixed} el
* @return HTMLElement
*/
getDom : function(el){
if(!el || !document){
return null;
}
return el.dom ? el.dom : (typeof el == 'string' ? document.getElementById(el) : el);
},
/**
* Returns the current HTML document object as an {@link Ext.Element}.
* @return Ext.Element The document
*/
getDoc : function(){
return Ext.get(document);
},
/**
* Returns the current document body as an {@link Ext.Element}.
* @return Ext.Element The document body
*/
getBody : function(){
return Ext.get(document.body || document.documentElement);
},
/**
* Shorthand for {@link Ext.ComponentMgr#get}
* @param {String} id
* @return Ext.Component
*/
getCmp : function(id){
return Ext.ComponentMgr.get(id);
},
/**
* Utility method for validating that a value is numeric, returning the specified default value if it is not.
* @param {Mixed} value Should be a number, but any type will be handled appropriately
* @param {Number} defaultValue The value to return if the original value is non-numeric
* @return {Number} Value, if numeric, else defaultValue
*/
num : function(v, defaultValue){
if(typeof v != 'number'){
return defaultValue;
}
return v;
},
/**
* Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
* DOM (if applicable) and calling their destroy functions (if available). This method is primarily
* intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of
* {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
* passed into this function in a single call as separate arguments.
* @param {Mixed} arg1 An {@link Ext.Element} or {@link Ext.Component} to destroy
* @param {Mixed} arg2 (optional)
* @param {Mixed} etc... (optional)
*/
destroy : function(){
for(var i = 0, a = arguments, len = a.length; i < len; i++) {
var as = a[i];
if(as){
if(typeof as.destroy == 'function'){
as.destroy();
}
else if(as.dom){
as.removeAllListeners();
as.remove();
}
}
}
},
/**
* Removes a DOM node from the document. The body node will be ignored if passed in.
* @param {HTMLElement} node The node to remove
*/
removeNode : isIE ? function(){
var d;
return function(n){
if(n && n.tagName != 'BODY'){
d = d || document.createElement('div');
d.appendChild(n);
d.innerHTML = '';
}
}
}() : function(n){
if(n && n.parentNode && n.tagName != 'BODY'){
n.parentNode.removeChild(n);
}
},
// inpired by a similar function in mootools library
/**
* Returns the type of object that is passed in. If the object passed in is null or undefined it
* return false otherwise it returns one of the following values:<ul>
* <li><b>string</b>: If the object passed is a string</li>
* <li><b>number</b>: If the object passed is a number</li>
* <li><b>boolean</b>: If the object passed is a boolean value</li>
* <li><b>function</b>: If the object passed is a function reference</li>
* <li><b>object</b>: If the object passed is an object</li>
* <li><b>array</b>: If the object passed is an array</li>
* <li><b>regexp</b>: If the object passed is a regular expression</li>
* <li><b>element</b>: If the object passed is a DOM Element</li>
* <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
* <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
* <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
* @param {Mixed} object
* @return {String}
*/
type : function(o){
if(o === undefined || o === null){
return false;
}
if(o.htmlElement){
return 'element';
}
var t = typeof o;
if(t == 'object' && o.nodeName) {
switch(o.nodeType) {
case 1: return 'element';
case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
}
}
if(t == 'object' || t == 'function') {
switch(o.constructor) {
case Array: return 'array';
case RegExp: return 'regexp';
}
if(typeof o.length == 'number' && typeof o.item == 'function') {
return 'nodelist';
}
}
return t;
},
/**
* Returns true if the passed value is null, undefined or an empty string (optional).
* @param {Mixed} value The value to test
* @param {Boolean} allowBlank (optional) Pass true if an empty string is not considered empty
* @return {Boolean}
*/
isEmpty : function(v, allowBlank){
return v === null || v === undefined || (!allowBlank ? v === '' : false);
},
value : function(v, defaultValue, allowBlank){
return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
},
/**
* Returns true if the passed object is a JavaScript array, otherwise false.
* @param {Object} The object to test
* @return {Boolean}
*/
isArray : function(v){
return v && typeof v.pop == 'function';
},
/**
* Returns true if the passed object is a JavaScript date object, otherwise false.
* @param {Object} The object to test
* @return {Boolean}
*/
isDate : function(v){
return v && typeof v.getFullYear == 'function';
},
/** @type Boolean */
isOpera : isOpera,
/** @type Boolean */
isSafari : isSafari,
/** @type Boolean */
isSafari3 : isSafari3,
/** @type Boolean */
isSafari2 : isSafari && !isSafari3,
/** @type Boolean */
isIE : isIE,
/** @type Boolean */
isIE6 : isIE && !isIE7,
/** @type Boolean */
isIE7 : isIE7,
/** @type Boolean */
isGecko : isGecko,
/** @type Boolean */
isBorderBox : isBorderBox,
/** @type Boolean */
isLinux : isLinux,
/** @type Boolean */
isWindows : isWindows,
/** @type Boolean */
isMac : isMac,
/** @type Boolean */
isAir : isAir,
/**
* By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
* you may want to set this to true.
* @type Boolean
*/
useShims : ((isIE && !isIE7) || (isGecko && isMac))
});
// in intellij using keyword "namespace" causes parsing errors
Ext.ns = Ext.namespace;
})();
Ext.ns("Ext", "Ext.util", "Ext.grid", "Ext.dd", "Ext.tree", "Ext.data",
"Ext.form", "Ext.menu", "Ext.state", "Ext.lib", "Ext.layout", "Ext.app", "Ext.ux");
/**
* @class Function
* These functions are available on every Function object (any JavaScript function).
*/
Ext.apply(Function.prototype, {
/**
* Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
* Call directly on any function. Example: <code>myFunction.createCallback(arg1, arg2)</code>
* Will create a function that is bound to those 2 args. <b>If a specific scope is required in the
* callback, use {@link #createDelegate} instead.</b> The function returned by createCallback always
* executes in the window scope.
* <p>This method is required when you want to pass arguments to a callback function. If no arguments
* are needed, you can simply pass a reference to the function as a callback (e.g., callback: myFn).
* However, if you tried to pass a function with arguments (e.g., callback: myFn(arg1, arg2)) the function
* would simply execute immediately when the code is parsed. Example usage:
* <pre><code>
var sayHi = function(name){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -