-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ | |
function swapElementNodes(currentNode, newNode, ignoreElements) { | ||
var $currentNode = $(currentNode), | ||
$newNode = $(newNode), | ||
idx = 0, | ||
shouldIgnore, | ||
$currChildNodes, | ||
$newChildNodes, | ||
|
@@ -65,10 +66,14 @@ | |
return; | ||
} | ||
|
||
// Remove current attributes | ||
// Remove current attributes that have changed | ||
currentAttributes = currentNode.attributes; | ||
while (currentAttributes.length > 0) { | ||
currentNode.removeAttribute(currentAttributes[0].name); | ||
while (idx < currentAttributes.length) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
arikwex
Contributor
|
||
currentAttr = currentAttributes[idx].name; | ||
if (!_.contains(currentAttr, newNode.attributes)) { | ||
currentNode.removeAttribute(currentAttr); | ||
} | ||
idx++; | ||
} | ||
|
||
// Set new attributes | ||
|
@@ -196,16 +201,16 @@ | |
}); | ||
return newDOM; | ||
}, | ||
/** | ||
|
||
/** | ||
* Determines if the element supports selection. As per spec, https://html.spec.whatwg.org/multipage/forms.html#do-not-apply | ||
* selection is only allowed for text, search, tel, url, password. Other input types will throw an exception in chrome | ||
* @param el {Element} the DOM element to check | ||
* @return {Boolean} boolean indicating whether or not the selection is allowed for {Element} el | ||
* @param el {Element} the DOM element to check | ||
* @return {Boolean} boolean indicating whether or not the selection is allowed for {Element} el | ||
* @method supportsSelection | ||
*/ | ||
supportsSelection : function (el) { | ||
return (/text|password|search|tel|url/).test(el.type); | ||
return (/text|password|search|tel|url/).test(el.type); | ||
}, | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
This is a bug. You aren't actually iterating over all elements.
currentNode.attributes
is aNamedNodeMap
, which is a "live" array representing the actual state of the DOM element at all times. In this case, each time you remove an element by callingcurrentNode.removeAttribute
, you shorten the length ofcurrentAttributes
. Since you still always call idx++, you'll end up skipping over every attribute that occurs immediately after a removed attribute.Also, what's the point of removing only the attributes that non-longer exist (as opposed to simply removing all attributes) if the next block manually sets all attributes from newNode anyways?