diff --git a/bower.json b/bower.json index 18def13..0f66b0a 100755 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "backbone.tabs", - "version": "0.1.1", + "version": "0.2.0", "homepage": "https://github.com/backbonex/tabs", "authors": [ "jifeon ", @@ -27,7 +27,7 @@ ], "dependencies": { "backbone": "1.0.x", - "jquery": ">1.7.0", + "jquery": ">1.8.0", "backbone-super": "~1.0.4", "backbone.view.elements": "~1.0.1", "backbone.factory": "~1.1.0", diff --git a/lib/Disablable.js b/lib/Disablable.js new file mode 100644 index 0000000..7819cb1 --- /dev/null +++ b/lib/Disablable.js @@ -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; +}); diff --git a/lib/DisablableTabs.js b/lib/DisablableTabs.js index ab6d17c..d1e1aa1 100644 --- a/lib/DisablableTabs.js +++ b/lib/DisablableTabs.js @@ -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); });