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
7 changes: 4 additions & 3 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 <balakirev.andrey@gmail.com>",
Expand All @@ -27,11 +27,12 @@
],
"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",
"backbone.anchor": "~1.0.1"
"backbone.anchor": "~1.0.1",
"backbone.mix": "~1.0.1"
},
"devDependencies": {
"mocha": "~2.0.1",
Expand Down
37 changes: 3 additions & 34 deletions lib/Tabs.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
define([
'backbone',
'Backbone.View.Elements',
'underscore',
'backbone.anchor/lib/anchor'
], function (Backbone, ElementsView, _, anchor) {
'underscore'
], function (Backbone, ElementsView, _) {
'use strict';

/**
Expand Down Expand Up @@ -73,35 +72,6 @@ define([

this.getName = _.once(this.getName);
this._initActiveTab();
this._linkWithAnchor();
},

/**
* @private
*/
_linkWithAnchor: function () {
var name = this.getName();
anchor.on('change:' + name, this._onHashChange, this);
if (anchor.has(name)) {
this._processAnchorChange(anchor.get(name));
}
},

/**
* @param {string} tabName
* @protected
*/
_processAnchorChange: function (tabName) {
this.show(tabName);
},

/**
* @param {Backbone.Model} model
* @param {string} tabName
* @private
*/
_onHashChange: function (model, tabName) {
this._processAnchorChange(tabName);
},

/**
Expand Down Expand Up @@ -140,7 +110,6 @@ define([
return this;
}
this._setActiveTab(name);
anchor.set(this.getName(), name);
return this;
},

Expand All @@ -159,7 +128,7 @@ define([

this._activeTab = name;

this.trigger('change', name, this);
this.trigger('change', name, $body, this);
Backbone.trigger('change:visibility');
},

Expand Down
11 changes: 7 additions & 4 deletions lib/TabsManager.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
define([
'underscore',
'backbone.factory/lib/SelectorsFactory',
'./Tabs'
], function (_, SelectorsFactory, Tabs) {
'./Tabs',
'./WithAnchor'
], function (_, SelectorsFactory, Tabs, WithAnchor) {
'use strict';

/**
Expand All @@ -17,7 +18,8 @@ define([
*/
_selectors: function () {
return _.defaults({
tabs: '.tabs'
tabs: '.tabs',
tabsWithoutAnchor: '.tabs_without-anchor'
}, this._super());
},

Expand All @@ -28,7 +30,8 @@ define([
*/
_products: function () {
return _.defaults({
'*': Tabs
'*': Tabs.mix(WithAnchor),
tabsWithoutAnchor: Tabs
}, this._super());
},

Expand Down
63 changes: 63 additions & 0 deletions lib/WithAnchor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
define([
'backbone.mix',
'backbone.anchor/lib/anchor',
'backbone-super'
], function (Mixin, anchor) {
'use strict';

/**
* @mixin WithAnchor
* @extends Tabs
*/
var WithAnchor = new Mixin(/** @lends WithAnchor# */{
/**
* @constructs
*/
initialize: function () {
this._super();

this._linkWithAnchor();
},

/**
* @private
*/
_linkWithAnchor: function () {
var name = this.getName();
anchor.on('change:' + name, this._onHashChange, this);
if (anchor.has(name)) {
this._processAnchorChange(anchor.get(name));
}
},

/**
* @param {string} tabName
* @protected
*/
_processAnchorChange: function (tabName) {
this.show(tabName);
},

/**
* @param {Backbone.Model} model
* @param {string} tabName
* @private
*/
_onHashChange: function (model, tabName) {
this._processAnchorChange(tabName);
},

/**
* @public
* @param {string} name
* @returns {Tabs} this
*/
show: function (name) {
this._super(name);

anchor.set(this.getName(), name);
return this;
}
});
return WithAnchor;
});