Disabling zoom if image viewer is open
authorAlexander Ebert <ebert@woltlab.com>
Sat, 29 Nov 2014 00:18:37 +0000 (01:18 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 29 Nov 2014 00:18:37 +0000 (01:18 +0100)
wcfsetup/install/files/js/WCF.ImageViewer.js
wcfsetup/install/files/js/WCF.js

index 19a9b068e96f91c9d92b8985fd3bc545ec80d5e8..7b5150b4c4601f69d28c13e52d948a002fcecf55 100644 (file)
@@ -317,6 +317,7 @@ $.widget('ui.wcfImageViewer', {
                        this._isOpen = true;
                        
                        WCF.System.DisableScrolling.disable();
+                       WCF.System.DisableZoom.disable();
                        
                        // switch to fullscreen mode on smartphones
                        if ($.browser.touch) {
@@ -341,6 +342,7 @@ $.widget('ui.wcfImageViewer', {
                                this._isOpen = true;
                        
                                WCF.System.DisableScrolling.disable();
+                               WCF.System.DisableZoom.disable();
                        }
                }
                
@@ -371,6 +373,7 @@ $.widget('ui.wcfImageViewer', {
                this._isOpen = false;
                
                WCF.System.DisableScrolling.enable();
+               WCF.System.DisableZoom.enable();
                
                return true;
        },
@@ -1198,6 +1201,7 @@ $.widget('ui.wcfImageViewer', {
                        this._isOpen = true;
                
                        WCF.System.DisableScrolling.disable();
+                       WCF.System.DisableZoom.disable();
                }
        }
 });
index ed8e801eceaf74a8e3bcd05913763f8ad1e27a58..b1f60721c5b9173f4ab2a88bdac07c3e1b637c02 100755 (executable)
@@ -7420,6 +7420,50 @@ WCF.System.DisableScrolling = {
        }
 };
 
+/**
+ * Disables the ability to zoom the page.
+ */
+WCF.System.DisableZoom = {
+       /**
+        * number of times zoom was disabled (nested calls)
+        * @var integer
+        */
+       _depth: 0,
+       
+       /**
+        * old viewport settings in meta[name=viewport]
+        * @var string
+        */
+       _oldViewportSettings: null,
+       
+       /**
+        * Disables zooming.
+        */
+       disable: function () {
+               if (this._depth === 0) {
+                       var $meta = $('meta[name=viewport]');
+                       this._oldViewportSettings = $meta.attr('content');
+                       $meta.attr('content', this._oldViewportSettings + ',maximum-scale=1');
+               }
+               
+               this._depth++;
+       },
+       
+       /**
+        * Enables scrolling again.
+        * Must be called the same number of times disable() was called to enable scrolling.
+        */
+       enable: function () {
+               if (this._depth === 0) return;
+               
+               this._depth--;
+               
+               if (this._depth === 0) {
+                       $('meta[name=viewport]').attr('content', this._oldViewportSettings);
+               }
+       }
+};
+
 /**
  * Puts an element into HTML 5 fullscreen mode.
  */