mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-23 14:30:02 +00:00
Add a linkcatcher widget
This commit is contained in:
parent
adb395d10f
commit
a3eaffa666
87
core/modules/new_widgets/linkcatcher.js
Normal file
87
core/modules/new_widgets/linkcatcher.js
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/new_widgets/linkcatcher.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: new_widget
|
||||||
|
|
||||||
|
Linkcatcher widget
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var Widget = require("$:/core/modules/new_widgets/widget.js").widget;
|
||||||
|
|
||||||
|
var LinkCatcherWidget = function(parseTreeNode,options) {
|
||||||
|
this.initialise(parseTreeNode,options);
|
||||||
|
this.addEventListeners([
|
||||||
|
{type: "tw-navigate", handler: "handleNavigateEvent"}
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Inherit from the base widget class
|
||||||
|
*/
|
||||||
|
LinkCatcherWidget.prototype = new Widget();
|
||||||
|
|
||||||
|
/*
|
||||||
|
Render this widget into the DOM
|
||||||
|
*/
|
||||||
|
LinkCatcherWidget.prototype.render = function(parent,nextSibling) {
|
||||||
|
this.parentDomNode = parent;
|
||||||
|
this.computeAttributes();
|
||||||
|
this.execute();
|
||||||
|
this.renderChildren(parent,nextSibling);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Compute the internal state of the widget
|
||||||
|
*/
|
||||||
|
LinkCatcherWidget.prototype.execute = function() {
|
||||||
|
// Get our parameters
|
||||||
|
this.catchTo = this.getAttribute("to");
|
||||||
|
this.catchMessage = this.getAttribute("message");
|
||||||
|
this.catchSet = this.getAttribute("set");
|
||||||
|
this.catchSetTo = this.getAttribute("setTo");
|
||||||
|
// Construct the child widgets
|
||||||
|
this.makeChildWidgets();
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
||||||
|
*/
|
||||||
|
LinkCatcherWidget.prototype.refresh = function(changedTiddlers) {
|
||||||
|
var changedAttributes = this.computeAttributes();
|
||||||
|
if(changedAttributes.to || changedAttributes.message || changedAttributes.set || changedAttributes.setTo) {
|
||||||
|
this.refreshSelf();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return this.refreshChildren(changedTiddlers);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Handle a tw-navigate event
|
||||||
|
*/
|
||||||
|
LinkCatcherWidget.prototype.handleNavigateEvent = function(event) {
|
||||||
|
if(this.catchTo) {
|
||||||
|
this.wiki.setTextReference(this.catchTo,event.navigateTo,this.getVariable("tiddlerTitle"));
|
||||||
|
}
|
||||||
|
if(this.catchMessage) {
|
||||||
|
this.dispatchEvent({
|
||||||
|
type: this.catchMessage,
|
||||||
|
param: event.navigateTo
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if(this.catchSet) {
|
||||||
|
var tiddler = this.wiki.getTiddler(this.catchSet);
|
||||||
|
this.wiki.addTiddler(new $tw.Tiddler(tiddler,{title: this.catchSet, text: this.catchSetTo}));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.linkcatcher = LinkCatcherWidget;
|
||||||
|
|
||||||
|
})();
|
@ -14,7 +14,6 @@ Temporary shim widgets
|
|||||||
|
|
||||||
var Widget = require("$:/core/modules/new_widgets/widget.js").widget;
|
var Widget = require("$:/core/modules/new_widgets/widget.js").widget;
|
||||||
|
|
||||||
exports.linkcatcher = Widget;
|
|
||||||
exports["import"] = Widget;
|
exports["import"] = Widget;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user