1(function($){ 2 3 /** 4 * Copyright 2012, Digital Fusion 5 * Licensed under the MIT license. 6 * http://teamdf.com/jquery-plugins/license/ 7 * 8 * @author Sam Sehnert 9 * @desc A small plugin that checks whether elements are within 10 * the user visible viewport of a web browser. 11 * can accounts for vertical position, horizontal, or both 12 */ 13 var $w=$(window); 14 $.fn.visible = function(partial,hidden,direction,container){ 15 16 if (this.length < 1) 17 return; 18 19 // Set direction default to 'both'. 20 direction = direction || 'both'; 21 22 var $t = this.length > 1 ? this.eq(0) : this, 23 isContained = typeof container !== 'undefined' && container !== null, 24 $c = isContained ? $(container) : $w, 25 wPosition = isContained ? $c.position() : 0, 26 t = $t.get(0), 27 vpWidth = $c.outerWidth(), 28 vpHeight = $c.outerHeight(), 29 clientSize = hidden === true ? t.offsetWidth * t.offsetHeight : true; 30 31 if (typeof t.getBoundingClientRect === 'function'){ 32 33 // Use this native browser method, if available. 34 var rec = t.getBoundingClientRect(), 35 tViz = isContained ? 36 rec.top - wPosition.top >= 0 && rec.top < vpHeight + wPosition.top : 37 rec.top >= 0 && rec.top < vpHeight, 38 bViz = isContained ? 39 rec.bottom - wPosition.top > 0 && rec.bottom <= vpHeight + wPosition.top : 40 rec.bottom > 0 && rec.bottom <= vpHeight, 41 lViz = isContained ? 42 rec.left - wPosition.left >= 0 && rec.left < vpWidth + wPosition.left : 43 rec.left >= 0 && rec.left < vpWidth, 44 rViz = isContained ? 45 rec.right - wPosition.left > 0 && rec.right < vpWidth + wPosition.left : 46 rec.right > 0 && rec.right <= vpWidth, 47 vVisible = partial ? tViz || bViz : tViz && bViz, 48 hVisible = partial ? lViz || rViz : lViz && rViz, 49 vVisible = (rec.top < 0 && rec.bottom > vpHeight) ? true : vVisible, 50 hVisible = (rec.left < 0 && rec.right > vpWidth) ? true : hVisible; 51 52 if(direction === 'both') 53 return clientSize && vVisible && hVisible; 54 else if(direction === 'vertical') 55 return clientSize && vVisible; 56 else if(direction === 'horizontal') 57 return clientSize && hVisible; 58 } else { 59 60 var viewTop = isContained ? 0 : wPosition,
61 viewBottom = viewTop + vpHeight, 62 viewLeft = $c.scrollLeft(), 63 viewRight = viewLeft + vpWidth, 64 position = $t.position(), 65 _top = position.top, 66 _bottom = _top + $t.height(), 67 _left = position.left, 68 _right = _left + $t.width(), 69 compareTop = partial === true ? _bottom : _top, 70 compareBottom = partial === true ? _top : _bottom, 71 compareLeft = partial === true ? _right : _left, 72 compareRight = partial === true ? _left : _right; 73 74 if(direction === 'both') 75 return !!clientSize && ((compareBottom <= viewBottom) && (compareTop >= viewTop)) && ((compareRight <= viewRight) && (compareLeft >= viewLeft)); 76 else if(direction === 'vertical') 77 return !!clientSize && ((compareBottom <= viewBottom) && (compareTop >= viewTop)); 78 else if(direction === 'horizontal') 79 return !!clientSize && ((compareRight <= viewRight) && (compareLeft >= viewLeft)); 80 } 81 }; 82 83})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.