mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-11 18:00:26 +00:00
Add a linkcatcher widget
It intercepts navigation events and saves the target tiddler title into a specified text reference
This commit is contained in:
parent
92038028e9
commit
aa7b9441fd
56
core/modules/widgets/linkcatcher.js
Normal file
56
core/modules/widgets/linkcatcher.js
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/widget/linkcatcher.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: widget
|
||||||
|
|
||||||
|
Implements the linkcatcher widget.
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var LinkCatcherWidget = function(renderer) {
|
||||||
|
// Save state
|
||||||
|
this.renderer = renderer;
|
||||||
|
// Generate child nodes
|
||||||
|
this.generate();
|
||||||
|
};
|
||||||
|
|
||||||
|
LinkCatcherWidget.prototype.generate = function() {
|
||||||
|
// Get our attributes
|
||||||
|
this.to = this.renderer.getAttribute("to");
|
||||||
|
// Set the element
|
||||||
|
this.tag = "div";
|
||||||
|
this.attributes = {
|
||||||
|
"class": "tw-linkcatcher"
|
||||||
|
};
|
||||||
|
this.children = this.renderer.renderTree.createRenderers(this.renderer.renderContext,this.renderer.parseTreeNode.children);
|
||||||
|
this.events = [
|
||||||
|
{name: "tw-navigate", handlerObject: this, handlerMethod: "handleNavigateEvent"}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
LinkCatcherWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) {
|
||||||
|
// We don't need to refresh ourselves, so just refresh any child nodes
|
||||||
|
$tw.utils.each(this.children,function(node) {
|
||||||
|
if(node.refreshInDom) {
|
||||||
|
node.refreshInDom(changedTiddlers);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Navigate to a specified tiddler
|
||||||
|
LinkCatcherWidget.prototype.handleNavigateEvent = function(event) {
|
||||||
|
if(this.to) {
|
||||||
|
this.renderer.renderTree.wiki.setTextReference(this.to,event.navigateTo,this.renderer.getContextTiddlerTitle());
|
||||||
|
}
|
||||||
|
event.stopPropagation();
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.linkcatcher = LinkCatcherWidget;
|
||||||
|
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user