-
Notifications
You must be signed in to change notification settings - Fork 210
/
jquery.reel.js
2821 lines (2585 loc) · 122 KB
/
jquery.reel.js
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@ @@@@@@@@
@@@@@@@ @@@@@@@
@@@@@@@ @@@@@@@
@@@@@@@ @@@@@@@
@@@@@@@@ @ @@@@@@@@
@@@@@@@@@ @@@ @@@@@@@@@
@@@@@@@@@@@@@@ @@@@@@@@@@@
@@@@@@@@@@@@@ @@@@@@@
@@@@@@@@@@@@ @@@
@@@@@@
@@@@
@@
*
* jQuery Reel
* ===========
* The 360° plugin for jQuery
*
* @license Copyright (c) 2009-2013 Petr Vostrel (http://petr.vostrel.cz/)
* Licensed under the MIT License (LICENSE.txt).
*
* jQuery Reel
* http://reel360.org
* Version: 1.3.0
* Updated: 2013-11-04
*
* Requires jQuery 1.6.2 or higher
*/
/*
* CDN
* ---
* - http://code.vostrel.net/jquery.reel-bundle.js (recommended)
* - http://code.vostrel.net/jquery.reel.js
* - http://code.vostrel.net/jquery.reel-debug.js
* - or http://code.vostrel.net/jquery.reel-edge.js if you feel like it ;)
*
* Optional Plugins
* ----------------
* - jQuery.mouseWheel [B] (Brandon Aaron, http://plugins.jquery.com/project/mousewheel)
* - or jQuery.event.special.wheel (Three Dub Media, http://blog.threedubmedia.com/2008/08/eventspecialwheel.html)
*
* [B] Marked plugins are contained (with permissions) in the "bundle" version from the CDN
*/
(function(factory){
// -----------------------
// [NEW] AMD Compatibility
// -----------------------
//
// Reel registers as an asynchronous module with dependency on jQuery for [AMD][1] compatible script loaders.
// Besides that it also complies with [CommonJS][2] module definition for Node and such.
// Of course, no fancy script loader is necessary and good old plain script tag still works too.
//
// [1]:http://en.wikipedia.org/wiki/Asynchronous_module_definition
// [2]:http://en.wikipedia.org/wiki/CommonJS
//
var
amd= typeof define == 'function' && define.amd && (define(['jquery'], factory) || true),
commonjs= !amd && typeof module == 'object' && typeof module.exports == 'object' && (module.exports= factory),
plain= !amd && !commonjs && factory()
})(function(){ return jQuery.reel || (function($, window, document, undefined){
// ------
// jQuery
// ------
//
// One vital requirement is the correct jQuery. Reel requires at least version 1.6.2
// and a make sure check is made at the very beginning.
//
if (!$) return;
var
version= $ && $().jquery.split(/\./)
if (!version || +(twochar(version[0])+twochar(version[1])+twochar(version[2] || '')) < 10602)
return error('Too old jQuery library. Please upgrade your jQuery to version 1.6.2 or higher');
// ----------------
// Global Namespace
// ----------------
//
// `$.reel` (or `jQuery.reel`) namespace is provided for storage of all Reel belongings.
// It is locally referenced as just `reel` for speedier access.
//
var
reel= $.reel= {
// ### `$.reel.version`
//
// `String` (major.minor.patch), since 1.1
//
version: '1.3.0',
// Options
// -------
//
// When calling `.reel()` method you have plenty of options (far too many) available.
// You collect them into one hash and supply them with your call.
//
// _**Example:** Initiate a non-looping Reel with 12 frames:_
//
// .reel({
// frames: 12,
// looping: false
// })
//
//
// All options are optional and if omitted, default value is used instead.
// Defaults are being housed as members of `$.reel.def` hash.
// If you customize any default value therein, all subsequent `.reel()` calls
// will use the new value as default.
//
// _**Example:** Change default initial frame to 5th:_
//
// $.reel.def.frame = 5
//
// ---
// ### `$.reel.def` ######
// `Object`, since 1.1
//
def: {
//
// ### Basic Definition ######
//
// Reel is just fine with you not setting any options, however if you don't have
// 36 frames or beginning at frame 1, you will want to set total number
// of `frames` and pick a different starting `frame`.
//
// ---
// #### `frame` Option ####
// `Number` (frames), since 1.0
//
frame: 1,
// #### `frames` Option ####
// `Number` (frames), since 1.0
//
frames: 36,
// ~~~
//
// Another common characteristics of any Reel is whether it `loops` and covers
// entire 360° or not.
//
// ---
// #### `loops` Option ####
// `Boolean`, since 1.0
//
loops: true,
// ### Interaction ######
//
// Using boolean switches many user interaction aspects can be turned on and off.
// You can disable the mouse wheel control with `wheelable`, the drag & throw
// action with `throwable`, disallow the dragging completely with `draggable`,
// on touch devices you can disable the browser's decision to scroll the page
// instead of Reel script and you can of course disable the stepping of Reel by
// clicking on either half of the image with `steppable`.
//
// You can even enable `clickfree` operation,
// which will cause Reel to bind to mouse enter/leave events instead of mouse down/up,
// thus allowing a click-free dragging.
//
// ---
// #### `clickfree` Option ####
// `Boolean`, since 1.1
//
clickfree: false,
// #### `draggable` Option ####
// `Boolean`, since 1.1
//
draggable: true,
// #### `scrollable` Option ####
// `Boolean`, since 1.2
//
scrollable: true,
// #### `steppable` Option ####
// `Boolean`, since 1.2
//
steppable: true,
// #### `throwable` Option ####
// `Boolean`, since 1.1; or `Number`, since 1.2.1
//
throwable: true,
// #### `wheelable` Option ####
// `Boolean`, since 1.1
//
wheelable: true,
// ### [NEW] Gyroscope Support ######
//
// When enabled allows gyro-enabled devices (iPad2 for example) to control rotational
// position using the device's attitude in space. In this more, Reel directly maps the
// 360° range of your gyro's primary (alpha) axis directly to the value of `fraction`.
//
// #### `orientable` Option ####
// [NEW] `Boolean`, since 1.3
//
orientable: false,
// ### Order of Images ######
//
// Reel presumes counter-clockwise order of the pictures taken. If the nearer facing
// side doesn't follow your cursor/finger, you did clockwise. Use the `cw` option to
// correct this.
//
// ---
// #### `cw` Option ####
// `Boolean`, since 1.1
//
cw: false,
// ### Sensitivity ######
//
// In Reel sensitivity is set through the `revolution` parameter, which represents horizontal
// dragging distance one must cover to perform one full revolution. By default this value
// is calculated based on the setup you have - it is either twice the width of the image
// or half the width of stitched panorama. You may also set your own.
//
// Optionally `revolution` can be set as an Object with `x` member for horizontal revolution
// and/or `y` member for vertical revolution in multi-row movies.
//
// ---
// #### `revolution` Option ####
// `Number` (pixels) or `Object`, since 1.1, `Object` support since 1.2
//
revolution: undefined,
// ### Rectilinear Panorama ######
//
// The easiest of all is the stitched panorama mode. For this mode, instead of the sprite,
// a single seamlessly stitched stretched image is used and the view scrolls the image.
// This mode is triggered by setting a pixel width of the `stitched` image.
//
// ---
// #### `stitched` Option ####
// `Number` (pixels), since 1.0
//
stitched: 0,
// ### Directional Mode ######
//
// As you may have noticed on Reel's homepage or in [`example/object-movie-directional-sprite`][1]
// when you drag the arrow will point to either direction. In such `directional` mode, the sprite
// is actually 2 in 1 - one file contains two sprites one tightly following the other, one
// for visually going one way (`A`) and one for the other (`B`).
//
// A01 A02 A03 A04 A05 A06
// A07 A08 A09 A10 A11 A12
// A13 A14 A15 B01 B02 B03
// B04 B05 B06 B07 B08 B09
// B10 B11 B12 B13 B14 B15
//
// Switching between `A` and `B` frames is based on direction of the drag. Directional mode isn't
// limited to sprites only, sequences also apply. The figure below shows the very same setup like
// the above figure, only translated into actual frames of the sequence.
//
// 001 002 003 004 005 006
// 007 008 009 010 011 012
// 013 014 015 016 017 018
// 019 020 021 022 023 024
// 025 026 027 028 029 030
//
// Frame `016` represents the `B01` so it actually is first frame of the other direction.
//
// [1]:../example/object-movie-directional-sprite/
//
// ---
// #### `directional` Option ####
// `Boolean`, since 1.1
//
directional: false,
// ### Multi-Row Mode ######
//
// As [`example/object-movie-multirow-sequence`][1] very nicely demonstrates, in multi-row arrangement
// you can perform two-axis manipulation allowing you to add one or more vertical angles. Think of it as
// a layered cake, each new elevation of the camera during shooting creates one layer of the cake -
// - a _row_. One plain horizontal object movie full spin is one row:
//
// A01 A02 A03 A04 A05 A06
// A07 A08 A09 A10 A11 A12
// A13 A14 A15
//
// Second row tightly follows after the first one:
//
// A01 A02 A03 A04 A05 A06
// A07 A08 A09 A10 A11 A12
// A13 A14 A15 B01 B02 B03
// B04 B05 B06 B07 B08 B09
// B10 B11 B12 B13 B14 B15
// C01...
//
// This way you stack up any number of __`rows`__ you wish and set the initial `row` to start with.
// Again, not limited to sprites, sequences also apply.
//
// [1]:../example/object-movie-multirow-sequence/
//
// ---
// #### `row` Option ####
// `Number` (rows), since 1.1
//
row: 1,
// #### `rows` Option ####
// `Number` (rows), since 1.1
//
rows: 0,
// ### [NEW] Multi-Row Locks ######
//
// Optionally you can apply a lock on either of the two axes with `rowlock` and/or `framelock`.
// That will disable direct mouse interaction and will leave using of `.reel()` the only way
// of changing position on the locked axis.
//
// ---
// #### `rowlock` Option ####
// [NEW] `Boolean`, since 1.3
//
rowlock: false,
// #### `framelock` Option ####
// [NEW] `Boolean`, since 1.3
//
framelock: false,
// ### Dual-Orbit Mode ######
//
// Special form of multi-axis movie is the dual-axis mode. In this mode the object offers two plain
// spins - horizontal and vertical orbits combined together crossing each other at the `frame`
// forming sort of a cross if envisioned. [`example/object-movie-dual-orbit-sequence`][1] demonstrates
// this setup. When the phone in the example is facing you (marked in the example with green square
// in the top right), you are at the center. That is within the distance (in frames) defined
// by the `orbital` option. Translation from horizontal to vertical orbit can be achieved on this sweet-spot.
// By default horizontal orbit is chosen first, unless `vertical` option is used against.
//
// In case the image doesn't follow the vertical drag, you may have your vertical orbit `inversed`.
//
// Technically it is just a two-layer movie:
//
// A01 A02 A03 A04 A05 A06
// A07 A08 A09 A10 A11 A12
// A13 A14 A15 B01 B02 B03
// B04 B05 B06 B07 B08 B09
// B10 B11 B12 B13 B14 B15
//
// [1]:../example/object-movie-dual-orbit-sequence/
//
// ---
// #### `orbital` Option ####
// `Number` (frames), since 1.1
//
orbital: 0,
// #### `vertical` Option ####
// `Boolean`, since 1.1
//
vertical: false,
// #### `inversed` Option ####
// `Boolean`, since 1.1
//
inversed: false,
// ### Sprite Layout ######
//
// For both object movies and panoramas Reel presumes you use a combined _Sprite_ to hold all your
// frames in a single file. This powerful technique of using a sheet of several individual images
// has many advantages in terms of compactness, loading, caching, etc. However, know your enemy,
// be also aware of the limitations, which stem from memory limits of mobile
// (learn more in [FAQ](https://github.com/pisi/Reel/wiki/FAQ)).
//
// Inside the sprite, individual frames are laid down one by one, to the right of the previous one
// in a straight _Line_:
//
// 01 02 03 04 05 06
// 07...
//
// Horizontal length of the line is reffered to as `footage`. Unless frames `spacing` in pixels
// is set, edges of frames must touch.
//
// 01 02 03 04 05 06
// 07 08 09 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
//
// This is what you'll get by calling `.reel()` without any options. All frames laid out 6 in line.
// By default nicely even 6 x 6 grid like, which also inherits the aspect ratio of your frames.
//
// By setting `horizontal` to `false`, instead of forming lines, frames are expected to form
// _Columns_. All starts at the top left corner in both cases.
//
// 01 07 13 19 25 31
// 02 08 14 20 26 32
// 03 09 15 21 27 33
// 04 10 16 22 28 34
// 05 11 17 23 29 35
// 06 12 18 24 30 36
//
// URL for the sprite image file is being build from the name of the original `<img>` `src` image
// by adding a `suffix` to it. By default this results in `"object-reel.jpg"` for `"object.jpg"`.
// You can also take full control over the sprite `image` URL that will be used.
//
// ---
// #### `footage` Option ####
// `Number` (frames), since 1.0
//
footage: 6,
// #### `spacing` Option ####
// `Number` (pixels), since 1.0
//
spacing: 0,
// #### `horizontal` Option ####
// `Boolean`, since 1.0
//
horizontal: true,
// #### `suffix` Option ####
// `String`, since 1.0
//
suffix: '-reel',
// #### `image` Option ####
// `String`, since 1.1
//
image: undefined,
// ### Sequence ######
//
// Collection of individual frame images is called _Sequence_ and it this way one HTTP request per
// frame is made carried out as opposed to sprite with one request per entire sprite. Define it with
// string like: `"image_###.jpg"`. The `#` placeholders will be replaced with a numeric +1 counter
// padded to the placeholders length.
// Learn more about [sequences](Sequences).
//
// In case you work with hashed filenames like `64bc654d21cb.jpg`, where no counter element can
// be indentified, or you prefer direct control, `images` can also accept array of plain URL strings.
//
// All images are retrieved from a specified `path`.
//
// ---
// #### `images` Option ####
// [IMPROVED] `String` or `Array`, since 1.1
//
images: '',
// #### `path` Option ####
// `String` (URL path), since 1.1
//
path: '',
// ### Images Preload Order ######
//
// Given sequence images can be additionally reordered to achieve a perceived faster preloading.
// Value given to `preload` option must match a name of a pre-registered function within
// `$.reel.preload` object. There are two functions built-in:
//
// - `"fidelity"` - non-linear way that ensures even spreading of preloaded images around the entire
// revolution leaving the gaps in-between as small as possible. This results in a gradually
// increasing fidelity of the image rather than having one large shrinking gap. This is the default
// behavior.
// - `"linear"` - linear order of preloading
//
// ---
// #### `preload` Option ####
// `String`, since 1.2
//
preload: 'fidelity',
// ### [NEW] Shy Initialization ######
//
// Sometimes, on-demand activation is desirable in order to conserve device resources or bandwidth
// especially with multiple instances on a single page. If so, enable _shy mode_, in which Reel will
// hold up the initialization process until the image is clicked by the user. Alternativelly you can
// initialize shy instance by triggering `"setup"` event.
//
// ---
// #### `shy` Option ####
// [NEW] `Boolean`, since 1.3
//
shy: false,
// ### Animation ######
//
// Your object movie or a panorama can perform an autonomous sustained motion in one direction.
// When `speed` is set in revolutions per second (Hz), after a given `delay` the instance will
// animate and advance frames by itself.
//
// t
// |-------›|-----------›
// Delay Animation
//
// Start and resume of animation happens when given `timeout` has elapsed since user became idle.
//
// t
// |-----------›|= == == = === = = | |-----------›
// Animation User interaction Timeout Animation
//
// When a scene doesn't loop (see [`loops`](#loops-Option)) and the animation reaches one end,
// it stays there for a while and then reversing the direction of the animation it bounces back
// towards the other end. The time spent on the edge can be customized with `rebound`.
//
// ---
// #### `speed` Option ####
// `Number` (Hz), since 1.1
//
speed: 0,
// #### `delay` Option ####
// `Number` (seconds), since 1.1
//
delay: 0,
// #### `timeout` Option ####
// `Number` (seconds), since 1.1
//
timeout: 2,
// #### `duration` Option ####
// `Number` (seconds), since 1.3
//
duration: undefined,
// #### `rebound` Option ####
// `Number` (seconds), since 1.1
//
rebound: 0.5,
// ### Opening Animation ######
//
// Chance is you want the object to spin a little to attract attention and then stop and wait
// for the user to engage. This is called "opening animation" and it is performed for given number
// of seconds (`opening`) at dedicated `entry` speed. The `entry` speed defaults to value of `speed`
// option. After the opening animation has passed, regular animation procedure begins starting with
// the delay (if any).
//
// t
// |--------›|-------›|-----------›
// Opening Delay Animation
//
// ---
// #### `entry` Option ####
// `Number` (Hz), since 1.1
//
entry: undefined,
// #### `opening` Option ####
// `Number` (seconds), since 1.1
//
opening: 0,
// ### Momentum ######
//
// Often also called inertial motion is a result of measuring a velocity of dragging. This velocity
// builds up momentum, so when a drag is released, the image still retains the momentum and continues
// to spin on itself. Naturally the momentum soon wears off as `brake` is being applied.
//
// One can utilize this momentum for a different kind of an opening animation. By setting initial
// `velocity`, the instance gets artificial momentum and spins to slow down to stop.
//
// ---
// #### `brake` Option ####
// `Number`, since 1.1, where it also has a different default `0.5`
//
brake: 0.23,
// #### `velocity` Option ####
// `Number`, since 1.2
//
velocity: 0,
// ### Ticker ######
//
// For purposes of animation, Reel starts and maintains a timer device which emits ticks timing all
// animations. There is only one ticker running in the document and all instances subscribe to this
// one ticker. Ticker is equipped with a mechanism, which compensates for the measured costs
// of running Reels to ensure the ticker ticks on time. The `tempo` (in Hz) of the ticker can be
// specified.
//
// Please note, that ticker is synchronized with a _leader_, the oldest living instance on page,
// and adjusts to his tempo.
//
// ---
// #### `tempo` Option ####
// `Number` (Hz, ticks per second), since 1.1
//
tempo: 36,
// ~~~
//
// Since many mobile devices are sometimes considerably underpowered in comparison with desktops,
// they often can keep up with the 36 Hz rhythm. In Reel these are called __lazy devices__
// and everything mobile qualifies as lazy for the sake of the battery and interaction fluency.
// The ticker is under-clocked for them by a `laziness` factor, which is used to divide the `tempo`.
// Default `laziness` of `6` will effectively use 6 Hz instead (6 = 36 / 6) on lazy devices.
//
// ---
// #### `laziness` Option ####
// `Number`, since 1.1
//
laziness: 6,
// ### Customization ######
//
// You can customize Reel on both functional and visual front. The most visible thing you can
// customize is probably the `cursor`, size of the `preloader`, perhaps add visual `indicator`(s)
// of Reel's position within the range. You can also set custom `hint` for the tooltip, which appears
// when you mouse over the image area. Last but not least you can also add custom class name `klass`
// to the instance.
//
// ---
// #### `cursor` Option ####
// `String`, since 1.2
//
cursor: undefined,
// #### `hint` Option ####
// `String`, since 1.0
//
hint: '',
// #### `indicator` Option ####
// `Number` (pixels), since 1.0
//
indicator: 0,
// #### `klass` Option ####
// `String`, since 1.0
//
klass: '',
// #### `preloader` Option ####
// `Number` (pixels), since 1.1
//
preloader: 2,
// ~~~
//
// You can use custom attributes (`attr`) on the node - it accepts the same name-value pairs object
// jQuery `.attr()` does. In case you want to delegate full interaction control over the instance
// to some other DOM element(s) on page, you can with `area`.
//
// ---
// #### `area` Option ####
// `jQuery`, since 1.1
//
area: undefined,
// #### `attr` Option ####
// `Object`, since 1.2
//
attr: {},
// ### Annotations ######
//
// To further visually describe your scene you can place all kinds of in-picture HTML annotations
// by defining an `annotations` object. Learn more about [Annotations][1] in a dedicated article.
//
// [1]:https://github.com/pisi/Reel/wiki/Annotations
//
// ---
// #### `annotations` Option ####
// `Object`, since 1.2
//
annotations: undefined,
// ### [NEW] Responsiveness ######
//
// By default, dimensions of Reel are fixed and pixel-match the dimensions of the original image
// and the responsive mode is disabled. Using `responsive` option you can enable responsiveness.
// In such a case Reel will adopt dimensions of its parent container element and scale all relevant
// data store values accordingly.
// The scale applied is stored in `"ratio"` data key, where `1.0` means 100% or no scale.
//
// To take full advantage of this, you can setup your URLs to contain actual dimensions and
// serve images in appropriate detail.
// Learn more about [data values in URLs](#Data-Values-in-URLs).
//
// ---
// #### `responsive` Option ####
// [NEW] `Boolean`, since 1.3
//
responsive: false,
// ### Mathematics ######
//
// When reeling, instance conforms to a graph function, which defines whether it will loop
// (`$.reel.math.hatch`) or it won't (`$.reel.math.envelope`). My math is far from flawless
// and I'm sure there are much better ways how to handle things. the `graph` option is there for you
// shall you need it. It accepts a function, which should process given criteria and return
// a fraction of 1.
//
// function( x, start, revolution, lo, hi, cwness, y ){
// return fraction // 0.0 - 1.0
// }
//
// ---
// #### `graph` Option ####
// `Function`, since 1.1
//
graph: undefined,
// ### Monitor ######
//
// Specify a string data key and you will see its real-time value dumped in the upper-left corner
// of the viewport. Its visual can be customized by CSS using `.jquery-reel-monitor` selector.
//
// ---
// #### `monitor` Option ####
// `String` (data key), since 1.1
//
monitor: undefined
},
// -----------------
// [NEW] Quick Start
// -----------------
//
// For basic Reel initialization, you don't even need to write any Javascript!
// All it takes is to add __class name__ `"reel"` to your `<img>` HTML tag,
// assign an unique __`id` attribute__ and decorate the tag with configuration __data attributes__.
// Result of which will be interactive Reel projection.
//
// <img src="some/image.jpg" width="300" height="200"
// id="my_image"
// class="reel"
// data-images="some/images/01.jpg, some/images/02.jpg"
// data-speed="0.5">
//
// All otherwise Javascript [options](#Options) are made available as HTML `data-*` attributes.
//
// Only the `annotations` option doesn't work this way. To quickly create annotations,
// simply have any HTML node (`<div>` prefferably) anywhere in the DOM,
// assign it __class name__ `"reel-annotation"`, an unique __`id` attribute__
// and add configuration __data attributes__.
//
// <div id="my_annotation"
// class="reel-annotation"
// data-for="my_image"
// data-x="120"
// data-y="60">
// Whatever HTML I'd like to have in the annotation
// </div>
//
// Most important is the `data-for` attribute, which references target Reel instance by `id`.
//
// ---
//
// Responsible for discovery and subsequent conversion of data-configured Reel images is
// `$.reel.scan()` method, which is being called automagically when the DOM becomes ready.
// Under normal circumstances you don't need to scan by yourself.
//
// It however comes in handy to re-scan when you happen to inject a data-configured Reel `<img>`
// into already ready DOM.
//
// ---
// ### `$.reel.scan()` Method ######
// [NEW] returns `jQuery`, since 1.3
//
scan: function(){
return $(dot(klass)+':not('+dot(overlay_klass)+' > '+dot(klass)+')').each(function(ix, image){
var
$image= $(image),
options= $image.data(),
images= options.images= soft_array(options.images),
annotations= {}
$(dot(annotation_klass)+'[data-for='+$image.attr(_id_)+']').each(function(ix, annotation){
var
$annotation= $(annotation),
def= $annotation.data(),
x= def.x= numerize_array(soft_array(def.x)),
y= def.y= numerize_array(soft_array(def.y)),
id= $annotation.attr(_id_),
node= def.node= $annotation.removeData()
annotations[id] = def;
});
options.annotations = annotations;
$image.removeData().reel(options);
});
},
// -------
// Methods
// -------
//
// Reel's methods extend jQuery core functions with members of its `$.reel.fn` object. Despite Reel
// being a typical one-method plug-in with its `.reel()` function, for convenience it also offers
// its bipolar twin `.unreel()`.
//
// ---
// ### `$.reel.fn` ######
// returns `Object`, since 1.1
//
fn: {
// ------------
// Construction
// ------------
//
// `.reel()` method is the core of Reel and similar to some jQuery functions, it has adaptive interface.
// It either builds, [reads & writes data](#Data) or [causes events](#Control-Events).
//
// ---
// ### `.reel( [options] )` Method ######
// returns `jQuery`, since 1.0
//
reel: function(){
var
args= arguments,
t= $(this),
data= t.data(),
name= args[0] || {},
value= args[1]
// The main [core of this procedure](#Construction-Core) is rather bulky, so let's skip it for now
// and instead let me introduce the other uses first.
// --------------------
// [NEW] Control Events
// --------------------
//
// [Event][1] messages are what ties and binds all Reel's internal working components together.
// Besides being able to binding to any of these events from your script and react on Reel status changes
// (e.g. position), you can also trigger some of them in order to control Reel's attitude.
//
// You can:
//
// * control the playback of animated Reels with [`play`](#play-Event), [`pause`](#pause-Event)
// or [`stop`](#stop-Event)
// * step the Reel in any direction with [`stepRight`](#stepRight-Event), [`stepLeft`](#stepLeft-Event),
// [`stepUp`](#stepUp-Event), [`stepDown`](#stepDown-Event),
// * reach certain frame with [`reach`](#reach-Event)
//
// Triggering Reel's control event is as simple as passing the desired event name to `.reel()`.
//
// _**Example:** Stop the animation in progress:_
//
// .reel(':stop')
//
// Think of `.reel()` as a convenient shortcut to and synonym for [`.trigger()`][2], only prefix
// the event name with `:`. Of course you can use simple `.trigger()` instead and without the colon.
//
//
// [1]:http://api.jquery.com/category/events/event-object/
// [2]:http://api.jquery.com/trigger
//
// ---
// #### `.reel( event, [arguments] )` ######
// returns `jQuery`, since 1.3
//
if (typeof name != 'object'){
if (name.slice(0, 1) == ':'){
return t.trigger(name.slice(1), value);
}
// ----
// Data
// ----
//
// Reel stores all its inner state values with the standard DOM [data interface][1] interface
// while adding an additional change-detecting event layer, which makes Reel entirely data-driven.
//
// [1]:http://api.jquery.com/data
//
// _**Example:** Find out on what frame a Reel instance currently is:_
//
// .reel('frame') // Returns the frame number
//
// This time think of `.reel(data)` as a synonym for `.data()`. Note, that you can therefore easily
// inspect the entire datastore with `.data()` (without arguments). Use it for debugging only.
// For real-time data watch use [`monitor`](#Monitor) option instead of manually hooking into
// the data.
//
// ---
// #### `.reel( data )` ######
// can return anything, since 1.2
//
else{
if (args.length == 1){
return data[name]
}
// ### Write Access ###
//
// You can store any value the very same way by passing the value as the second function
// argument.
//
// _**Example:** Jump to frame 12:_
//
// .reel('frame', 12)
//
// Only a handful of data keys is suitable for external manipulation. These include `area`,
// `backwards`, `brake`, __`fraction`__, __`frame`__, `playing`, `reeling`, __`row`__, `speed`,
// `stopped`, `velocity` and `vertical`. Use the rest of the keys for reading only, you can
// mess up easily changing them.
//
// ---
// #### `.reel( data, value )` ######
// returns `jQuery`, since 1.2
//
else{
if (value !== undefined){
reel.normal[name] && (value= reel.normal[name](value, data));
// ### Changes ######
//
// Any value that does not equal (`===`) the old value is considered _new value_ and
// in such a case Reel will trigger a _change event_ to announce the change. The event
// type takes form of _`key`_`Change`, where _`key`_ will be the data key/name you've
// just assigned.
//
// _**Example:** Setting `"frame"` to `12` in the above example will trigger
// `"frameChange"`._
//
// Some of these _change events_ (like `frame` or `fraction`) have a
// default handler attached.
//
// You can easily bind to any of the data key change with standard event
// binding methods.
//
// _**Example:** React on instance being manipulated or not:_
//
// .bind('reelingChange', function(evnt, nothing, reeling){
// if (reeling) console.log('Rock & reel!')
// else console.log('Not reeling...')
// })
//
// ---
// The handler function will be executed every time the value changes and
// it will be supplied with three arguments. First one is the event object
// as usual, second is `undefined` and the third will be the actual value.
// In this case it was a boolean type value.
// If the second argument is not `undefined` it is the backward compatible