Skip to content

Commit

Permalink
Allow .isWrappped() to handle nodeLists and more wrapped types. FORM …
Browse files Browse the repository at this point in the history
…has a length and is not wrapped, so disallow Nodes

Fixes #723
  • Loading branch information
Rycochet committed Dec 14, 2016
1 parent 60c9113 commit abfd965
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions velocity.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,16 +553,15 @@
isNode: function(variable) {
return variable && variable.nodeType;
},
/* Copyright Martin Bohm. MIT License: https://gist.github.com/Tomalak/818a78a226a0738eaade */
isNodeList: function(variable) {
return typeof variable === "object" &&
/^\[object (HTMLCollection|NodeList|Object)\]$/.test(Object.prototype.toString.call(variable)) &&
variable.length !== undefined &&
(variable.length === 0 || (typeof variable[0] === "object" && variable[0].nodeType > 0));
},
/* Determine if variable is an array-like wrapped jQuery, Zepto or similar element. */
/* Determine if variable is an array-like wrapped jQuery, Zepto or similar element, or even a NodeList etc. */
/* NOTE: HTMLFormElements also have a length. */
isWrapped: function(variable) {
return variable && (Type.isArray(variable) || (Type.isNumber(variable.length) && !Type.isString(variable) && !Type.isFunction(variable)));
return variable
&& Type.isNumber(variable.length)
&& !Type.isString(variable)
&& !Type.isFunction(variable)
&& !Type.isNode(variable)
&& (variable.length === 0 || Type.isNode(variable[0]));
},
isSVG: function(variable) {
return window.SVGElement && (variable instanceof window.SVGElement);
Expand Down
Loading

0 comments on commit abfd965

Please sign in to comment.