assets/js/scale.fix.js in jekyll-theme-minimal-0.0.3 vs assets/js/scale.fix.js in jekyll-theme-minimal-0.0.4

- old
+ new

@@ -1,17 +1,27 @@ -var metas = document.getElementsByTagName('meta'); -var i; -if (navigator.userAgent.match(/iPhone/i)) { - for (i=0; i<metas.length; i++) { - if (metas[i].name == "viewport") { - metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0"; +(function(document) { + var metas = document.getElementsByTagName('meta'), + changeViewportContent = function(content) { + for (var i = 0; i < metas.length; i++) { + if (metas[i].name == "viewport") { + metas[i].content = content; + } + } + }, + initialize = function() { + changeViewportContent("width=device-width, minimum-scale=1.0, maximum-scale=1.0"); + }, + gestureStart = function() { + changeViewportContent("width=device-width, minimum-scale=0.25, maximum-scale=1.6"); + }, + gestureEnd = function() { + initialize(); + }; + + + if (navigator.userAgent.match(/iPhone/i)) { + initialize(); + + document.addEventListener("touchstart", gestureStart, false); + document.addEventListener("touchend", gestureEnd, false); } - } - document.addEventListener("gesturestart", gestureStart, false); -} -function gestureStart() { - for (i=0; i<metas.length; i++) { - if (metas[i].name == "viewport") { - metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6"; - } - } -} \ No newline at end of file +})(document);