annotate modules/contrib/views_slideshow/js/views_slideshow.js @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents c69a71b4f40f
children
rev   line source
Chris@5 1 (function ($, Drupal, drupalSettings) {
Chris@5 2 'use strict';
Chris@5 3 Drupal.viewsSlideshow = Drupal.viewsSlideshow || {};
Chris@5 4 var pagerLocation;
Chris@5 5 var slideNum;
Chris@5 6 var error;
Chris@5 7 var excludeMethods;
Chris@5 8 /**
Chris@5 9 * Views Slideshow Controls
Chris@5 10 */
Chris@5 11 Drupal.viewsSlideshowControls = Drupal.viewsSlideshowControls || {};
Chris@5 12
Chris@5 13 /**
Chris@5 14 * Implement the play hook for controls.
Chris@5 15 */
Chris@5 16 Drupal.viewsSlideshowControls.play = function (options) {
Chris@5 17 // Route the control call to the correct control type.
Chris@5 18 // Need to use try catch so we don't have to check to make sure every part
Chris@5 19 // of the object is defined.
Chris@5 20 try {
Chris@5 21 if (typeof drupalSettings.viewsSlideshowControls[options.slideshowID].top.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].top.type].play == 'function') {
Chris@5 22 Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].top.type].play(options);
Chris@5 23 }
Chris@5 24 }
Chris@5 25 catch(err) {
Chris@5 26 // Don't need to do anything on error.
Chris@5 27 }
Chris@5 28
Chris@5 29 try {
Chris@5 30 if (typeof drupalSettings.viewsSlideshowControls[options.slideshowID].bottom.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].bottom.type].play == 'function') {
Chris@5 31 Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].bottom.type].play(options);
Chris@5 32 }
Chris@5 33 }
Chris@5 34 catch(err) {
Chris@5 35 // Don't need to do anything on error.
Chris@5 36 }
Chris@5 37 };
Chris@5 38
Chris@5 39 /**
Chris@5 40 * Implement the pause hook for controls.
Chris@5 41 */
Chris@5 42 Drupal.viewsSlideshowControls.pause = function (options) {
Chris@5 43 // Route the control call to the correct control type.
Chris@5 44 // Need to use try catch so we don't have to check to make sure every part
Chris@5 45 // of the object is defined.
Chris@5 46 try {
Chris@5 47 if (typeof drupalSettings.viewsSlideshowControls[options.slideshowID].top.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].top.type].pause == 'function') {
Chris@5 48 Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].top.type].pause(options);
Chris@5 49 }
Chris@5 50 }
Chris@5 51 catch(err) {
Chris@5 52 // Don't need to do anything on error.
Chris@5 53 }
Chris@5 54
Chris@5 55 try {
Chris@5 56 if (typeof drupalSettings.viewsSlideshowControls[options.slideshowID].bottom.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].bottom.type].pause == 'function') {
Chris@5 57 Drupal[drupalSettings.viewsSlideshowControls[options.slideshowID].bottom.type].pause(options);
Chris@5 58 }
Chris@5 59 }
Chris@5 60 catch(err) {
Chris@5 61 // Don't need to do anything on error.
Chris@5 62 }
Chris@5 63 };
Chris@5 64
Chris@5 65
Chris@5 66 /**
Chris@5 67 * Views Slideshow Text Controls
Chris@5 68 */
Chris@5 69
Chris@5 70 // Add views slieshow api calls for views slideshow text controls.
Chris@5 71 Drupal.behaviors.viewsSlideshowControlsText = {
Chris@5 72 attach: function (context) {
Chris@5 73
Chris@5 74 // Process previous link
Chris@5 75 $('.views_slideshow_controls_text_previous:not(.views-slideshow-controls-text-previous-processed)', context).addClass('views-slideshow-controls-text-previous-processed').each(function () {
Chris@5 76 var uniqueID = $(this).attr('id').replace('views_slideshow_controls_text_previous_', '');
Chris@5 77 $(this).click(function () {
Chris@5 78 Drupal.viewsSlideshow.action({"action": 'previousSlide', "slideshowID": uniqueID});
Chris@5 79 return false;
Chris@5 80 });
Chris@5 81 });
Chris@5 82
Chris@5 83 // Process next link
Chris@5 84 $('.views_slideshow_controls_text_next:not(.views-slideshow-controls-text-next-processed)', context).addClass('views-slideshow-controls-text-next-processed').each(function () {
Chris@5 85 var uniqueID = $(this).attr('id').replace('views_slideshow_controls_text_next_', '');
Chris@5 86 $(this).click(function () {
Chris@5 87 Drupal.viewsSlideshow.action({"action": 'nextSlide', "slideshowID": uniqueID});
Chris@5 88 return false;
Chris@5 89 });
Chris@5 90 });
Chris@5 91
Chris@5 92 // Process pause link
Chris@5 93 $('.views_slideshow_controls_text_pause:not(.views-slideshow-controls-text-pause-processed)', context).addClass('views-slideshow-controls-text-pause-processed').each(function () {
Chris@5 94 var uniqueID = $(this).attr('id').replace('views_slideshow_controls_text_pause_', '');
Chris@5 95 $(this).click(function () {
Chris@5 96 if (drupalSettings.viewsSlideshow[uniqueID].paused) {
Chris@5 97 Drupal.viewsSlideshow.action({"action": 'play', "slideshowID": uniqueID, "force": true});
Chris@5 98 }
Chris@5 99 else {
Chris@5 100 Drupal.viewsSlideshow.action({"action": 'pause', "slideshowID": uniqueID, "force": true});
Chris@5 101 }
Chris@5 102 return false;
Chris@5 103 });
Chris@5 104 });
Chris@5 105 }
Chris@5 106 };
Chris@5 107
Chris@5 108 Drupal.viewsSlideshowControlsText = Drupal.viewsSlideshowControlsText || {};
Chris@5 109
Chris@5 110 /**
Chris@5 111 * Implement the pause hook for text controls.
Chris@5 112 */
Chris@5 113 Drupal.viewsSlideshowControlsText.pause = function (options) {
Chris@5 114 var pauseText = Drupal.theme.viewsSlideshowControlsPause ? Drupal.theme('viewsSlideshowControlsPause') : '';
Chris@5 115 var $element = $('#views_slideshow_controls_text_pause_' + options.slideshowID);
Chris@5 116 $element.find('a').text(pauseText);
Chris@5 117 $element.removeClass('views-slideshow-controls-text-status-play');
Chris@5 118 $element.addClass('views-slideshow-controls-text-status-pause');
Chris@5 119 };
Chris@5 120
Chris@5 121 /**
Chris@5 122 * Implement the play hook for text controls.
Chris@5 123 */
Chris@5 124 Drupal.viewsSlideshowControlsText.play = function (options) {
Chris@5 125 var playText = Drupal.theme.viewsSlideshowControlsPlay ? Drupal.theme('viewsSlideshowControlsPlay') : '';
Chris@5 126 var $element = $('#views_slideshow_controls_text_pause_' + options.slideshowID);
Chris@5 127 $element.find('a').text(playText);
Chris@5 128 $element.removeClass('views-slideshow-controls-text-status-pause');
Chris@5 129 $element.addClass('views-slideshow-controls-text-status-play');
Chris@5 130 };
Chris@5 131
Chris@5 132 // Theme the resume control.
Chris@5 133 Drupal.theme.viewsSlideshowControlsPause = function () {
Chris@5 134 return Drupal.t('Resume');
Chris@5 135 };
Chris@5 136
Chris@5 137 // Theme the pause control.
Chris@5 138 Drupal.theme.viewsSlideshowControlsPlay = function () {
Chris@5 139 return Drupal.t('Pause');
Chris@5 140 };
Chris@5 141
Chris@5 142 /**
Chris@5 143 * Views Slideshow Pager
Chris@5 144 */
Chris@5 145 Drupal.viewsSlideshowPager = Drupal.viewsSlideshowPager || {};
Chris@5 146
Chris@5 147 /**
Chris@5 148 * Implement the transitionBegin hook for pagers.
Chris@5 149 */
Chris@5 150 Drupal.viewsSlideshowPager.transitionBegin = function (options) {
Chris@5 151 // Route the pager call to the correct pager type.
Chris@5 152 // Need to use try catch so we don't have to check to make sure every part
Chris@5 153 // of the object is defined.
Chris@5 154 try {
Chris@5 155 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 156 Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].transitionBegin(options);
Chris@5 157 }
Chris@5 158 }
Chris@5 159 catch(err) {
Chris@5 160 // Don't need to do anything on error.
Chris@5 161 }
Chris@5 162
Chris@5 163 try {
Chris@5 164 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 165 Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].transitionBegin(options);
Chris@5 166 }
Chris@5 167 }
Chris@5 168 catch(err) {
Chris@5 169 // Don't need to do anything on error.
Chris@5 170 }
Chris@5 171 };
Chris@5 172
Chris@5 173 /**
Chris@5 174 * Implement the goToSlide hook for pagers.
Chris@5 175 */
Chris@5 176 Drupal.viewsSlideshowPager.goToSlide = function (options) {
Chris@5 177 // Route the pager call to the correct pager type.
Chris@5 178 // Need to use try catch so we don't have to check to make sure every part
Chris@5 179 // of the object is defined.
Chris@5 180 try {
Chris@5 181 if (typeof drupalSettings.viewsSlideshowPager[options.slideshowID].top.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].goToSlide == 'function') {
Chris@5 182 Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].goToSlide(options);
Chris@5 183 }
Chris@5 184 }
Chris@5 185 catch(err) {
Chris@5 186 // Don't need to do anything on error.
Chris@5 187 }
Chris@5 188
Chris@5 189 try {
Chris@5 190 if (typeof drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].goToSlide == 'function') {
Chris@5 191 Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].goToSlide(options);
Chris@5 192 }
Chris@5 193 }
Chris@5 194 catch(err) {
Chris@5 195 // Don't need to do anything on error.
Chris@5 196 }
Chris@5 197 };
Chris@5 198
Chris@5 199 /**
Chris@5 200 * Implement the previousSlide hook for pagers.
Chris@5 201 */
Chris@5 202 Drupal.viewsSlideshowPager.previousSlide = function (options) {
Chris@5 203 // Route the pager call to the correct pager type.
Chris@5 204 // Need to use try catch so we don't have to check to make sure every part
Chris@5 205 // of the object is defined.
Chris@5 206 try {
Chris@5 207 if (typeof drupalSettings.viewsSlideshowPager[options.slideshowID].top.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].previousSlide == 'function') {
Chris@5 208 Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].previousSlide(options);
Chris@5 209 }
Chris@5 210 }
Chris@5 211 catch(err) {
Chris@5 212 // Don't need to do anything on error.
Chris@5 213 }
Chris@5 214
Chris@5 215 try {
Chris@5 216 if (typeof drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].previousSlide == 'function') {
Chris@5 217 Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].previousSlide(options);
Chris@5 218 }
Chris@5 219 }
Chris@5 220 catch(err) {
Chris@5 221 // Don't need to do anything on error.
Chris@5 222 }
Chris@5 223 };
Chris@5 224
Chris@5 225 /**
Chris@5 226 * Implement the nextSlide hook for pagers.
Chris@5 227 */
Chris@5 228 Drupal.viewsSlideshowPager.nextSlide = function (options) {
Chris@5 229 // Route the pager call to the correct pager type.
Chris@5 230 // Need to use try catch so we don't have to check to make sure every part
Chris@5 231 // of the object is defined.
Chris@5 232 try {
Chris@5 233 if (typeof drupalSettings.viewsSlideshowPager[options.slideshowID].top.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].nextSlide == 'function') {
Chris@5 234 Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].top.type].nextSlide(options);
Chris@5 235 }
Chris@5 236 }
Chris@5 237 catch(err) {
Chris@5 238 // Don't need to do anything on error.
Chris@5 239 }
Chris@5 240
Chris@5 241 try {
Chris@5 242 if (typeof drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type != "undefined" && typeof Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].nextSlide == 'function') {
Chris@5 243 Drupal[drupalSettings.viewsSlideshowPager[options.slideshowID].bottom.type].nextSlide(options);
Chris@5 244 }
Chris@5 245 }
Chris@5 246 catch(err) {
Chris@5 247 // Don't need to do anything on error.
Chris@5 248 }
Chris@5 249 };
Chris@5 250
Chris@5 251
Chris@5 252 /**
Chris@5 253 * Views Slideshow Pager Fields
Chris@5 254 */
Chris@5 255
Chris@5 256 // Add views slieshow api calls for views slideshow pager fields.
Chris@5 257 Drupal.behaviors.viewsSlideshowPagerFields = {
Chris@5 258 attach: function (context) {
Chris@5 259 // Process pause on hover.
Chris@5 260 $('.views_slideshow_pager_field:not(.views-slideshow-pager-field-processed)', context).addClass('views-slideshow-pager-field-processed').each(function () {
Chris@5 261 // Parse out the location and unique id from the full id.
Chris@5 262 var pagerInfo = $(this).attr('id').split('_');
Chris@5 263 var location = pagerInfo[2];
Chris@5 264 pagerInfo.splice(0, 3);
Chris@5 265 var uniqueID = pagerInfo.join('_');
Chris@5 266
Chris@5 267 // Add the activate and pause on pager hover event to each pager item.
Chris@5 268 if (drupalSettings.viewsSlideshowPagerFields[uniqueID][location].activatePauseOnHover) {
Chris@5 269 $(this).children().each(function (index, pagerItem) {
Chris@5 270 var mouseIn = function () {
Chris@5 271 Drupal.viewsSlideshow.action({"action": 'goToSlide', "slideshowID": uniqueID, "slideNum": index});
Chris@5 272 Drupal.viewsSlideshow.action({"action": 'pause', "slideshowID": uniqueID});
Chris@5 273 };
Chris@5 274
Chris@5 275 var mouseOut = function () {
Chris@5 276 Drupal.viewsSlideshow.action({"action": 'play', "slideshowID": uniqueID});
Chris@5 277 };
Chris@5 278
Chris@5 279 if (jQuery.fn.hoverIntent) {
Chris@5 280 $(pagerItem).hoverIntent(mouseIn, mouseOut);
Chris@5 281 }
Chris@5 282 else {
Chris@5 283 $(pagerItem).hover(mouseIn, mouseOut);
Chris@5 284 }
Chris@5 285 });
Chris@5 286 }
Chris@5 287 else {
Chris@5 288 $(this).children().each(function (index, pagerItem) {
Chris@5 289 $(pagerItem).click(function () {
Chris@5 290 Drupal.viewsSlideshow.action({"action": 'goToSlide', "slideshowID": uniqueID, "slideNum": index});
Chris@5 291 });
Chris@5 292 });
Chris@5 293 }
Chris@5 294 });
Chris@5 295 }
Chris@5 296 };
Chris@5 297
Chris@5 298 Drupal.viewsSlideshowPagerFields = Drupal.viewsSlideshowPagerFields || {};
Chris@5 299
Chris@5 300 /**
Chris@5 301 * Implement the transitionBegin hook for pager fields pager.
Chris@5 302 */
Chris@5 303 Drupal.viewsSlideshowPagerFields.transitionBegin = function (options) {
Chris@5 304 for (pagerLocation in drupalSettings.viewsSlideshowPager[options.slideshowID]) {
Chris@5 305 if (drupalSettings.viewsSlideshowPager[options.slideshowID]) {
Chris@5 306 // Remove active class from pagers
Chris@5 307 $('[id^="views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '"]').removeClass('active');
Chris@5 308
Chris@5 309 // Add active class to active pager.
Chris@5 310 $('#views_slideshow_pager_field_item_'+ pagerLocation + '_' + options.slideshowID + '_' + options.slideNum).addClass('active');
Chris@5 311 }
Chris@5 312 }
Chris@5 313 };
Chris@5 314
Chris@5 315 /**
Chris@5 316 * Implement the goToSlide hook for pager fields pager.
Chris@5 317 */
Chris@5 318 Drupal.viewsSlideshowPagerFields.goToSlide = function (options) {
Chris@5 319 for (pagerLocation in drupalSettings.viewsSlideshowPager[options.slideshowID]) {
Chris@5 320 if (drupalSettings.viewsSlideshowPager[options.slideshowID]) {
Chris@5 321 // Remove active class from pagers
Chris@5 322 $('[id^="views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '"]').removeClass('active');
Chris@5 323
Chris@5 324 // Add active class to active pager.
Chris@5 325 $('#views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '_' + options.slideNum).addClass('active');
Chris@5 326 }
Chris@5 327 }
Chris@5 328 };
Chris@5 329
Chris@5 330 /**
Chris@5 331 * Implement the previousSlide hook for pager fields pager.
Chris@5 332 */
Chris@5 333 Drupal.viewsSlideshowPagerFields.previousSlide = function (options) {
Chris@5 334 for (pagerLocation in drupalSettings.viewsSlideshowPager[options.slideshowID]) {
Chris@5 335 if (drupalSettings.viewsSlideshowPager[options.slideshowID]) {
Chris@5 336 // Get the current active pager.
Chris@5 337 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 338
Chris@5 339 // If we are on the first pager then activate the last pager.
Chris@5 340 // Otherwise activate the previous pager.
Chris@5 341 if (pagerNum === 0) {
Chris@5 342 pagerNum = $('[id^="views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '"]').length() - 1;
Chris@5 343 }
Chris@5 344 else {
Chris@5 345 pagerNum--;
Chris@5 346 }
Chris@5 347
Chris@5 348 // Remove active class from pagers
Chris@5 349 $('[id^="views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '"]').removeClass('active');
Chris@5 350
Chris@5 351 // Add active class to active pager.
Chris@5 352 $('#views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '_' + pagerNum).addClass('active');
Chris@5 353 }
Chris@5 354 }
Chris@5 355 };
Chris@5 356
Chris@5 357 /**
Chris@5 358 * Implement the nextSlide hook for pager fields pager.
Chris@5 359 */
Chris@5 360 Drupal.viewsSlideshowPagerFields.nextSlide = function (options) {
Chris@5 361 for (pagerLocation in drupalSettings.viewsSlideshowPager[options.slideshowID]) {
Chris@5 362 if (drupalSettings.viewsSlideshowPager[options.slideshowID]) {
Chris@5 363 // Get the current active pager.
Chris@5 364 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 365 var totalPagers = $('[id^="views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '"]').length();
Chris@5 366
Chris@5 367 // If we are on the last pager then activate the first pager.
Chris@5 368 // Otherwise activate the next pager.
Chris@5 369 pagerNum++;
Chris@5 370 if (pagerNum === totalPagers) {
Chris@5 371 pagerNum = 0;
Chris@5 372 }
Chris@5 373
Chris@5 374 // Remove active class from pagers
Chris@5 375 $('[id^="views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '"]').removeClass('active');
Chris@5 376
Chris@5 377 // Add active class to active pager.
Chris@5 378 $('#views_slideshow_pager_field_item_' + pagerLocation + '_' + options.slideshowID + '_' + slideNum).addClass('active');
Chris@5 379 }
Chris@5 380 }
Chris@5 381 };
Chris@5 382
Chris@5 383 // Copy the pager hooks from fields pager to the bullets one.
Chris@5 384 Drupal.viewsSlideshowPagerBullets = Drupal.viewsSlideshowPagerFields || {};
Chris@5 385
Chris@5 386 /**
Chris@5 387 * Views Slideshow Slide Counter
Chris@5 388 */
Chris@5 389
Chris@5 390 Drupal.viewsSlideshowSlideCounter = Drupal.viewsSlideshowSlideCounter || {};
Chris@5 391
Chris@5 392 /**
Chris@5 393 * Implement the transitionBegin for the slide counter.
Chris@5 394 */
Chris@5 395 Drupal.viewsSlideshowSlideCounter.transitionBegin = function (options) {
Chris@5 396 $('#views_slideshow_slide_counter_' + options.slideshowID + ' .num').text(options.slideNum + 1);
Chris@5 397 };
Chris@5 398
Chris@5 399 /**
Chris@5 400 * This is used as a router to process actions for the slideshow.
Chris@5 401 */
Chris@5 402 Drupal.viewsSlideshow.action = function (options) {
Chris@5 403 // Set default values for our return status.
Chris@5 404 var status = {
Chris@5 405 'value': true,
Chris@5 406 'text': ''
Chris@5 407 };
Chris@5 408
Chris@5 409 // If an action isn't specified return false.
Chris@5 410 if (typeof options.action == 'undefined' || options.action === '') {
Chris@5 411 status.value = false;
Chris@5 412 status.text = Drupal.t('There was no action specified.');
Chris@5 413 return error;
Chris@5 414 }
Chris@5 415
Chris@5 416 // If we are using pause or play switch paused state accordingly.
Chris@5 417 if (options.action === 'pause') {
Chris@5 418 drupalSettings.viewsSlideshow[options.slideshowID].paused = 1;
Chris@5 419 // If the calling method is forcing a pause then mark it as such.
Chris@5 420 if (options.force) {
Chris@5 421 drupalSettings.viewsSlideshow[options.slideshowID].pausedForce = 1;
Chris@5 422 }
Chris@5 423 }
Chris@5 424 else if (options.action === 'play') {
Chris@5 425 // If the slideshow isn't forced pause or we are forcing a play then play
Chris@5 426 // the slideshow.
Chris@5 427 // Otherwise return telling the calling method that it was forced paused.
Chris@5 428 if (!drupalSettings.viewsSlideshow[options.slideshowID].pausedForce || options.force) {
Chris@5 429 drupalSettings.viewsSlideshow[options.slideshowID].paused = 0;
Chris@5 430 drupalSettings.viewsSlideshow[options.slideshowID].pausedForce = 0;
Chris@5 431 }
Chris@5 432 else {
Chris@5 433 status.value = false;
Chris@5 434 status.text += ' ' + Drupal.t('This slideshow is forced paused.');
Chris@5 435 return status;
Chris@5 436 }
Chris@5 437 }
Chris@5 438
Chris@5 439 // We use a switch statement here mainly just to limit the type of actions
Chris@5 440 // that are available.
Chris@5 441 switch (options.action) {
Chris@5 442 case "goToSlide":
Chris@5 443 case "transitionBegin":
Chris@5 444 case "transitionEnd":
Chris@5 445 // The three methods above require a slide number. Checking if it is
Chris@5 446 // defined and it is a number that is an integer.
Chris@5 447 if (typeof options.slideNum == 'undefined' || typeof options.slideNum !== 'number' || parseInt(options.slideNum) !== (options.slideNum - 0)) {
Chris@5 448 status.value = false;
Chris@5 449 status.text = Drupal.t('An invalid integer was specified for slideNum.');
Chris@5 450 }
Chris@5 451 case "pause":
Chris@5 452 case "play":
Chris@5 453 case "nextSlide":
Chris@5 454 case "previousSlide":
Chris@5 455 // Grab our list of methods.
Chris@5 456 var methods = drupalSettings.viewsSlideshow[options.slideshowID]['methods'];
Chris@5 457
Chris@5 458 // if the calling method specified methods that shouldn't be called then
Chris@5 459 // exclude calling them.
Chris@5 460 var excludeMethodsObj = {};
Chris@5 461 if (typeof options.excludeMethods !== 'undefined') {
Chris@5 462 // We need to turn the excludeMethods array into an object so we can use the in
Chris@5 463 // function.
Chris@5 464 for (var i=0; i < excludeMethods.length; i++) {
Chris@5 465 excludeMethodsObj[excludeMethods[i]] = '';
Chris@5 466 }
Chris@5 467 }
Chris@5 468
Chris@5 469 // Call every registered method and don't call excluded ones.
Chris@5 470 for (var i = 0; i < methods[options.action].length; i++) {
Chris@5 471 if (Drupal[methods[options.action][i]] !== 'undefined' && typeof Drupal[methods[options.action][i]][options.action] == 'function' && !(methods[options.action][i] in excludeMethodsObj)) {
Chris@5 472 Drupal[methods[options.action][i]][options.action](options);
Chris@5 473 }
Chris@5 474 }
Chris@5 475 break;
Chris@5 476
Chris@5 477 // If it gets here it's because it's an invalid action.
Chris@5 478 default:
Chris@5 479 status.value = false;
Chris@5 480 status.text = Drupal.t('An invalid action "@action" was specified.', {"@action": options.action});
Chris@5 481 }
Chris@5 482 return status;
Chris@5 483 };
Chris@5 484 })(jQuery, Drupal, drupalSettings);