1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 18:39:54 +00:00

Support selectedClass properly in the button widget

This commit is contained in:
Jeremy Ruston 2013-10-14 16:56:13 +01:00
parent fe6c1ae2dd
commit 94c2eacdc9
2 changed files with 25 additions and 5 deletions

View File

@ -37,9 +37,12 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
var domNode = this.document.createElement("button");
// Assign classes
var classes = this["class"].split(" ") || [];
if(this.set && this.setTo && this.selectedClass) {
if(this.isSelected()) {
classes.push(this.selectedClass.split(" "));
if(this.selectedClass) {
if(this.set && this.setTo && this.isSelected()) {
$tw.utils.pushTop(classes,this.selectedClass.split(" "));
}
if(this.popup && this.isPoppedUp()) {
$tw.utils.pushTop(classes,this.selectedClass.split(" "));
}
}
domNode.className = classes.join(" ");
@ -75,6 +78,12 @@ ButtonWidget.prototype.isSelected = function() {
return tiddler ? tiddler.fields.text === this.setTo : false;
};
ButtonWidget.prototype.isPoppedUp = function() {
var tiddler = this.wiki.getTiddler(this.popup);
var result = tiddler && tiddler.fields.text ? $tw.popup.readPopupState(this.popup,tiddler.fields.text) : false;
return result;
};
ButtonWidget.prototype.dispatchMessage = function(event) {
this.dispatchEvent({type: this.message, param: this.param, tiddlerTitle: this.getVariable("tiddlerTitle")});
};

View File

@ -54,8 +54,7 @@ Popup.prototype.triggerPopup = function(options) {
// Get the current popup state tiddler
var value = options.wiki.getTextReference(options.title,"");
// Check if the popup is open by checking whether it matches "(<x>,<y>)"
var popupLocationRegExp = /^\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/,
state = !popupLocationRegExp.test(value);
var state = !this.readPopupState(options.title,value);
if("force" in options) {
state = options.force;
}
@ -71,6 +70,18 @@ Popup.prototype.triggerPopup = function(options) {
}
};
/*
Returns true if the specified title and text identifies an active popup
*/
Popup.prototype.readPopupState = function(title,text) {
var popupLocationRegExp = /^\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/,
result = false;
if(this.title === title) {
result = popupLocationRegExp.test(text);
}
return result;
};
exports.Popup = Popup;
})();