Javascript Dijit自定义工具提示不起作用
我正在将web应用程序从Dojo 1.3.1迁移到Dojo 1.9.3。该应用程序有许多自定义小部件。其中之一是Javascript Dijit自定义工具提示不起作用,javascript,dojo,tooltip,Javascript,Dojo,Tooltip,我正在将web应用程序从Dojo 1.3.1迁移到Dojo 1.9.3。该应用程序有许多自定义小部件。其中之一是HelpTip,它是从dijit/Tooltip扩展而来的 现在,当我单击显示帮助提示的按钮时,下面显示的第2行出现异常,它显示TypeError:this.\u showTimer.remove不是一个函数 if(this._showTimer){ this._showTimer.remove(); delete this._showTimer; } 我从dijit
HelpTip
,它是从dijit/Tooltip
扩展而来的
现在,当我单击显示帮助提示的按钮时,下面显示的第2行出现异常,它显示TypeError:this.\u showTimer.remove不是一个函数
if(this._showTimer){
this._showTimer.remove();
delete this._showTimer;
}
我从dijit/Tooltip(dojo1.9.1)的open
函数中复制了上面的代码。但是dijit.Tooltip(Dojo 1.3.1)中存在差异,如下所示:
if(this._showTimer){
clearTimeout(this._showTimer);
delete this._showTimer;
}
调试应用程序时,它会在\u showTimer
变量中显示一些编号的值。所以,您可以看到,在应用程序的1.3.1版本中,clearTimeout得到一个数字,并且工作正常。但在1.9.3版本中,它试图调用编号值的remove
方法,我真的不知道这是为什么
编辑:这是我的
HelpTip.js
文件的代码
define([
"dojo/_base/array",
"dojo/_base/declare",
"dojo/_base/lang",
"dojo/dom",
"dojo/has",
"dojo/topic",
"dijit/Tooltip",
"dojo/on"
], function (array, declare, lang, dom, has, topic, Tooltip, on) {
var HelpTip = declare("tt.widget.HelpTip",Tooltip,{
// summary
// Pops up a tooltip (a help message) when you hover over a node.
showDelay: 0,
_noHelpAvailable: "Unable to load help for this item. Please contact support.",
api: null,
connectHandlers: function(/*Array*/ ids) {
array.forEach(ids, function(id) {
var node = dom.byId(id);
if (node && node.tagName.toLowerCase() != "html" && node.tagName.toLowerCase() != "head" && node.tagName.toLowerCase() != "body") {
this.connectId.push(node);
// For A11y we may need to work with onFocus as well
this.connect(node, "onclick", "_onClick");
if(has("ie")){
// BiDi workaround
node.style.zoom = 1;
}
}
}, this);
},
disconnectHandlers: function(/*Array*/ ids) {
if (ids) {
for (var i = this._connects.length - 1; i >= 0; i--) {
if (this._connects[i] && this._connects[i][0] && this._connects[i][0][0]) {
if (array.indexOf(ids, this._connects[i][0][0].id) != -1) {
this._connects[i].remove();
}
}
}
}
},
_onClick: function(/*Event*/ e) {
e.preventDefault(); // don't navigate!
this._onHover(/*Event*/ e);
},
_onHover: function(/*Event*/ e){
if (e.target.id == null || e.target.id == "") {
this.label = this._noHelpAvailable;
} else {
this.label = "Retreiving help for this item...";
this.aroundNode = e.target;
var ids = e.target.id.split("_");
this.api.helpGetText(lang.hitch(this, this.helpGetText), ids[0], ids[1], ids[2]);
}
if(!this._showTimer){
var target = e.target;
this._showTimer = setTimeout(lang.hitch(this, function(){this.open(target)}), this.showDelay);
}
},
_onUnHover: function(/*Event*/ e){
// keep a tooltip open if the associated element has focus
if(this._focus){ return; }
if(this._showTimer){
clearTimeout(this._showTimer);
delete this._showTimer;
}
this.closeNodeConnect.remove();
this.close();
},
helpGetText: function(/*String*/ helpText, /*Object*/ error) {
if (error) {
topic.publish("/errorHandling/trapError", error);
return;
}
this.closeNode = document.createElement("div");
this.closeNode.className = "fakeLink";
this.closeNode.innerHTML = "Close";
this.closeNodeConnect = this.connect(this.closeNode, "click", "_onUnHover");
if (helpText != null && helpText != "") {
if (dijit._masterTT.containerNode != null) {
dijit._masterTT.containerNode.innerHTML = helpText + "<br><br>";
dijit._masterTT.containerNode.appendChild(this.closeNode);
}
} else {
if (dijit._masterTT.containerNode != null) {
dijit._masterTT.containerNode.innerHTML = this._noHelpAvailable + "<br><br>";
dijit._masterTT.containerNode.appendChild(this.closeNode);
}
}
// Firefox bug. when innerHTML changes to be shorter than previous
// one, the node size will not be updated until it moves.
dijit._masterTT.domNode.style.top = (dijit._masterTT.domNode.offsetTop + 1) + "px";
// position the element and change CSS according to position
var align = dijit._masterTT.isLeftToRight() ? {'BR': 'BL', 'BL': 'BR'} : {'BL': 'BR', 'BR': 'BL'};
var pos = dijit.placeOnScreenAroundElement(dijit._masterTT.domNode, this.aroundNode, align);
this.aroundNode = null;
dijit._masterTT.domNode.className="dijitTooltip dijitTooltip" + (pos.corner=='BL' ? "Right" : "Left");//FIXME: might overwrite class
}
}
);
return HelpTip;
});
定义([
“dojo/_基/阵列”,
“dojo/_base/declare”,
“dojo/_base/lang”,
“dojo/dom”,
“dojo/has”,
“dojo/主题”,
“dijit/工具提示”,
“dojo/on”
],函数(数组、声明、语言、dom、has、主题、工具提示等){
var HelpTip=declare(“tt.widget.HelpTip”),工具提示{
//总结
//将鼠标悬停在节点上时,会弹出工具提示(帮助消息)。
显示延迟:0,
_noHelpAvailable:“无法加载此项目的帮助。请与支持人员联系。”,
api:null,
connectHandlers:函数(/*数组*/ids){
forEach(id,function(id){
var节点=dom.byId(id);
if(node&&node.tagName.toLowerCase()!=“html”&&node.tagName.toLowerCase()!=“head”&&node.tagName.toLowerCase()!=“body”){
此.connected.push(节点);
//对于11年,我们可能还需要与onFocus合作
this.connect(节点,“onclick”,“onclick”);
如有(即有){
//比迪解决方案
node.style.zoom=1;
}
}
},这个);
},
disconnectHandlers:函数(/*Array*/ids){
如果(ID){
对于(var i=this.\u.length-1;i>=0;i--){
if(this._连接[i]&此._连接[i][0]&此._连接[i][0][0]){
if(array.indexOf(id,this._连接[i][0][0].id)!=-1){
此._连接[i].remove();
}
}
}
}
},
_onClick:function(/*Event*/e){
e、 preventDefault();//不要导航!
这个。_onHover(/*事件*/e);
},
_onHover:function(/*Event*/e){
如果(e.target.id==null | | e.target.id==“”){
this.label=this.\u无可用帮助;
}否则{
this.label=“检索此项目的帮助…”;
this.aroundNode=e.target;
var id=e.target.id.split(“”);
this.api.helpGetText(lang.hitch(this,this.helpGetText),ids[0],ids[1],ids[2]);
}
如果(!this.\u showTimer){
var目标=e.target;
this._showTimer=setTimeout(lang.hitch(this,function(){this.open(target)}),this.showtelay);
}
},
_onUnHover:函数(/*Event*/e){
//如果关联元素具有焦点,则保持工具提示打开
if(this._focus){return;}
如果(这个._showTimer){
clearTimeout(此.\u showTimer);
删除此项。\u showTimer;
}
this.closeNodeConnect.remove();
这个。关闭();
},
helpGetText:函数(/*String*/helpText,/*Object*/error){
如果(错误){
发布(“/errorHandling/traperor”,错误);
返回;
}
this.closeNode=document.createElement(“div”);
this.closeNode.className=“fakeLink”;
this.closeNode.innerHTML=“Close”;
this.closeNodeConnect=this.connect(this.closeNode,“单击”,“打开”);
如果(helpText!=null&&helpText!=“”){
if(dijit.\u masterTT.containerNode!=null){
dijit._masterTT.containerNode.innerHTML=helpText+“
”;
dijit._masterTT.containerNode.appendChild(this.closeNode);
}
}否则{
if(dijit.\u masterTT.containerNode!=null){
dijit._masterTT.containerNode.innerHTML=this._noHelpAvailable+“
”;
dijit._masterTT.containerNode.appendChild(this.closeNode);
}
}
//Firefox错误。当innerHTML更改为比以前短时
//首先,节点大小在移动之前不会更新。
dijit._masterTT.domNode.style.top=(dijit._masterTT.domNode.offsetTop+1)+“px”;
//定位元素并根据位置更改CSS
var align=dijit.\u masterTT.isleftorght()?{'BR':'BL','BL':'BR'}:{'BL':'BR','BR':'BL'};
var pos=dijit.placeOnScreenAroundElement(dijit.\u masterTT.domNode,this.aroundNode,align);
this.aroundNode=null;
dijit.\u masterTT.domNode.className=“dijitTooltip dijitTooltip”+(pos.corner==“BL”?“Right”:“Left”);//修复:可能会覆盖类
}
_onHover: function(/*DomNode*/ target){
// summary:
// Despite the name of this method, it actually handles both hover and focus
// events on the target node, setting a timer to show the tooltip.
// tags:
// private
if(!this._showTimer){
this._showTimer = this.defer(function(){ this.open(target); }, this.showDelay);
}
},