Mercurial > hg > rr-repo
comparison sites/all/modules/quicktabs/js/quicktabs.js @ 2:b74b41bb73f0
-- Google analytics module
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Thu, 22 Aug 2013 17:22:54 +0100 |
parents | |
children | 134d4b2e75f6 |
comparison
equal
deleted
inserted
replaced
1:67ce89da90df | 2:b74b41bb73f0 |
---|---|
1 (function ($) { | |
2 Drupal.settings.views = Drupal.settings.views || {'ajax_path': '/views/ajax'}; | |
3 | |
4 Drupal.quicktabs = Drupal.quicktabs || {}; | |
5 | |
6 Drupal.quicktabs.getQTName = function (el) { | |
7 return el.id.substring(el.id.indexOf('-') +1); | |
8 } | |
9 | |
10 Drupal.behaviors.quicktabs = { | |
11 attach: function (context, settings) { | |
12 $.extend(true, Drupal.settings, settings); | |
13 $('.quicktabs-wrapper', context).once(function(){ | |
14 Drupal.quicktabs.prepare(this); | |
15 }); | |
16 } | |
17 } | |
18 | |
19 // Setting up the inital behaviours | |
20 Drupal.quicktabs.prepare = function(el) { | |
21 // el.id format: "quicktabs-$name" | |
22 var qt_name = Drupal.quicktabs.getQTName(el); | |
23 var $ul = $(el).find('ul.quicktabs-tabs:first'); | |
24 $ul.find('li a').each(function(i, element){ | |
25 element.myTabIndex = i; | |
26 element.qt_name = qt_name; | |
27 var tab = new Drupal.quicktabs.tab(element); | |
28 var parent_li = $(element).parents('li').get(0); | |
29 if ($(parent_li).hasClass('active')) { | |
30 $(element).addClass('quicktabs-loaded'); | |
31 } | |
32 $(element).once(function() {$(this).bind('click', {tab: tab}, Drupal.quicktabs.clickHandler);}); | |
33 }); | |
34 } | |
35 | |
36 Drupal.quicktabs.clickHandler = function(event) { | |
37 var tab = event.data.tab; | |
38 var element = this; | |
39 // Set clicked tab to active. | |
40 $(this).parents('li').siblings().removeClass('active'); | |
41 $(this).parents('li').addClass('active'); | |
42 | |
43 // Hide all tabpages. | |
44 tab.container.children().addClass('quicktabs-hide'); | |
45 | |
46 if (!tab.tabpage.hasClass("quicktabs-tabpage")) { | |
47 tab = new Drupal.quicktabs.tab(element); | |
48 } | |
49 | |
50 tab.tabpage.removeClass('quicktabs-hide'); | |
51 return false; | |
52 } | |
53 | |
54 // Constructor for an individual tab | |
55 Drupal.quicktabs.tab = function (el) { | |
56 this.element = el; | |
57 this.tabIndex = el.myTabIndex; | |
58 var qtKey = 'qt_' + el.qt_name; | |
59 var i = 0; | |
60 for (var key in Drupal.settings.quicktabs[qtKey].tabs) { | |
61 if (i == this.tabIndex) { | |
62 this.tabObj = Drupal.settings.quicktabs[qtKey].tabs[key]; | |
63 this.tabKey = key; | |
64 } | |
65 i++; | |
66 } | |
67 this.tabpage_id = 'quicktabs-tabpage-' + el.qt_name + '-' + this.tabKey; | |
68 this.container = $('#quicktabs-container-' + el.qt_name); | |
69 this.tabpage = this.container.find('#' + this.tabpage_id); | |
70 } | |
71 | |
72 if (Drupal.ajax) { | |
73 /** | |
74 * Handle an event that triggers an AJAX response. | |
75 * | |
76 * We unfortunately need to override this function, which originally comes from | |
77 * misc/ajax.js, in order to be able to cache loaded tabs, i.e. once a tab | |
78 * content has loaded it should not need to be loaded again. | |
79 * | |
80 * I have removed all comments that were in the original core function, so that | |
81 * the only comments inside this function relate to the Quicktabs modification | |
82 * of it. | |
83 */ | |
84 Drupal.ajax.prototype.eventResponse = function (element, event) { | |
85 var ajax = this; | |
86 | |
87 if (ajax.ajaxing) { | |
88 return false; | |
89 } | |
90 | |
91 try { | |
92 if (ajax.form) { | |
93 if (ajax.setClick) { | |
94 element.form.clk = element; | |
95 } | |
96 | |
97 ajax.form.ajaxSubmit(ajax.options); | |
98 } | |
99 else { | |
100 // Do not perform an ajax request for already loaded Quicktabs content. | |
101 if (!$(element).hasClass('quicktabs-loaded')) { | |
102 ajax.beforeSerialize(ajax.element, ajax.options); | |
103 $.ajax(ajax.options); | |
104 if ($(element).parents('ul').hasClass('quicktabs-tabs')) { | |
105 $(element).addClass('quicktabs-loaded'); | |
106 } | |
107 } | |
108 } | |
109 } | |
110 catch (e) { | |
111 ajax.ajaxing = false; | |
112 alert("An error occurred while attempting to process " + ajax.options.url + ": " + e.message); | |
113 } | |
114 return false; | |
115 }; | |
116 } | |
117 | |
118 | |
119 })(jQuery); |