aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlava Bacherikov <slava@bacher09.org>2012-08-09 15:43:46 +0300
committerSlava Bacherikov <slava@bacher09.org>2012-08-09 15:43:46 +0300
commit33328b3ceac1dcbc0f52a662484709e77824f5fa (patch)
treea2579811009cdb92e50977ec6f92a366fb447740
parentUpdate Requirements (diff)
downloadgentoo-packages-33328b3ceac1dcbc0f52a662484709e77824f5fa.tar.gz
gentoo-packages-33328b3ceac1dcbc0f52a662484709e77824f5fa.tar.bz2
gentoo-packages-33328b3ceac1dcbc0f52a662484709e77824f5fa.zip
Extend tabs history
-rw-r--r--gpackages/static/js/tab_history.js83
1 files changed, 48 insertions, 35 deletions
diff --git a/gpackages/static/js/tab_history.js b/gpackages/static/js/tab_history.js
index f25d5a5..12d4434 100644
--- a/gpackages/static/js/tab_history.js
+++ b/gpackages/static/js/tab_history.js
@@ -1,45 +1,58 @@
-$('.nav-tabs a').each(function(num, obj){
- var tab_id = obj.attributes["tab-id"].value;
- obj.id = tab_id + '_link';
-});
+var HistoryTabs = function(selected_tabs){
+ if (selected_tabs.lenght < 1){
+ return ;
+ }
-var def_tab = $('.nav-tabs li.active').children('a')[0].id;
+ selected_tabs.each(function(num, obj){
+ var tab_id = obj.attributes["tab-id"].value;
+ obj.id = tab_id + '_link';
+ });
-function activate_tab(objs){
- var obj = objs[0],
- real_url = obj.href;
- obj.href = "#" + obj.attributes["tab-id"].value;
- obj.real_url = real_url;
- objs.tab("show");
- obj.href = real_url;
+ var def_tab;
+ selected_tabs.parent().children('.active a').each(function (num, obj){
+ def_tab = obj.id;
+ });
-}
-function activate_tab_by_id(tab_id){
- activate_tab($('#' + tab_id));
-}
-$('.nav-tabs a').click(function(e){
- e.preventDefault();
- activate_tab($(this));
-});
+ function activate_tab(objs){
+ var obj = objs[0],
+ real_url = obj.href;
+ obj.href = "#" + obj.attributes["tab-id"].value;
+ obj.real_url = real_url;
+ objs.tab("show");
+ obj.href = real_url;
-function event_tab_show(){
- $('.nav-tabs a').on("show", function(e){
- history.pushState({tab: e.target.id}, null, e.target.real_url);
+ }
+ function activate_tab_by_id(tab_id){
+ activate_tab($('#' + tab_id));
+ }
+ $('.nav-tabs a').click(function(e){
+ e.preventDefault();
+ activate_tab($(this));
});
-}
-event_tab_show();
-function change_tab(tab_id){
- $('.nav-tabs a').off("show");
- activate_tab_by_id(tab_id);
+ function event_tab_show(){
+ selected_tabs.on("show", function(e){
+ history.pushState({tab: e.target.id}, null, e.target.real_url);
+ });
+ }
event_tab_show();
-}
-$(window).on('popstate', function(){
- var current = history.state;
- if (current && "tab" in current){
- change_tab(current.tab);
- } else {
- change_tab(def_tab);
+ function change_tab(tab_id){
+ selected_tabs.off("show");
+ activate_tab_by_id(tab_id);
+ event_tab_show();
}
+
+ $(window).on('popstate', function(){
+ var current = history.state;
+ if (current && "tab" in current){
+ change_tab(current.tab);
+ } else {
+ change_tab(def_tab);
+ }
+ });
+}
+
+$(function() {
+ HistoryTabs($('.nav-tabs a'));
});