Skip to content
This repository
Browse code

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...
commit b8c5e458896f1222b38b1eecd0f87578e826120e 1 parent da7237a
authored March 20, 2012
15  js/jquery.mobile.zoom.js
@@ -8,28 +8,31 @@ define( [ "jquery", "./jquery.mobile.core" ], function( $ ) {
8 8
 	var	meta = $( "meta[name=viewport]" ),
9 9
         initialContent = meta.attr( "content" ),
10 10
         disabledZoom = initialContent + ",maximum-scale=1, user-scalable=no",
11  
-        enabledZoom = initialContent + ",maximum-scale=10, user-scalable=yes";
  11
+        enabledZoom = initialContent + ",maximum-scale=10, user-scalable=yes",
  12
+		disabledInitially = /(user-scalable[\s]*=[\s]*no)|(maximum-scale[\s]*=[\s]*1)[$,\s]/.test( initialContent );
12 13
 	
13 14
 	$.mobile.zoom = $.extend( {}, {
14  
-		enabled: true,
  15
+		enabled: !disabledInitially,
15 16
 		locked: false,
16 17
 		disable: function( lock ) {
17  
-			if( !$.mobile.zoom.locked ){
  18
+			if( !disabledInitially && !$.mobile.zoom.locked ){
18 19
 	        	meta.attr( "content", disabledZoom );
19 20
 	        	$.mobile.zoom.enabled = false;
20 21
 				$.mobile.zoom.locked = lock || false;
21 22
 			}
22 23
 		},
23 24
 		enable: function( unlock ) {
24  
-			if( !$.mobile.zoom.locked || unlock ){
  25
+			if( !disabledInitially && ( !$.mobile.zoom.locked || unlock === true ) ){
25 26
 		        meta.attr( "content", enabledZoom );
26 27
 		        $.mobile.zoom.enabled = true;
27 28
 				$.mobile.zoom.locked = false;
28 29
 			}
29 30
 		},
30 31
 		restore: function() {
31  
-	        meta.attr( "content", initialContent );
32  
-	        $.mobile.zoom.enabled = true;
  32
+			if( !disabledInitially ){
  33
+	        	meta.attr( "content", initialContent );
  34
+	        	$.mobile.zoom.enabled = true;
  35
+			}
33 36
 		}
34 37
 	});
35 38
 
46  tests/unit/zoom/initial-disable.html
... ...
@@ -0,0 +1,46 @@
  1
+<!DOCTYPE html>
  2
+<html lang="en">
  3
+<head>
  4
+	<meta charset="UTF-8" />
  5
+	<title>jQuery Mobile Zoom Maniplation Integration Test</title>
  6
+	<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  7
+
  8
+	<script src="../../../external/requirejs/require.js"></script>
  9
+	<script src="../../../js/jquery.js"></script>
  10
+	<script src="../jquery.setNameSpace.js"></script>
  11
+	<script src="../../../tests/jquery.testHelper.js"></script>
  12
+	<script src="../../../external/qunit.js"></script>
  13
+	<script>
  14
+		$.testHelper.asyncLoad([
  15
+			[
  16
+				"jquery.mobile.zoom"
  17
+			],
  18
+			[ "jquery.mobile.init" ],
  19
+			[
  20
+				"./zoom-initial-disable.js"
  21
+			]
  22
+		]);
  23
+	</script>
  24
+
  25
+	<link rel="stylesheet"  href="../../../css/themes/default/jquery.mobile.css"/>
  26
+	<link rel="stylesheet" href="../../../external/qunit.css"/>
  27
+
  28
+	<script src="../swarminject.js"></script>
  29
+</head>
  30
+<body>
  31
+
  32
+<h1 id="qunit-header">jQuery Mobile FieldContainer Test Suite</h1>
  33
+<h2 id="qunit-banner"></h2>
  34
+<h2 id="qunit-userAgent"></h2>
  35
+<ol id="qunit-tests">
  36
+</ol>
  37
+
  38
+<div data-nstest-role="page">
  39
+
  40
+
  41
+</div>
  42
+
  43
+
  44
+
  45
+</body>
  46
+</html>
9  tests/unit/zoom/zoom-initial-disable.js
... ...
@@ -0,0 +1,9 @@
  1
+/*
  2
+ * mobile zoom
  3
+ */
  4
+(function($){
  5
+	test( "User zooming will not enable when calling enable() method if zooming was disabled in page source", function(){
  6
+		$.mobile.zoom.enable();
  7
+		ok( !$.mobile.zoom.enabled );		
  8
+	});
  9
+})(jQuery);

0 notes on commit b8c5e45

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