Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add public "viewporter.refresh()" method. This is eg. used when the b…

…rowser displays inline confirmations such as the geolocation alert on Android.
  • Loading branch information...
commit 3a818be0d682060bfccbb8675c0545baddc45e70 1 parent eae5bbf
@aemkei aemkei authored
Showing with 68 additions and 1 deletion.
  1. +1 −0  README.md
  2. +58 −0 demo/refresh.html
  3. +9 −1 src/viewporter.js
View
1  README.md
@@ -66,6 +66,7 @@ Viewporter is almost zero configuration. There's only one constant to check if V
* viewporter.isLandscape() - returns wether the device is rotated to landscape or not
* viewporter.ready() - accepts a callback and fires it when the viewporter has been successfully executed
+* viewporter.refresh() - refreshes the viewport. This is eg. used when the browser displays inline confirmations such as the geolocation alert on Android.
### Events
View
58 demo/refresh.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+
+ <title>No Page Scroll</title>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta name="apple-mobile-web-app-capable" content="yes">
+ <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
+
+ <!-- This exact meta viewport is required for Viewporter for work properly -->
+ <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0" />
+
+ <link rel="stylesheet" href="style.css" type="text/css" media="screen">
+
+ <script src="../src/viewporter.js"></script>
+
+
+</head>
+<body>
+<div id="viewporter"><!-- This wrapper element is also required -->
+
+ <div id="checker-bl">
+ <p id="coords"></p>
+ </div>
+ <div id="checker-tr">
+ <p></p>
+ </div>
+
+</div>
+
+<script type="text/javascript">
+
+ viewporter.preventPageScroll = true;
+
+ document.addEventListener('DOMContentLoaded', function() {
+
+ if (navigator.geolocation){
+
+ function success(position){
+ var coords = [position.coords.latitude, position.coords.longitude]
+ document.getElementById("coords").innerHTML = coords.join(", ");
+ viewporter.refresh();
+ }
+
+ function error(){
+ viewporter.refresh();
+ }
+
+ navigator.geolocation.getCurrentPosition(success, error);
+ viewporter.refresh();
+ }
+
+ });
+</script>
+
+</body>
+</html>
View
10 src/viewporter.js
@@ -9,6 +9,8 @@
var viewporter;
(function() {
+ var _viewporter;
+
// initialize viewporter object
viewporter = {
@@ -29,6 +31,12 @@ var viewporter;
ready: function(callback) {
window.addEventListener('viewportready', callback, false);
+ },
+
+ refresh: function(){
+ if (_viewporter){
+ _viewporter.prepareVisualViewport();
+ }
}
};
@@ -176,7 +184,7 @@ var viewporter;
};
// initialize
- new _Viewporter();
+ _viewporter = new _Viewporter();
})();
Please sign in to comment.
Something went wrong with that request. Please try again.