Permalink
Browse files

Merge branch 'develop' into fix-62

  • Loading branch information...
2 parents e2f3dd7 + dcc548a commit 0dca9cd152d7079081589331512c31633c0411ae Marlow Payne committed Oct 3, 2016
Showing with 41 additions and 1 deletion.
  1. +1 −0 CHANGELOG
  2. +12 −0 dist/bellows.js
  3. +1 −1 dist/bellows.min.js
  4. +12 −0 src/js/bellows.js
  5. +15 −0 tests/unit/plugin.js
View
@@ -1,5 +1,6 @@
6.0.1
- Fix [#62](https://github.com/mobify/bellows/issues/62): Use published Plugin dependency
+ - Fix [#63](https://github.com/mobify/bellows/issues/63): Short circuit open if other items are opening
6.0.0
- Publish to NPM
- Remove Zepto support in favor of jQuery
View
@@ -137,6 +137,13 @@
.attr('aria-hidden', true);
},
+ /*
+ Checks if other bellows items are currently opening
+ */
+ _othersAreOpening: function() {
+ return this.$bellows.find('.' + cssClasses.OPENING).length > 0;
+ },
+
toggle: function($item) {
$item = this._item($item);
@@ -155,6 +162,11 @@
if (this.options.singleItemOpen) {
this.closeAll();
+
+ // Fix #63
+ if (this._othersAreOpening()) {
+ return;
+ }
}
this._trigger('open', {item: $item});
View
@@ -1,2 +1,2 @@
/*! bellows-ui 6.0.0 (git+https://github.com/mobify/bellows.git) */
-!function(a){if("function"==typeof define&&define.amd)define(["$","velocity","plugin"],a);else{var b=window.jQuery;a(b,b.Velocity,window.Plugin)}}(function(a,b,c){var d={ITEM:"bellows__item",HEADER:"bellows__header",OPENED:"bellows--is-open",OPENING:"bellows--is-opening",CLOSING:"bellows--is-closing",DISABLED:"bellows--is-disabled"},e={ITEM_HEADER:"> .bellows__item > .bellows__header",ITEM_CONTENT_WRAPPER:"> .bellows__content-wrapper",ITEM_CONTENT:"> .bellows__item > .bellows__content"},f={CLICK:"click.bellows"},g=function(a,b){g.__super__.call(this,a,b,g.DEFAULTS)};return g.VERSION="6.0.0",g.DEFAULTS={singleItemOpen:!1,duration:200,easing:"swing",open:a.noop,opened:a.noop,close:a.noop,closed:a.noop},c.create("bellows",g,{_init:function(b){this.$bellows=a(b),this._wrapContent(this.$bellows),this._bindEvents()},destroy:function(){this.$bellows.removeData(this.name).off(f.CLICK)},_bindEvents:function(){var b=this;this.$bellows.on(f.CLICK,function(c){var e=a(c.target),f=e.closest(".bellows");e.is("a")||e.parents("a").length||f[0]===b.$bellows[0]&&(e.hasClass(d.HEADER)||e.closest(".bellows__header").length)&&(c.preventDefault(),b.toggle(e.closest(".bellows__item")))})},_getHeight:function(a){return parseFloat(b.CSS.getPropertyValue(a[0],"height"))},_setHeight:function(a){this.$bellows.css("height",a||"")},_item:function(a){return"number"==typeof a&&(a=this.$bellows.find("."+d.ITEM).eq(a)),a},_isOpen:function(a){return a.hasClass(d.OPENED)},_isDisabled:function(a){return a.hasClass(d.DISABLED)},_wrapContent:function(a){a.find(e.ITEM_CONTENT).wrap('<div class="bellows__content-wrapper" />').parents(".bellows__item:not(.bellows--is-open)").find(e.ITEM_CONTENT_WRAPPER).attr("aria-hidden",!0)},toggle:function(a){a=this._item(a),this[a.hasClass(d.OPENED)?"close":"open"](a)},open:function(a){if(a=this._item(a),!this._isOpen(a)&&!this._isDisabled(a)){var c=this,f=a.find(e.ITEM_CONTENT_WRAPPER);this.options.singleItemOpen&&this.closeAll(),this._trigger("open",{item:a}),b.animate(f,"slideDown",{begin:function(){c._setHeight(c._getHeight(c.$bellows)+c._getHeight(f)),a.addClass(d.OPENING)},duration:this.options.duration,easing:this.options.easing,complete:function(){a.removeClass(d.OPENING).addClass(d.OPENED).find(e.ITEM_CONTENT_WRAPPER).removeAttr("aria-hidden"),c._setHeight(),c._trigger("opened",{item:a})}})}},close:function(a){if(a=this._item(a),this._isOpen(a)&&!this._isDisabled(a)){var c=this,f=a.find(e.ITEM_CONTENT_WRAPPER);this._trigger("close",{item:a}),b.animate(f,"slideUp",{begin:function(){c._setHeight(c._getHeight(c.$bellows)),a.removeClass(d.OPENED).addClass(d.CLOSING)},duration:this.options.duration,easing:this.options.easing,complete:function(){a.removeClass(d.CLOSING).find(e.ITEM_CONTENT_WRAPPER).attr("aria-hidden",!0),c._setHeight(),c._trigger("closed",{item:a})}})}},toggleAll:function(){var b=this;this.$bellows.find("."+d.ITEM).each(function(){b.toggle(a(this))})},openAll:function(){var b=this;this.$bellows.find("."+d.ITEM+":not(."+d.OPENED+")").each(function(){b.open(a(this))})},closeAll:function(){var b=this;this.$bellows.find("."+d.OPENED).each(function(){b.close(a(this))})},add:function(b,c){var d=a("<div />");a(b).appendTo(d),c&&this.$bellows.empty(),this._wrapContent(d),this.$bellows.append(d.children())}}),a("[data-bellows]").bellows(),a});
+!function(a){if("function"==typeof define&&define.amd)define(["$","velocity","plugin"],a);else{var b=window.jQuery;a(b,b.Velocity,window.Plugin)}}(function(a,b,c){var d={ITEM:"bellows__item",HEADER:"bellows__header",OPENED:"bellows--is-open",OPENING:"bellows--is-opening",CLOSING:"bellows--is-closing",DISABLED:"bellows--is-disabled"},e={ITEM_HEADER:"> .bellows__item > .bellows__header",ITEM_CONTENT_WRAPPER:"> .bellows__content-wrapper",ITEM_CONTENT:"> .bellows__item > .bellows__content"},f={CLICK:"click.bellows"},g=function(a,b){g.__super__.call(this,a,b,g.DEFAULTS)};return g.VERSION="6.0.0",g.DEFAULTS={singleItemOpen:!1,duration:200,easing:"swing",open:a.noop,opened:a.noop,close:a.noop,closed:a.noop},c.create("bellows",g,{_init:function(b){this.$bellows=a(b),this._wrapContent(this.$bellows),this._bindEvents()},destroy:function(){this.$bellows.removeData(this.name).off(f.CLICK)},_bindEvents:function(){var b=this;this.$bellows.on(f.CLICK,function(c){var e=a(c.target),f=e.closest(".bellows");e.is("a")||e.parents("a").length||f[0]===b.$bellows[0]&&(e.hasClass(d.HEADER)||e.closest(".bellows__header").length)&&(c.preventDefault(),b.toggle(e.closest(".bellows__item")))})},_getHeight:function(a){return parseFloat(b.CSS.getPropertyValue(a[0],"height"))},_setHeight:function(a){this.$bellows.css("height",a||"")},_item:function(a){return"number"==typeof a&&(a=this.$bellows.find("."+d.ITEM).eq(a)),a},_isOpen:function(a){return a.hasClass(d.OPENED)},_isDisabled:function(a){return a.hasClass(d.DISABLED)},_wrapContent:function(a){a.find(e.ITEM_CONTENT).wrap('<div class="bellows__content-wrapper" />').parents(".bellows__item:not(.bellows--is-open)").find(e.ITEM_CONTENT_WRAPPER).attr("aria-hidden",!0)},_othersAreOpening:function(){return this.$bellows.find("."+d.OPENING).length>0},toggle:function(a){a=this._item(a),this[a.hasClass(d.OPENED)?"close":"open"](a)},open:function(a){if(a=this._item(a),!this._isOpen(a)&&!this._isDisabled(a)){var c=this,f=a.find(e.ITEM_CONTENT_WRAPPER);this.options.singleItemOpen&&(this.closeAll(),this._othersAreOpening())||(this._trigger("open",{item:a}),b.animate(f,"slideDown",{begin:function(){c._setHeight(c._getHeight(c.$bellows)+c._getHeight(f)),a.addClass(d.OPENING)},duration:this.options.duration,easing:this.options.easing,complete:function(){a.removeClass(d.OPENING).addClass(d.OPENED).find(e.ITEM_CONTENT_WRAPPER).removeAttr("aria-hidden"),c._setHeight(),c._trigger("opened",{item:a})}}))}},close:function(a){if(a=this._item(a),this._isOpen(a)&&!this._isDisabled(a)){var c=this,f=a.find(e.ITEM_CONTENT_WRAPPER);this._trigger("close",{item:a}),b.animate(f,"slideUp",{begin:function(){c._setHeight(c._getHeight(c.$bellows)),a.removeClass(d.OPENED).addClass(d.CLOSING)},duration:this.options.duration,easing:this.options.easing,complete:function(){a.removeClass(d.CLOSING).find(e.ITEM_CONTENT_WRAPPER).attr("aria-hidden",!0),c._setHeight(),c._trigger("closed",{item:a})}})}},toggleAll:function(){var b=this;this.$bellows.find("."+d.ITEM).each(function(){b.toggle(a(this))})},openAll:function(){var b=this;this.$bellows.find("."+d.ITEM+":not(."+d.OPENED+")").each(function(){b.open(a(this))})},closeAll:function(){var b=this;this.$bellows.find("."+d.OPENED).each(function(){b.close(a(this))})},add:function(b,c){var d=a("<div />");a(b).appendTo(d),c&&this.$bellows.empty(),this._wrapContent(d),this.$bellows.append(d.children())}}),a("[data-bellows]").bellows(),a});
View
@@ -137,6 +137,13 @@
.attr('aria-hidden', true);
},
+ /*
+ Checks if other bellows items are currently opening
+ */
+ _othersAreOpening: function() {
+ return this.$bellows.find('.' + cssClasses.OPENING).length > 0;
+ },
+
toggle: function($item) {
$item = this._item($item);
@@ -155,6 +162,11 @@
if (this.options.singleItemOpen) {
this.closeAll();
+
+ // Fix #63
+ if (this._othersAreOpening()) {
+ return;
+ }
}
this._trigger('open', {item: $item});
View
@@ -282,5 +282,20 @@ define([
expect($openDisabledItem.hasClass('bellows--is-open')).to.be.true;
});
});
+
+ describe('a Bellows instance with singleItemOpen set', function() {
+ it('only allows a single item open when opening another item', function() {
+ $element.bellows({
+ singleItemOpen: true,
+ opened: function() {
+ $element.bellows('open', 1);
+ $element.find('.bellows__item.bellows--is-open').to.have.length(1);
+ done();
+ }
+ });
+
+ $element.bellows('open', 0);
+ });
+ });
});
});

0 comments on commit 0dca9cd

Please sign in to comment.