* Checks document order of two siblings * @param {Element} a * @param {Element} b * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
(a, b)
| 412 | */ |
| 413 | |
| 414 | function siblingCheck(a, b) { |
| 415 | var cur = b && a, |
| 416 | diff = cur && a.nodeType === 1 && b.nodeType === 1 && |
| 417 | (~b.sourceIndex || MAX_NEGATIVE) - |
| 418 | (~a.sourceIndex || MAX_NEGATIVE); |
| 419 | |
| 420 | // Use IE sourceIndex if available on both nodes |
| 421 | if (diff) { |
| 422 | return diff; |
| 423 | } |
| 424 | |
| 425 | // Check if b follows a |
| 426 | if (cur) { |
| 427 | while ((cur = cur.nextSibling)) { |
| 428 | if (cur === b) { |
| 429 | return -1; |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | return a ? 1 : -1; |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * Returns a function to use in pseudos for input types |