social_stream-events 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/app/assets/javascripts/0_init.js +4 -0
  2. data/app/assets/javascripts/events.js.coffee +66 -0
  3. data/app/assets/stylesheets/events.css.scss +37 -0
  4. data/app/controllers/events_controller.rb +40 -0
  5. data/app/controllers/rooms_controller.rb +7 -0
  6. data/app/models/event.rb +53 -0
  7. data/app/models/room.rb +8 -0
  8. data/app/views/events/_event.html.erb +1 -0
  9. data/app/views/events/_new.html.erb +40 -0
  10. data/app/views/events/_sidebar_calendar.html.erb +26 -0
  11. data/app/views/events/create.js.erb +21 -0
  12. data/app/views/events/destroy.js.erb +1 -0
  13. data/app/views/events/index.html.erb +96 -0
  14. data/app/views/rooms/_form.html.erb +31 -0
  15. data/app/views/rooms/_index.html.erb +10 -0
  16. data/app/views/rooms/_settings.html.erb +23 -0
  17. data/app/views/rooms/create.js.erb +7 -0
  18. data/app/views/rooms/destroy.js.erb +1 -0
  19. data/config/locales/en.yml +34 -4
  20. data/config/locales/es.yml +34 -4
  21. data/config/routes.rb +1 -0
  22. data/db/migrate/20111101193523_create_events.rb +13 -0
  23. data/db/migrate/20111120104349_create_rooms.rb +26 -0
  24. data/db/migrate/20111204155637_add_scheduler.rb +33 -0
  25. data/db/migrate/20111218203314_change_scheduler.rb +11 -0
  26. data/lib/social_stream-events.rb +15 -0
  27. data/lib/social_stream/events/ability.rb +13 -0
  28. data/lib/social_stream/events/engine.rb +17 -0
  29. data/lib/social_stream/events/models/actor.rb +13 -0
  30. data/lib/social_stream/events/version.rb +1 -1
  31. data/lib/social_stream/views/settings/events.rb +18 -0
  32. data/social_stream-events.gemspec +6 -10
  33. data/vendor/assets/images/boxy-ne.png +0 -0
  34. data/vendor/assets/images/boxy-nw.png +0 -0
  35. data/vendor/assets/images/boxy-se.png +0 -0
  36. data/vendor/assets/images/boxy-sw.png +0 -0
  37. data/vendor/assets/javascripts/fullcalendar.js +12 -10
  38. data/vendor/assets/javascripts/gcal.js +2 -2
  39. data/vendor/assets/javascripts/jquery.boxy.js +570 -0
  40. data/vendor/assets/javascripts/sprintf.js +183 -0
  41. data/vendor/assets/stylesheets/boxy.css +49 -0
  42. data/vendor/assets/stylesheets/fullcalendar.css +7 -10
  43. data/vendor/assets/stylesheets/fullcalendar.print.css +4 -4
  44. metadata +81 -175
  45. data/db/migrate/20110910161707_create_social_stream_events.rb +0 -54
  46. data/db/migrate/20111102145626_add_more_fields_to_events.rb +0 -20
  47. data/db/migrate/20111104165944_add_more_fields_to_sessions.rb +0 -13
  48. data/db/migrate/20111104182420_add_details_to_events.rb +0 -18
  49. data/db/migrate/20111209120019_reset_events.rb +0 -18
  50. data/vendor/assets/javascripts/jquery.ad-gallery.js +0 -850
  51. data/vendor/assets/javascripts/jquery.ad-gallery.pack.js +0 -10
  52. data/vendor/assets/stylesheets/ad_next.png +0 -0
  53. data/vendor/assets/stylesheets/ad_prev.png +0 -0
  54. data/vendor/assets/stylesheets/ad_scroll_back.png +0 -0
  55. data/vendor/assets/stylesheets/ad_scroll_forward.png +0 -0
  56. data/vendor/assets/stylesheets/jquery.ad-gallery.css +0 -171
  57. data/vendor/assets/stylesheets/loader.gif +0 -0
  58. data/vendor/assets/stylesheets/social_stream-events.css +0 -273
@@ -1,54 +0,0 @@
1
- class CreateSocialStreamEvents < ActiveRecord::Migration
2
-
3
- def self.up
4
-
5
- create_table :events do |t|
6
- t.references :actor
7
- t.datetime :initDate
8
- t.datetime :endDate
9
- t.integer :founder_id
10
- t.timestamps
11
- end
12
-
13
- create_table :agendas do |t|
14
- t.references :activity_object
15
- t.references :event
16
- t.timestamps
17
- end
18
-
19
- create_table :sessions do |t|
20
- t.references :activity_object
21
- t.references :agenda
22
- t.datetime :initDate
23
- t.datetime :endDate
24
- t.string :title
25
- t.string :description
26
- t.timestamps
27
- end
28
-
29
-
30
- add_foreign_key "agendas", "activity_objects", :name => "agendas_on_activity_object_id"
31
- add_foreign_key "agendas", "events", :name => "agendas_on_event_id"
32
-
33
- add_foreign_key "events", "actors", :name => "events_on_actor_id"
34
-
35
- add_foreign_key "sessions", "activity_objects", :name => "sessions_on_activity_object_id"
36
- add_foreign_key "sessions", "agendas", :name => "sessions_on_agenda_id"
37
-
38
- end
39
-
40
- def self.down
41
- remove_foreign_key "agendas", :name => "agendas_on_activity_object_id"
42
- remove_foreign_key "agendas", :name => "agendas_on_event_id"
43
-
44
- remove_foreign_key "events", :name => "events_on_actor_id"
45
-
46
- remove_foreign_key "sessions", :name => "sessions_on_activity_object_id"
47
- remove_foreign_key "sessions", :name => "sessions_on_agenda_id"
48
-
49
- drop_table :sessions
50
- drop_table :agendas
51
- drop_table :events
52
- end
53
-
54
- end
@@ -1,20 +0,0 @@
1
- class AddMoreFieldsToEvents < ActiveRecord::Migration
2
- def change
3
- add_column :events, :description, :string
4
- add_column :events, :place, :string
5
- add_column :events, :isabel_event, :string
6
- add_column :events, :machine_id, :integer
7
- add_column :events, :repeat, :string
8
- add_column :events, :at_job, :integer
9
- add_column :events, :parent_id, :integer
10
- add_column :events, :character, :integer
11
- add_column :events, :public_read, :integer
12
- add_column :events, :marte_room, :integer
13
- add_column :events, :notes, :integer
14
- add_column :events, :location, :text
15
- add_column :events, :streamming_url, :text
16
- add_column :events, :permalink, :string
17
- add_column :events, :cm_event_id, :integer
18
- add_column :events, :other_participation_url, :text
19
- end
20
- end
@@ -1,13 +0,0 @@
1
- class AddMoreFieldsToSessions < ActiveRecord::Migration
2
-
3
- def change
4
- add_column :sessions, :speakers, :string
5
- add_column :sessions, :embedded_video, :text
6
- add_column :sessions, :video_thumbnail, :text
7
- add_column :sessions, :uid, :text
8
- add_column :sessions, :cm_session_id, :integer
9
- add_column :sessions, :cm_streaming, :boolean, :default => false
10
- add_column :sessions, :cm_recording, :boolean, :default => false
11
- end
12
-
13
- end
@@ -1,18 +0,0 @@
1
- class AddDetailsToEvents < ActiveRecord::Migration
2
-
3
- def change
4
- add_column :events, :marte_event, :boolean, :default => false
5
- add_column :events, :spam, :boolean, :default => false
6
- add_column :events, :vc_mode, :integer , :default => 0
7
- add_column :events, :web_interface, :string, :default => false
8
- add_column :events, :isabel_interface, :string, :default => false
9
- add_column :events, :sip_interface, :string, :default => false
10
- add_column :events, :streaming_by_default, :string, :default => true
11
- add_column :events, :manual_configuration, :string, :default => false
12
- add_column :events, :recording_type, :string, :default => 0
13
-
14
- add_column :events, :isabel_bw, :text
15
- add_column :events, :web_bw, :integer
16
- add_column :events, :recording_bw, :integer
17
- end
18
- end
@@ -1,18 +0,0 @@
1
- class ResetEvents < ActiveRecord::Migration
2
- def up
3
- remove_foreign_key "agendas", :name => "agendas_on_activity_object_id"
4
- remove_foreign_key "agendas", :name => "agendas_on_event_id"
5
-
6
- remove_foreign_key "events", :name => "events_on_actor_id"
7
-
8
- remove_foreign_key "sessions", :name => "sessions_on_activity_object_id"
9
- remove_foreign_key "sessions", :name => "sessions_on_agenda_id"
10
-
11
- drop_table :sessions
12
- drop_table :agendas
13
- drop_table :events
14
- end
15
-
16
- def down
17
- end
18
- end
@@ -1,850 +0,0 @@
1
- /**
2
- * Copyright (c) 2010 Anders Ekdahl (http://coffeescripter.com/)
3
- * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
4
- * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
5
- *
6
- * Version: 1.2.4
7
- *
8
- * Demo and documentation: http://coffeescripter.com/code/ad-gallery/
9
- */
10
- (function($) {
11
- $.fn.adGallery = function(options) {
12
- var defaults = { loader_image: 'loader.gif',
13
- initDate_index: 0,
14
- description_wrapper: false,
15
- thumb_opacity: 0.7,
16
- animate_first_image: false,
17
- animation_speed: 400,
18
- width: false,
19
- height: false,
20
- display_next_and_prev: true,
21
- display_back_and_forward: true,
22
- scroll_jump: 0, // If 0, it jumps the width of the container
23
- slideshow: {
24
- enable: true,
25
- autostart: false,
26
- speed: 5000,
27
- start_label: 'Start',
28
- stop_label: 'Stop',
29
- stop_on_scroll: true,
30
- countdown_prefix: '(',
31
- countdown_sufix: ')',
32
- onStart: false,
33
- onStop: false
34
- },
35
- effect: 'slide-hori', // or 'slide-vert', 'fade', or 'resize', 'none'
36
- enable_keyboard_move: true,
37
- cycle: true,
38
- callbacks: {
39
- init: false,
40
- afterImageVisible: false,
41
- beforeImageVisible: false
42
- }
43
- };
44
- var settings = $.extend(false, defaults, options);
45
- if(options && options.slideshow) {
46
- settings.slideshow = $.extend(false, defaults.slideshow, options.slideshow);
47
- };
48
- if(!settings.slideshow.enable) {
49
- settings.slideshow.autostart = false;
50
- };
51
- var galleries = [];
52
- $(this).each(function() {
53
- var gallery = new AdGallery(this, settings);
54
- galleries[galleries.length] = gallery;
55
- });
56
- // Sorry, breaking the jQuery chain because the gallery instances
57
- // are returned so you can fiddle with them
58
- return galleries;
59
- };
60
-
61
- function VerticalSlideAnimation(img_container, direction, desc) {
62
- var current_top = parseInt(img_container.css('top'), 10);
63
- if(direction == 'left') {
64
- var old_image_top = '-'+ this.image_wrapper_height +'px';
65
- img_container.css('top', this.image_wrapper_height +'px');
66
- } else {
67
- var old_image_top = this.image_wrapper_height +'px';
68
- img_container.css('top', '-'+ this.image_wrapper_height +'px');
69
- };
70
- if(desc) {
71
- desc.css('bottom', '-'+ desc[0].offsetHeight +'px');
72
- desc.animate({bottom: 0}, this.settings.animation_speed * 2);
73
- };
74
- if(this.current_description) {
75
- this.current_description.animate({bottom: '-'+ this.current_description[0].offsetHeight +'px'}, this.settings.animation_speed * 2);
76
- };
77
- return {old_image: {top: old_image_top},
78
- new_image: {top: current_top}};
79
- };
80
-
81
- function HorizontalSlideAnimation(img_container, direction, desc) {
82
- var current_left = parseInt(img_container.css('left'), 10);
83
- if(direction == 'left') {
84
- var old_image_left = '-'+ this.image_wrapper_width +'px';
85
- img_container.css('left',this.image_wrapper_width +'px');
86
- } else {
87
- var old_image_left = this.image_wrapper_width +'px';
88
- img_container.css('left','-'+ this.image_wrapper_width +'px');
89
- };
90
- if(desc) {
91
- desc.css('bottom', '-'+ desc[0].offsetHeight +'px');
92
- desc.animate({bottom: 0}, this.settings.animation_speed * 2);
93
- };
94
- if(this.current_description) {
95
- this.current_description.animate({bottom: '-'+ this.current_description[0].offsetHeight +'px'}, this.settings.animation_speed * 2);
96
- };
97
- return {old_image: {left: old_image_left},
98
- new_image: {left: current_left}};
99
- };
100
-
101
- function ResizeAnimation(img_container, direction, desc) {
102
- var image_width = img_container.width();
103
- var image_height = img_container.height();
104
- var current_left = parseInt(img_container.css('left'), 10);
105
- var current_top = parseInt(img_container.css('top'), 10);
106
- img_container.css({width: 0, height: 0, top: this.image_wrapper_height / 2, left: this.image_wrapper_width / 2});
107
- return {old_image: {width: 0,
108
- height: 0,
109
- top: this.image_wrapper_height / 2,
110
- left: this.image_wrapper_width / 2},
111
- new_image: {width: image_width,
112
- height: image_height,
113
- top: current_top,
114
- left: current_left}};
115
- };
116
-
117
- function FadeAnimation(img_container, direction, desc) {
118
- img_container.css('opacity', 0);
119
- return {old_image: {opacity: 0},
120
- new_image: {opacity: 1}};
121
- };
122
-
123
- // Sort of a hack, will clean this up... eventually
124
- function NoneAnimation(img_container, direction, desc) {
125
- img_container.css('opacity', 0);
126
- return {old_image: {opacity: 0},
127
- new_image: {opacity: 1},
128
- speed: 0};
129
- };
130
-
131
- function AdGallery(wrapper, settings) {
132
- this.init(wrapper, settings);
133
- };
134
- AdGallery.prototype = {
135
- // Elements
136
- wrapper: false,
137
- image_wrapper: false,
138
- gallery_info: false,
139
- nav: false,
140
- loader: false,
141
- preloads: false,
142
- thumbs_wrapper: false,
143
- scroll_back: false,
144
- scroll_forward: false,
145
- next_link: false,
146
- prev_link: false,
147
-
148
- slideshow: false,
149
- image_wrapper_width: 0,
150
- image_wrapper_height: 0,
151
- current_index: 0,
152
- current_image: false,
153
- current_description: false,
154
- nav_display_width: 0,
155
- settings: false,
156
- images: false,
157
- in_transition: false,
158
- animations: false,
159
- init: function(wrapper, settings) {
160
- var context = this;
161
- this.wrapper = $(wrapper);
162
- this.settings = settings;
163
- this.setupElements();
164
- this.setupAnimations();
165
- if(this.settings.width) {
166
- this.image_wrapper_width = this.settings.width;
167
- this.image_wrapper.width(this.settings.width);
168
- this.wrapper.width(this.settings.width);
169
- } else {
170
- this.image_wrapper_width = this.image_wrapper.width();
171
- };
172
- if(this.settings.height) {
173
- this.image_wrapper_height = this.settings.height;
174
- this.image_wrapper.height(this.settings.height);
175
- } else {
176
- this.image_wrapper_height = this.image_wrapper.height();
177
- };
178
- this.nav_display_width = this.nav.width();
179
- this.current_index = 0;
180
- this.current_image = false;
181
- this.current_description = false;
182
- this.in_transition = false;
183
- this.findImages();
184
- if(this.settings.display_next_and_prev) {
185
- this.initNextAndPrev();
186
- };
187
- // The slideshow needs a callback to trigger the next image to be shown
188
- // but we don't want to give it access to the whole gallery instance
189
- var nextimage_callback = function(callback) {
190
- return context.nextImage(callback);
191
- };
192
- this.slideshow = new AdGallerySlideshow(nextimage_callback, this.settings.slideshow);
193
- this.controls.append(this.slideshow.create());
194
- if(this.settings.slideshow.enable) {
195
- this.slideshow.enable();
196
- } else {
197
- this.slideshow.disable();
198
- };
199
- if(this.settings.display_back_and_forward) {
200
- this.initBackAndForward();
201
- };
202
- if(this.settings.enable_keyboard_move) {
203
- this.initKeyEvents();
204
- };
205
- var initDate = parseInt(this.settings.initDate_index, 10);
206
- if(window.location.hash && window.location.hash.indexOf('#ad-image') === 0) {
207
- initDate = window.location.hash.replace(/[^0-9]+/g, '');
208
- // Check if it's a number
209
- if((initDate * 1) != initDate) {
210
- initDate = this.settings.initDate_index;
211
- };
212
- };
213
-
214
- this.loading(true);
215
- this.showImage(initDate,
216
- function() {
217
- // We don't want to start the slideshow before the image has been
218
- // displayed
219
- if(context.settings.slideshow.autostart) {
220
- context.preloadImage(initDate + 1);
221
- context.slideshow.start();
222
- };
223
- }
224
- );
225
- this.fireCallback(this.settings.callbacks.init);
226
- },
227
- setupAnimations: function() {
228
- this.animations = {
229
- 'slide-vert': VerticalSlideAnimation,
230
- 'slide-hori': HorizontalSlideAnimation,
231
- 'resize': ResizeAnimation,
232
- 'fade': FadeAnimation,
233
- 'none': NoneAnimation
234
- };
235
- },
236
- setupElements: function() {
237
- this.controls = this.wrapper.find('.ad-controls');
238
- this.gallery_info = $('<p class="ad-info"></p>');
239
- this.controls.append(this.gallery_info);
240
- this.image_wrapper = this.wrapper.find('.ad-image-wrapper');
241
- this.image_wrapper.empty();
242
- this.nav = this.wrapper.find('.ad-nav');
243
- this.thumbs_wrapper = this.nav.find('.ad-thumbs');
244
- this.preloads = $('<div class="ad-preloads"></div>');
245
- this.loader = $('<img class="ad-loader" src="'+ this.settings.loader_image +'">');
246
- this.image_wrapper.append(this.loader);
247
- this.loader.hide();
248
- $(document.body).append(this.preloads);
249
- },
250
- loading: function(bool) {
251
- if(bool) {
252
- this.loader.show();
253
- } else {
254
- this.loader.hide();
255
- };
256
- },
257
- addAnimation: function(name, fn) {
258
- if($.isFunction(fn)) {
259
- this.animations[name] = fn;
260
- };
261
- },
262
- findImages: function() {
263
- var context = this;
264
- this.images = [];
265
- var thumb_wrapper_width = 0;
266
- var thumbs_loaded = 0;
267
- var thumbs = this.thumbs_wrapper.find('a');
268
- var thumb_count = thumbs.length;
269
- if(this.settings.thumb_opacity < 1) {
270
- thumbs.find('img').css('opacity', this.settings.thumb_opacity);
271
- };
272
- thumbs.each(
273
- function(i) {
274
- var link = $(this);
275
- var image_src = link.attr('href');
276
- var thumb = link.find('img');
277
- // Check if the thumb has already loaded
278
- if(!context.isImageLoaded(thumb[0])) {
279
- thumb.load(
280
- function() {
281
- thumb_wrapper_width += this.parentNode.parentNode.offsetWidth;
282
- thumbs_loaded++;
283
- }
284
- );
285
- } else{
286
- thumb_wrapper_width += thumb[0].parentNode.parentNode.offsetWidth;
287
- thumbs_loaded++;
288
- };
289
- link.addClass('ad-thumb'+ i);
290
- link.click(
291
- function() {
292
- context.showImage(i);
293
- context.slideshow.stop();
294
- return false;
295
- }
296
- ).hover(
297
- function() {
298
- if(!$(this).is('.ad-active') && context.settings.thumb_opacity < 1) {
299
- $(this).find('img').fadeTo(300, 1);
300
- };
301
- context.preloadImage(i);
302
- },
303
- function() {
304
- if(!$(this).is('.ad-active') && context.settings.thumb_opacity < 1) {
305
- $(this).find('img').fadeTo(300, context.settings.thumb_opacity);
306
- };
307
- }
308
- );
309
- var link = false;
310
- if(thumb.data('ad-link')) {
311
- link = thumb.data('ad-link');
312
- } else if(thumb.attr('longdesc') && thumb.attr('longdesc').length) {
313
- link = thumb.attr('longdesc');
314
- };
315
- var desc = false;
316
- if(thumb.data('ad-desc')) {
317
- desc = thumb.data('ad-desc');
318
- } else if(thumb.attr('alt') && thumb.attr('alt').length) {
319
- desc = thumb.attr('alt');
320
- };
321
- var title = false;
322
- if(thumb.data('ad-title')) {
323
- title = thumb.data('ad-title');
324
- } else if(thumb.attr('title') && thumb.attr('title').length) {
325
- title = thumb.attr('title');
326
- };
327
- context.images[i] = { thumb: thumb.attr('src'), image: image_src, error: false,
328
- preloaded: false, desc: desc, title: title, size: false,
329
- link: link };
330
- }
331
- );
332
- // Wait until all thumbs are loaded, and then set the width of the ul
333
- var inter = setInterval(
334
- function() {
335
- if(thumb_count == thumbs_loaded) {
336
- thumb_wrapper_width -= 100;
337
- var list = context.nav.find('.ad-thumb-list');
338
- list.css('width', thumb_wrapper_width +'px');
339
- var i = 1;
340
- var last_height = list.height();
341
- while(i < 201) {
342
- list.css('width', (thumb_wrapper_width + i) +'px');
343
- if(last_height != list.height()) {
344
- break;
345
- }
346
- last_height = list.height();
347
- i++;
348
- }
349
- clearInterval(inter);
350
- };
351
- },
352
- 100
353
- );
354
- },
355
- initKeyEvents: function() {
356
- var context = this;
357
- $(document).keydown(
358
- function(e) {
359
- if(e.keyCode == 39) {
360
- // right arrow
361
- context.nextImage();
362
- context.slideshow.stop();
363
- } else if(e.keyCode == 37) {
364
- // left arrow
365
- context.prevImage();
366
- context.slideshow.stop();
367
- };
368
- }
369
- );
370
- },
371
- initNextAndPrev: function() {
372
- this.next_link = $('<div class="ad-next"><div class="ad-next-image"></div></div>');
373
- this.prev_link = $('<div class="ad-prev"><div class="ad-prev-image"></div></div>');
374
- this.image_wrapper.append(this.next_link);
375
- this.image_wrapper.append(this.prev_link);
376
- var context = this;
377
- this.prev_link.add(this.next_link).mouseover(
378
- function(e) {
379
- // IE 6 hides the wrapper div, so we have to set it's width
380
- $(this).css('height', context.image_wrapper_height);
381
- $(this).find('div').show();
382
- }
383
- ).mouseout(
384
- function(e) {
385
- $(this).find('div').hide();
386
- }
387
- ).click(
388
- function() {
389
- if($(this).is('.ad-next')) {
390
- context.nextImage();
391
- context.slideshow.stop();
392
- } else {
393
- context.prevImage();
394
- context.slideshow.stop();
395
- };
396
- }
397
- ).find('div').css('opacity', 0.7);
398
- },
399
- initBackAndForward: function() {
400
- var context = this;
401
- this.scroll_forward = $('<div class="ad-forward"></div>');
402
- this.scroll_back = $('<div class="ad-back"></div>');
403
- this.nav.append(this.scroll_forward);
404
- this.nav.prepend(this.scroll_back);
405
- var has_scrolled = 0;
406
- var thumbs_scroll_interval = false;
407
- $(this.scroll_back).add(this.scroll_forward).click(
408
- function() {
409
- // We don't want to jump the whole width, since an image
410
- // might be cut at the edge
411
- var width = context.nav_display_width - 50;
412
- if(context.settings.scroll_jump > 0) {
413
- var width = context.settings.scroll_jump;
414
- };
415
- if($(this).is('.ad-forward')) {
416
- var left = context.thumbs_wrapper.scrollLeft() + width;
417
- } else {
418
- var left = context.thumbs_wrapper.scrollLeft() - width;
419
- };
420
- if(context.settings.slideshow.stop_on_scroll) {
421
- context.slideshow.stop();
422
- };
423
- context.thumbs_wrapper.animate({scrollLeft: left +'px'});
424
- return false;
425
- }
426
- ).css('opacity', 0.6).hover(
427
- function() {
428
- var direction = 'left';
429
- if($(this).is('.ad-forward')) {
430
- direction = 'right';
431
- };
432
- thumbs_scroll_interval = setInterval(
433
- function() {
434
- has_scrolled++;
435
- // Don't want to stop the slideshow just because we scrolled a pixel or two
436
- if(has_scrolled > 30 && context.settings.slideshow.stop_on_scroll) {
437
- context.slideshow.stop();
438
- };
439
- var left = context.thumbs_wrapper.scrollLeft() + 1;
440
- if(direction == 'left') {
441
- left = context.thumbs_wrapper.scrollLeft() - 1;
442
- };
443
- context.thumbs_wrapper.scrollLeft(left);
444
- },
445
- 10
446
- );
447
- $(this).css('opacity', 1);
448
- },
449
- function() {
450
- has_scrolled = 0;
451
- clearInterval(thumbs_scroll_interval);
452
- $(this).css('opacity', 0.6);
453
- }
454
- );
455
- },
456
- _afterShow: function() {
457
- this.gallery_info.html((this.current_index + 1) +' / '+ this.images.length);
458
- if(!this.settings.cycle) {
459
- // Needed for IE
460
- this.prev_link.show().css('height', this.image_wrapper_height);
461
- this.next_link.show().css('height', this.image_wrapper_height);
462
- if(this.current_index == (this.images.length - 1)) {
463
- this.next_link.hide();
464
- };
465
- if(this.current_index == 0) {
466
- this.prev_link.hide();
467
- };
468
- };
469
- this.fireCallback(this.settings.callbacks.afterImageVisible);
470
- },
471
- /**
472
- * Checks if the image is small enough to fit inside the container
473
- * If it's not, shrink it proportionally
474
- */
475
- _getContainedImageSize: function(image_width, image_height) {
476
- if(image_height > this.image_wrapper_height) {
477
- var ratio = image_width / image_height;
478
- image_height = this.image_wrapper_height;
479
- image_width = this.image_wrapper_height * ratio;
480
- };
481
- if(image_width > this.image_wrapper_width) {
482
- var ratio = image_height / image_width;
483
- image_width = this.image_wrapper_width;
484
- image_height = this.image_wrapper_width * ratio;
485
- };
486
- return {width: image_width, height: image_height};
487
- },
488
- /**
489
- * If the image dimensions are smaller than the wrapper, we position
490
- * it in the middle anyway
491
- */
492
- _centerImage: function(img_container, image_width, image_height) {
493
- img_container.css('top', '0px');
494
- if(image_height < this.image_wrapper_height) {
495
- var dif = this.image_wrapper_height - image_height;
496
- img_container.css('top', (dif / 2) +'px');
497
- };
498
- img_container.css('left', '0px');
499
- if(image_width < this.image_wrapper_width) {
500
- var dif = this.image_wrapper_width - image_width;
501
- img_container.css('left', (dif / 2) +'px');
502
- };
503
- },
504
- _getDescription: function(image) {
505
- var desc = false;
506
- if(image.desc.length || image.title.length) {
507
- var title = '';
508
- if(image.title.length) {
509
- title = '<strong class="ad-description-title">'+ image.title +'</strong>';
510
- };
511
- var desc = '';
512
- if(image.desc.length) {
513
- desc = '<span>'+ image.desc +'</span>';
514
- };
515
- desc = $('<p class="ad-image-description">'+ title + desc +'</p>');
516
- };
517
- return desc;
518
- },
519
- /**
520
- * @param function callback Gets fired when the image has loaded, is displaying
521
- * and it's animation has finished
522
- */
523
- showImage: function(index, callback) {
524
- if(this.images[index] && !this.in_transition) {
525
- var context = this;
526
- var image = this.images[index];
527
- this.in_transition = true;
528
- if(!image.preloaded) {
529
- this.loading(true);
530
- this.preloadImage(index, function() {
531
- context.loading(false);
532
- context._showWhenLoaded(index, callback);
533
- });
534
- } else {
535
- this._showWhenLoaded(index, callback);
536
- };
537
- };
538
- },
539
- /**
540
- * @param function callback Gets fired when the image has loaded, is displaying
541
- * and it's animation has finished
542
- */
543
- _showWhenLoaded: function(index, callback) {
544
- if(this.images[index]) {
545
- var context = this;
546
- var image = this.images[index];
547
- var img_container = $(document.createElement('div')).addClass('ad-image');
548
- var img = $(new Image()).attr('src', image.image);
549
- if(image.link) {
550
- var link = $('<a href="'+ image.link +'" target="_blank"></a>');
551
- link.append(img);
552
- img_container.append(link);
553
- } else {
554
- img_container.append(img);
555
- }
556
- this.image_wrapper.prepend(img_container);
557
- var size = this._getContainedImageSize(image.size.width, image.size.height);
558
- img.attr('width', size.width);
559
- img.attr('height', size.height);
560
- img_container.css({width: size.width +'px', height: size.height +'px'});
561
- this._centerImage(img_container, size.width, size.height);
562
- var desc = this._getDescription(image, img_container);
563
- if(desc) {
564
- if(!this.settings.description_wrapper) {
565
- img_container.append(desc);
566
- var width = size.width - parseInt(desc.css('padding-left'), 10) - parseInt(desc.css('padding-right'), 10);
567
- desc.css('width', width +'px');
568
- } else {
569
- this.settings.description_wrapper.append(desc);
570
- }
571
- };
572
- this.highLightThumb(this.nav.find('.ad-thumb'+ index));
573
-
574
- var direction = 'right';
575
- if(this.current_index < index) {
576
- direction = 'left';
577
- };
578
- this.fireCallback(this.settings.callbacks.beforeImageVisible);
579
- if(this.current_image || this.settings.animate_first_image) {
580
- var animation_speed = this.settings.animation_speed;
581
- var easing = 'swing';
582
- var animation = this.animations[this.settings.effect].call(this, img_container, direction, desc);
583
- if(typeof animation.speed != 'undefined') {
584
- animation_speed = animation.speed;
585
- };
586
- if(typeof animation.easing != 'undefined') {
587
- easing = animation.easing;
588
- };
589
- if(this.current_image) {
590
- var old_image = this.current_image;
591
- var old_description = this.current_description;
592
- old_image.animate(animation.old_image, animation_speed, easing,
593
- function() {
594
- old_image.remove();
595
- if(old_description) old_description.remove();
596
- }
597
- );
598
- };
599
- img_container.animate(animation.new_image, animation_speed, easing,
600
- function() {
601
- context.current_index = index;
602
- context.current_image = img_container;
603
- context.current_description = desc;
604
- context.in_transition = false;
605
- context._afterShow();
606
- context.fireCallback(callback);
607
- }
608
- );
609
- } else {
610
- this.current_index = index;
611
- this.current_image = img_container;
612
- context.current_description = desc;
613
- this.in_transition = false;
614
- context._afterShow();
615
- this.fireCallback(callback);
616
- };
617
- };
618
- },
619
- nextIndex: function() {
620
- if(this.current_index == (this.images.length - 1)) {
621
- if(!this.settings.cycle) {
622
- return false;
623
- };
624
- var next = 0;
625
- } else {
626
- var next = this.current_index + 1;
627
- };
628
- return next;
629
- },
630
- nextImage: function(callback) {
631
- var next = this.nextIndex();
632
- if(next === false) return false;
633
- this.preloadImage(next + 1);
634
- this.showImage(next, callback);
635
- return true;
636
- },
637
- prevIndex: function() {
638
- if(this.current_index == 0) {
639
- if(!this.settings.cycle) {
640
- return false;
641
- };
642
- var prev = this.images.length - 1;
643
- } else {
644
- var prev = this.current_index - 1;
645
- };
646
- return prev;
647
- },
648
- prevImage: function(callback) {
649
- var prev = this.prevIndex();
650
- if(prev === false) return false;
651
- this.preloadImage(prev - 1);
652
- this.showImage(prev, callback);
653
- return true;
654
- },
655
- preloadAll: function() {
656
- var context = this;
657
- var i = 0;
658
- function preloadNext() {
659
- if(i < context.images.length) {
660
- i++;
661
- context.preloadImage(i, preloadNext);
662
- };
663
- };
664
- context.preloadImage(i, preloadNext);
665
- },
666
- preloadImage: function(index, callback) {
667
- if(this.images[index]) {
668
- var image = this.images[index];
669
- if(!this.images[index].preloaded) {
670
- var img = $(new Image());
671
- img.attr('src', image.image);
672
- if(!this.isImageLoaded(img[0])) {
673
- this.preloads.append(img);
674
- var context = this;
675
- img.load(
676
- function() {
677
- image.preloaded = true;
678
- image.size = { width: this.width, height: this.height };
679
- context.fireCallback(callback);
680
- }
681
- ).error(
682
- function() {
683
- image.error = true;
684
- image.preloaded = false;
685
- image.size = false;
686
- }
687
- );
688
- } else {
689
- image.preloaded = true;
690
- image.size = { width: img[0].width, height: img[0].height };
691
- this.fireCallback(callback);
692
- };
693
- } else {
694
- this.fireCallback(callback);
695
- };
696
- };
697
- },
698
- isImageLoaded: function(img) {
699
- if(typeof img.complete != 'undefined' && !img.complete) {
700
- return false;
701
- };
702
- if(typeof img.naturalWidth != 'undefined' && img.naturalWidth == 0) {
703
- return false;
704
- };
705
- return true;
706
- },
707
- highLightThumb: function(thumb) {
708
- this.thumbs_wrapper.find('.ad-active').removeClass('ad-active');
709
- thumb.addClass('ad-active');
710
- if(this.settings.thumb_opacity < 1) {
711
- this.thumbs_wrapper.find('a:not(.ad-active) img').fadeTo(300, this.settings.thumb_opacity);
712
- thumb.find('img').fadeTo(300, 1);
713
- };
714
- var left = thumb[0].parentNode.offsetLeft;
715
- left -= (this.nav_display_width / 2) - (thumb[0].offsetWidth / 2);
716
- this.thumbs_wrapper.animate({scrollLeft: left +'px'});
717
- },
718
- fireCallback: function(fn) {
719
- if($.isFunction(fn)) {
720
- fn.call(this);
721
- };
722
- }
723
- };
724
-
725
- function AdGallerySlideshow(nextimage_callback, settings) {
726
- this.init(nextimage_callback, settings);
727
- };
728
- AdGallerySlideshow.prototype = {
729
- start_link: false,
730
- stop_link: false,
731
- countdown: false,
732
- controls: false,
733
-
734
- settings: false,
735
- nextimage_callback: false,
736
- enabled: false,
737
- running: false,
738
- countdown_interval: false,
739
- init: function(nextimage_callback, settings) {
740
- var context = this;
741
- this.nextimage_callback = nextimage_callback;
742
- this.settings = settings;
743
- },
744
- create: function() {
745
- this.start_link = $('<span class="ad-slideshow-start">'+ this.settings.start_label +'</span>');
746
- this.stop_link = $('<span class="ad-slideshow-stop">'+ this.settings.stop_label +'</span>');
747
- this.countdown = $('<span class="ad-slideshow-countdown"></span>');
748
- this.controls = $('<div class="ad-slideshow-controls"></div>');
749
- this.controls.append(this.start_link).append(this.stop_link).append(this.countdown);
750
- this.countdown.hide();
751
-
752
- var context = this;
753
- this.start_link.click(
754
- function() {
755
- context.start();
756
- }
757
- );
758
- this.stop_link.click(
759
- function() {
760
- context.stop();
761
- }
762
- );
763
- $(document).keydown(
764
- function(e) {
765
- if(e.keyCode == 83) {
766
- // 's'
767
- if(context.running) {
768
- context.stop();
769
- } else {
770
- context.start();
771
- };
772
- };
773
- }
774
- );
775
- return this.controls;
776
- },
777
- disable: function() {
778
- this.enabled = false;
779
- this.stop();
780
- this.controls.hide();
781
- },
782
- enable: function() {
783
- this.enabled = true;
784
- this.controls.show();
785
- },
786
- toggle: function() {
787
- if(this.enabled) {
788
- this.disable();
789
- } else {
790
- this.enable();
791
- };
792
- },
793
- start: function() {
794
- if(this.running || !this.enabled) return false;
795
- var context = this;
796
- this.running = true;
797
- this.controls.addClass('ad-slideshow-running');
798
- this._next();
799
- this.fireCallback(this.settings.onStart);
800
- return true;
801
- },
802
- stop: function() {
803
- if(!this.running) return false;
804
- this.running = false;
805
- this.countdown.hide();
806
- this.controls.removeClass('ad-slideshow-running');
807
- clearInterval(this.countdown_interval);
808
- this.fireCallback(this.settings.onStop);
809
- return true;
810
- },
811
- _next: function() {
812
- var context = this;
813
- var pre = this.settings.countdown_prefix;
814
- var su = this.settings.countdown_sufix;
815
- clearInterval(context.countdown_interval);
816
- this.countdown.show().html(pre + (this.settings.speed / 1000) + su);
817
- var slide_timer = 0;
818
- this.countdown_interval = setInterval(
819
- function() {
820
- slide_timer += 1000;
821
- if(slide_timer >= context.settings.speed) {
822
- var whenNextIsShown = function() {
823
- // A check so the user hasn't stoped the slideshow during the
824
- // animation
825
- if(context.running) {
826
- context._next();
827
- };
828
- slide_timer = 0;
829
- };
830
- if(!context.nextimage_callback(whenNextIsShown)) {
831
- context.stop();
832
- };
833
- slide_timer = 0;
834
- };
835
- var sec = parseInt(context.countdown.text().replace(/[^0-9]/g, ''), 10);
836
- sec--;
837
- if(sec > 0) {
838
- context.countdown.html(pre + sec + su);
839
- };
840
- },
841
- 1000
842
- );
843
- },
844
- fireCallback: function(fn) {
845
- if($.isFunction(fn)) {
846
- fn.call(this);
847
- };
848
- }
849
- };
850
- })(jQuery);