* Turns a selector, nodeList, or array of elements into an array of elements (so we can use array methods). * It also throws errors on any other inputs. Used to handle inputs to .add and .remove. * @param {String|Array|Nodelist} input - A CSS selector string targeting elements with anchor
(input)
| 279 | * @returns {Array} - An array containing the elements we want. |
| 280 | */ |
| 281 | function _getElements(input) { |
| 282 | var elements; |
| 283 | if (typeof input === 'string' || input instanceof String) { |
| 284 | // See https://davidwalsh.name/nodelist-array for the technique transforming nodeList -> Array. |
| 285 | elements = [].slice.call(document.querySelectorAll(input)); |
| 286 | // I checked the 'input instanceof NodeList' test in IE9 and modern browsers and it worked for me. |
| 287 | } else if (Array.isArray(input) || input instanceof NodeList) { |
| 288 | elements = [].slice.call(input); |
| 289 | } else { |
| 290 | throw new Error('The selector provided to AnchorJS was invalid.'); |
| 291 | } |
| 292 | return elements; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * _addBaselineStyles |