kopia lustrzana https://github.com/miklobit/TiddlyWiki5
Support selectedClass properly in the button widget
rodzic
fe6c1ae2dd
commit
94c2eacdc9
|
@ -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")});
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
||||
})();
|
||||
|
|
Ładowanie…
Reference in New Issue