kopia lustrzana https://github.com/miklobit/TiddlyWiki5
Refactor link widget with tidier event handler
rodzic
ad518c181d
commit
068befb24f
|
@ -74,24 +74,28 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) {
|
||||||
wikiLinkText = wikiLinkText.replace("$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to)));
|
wikiLinkText = wikiLinkText.replace("$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to)));
|
||||||
domNode.setAttribute("href",wikiLinkText);
|
domNode.setAttribute("href",wikiLinkText);
|
||||||
// Add a click event handler
|
// Add a click event handler
|
||||||
domNode.addEventListener("click",function (event) {
|
$tw.utils.addEventListeners(domNode,[
|
||||||
|
{name: "click", handlerObject: this, handlerMethod: "handleClickEvent"}
|
||||||
|
]);
|
||||||
|
// Insert the link into the DOM and render any children
|
||||||
|
parent.insertBefore(domNode,nextSibling);
|
||||||
|
this.renderChildren(domNode,null);
|
||||||
|
this.domNodes.push(domNode);
|
||||||
|
};
|
||||||
|
|
||||||
|
LinkWidget.prototype.handleClickEvent = function (event) {
|
||||||
// Send the click on it's way as a navigate event
|
// Send the click on it's way as a navigate event
|
||||||
var bounds = domNode.getBoundingClientRect();
|
var bounds = this.domNodes[0].getBoundingClientRect();
|
||||||
self.dispatchEvent({
|
this.dispatchEvent({
|
||||||
type: "tw-navigate",
|
type: "tw-navigate",
|
||||||
navigateTo: self.to,
|
navigateTo: this.to,
|
||||||
navigateFromNode: self,
|
navigateFromNode: this,
|
||||||
navigateFromClientRect: { top: bounds.top, left: bounds.left, width: bounds.width, right: bounds.right, bottom: bounds.bottom, height: bounds.height
|
navigateFromClientRect: { top: bounds.top, left: bounds.left, width: bounds.width, right: bounds.right, bottom: bounds.bottom, height: bounds.height
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return false;
|
return false;
|
||||||
},false);
|
|
||||||
// Insert the link into the DOM and render any children
|
|
||||||
parent.insertBefore(domNode,nextSibling);
|
|
||||||
this.renderChildren(domNode,null);
|
|
||||||
this.domNodes.push(domNode);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Ładowanie…
Reference in New Issue