Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add action-popup widget ... #4185

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions core/modules/widgets/action-popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*\
title: $:/core/modules/widgets/action-popup.js
type: application/javascript
module-type: widget

ActionPopup widget

\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

var Widget = require("$:/core/modules/widgets/widget.js").widget;

var ActionPopupWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};

/*
Inherit from the base widget class
*/
ActionPopupWidget.prototype = new Widget();

/*
Render this widget into the DOM
*/
ActionPopupWidget.prototype.render = function(parent,nextSibling) {
var self = this;
// Remember parent
this.parentDomNode = parent;
// Compute attributes and execute state
this.computeAttributes();
this.execute();
var domNode = this.document.createElement("div");
parent.insertBefore(domNode,nextSibling);
this.domNodes.push(domNode);
};

ActionPopupWidget.prototype.triggerPopup = function(event) {
$tw.popup.triggerPopup({
domNode: this.domNodes[0],
title: this.popup,
wiki: this.wiki
});
};

/*
Compute the internal state of the widget
*/
ActionPopupWidget.prototype.execute = function() {
// Get attributes
this.popup = this.getAttribute("$popup");
};

ActionPopupWidget.prototype.invokeAction = function(triggeringWidget,event) {
if(this.popup) {
this.triggerPopup();
}
return true;
};

/*
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
*/
ActionPopupWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes["$popup"] || (this.popup && changedTiddlers[this.popup])) {
this.refreshSelf();
return true;
}
return this.refreshChildren(changedTiddlers);
};

exports["action-popup"] = ActionPopupWidget;

})();