Fossil SCM

fossil.dom.attr(target,key,val) now supports any number of key/value pairs to set in a single call.

stephan 2020-08-30 15:57 wikiedit-wysiwyg-legacy
Commit a89f116e111e00dd88aec7c227c78969fb436b393e9e89f1ef10322c5743261c
1 file changed +21 -12
+21 -12
--- src/fossil.dom.js
+++ src/fossil.dom.js
@@ -400,26 +400,35 @@
400400
};
401401
dom.replaceNode.counter = 0;
402402
/**
403403
Two args == getter: (e,key), returns value
404404
405
- Three == setter: (e,key,val), returns e. If val===null
406
- or val===undefined then the attribute is removed. If (e)
407
- has a forEach method then this routine is applied to each
408
- element of that collection via that method.
405
+ Three or more == setter: (e,key,val[...,keyN,valN]), returns
406
+ e. If val===null or val===undefined then the attribute is
407
+ removed. If (e) has a forEach method then this routine is applied
408
+ to each element of that collection via that method. Each pair of
409
+ keys/values is applied to all elements designated by the first
410
+ argument.
409411
*/
410412
dom.attr = function f(e){
411413
if(2===arguments.length) return e.getAttribute(arguments[1]);
412
- if(e.forEach){
413
- e.forEach((x)=>f(x,arguments[1],arguments[2]));
414
+ const a = argsToArray(arguments);
415
+ if(e.forEach){ /* Apply to all elements in the collection */
416
+ e.forEach(function(x){
417
+ a[0] = x;
418
+ f.apply(f,a);
419
+ });
414420
return e;
415
- }
416
- const key = arguments[1], val = arguments[2];
417
- if(null===val || undefined===val){
418
- e.removeAttribute(key);
419
- }else{
420
- e.setAttribute(key,val);
421
+ }
422
+ a.shift(/*element(s)*/);
423
+ while(a.length){
424
+ const key = a.shift(), val = a.shift();
425
+ if(null===val || undefined===val){
426
+ e.removeAttribute(key);
427
+ }else{
428
+ e.setAttribute(key,val);
429
+ }
421430
}
422431
return e;
423432
};
424433
425434
const enableDisable = function f(enable){
426435
--- src/fossil.dom.js
+++ src/fossil.dom.js
@@ -400,26 +400,35 @@
400 };
401 dom.replaceNode.counter = 0;
402 /**
403 Two args == getter: (e,key), returns value
404
405 Three == setter: (e,key,val), returns e. If val===null
406 or val===undefined then the attribute is removed. If (e)
407 has a forEach method then this routine is applied to each
408 element of that collection via that method.
 
 
409 */
410 dom.attr = function f(e){
411 if(2===arguments.length) return e.getAttribute(arguments[1]);
412 if(e.forEach){
413 e.forEach((x)=>f(x,arguments[1],arguments[2]));
 
 
 
 
414 return e;
415 }
416 const key = arguments[1], val = arguments[2];
417 if(null===val || undefined===val){
418 e.removeAttribute(key);
419 }else{
420 e.setAttribute(key,val);
 
 
 
421 }
422 return e;
423 };
424
425 const enableDisable = function f(enable){
426
--- src/fossil.dom.js
+++ src/fossil.dom.js
@@ -400,26 +400,35 @@
400 };
401 dom.replaceNode.counter = 0;
402 /**
403 Two args == getter: (e,key), returns value
404
405 Three or more == setter: (e,key,val[...,keyN,valN]), returns
406 e. If val===null or val===undefined then the attribute is
407 removed. If (e) has a forEach method then this routine is applied
408 to each element of that collection via that method. Each pair of
409 keys/values is applied to all elements designated by the first
410 argument.
411 */
412 dom.attr = function f(e){
413 if(2===arguments.length) return e.getAttribute(arguments[1]);
414 const a = argsToArray(arguments);
415 if(e.forEach){ /* Apply to all elements in the collection */
416 e.forEach(function(x){
417 a[0] = x;
418 f.apply(f,a);
419 });
420 return e;
421 }
422 a.shift(/*element(s)*/);
423 while(a.length){
424 const key = a.shift(), val = a.shift();
425 if(null===val || undefined===val){
426 e.removeAttribute(key);
427 }else{
428 e.setAttribute(key,val);
429 }
430 }
431 return e;
432 };
433
434 const enableDisable = function f(enable){
435

Keyboard Shortcuts

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