1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 12:07:19 +00:00

Add "tag" attribute to keyboard widget (#2593)

* allows to define the tag for keyboard widget

* added from 5.1.14 to docs
This commit is contained in:
Tobias Beer 2017-01-13 19:17:19 +01:00 committed by Jeremy Ruston
parent 2b90d0ab96
commit 1b339e17bc
2 changed files with 9 additions and 3 deletions

View File

@ -33,8 +33,12 @@ KeyboardWidget.prototype.render = function(parent,nextSibling) {
// Compute attributes and execute state
this.computeAttributes();
this.execute();
var tag = this.parseTreeNode.isBlock ? "div" : "span";
if(this.tag && $tw.config.htmlUnsafeElements.indexOf(this.tag) === -1) {
tag = this.tag;
}
// Create element
var domNode = this.document.createElement("div");
var domNode = this.document.createElement(tag);
// Assign classes
var classes = (this["class"] || "").split(" ");
classes.push("tc-keyboard");
@ -72,6 +76,7 @@ KeyboardWidget.prototype.execute = function() {
this.message = this.getAttribute("message");
this.param = this.getAttribute("param");
this.key = this.getAttribute("key");
this.tag = this.getAttribute("tag");
this.keyInfoArray = $tw.keyboardManager.parseKeyDescriptors(this.key);
this["class"] = this.getAttribute("class");
// Make child widgets
@ -83,7 +88,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
*/
KeyboardWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes.message || changedAttributes.param || changedAttributes.key || changedAttributes["class"]) {
if(changedAttributes.message || changedAttributes.param || changedAttributes.key || changedAttributes["class"] || changedAttributes.tag) {
this.refreshSelf();
return true;
}

View File

@ -1,6 +1,6 @@
caption: keyboard
created: 20140302192136805
modified: 20160429175258940
modified: 20161003114634019
tags: Widgets
title: KeyboardWidget
type: text/vnd.tiddlywiki
@ -19,6 +19,7 @@ The content of the `<$keyboard>` widget is rendered normally. The keyboard short
|param |The parameter to be passed with the [[WidgetMessage|Messages]] |
|key |Key string identifying the key(s) to be trapped (see below) |
|class |A CSS class to be assigned to the generated HTML DIV element |
|tag|<<.from-version "5.1.14">> The html element the widget creates to capture the keyboard event, defaults to:<br>» `span` when parsed in inline-mode<br>» `div` when parsed in block-mode|
! Key Strings