1/* 2FlameViewportScale. 0.12. Facilitates a simple viewport scale query. 3Optic Swerve, opticswerve.com 4Documented at http://menacingcloud.com/?c=viewportScale 5*/ 6 7/*--------------------------| 8| FlameViewportScale | 9|--------------------------*/ 10function FlameViewportScale() { 11 this.delay = 600; // Delay after calling update to account for viewport bounce 12 this.orientation; 13 this.screenWidth; // Screen width corrected for orientation 14 this.timeout; 15 this.viewportScale; 16 17 // Get current scale 18 //------------------- 19 this.getScale = function() { 20 this.viewportScale = undefined; 21 22 // Get viewport width 23 var viewportWidth = document.documentElement.clientWidth; 24 25 // Abort. Screen width is greater than the viewport width (not fullscreen). 26 if(screen.width > viewportWidth) { 27 console.log('Aborted viewport scale measurement. Screen width > viewport width'); 28 return; 29 30 } 31 32 // Get the orientation corrected screen width 33 this.updateOrientation(); 34 this.screenWidth = screen.width; 35 36 if(this.orientation === 'portrait') { 37 // Take smaller of the two dimensions 38 if(screen.width > screen.height) this.screenWidth = screen.height; 39 40 } 41 else { 42 // Take larger of the two dimensions 43 if(screen.width < screen.height) this.screenWidth = screen.height; 44 45 } 46 47 // Calculate viewport scale 48 this.viewportScale = this.screenWidth / window.innerWidth; 49 return this.viewportScale; 50 51 }; 52 53 // Update viewport orientation 54 //----------------------------- 55 this.updateOrientation = function() { 56 this.orientation = window.orientation; 57 58 if(this.orientation === undefined) { 59 // No JavaScript orientation support. Work it out. 60 if(document.documentElement.clientWidth > document.documentElement.clientHeight) this.orientation = 'landscape'; 61 else this.orientation = 'portrait'; 62 63 } 64 else if(this.orientation === 0 || this.orientation === 180) this.orientation = 'portrait'; 65 else this.orientation = 'landscape'; // Assumed default, most laptop and PC screens. 66 67 }; 68 69 // Update 70 //-------- 71 this.update = function(callback) { 72 // Clear timeout if already set 73 if(this.timeout !== undefined) { 74 clearTimeout(this.timeout); 75 this.timeout = undefined; 76 77 } 78 79 if(this.delay > 0) { 80 // Delay compensates for viewport bounce 81 var viewScale = this; 82 83 this.timeout = setTimeout(function() { 84 viewScale.getScale(); 85 if(callback !== undefined) callback(); 86 87 }, this.delay); 88 89 } 90 else { 91 // Immediate scale update 92 this.getScale(); 93 if(callback !== undefined) callback(); 94 95 } 96 97 }; 98 99 return true; 100 101}
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.