Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split DisablableTabs of Tabs and mixin WithDisablable #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backbone.tabs",
"version": "0.1.1",
"version": "0.1.2",
"homepage": "https://github.com/backbonex/tabs",
"authors": [
"jifeon <[email protected]>",
Expand All @@ -27,7 +27,7 @@
],
"dependencies": {
"backbone": "1.0.x",
"jquery": ">1.7.0",
"jquery": ">1.8.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we should increase minimal jQuery version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handler _onTabClick don't works in sub-tabs.

"backbone-super": "~1.0.4",
"backbone.view.elements": "~1.0.1",
"backbone.factory": "~1.1.0",
Expand Down
80 changes: 5 additions & 75 deletions lib/DisablableTabs.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,15 @@
define([
'jquery',
'underscore',
'./Tabs'
], function ($, _, Tabs) {
'./Tabs',
'./WithDisablable'
], function ($, _, Tabs, WithDisablable) {
"use strict";

/**
* @class DisablableTabs
* @mixes WithDisablable
* @extends Tabs
*/
var DisablableTabs = Tabs.extend(/**@lends DisablableTabs*/{

/**
* @see {@link Backbone.View._classes}
* @protected
* @returns {Object}
*/
_classes: function () {
return _.defaults({
disabled: 'tabs__title_disabled_yes'
}, this._super());
},

/**
* @protected
*/
_initActiveTab: function () {
var $enabledTitles = this._elem('titles').not(this._selector('disabled'));
if ($enabledTitles.length) {
this._activeTab = this._getTabNameFromEl($enabledTitles.eq(0).find(this._selector('control'))[0]);
}
},

/**
* @public
* @param {string} name
*/
enableTab: function (name) {
this._removeClass('disabled', this._getTabTitleByName(name));
return this;
},

/**
* @public
* @param {string} name
*/
disableTab: function (name) {
this._addClass('disabled', this._getTabTitleByName(name));
return this;
},

/**
* Disables all tabs in the collection
* @public
* @returns DisablableTabs this
*/
disable: function () {
this._addClass('disabled', 'title');
return this;
},

/**
* Enables all tabs in the collection
* @public
* @returns DisablableTabs this
*/
enable: function () {
this._removeClass('disabled', 'title');
return this;
},

/**
* @param {string} name
*/
show: function (name) {
if (this._hasClass('disabled', this._getTabTitleByName(name))) {
return this;
}
return this._super(name);
}
});

return DisablableTabs;
return Tabs.mix(WithDisablable);
});
95 changes: 95 additions & 0 deletions lib/WithDisablable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
define([
'backbone.mix',
'backbone-super'
], function (Mixin) {
'use strict';

/**
* @mixin WithDisablable
* @extends Tabs
*/
var WithDisablable = new Mixin(/** @lends WithDisablable# */{

/**
* @see {@link Backbone.View._classes}
* @protected
* @returns {Object}
*/
_classes: function () {
return _.defaults({
disabled: 'tabs__title_disabled_yes'
}, this._super());
},

/**
* @protected
*/
_initActiveTab: function () {
var $enabledTitles = this._elem('titles').not(this._selector('disabled'));
if ($enabledTitles.length) {
this._activeTab = this._getTabNameFromEl($enabledTitles.eq(0).find(this._selector('control'))[0]);
}
},

/**
* @public
* @param {string} name
* @returns {Tabs} this
*/
enableTab: function (name) {
this._removeClass('disabled', this._getTabTitleByName(name));
return this;
},

/**
* @public
* @param {string} name
* @returns {Tabs} this
*/
disableTab: function (name) {
this._addClass('disabled', this._getTabTitleByName(name));
return this;
},

/**
* Disables all tabs in the collection
* @public
* @returns {Tabs} this
*/
disable: function () {
this._addClass('disabled', 'title');
return this;
},

/**
* Enables all tabs in the collection
* @public
* @returns {Tabs} this
*/
enable: function () {
this._removeClass('disabled', 'title');
return this;
},

/**
* @param {string} name
* @returns {Tabs} this
*/
show: function (name) {
if (this._isDisabled(name)) {
return this;
}
return this._super(name);
},

/**
* @protected
* @param {string} name
* @returns {boolean}
*/
_isDisabled: function (name) {
return this._hasClass('disabled', this._getTabTitleByName(name));
}
});
return WithDisablable;
});