问题描述
我想覆盖dijit._CssStateMixin的domReady()方法。
有什么办法来覆盖,而不是改变Dojo中的监听器机制。
I want to override dijit._CssStateMixin's domReady() method.Is there any way to override that instead of changing the listener mechanism in Dojo.
我尝试在简单的javascript中覆盖_cssMouseEvent()方法,但它仍然从domReady()调用dijit的_cssMouseEvent()。
I tried overriding _cssMouseEvent() method in simple javascript, but it still does invoke dijit's _cssMouseEvent() from domReady().
我尝试了以下方法:
dojoConfig = {
map: {
'dijit/_CssStateMixin': {
'dojo/domReady': 'app/noop'
}
}
};
我已经添加了'app'文件夹,然后在其中添加了noop.js。
noop.js没有任何内容:
I have added 'app' folder and then 'noop.js' inside that.noop.js has nothing in it:
define([], function () {
return function () {};
});
即使这样,我可以看到dijit.js的_CssStateMaxin domReady()从listener.apply代码片段粘贴在下面)
Even after this I can see that dijit.js's _CssStateMaxin domReady() getting called from listener.apply (code snippet pasted below)
var addStopImmediate = function(listener){
return function(event){
if(!event.immediatelyStopped){// check to make sure it hasn't been stopped immediately
event.stopImmediatePropagation = stopImmediatePropagation;
return listener.apply(this, arguments);
}
};
}
推荐答案
如果您的最终目标是防止 dijit / _CssStateMixin
中的 domReady
回调运行,您最简单的下注可能会重新映射 dojo / domReady
到不通过调用回调的不同模块,通过 dijit / _CssStateMixin
加载时。
If your ultimate goal is to prevent the domReady
callback in dijit/_CssStateMixin
from running, your simplest bet is likely to re-map dojo/domReady
to a different module that doesn't call the callback at all, when loaded via dijit/_CssStateMixin
.
注意:剥离这些处理程序可能会对继承 _CssStateMixin
的Dijit小部件产生不利的视觉效果,因为这可能会妨碍Dijit CSS类的应用与悬停和关注相关。但是,如果您关心的是 _CssStateMixin
阻碍了性能,至少值得尝试确认或否认您的怀疑。
NOTE: Stripping out these handlers might have adverse visual effects on Dijit widgets which inherit _CssStateMixin
, since it may hinder the application of Dijit CSS classes related to hover and focus. But if your concern is that _CssStateMixin
is hampering performance, it may at least be worth a try to confirm or deny your suspicion.
首先,我们必须创建一个返回一个不执行任何操作的函数的简单模块,当$ dojo / domReady > dijit / _CssStateMixin ,所以它仍然可以调用 domReady
,但它不会执行它通过的回调。
First we have to create a simple module that returns a function that does nothing, which we will later substitute for dojo/domReady
when loaded by dijit/_CssStateMixin
, so that it can still call domReady
but it won't execute the callback it passes.
为了简单起见,我假设你已经有一个自定义包,你可以轻松地添加一个模块;对于这个例子,我假设它被称为 app
。我们创建 app / noop
:
For simplicity's sake I'll assume you already have a custom package that you can easily add a module to; for this example I'll assume it's called app
. Let's create app/noop
:
define([], function () {
return function () {};
});
现在我们来配置加载器来映射 app / noop
代替 dojo / domReady
具体来说,当由 dijit / _CssStateMixin
加载时:
Now let's configure the loader to map app/noop
in place of dojo/domReady
specifically when loaded by dijit/_CssStateMixin
:
var dojoConfig = {
...,
map: {
'dijit/_CssStateMixin': {
'dojo/domReady': 'app/noop'
}
},
...
};
现在,不应再有这样的错误的 domReady
回调
Now the offending domReady
callback should no longer be run.
如果您对地图
感到好奇,您可以在这个。
If you're curious about map
, you can read more about it in this SitePen FAQ.
这篇关于如何覆盖dojo的domReady的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!