Last active
August 29, 2015 14:17
-
-
Save vermilion1/4dc9fd44c17cd91f9ba5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* 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