comparison sites/all/modules/flexslider_views_slideshow/js/flexslider_views_slideshow.js @ 2:b74b41bb73f0

-- Google analytics module
author danieleb <danielebarchiesi@me.com>
date Thu, 22 Aug 2013 17:22:54 +0100
parents
children
comparison
equal deleted inserted replaced
1:67ce89da90df 2:b74b41bb73f0
1 (function ($) {
2 // @todo convert to use Drupal.behaviors
3 // @todo add configuration options
4
5 // Register callback to save references to flexslider instances. Allows
6 // Views Slideshow controls to affect the slider
7 function flexslider_views_slideshow_register(fullId, slider) {
8 Drupal.flexsliderViewsSlideshow.active = Drupal.flexsliderViewsSlideshow.active || {};
9 Drupal.flexsliderViewsSlideshow.active[fullId] = slider;
10 }
11
12 Drupal.behaviors.flexsliderViewsSlideshow = {
13 attach: function (context) {
14 $('.flexslider_views_slideshow_main:not(.flexslider_views_slideshow-processed)', context).addClass('flexslider_views_slideshow-processed').each(function() {
15 // Get the ID of the slideshow
16 var fullId = '#' + $(this).attr('id');
17
18 // Create settings container
19 var settings = Drupal.settings.flexslider_views_slideshow[fullId];
20
21 //console.log(settings);
22
23 // @todo map the settings from the form to their javascript equivalents
24 settings.targetId = fullId;
25
26 settings.loaded = false;
27
28 // Assign default settings
29 // @todo update the list of options to match the new set
30 settings.opts = {
31 // v2.x options
32 namespace:settings.namespace,
33 selector:settings.selector,
34 easing:settings.easing,
35 direction:settings.direction,
36 reverse:settings.reverse,
37 smoothHeight:settings.smoothHeight,
38 startAt:settings.startAt,
39 animationSpeed:settings.animationSpeed,
40 initDelay:settings.initDelay,
41 useCSS:settings.useCSS,
42 touch:settings.touch,
43 video:settings.video,
44 keyboard:settings.keyboard,
45 multipleKeyboard:settings.multipleKeyboard,
46 mousewheel:settings.mousewheel,
47 controlsContainer:settings.controlsContainer,
48 sync:settings.sync,
49 asNavFor:settings.asNavFor,
50 itemWidth:settings.itemWidth,
51 itemMargin:settings.itemMargin,
52 minItems:settings.minItems,
53 maxItems:settings.maxItems,
54 move:settings.move,
55 // v1.x options
56 animation:settings.animation,
57 slideshow:settings.slideshow,
58 slideshowSpeed:settings.slideshowSpeed,
59 directionNav:settings.directionNav,
60 controlNav:settings.controlNav,
61 prevText:settings.prevText,
62 nextText:settings.nextText,
63 pausePlay:settings.pausePlay,
64 pauseText:settings.pauseText,
65 playText:settings.playText,
66 randomize:settings.randomize,
67 animationLoop:settings.animationLoop,
68 pauseOnAction:settings.pauseOnAction,
69 pauseOnHover:settings.pauseOnHover,
70 manualControls:settings.manualControls,
71 start: function(slider) {
72 flexslider_views_slideshow_register(fullId, slider);
73 }
74 // @todo register other callbacks
75 };
76
77 Drupal.flexsliderViewsSlideshow.load(fullId);
78 });
79 }
80 };
81
82
83 // Initialize the flexslider object
84 Drupal.flexsliderViewsSlideshow = Drupal.flexsliderViewsSlideshow || {};
85
86 // Load mapping from Views Slideshow to FlexSlider
87 Drupal.flexsliderViewsSlideshow.load = function(fullId) {
88 var settings = Drupal.settings.flexslider_views_slideshow[fullId];
89
90 // Ensure the slider isn't already loaded
91 if (!settings.loaded) {
92 $(settings.targetId + " .flexslider").flexslider(settings.opts);
93 settings.loaded = true;
94 }
95 }
96
97 // Pause mapping from Views Slideshow to FlexSlider
98 Drupal.flexsliderViewsSlideshow.pause = function (options) {
99 Drupal.flexsliderViewsSlideshow.active['#flexslider_views_slideshow_main_' + options.slideshowID].pause();
100 Drupal.flexsliderViewsSlideshow.active['#flexslider_views_slideshow_main_' + options.slideshowID].manualPause = true;
101 }
102
103 // Play mapping from Views Slideshow to FlexSlider
104 Drupal.flexsliderViewsSlideshow.play = function (options) {
105 console.log(Drupal.flexsliderViewsSlideshow);
106 Drupal.flexsliderViewsSlideshow.active['#flexslider_views_slideshow_main_' + options.slideshowID].resume();
107 Drupal.flexsliderViewsSlideshow.active['#flexslider_views_slideshow_main_' + options.slideshowID].manualPause = false;
108 }
109
110 Drupal.flexsliderViewsSlideshow.nextSlide = function (options) {
111 var target = Drupal.flexsliderViewsSlideshow.active['#flexslider_views_slideshow_main_' + options.slideshowID].getTarget('next');
112
113 if (Drupal.flexsliderViewsSlideshow.active['#flexslider_views_slideshow_main_' + options.slideshowID].canAdvance(target)) {
114 Drupal.flexsliderViewsSlideshow.active['#flexslider_views_slideshow_main_' + options.slideshowID].flexAnimate(target, Drupal.flexsliderViewsSlideshow.active['#flexslider_views_slideshow_main_' + options.slideshowID].vars.pauseOnAction);
115 }
116 }
117 Drupal.flexsliderViewsSlideshow.previousSlide = function (options) {
118 var target = Drupal.flexsliderViewsSlideshow.active['#flexslider_views_slideshow_main_' + options.slideshowID].getTarget('prev');
119
120 if (Drupal.flexsliderViewsSlideshow.active['#flexslider_views_slideshow_main_' + options.slideshowID].canAdvance(target)) {
121 Drupal.flexsliderViewsSlideshow.active['#flexslider_views_slideshow_main_' + options.slideshowID].flexAnimate(target, Drupal.flexsliderViewsSlideshow.active['#flexslider_views_slideshow_main_' + options.slideshowID].vars.pauseOnAction);
122 }
123 }
124 // @todo add support for jquery mobile page init
125 })(jQuery);