(function ($) {

Drupal.settings.views = Drupal.settings.views || {'ajax_path': '/views/ajax'};

 

Drupal.quicktabs = Drupal.quicktabs || {};

 

Drupal.quicktabs.getQTName = function (el) {

return el.id.substring(el.id.indexOf('-') +1);

}

 

Drupal.behaviors.quicktabs = {

attach: function (context, settings) {

$.extend(true, Drupal.settings, settings);

$('.quicktabs-wrapper', context).once(function(){

Drupal.quicktabs.prepare(this);

});

}

}

 

// Setting up the inital behaviours

Drupal.quicktabs.prepare = function(el) {

// el.id format: "quicktabs-$name"

var qt_name = Drupal.quicktabs.getQTName(el);

var $ul = $(el).find('ul.quicktabs-tabs:first');

$ul.find('li a').each(function(i, element){

element.myTabIndex = i;

element.qt_name = qt_name;

var tab = new Drupal.quicktabs.tab(element);

var parent_li = $(element).parents('li').get(0);

if ($(parent_li).hasClass('active')) {

$(element).addClass('quicktabs-loaded');

}

$(element).once(function() {$(this).bind('click', {tab: tab}, Drupal.quicktabs.clickHandler);});

});

}

 

Drupal.quicktabs.clickHandler = function(event) {

var tab = event.data.tab;

var element = this;

// Set clicked tab to active.

$(this).parents('li').siblings().removeClass('active');

$(this).parents('li').addClass('active');

 

// Hide all tabpages.

tab.container.children().addClass('quicktabs-hide');

if (!tab.tabpage.hasClass("quicktabs-tabpage")) {

tab = new Drupal.quicktabs.tab(element);

}

 

tab.tabpage.removeClass('quicktabs-hide');

return false;

}

 

// Constructor for an individual tab

Drupal.quicktabs.tab = function (el) {

this.element = el;

this.tabIndex = el.myTabIndex;

var qtKey = 'qt_' + el.qt_name;

var i = 0;

for (var i = 0; i < Drupal.settings.quicktabs[qtKey].tabs.length; i++) {

if (i == this.tabIndex) {

this.tabObj = Drupal.settings.quicktabs[qtKey].tabs[i];

this.tabKey = i;

}

}

this.tabpage_id = 'quicktabs-tabpage-' + el.qt_name + '-' + this.tabKey;

this.container = $('#quicktabs-container-' + el.qt_name);

this.tabpage = this.container.find('#' + this.tabpage_id);

}

 

if (Drupal.ajax) {

/**

* Handle an event that triggers an AJAX response.

*

* We unfortunately need to override this function, which originally comes from

* misc/ajax.js, in order to be able to cache loaded tabs, i.e. once a tab

* content has loaded it should not need to be loaded again.

*

* I have removed all comments that were in the original core function, so that

* the only comments inside this function relate to the Quicktabs modification

* of it.

*/

Drupal.ajax.prototype.eventResponse = function (element, event) {

var ajax = this;

 

if (ajax.ajaxing) {

return false;

}

try {

if (ajax.form) {

if (ajax.setClick) {

element.form.clk = element;

}

ajax.form.ajaxSubmit(ajax.options);

}

else {

// Do not perform an ajax request for already loaded Quicktabs content.

if (!$(element).hasClass('quicktabs-loaded')) {

ajax.beforeSerialize(ajax.element, ajax.options);

$.ajax(ajax.options);

if ($(element).parents('ul').hasClass('quicktabs-tabs')) {

$(element).addClass('quicktabs-loaded');

}

}

}

}

catch (e) {

ajax.ajaxing = false;

alert("An error occurred while attempting to process " + ajax.options.url + ": " + e.message);

}

return false;

};

}

 

 

})(jQuery);

;

(function ($) {

 

/**

* Toggle the visibility of a fieldset using smooth animations.

*/

Drupal.toggleFieldset = function (fieldset) {

var $fieldset = $(fieldset);

if ($fieldset.is('.collapsed')) {

var $content = $('> .fieldset-wrapper', fieldset).hide();

$fieldset

.removeClass('collapsed')

.trigger({ type: 'collapsed', value: false })

.find('> legend span.fieldset-legend-prefix').html(Drupal.t('Hide'));

$content.slideDown({

duration: 'fast',

easing: 'linear',

complete: function () {

Drupal.collapseScrollIntoView(fieldset);

fieldset.animating = false;

},

step: function () {

// Scroll the fieldset into view.

Drupal.collapseScrollIntoView(fieldset);

}

});

}

else {

$fieldset.trigger({ type: 'collapsed', value: true });

$('> .fieldset-wrapper', fieldset).slideUp('fast', function () {

$fieldset

.addClass('collapsed')

.find('> legend span.fieldset-legend-prefix').html(Drupal.t('Show'));

fieldset.animating = false;

});

}

};

 

/**

* Scroll a given fieldset into view as much as possible.

*/

Drupal.collapseScrollIntoView = function (node) {

var h = document.documentElement.clientHeight || document.body.clientHeight || 0;

var offset = document.documentElement.scrollTop || document.body.scrollTop || 0;

var posY = $(node).offset().top;

var fudge = 55;

if (posY + node.offsetHeight + fudge > h + offset) {

if (node.offsetHeight > h) {

window.scrollTo(0, posY);

}

else {

window.scrollTo(0, posY + node.offsetHeight - h + fudge);

}

}

};

 

Drupal.behaviors.collapse = {

attach: function (context, settings) {

$('fieldset.collapsible', context).once('collapse', function () {

var $fieldset = $(this);

// Expand fieldset if there are errors inside, or if it contains an

// element that is targeted by the URI fragment identifier.

var anchor = location.hash && location.hash != '#' ? ', ' + location.hash : '';

if ($fieldset.find('.error' + anchor).length) {

$fieldset.removeClass('collapsed');

}

 

var summary = $('<span class="summary"></span>');

$fieldset.

bind('summaryUpdated', function () {

var text = $.trim($fieldset.drupalGetSummary());

summary.html(text ? ' (' + text + ')' : '');

})

.trigger('summaryUpdated');

 

// Turn the legend into a clickable link, but retain span.fieldset-legend

// for CSS positioning.

var $legend = $('> legend .fieldset-legend', this);

 

$('<span class="fieldset-legend-prefix element-invisible"></span>')

.append($fieldset.hasClass('collapsed') ? Drupal.t('Show') : Drupal.t('Hide'))

.prependTo($legend)

.after(' ');

 

// .wrapInner() does not retain bound events.

var $link = $('<a class="fieldset-title" href="#"></a>')

.prepend($legend.contents())

.appendTo($legend)

.click(function () {

var fieldset = $fieldset.get(0);

// Don't animate multiple times.

if (!fieldset.animating) {

fieldset.animating = true;

Drupal.toggleFieldset(fieldset);

}

return false;

});

 

$legend.append(summary);

});

}

};

 

})(jQuery);

;