Skip to content

Commit 7349037

Browse files
committed
fix #422
1 parent 4c26f64 commit 7349037

File tree

3 files changed

+86
-6
lines changed

3 files changed

+86
-6
lines changed

blocks/popup/popup.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ nb.define('popup-toggler', {
720720
if (evt) {
721721
evt.preventDefault();
722722
}
723-
if (!this.$node.hasClass('_nb-is-disabled') && this.popup && !this.popup.isOpen()) {
723+
if (this.isEnabled() && this.popup && !this.popup.isOpen()) {
724724
this.popup.open(this.options);
725725
this.trigger('nb-opened', this);
726726
}
@@ -733,7 +733,7 @@ nb.define('popup-toggler', {
733733
* @returns {Object} nb.block
734734
*/
735735
close: function() {
736-
if (!this.$node.hasClass('_nb-is-disabled') && this.popup && this.popup.isOpen()) {
736+
if (this.isEnabled() && this.popup && this.popup.isOpen()) {
737737
this.popup.close();
738738
this.trigger('nb-closed', this);
739739
}
@@ -814,6 +814,51 @@ nb.define('popup-toggler', {
814814
return this;
815815
},
816816

817+
/**
818+
* Disable the toggler
819+
*
820+
* ```
821+
* popupToggler.disable();
822+
* ```
823+
*
824+
* @fires 'nb-disabled'
825+
* @return {Object} blocks for chaining
826+
*/
827+
disable: function() {
828+
this._tabindex = this.$node.attr('tabindex');
829+
this.$node.attr('tabindex', '-1');
830+
this.$node.addClass('_nb-is-disabled');
831+
this.trigger('nb-disabled', this);
832+
return this;
833+
},
834+
835+
/**
836+
* Enables the toggler
837+
*
838+
* ```
839+
* popupToggler.enable();
840+
* ```
841+
*
842+
* @fires 'nb-enabled'
843+
* @return {Object} blocks for chaining
844+
*/
845+
enable: function() {
846+
this.$node.attr('tabindex', this._tabindex || '0');
847+
this.$node.removeClass('_nb-is-disabled');
848+
this.trigger('nb-enabled', this);
849+
return this;
850+
},
851+
852+
/**
853+
* Return state of the toggler
854+
*
855+
*
856+
* @return {Boolean}
857+
*/
858+
isEnabled: function() {
859+
return !this.$node.hasClass('_nb-is-disabled');
860+
},
861+
817862
/**
818863
* Destroy the popup toggler
819864
* @fires 'nb-destroyed'

blocks/popup/popup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ There are 2 parts of popup control:
66
#### Options for popup toggler
77

88

9-
<a `id="popup-toggler" class="nb link link_wrapper link_pseudo" data-nb="popup-toggler" data-nb-popup-toggler="{id: 'popup1'}" href="#default">
9+
<a id="popup-toggler" class="nb link link_wrapper link_pseudo" data-nb="popup-toggler" data-nb-popup-toggler="{id: 'popup1'}" href="#default">
1010
<span class="link__inner">Default Toggler</span>
1111
</a>
1212

unittests/spec/popup/popup.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,45 @@ describe("Popup Tests", function() {
140140
expect(this.toggler.getOptions().where).to.equal('.content');
141141
});
142142

143-
it("should destroy nb.block", function() {
144-
this.toggler.destroy();
145-
expect(nb.hasBlock($('#popup-toggler')[0])).to.be.equal(false);
143+
144+
it("#disable() check state", function() {
145+
this.toggler.disable();
146+
expect(this.toggler.isEnabled()).to.not.ok();
147+
});
148+
149+
it("#disable() check event", function() {
150+
var flag = true;
151+
152+
this.toggler.on('nb-disabled', function() {
153+
flag = false;
154+
});
155+
156+
this.toggler.disable();
157+
158+
expect(flag).to.not.ok();
159+
});
160+
161+
it("#enable() check state", function() {
162+
this.toggler.disable();
163+
this.toggler.enable();
164+
expect(this.toggler.isEnabled()).to.ok();
146165
});
166+
167+
it("#enable() check event", function() {
168+
var flag = false;
169+
this.toggler.on('nb-enabled', function() {
170+
flag = true;
171+
});
172+
173+
this.toggler.disable();
174+
this.toggler.enable();
175+
expect(flag).to.ok();
176+
});
177+
it("should destroy nb.block", function() {
178+
this.toggler.destroy();
179+
expect(nb.hasBlock($('#popup-toggler')[0])).to.be.equal(false);
180+
});
181+
147182
});
148183

149184
describe("#Popup", function() {

0 commit comments

Comments
 (0)