-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpanopoly-widgets-spotlight.js
More file actions
122 lines (104 loc) · 4.5 KB
/
Copy pathpanopoly-widgets-spotlight.js
File metadata and controls
122 lines (104 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Drupal.settings.spotlight_settings = Drupal.settings.spotlight_settings || {};
(function ($) {
/**
* Form behavior for Spotlight
*/
Drupal.behaviors.panopolySpotlight = {
attach: function (context, settings) {
if ($('.field-name-field-basic-spotlight-items', context).length) {
$('.field-name-field-basic-spotlight-items', context).each(function() {
var rotation_time = $(this).find('.panopoly-spotlight-buttons-wrapper').data('rotation-time'),
$widget = $(this),
$slides = $widget.find('.panopoly-spotlight'),
$controls = $widget.find('.panopoly-spotlight-buttons-wrapper li'),
current = 0,
timer = null;
function start() {
if (timer === null) {
timer = setTimeout(rotate, rotation_time);
}
}
function stop() {
if (timer !== null) {
clearTimeout(timer);
timer = null;
}
}
function rotate() {
// Increment the current slide.
current++;
if (current >= $controls.length) {
current = 0;
}
// Click the control for the next slide.
$controls.eq(current).children('a').trigger('click.panopoly-widgets-spotlight');
}
// Navigation is hidden by default, display it if JavaScript is enabled.
$widget.find('.panopoly-spotlight-buttons-wrapper').css('display', 'block');
// Hide all the slides but the first one.
$slides.hide();
$slides.eq(0).show();
$controls.eq(0).addClass('active');
// Bind the event for the slide numbers.
$controls.once('panopoly-spotlight').children('a').bind('click.panopoly-widgets-spotlight', function (event) {
var selector = $(this).attr('href');
if (selector.indexOf('#') === 0) {
event.preventDefault();
// Mark the slide number as active.
$controls.removeClass('active');
$(this).parent().addClass('active');
// Hide all slides but the selected one.
$slides.hide();
$slides.filter(selector).show();
// Start the timer over if it's running.
if (timer !== null) {
stop();
start();
}
return false;
}
});
// Bind events to all the extra buttonts.
$widget.find('.panopoly-spotlight-pause-play').once('panopoly-spotlight').bind('click.panopoly-widgets-spotlight', function(event) {
event.preventDefault();
if ($(this).hasClass('paused')) {
start();
$(this).text(Drupal.t('Pause'));
$(this).removeClass('paused');
}
else {
stop();
$(this).text(Drupal.t('Play'));
$(this).addClass('paused');
}
});
if ($widget.find('.panopoly-spotlight-previous').length && $widget.find('.panopoly-spotlight-next').length) {
$widget.find('.panopoly-spotlight-previous').once('panopoly-spotlight').bind('click.panopoly-widgets-spotlight', function (event) {
event.preventDefault();
$widget.find('.panopoly-spotlight-pause-play:not(.paused)').trigger('click.panopoly-widgets-spotlight');
var activeControl = $($controls.filter('.active'));
if (activeControl.prev().length != 0) {
activeControl.prev().children('a').trigger('click.panopoly-widgets-spotlight');
}
else {
$controls.last().children('a').trigger('click.panopoly-widgets-spotlight');
}
});
$widget.find('.panopoly-spotlight-next').once('panopoly-spotlight').bind('click.panopoly-widgets-spotlight', function (event) {
event.preventDefault();
$widget.find('.panopoly-spotlight-pause-play:not(.paused)').trigger('click.panopoly-widgets-spotlight');
var activeControl = $($controls.filter('.active'));
if (activeControl.next().length != 0) {
activeControl.next().children('a').trigger('click.panopoly-widgets-spotlight');
}
else {
$controls.first().children('a').trigger('click.panopoly-widgets-spotlight');
}
});
}
start();
});
}
}
};
})(jQuery);