From f9a64214777a0f5c63b5b3896b566297691e5de0 Mon Sep 17 00:00:00 2001 From: heymexa Date: Tue, 30 Jun 2015 17:15:57 +0300 Subject: [PATCH 1/2] split Tabs of Tabs and WithAnchor --- bower.json | 3 ++- lib/Tabs.js | 35 ++------------------------ lib/TabsManager.js | 11 +++++--- lib/WithAnchor.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 38 deletions(-) create mode 100644 lib/WithAnchor.js diff --git a/bower.json b/bower.json index 46c15b5..32a8e3c 100755 --- a/bower.json +++ b/bower.json @@ -31,7 +31,8 @@ "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", diff --git a/lib/Tabs.js b/lib/Tabs.js index 936297d..fa44f36 100644 --- a/lib/Tabs.js +++ b/lib/Tabs.js @@ -1,9 +1,8 @@ define([ 'backbone', 'Backbone.View.Elements', - 'underscore', - 'backbone.anchor/lib/anchor' -], function (Backbone, ElementsView, _, anchor) { + 'underscore' +], function (Backbone, ElementsView, _) { 'use strict'; /** @@ -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); }, /** @@ -140,7 +110,6 @@ define([ return this; } this._setActiveTab(name); - anchor.set(this.getName(), name); return this; }, diff --git a/lib/TabsManager.js b/lib/TabsManager.js index 9f03b7c..10100e4 100644 --- a/lib/TabsManager.js +++ b/lib/TabsManager.js @@ -1,8 +1,9 @@ define([ 'underscore', 'backbone.factory/lib/SelectorsFactory', - './Tabs' -], function (_, SelectorsFactory, Tabs) { + './Tabs', + './WithAnchor' +], function (_, SelectorsFactory, Tabs, WithAnchor) { 'use strict'; /** @@ -17,7 +18,8 @@ define([ */ _selectors: function () { return _.defaults({ - tabs: '.tabs' + tabs: '.tabs', + anchorTabs: '.tabs_with_anchor' }, this._super()); }, @@ -28,7 +30,8 @@ define([ */ _products: function () { return _.defaults({ - '*': Tabs + '*': Tabs, + anchorTabs: Tabs.mix(WithAnchor) }, this._super()); }, diff --git a/lib/WithAnchor.js b/lib/WithAnchor.js new file mode 100644 index 0000000..34057d6 --- /dev/null +++ b/lib/WithAnchor.js @@ -0,0 +1,63 @@ +define([ + 'backbone.mix', + 'backbone.anchor/lib/anchor', + 'backbone-super' +], function (Mixin, anchor) { + 'use strict'; + + /** + * @mixin WithAnchors + * @extends Tabs + */ + var WithAnchors = new Mixin(/** @lends WithAnchors# */{ + /** + * @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 WithAnchors; +}); From 01a14bd552b50f29dd444e87661ec069b3a423d0 Mon Sep 17 00:00:00 2001 From: heymexa Date: Wed, 8 Jul 2015 14:55:09 +0300 Subject: [PATCH 2/2] split Tabs of Tabs and WithAnchor --- bower.json | 4 ++-- lib/Tabs.js | 2 +- lib/TabsManager.js | 6 +++--- lib/WithAnchor.js | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bower.json b/bower.json index aceb368..9999248 100755 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "backbone.tabs", - "version": "0.1.1", + "version": "0.1.2", "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/Tabs.js b/lib/Tabs.js index fa44f36..8da734d 100644 --- a/lib/Tabs.js +++ b/lib/Tabs.js @@ -128,7 +128,7 @@ define([ this._activeTab = name; - this.trigger('change', name, this); + this.trigger('change', name, $body, this); Backbone.trigger('change:visibility'); }, diff --git a/lib/TabsManager.js b/lib/TabsManager.js index 10100e4..78276a1 100644 --- a/lib/TabsManager.js +++ b/lib/TabsManager.js @@ -19,7 +19,7 @@ define([ _selectors: function () { return _.defaults({ tabs: '.tabs', - anchorTabs: '.tabs_with_anchor' + tabsWithoutAnchor: '.tabs_without-anchor' }, this._super()); }, @@ -30,8 +30,8 @@ define([ */ _products: function () { return _.defaults({ - '*': Tabs, - anchorTabs: Tabs.mix(WithAnchor) + '*': Tabs.mix(WithAnchor), + tabsWithoutAnchor: Tabs }, this._super()); }, diff --git a/lib/WithAnchor.js b/lib/WithAnchor.js index 34057d6..c9fa866 100644 --- a/lib/WithAnchor.js +++ b/lib/WithAnchor.js @@ -6,10 +6,10 @@ define([ 'use strict'; /** - * @mixin WithAnchors + * @mixin WithAnchor * @extends Tabs */ - var WithAnchors = new Mixin(/** @lends WithAnchors# */{ + var WithAnchor = new Mixin(/** @lends WithAnchor# */{ /** * @constructs */ @@ -59,5 +59,5 @@ define([ return this; } }); - return WithAnchors; + return WithAnchor; });