254 lines
11 KiB
HTML
254 lines
11 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<title>The source code</title>
|
|
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
|
|
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
|
|
<style type="text/css">
|
|
.highlight { display: block; background-color: #ddd; }
|
|
</style>
|
|
<script type="text/javascript">
|
|
function highlight() {
|
|
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
|
|
}
|
|
</script>
|
|
</head>
|
|
<body onload="prettyPrint(); highlight();">
|
|
<pre class="prettyprint lang-js"><span id='Ext-util-Functions'>/**
|
|
</span> * @class Ext.util.Functions
|
|
* @singleton
|
|
*/
|
|
Ext.util.Functions = {
|
|
<span id='Ext-util-Functions-method-createInterceptor'> /**
|
|
</span> * Creates an interceptor function. The passed function is called before the original one. If it returns false,
|
|
* the original one is not called. The resulting function returns the results of the original function.
|
|
* The passed function is called with the parameters of the original function. Example usage:
|
|
* <pre><code>
|
|
var sayHi = function(name){
|
|
alert('Hi, ' + name);
|
|
}
|
|
|
|
sayHi('Fred'); // alerts "Hi, Fred"
|
|
|
|
// create a new function that validates input without
|
|
// directly modifying the original function:
|
|
var sayHiToFriend = Ext.createInterceptor(sayHi, function(name){
|
|
return name == 'Brian';
|
|
});
|
|
|
|
sayHiToFriend('Fred'); // no alert
|
|
sayHiToFriend('Brian'); // alerts "Hi, Brian"
|
|
</code></pre>
|
|
* @param {Function} origFn The original function.
|
|
* @param {Function} newFn The function to call before the original
|
|
* @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
|
|
* <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
|
|
* @return {Function} The new function
|
|
*/
|
|
createInterceptor: function(origFn, newFn, scope) {
|
|
var method = origFn;
|
|
if (!Ext.isFunction(newFn)) {
|
|
return origFn;
|
|
}
|
|
else {
|
|
return function() {
|
|
var me = this,
|
|
args = arguments;
|
|
newFn.target = me;
|
|
newFn.method = origFn;
|
|
return (newFn.apply(scope || me || window, args) !== false) ?
|
|
origFn.apply(me || window, args) :
|
|
null;
|
|
};
|
|
}
|
|
},
|
|
|
|
<span id='Ext-util-Functions-method-createDelegate'> /**
|
|
</span> * Creates a delegate (callback) that sets the scope to obj.
|
|
* Call directly on any function. Example: <code>Ext.createDelegate(this.myFunction, this, [arg1, arg2])</code>
|
|
* Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
|
|
* callback points to obj. Example usage:
|
|
* <pre><code>
|
|
var sayHi = function(name){
|
|
// Note this use of "this.text" here. This function expects to
|
|
// execute within a scope that contains a text property. In this
|
|
// example, the "this" variable is pointing to the btn object that
|
|
// was passed in createDelegate below.
|
|
alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
|
|
}
|
|
|
|
var btn = new Ext.Button({
|
|
text: 'Say Hi',
|
|
renderTo: Ext.getBody()
|
|
});
|
|
|
|
// This callback will execute in the scope of the
|
|
// button instance. Clicking the button alerts
|
|
// "Hi, Fred. You clicked the "Say Hi" button."
|
|
btn.on('click', Ext.createDelegate(sayHi, btn, ['Fred']));
|
|
</code></pre>
|
|
* @param {Function} fn The function to delegate.
|
|
* @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
|
|
* <b>If omitted, defaults to the browser window.</b>
|
|
* @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
|
|
* @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
|
|
* if a number the args are inserted at the specified position
|
|
* @return {Function} The new function
|
|
*/
|
|
createDelegate: function(fn, obj, args, appendArgs) {
|
|
if (!Ext.isFunction(fn)) {
|
|
return fn;
|
|
}
|
|
return function() {
|
|
var callArgs = args || arguments;
|
|
if (appendArgs === true) {
|
|
callArgs = Array.prototype.slice.call(arguments, 0);
|
|
callArgs = callArgs.concat(args);
|
|
}
|
|
else if (Ext.isNumber(appendArgs)) {
|
|
callArgs = Array.prototype.slice.call(arguments, 0);
|
|
// copy arguments first
|
|
var applyArgs = [appendArgs, 0].concat(args);
|
|
// create method call params
|
|
Array.prototype.splice.apply(callArgs, applyArgs);
|
|
// splice them in
|
|
}
|
|
return fn.apply(obj || window, callArgs);
|
|
};
|
|
},
|
|
|
|
<span id='Ext-util-Functions-method-defer'> /**
|
|
</span> * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
|
|
* <pre><code>
|
|
var sayHi = function(name){
|
|
alert('Hi, ' + name);
|
|
}
|
|
|
|
// executes immediately:
|
|
sayHi('Fred');
|
|
|
|
// executes after 2 seconds:
|
|
Ext.defer(sayHi, 2000, this, ['Fred']);
|
|
|
|
// this syntax is sometimes useful for deferring
|
|
// execution of an anonymous function:
|
|
Ext.defer(function(){
|
|
alert('Anonymous');
|
|
}, 100);
|
|
</code></pre>
|
|
* @param {Function} fn The function to defer.
|
|
* @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
|
|
* @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
|
|
* <b>If omitted, defaults to the browser window.</b>
|
|
* @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
|
|
* @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
|
|
* if a number the args are inserted at the specified position
|
|
* @return {Number} The timeout id that can be used with clearTimeout
|
|
*/
|
|
defer: function(fn, millis, obj, args, appendArgs) {
|
|
fn = Ext.util.Functions.createDelegate(fn, obj, args, appendArgs);
|
|
if (millis > 0) {
|
|
return setTimeout(fn, millis);
|
|
}
|
|
fn();
|
|
return 0;
|
|
},
|
|
|
|
|
|
<span id='Ext-util-Functions-method-createSequence'> /**
|
|
</span> * Create a combined function call sequence of the original function + the passed function.
|
|
* The resulting function returns the results of the original function.
|
|
* The passed fcn is called with the parameters of the original function. Example usage:
|
|
*
|
|
|
|
var sayHi = function(name){
|
|
alert('Hi, ' + name);
|
|
}
|
|
|
|
sayHi('Fred'); // alerts "Hi, Fred"
|
|
|
|
var sayGoodbye = Ext.createSequence(sayHi, function(name){
|
|
alert('Bye, ' + name);
|
|
});
|
|
|
|
sayGoodbye('Fred'); // both alerts show
|
|
|
|
* @param {Function} origFn The original function.
|
|
* @param {Function} newFn The function to sequence
|
|
* @param {Object} scope (optional) The scope (this reference) in which the passed function is executed.
|
|
* If omitted, defaults to the scope in which the original function is called or the browser window.
|
|
* @return {Function} The new function
|
|
*/
|
|
createSequence: function(origFn, newFn, scope) {
|
|
if (!Ext.isFunction(newFn)) {
|
|
return origFn;
|
|
}
|
|
else {
|
|
return function() {
|
|
var retval = origFn.apply(this || window, arguments);
|
|
newFn.apply(scope || this || window, arguments);
|
|
return retval;
|
|
};
|
|
}
|
|
}
|
|
};
|
|
|
|
<span id='Ext-method-defer'>/**
|
|
</span> * Shorthand for {@link Ext.util.Functions#defer}
|
|
* @param {Function} fn The function to defer.
|
|
* @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
|
|
* @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
|
|
* <b>If omitted, defaults to the browser window.</b>
|
|
* @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
|
|
* @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
|
|
* if a number the args are inserted at the specified position
|
|
* @return {Number} The timeout id that can be used with clearTimeout
|
|
* @member Ext
|
|
* @method defer
|
|
*/
|
|
|
|
Ext.defer = Ext.util.Functions.defer;
|
|
|
|
<span id='Ext-method-createInterceptor'>/**
|
|
</span> * Shorthand for {@link Ext.util.Functions#createInterceptor}
|
|
* @param {Function} origFn The original function.
|
|
* @param {Function} newFn The function to call before the original
|
|
* @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
|
|
* <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
|
|
* @return {Function} The new function
|
|
* @member Ext
|
|
* @method createInterceptor
|
|
*/
|
|
|
|
Ext.createInterceptor = Ext.util.Functions.createInterceptor;
|
|
|
|
<span id='Ext-method-createSequence'>/**
|
|
</span> * Shorthand for {@link Ext.util.Functions#createSequence}
|
|
* @param {Function} origFn The original function.
|
|
* @param {Function} newFn The function to sequence
|
|
* @param {Object} scope (optional) The scope (this reference) in which the passed function is executed.
|
|
* If omitted, defaults to the scope in which the original function is called or the browser window.
|
|
* @return {Function} The new function
|
|
* @member Ext
|
|
* @method createSequence
|
|
*/
|
|
|
|
Ext.createSequence = Ext.util.Functions.createSequence;
|
|
|
|
<span id='Ext-method-createDelegate'>/**
|
|
</span> * Shorthand for {@link Ext.util.Functions#createDelegate}
|
|
* @param {Function} fn The function to delegate.
|
|
* @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
|
|
* <b>If omitted, defaults to the browser window.</b>
|
|
* @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
|
|
* @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
|
|
* if a number the args are inserted at the specified position
|
|
* @return {Function} The new function
|
|
* @member Ext
|
|
* @method createDelegate
|
|
*/
|
|
Ext.createDelegate = Ext.util.Functions.createDelegate;
|
|
</pre>
|
|
</body>
|
|
</html>
|