From c81d5f00f71ff3f0833b5966c14f14bc0af7c4ad Mon Sep 17 00:00:00 2001 From: piro Date: Mon, 13 Sep 2010 10:20:43 +0000 Subject: [PATCH] old => expected git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@7187 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- modules/utils.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/modules/utils.js b/modules/utils.js index 7b7afd0b..64d99ebb 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -793,30 +793,38 @@ var TreeStyleTabUtils = { safeSetAttribute : function TSTUtils_safeSetAttribute(aElem, aAttr, aValue) { - var old = {}; + var expected = {}; Array.slice(aElem.attributes).forEach(function(aAttr) { - old[aAttr.name] = aAttr.value; + expected[aAttr.name] = aAttr.value; }); - if (aValue) + if (aValue) { + expected[aAttr] = aValue; aElem.setAttribute(aAttr, aValue); - else + } + else { + expected[aAttr] = ''; aElem.removeAttribute(aAttr); + } - for (var i in old) + for (let i in expected) { - if (old[i] != aElem.getAttribute(i)) { + if (expected[i] != aElem.getAttribute(i)) { dump('TSTUtils_safeSetAttribute restores '+aElem+'.'+i+ - ', from '+aElem.getAttribute(i)+' to '+old[i]+'\n'); - aElem.setAttribute(i, old[i]); + ', from '+aElem.getAttribute(i)+' to '+expected[i]+'\n'); + if (expected[i]) + aElem.setAttribute(i, expected[i]); + else + aElem.removeAttribute(i); } } + // verification - for (var i in old) + for (let i in expected) { - if (old[i] != aElem.getAttribute(i)) { - dump('TSTUtils_safeSetAttribute failed to restore '+aElem+'.'+i+ - ', from '+aElem.getAttribute(i)+' to '+old[i]+'\n'); + if (expected[i] != aElem.getAttribute(i)) { + dump(' => failed to change '+aElem+'.'+i+ + ', from '+aElem.getAttribute(i)+' to '+expected[i]+'\n'); } } },