Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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.2.0",
"homepage": "https://github.com/backbonex/tabs",
"authors": [
"jifeon <balakirev.andrey@gmail.com>",
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
95 changes: 95 additions & 0 deletions lib/Disablable.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 Disablable
* @extends Tabs
*/
var Disablable = new Mixin(/** @lends Disablable# */{

/**
* @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 Disablable;
});
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',
'./Disablable'
], function ($, _, Tabs, Disablable) {
"use strict";

/**
* @class DisablableTabs
* @mixes Disablable
* @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(Disablable);
});