Fossil SCM

fossil.dom: added label() and checkbox() methods.

stephan 2020-09-11 21:52 trunk
Commit ba912d94b9675177e8cf3dd1685e4b09f28bb0a42899762f5b4a5010e86318fd
1 file changed +20 -2
--- src/fossil.dom.js
+++ src/fossil.dom.js
@@ -72,11 +72,28 @@
7272
dom.footer = dom.createElemFactory('footer');
7373
dom.section = dom.createElemFactory('section');
7474
dom.span = dom.createElemFactory('span');
7575
dom.strong = dom.createElemFactory('strong');
7676
dom.em = dom.createElemFactory('em');
77
- dom.label = dom.createElemFactory('label');
77
+ /**
78
+ Returns a LABEL element. If passed an argument,
79
+ it must be an id or an HTMLElement with an id,
80
+ and that id is set as the 'for' attribute of the
81
+ label. If passed 2 arguments, the 2nd is text or
82
+ a DOM element to append to the label.
83
+ */
84
+ dom.label = function(forElem, text){
85
+ const rc = document.createElement('label');
86
+ if(forElem){
87
+ if(forElem instanceof HTMLElement){
88
+ forElem = dom.attr(forElem, 'id');
89
+ }
90
+ dom.attr(rc, 'for', forElem);
91
+ }
92
+ if(text) dom.append(rc, text);
93
+ return rc;
94
+ };
7895
dom.img = function(src){
7996
const e = dom.create('img');
8097
if(src) e.setAttribute('src',src);
8198
return e;
8299
};
@@ -233,11 +250,12 @@
233250
};
234251
235252
dom.input = function(type){
236253
return this.attr(this.create('input'), 'type', type);
237254
};
238
-
255
+ dom.checkbox = ()=>dom.input('checkbox');
256
+
239257
/**
240258
Internal impl for addClass(), removeClass().
241259
*/
242260
const domAddRemoveClass = function f(action,e){
243261
if(!f.rxSPlus){
244262
--- src/fossil.dom.js
+++ src/fossil.dom.js
@@ -72,11 +72,28 @@
72 dom.footer = dom.createElemFactory('footer');
73 dom.section = dom.createElemFactory('section');
74 dom.span = dom.createElemFactory('span');
75 dom.strong = dom.createElemFactory('strong');
76 dom.em = dom.createElemFactory('em');
77 dom.label = dom.createElemFactory('label');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78 dom.img = function(src){
79 const e = dom.create('img');
80 if(src) e.setAttribute('src',src);
81 return e;
82 };
@@ -233,11 +250,12 @@
233 };
234
235 dom.input = function(type){
236 return this.attr(this.create('input'), 'type', type);
237 };
238
 
239 /**
240 Internal impl for addClass(), removeClass().
241 */
242 const domAddRemoveClass = function f(action,e){
243 if(!f.rxSPlus){
244
--- src/fossil.dom.js
+++ src/fossil.dom.js
@@ -72,11 +72,28 @@
72 dom.footer = dom.createElemFactory('footer');
73 dom.section = dom.createElemFactory('section');
74 dom.span = dom.createElemFactory('span');
75 dom.strong = dom.createElemFactory('strong');
76 dom.em = dom.createElemFactory('em');
77 /**
78 Returns a LABEL element. If passed an argument,
79 it must be an id or an HTMLElement with an id,
80 and that id is set as the 'for' attribute of the
81 label. If passed 2 arguments, the 2nd is text or
82 a DOM element to append to the label.
83 */
84 dom.label = function(forElem, text){
85 const rc = document.createElement('label');
86 if(forElem){
87 if(forElem instanceof HTMLElement){
88 forElem = dom.attr(forElem, 'id');
89 }
90 dom.attr(rc, 'for', forElem);
91 }
92 if(text) dom.append(rc, text);
93 return rc;
94 };
95 dom.img = function(src){
96 const e = dom.create('img');
97 if(src) e.setAttribute('src',src);
98 return e;
99 };
@@ -233,11 +250,12 @@
250 };
251
252 dom.input = function(type){
253 return this.attr(this.create('input'), 'type', type);
254 };
255 dom.checkbox = ()=>dom.input('checkbox');
256
257 /**
258 Internal impl for addClass(), removeClass().
259 */
260 const domAddRemoveClass = function f(action,e){
261 if(!f.rxSPlus){
262

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button