提交 2343b38d 编写于 作者: M Minwe LUO

Merge pull request #147 from allmobilize/codename-h

resolved #131: close OffCanvas on window resize
...@@ -19,6 +19,7 @@ define(function(require, exports, module) { ...@@ -19,6 +19,7 @@ define(function(require, exports, module) {
var OffCanvas = function(element, options) { var OffCanvas = function(element, options) {
this.$element = $(element); this.$element = $(element);
this.options = options; this.options = options;
this.active = null;
this.events(); this.events();
}; };
...@@ -34,11 +35,11 @@ define(function(require, exports, module) { ...@@ -34,11 +35,11 @@ define(function(require, exports, module) {
return; return;
} }
var effect = this.options.effect, var effect = this.options.effect;
$html = $('html'), var $html = $('html');
$body = $('body'), var $body = $('body');
$bar = $element.find('.am-offcanvas-bar').first(), var $bar = $element.find('.am-offcanvas-bar').first();
dir = $bar.hasClass('am-offcanvas-bar-flip') ? -1 : 1; var dir = $bar.hasClass('am-offcanvas-bar-flip') ? -1 : 1;
$bar.addClass('am-offcanvas-bar-' + effect); $bar.addClass('am-offcanvas-bar-' + effect);
...@@ -64,6 +65,8 @@ define(function(require, exports, module) { ...@@ -64,6 +65,8 @@ define(function(require, exports, module) {
$doc.trigger('open:offcanvas:amui'); $doc.trigger('open:offcanvas:amui');
this.active = 1;
$element.off('.offcanvas.amui'). $element.off('.offcanvas.amui').
on('click.offcanvas.amui swipe.offcanvas.amui', $.proxy(function(e) { on('click.offcanvas.amui swipe.offcanvas.amui', $.proxy(function(e) {
var $target = $(e.target); var $target = $(e.target);
...@@ -92,6 +95,7 @@ define(function(require, exports, module) { ...@@ -92,6 +95,7 @@ define(function(require, exports, module) {
}; };
OffCanvas.prototype.close = function(relatedElement) { OffCanvas.prototype.close = function(relatedElement) {
var me = this;
var $html = $('html'); var $html = $('html');
var $body = $('body'); var $body = $('body');
var $element = this.$element; var $element = this.$element;
...@@ -111,6 +115,7 @@ define(function(require, exports, module) { ...@@ -111,6 +115,7 @@ define(function(require, exports, module) {
$html.css('margin-top', ''); $html.css('margin-top', '');
window.scrollTo(scrollPos.x, scrollPos.y); window.scrollTo(scrollPos.x, scrollPos.y);
$doc.trigger('closed:offcanvas:amui'); $doc.trigger('closed:offcanvas:amui');
me.active = 0;
} }
if (UI.support.transition) { if (UI.support.transition) {
...@@ -136,6 +141,11 @@ define(function(require, exports, module) { ...@@ -136,6 +141,11 @@ define(function(require, exports, module) {
this.close(); this.close();
}, this)); }, this));
$win.on('resize.offcanvas.amui orientationchange.offcanvas.amui',
$.proxy(function(e) {
this.active && this.close();
}, this));
return this; return this;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册