add delay before resizing on fullscreen, because the callback isn't called exactly at the end of the fullscreen set up
authorrougeronj
Mon, 05 Oct 2015 11:08:26 +0200
changeset 576 1e1791dfc9e4
parent 575 3e48b1672ace
child 577 105ddd569ff7
add delay before resizing on fullscreen, because the callback isn't called exactly at the end of the fullscreen set up
client/js/renderer/scene.js
--- a/client/js/renderer/scene.js	Fri Oct 02 18:15:48 2015 +0200
+++ b/client/js/renderer/scene.js	Mon Oct 05 11:08:26 2015 +0200
@@ -245,31 +245,36 @@
             bindClick(".Rk-FullScreen-Button", "fullScreen");
             
             document.addEventListener(Screenfull.raw.fullscreenchange, function () {
-                var widthAft = _this.$.width();
-                var heightAft = _this.$.height();
-                
-                if (_this.renkan.options.show_top_bar) {
-                    heightAft -= _this.$.find(".Rk-TopBar").height();
-                }
-                if (_this.renkan.options.show_bins && (this.renkan.$.find(".Rk-Bins").position().left > 0)) {
-                    widthAft -= this.renkan.$.find(".Rk-Bins").width();
-                }
-                
-                paper.view.viewSize = new paper.Size([widthAft, heightAft]);
-                
-                _this.resize(_this.currentWidth, widthAft, _this.currentHeight, heightAft);
-                
-                _this.currentWidth = widthAft;
-                _this.currentHeight = heightAft;
-                
-                paper.view.onResize = function(_event) {
-                    var newWidth = _event.size._width,
-                        newHeight = _event.size._height;
-                    var prevHeight = newHeight - _event.delta.height,
-                        prevWidth = newWidth - _event.delta.width;
+                //the listener occur too randomly and sometimes before the fullscreen is fully set up
+                //so we add 500 delay
+                setTimeout(function(){
+                    var widthAft = _this.$.width();
+                    var heightAft = _this.$.height();
+                    
+                    if (_this.renkan.options.show_top_bar) {
+                        heightAft -= _this.$.find(".Rk-TopBar").height();
+                    }
+                    if (_this.renkan.options.show_bins && (this.renkan.$.find(".Rk-Bins").position().left > 0)) {
+                        widthAft -= this.renkan.$.find(".Rk-Bins").width();
+                    }
                     
-                    _this.resize(prevWidth, newWidth, prevHeight, newHeight);
-                };
+                    paper.view.viewSize = new paper.Size([widthAft, heightAft]);
+                    _this.resize(_this.currentWidth, widthAft, _this.currentHeight, heightAft);
+                    
+                    _this.currentWidth = widthAft;
+                    _this.currentHeight = heightAft;
+                    
+                    if (!Screenfull.isFullscreen) {
+                        paper.view.onResize = function(_event) {
+                            var newWidth = _event.size._width,
+                                newHeight = _event.size._height;
+                            var prevHeight = newHeight - _event.delta.height,
+                                prevWidth = newWidth - _event.delta.width;
+                            
+                            _this.resize(prevWidth, newWidth, prevHeight, newHeight);
+                        };
+                    }
+                }, 600);
             });
         } else {
             this.$.find(".Rk-FullScreen-Button").addClass("disabled");