Update select widget to support style.* attributes

This commit is contained in:
Jeremy Ruston 2023-11-13 09:47:18 +00:00
parent 980022a6e7
commit 65b3b18e1f
3 changed files with 20 additions and 16 deletions

View File

@ -169,7 +169,7 @@ SelectWidget.prototype.execute = function() {
if(this.selectTooltip) {
$tw.utils.addAttributeToParseTreeNode(selectNode,"title",this.selectTooltip);
}
this.updateParseTreeDataAttributes(selectNode);
this.assignAttributesToParseTreeNode(selectNode);
this.makeChildWidgets([selectNode]);
};

View File

@ -458,6 +458,21 @@ Widget.prototype.assignAttributes = function(domNode,options) {
});
};
/*
Set the data- and style. attributes of a parse tree node according to the attributes of the widget
domNode: optional domNode to be assigned
*/
Widget.prototype.assignAttributesToParseTreeNode = function(parseTreeNode) {
var self = this;
var DATA_ATTRIBUTE_PREFIX = "data-",
STYLE_ATTRIBUTE_PREFIX = "style.";
$tw.utils.each(this.attributes,function(value,name) {
if(name.substr(0,DATA_ATTRIBUTE_PREFIX.length) === DATA_ATTRIBUTE_PREFIX || name.substr(0,STYLE_ATTRIBUTE_PREFIX.length) === STYLE_ATTRIBUTE_PREFIX) {
$tw.utils.addAttributeToParseTreeNode(parseTreeNode,name,value);
}
});
};
/*
Get the number of ancestor widgets for this widget
*/
@ -813,20 +828,6 @@ Widget.evaluateVariable = function(widget,name,options) {
return result;
};
/*
Set the data- attributes of a parse tree node according to the attributes of the widget
domNode: optional domNode to be assigned
*/
Widget.prototype.updateParseTreeDataAttributes = function(parseTreeNode) {
var self = this;
var DATA_ATTRIBUTE_PREFIX = "data-";
$tw.utils.each(this.attributes,function(value,name) {
if(name.substr(0,DATA_ATTRIBUTE_PREFIX.length) === DATA_ATTRIBUTE_PREFIX) {
$tw.utils.addAttributeToParseTreeNode(parseTreeNode,name,value);
}
});
};
exports.widget = Widget;
})();

View File

@ -1,6 +1,6 @@
caption: select
created: 20131024141900000
modified: 20211108165037846
modified: 20231113093304323
tags: TriggeringWidgets Widgets
title: SelectWidget
type: text/vnd.tiddlywiki
@ -42,6 +42,9 @@ The content of the `<$select>` widget should be one or more HTML `<option>` or `
|actions |A string containing ActionWidgets to be triggered when the key combination is detected |
|focus |<<.from-version "5.2.4">> Optional. Set to "yes" to automatically focus the HTML select element after creation |
|tabindex |<<.from-version "5.3.1">> Optional. Sets the `tabindex` attribute of the HTML select element to the given value |
|data-* |<<.from-version "5.3.2">> Optional [[data attributes|https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes]] to be assigned to the HTML element |
|style.* |<<.from-version "5.3.2">> Optional [[CSS properties|https://developer.mozilla.org/en-US/docs/Web/CSS/Reference]] to be assigned to the HTML element |
! Examples
!! Simple Lists