Fossil SCM
fossil.dom: added label() and checkbox() methods.
Commit
ba912d94b9675177e8cf3dd1685e4b09f28bb0a42899762f5b4a5010e86318fd
Parent
299e06435d51e83…
1 file changed
+20
-2
+20
-2
| --- src/fossil.dom.js | ||
| +++ src/fossil.dom.js | ||
| @@ -72,11 +72,28 @@ | ||
| 72 | 72 | dom.footer = dom.createElemFactory('footer'); |
| 73 | 73 | dom.section = dom.createElemFactory('section'); |
| 74 | 74 | dom.span = dom.createElemFactory('span'); |
| 75 | 75 | dom.strong = dom.createElemFactory('strong'); |
| 76 | 76 | 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 | + }; | |
| 78 | 95 | dom.img = function(src){ |
| 79 | 96 | const e = dom.create('img'); |
| 80 | 97 | if(src) e.setAttribute('src',src); |
| 81 | 98 | return e; |
| 82 | 99 | }; |
| @@ -233,11 +250,12 @@ | ||
| 233 | 250 | }; |
| 234 | 251 | |
| 235 | 252 | dom.input = function(type){ |
| 236 | 253 | return this.attr(this.create('input'), 'type', type); |
| 237 | 254 | }; |
| 238 | - | |
| 255 | + dom.checkbox = ()=>dom.input('checkbox'); | |
| 256 | + | |
| 239 | 257 | /** |
| 240 | 258 | Internal impl for addClass(), removeClass(). |
| 241 | 259 | */ |
| 242 | 260 | const domAddRemoveClass = function f(action,e){ |
| 243 | 261 | if(!f.rxSPlus){ |
| 244 | 262 |
| --- 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 |