var a=function(){
if(document.readyState != "loaded")
setInterval(a,13);}


else...{//对dom元素操作的代码}
onDocumentReady : function(fn, scope, options){


if(!docReadyEvent)...{ initDocReady();}

if(docReadyState || Ext.isReady)...{ // if it already fired
options || (options = ...{});
fn.defer(options.delay||0, scope); }
else...{docReadyEvent.addListener(fn, scope, options); }
},
点击展开示例
var initDocReady = function(){
docReadyEvent = new Ext.util.Event();


if(Ext.isReady)...{ return; }
E.on(window, 'load', fireDocReady);

if(Ext.isGecko || Ext.isOpera) ...{
document.addEventListener('DOMContentLoaded',fireDocReady, false);}

else if(Ext.isIE)...{

docReadyProcId = setInterval(function()...{
try...{Ext.isReady ||(document.documentElement.doScroll('left'));}
catch(e)...{ return; } fireDocReady();}, 5);

document.onreadystatechange = function()...{

if(document.readyState == 'complete')...{
document.onreadystatechange = null;
fireDocReady();} }; }

else if(Ext.isSafari)...{

docReadyProcId = setInterval(function()...{
var rs = document.readyState;
if(rs == 'complete') ...{ fireDocReady();}
}, 10); }
};
点击展开示例
var fireDocReady = function(){

if(!docReadyState)...{
docReadyState = Ext.isReady = true;

if(Ext.isGecko || Ext.isOpera) ...{
document.removeEventListener("DOMContentLoaded",
fireDocReady,false); } }

if(docReadyProcId)...{
clearInterval(docReadyProcId);
docReadyProcId = null; }

if(docReadyEvent)...{
docReadyEvent.fire();
docReadyEvent.clearListeners(); }
};
Ext.EventManager.onWindowResize(this.fireResize, this);
.. .. ..

fireResize : function(w, h)...{
this.fireEvent('resize', this, w, h, w, h); }
onWindowResize : function(fn, scope, options){

if(!resizeEvent)...{
resizeEvent = new Ext.util.Event();

resizeTask = new Ext.util.DelayedTask(function()...{
resizeEvent.fire(D.getViewWidth(), D.getViewHeight()); });
E.on(window, "resize", this.fireWindowResize, this);
}
resizeEvent.addListener(fn, scope, options);
},
fireWindowResize : function(){

if(resizeEvent)...{
if((Ext.isIE||Ext.isAir) && resizeTask)...{ resizeTask.delay(50); }
else...{resizeEvent.fire(D.getViewWidth(), D.getViewHeight());}}
},
var map = new Ext.KeyMap("my-element", [


...{key: [10,13],fn: function(){ alert("Return was pressed"); }},
...{key: "abc", fn: function(){ alert('a, b or c was pressed'); }},

...{key: "\t", ctrl:true, shift:true,


fn: function()...{alert('Control + shift + tab was pressed.'); }}
]);
Ext.KeyMap = function(el, config, eventName){
this.el = Ext.get(el);
this.eventName = eventName || "keydown";
this.bindings = [];


if(config)...{ this.addBinding(config); }//转换成回调函数
this.enable();//把上面转换成函数注册事件的监听中
};
点击展开示例
addBinding : function(config){

if(Ext.isArray(config))...{ //数组,就找到每一个元素 ①

for(var i = 0, len = config.length; i < len; i++)...{
this.addBinding(config[i]); }
return;
}
var keyCode = config.key, shift = config.shift, ②
ctrl = config.ctrl, alt = config.alt,
fn = config.fn || config.handler, scope = config.scope;

if(typeof keyCode == "string")...{ //把字符串转换成数组 ③
var ks = [];
var keyString = keyCode.toUpperCase();

for(var j = 0, len = keyString.length; j < len; j++)...{
ks.push(keyString.charCodeAt(j)); }
keyCode = ks;
}
var keyArray = Ext.isArray(keyCode);

var handler = function(e)...{ ④

if((!shift||e.shiftKey)&&(!ctrl||e.ctrlKey)&&(!alt ||e.altKey))...{
var k = e.getKey();//按键的key

if(keyArray)...{ ⑤

for(var i = 0, len = keyCode.length; i < len; i++)...{

if(keyCode[i] == k)...{
if(this.stopEvent)...{ e.stopEvent();}
fn.call(scope || window, k, e);
return; }}}

else...{

if(k == keyCode)...{ ⑥
if(this.stopEvent)...{ e.stopEvent();}
fn.call(scope || window, k, e); }
}
}
};
this.bindings.push(handler); ⑦
},
enable: function(){

if(!this.enabled)...{
this.el.on(this.eventName, this.handleKeyDown, this);
this.enabled = true;}
},
handleKeyDown : function(e){

if(this.enabled)...{
var b = this.bindings;
for(var i = 0, len = b.length;i < len; i++)...{b[i].call(this,e);} }
},|
函数名 |
使用说明 |
|
isEnabled |
该keyMap注册的按键是否启用 |
|
enable |
启用该keyMap注册的按键事件。 |
|
disable |
禁用该keyMap注册的按键事件。 |
|
addBinding |
它只有一个参数,这个参数是数组的话,就是注册多条配置对象,这个配置对象只要包括keyMap的七个配置项中一些就可以。 |
|
on |
注册按键,它有三个参数,第一个参数是可以为字符形式的Ascill值或数组形式的数值,或含有配项的对象,第二个参数是函数,第三个是作用域 |
表4.5 keyMap的常用方法。
4.3.4注册导航键
var nav = new Ext.KeyNav("my-element", {


"left" : function(e)...{ this.moveLeft(); },
"right" : function(e)...{ this.moveRight(e.ctrlKey); },
"enter" : function(e)...{ this.save(); },
scope : this});
Ext.KeyNav = function(el, config){
this.el = Ext.get(el);
Ext.apply(this, config);


if(!this.disabled)...{ this.disabled = true; this.enable(); }
};
enable: function(){

if(this.disabled)...{

if(this.forceKeyDown || Ext.isIE || Ext.isAir)...{
this.el.on("keydown", this.relay, this);}

else...{
this.el.on("keydown", this.prepareEvent, this);
this.el.on("keypress", this.relay, this); }
this.disabled = false;
}
},
relay : function(e){
var k = e.getKey();
var h = this.keyToHandler[k];

if(h && this[h])...{

if(this.doRelay(e, this[h], h) !== true)...{
e[this.defaultEventAction](); }
}
},|
配置项 |
说明 |
|
delay |
指定的按下多长时间后才运行注册的处理函数 |
|
interval |
和delay差不多,指定多长时间后才运行注册处理函数,20ms 默认 |
|
pressClass |
鼠标按下的之后的CSS样式。 |
|
accelerate |
为true时会,会出现先按下要长一点时间才运行,后按下短一点 |
|
preventDefault |
阻止click默认的动作发生,默认是true. |
|
stopDefault |
阻止默认的动作发生和冒泡操作。默认是false. |
|
handler |
用来指定鼠按下一定时间后才执行的函数。 |
我们先来看一下其构建函数:

点击展开示例
Ext.util.ClickRepeater = function(el, config)

...{
this.el = Ext.get(el);
this.el.unselectable();
Ext.apply(this, config);
this.addEvents( "mousedown", "click", "mouseup" );
this.el.on("mousedown", this.handleMouseDown, this);

if(this.preventDefault || this.stopDefault)...{

this.el.on("click", function(e)...{
if(this.preventDefault)...{ e.preventDefault();}
if(this.stopDefault)...{ e.stopEvent();}
}, this);
}

if(this.handler)...{
this.on("click", this.handler, this.scope || this); }
Ext.util.ClickRepeater.superclass.constructor.call(this);
};
handleMouseDown : function(){
clearTimeout(this.timer);
this.el.blur();


if(this.pressClass)...{ this.el.addClass(this.pressClass);}
this.mousedownTime = new Date();
Ext.getDoc().on("mouseup", this.handleMouseUp, this);
this.el.on("mouseout", this.handleMouseOut, this);
this.fireEvent("mousedown", this);
this.fireEvent("click", this);
if (this.accelerate) ...{ this.delay = 400; }
this.timer = this.click.defer(this.delay || this.interval, this);
},
click : function(){
this.fireEvent("click", this);
this.timer = this.click.defer(this.accelerate ?
this.easeOutExpo(this.mousedownTime.getElapsed(),
400, -390, 12000) : this.interval, this);
},