123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- (function ($) {
- Drupal.behaviors.initFaqModule = {
- attach: function (context) {
- // Hide/show answer for a question.
- var faq_hide_qa_accordion = Drupal.settings.faq.faq_hide_qa_accordion;
- $('div.faq-dd-hide-answer', context).addClass("collapsible collapsed");
- if (!faq_hide_qa_accordion) {
- $('div.faq-dd-hide-answer:not(.faq-processed)', context).addClass('faq-processed').hide();
- }
- $('div.faq-dt-hide-answer:not(.faq-processed)', context).addClass('faq-processed').click(function() {
- if (faq_hide_qa_accordion) {
- $('div.faq-dt-hide-answer').not($(this)).removeClass('faq-qa-visible');
- }
- $(this).toggleClass('faq-qa-visible');
- $(this).parent().addClass('faq-viewed');
- $('div.faq-dd-hide-answer').not($(this).next('div.faq-dd-hide-answer')).addClass("collapsed");
- if (!faq_hide_qa_accordion) {
- $(this).next('div.faq-dd-hide-answer').slideToggle('fast', function() {
- $(this).parent().toggleClass('expanded');
- });
- }
- $(this).next('div.faq-dd-hide-answer').toggleClass("collapsed");
- // Change the fragment, too, for permalink/bookmark.
- // To keep the current page from scrolling, refs
- // http://stackoverflow.com/questions/1489624/modifying-document-location-hash-without-page-scrolling/1489802#1489802
- var hash = $(this).find('a').attr('id');
- var fx, node = $('#' + hash);
- if (node.length) {
- fx = $('<div></div>')
- .css({position: 'absolute', visibility: 'hidden', top: $(window).scrollTop() + 'px'})
- .attr('id', hash)
- .appendTo(document.body);
- node.attr('id', '');
- }
- document.location.hash = hash;
- if (node.length) {
- fx.remove();
- node.attr('id', hash);
- }
- // Scroll the page if the collapsed FAQ is not visible.
- // If we have the toolbar so the title may be hidden by the bar.
- var mainScrollTop = Math.max($('html', context).scrollTop(), $('body', context).scrollTop());
- // We compute mainScrollTop because the behaviour is different on FF, IE and CR
- if (mainScrollTop > $(this).offset().top) {
- $('html, body', context).animate({
- scrollTop: $(this).offset().top
- }, 1);
- }
-
- return false;
- });
- // Show any question identified by a fragment
- if (/^#\w+$/.test(document.location.hash)) {
- $('div.faq-dt-hide-answer ' + document.location.hash).parents('.faq-dt-hide-answer').triggerHandler('click');
- }
- // Hide/show q/a for a category.
- var faq_category_hide_qa_accordion = Drupal.settings.faq.faq_category_hide_qa_accordion;
- $('div.faq-qa-hide', context).addClass("collapsible collapsed");
- if (!faq_category_hide_qa_accordion) {
- $('div.faq-qa-hide', context).hide();
- }
- $('div.faq-qa-header .faq-header:not(.faq-processed)', context).addClass('faq-processed').click(function() {
- if (faq_category_hide_qa_accordion) {
- $('div.faq-qa-header .faq-header').not($(this)).removeClass('faq-category-qa-visible');
- }
- $(this).toggleClass('faq-category-qa-visible');
- $('div.faq-qa-hide').not($(this).parent().next('div.faq-qa-hide')).addClass("collapsed");
- if (!faq_category_hide_qa_accordion) {
- $(this).parent().next('div.faq-qa-hide').slideToggle('fast', function() {
- $(this).parent().toggleClass('expanded');
- });
- }
- $(this).parent().next('div.faq-qa-hide').toggleClass("collapsed");
- // Scroll the page if the collapsed FAQ is not visible.
- // If we have the toolbar so the title may be hidden by the bar.
- var mainScrollTop = Math.max($('html', context).scrollTop(), $('body', context).scrollTop());
- // We compute mainScrollTop because the behaviour is different on FF, IE and CR
- if (mainScrollTop > $(this).offset().top) {
- $('html, body', context).animate({
- scrollTop: $(this).offset().top
- }, 1);
- }
-
- return false;
- });
- // Show expand all link.
- if (!faq_hide_qa_accordion && !faq_category_hide_qa_accordion) {
- $('#faq-expand-all', context).show();
- $('#faq-expand-all a.faq-expand-all-link', context).show();
- // Add collapse link click event.
- $('#faq-expand-all a.faq-collapse-all-link:not(.faq-processed)', context).addClass('faq-processed').click(function () {
- $(this).hide();
- $('#faq-expand-all a.faq-expand-all-link').show();
- $('div.faq-qa-hide').slideUp('slow', function() {
- $(this).removeClass('expanded');
- });
- $('div.faq-dd-hide-answer').slideUp('slow', function() {
- $(this).removeClass('expanded');
- });
- });
- // Add expand link click event.
- $('#faq-expand-all a.faq-expand-all-link:not(.faq-processed)', context).addClass('faq-processed').click(function () {
- $(this).hide();
- $('#faq-expand-all a.faq-collapse-all-link').show();
- $('div.faq-qa-hide').slideDown('slow', function() {
- $(this).addClass('expanded');
- });
- $('div.faq-dd-hide-answer').slideDown('slow', function() {
- $(this).addClass('expanded');
- });
- });
- }
- }
- }
- })(jQuery);
|