Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixes for having no dependency of DOMContentLoaded event. Didnt work …

…if you were loading all JavaScripts after the DOM was ready.
  • Loading branch information...
commit 505a2d8bc315c2b57e70294f4b8347bd402f2907 1 parent 0653c5e
authored January 18, 2012
2  jasyproject.json
... ...
@@ -1,4 +1,4 @@
1 1
 {
2 2
 	"name" : "viewporter",
3  
-	"package" : "z"
  3
+	"package" : ""
4 4
 }
25  src/viewporter.js
@@ -38,8 +38,7 @@ var viewporter;
38 38
 
39 39
 		this.IS_ANDROID = /Android/.test(navigator.userAgent);
40 40
 
41  
-		// listen for document ready, then try to prepare the visual viewport and start firing custom events
42  
-		document.addEventListener('DOMContentLoaded', function() {
  41
+		var _onReady = function() {
43 42
 
44 43
 			// scroll the shit away and fix the viewport!
45 44
 			that.prepareVisualViewport();
@@ -53,7 +52,19 @@ var viewporter;
53 52
 				}
54 53
 			}, false);
55 54
 
56  
-		}, false);
  55
+		};
  56
+
  57
+
  58
+		// listen for document ready if not already loaded
  59
+		// then try to prepare the visual viewport and start firing custom events
  60
+		if (document.readyState === 'loading') {
  61
+			document.addEventListener('DOMContentLoaded', function() {
  62
+				_onReady();
  63
+			}, false);
  64
+		} else {
  65
+			_onReady();
  66
+		}
  67
+
57 68
 
58 69
 	};
59 70
 
@@ -69,7 +80,7 @@ var viewporter;
69 80
 		},
70 81
 
71 82
 		prepareVisualViewport: function() {
72  
-			
  83
+
73 84
 			var that = this;
74 85
 
75 86
 			// maximize the document element's height to be able to scroll away the url bar
@@ -94,7 +105,7 @@ var viewporter;
94 105
 						? (deviceProfile ? window.innerHeight === deviceProfile[orientation] : --iterations < 0) // Android: either match against a device profile, or brute force
95 106
 						: (window.innerHeight > startHeight || --iterations < 0) // iOS is comparably easy!
96 107
 				) {
97  
-					
  108
+
98 109
 					// set minimum height of content to new window height
99 110
 					document.documentElement.style.minHeight = window.innerHeight + 'px';
100 111
 
@@ -110,7 +121,7 @@ var viewporter;
110 121
 				}
111 122
 
112 123
 			}, 10);
113  
-				
  124
+
114 125
 		},
115 126
 
116 127
 		triggerWindowEvent: function(name) {
@@ -152,4 +163,4 @@ viewporter.profiles = {
152 163
 		landscape: 320
153 164
 	}
154 165
 
155  
-}
  166
+}

0 notes on commit 505a2d8

Please sign in to comment.
Something went wrong with that request. Please try again.