Permalink
Browse files

This change fixes #3859, in which user scaling/zoom would become re-e…

…nabled after an orientationchange, even if it was locked, such as on a fixed toolbars page. Also, this change addresses @toddparker's point that the zoom plugin does not respect meta viewport tags that have user scaling disabled at the start. This was a slightly separate issue to address, but it's all on this same ticket. lastly, this includes a new unit test to ensure the zoom plugin does respect pages that have scaling disabled in source - in those cases, the zoom api will still be defined, but the methods won't do anything.. and $.mobile.zoom.enabled will begin and remain false.
  • Loading branch information...
scottjehl
scottjehl committed Mar 20, 2012
1 parent da7237a commit b8c5e458896f1222b38b1eecd0f87578e826120e
Showing with 64 additions and 6 deletions.
  1. +9 −6 js/jquery.mobile.zoom.js
  2. +46 −0 tests/unit/zoom/initial-disable.html
  3. +9 −0 tests/unit/zoom/zoom-initial-disable.js
View
@@ -8,28 +8,31 @@ define( [ "jquery", "./jquery.mobile.core" ], function( $ ) {
var meta = $( "meta[name=viewport]" ),
initialContent = meta.attr( "content" ),
disabledZoom = initialContent + ",maximum-scale=1, user-scalable=no",
- enabledZoom = initialContent + ",maximum-scale=10, user-scalable=yes";
+ enabledZoom = initialContent + ",maximum-scale=10, user-scalable=yes",
+ disabledInitially = /(user-scalable[\s]*=[\s]*no)|(maximum-scale[\s]*=[\s]*1)[$,\s]/.test( initialContent );
$.mobile.zoom = $.extend( {}, {
- enabled: true,
+ enabled: !disabledInitially,
locked: false,
disable: function( lock ) {
- if( !$.mobile.zoom.locked ){
+ if( !disabledInitially && !$.mobile.zoom.locked ){
meta.attr( "content", disabledZoom );
$.mobile.zoom.enabled = false;
$.mobile.zoom.locked = lock || false;
}
},
enable: function( unlock ) {
- if( !$.mobile.zoom.locked || unlock ){
+ if( !disabledInitially && ( !$.mobile.zoom.locked || unlock === true ) ){
meta.attr( "content", enabledZoom );
$.mobile.zoom.enabled = true;
$.mobile.zoom.locked = false;
}
},
restore: function() {
- meta.attr( "content", initialContent );
- $.mobile.zoom.enabled = true;
+ if( !disabledInitially ){
+ meta.attr( "content", initialContent );
+ $.mobile.zoom.enabled = true;
+ }
}
});
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8" />
+ <title>jQuery Mobile Zoom Maniplation Integration Test</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
+
+ <script src="../../../external/requirejs/require.js"></script>
+ <script src="../../../js/jquery.js"></script>
+ <script src="../jquery.setNameSpace.js"></script>
+ <script src="../../../tests/jquery.testHelper.js"></script>
+ <script src="../../../external/qunit.js"></script>
+ <script>
+ $.testHelper.asyncLoad([
+ [
+ "jquery.mobile.zoom"
+ ],
+ [ "jquery.mobile.init" ],
+ [
+ "./zoom-initial-disable.js"
+ ]
+ ]);
+ </script>
+
+ <link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css"/>
+ <link rel="stylesheet" href="../../../external/qunit.css"/>
+
+ <script src="../swarminject.js"></script>
+</head>
+<body>
+
+<h1 id="qunit-header">jQuery Mobile FieldContainer Test Suite</h1>
+<h2 id="qunit-banner"></h2>
+<h2 id="qunit-userAgent"></h2>
+<ol id="qunit-tests">
+</ol>
+
+<div data-nstest-role="page">
+
+
+</div>
+
+
+
+</body>
+</html>
@@ -0,0 +1,9 @@
+/*
+ * mobile zoom
+ */
+(function($){
+ test( "User zooming will not enable when calling enable() method if zooming was disabled in page source", function(){
+ $.mobile.zoom.enable();
+ ok( !$.mobile.zoom.enabled );
+ });
+})(jQuery);

0 comments on commit b8c5e45

Please sign in to comment.