Skip to content

Instantly share code, notes, and snippets.

@vermilion1
Last active August 29, 2015 14:17
Show Gist options
  • Save vermilion1/4dc9fd44c17cd91f9ba5 to your computer and use it in GitHub Desktop.
Save vermilion1/4dc9fd44c17cd91f9ba5 to your computer and use it in GitHub Desktop.
/**
* Get all items starting from the passed index that are located in the same top line.
* @param {jQuery} $items - List of elements.
* @param {Number} index - Index of the first element.
* @returns {Array|undefined} Found items.
*/
getLineItems: function ($items, index) {
var $first = $items.eq(index);
var items = [$first];
var $next, getNext, top;
if (!$first.length) {
return void 0;
}
top = $first.offset().top;
getNext = function () {
var $item = $items.eq(index + items.length);
if ($item.length && top === $item.offset().top) {
return $item;
}
return void 0;
};
while (($next = getNext()) !== void 0) {
items.push($next);
}
return items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment