Permalink
Browse files

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

…if you were loading all JavaScripts after the DOM was ready.
  • Loading branch information...
1 parent 0653c5e commit 505a2d8bc315c2b57e70294f4b8347bd402f2907 Christoph Martens committed Jan 18, 2012
Showing with 19 additions and 8 deletions.
  1. +1 −1 jasyproject.json
  2. +18 −7 src/viewporter.js
View
@@ -1,4 +1,4 @@
{
"name" : "viewporter",
- "package" : "z"
+ "package" : ""
}
View
@@ -38,8 +38,7 @@ var viewporter;
this.IS_ANDROID = /Android/.test(navigator.userAgent);
- // listen for document ready, then try to prepare the visual viewport and start firing custom events
- document.addEventListener('DOMContentLoaded', function() {
+ var _onReady = function() {
// scroll the shit away and fix the viewport!
that.prepareVisualViewport();
@@ -53,7 +52,19 @@ var viewporter;
}
}, false);
- }, false);
+ };
+
+
+ // listen for document ready if not already loaded
+ // then try to prepare the visual viewport and start firing custom events
+ if (document.readyState === 'loading') {
+ document.addEventListener('DOMContentLoaded', function() {
+ _onReady();
+ }, false);
+ } else {
+ _onReady();
+ }
+
};
@@ -69,7 +80,7 @@ var viewporter;
},
prepareVisualViewport: function() {
-
+
var that = this;
// maximize the document element's height to be able to scroll away the url bar
@@ -94,7 +105,7 @@ var viewporter;
? (deviceProfile ? window.innerHeight === deviceProfile[orientation] : --iterations < 0) // Android: either match against a device profile, or brute force
: (window.innerHeight > startHeight || --iterations < 0) // iOS is comparably easy!
) {
-
+
// set minimum height of content to new window height
document.documentElement.style.minHeight = window.innerHeight + 'px';
@@ -110,7 +121,7 @@ var viewporter;
}
}, 10);
-
+
},
triggerWindowEvent: function(name) {
@@ -152,4 +163,4 @@ viewporter.profiles = {
landscape: 320
}
-}
+}

0 comments on commit 505a2d8

Please sign in to comment.