Unverified Commit 47e0bff6 authored by Joel Copi's avatar Joel Copi Committed by GitHub
Browse files

Merge pull request #2 from jcopi/develop

Develop
parents b109df6a 31b58165
......@@ -23,7 +23,8 @@ Name | Arguments | Behavior
index | `(Number desired_index)` | Sets the current selection to `desired_index`
include | `(Generic selector)` | Adds a new selection to the current selection. `selector` functions in the same way as the constructor
exclude | `(Generic selector)` | Removes any elements from the current selection that match `selector` which functions in the same way as the constructor
get | `(Number index)` | Returns the raw HTMLElement of the selection at `index`
get | `(Number index)` | Shrinks the selection to only the element at `index` in the current selection
raw | `(Number index)` | Returns the raw HTMLElement of the selection at `index`
remove | `(void)` | Removes all selected elements from the document
each | `(Function func)` | Calls `func` on each selected element
filter | `(Function func)` | Calls `func` on each selected element if it returns `false` the current element is removed from the selection
......
......@@ -158,6 +158,11 @@
return _lib(result);
},
get: function (num) {
/* changes the selection to include only the elemnt at the inputted index of the current selection */
if (!(num instanceof Number || typeof num == "number")) throw "Method get only accepts an argument of type Number";
return _lib(this[num]);
},
raw: function (num) {
/* returns the raw HTML element at a particular index */
if (!(num instanceof Number || typeof num == "number")) throw "Method get only accepts an argument of type Number";
return this[num];
......@@ -199,12 +204,32 @@
for (var i = 0; i < this.length; i++) {
result.push(this[i].parentNode);
/* check all previously found parents to make sure none are repeated */
for (ii = i; ii--; check = check && result[i] === result[ii]);
for (var ii = i; i--; check = check && result[i] !== result[ii]);
if (!check) result.pop();
}
return _lib(result);
},
/* The algorithm for sibling is not particularly space efficient at this stage of development */
sibling: function (selector) {
/* returns a selection of the siblings of each child that match the input selection */
var interm = [], check = true;
for (var i = 0; i < this.length; i++) {
interm.push(_lib(selector, this[i]));
}
/* The interm array may hold iterable objects as elements. Calling _lib on it will flatten it,
allowing duplicates to be removed iteratively */
var interm2 = _lib(interm);
var result = [];
for (var i = 0; i < interm2.length; i++) {
result.push(interm2[i]);
for (var ii = i; i--; check = check && result[i] !== result[ii]);
if (!check) result.pop();
}
return _lib(result);
},
appendTo: function (parent) {
/* An undefined parent could cause issues */
if (!parent) throw "Method appendTo expects an argument";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment