From 544cb24064a2806d9653abc523fbae6bdcef4ad7 Mon Sep 17 00:00:00 2001 From: Minwe Date: Mon, 20 Oct 2014 13:31:25 +0800 Subject: [PATCH] resolved #131: close OffCanvas on window resize --- js/ui.offcanvas.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/js/ui.offcanvas.js b/js/ui.offcanvas.js index 7b461bc..4bfdd82 100644 --- a/js/ui.offcanvas.js +++ b/js/ui.offcanvas.js @@ -19,6 +19,7 @@ define(function(require, exports, module) { var OffCanvas = function(element, options) { this.$element = $(element); this.options = options; + this.active = null; this.events(); }; @@ -34,11 +35,11 @@ define(function(require, exports, module) { return; } - var effect = this.options.effect, - $html = $('html'), - $body = $('body'), - $bar = $element.find('.am-offcanvas-bar').first(), - dir = $bar.hasClass('am-offcanvas-bar-flip') ? -1 : 1; + var effect = this.options.effect; + var $html = $('html'); + var $body = $('body'); + var $bar = $element.find('.am-offcanvas-bar').first(); + var dir = $bar.hasClass('am-offcanvas-bar-flip') ? -1 : 1; $bar.addClass('am-offcanvas-bar-' + effect); @@ -64,6 +65,8 @@ define(function(require, exports, module) { $doc.trigger('open:offcanvas:amui'); + this.active = 1; + $element.off('.offcanvas.amui'). on('click.offcanvas.amui swipe.offcanvas.amui', $.proxy(function(e) { var $target = $(e.target); @@ -92,6 +95,7 @@ define(function(require, exports, module) { }; OffCanvas.prototype.close = function(relatedElement) { + var me = this; var $html = $('html'); var $body = $('body'); var $element = this.$element; @@ -111,6 +115,7 @@ define(function(require, exports, module) { $html.css('margin-top', ''); window.scrollTo(scrollPos.x, scrollPos.y); $doc.trigger('closed:offcanvas:amui'); + me.active = 0; } if (UI.support.transition) { @@ -136,6 +141,11 @@ define(function(require, exports, module) { this.close(); }, this)); + $win.on('resize.offcanvas.amui orientationchange.offcanvas.amui', + $.proxy(function(e) { + this.active && this.close(); + }, this)); + return this; }; -- GitLab