1/** 2 * jQuery Screen Control 3 * Author: Crowd Favorite 4 * Description: Provides a lightweight interface for detecting and storing screen properties and events. 5 * Version: 1.2-dev 6 */ 7(function() { 8 "use strict"; 9 if (jQuery) { 10 // This is intentionally run in-line so that its values can be available from the start for anything using them. 11 window.screenData = { 12 "height": 0, 13 "width": 0, 14 "top": 0, 15 "left": 0, 16 "right": 0, 17 "bottom": 0, 18 "initialized": false, 19 "resized": true, 20 "scrolled": true, 21 "orientation": "landscape", 22 "refresh": function() { 23 var $window = jQuery(window), windowHeight; 24 // Logic for calculating width and height largely borrowed from responsejs.com/labs/dimensions, but rewritten for our use and for clarity. 25 function getScreenDataWidth() { 26 var matchMedia = (window['matchMedia'] || window['msMatchMedia']), 27 client = document.documentElement['clientWidth'], 28 inner = window['innerWidth']; 29 30 if (matchMedia && client < inner && matchMedia('(min-width:' + inner + 'px)')['matches']) { 31 return inner; 32 } 33 else { 34 return client; 35 } 36 } 37 window.screenData.width = getScreenDataWidth(); 38 function getScreenDataHeight() { 39 var matchMedia = (window['matchMedia'] || window['msMatchMedia']), 40 client = document.documentElement['clientHeight'], 41 inner = window['innerHeight']; 42 43 if (matchMedia && client < inner && matchMedia('(min-height:' + inner + 'px)')['matches']) { 44 return inner; 45 } 46 else { 47 return client; 48 } 49 } 50 window.screenData.height = getScreenDataHeight(); 51 window.screenData.top = $window.scrollTop(), 52 window.screenData.bottom = window.screenData.height + window.screenData.top; 53 window.screenData.left = $window.scrollLeft(), 54 window.screenData.right = window.screenData.left + window.screenData.width; 55 if (window.screenData.height > window.screenData.width) { 56 window.screenData.orientation = "portrait"; 57 } 58 else { 59 window.screenData.orientation = "landscape"; 60 } 61 }, 62 "init": function() { 63 var $window = jQuery(window), changed = false, scrollVertical, scrollHorizontal; 64 if (window.screenData.initialized) { return; } 65 window.screenData.initialized = true; 66 window.screenData.refresh(); 67 var changed = false; 68 setInterval(function() { 69 if (changed) { 70 changed = false; 71 72 scrollVertical = $window.scrollTop() - window.screenData.top; 73 scrollHorizontal = $window.scrollLeft() - window.screenData.left; 74 window.screenData.scrolled = !(scrollVertical === 0 && scrollHorizontal === 0); 75 window.screenData.resized = (window.screenData.height !== $window.height() || window.screenData.width !== $window.width()); 76 77 window.screenData.refresh(); 78 if (window.screenData.scrolled) { 79 jQuery("body").trigger("screendata-scrolled", { "vertical": scrollVertical, "horizontal": scrollHorizontal }); 80 } 81 if (window.screenData.resized) { 82 jQuery("body").trigger("screendata-resized"); 83 } 84 if (window.screenData.scrolled || window.screenData.resized) { 85 jQuery("body").trigger("screendata-changed"); 86 } 87 88 window.screenData.scrolled = false; 89 window.screenData.resized = false; 90 } 91 }, 100); 92 $window.on("resize scroll orientationchange", function() { 93 // If any properties changed, trigger the change notice. 94 changed = true; 95 }); 96 return this; 97 } 98 }; 99 100 window.screenData.init().refresh(); 101 } 102})();
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.