PageSourceSearch

https://www.nmp.co.jp/modules/contrib/views_slideshow/js/views_slideshow.js?v=11.3.10

js nmp.co.jp collected 2026-09-24 21:27:38 UTC 20,297 bytes, 486 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.