1/*jslint browser: true, indent: 2 */ 2(function ($) { 3 'use strict'; 4 $.fn.inviewport = function (options) { 5 var settings = $.extend({ 6 'minPercentageInView' : 25, 7 'standardClassName': 'in-view' 8 }, options); 9 this.each(function () { 10 var $this = $(this), 11 $win = $(window), 12 changed = false, 13 isVisible = function () { 14 var c = settings.className || settings.standardClassName, 15 min = (settings.threshold || settings.minPercentageInView) / 100, 16 xMin = $this.width() * min, 17 yMin = $this.height() * min, 18 winPosX = $win.scrollLeft() + $win.width(), 19 winPosY = $win.scrollTop() + $win.height(), 20 elPosX = $this.offset().left + xMin, 21 elPosY = $this.offset().top + yMin; 22 if (winPosX > elPosX && winPosY > elPosY) { 23 $this.addClass(c); 24 } 25 }; 26 $win.on('ready', isVisible()) 27 .on('resize scroll', function () { 28 changed = true; 29 }); 30 setInterval(function () { 31 if (changed) { 32 changed = false; 33 isVisible(); 34 } 35 }, 250); 36 }); 37 }; 38}(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.