Skip to content

Commit c96cde3

Browse files
committed
split DisablableTabs of Tabs and mixin WithDisablable
1 parent bc622bb commit c96cde3

3 files changed

Lines changed: 102 additions & 77 deletions

File tree

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "backbone.tabs",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"homepage": "https://github.com/backbonex/tabs",
55
"authors": [
66
"jifeon <balakirev.andrey@gmail.com>",
@@ -27,7 +27,7 @@
2727
],
2828
"dependencies": {
2929
"backbone": "1.0.x",
30-
"jquery": ">1.7.0",
30+
"jquery": ">1.8.0",
3131
"backbone-super": "~1.0.4",
3232
"backbone.view.elements": "~1.0.1",
3333
"backbone.factory": "~1.1.0",

lib/DisablableTabs.js

Lines changed: 5 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,15 @@
11
define([
22
'jquery',
33
'underscore',
4-
'./Tabs'
5-
], function ($, _, Tabs) {
4+
'./Tabs',
5+
'./WithDisablable'
6+
], function ($, _, Tabs, WithDisablable) {
67
"use strict";
78

89
/**
910
* @class DisablableTabs
11+
* @mixes WithDisablable
1012
* @extends Tabs
1113
*/
12-
var DisablableTabs = Tabs.extend(/**@lends DisablableTabs*/{
13-
14-
/**
15-
* @see {@link Backbone.View._classes}
16-
* @protected
17-
* @returns {Object}
18-
*/
19-
_classes: function () {
20-
return _.defaults({
21-
disabled: 'tabs__title_disabled_yes'
22-
}, this._super());
23-
},
24-
25-
/**
26-
* @protected
27-
*/
28-
_initActiveTab: function () {
29-
var $enabledTitles = this._elem('titles').not(this._selector('disabled'));
30-
if ($enabledTitles.length) {
31-
this._activeTab = this._getTabNameFromEl($enabledTitles.eq(0).find(this._selector('control'))[0]);
32-
}
33-
},
34-
35-
/**
36-
* @public
37-
* @param {string} name
38-
*/
39-
enableTab: function (name) {
40-
this._removeClass('disabled', this._getTabTitleByName(name));
41-
return this;
42-
},
43-
44-
/**
45-
* @public
46-
* @param {string} name
47-
*/
48-
disableTab: function (name) {
49-
this._addClass('disabled', this._getTabTitleByName(name));
50-
return this;
51-
},
52-
53-
/**
54-
* Disables all tabs in the collection
55-
* @public
56-
* @returns DisablableTabs this
57-
*/
58-
disable: function () {
59-
this._addClass('disabled', 'title');
60-
return this;
61-
},
62-
63-
/**
64-
* Enables all tabs in the collection
65-
* @public
66-
* @returns DisablableTabs this
67-
*/
68-
enable: function () {
69-
this._removeClass('disabled', 'title');
70-
return this;
71-
},
72-
73-
/**
74-
* @param {string} name
75-
*/
76-
show: function (name) {
77-
if (this._hasClass('disabled', this._getTabTitleByName(name))) {
78-
return this;
79-
}
80-
return this._super(name);
81-
}
82-
});
83-
84-
return DisablableTabs;
14+
return Tabs.mix(WithDisablable);
8515
});

lib/WithDisablable.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
define([
2+
'backbone.mix',
3+
'backbone-super'
4+
], function (Mixin) {
5+
'use strict';
6+
7+
/**
8+
* @mixin WithDisablable
9+
* @extends Tabs
10+
*/
11+
var WithDisablable = new Mixin(/** @lends WithDisablable# */{
12+
13+
/**
14+
* @see {@link Backbone.View._classes}
15+
* @protected
16+
* @returns {Object}
17+
*/
18+
_classes: function () {
19+
return _.defaults({
20+
disabled: 'tabs__title_disabled_yes'
21+
}, this._super());
22+
},
23+
24+
/**
25+
* @protected
26+
*/
27+
_initActiveTab: function () {
28+
var $enabledTitles = this._elem('titles').not(this._selector('disabled'));
29+
if ($enabledTitles.length) {
30+
this._activeTab = this._getTabNameFromEl($enabledTitles.eq(0).find(this._selector('control'))[0]);
31+
}
32+
},
33+
34+
/**
35+
* @public
36+
* @param {string} name
37+
* @returns {Tabs} this
38+
*/
39+
enableTab: function (name) {
40+
this._removeClass('disabled', this._getTabTitleByName(name));
41+
return this;
42+
},
43+
44+
/**
45+
* @public
46+
* @param {string} name
47+
* @returns {Tabs} this
48+
*/
49+
disableTab: function (name) {
50+
this._addClass('disabled', this._getTabTitleByName(name));
51+
return this;
52+
},
53+
54+
/**
55+
* Disables all tabs in the collection
56+
* @public
57+
* @returns {Tabs} this
58+
*/
59+
disable: function () {
60+
this._addClass('disabled', 'title');
61+
return this;
62+
},
63+
64+
/**
65+
* Enables all tabs in the collection
66+
* @public
67+
* @returns {Tabs} this
68+
*/
69+
enable: function () {
70+
this._removeClass('disabled', 'title');
71+
return this;
72+
},
73+
74+
/**
75+
* @param {string} name
76+
* @returns {Tabs} this
77+
*/
78+
show: function (name) {
79+
if (this._isDisabled(name)) {
80+
return this;
81+
}
82+
return this._super(name);
83+
},
84+
85+
/**
86+
* @protected
87+
* @param {string} name
88+
* @returns {boolean}
89+
*/
90+
_isDisabled: function (name) {
91+
return this._hasClass('disabled', this._getTabTitleByName(name));
92+
}
93+
});
94+
return WithDisablable;
95+
});

0 commit comments

Comments
 (0)