From 94c2eacdc9c4cad8d1e4a766b13aad39e4d0fe15 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Mon, 14 Oct 2013 16:56:13 +0100 Subject: [PATCH] Support selectedClass properly in the button widget --- core/modules/new_widgets/button.js | 15 ++++++++++++--- core/modules/utils/dom/popup.js | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/core/modules/new_widgets/button.js b/core/modules/new_widgets/button.js index f09f64a91..76f1bf0e5 100644 --- a/core/modules/new_widgets/button.js +++ b/core/modules/new_widgets/button.js @@ -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")}); }; diff --git a/core/modules/utils/dom/popup.js b/core/modules/utils/dom/popup.js index cd2c92277..2626fff0f 100644 --- a/core/modules/utils/dom/popup.js +++ b/core/modules/utils/dom/popup.js @@ -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 "(,)" - 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; })();