(function ($) { drupal.viewsslideshow = drupal.viewsslideshow || {}; /** * views slideshow controls */ drupal.viewsslideshowcontrols = drupal.viewsslideshowcontrols || {}; /** * implement the play hook for controls. */ drupal.viewsslideshowcontrols.play = function (options) { // route the control call to the correct control type. // need to use try catch so we don't have to check to make sure every part // of the object is defined. try { if (typeof drupal.settings.viewsslideshowcontrols[options.slideshowid].top.type != "undefined" && typeof drupal[drupal.settings.viewsslideshowcontrols[options.slideshowid].top.type].play == 'function') { drupal[drupal.settings.viewsslideshowcontrols[options.slideshowid].top.type].play(options); } } catch(err) { // don't need to do anything on error. } try { if (typeof drupal.settings.viewsslideshowcontrols[options.slideshowid].bottom.type != "undefined" && typeof drupal[drupal.settings.viewsslideshowcontrols[options.slideshowid].bottom.type].play == 'function') { drupal[drupal.settings.viewsslideshowcontrols[options.slideshowid].bottom.type].play(options); } } catch(err) { // don't need to do anything on error. } }; /** * implement the pause hook for controls. */ drupal.viewsslideshowcontrols.pause = function (options) { // route the control call to the correct control type. // need to use try catch so we don't have to check to make sure every part // of the object is defined. try { if (typeof drupal.settings.viewsslideshowcontrols[options.slideshowid].top.type != "undefined" && typeof drupal[drupal.settings.viewsslideshowcontrols[options.slideshowid].top.type].pause == 'function') { drupal[drupal.settings.viewsslideshowcontrols[options.slideshowid].top.type].pause(options); } } catch(err) { // don't need to do anything on error. } try { if (typeof drupal.settings.viewsslideshowcontrols[options.slideshowid].bottom.type != "undefined" && typeof drupal[drupal.settings.viewsslideshowcontrols[options.slideshowid].bottom.type].pause == 'function') { drupal[drupal.settings.viewsslideshowcontrols[options.slideshowid].bottom.type].pause(options); } } catch(err) { // don't need to do anything on error. } }; /** * views slideshow text controls */ // add views slieshow api calls for views slideshow text controls. drupal.behaviors.viewsslideshowcontrolstext = { attach: function (context) { // process previous link $('.views_slideshow_controls_text_previous:not(.views-slideshow-controls-text-previous-processed)', context).addclass('views-slideshow-controls-text-previous-processed').each(function() { var uniqueid = $(this).attr('id').replace('views_slideshow_controls_text_previous_', ''); $(this).click(function() { drupal.viewsslideshow.action({ "action": 'previousslide', "slideshowid": uniqueid }); return false; }); }); // process next link $('.views_slideshow_controls_text_next:not(.views-slideshow-controls-text-next-processed)', context).addclass('views-slideshow-controls-text-next-processed').each(function() { var uniqueid = $(this).attr('id').replace('views_slideshow_controls_text_next_', ''); $(this).click(function() { drupal.viewsslideshow.action({ "action": 'nextslide', "slideshowid": uniqueid }); return false; }); }); // process pause link $('.views_slideshow_controls_text_pause:not(.views-slideshow-controls-text-pause-processed)', context).addclass('views-slideshow-controls-text-pause-processed').each(function() { var uniqueid = $(this).attr('id').replace('views_slideshow_controls_text_pause_', ''); $(this).click(function() { if (drupal.settings.viewsslideshow[uniqueid].paused) { drupal.viewsslideshow.action({ "action": 'play', "slideshowid": uniqueid, "force": true }); } else { drupal.viewsslideshow.action({ "action": 'pause', "slideshowid": uniqueid, "force": true }); } return false; }); }); } }; drupal.viewsslideshowcontrolstext = drupal.viewsslideshowcontrolstext || {}; /** * implement the pause hook for text controls. */ drupal.viewsslideshowcontrolstext.pause = function (options) { var pausetext = drupal.theme.prototype['viewsslideshowcontrolspause'] ? drupal.theme('viewsslideshowcontrolspause') : ''; $('#views_slideshow_controls_text_pause_' + options.slideshowid + ' a').text(pausetext); $('#views_slideshow_controls_text_pause_' + options.slideshowid).removeclass('views-slideshow-controls-text-status-play'); $('#views_slideshow_controls_text_pause_' + options.slideshowid).addclass('views-slideshow-controls-text-status-pause'); }; /** * implement the play hook for text controls. */ drupal.viewsslideshowcontrolstext.play = function (options) { var playtext = drupal.theme.prototype['viewsslideshowcontrolsplay'] ? drupal.theme('viewsslideshowcontrolsplay') : ''; $('#views_slideshow_controls_text_pause_' + options.slideshowid + ' a').text(playtext); $('#views_slideshow_controls_text_pause_' + options.slideshowid).removeclass('views-slideshow-controls-text-status-pause'); $('#views_slideshow_controls_text_pause_' + options.slideshowid).addclass('views-slideshow-controls-text-status-play'); }; // theme the resume control. drupal.theme.prototype.viewsslideshowcontrolspause = function () { return drupal.t('resume'); }; // theme the pause control. drupal.theme.prototype.viewsslideshowcontrolsplay = function () { return drupal.t('pause'); }; /** * views slideshow pager */ drupal.viewsslideshowpager = drupal.viewsslideshowpager || {}; /** * implement the transitionbegin hook for pagers. */ drupal.viewsslideshowpager.transitionbegin = function (options) { // route the pager call to the correct pager type. // need to use try catch so we don't have to check to make sure every part // of the object is defined. try { if (typeof drupal.settings.viewsslideshowpager != "undefined" && typeof drupal.settings.viewsslideshowpager[options.slideshowid].top.type != "undefined" && typeof drupal[drupal.settings.viewsslideshowpager[options.slideshowid].top.type].transitionbegin == 'function') { drupal[drupal.settings.viewsslideshowpager[options.slideshowid].top.type].transitionbegin(options); } } catch(err) { // don't need to do anything on error. } try { if (typeof drupal.settings.viewsslideshowpager != "undefined" && typeof drupal.settings.viewsslideshowpager[options.slideshowid].bottom.type != "undefined" && typeof drupal[drupal.settings.viewsslideshowpager[options.slideshowid].bottom.type].transitionbegin == 'function') { drupal[drupal.settings.viewsslideshowpager[options.slideshowid].bottom.type].transitionbegin(options); } } catch(err) { // don't need to do anything on error. } }; /** * implement the gotoslide hook for pagers. */ drupal.viewsslideshowpager.gotoslide = function (options) { // route the pager call to the correct pager type. // need to use try catch so we don't have to check to make sure every part // of the object is defined. try { if (typeof drupal.settings.viewsslideshowpager[options.slideshowid].top.type != "undefined" && typeof drupal[drupal.settings.viewsslideshowpager[options.slideshowid].top.type].gotoslide == 'function') { drupal[drupal.settings.viewsslideshowpager[options.slideshowid].top.type].gotoslide(options); } } catch(err) { // don't need to do anything on error. } try { if (typeof drupal.settings.viewsslideshowpager[options.slideshowid].bottom.type != "undefined" && typeof drupal[drupal.settings.viewsslideshowpager[options.slideshowid].bottom.type].gotoslide == 'function') { drupal[drupal.settings.viewsslideshowpager[options.slideshowid].bottom.type].gotoslide(options); } } catch(err) { // don't need to do anything on error. } }; /** * implement the previousslide hook for pagers. */ drupal.viewsslideshowpager.previousslide = function (options) { // route the pager call to the correct pager type. // need to use try catch so we don't have to check to make sure every part // of the object is defined. try { if (typeof drupal.settings.viewsslideshowpager[options.slideshowid].top.type != "undefined" && typeof drupal[drupal.settings.viewsslideshowpager[options.slideshowid].top.type].previousslide == 'function') { drupal[drupal.settings.viewsslideshowpager[options.slideshowid].top.type].previousslide(options); } } catch(err) { // don't need to do anything on error. } try { if (typeof drupal.settings.viewsslideshowpager[options.slideshowid].bottom.type != "undefined" && typeof drupal[drupal.settings.viewsslideshowpager[options.slideshowid].bottom.type].previousslide == 'function') { drupal[drupal.settings.viewsslideshowpager[options.slideshowid].bottom.type].previousslide(options); } } catch(err) { // don't need to do anything on error. } }; /** * implement the nextslide hook for pagers. */ drupal.viewsslideshowpager.nextslide = function (options) { // route the pager call to the correct pager type. // need to use try catch so we don't have to check to make sure every part // of the object is defined. try { if (typeof drupal.settings.viewsslideshowpager[options.slideshowid].top.type != "undefined" && typeof drupal[drupal.settings.viewsslideshowpager[options.slideshowid].top.type].nextslide == 'function') { drupal[drupal.settings.viewsslideshowpager[options.slideshowid].top.type].nextslide(options); } } catch(err) { // don't need to do anything on error. } try { if (typeof drupal.settings.viewsslideshowpager[options.slideshowid].bottom.type != "undefined" && typeof drupal[drupal.settings.viewsslideshowpager[options.slideshowid].bottom.type].nextslide == 'function') { drupal[drupal.settings.viewsslideshowpager[options.slideshowid].bottom.type].nextslide(options); } } catch(err) { // don't need to do anything on error. } }; /** * views slideshow pager fields */ // add views slieshow api calls for views slideshow pager fields. drupal.behaviors.viewsslideshowpagerfields = { attach: function (context) { // process pause on hover. $('.views_slideshow_pager_field:not(.views-slideshow-pager-field-processed)', context).addclass('views-slideshow-pager-field-processed').each(function() { // parse out the location and unique id from the full id. var pagerinfo = $(this).attr('id').split('_'); var location = pagerinfo[2]; pagerinfo.splice(0, 3); var uniqueid = pagerinfo.join('_'); // add the activate and pause on pager hover event to each pager item. if (drupal.settings.viewsslideshowpagerfields[uniqueid][location].activatepauseonhover) { $(this).children().each(function(index, pageritem) { var mousein = function() { drupal.viewsslideshow.action({ "action": 'gotoslide', "slideshowid": uniqueid, "slidenum": index }); drupal.viewsslideshow.action({ "action": 'pause', "slideshowid": uniqueid }); }; var mouseout = function() { drupal.viewsslideshow.action({ "action": 'play', "slideshowid": uniqueid }); }; if (jquery.fn.hoverintent) { $(pageritem).hoverintent(mousein, mouseout); } else { $(pageritem).hover(mousein, mouseout); } }); } else { $(this).children().each(function(index, pageritem) { $(pageritem).click(function() { drupal.viewsslideshow.action({ "action": 'gotoslide', "slideshowid": uniqueid, "slidenum": index }); }); }); } }); } }; drupal.viewsslideshowpagerfields = drupal.viewsslideshowpagerfields || {}; /** * implement the transitionbegin hook for pager fields pager. */ drupal.viewsslideshowpagerfields.transitionbegin = function (options) { for (pagerlocation in drupal.settings.viewsslideshowpager[options.slideshowid]) { // remove active class from pagers $('[id^="views_slideshow_pager_field_item_' + pagerlocation + '_' + options.slideshowid + '"]').removeclass('active'); // add active class to active pager. $('#views_slideshow_pager_field_item_'+ pagerlocation + '_' + options.slideshowid + '_' + options.slidenum).addclass('active'); } }; /** * implement the gotoslide hook for pager fields pager. */ drupal.viewsslideshowpagerfields.gotoslide = function (options) { for (pagerlocation in drupal.settings.viewsslideshowpager[options.slideshowid]) { // remove active class from pagers $('[id^="views_slideshow_pager_field_item_' + pagerlocation + '_' + options.slideshowid + '"]').removeclass('active'); // add active class to active pager. $('#views_slideshow_pager_field_item_' + pagerlocation + '_' + options.slideshowid + '_' + options.slidenum).addclass('active'); } }; /** * implement the previousslide hook for pager fields pager. */ drupal.viewsslideshowpagerfields.previousslide = function (options) { for (pagerlocation in drupal.settings.viewsslideshowpager[options.slideshowid]) { // get the current active pager. var pagernum = $('[id^="views_slideshow_pager_field_item_' + pagerlocation + '_' + options.slideshowid + '"].active').attr('id').replace('views_slideshow_pager_field_item_' + pagerlocation + '_' + options.slideshowid + '_', ''); // if we are on the first pager then activate the last pager. // otherwise activate the previous pager. if (pagernum == 0) { pagernum = $('[id^="views_slideshow_pager_field_item_' + pagerlocation + '_' + options.slideshowid + '"]').length() - 1; } else { pagernum--; } // remove active class from pagers $('[id^="views_slideshow_pager_field_item_' + pagerlocation + '_' + options.slideshowid + '"]').removeclass('active'); // add active class to active pager. $('#views_slideshow_pager_field_item_' + pagerlocation + '_' + options.slideshowid + '_' + pagernum).addclass('active'); } }; /** * implement the nextslide hook for pager fields pager. */ drupal.viewsslideshowpagerfields.nextslide = function (options) { for (pagerlocation in drupal.settings.viewsslideshowpager[options.slideshowid]) { // get the current active pager. var pagernum = $('[id^="views_slideshow_pager_field_item_' + pagerlocation + '_' + options.slideshowid + '"].active').attr('id').replace('views_slideshow_pager_field_item_' + pagerlocation + '_' + options.slideshowid + '_', ''); var totalpagers = $('[id^="views_slideshow_pager_field_item_' + pagerlocation + '_' + options.slideshowid + '"]').length(); // if we are on the last pager then activate the first pager. // otherwise activate the next pager. pagernum++; if (pagernum == totalpagers) { pagernum = 0; } // remove active class from pagers $('[id^="views_slideshow_pager_field_item_' + pagerlocation + '_' + options.slideshowid + '"]').removeclass('active'); // add active class to active pager. $('#views_slideshow_pager_field_item_' + pagerlocation + '_' + options.slideshowid + '_' + slidenum).addclass('active'); } }; /** * views slideshow slide counter */ drupal.viewsslideshowslidecounter = drupal.viewsslideshowslidecounter || {}; /** * implement the transitionbegin for the slide counter. */ drupal.viewsslideshowslidecounter.transitionbegin = function (options) { $('#views_slideshow_slide_counter_' + options.slideshowid + ' .num').text(options.slidenum + 1); }; /** * this is used as a router to process actions for the slideshow. */ drupal.viewsslideshow.action = function (options) { // set default values for our return status. var status = { 'value': true, 'text': '' }; // if an action isn't specified return false. if (typeof options.action == 'undefined' || options.action == '') { status.value = false; status.text = drupal.t('there was no action specified.'); return error; } // if we are using pause or play switch paused state accordingly. if (options.action == 'pause') { drupal.settings.viewsslideshow[options.slideshowid].paused = 1; // if the calling method is forcing a pause then mark it as such. if (options.force) { drupal.settings.viewsslideshow[options.slideshowid].pausedforce = 1; } } else if (options.action == 'play') { // if the slideshow isn't forced pause or we are forcing a play then play // the slideshow. // otherwise return telling the calling method that it was forced paused. if (!drupal.settings.viewsslideshow[options.slideshowid].pausedforce || options.force) { drupal.settings.viewsslideshow[options.slideshowid].paused = 0; drupal.settings.viewsslideshow[options.slideshowid].pausedforce = 0; } else { status.value = false; status.text += ' ' + drupal.t('this slideshow is forced paused.'); return status; } } // we use a switch statement here mainly just to limit the type of actions // that are available. switch (options.action) { case "gotoslide": case "transitionbegin": case "transitionend": // the three methods above require a slide number. checking if it is // defined and it is a number that is an integer. if (typeof options.slidenum == 'undefined' || typeof options.slidenum !== 'number' || parseint(options.slidenum) != (options.slidenum - 0)) { status.value = false; status.text = drupal.t('an invalid integer was specified for slidenum.'); } case "pause": case "play": case "nextslide": case "previousslide": // grab our list of methods. var methods = drupal.settings.viewsslideshow[options.slideshowid]['methods']; // if the calling method specified methods that shouldn't be called then // exclude calling them. var excludemethodsobj = {}; if (typeof options.excludemethods !== 'undefined') { // we need to turn the excludemethods array into an object so we can use the in // function. for (var i=0; i < excludemethods.length; i++) { excludemethodsobj[excludemethods[i]] = ''; } } // call every registered method and don't call excluded ones. for (i = 0; i < methods[options.action].length; i++) { if (drupal[methods[options.action][i]] != undefined && typeof drupal[methods[options.action][i]][options.action] == 'function' && !(methods[options.action][i] in excludemethodsobj)) { drupal[methods[options.action][i]][options.action](options); } } break; // if it gets here it's because it's an invalid action. default: status.value = false; status.text = drupal.t('an invalid action "!action" was specified.', { "!action": options.action }); } return status; }; })(jquery); ;