Chris@5: (function ($, Drupal, drupalSettings) { Chris@5: 'use strict'; Chris@5: Drupal.viewsSlideshow = Drupal.viewsSlideshow || {}; Chris@5: var pagerLocation; Chris@5: var slideNum; Chris@5: var error; Chris@5: var excludeMethods; Chris@5: /** Chris@5: * Views Slideshow Controls Chris@5: */ Chris@5: Drupal.viewsSlideshowControls = Drupal.viewsSlideshowControls || {}; Chris@5: Chris@5: /** Chris@5: * Implement the play hook for controls. Chris@5: */ Chris@5: Drupal.viewsSlideshowControls.play = function (options) { Chris@5: // Route the control call to the correct control type. Chris@5: // Need to use try catch so we don't have to check to make sure every part Chris@5: // of the object is defined. Chris@5: try { Chris@5: if (typeof drupalSettings.viewsSlideshowControls[options.slideshowID].top.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].top.type].play == 'function') { Chris@5: Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].top.type].play(options); Chris@5: } Chris@5: } Chris@5: catch(err) { Chris@5: // Don't need to do anything on error. Chris@5: } Chris@5: Chris@5: try { Chris@5: if (typeof drupalSettings.viewsSlideshowControls[options.slideshowID].bottom.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].bottom.type].play == 'function') { Chris@5: Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].bottom.type].play(options); Chris@5: } Chris@5: } Chris@5: catch(err) { Chris@5: // Don't need to do anything on error. Chris@5: } Chris@5: }; Chris@5: Chris@5: /** Chris@5: * Implement the pause hook for controls. Chris@5: */ Chris@5: Drupal.viewsSlideshowControls.pause = function (options) { Chris@5: // Route the control call to the correct control type. Chris@5: // Need to use try catch so we don't have to check to make sure every part Chris@5: // of the object is defined. Chris@5: try { Chris@5: if (typeof drupalSettings.viewsSlideshowControls[options.slideshowID].top.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].top.type].pause == 'function') { Chris@5: Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].top.type].pause(options); Chris@5: } Chris@5: } Chris@5: catch(err) { Chris@5: // Don't need to do anything on error. Chris@5: } Chris@5: Chris@5: try { Chris@5: if (typeof drupalSettings.viewsSlideshowControls[options.slideshowID].bottom.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].bottom.type].pause == 'function') { Chris@5: Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].bottom.type].pause(options); Chris@5: } Chris@5: } Chris@5: catch(err) { Chris@5: // Don't need to do anything on error. Chris@5: } Chris@5: }; Chris@5: Chris@5: Chris@5: /** Chris@5: * Views Slideshow Text Controls Chris@5: */ Chris@5: Chris@5: // Add views slieshow api calls for views slideshow text controls. Chris@5: Drupal.behaviors.viewsSlideshowControlsText = { Chris@5: attach: function (context) { Chris@5: Chris@5: // Process previous link Chris@5: $('.views_slideshow_controls_text_previous:not(.views-slideshow-controls-text-previous-processed)', context).addClass('views-slideshow-controls-text-previous-processed').each(function () { Chris@5: var uniqueID = $(this).attr('id').replace('views_slideshow_controls_text_previous_', ''); Chris@5: $(this).click(function () { Chris@5: Drupal.viewsSlideshow.action({"action": 'previousSlide', "slideshowID": uniqueID}); Chris@5: return false; Chris@5: }); Chris@5: }); Chris@5: Chris@5: // Process next link Chris@5: $('.views_slideshow_controls_text_next:not(.views-slideshow-controls-text-next-processed)', context).addClass('views-slideshow-controls-text-next-processed').each(function () { Chris@5: var uniqueID = $(this).attr('id').replace('views_slideshow_controls_text_next_', ''); Chris@5: $(this).click(function () { Chris@5: Drupal.viewsSlideshow.action({"action": 'nextSlide', "slideshowID": uniqueID}); Chris@5: return false; Chris@5: }); Chris@5: }); Chris@5: Chris@5: // Process pause link Chris@5: $('.views_slideshow_controls_text_pause:not(.views-slideshow-controls-text-pause-processed)', context).addClass('views-slideshow-controls-text-pause-processed').each(function () { Chris@5: var uniqueID = $(this).attr('id').replace('views_slideshow_controls_text_pause_', ''); Chris@5: $(this).click(function () { Chris@5: if (drupalSettings.viewsSlideshow[uniqueID].paused) { Chris@5: Drupal.viewsSlideshow.action({"action": 'play', "slideshowID": uniqueID, "force": true}); Chris@5: } Chris@5: else { Chris@5: Drupal.viewsSlideshow.action({"action": 'pause', "slideshowID": uniqueID, "force": true}); Chris@5: } Chris@5: return false; Chris@5: }); Chris@5: }); Chris@5: } Chris@5: }; Chris@5: Chris@5: Drupal.viewsSlideshowControlsText = Drupal.viewsSlideshowControlsText || {}; Chris@5: Chris@5: /** Chris@5: * Implement the pause hook for text controls. Chris@5: */ Chris@5: Drupal.viewsSlideshowControlsText.pause = function (options) { Chris@5: var pauseText = Drupal.theme.viewsSlideshowControlsPause ? Drupal.theme('viewsSlideshowControlsPause') : ''; Chris@5: var $element = $('#views_slideshow_controls_text_pause_' + options.slideshowID); Chris@5: $element.find('a').text(pauseText); Chris@5: $element.removeClass('views-slideshow-controls-text-status-play'); Chris@5: $element.addClass('views-slideshow-controls-text-status-pause'); Chris@5: }; Chris@5: Chris@5: /** Chris@5: * Implement the play hook for text controls. Chris@5: */ Chris@5: Drupal.viewsSlideshowControlsText.play = function (options) { Chris@5: var playText = Drupal.theme.viewsSlideshowControlsPlay ? Drupal.theme('viewsSlideshowControlsPlay') : ''; Chris@5: var $element = $('#views_slideshow_controls_text_pause_' + options.slideshowID); Chris@5: $element.find('a').text(playText); Chris@5: $element.removeClass('views-slideshow-controls-text-status-pause'); Chris@5: $element.addClass('views-slideshow-controls-text-status-play'); Chris@5: }; Chris@5: Chris@5: // Theme the resume control. Chris@5: Drupal.theme.viewsSlideshowControlsPause = function () { Chris@5: return Drupal.t('Resume'); Chris@5: }; Chris@5: Chris@5: // Theme the pause control. Chris@5: Drupal.theme.viewsSlideshowControlsPlay = function () { Chris@5: return Drupal.t('Pause'); Chris@5: }; Chris@5: Chris@5: /** Chris@5: * Views Slideshow Pager Chris@5: */ Chris@5: Drupal.viewsSlideshowPager = Drupal.viewsSlideshowPager || {}; Chris@5: Chris@5: /** Chris@5: * Implement the transitionBegin hook for pagers. Chris@5: */ Chris@5: Drupal.viewsSlideshowPager.transitionBegin = function (options) { Chris@5: // Route the pager call to the correct pager type. Chris@5: // Need to use try catch so we don't have to check to make sure every part Chris@5: // of the object is defined. Chris@5: try { Chris@5: if (typeof drupalSettings.viewsSlideshowPager != "undefined" && typeof drupalSettings.viewsSlideshowPager[options.slideshowID].top.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].transitionBegin == 'function') { Chris@5: Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].transitionBegin(options); Chris@5: } Chris@5: } Chris@5: catch(err) { Chris@5: // Don't need to do anything on error. Chris@5: } Chris@5: Chris@5: try { Chris@5: if (typeof drupalSettings.viewsSlideshowPager != "undefined" && typeof drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].transitionBegin == 'function') { Chris@5: Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].transitionBegin(options); Chris@5: } Chris@5: } Chris@5: catch(err) { Chris@5: // Don't need to do anything on error. Chris@5: } Chris@5: }; Chris@5: Chris@5: /** Chris@5: * Implement the goToSlide hook for pagers. Chris@5: */ Chris@5: Drupal.viewsSlideshowPager.goToSlide = function (options) { Chris@5: // Route the pager call to the correct pager type. Chris@5: // Need to use try catch so we don't have to check to make sure every part Chris@5: // of the object is defined. Chris@5: try { Chris@5: if (typeof drupalSettings.viewsSlideshowPager[options.slideshowID].top.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].goToSlide == 'function') { Chris@5: Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].goToSlide(options); Chris@5: } Chris@5: } Chris@5: catch(err) { Chris@5: // Don't need to do anything on error. Chris@5: } Chris@5: Chris@5: try { Chris@5: if (typeof drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].goToSlide == 'function') { Chris@5: Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].goToSlide(options); Chris@5: } Chris@5: } Chris@5: catch(err) { Chris@5: // Don't need to do anything on error. Chris@5: } Chris@5: }; Chris@5: Chris@5: /** Chris@5: * Implement the previousSlide hook for pagers. Chris@5: */ Chris@5: Drupal.viewsSlideshowPager.previousSlide = function (options) { Chris@5: // Route the pager call to the correct pager type. Chris@5: // Need to use try catch so we don't have to check to make sure every part Chris@5: // of the object is defined. Chris@5: try { Chris@5: if (typeof drupalSettings.viewsSlideshowPager[options.slideshowID].top.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].previousSlide == 'function') { Chris@5: Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].previousSlide(options); Chris@5: } Chris@5: } Chris@5: catch(err) { Chris@5: // Don't need to do anything on error. Chris@5: } Chris@5: Chris@5: try { Chris@5: if (typeof drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].previousSlide == 'function') { Chris@5: Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].previousSlide(options); Chris@5: } Chris@5: } Chris@5: catch(err) { Chris@5: // Don't need to do anything on error. Chris@5: } Chris@5: }; Chris@5: Chris@5: /** Chris@5: * Implement the nextSlide hook for pagers. Chris@5: */ Chris@5: Drupal.viewsSlideshowPager.nextSlide = function (options) { Chris@5: // Route the pager call to the correct pager type. Chris@5: // Need to use try catch so we don't have to check to make sure every part Chris@5: // of the object is defined. Chris@5: try { Chris@5: if (typeof drupalSettings.viewsSlideshowPager[options.slideshowID].top.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].nextSlide == 'function') { Chris@5: Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].nextSlide(options); Chris@5: } Chris@5: } Chris@5: catch(err) { Chris@5: // Don't need to do anything on error. Chris@5: } Chris@5: Chris@5: try { Chris@5: if (typeof drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].nextSlide == 'function') { Chris@5: Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].nextSlide(options); Chris@5: } Chris@5: } Chris@5: catch(err) { Chris@5: // Don't need to do anything on error. Chris@5: } Chris@5: }; Chris@5: Chris@5: Chris@5: /** Chris@5: * Views Slideshow Pager Fields Chris@5: */ Chris@5: Chris@5: // Add views slieshow api calls for views slideshow pager fields. Chris@5: Drupal.behaviors.viewsSlideshowPagerFields = { Chris@5: attach: function (context) { Chris@5: // Process pause on hover. Chris@5: $('.views_slideshow_pager_field:not(.views-slideshow-pager-field-processed)', context).addClass('views-slideshow-pager-field-processed').each(function () { Chris@5: // Parse out the location and unique id from the full id. Chris@5: var pagerInfo = $(this).attr('id').split('_'); Chris@5: var location = pagerInfo[2]; Chris@5: pagerInfo.splice(0, 3); Chris@5: var uniqueID = pagerInfo.join('_'); Chris@5: Chris@5: // Add the activate and pause on pager hover event to each pager item. Chris@5: if (drupalSettings.viewsSlideshowPagerFields[uniqueID][location].activatePauseOnHover) { Chris@5: $(this).children().each(function (index, pagerItem) { Chris@5: var mouseIn = function () { Chris@5: Drupal.viewsSlideshow.action({"action": 'goToSlide', "slideshowID": uniqueID, "slideNum": index}); Chris@5: Drupal.viewsSlideshow.action({"action": 'pause', "slideshowID": uniqueID}); Chris@5: }; Chris@5: Chris@5: var mouseOut = function () { Chris@5: Drupal.viewsSlideshow.action({"action": 'play', "slideshowID": uniqueID}); Chris@5: }; Chris@5: Chris@5: if (jQuery.fn.hoverIntent) { Chris@5: $(pagerItem).hoverIntent(mouseIn, mouseOut); Chris@5: } Chris@5: else { Chris@5: $(pagerItem).hover(mouseIn, mouseOut); Chris@5: } Chris@5: }); Chris@5: } Chris@5: else { Chris@5: $(this).children().each(function (index, pagerItem) { Chris@5: $(pagerItem).click(function () { Chris@5: Drupal.viewsSlideshow.action({"action": 'goToSlide', "slideshowID": uniqueID, "slideNum": index}); Chris@5: }); Chris@5: }); Chris@5: } Chris@5: }); Chris@5: } Chris@5: }; Chris@5: Chris@5: Drupal.viewsSlideshowPagerFields = Drupal.viewsSlideshowPagerFields || {}; Chris@5: Chris@5: /** Chris@5: * Implement the transitionBegin hook for pager fields pager. Chris@5: */ Chris@5: Drupal.viewsSlideshowPagerFields.transitionBegin = function (options) { Chris@5: for (pagerLocation in drupalSettings.viewsSlideshowPager[options.slideshowID]) { Chris@5: if (drupalSettings.viewsSlideshowPager[options.slideshowID]) { Chris@5: // Remove active class from pagers Chris@5: $('[id^="views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '"]').removeClass('active'); Chris@5: Chris@5: // Add active class to active pager. Chris@5: $('#views_slideshow_pager_field_item_'+ pagerLocation + '_' + options.slideshowID + '_' + options.slideNum).addClass('active'); Chris@5: } Chris@5: } Chris@5: }; Chris@5: Chris@5: /** Chris@5: * Implement the goToSlide hook for pager fields pager. Chris@5: */ Chris@5: Drupal.viewsSlideshowPagerFields.goToSlide = function (options) { Chris@5: for (pagerLocation in drupalSettings.viewsSlideshowPager[options.slideshowID]) { Chris@5: if (drupalSettings.viewsSlideshowPager[options.slideshowID]) { Chris@5: // Remove active class from pagers Chris@5: $('[id^="views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '"]').removeClass('active'); Chris@5: Chris@5: // Add active class to active pager. Chris@5: $('#views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '_' + options.slideNum).addClass('active'); Chris@5: } Chris@5: } Chris@5: }; Chris@5: Chris@5: /** Chris@5: * Implement the previousSlide hook for pager fields pager. Chris@5: */ Chris@5: Drupal.viewsSlideshowPagerFields.previousSlide = function (options) { Chris@5: for (pagerLocation in drupalSettings.viewsSlideshowPager[options.slideshowID]) { Chris@5: if (drupalSettings.viewsSlideshowPager[options.slideshowID]) { Chris@5: // Get the current active pager. Chris@5: var pagerNum = $('[id^="views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '"].active').attr('id').replace('views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '_', ''); Chris@5: Chris@5: // If we are on the first pager then activate the last pager. Chris@5: // Otherwise activate the previous pager. Chris@5: if (pagerNum === 0) { Chris@5: pagerNum = $('[id^="views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '"]').length() - 1; Chris@5: } Chris@5: else { Chris@5: pagerNum--; Chris@5: } Chris@5: Chris@5: // Remove active class from pagers Chris@5: $('[id^="views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '"]').removeClass('active'); Chris@5: Chris@5: // Add active class to active pager. Chris@5: $('#views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '_' + pagerNum).addClass('active'); Chris@5: } Chris@5: } Chris@5: }; Chris@5: Chris@5: /** Chris@5: * Implement the nextSlide hook for pager fields pager. Chris@5: */ Chris@5: Drupal.viewsSlideshowPagerFields.nextSlide = function (options) { Chris@5: for (pagerLocation in drupalSettings.viewsSlideshowPager[options.slideshowID]) { Chris@5: if (drupalSettings.viewsSlideshowPager[options.slideshowID]) { Chris@5: // Get the current active pager. Chris@5: var pagerNum = $('[id^="views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '"].active').attr('id').replace('views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '_', ''); Chris@5: var totalPagers = $('[id^="views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '"]').length(); Chris@5: Chris@5: // If we are on the last pager then activate the first pager. Chris@5: // Otherwise activate the next pager. Chris@5: pagerNum++; Chris@5: if (pagerNum === totalPagers) { Chris@5: pagerNum = 0; Chris@5: } Chris@5: Chris@5: // Remove active class from pagers Chris@5: $('[id^="views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '"]').removeClass('active'); Chris@5: Chris@5: // Add active class to active pager. Chris@5: $('#views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '_' + slideNum).addClass('active'); Chris@5: } Chris@5: } Chris@5: }; Chris@5: Chris@5: // Copy the pager hooks from fields pager to the bullets one. Chris@5: Drupal.viewsSlideshowPagerBullets = Drupal.viewsSlideshowPagerFields || {}; Chris@5: Chris@5: /** Chris@5: * Views Slideshow Slide Counter Chris@5: */ Chris@5: Chris@5: Drupal.viewsSlideshowSlideCounter = Drupal.viewsSlideshowSlideCounter || {}; Chris@5: Chris@5: /** Chris@5: * Implement the transitionBegin for the slide counter. Chris@5: */ Chris@5: Drupal.viewsSlideshowSlideCounter.transitionBegin = function (options) { Chris@5: $('#views_slideshow_slide_counter_' + options.slideshowID + ' .num').text(options.slideNum + 1); Chris@5: }; Chris@5: Chris@5: /** Chris@5: * This is used as a router to process actions for the slideshow. Chris@5: */ Chris@5: Drupal.viewsSlideshow.action = function (options) { Chris@5: // Set default values for our return status. Chris@5: var status = { Chris@5: 'value': true, Chris@5: 'text': '' Chris@5: }; Chris@5: Chris@5: // If an action isn't specified return false. Chris@5: if (typeof options.action == 'undefined' || options.action === '') { Chris@5: status.value = false; Chris@5: status.text = Drupal.t('There was no action specified.'); Chris@5: return error; Chris@5: } Chris@5: Chris@5: // If we are using pause or play switch paused state accordingly. Chris@5: if (options.action === 'pause') { Chris@5: drupalSettings.viewsSlideshow[options.slideshowID].paused = 1; Chris@5: // If the calling method is forcing a pause then mark it as such. Chris@5: if (options.force) { Chris@5: drupalSettings.viewsSlideshow[options.slideshowID].pausedForce = 1; Chris@5: } Chris@5: } Chris@5: else if (options.action === 'play') { Chris@5: // If the slideshow isn't forced pause or we are forcing a play then play Chris@5: // the slideshow. Chris@5: // Otherwise return telling the calling method that it was forced paused. Chris@5: if (!drupalSettings.viewsSlideshow[options.slideshowID].pausedForce || options.force) { Chris@5: drupalSettings.viewsSlideshow[options.slideshowID].paused = 0; Chris@5: drupalSettings.viewsSlideshow[options.slideshowID].pausedForce = 0; Chris@5: } Chris@5: else { Chris@5: status.value = false; Chris@5: status.text += ' ' + Drupal.t('This slideshow is forced paused.'); Chris@5: return status; Chris@5: } Chris@5: } Chris@5: Chris@5: // We use a switch statement here mainly just to limit the type of actions Chris@5: // that are available. Chris@5: switch (options.action) { Chris@5: case "goToSlide": Chris@5: case "transitionBegin": Chris@5: case "transitionEnd": Chris@5: // The three methods above require a slide number. Checking if it is Chris@5: // defined and it is a number that is an integer. Chris@5: if (typeof options.slideNum == 'undefined' || typeof options.slideNum !== 'number' || parseInt(options.slideNum) !== (options.slideNum - 0)) { Chris@5: status.value = false; Chris@5: status.text = Drupal.t('An invalid integer was specified for slideNum.'); Chris@5: } Chris@5: case "pause": Chris@5: case "play": Chris@5: case "nextSlide": Chris@5: case "previousSlide": Chris@5: // Grab our list of methods. Chris@5: var methods = drupalSettings.viewsSlideshow[options.slideshowID]['methods']; Chris@5: Chris@5: // if the calling method specified methods that shouldn't be called then Chris@5: // exclude calling them. Chris@5: var excludeMethodsObj = {}; Chris@5: if (typeof options.excludeMethods !== 'undefined') { Chris@5: // We need to turn the excludeMethods array into an object so we can use the in Chris@5: // function. Chris@5: for (var i=0; i < excludeMethods.length; i++) { Chris@5: excludeMethodsObj[excludeMethods[i]] = ''; Chris@5: } Chris@5: } Chris@5: Chris@5: // Call every registered method and don't call excluded ones. Chris@5: for (var i = 0; i < methods[options.action].length; i++) { Chris@5: if (Drupal[methods[options.action][i]] !== 'undefined' && typeof Drupal[methods[options.action][i]][options.action] == 'function' && !(methods[options.action][i] in excludeMethodsObj)) { Chris@5: Drupal[methods[options.action][i]][options.action](options); Chris@5: } Chris@5: } Chris@5: break; Chris@5: Chris@5: // If it gets here it's because it's an invalid action. Chris@5: default: Chris@5: status.value = false; Chris@5: status.text = Drupal.t('An invalid action "@action" was specified.', {"@action": options.action}); Chris@5: } Chris@5: return status; Chris@5: }; Chris@5: })(jQuery, Drupal, drupalSettings);