carousel-debug.js
146 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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
/*
Copyright (c) 2011, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.com/yui/license.html
version: 2.9.0
*/
/**
* The Carousel module provides a widget for browsing among a set of like
* objects represented pictorially.
*
* @module carousel
* @requires yahoo, dom, event, element
* @optional animation
* @namespace YAHOO.widget
* @title Carousel Widget
*/
(function () {
var WidgetName = "Carousel"; // forward declaration
/**
* The Carousel widget.
*
* @class Carousel
* @extends YAHOO.util.Element
* @constructor
* @param el {HTMLElement | String} The HTML element that represents the
* the container that houses the Carousel.
* @param cfg {Object} (optional) The configuration values
*/
YAHOO.widget.Carousel = function (el, cfg) {
YAHOO.log("Component creation", WidgetName);
YAHOO.widget.Carousel.superclass.constructor.call(this, el, cfg);
};
/*
* Private variables of the Carousel component
*/
/* Some abbreviations to avoid lengthy typing and lookups. */
var
Carousel = YAHOO.widget.Carousel,
Dom = YAHOO.util.Dom,
Event = YAHOO.util.Event,
JS = YAHOO.lang,
/**
* The internal table of Carousel instances.
* @private
* @static
*/
instances = {},
syncUiOnItemInsert = true,
/*
* Custom events of the Carousel component
*/
/**
* @event afterScroll
* @description Fires when the Carousel has scrolled to the previous or
* next page. Passes back the index of the first and last visible items in
* the Carousel. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
afterScrollEvent = "afterScroll",
/**
* @event allItemsRemovedEvent
* @description Fires when all items have been removed from the Carousel.
* See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
allItemsRemovedEvent = "allItemsRemoved",
/**
* @event beforeHide
* @description Fires before the Carousel is hidden. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
beforeHideEvent = "beforeHide",
/**
* @event beforePageChange
* @description Fires when the Carousel is about to scroll to the previous
* or next page. Passes back the page number of the current page. Note
* that the first page number is zero. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
beforePageChangeEvent = "beforePageChange",
/**
* @event beforeScroll
* @description Fires when the Carousel is about to scroll to the previous
* or next page. Passes back the index of the first and last visible items
* in the Carousel and the direction (backward/forward) of the scroll. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
beforeScrollEvent = "beforeScroll",
/**
* @event beforeShow
* @description Fires when the Carousel is about to be shown. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
beforeShowEvent = "beforeShow",
/**
* @event blur
* @description Fires when the Carousel loses focus. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
blurEvent = "blur",
/**
* @event focus
* @description Fires when the Carousel gains focus. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
focusEvent = "focus",
/**
* @event hide
* @description Fires when the Carousel is hidden. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
hideEvent = "hide",
/**
* @event itemAdded
* @description Fires when an item has been added to the Carousel. Passes
* back the content of the item that would be added, the index at which the
* item would be added, and the event itself. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
itemAddedEvent = "itemAdded",
/**
* @event itemRemoved
* @description Fires when an item has been removed from the Carousel.
* Passes back the content of the item that would be removed, the index
* from which the item would be removed, and the event itself. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
itemRemovedEvent = "itemRemoved",
/**
* @event itemReplaced
* @description Fires when an item has been replaced in the Carousel.
* Passes back the content of the item that was replaced, the content
* of the new item, the index where the replacement occurred, and the event
* itself. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
itemReplacedEvent = "itemReplaced",
/**
* @event itemSelected
* @description Fires when an item has been selected in the Carousel.
* Passes back the index of the selected item in the Carousel. Note, that
* the index begins from zero. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
itemSelectedEvent = "itemSelected",
/**
* @event loadItems
* @description Fires when the Carousel needs more items to be loaded for
* displaying them. Passes back the first and last visible items in the
* Carousel, and the number of items needed to be loaded. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
loadItemsEvent = "loadItems",
/**
* @event navigationStateChange
* @description Fires when the state of either one of the navigation
* buttons are changed from enabled to disabled or vice versa. Passes back
* the state (true/false) of the previous and next buttons. The value true
* signifies the button is enabled, false signifies disabled. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
navigationStateChangeEvent = "navigationStateChange",
/**
* @event pageChange
* @description Fires after the Carousel has scrolled to the previous or
* next page. Passes back the page number of the current page. Note
* that the first page number is zero. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
pageChangeEvent = "pageChange",
/*
* Internal event.
* @event render
* @description Fires when the Carousel is rendered. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
renderEvent = "render",
/**
* @event show
* @description Fires when the Carousel is shown. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
showEvent = "show",
/**
* @event startAutoPlay
* @description Fires when the auto play has started in the Carousel. See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
startAutoPlayEvent = "startAutoPlay",
/**
* @event stopAutoPlay
* @description Fires when the auto play has been stopped in the Carousel.
* See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
stopAutoPlayEvent = "stopAutoPlay",
/*
* Internal event.
* @event uiUpdateEvent
* @description Fires when the UI has been updated.
* See
* <a href="YAHOO.util.Element.html#addListener">Element.addListener</a>
* for more information on listening for this event.
* @type YAHOO.util.CustomEvent
*/
uiUpdateEvent = "uiUpdate";
/*
* Private helper functions used by the Carousel component
*/
/**
* Set multiple styles on one element.
* @method setStyles
* @param el {HTMLElement} The element to set styles on
* @param style {Object} top:"10px", left:"0px", etc.
* @private
*/
function setStyles(el, styles) {
var which;
for (which in styles) {
if (styles.hasOwnProperty(which)) {
Dom.setStyle(el, which, styles[which]);
}
}
}
/**
* Create an element, set its class name and optionally install the element
* to its parent.
* @method createElement
* @param el {String} The element to be created
* @param attrs {Object} Configuration of parent, class and id attributes.
* If the content is specified, it is inserted after creation of the
* element. The content can also be an HTML element in which case it would
* be appended as a child node of the created element.
* @private
*/
function createElement(el, attrs) {
var newEl = document.createElement(el);
attrs = attrs || {};
if (attrs.className) {
Dom.addClass(newEl, attrs.className);
}
if (attrs.styles) {
setStyles(newEl, attrs.styles);
}
if (attrs.parent) {
attrs.parent.appendChild(newEl);
}
if (attrs.id) {
newEl.setAttribute("id", attrs.id);
}
if (attrs.content) {
if (attrs.content.nodeName) {
newEl.appendChild(attrs.content);
} else {
newEl.innerHTML = attrs.content;
}
}
return newEl;
}
/**
* Get the computed style of an element.
*
* @method getStyle
* @param el {HTMLElement} The element for which the style needs to be
* returned.
* @param style {String} The style attribute
* @param type {String} "int", "float", etc. (defaults to int)
* @private
*/
function getStyle(el, style, type) {
var value;
if (!el) {
return 0;
}
function getStyleIntVal(el, style) {
var val;
/*
* XXX: Safari calculates incorrect marginRight for an element
* which has its parent element style set to overflow: hidden
* https://bugs.webkit.org/show_bug.cgi?id=13343
* Let us assume marginLeft == marginRight
*
* Seems like IE9 also has this issue!
*/
if (style == "marginRight" && (YAHOO.env.ua.webkit ||
(YAHOO.env.ua.ie && YAHOO.env.ua.ie >= 9))) {
val = parseInt(Dom.getStyle(el, "marginLeft"), 10);
} else {
val = parseInt(Dom.getStyle(el, style), 10);
}
return JS.isNumber(val) ? val : 0;
}
function getStyleFloatVal(el, style) {
var val;
/*
* XXX: Safari calculates incorrect marginRight for an element
* which has its parent element style set to overflow: hidden
* https://bugs.webkit.org/show_bug.cgi?id=13343
* Let us assume marginLeft == marginRight
*/
if (style == "marginRight" && YAHOO.env.ua.webkit) {
val = parseFloat(Dom.getStyle(el, "marginLeft"));
} else {
val = parseFloat(Dom.getStyle(el, style));
}
return JS.isNumber(val) ? val : 0;
}
if (typeof type == "undefined") {
type = "int";
}
switch (style) {
case "height":
value = el.offsetHeight;
if (value > 0) {
value += getStyleIntVal(el, "marginTop") +
getStyleIntVal(el, "marginBottom");
} else {
value = getStyleFloatVal(el, "height") +
getStyleIntVal(el, "marginTop") +
getStyleIntVal(el, "marginBottom") +
getStyleIntVal(el, "borderTopWidth") +
getStyleIntVal(el, "borderBottomWidth") +
getStyleIntVal(el, "paddingTop") +
getStyleIntVal(el, "paddingBottom");
}
break;
case "width":
value = el.offsetWidth;
if (value > 0) {
value += getStyleIntVal(el, "marginLeft") +
getStyleIntVal(el, "marginRight");
} else {
value = getStyleFloatVal(el, "width") +
getStyleIntVal(el, "marginLeft") +
getStyleIntVal(el, "marginRight") +
getStyleIntVal(el, "borderLeftWidth") +
getStyleIntVal(el, "borderRightWidth") +
getStyleIntVal(el, "paddingLeft") +
getStyleIntVal(el, "paddingRight");
}
break;
default:
if (type == "int") {
value = getStyleIntVal(el, style);
} else if (type == "float") {
value = getStyleFloatVal(el, style);
} else {
value = Dom.getStyle(el, style);
}
break;
}
return value;
}
/**
* Compute and return the height or width of a single Carousel item
* depending upon the orientation.
*
* @method getCarouselItemSize
* @param which {String} "height" or "width" to be returned. If this is
* passed explicitly, the calculated size is not cached.
* @private
*/
function getCarouselItemSize(which) {
var carousel = this,
child,
item,
size = 0,
vertical = false;
if (carousel._itemAttrCache[which]) {
return carousel._itemAttrCache[which];
}
if (carousel._itemsTable.numItems === 0) {
return 0;
}
// get first loaded item
item = carousel._findClosestSibling(-1);
if (JS.isUndefined(item)) {
return 0;
}
child = Dom.get(item.id);
if (typeof which == "undefined") {
vertical = carousel.get("isVertical");
} else {
vertical = which == "height";
}
if (vertical) {
size = getStyle(child, "height");
} else {
size = getStyle(child, "width");
}
if (size) {
carousel._itemAttrCache[which] = size;
}
return size;
}
/**
* Return the size of a part of the item (reveal).
*
* @method getRevealSize
* @private
*/
function getRevealSize() {
var carousel = this, isVertical, sz;
isVertical = carousel.get("isVertical");
sz = getCarouselItemSize.call(carousel,
isVertical ? "height" : "width");
return (sz * carousel.get("revealAmount") / 100);
}
/**
* Compute and return the position of a Carousel item based on its
* position.
*
* @method getCarouselItemPosition
* @param position {Number} The position of the Carousel item.
* @private
*/
function getCarouselItemPosition(pos) {
var carousel = this,
itemsPerRow = carousel._cols,
itemsPerCol = carousel._rows,
page,
sz,
isVertical,
itemsCol,
itemsRow,
sentinel,
top,
left,
rsz,
delta,
styles = {},
itemsTable = carousel._itemsTable;
isVertical = carousel.get("isVertical");
sz = getCarouselItemSize.call(carousel,
isVertical ? "height" : "width");
rsz = getRevealSize.call(carousel);
if (itemsPerCol) {
page = this.getPageForItem(pos);
if (isVertical) {
itemsRow = Math.floor(pos/itemsPerRow);
delta = itemsRow;
top = delta * sz;
styles.top = (top + rsz) + "px";
sz = getCarouselItemSize.call(carousel, "width");
itemsCol = pos % itemsPerRow;
delta = itemsCol;
left = delta * sz;
styles.left = left + "px";
} else {
itemsCol = pos % itemsPerRow;
sentinel = (page - 1) * itemsPerRow;
delta = itemsCol + sentinel;
left = delta * sz;
styles.left = (left + rsz) + "px";
sz = getCarouselItemSize.call(carousel, "height");
itemsRow = Math.floor(pos/itemsPerRow);
sentinel = (page - 1) * itemsPerCol;
delta = itemsRow - sentinel;
top = delta * sz;
styles.top = top + "px";
}
} else {
if (isVertical) {
styles.left = 0;
styles.top = ((pos * sz) + rsz) + "px";
} else {
styles.top = 0;
styles.left = ((pos * sz) + rsz) + "px";
}
}
return styles;
}
/**
* Return the index of the first item in the view port for displaying item
* in "pos".
*
* @method getFirstVisibleForPosition
* @param pos {Number} The position of the item to be displayed
* @private
*/
function getFirstVisibleForPosition(pos) {
var num = this.get("numVisible");
return Math.floor(pos / num) * num;
}
/**
* Return the scrolling offset size given the number of elements to
* scroll.
*
* @method getScrollOffset
* @param delta {Number} The delta number of elements to scroll by.
* @private
*/
function getScrollOffset(delta) {
var carousel = this,
itemSize = 0,
size = 0,
attr = carousel.get("isVertical") ? "height" : "width";
itemSize = getCarouselItemSize.call(carousel, attr);
size = itemSize * delta;
return size;
}
/**
* Scroll the Carousel by a page backward.
*
* @method scrollPageBackward
* @param {Event} ev The event object
* @param {Object} obj The context object
* @private
*/
function scrollPageBackward(ev, obj) {
obj.scrollPageBackward();
Event.preventDefault(ev);
}
/**
* Scroll the Carousel by a page forward.
*
* @method scrollPageForward
* @param {Event} ev The event object
* @param {Object} obj The context object
* @private
*/
function scrollPageForward(ev, obj) {
obj.scrollPageForward();
Event.preventDefault(ev);
}
/**
* Set the selected item.
*
* @method setItemSelection
* @param {Number} newpos The index of the new position
* @param {Number} oldpos The index of the previous position
* @private
*/
function setItemSelection(newpos, oldpos) {
var carousel = this,
cssClass = carousel.CLASSES,
el,
firstItem = carousel._firstItem,
numItems = carousel.get("numItems"),
numVisible = carousel.get("numVisible"),
position = oldpos,
sentinel = firstItem + numVisible - 1;
if (position >= 0 && position < numItems) {
if (!JS.isUndefined(carousel._itemsTable.items[position])) {
el = Dom.get(carousel._itemsTable.items[position].id);
if (el) {
Dom.removeClass(el, cssClass.SELECTED_ITEM);
}
}
}
if (JS.isNumber(newpos)) {
newpos = parseInt(newpos, 10);
newpos = JS.isNumber(newpos) ? newpos : 0;
} else {
newpos = firstItem;
}
if (JS.isUndefined(carousel._itemsTable.items[newpos])) {
newpos = getFirstVisibleForPosition.call(carousel, newpos);
carousel.scrollTo(newpos); // still loading the item
}
if (!JS.isUndefined(carousel._itemsTable.items[newpos])) {
el = Dom.get(carousel._itemsTable.items[newpos].id);
if (el) {
Dom.addClass(el, cssClass.SELECTED_ITEM);
}
}
if (newpos < firstItem || newpos > sentinel) { // out of focus
newpos = getFirstVisibleForPosition.call(carousel, newpos);
carousel.scrollTo(newpos);
}
}
/**
* Show or hide navigation.
*
* @method showNavigation
* @private
*/
function showNavigation(hide) {
var carousel = this,
cfg = carousel.get("navigation");
if (JS.isUndefined(cfg)) {
return; // can't do anything
}
if (JS.isUndefined(hide)) {
// show the navigation
if (!JS.isUndefined(cfg.prev) && JS.isArray(cfg.prev) &&
!JS.isUndefined(cfg.prev[0])) {
Dom.setStyle(cfg.prev[0], "visibility", "visible");
}
if (!JS.isUndefined(cfg.next) && JS.isArray(cfg.next) &&
!JS.isUndefined(cfg.next[0])) {
Dom.setStyle(cfg.next[0], "visibility", "visible");
}
if (!JS.isUndefined(carousel._pages) &&
!JS.isUndefined(carousel._pages.el)) {
Dom.setStyle(carousel._pages.el, "visibility", "visible");
}
} else {
// hide the navigation
if (!JS.isUndefined(cfg.prev) && JS.isArray(cfg.prev) &&
!JS.isUndefined(cfg.prev[0])) {
Dom.setStyle(cfg.prev[0], "visibility", "hidden");
}
if (!JS.isUndefined(cfg.next) && JS.isArray(cfg.next) &&
!JS.isUndefined(cfg.next[0])) {
Dom.setStyle(cfg.next[0], "visibility", "hidden");
}
if (!JS.isUndefined(carousel._pages) &&
!JS.isUndefined(carousel._pages.el)) {
Dom.setStyle(carousel._pages.el, "visibility", "hidden");
}
}
}
/**
* Fire custom events for enabling/disabling navigation elements.
*
* @method syncNavigation
* @private
*/
function syncNavigation() {
var attach = false,
carousel = this,
cssClass = carousel.CLASSES,
i,
navigation,
sentinel;
// Don't do anything if the Carousel is not rendered
if (!carousel._hasRendered) {
return;
}
navigation = carousel.get("navigation");
sentinel = carousel._firstItem + carousel.get("numVisible");
if (navigation.prev) {
if (carousel.get("numItems") === 0 || carousel._firstItem === 0) {
if (carousel.get("numItems") === 0 ||
!carousel.get("isCircular")) {
Event.removeListener(navigation.prev, "click",
scrollPageBackward);
Dom.addClass(navigation.prev, cssClass.FIRST_NAV_DISABLED);
for (i = 0; i < carousel._navBtns.prev.length; i++) {
carousel._navBtns.prev[i].setAttribute("disabled",
"true");
}
carousel._prevEnabled = false;
} else {
attach = !carousel._prevEnabled;
}
} else {
attach = !carousel._prevEnabled;
}
if (attach) {
Event.on(navigation.prev, "click", scrollPageBackward,
carousel);
Dom.removeClass(navigation.prev, cssClass.FIRST_NAV_DISABLED);
for (i = 0; i < carousel._navBtns.prev.length; i++) {
carousel._navBtns.prev[i].removeAttribute("disabled");
}
carousel._prevEnabled = true;
}
}
attach = false;
if (navigation.next) {
if (sentinel >= carousel.get("numItems")) {
if (!carousel.get("isCircular")) {
Event.removeListener(navigation.next, "click",
scrollPageForward);
Dom.addClass(navigation.next, cssClass.DISABLED);
for (i = 0; i < carousel._navBtns.next.length; i++) {
carousel._navBtns.next[i].setAttribute("disabled",
"true");
}
carousel._nextEnabled = false;
} else {
attach = !carousel._nextEnabled;
}
} else {
attach = !carousel._nextEnabled;
}
if (attach) {
Event.on(navigation.next, "click", scrollPageForward,
carousel);
Dom.removeClass(navigation.next, cssClass.DISABLED);
for (i = 0; i < carousel._navBtns.next.length; i++) {
carousel._navBtns.next[i].removeAttribute("disabled");
}
carousel._nextEnabled = true;
}
}
carousel.fireEvent(navigationStateChangeEvent,
{ next: carousel._nextEnabled, prev: carousel._prevEnabled });
}
/**
* Synchronize and redraw the Pager UI if necessary.
*
* @method syncPagerUi
* @private
*/
function syncPagerUi(page) {
var carousel = this, numPages, numVisible;
// Don't do anything if the Carousel is not rendered
if (!carousel._hasRendered) {
return;
}
numVisible = carousel.get("numVisible");
if (!JS.isNumber(page)) {
page = Math.floor(carousel.get("selectedItem") / numVisible);
}
numPages = Math.ceil(carousel.get("numItems") / numVisible);
carousel._pages.num = numPages;
carousel._pages.cur = page;
if (numPages > carousel.CONFIG.MAX_PAGER_BUTTONS) {
carousel._updatePagerMenu();
} else {
carousel._updatePagerButtons();
}
}
/**
* Get full dimensions of an element.
*
* @method getDimensions
* @param {Object} el The element to get the dimensions of
* @param {String} which Get the height or width of an element
* @private
*/
function getDimensions(el, which) {
switch (which) {
case 'height':
return getStyle(el, "marginTop") +
getStyle(el, "marginBottom") +
getStyle(el, "paddingTop") +
getStyle(el, "paddingBottom") +
getStyle(el, "borderTopWidth") +
getStyle(el, "borderBottomWidth");
case 'width':
return getStyle(el, "marginLeft") +
getStyle(el, "marginRight") +
getStyle(el, "paddingLeft") +
getStyle(el, "paddingRight") +
getStyle(el, "borderLeftWidth") +
getStyle(el, "borderRightWidth");
default:
break;
}
return getStyle(el, which);
}
/**
* Handle UI update.
* Call the appropriate methods on events fired when an item is added, or
* removed for synchronizing the DOM.
*
* @method syncUi
* @param {Object} o The item that needs to be added or removed
* @private
*/
function syncUi(o) {
var carousel = this;
if (!JS.isObject(o)) {
return;
}
switch (o.ev) {
case itemAddedEvent:
carousel._syncUiForItemAdd(o);
break;
case itemRemovedEvent:
carousel._syncUiForItemRemove(o);
break;
case itemReplacedEvent:
carousel._syncUiForItemReplace(o);
break;
case loadItemsEvent:
carousel._syncUiForLazyLoading(o);
break;
}
carousel.fireEvent(uiUpdateEvent);
}
/**
* Update the state variables after scrolling the Carousel view port.
*
* @method updateStateAfterScroll
* @param {Integer} item The index to which the Carousel has scrolled to.
* @param {Integer} sentinel The last element in the view port.
* @private
*/
function updateStateAfterScroll(item, sentinel) {
var carousel = this,
page = carousel.get("currentPage"),
newPage,
numPerPage = carousel.get("numVisible");
newPage = parseInt(carousel._firstItem / numPerPage, 10);
if (newPage != page) {
carousel.setAttributeConfig("currentPage", { value: newPage });
carousel.fireEvent(pageChangeEvent, newPage);
}
if (carousel.get("selectOnScroll")) {
if (carousel.get("selectedItem") != carousel._selectedItem) {
carousel.set("selectedItem", carousel._selectedItem);
}
}
clearTimeout(carousel._autoPlayTimer);
delete carousel._autoPlayTimer;
if (carousel.isAutoPlayOn()) {
carousel.startAutoPlay();
}
carousel.fireEvent(afterScrollEvent,
{ first: carousel._firstItem,
last: sentinel },
carousel);
}
/*
* Static members and methods of the Carousel component
*/
/**
* Return the appropriate Carousel object based on the id associated with
* the Carousel element or false if none match.
* @method getById
* @public
* @static
*/
Carousel.getById = function (id) {
return instances[id] ? instances[id].object : false;
};
YAHOO.extend(Carousel, YAHOO.util.Element, {
/*
* Internal variables used within the Carousel component
*/
/**
* Number of rows for a multirow carousel.
*
* @property _rows
* @private
*/
_rows: null,
/**
* Number of cols for a multirow carousel.
*
* @property _cols
* @private
*/
_cols: null,
/**
* The Animation object.
*
* @property _animObj
* @private
*/
_animObj: null,
/**
* The Carousel element.
*
* @property _carouselEl
* @private
*/
_carouselEl: null,
/**
* The Carousel clipping container element.
*
* @property _clipEl
* @private
*/
_clipEl: null,
/**
* The current first index of the Carousel.
*
* @property _firstItem
* @private
*/
_firstItem: 0,
/**
* Does the Carousel element have focus?
*
* @property _hasFocus
* @private
*/
_hasFocus: false,
/**
* Is the Carousel rendered already?
*
* @property _hasRendered
* @private
*/
_hasRendered: false,
/**
* Is the animation still in progress?
*
* @property _isAnimationInProgress
* @private
*/
_isAnimationInProgress: false,
/**
* Is the auto-scrolling of Carousel in progress?
*
* @property _isAutoPlayInProgress
* @private
*/
_isAutoPlayInProgress: false,
/**
* The table of items in the Carousel.
* The numItems is the number of items in the Carousel, items being the
* array of items in the Carousel. The size is the size of a single
* item in the Carousel. It is cached here for efficiency (to avoid
* computing the size multiple times).
*
* @property _itemsTable
* @private
*/
_itemsTable: null,
/**
* The Carousel navigation buttons.
*
* @property _navBtns
* @private
*/
_navBtns: null,
/**
* The Carousel navigation.
*
* @property _navEl
* @private
*/
_navEl: null,
/**
* Status of the next navigation item.
*
* @property _nextEnabled
* @private
*/
_nextEnabled: true,
/**
* The Carousel pages structure.
* This is an object of the total number of pages and the current page.
*
* @property _pages
* @private
*/
_pages: null,
/**
* The Carousel pagination structure.
*
* @property _pagination
* @private
*/
_pagination: null,
/**
* Status of the previous navigation item.
*
* @property _prevEnabled
* @private
*/
_prevEnabled: true,
/**
* Whether the Carousel size needs to be recomputed or not?
*
* @property _recomputeSize
* @private
*/
_recomputeSize: true,
/**
* Cache the Carousel item attributes.
*
* @property _itemAttrCache
* @private
*/
_itemAttrCache: null,
/*
* CSS classes used by the Carousel component
*/
CLASSES: {
/**
* The class name of the Carousel navigation buttons.
*
* @property BUTTON
* @default "yui-carousel-button"
*/
BUTTON: "yui-carousel-button",
/**
* The class name of the Carousel element.
*
* @property CAROUSEL
* @default "yui-carousel"
*/
CAROUSEL: "yui-carousel",
/**
* The class name of the container of the items in the Carousel.
*
* @property CAROUSEL_EL
* @default "yui-carousel-element"
*/
CAROUSEL_EL: "yui-carousel-element",
/**
* The class name of the Carousel's container element.
*
* @property CONTAINER
* @default "yui-carousel-container"
*/
CONTAINER: "yui-carousel-container",
/**
* The class name of the Carousel's container element.
*
* @property CONTENT
* @default "yui-carousel-content"
*/
CONTENT: "yui-carousel-content",
/**
* The class name of a disabled navigation button.
*
* @property DISABLED
* @default "yui-carousel-button-disabled"
*/
DISABLED: "yui-carousel-button-disabled",
/**
* The class name of the first Carousel navigation button.
*
* @property FIRST_NAV
* @default " yui-carousel-first-button"
*/
FIRST_NAV: " yui-carousel-first-button",
/**
* The class name of a first disabled navigation button.
*
* @property FIRST_NAV_DISABLED
* @default "yui-carousel-first-button-disabled"
*/
FIRST_NAV_DISABLED: "yui-carousel-first-button-disabled",
/**
* The class name of a first page element.
*
* @property FIRST_PAGE
* @default "yui-carousel-nav-first-page"
*/
FIRST_PAGE: "yui-carousel-nav-first-page",
/**
* The class name of the Carousel navigation button that has focus.
*
* @property FOCUSSED_BUTTON
* @default "yui-carousel-button-focus"
*/
FOCUSSED_BUTTON: "yui-carousel-button-focus",
/**
* The class name of a horizontally oriented Carousel.
*
* @property HORIZONTAL
* @default "yui-carousel-horizontal"
*/
HORIZONTAL: "yui-carousel-horizontal",
/**
* The element to be used as the progress indicator when the item
* is still being loaded.
*
* @property ITEM_LOADING
* @default The progress indicator (spinner) image CSS class
*/
ITEM_LOADING: "yui-carousel-item-loading",
/**
* The class name that will be set if the Carousel adjusts itself
* for a minimum width.
*
* @property MIN_WIDTH
* @default "yui-carousel-min-width"
*/
MIN_WIDTH: "yui-carousel-min-width",
/**
* The navigation element container class name.
*
* @property NAVIGATION
* @default "yui-carousel-nav"
*/
NAVIGATION: "yui-carousel-nav",
/**
* The class name of the next Carousel navigation button.
*
* @property NEXT_NAV
* @default " yui-carousel-next-button"
*/
NEXT_NAV: " yui-carousel-next-button",
/**
* The class name of the next navigation link. This variable is
* not only used for styling, but also for identifying the link
* within the Carousel container.
*
* @property NEXT_PAGE
* @default "yui-carousel-next"
*/
NEXT_PAGE: "yui-carousel-next",
/**
* The class name for the navigation container for prev/next.
*
* @property NAV_CONTAINER
* @default "yui-carousel-buttons"
*/
NAV_CONTAINER: "yui-carousel-buttons",
/**
* The class name for an item in the pager UL or dropdown menu.
*
* @property PAGER_ITEM
* @default "yui-carousel-pager-item"
*/
PAGER_ITEM: "yui-carousel-pager-item",
/**
* The class name for the pagination container
*
* @property PAGINATION
* @default "yui-carousel-pagination"
*/
PAGINATION: "yui-carousel-pagination",
/**
* The class name of the focussed page navigation. This class is
* specifically used for the ugly focus handling in Opera.
*
* @property PAGE_FOCUS
* @default "yui-carousel-nav-page-focus"
*/
PAGE_FOCUS: "yui-carousel-nav-page-focus",
/**
* The class name of the previous navigation link. This variable
* is not only used for styling, but also for identifying the link
* within the Carousel container.
*
* @property PREV_PAGE
* @default "yui-carousel-prev"
*/
PREV_PAGE: "yui-carousel-prev",
/**
* The class name of the item.
*
* @property ITEM
* @default "yui-carousel-item"
*/
ITEM: "yui-carousel-item",
/**
* The class name of the selected item.
*
* @property SELECTED_ITEM
* @default "yui-carousel-item-selected"
*/
SELECTED_ITEM: "yui-carousel-item-selected",
/**
* The class name of the selected paging navigation.
*
* @property SELECTED_NAV
* @default "yui-carousel-nav-page-selected"
*/
SELECTED_NAV: "yui-carousel-nav-page-selected",
/**
* The class name of a vertically oriented Carousel.
*
* @property VERTICAL
* @default "yui-carousel-vertical"
*/
VERTICAL: "yui-carousel-vertical",
/**
* The class name of a multirow Carousel.
*
* @property MULTI_ROW
* @default "yui-carousel-multi-row"
*/
MULTI_ROW: "yui-carousel-multi-row",
/**
* The class name of a row in a multirow Carousel.
*
* @property ROW
* @default "yui-carousel-new-row"
*/
ROW: "yui-carousel-row",
/**
* The class name of a vertical Carousel's container element.
*
* @property VERTICAL_CONTAINER
* @default "yui-carousel-vertical-container"
*/
VERTICAL_CONTAINER: "yui-carousel-vertical-container",
/**
* The class name of a visible Carousel.
*
* @property VISIBLE
* @default "yui-carousel-visible"
*/
VISIBLE: "yui-carousel-visible"
},
/*
* Configuration attributes for configuring the Carousel component
*/
CONFIG: {
/**
* The offset of the first visible item in the Carousel.
*
* @property FIRST_VISIBLE
* @default 0
*/
FIRST_VISIBLE: 0,
/**
* The minimum width of the horizontal Carousel container to support
* the navigation buttons.
*
* @property HORZ_MIN_WIDTH
* @default 180
*/
HORZ_MIN_WIDTH: 180,
/**
* The maximum number of pager buttons allowed beyond which the UI
* of the pager would be a drop-down of pages instead of buttons.
*
* @property MAX_PAGER_BUTTONS
* @default 5
*/
MAX_PAGER_BUTTONS: 5,
/**
* The minimum width of the vertical Carousel container to support
* the navigation buttons.
*
* @property VERT_MIN_WIDTH
* @default 155
*/
VERT_MIN_WIDTH: 115,
/**
* The number of visible items in the Carousel.
*
* @property NUM_VISIBLE
* @default 3
*/
NUM_VISIBLE: 3
},
/*
* Internationalizable strings in the Carousel component
*/
STRINGS: {
/**
* The content to be used as the progress indicator when the item
* is still being loaded. Inserted into DOM with innerHTML.
*
* @property ITEM_LOADING_CONTENT
* @type HTML
* @default "Loading"
*/
ITEM_LOADING_CONTENT: "Loading",
/**
* The next navigation button name/text. Inserted into DOM with innerHTML.
*
* @property NEXT_BUTTON_TEXT
* @type HTML
* @default "Next Page"
*/
NEXT_BUTTON_TEXT: "Next Page",
/**
* The prefix text for the pager in case the UI is a drop-down.
* Inserted into DOM with innerHTML.
*
* @property PAGER_PREFIX_TEXT
* @type HTML
* @default "Go to page "
*/
PAGER_PREFIX_TEXT: "Go to page ",
/**
* The previous navigation button name/text. Inserted into DOM with innerHTML.
*
* @property PREVIOUS_BUTTON_TEXT
* @type HTML
* @default "Previous Page"
*/
PREVIOUS_BUTTON_TEXT: "Previous Page"
},
/*
* Public methods of the Carousel component
*/
/**
* Insert or append an item to the Carousel.
* E.g. if Object: ({content:"Your Content", id:"", className:""}, index)
*
* @method addItem
* @public
* @param item {HTML | Object | HTMLElement} The item to be appended
* to the Carousel. If the parameter is a string, it is assumed to be
* the HTML content of the newly created item. If the parameter is an
* object, it is assumed to supply the content and an optional class
* and an optional id of the newly created item.
* @param index {Number} optional The position to where in the list
* (starts from zero).
* @return {Boolean} Return true on success, false otherwise
*/
addItem: function (item, index) {
var carousel = this,
className,
content,
elId,
replaceItems = 0,
newIndex, // Add newIndex as workaround for undefined pos
numItems = carousel.get("numItems");
if (!item) {
return false;
}
if (JS.isString(item) || item.nodeName) {
content = item.nodeName ? item.innerHTML : item;
} else if (JS.isObject(item)) {
content = item.content;
} else {
YAHOO.log("Invalid argument to addItem", "error", WidgetName);
return false;
}
className = carousel.CLASSES.ITEM +
(item.className ? " " + item.className : "");
elId = item.id ? item.id : Dom.generateId();
if (JS.isUndefined(index)) {
carousel._itemsTable.items.push({
item : content,
className : className,
id : elId
});
// Add newIndex as workaround for undefined pos
newIndex = carousel._itemsTable.items.length - 1;
} else {
if (index < 0 || index > numItems) {
YAHOO.log("Index out of bounds", "error", WidgetName);
return false;
}
// make sure we splice into the correct position
if (!carousel._itemsTable.items[index]) {
carousel._itemsTable.items[index] = undefined;
replaceItems = 1;
}
carousel._itemsTable.items.splice(index, replaceItems, {
item : content,
className : className,
id : elId
});
}
carousel._itemsTable.numItems++;
if (numItems < carousel._itemsTable.items.length) {
carousel.set("numItems", carousel._itemsTable.items.length);
}
// Add newPos as workaround for undefined pos
carousel.fireEvent(itemAddedEvent,
{ pos: index, ev: itemAddedEvent, newPos: newIndex });
return true;
},
/**
* Insert or append multiple items to the Carousel.
*
* @method addItems
* @public
* @param items {Array} An array containing an array of new items each linked to the
* index where the insertion should take place.
* E.g. [[{content:'<img/>'}, index1], [{content:'<img/>'}, index2]]
* NOTE: An item at index must already exist.
* @return {Boolean} Return true on success, false otherwise
*/
addItems: function (items) {
var i, n, rv = true;
if (!JS.isArray(items)) {
return false;
}
syncUiOnItemInsert = false;
for (i = 0, n = items.length; i < n; i++) {
if (this.addItem(items[i][0], items[i][1]) === false) {
rv = false;
}
}
syncUiOnItemInsert = true;
this._syncUiItems();
return rv;
},
/**
* Remove focus from the Carousel.
*
* @method blur
* @public
*/
blur: function () {
this._carouselEl.blur();
this.fireEvent(blurEvent);
},
/**
* Clears the items from Carousel.
*
* @method clearItems
* @public
*/
clearItems: function () {
var carousel = this, n = carousel.get("numItems");
while (n > 0) {
if (!carousel.removeItem(0)) {
YAHOO.log("Item could not be removed - missing?",
"warn", WidgetName);
}
/*
For dynamic loading, the numItems may be much larger than
the actual number of items in the table. So, set the
numItems to zero, and break out of the loop if the table
is already empty.
*/
if (carousel._itemsTable.numItems === 0) {
carousel.set("numItems", 0);
break;
}
n--;
}
carousel.fireEvent(allItemsRemovedEvent);
},
/**
* Set focus on the Carousel.
*
* @method focus
* @public
*/
focus: function () {
var carousel = this,
first,
focusEl,
isSelectionInvisible,
itemsTable,
last,
numVisible,
selectOnScroll,
selected,
selItem;
// Don't do anything if the Carousel is not rendered
if (!carousel._hasRendered) {
return;
}
if (carousel.isAnimating()) {
// this messes up real bad!
return;
}
selItem = carousel.get("selectedItem");
numVisible = carousel.get("numVisible");
selectOnScroll = carousel.get("selectOnScroll");
selected = (selItem >= 0) ?
carousel.getItem(selItem) : null;
first = carousel.get("firstVisible");
last = first + numVisible - 1;
isSelectionInvisible = (selItem < first || selItem > last);
focusEl = (selected && selected.id) ?
Dom.get(selected.id) : null;
itemsTable = carousel._itemsTable;
if (!selectOnScroll && isSelectionInvisible) {
focusEl = (itemsTable && itemsTable.items &&
itemsTable.items[first]) ?
Dom.get(itemsTable.items[first].id) : null;
}
if (focusEl) {
try {
focusEl.focus();
} catch (ex) {
// ignore focus errors
}
}
carousel.fireEvent(focusEvent);
},
/**
* Hide the Carousel.
*
* @method hide
* @public
*/
hide: function () {
var carousel = this;
if (carousel.fireEvent(beforeHideEvent) !== false) {
carousel.removeClass(carousel.CLASSES.VISIBLE);
showNavigation.call(carousel, false);
carousel.fireEvent(hideEvent);
}
},
/**
* Initialize the Carousel.
*
* @method init
* @public
* @param el {HTMLElement | String} The html element that represents
* the Carousel container.
* @param attrs {Object} The set of configuration attributes for
* creating the Carousel.
*/
init: function (el, attrs) {
var carousel = this,
elId = el, // save for a rainy day
parse = false,
selected;
if (!el) {
YAHOO.log(el + " is neither an HTML element, nor a string",
"error", WidgetName);
return;
}
carousel._hasRendered = false;
carousel._navBtns = { prev: [], next: [] };
carousel._pages = { el: null, num: 0, cur: 0 };
carousel._pagination = {};
carousel._itemAttrCache = {};
carousel._itemsTable = { loading: {}, numItems: 0,
items: [], size: 0 };
YAHOO.log("Component initialization", WidgetName);
if (JS.isString(el)) {
el = Dom.get(el);
} else if (!el.nodeName) {
YAHOO.log(el + " is neither an HTML element, nor a string",
"error", WidgetName);
return;
}
Carousel.superclass.init.call(carousel, el, attrs);
// check if we're starting somewhere in the middle
selected = carousel.get("selectedItem");
if(selected > 0){
carousel.set("firstVisible",getFirstVisibleForPosition.call(carousel,selected));
}
if (el) {
if (!el.id) { // in case the HTML element is passed
el.setAttribute("id", Dom.generateId());
}
parse = carousel._parseCarousel(el);
if (!parse) {
carousel._createCarousel(elId);
}
} else {
el = carousel._createCarousel(elId);
}
elId = el.id;
carousel.initEvents();
if (parse) {
carousel._parseCarouselItems();
}
// add the selected class
if(selected > 0){
setItemSelection.call(carousel,selected,0);
}
if (!attrs || typeof attrs.isVertical == "undefined") {
carousel.set("isVertical", false);
}
carousel._parseCarouselNavigation(el);
carousel._navEl = carousel._setupCarouselNavigation();
instances[elId] = { object: carousel };
carousel._loadItems(Math.min(carousel.get("firstVisible")+carousel.get("numVisible"),carousel.get("numItems"))-1);
},
/**
* Initialize the configuration attributes used to create the Carousel.
*
* @method initAttributes
* @public
* @param attrs {Object} The set of configuration attributes for
* creating the Carousel.
*/
initAttributes: function (attrs) {
var carousel = this;
attrs = attrs || {};
Carousel.superclass.initAttributes.call(carousel, attrs);
/**
* @attribute carouselEl
* @description The type of the Carousel element.
* @default OL
* @type Boolean
*/
carousel.setAttributeConfig("carouselEl", {
validator : JS.isString,
value : attrs.carouselEl || "OL"
});
/**
* @attribute carouselItemEl
* @description The type of the list of items within the Carousel.
* @default LI
* @type Boolean
*/
carousel.setAttributeConfig("carouselItemEl", {
validator : JS.isString,
value : attrs.carouselItemEl || "LI"
});
/**
* @attribute currentPage
* @description The current page number (read-only.)
* @type Number
*/
carousel.setAttributeConfig("currentPage", {
readOnly : true,
value : 0
});
/**
* @attribute firstVisible
* @description The index to start the Carousel from (indexes begin
* from zero)
* @default 0
* @type Number
*/
carousel.setAttributeConfig("firstVisible", {
method : carousel._setFirstVisible,
validator : carousel._validateFirstVisible,
value :
attrs.firstVisible || carousel.CONFIG.FIRST_VISIBLE
});
/**
* @attribute selectOnScroll
* @description Set this to true to automatically set focus to
* follow scrolling in the Carousel.
* @default true
* @type Boolean
*/
carousel.setAttributeConfig("selectOnScroll", {
validator : JS.isBoolean,
value : attrs.selectOnScroll || true
});
/**
* @attribute numVisible
* @description The number of visible items in the Carousel's
* viewport.
* @default 3
* @type Number
*/
carousel.setAttributeConfig("numVisible", {
setter : carousel._numVisibleSetter,
method : carousel._setNumVisible,
validator : carousel._validateNumVisible,
value : attrs.numVisible || carousel.CONFIG.NUM_VISIBLE
});
/**
* @attribute numItems
* @description The number of items in the Carousel.
* @type Number
*/
carousel.setAttributeConfig("numItems", {
method : carousel._setNumItems,
validator : carousel._validateNumItems,
value : carousel._itemsTable.numItems
});
/**
* @attribute scrollIncrement
* @description The number of items to scroll by for arrow keys.
* @default 1
* @type Number
*/
carousel.setAttributeConfig("scrollIncrement", {
validator : carousel._validateScrollIncrement,
value : attrs.scrollIncrement || 1
});
/**
* @attribute selectedItem
* @description The index of the selected item.
* @type Number
*/
carousel.setAttributeConfig("selectedItem", {
setter : carousel._selectedItemSetter,
method : carousel._setSelectedItem,
validator : JS.isNumber,
value : -1
});
/**
* @attribute revealAmount
* @description The percentage of the item to be revealed on each
* side of the Carousel (before and after the first and last item
* in the Carousel's viewport.)
* @default 0
* @type Number
*/
carousel.setAttributeConfig("revealAmount", {
method : carousel._setRevealAmount,
validator : carousel._validateRevealAmount,
value : attrs.revealAmount || 0
});
/**
* @attribute isCircular
* @description Set this to true to wrap scrolling of the contents
* in the Carousel.
* @default false
* @type Boolean
*/
carousel.setAttributeConfig("isCircular", {
validator : JS.isBoolean,
value : attrs.isCircular || false
});
/**
* @attribute isVertical
* @description True if the orientation of the Carousel is vertical
* @default false
* @type Boolean
*/
carousel.setAttributeConfig("isVertical", {
method : carousel._setOrientation,
validator : JS.isBoolean,
value : attrs.isVertical || false
});
/**
* @attribute navigation
* @description The set of navigation controls for Carousel
* @default <br>
* { prev: null, // the previous navigation element<br>
* next: null } // the next navigation element
* @type Object
*/
carousel.setAttributeConfig("navigation", {
method : carousel._setNavigation,
validator : carousel._validateNavigation,
value :
attrs.navigation || {prev: null,next: null,page: null}
});
/**
* @attribute animation
* @description The optional animation attributes for the Carousel.
* @default <br>
* { speed: 0, // the animation speed (in seconds)<br>
* effect: null } // the animation effect (like
* YAHOO.util.Easing.easeOut)
* @type Object
*/
carousel.setAttributeConfig("animation", {
validator : carousel._validateAnimation,
value : attrs.animation || { speed: 0, effect: null }
});
/**
* @attribute autoPlay
* @description Set this to time in milli-seconds to have the
* Carousel automatically scroll the contents.
* @type Number
* @deprecated Use autoPlayInterval instead.
*/
carousel.setAttributeConfig("autoPlay", {
validator : JS.isNumber,
value : attrs.autoPlay || 0
});
/**
* @attribute autoPlayInterval
* @description The delay in milli-seconds for scrolling the
* Carousel during auto-play.
* Note: The startAutoPlay() method needs to be invoked to trigger
* automatic scrolling of Carousel.
* @type Number
*/
carousel.setAttributeConfig("autoPlayInterval", {
validator : JS.isNumber,
value : attrs.autoPlayInterval || 0
});
/**
* @attribute numPages
* @description The number of pages in the carousel.
* @type Number
*/
carousel.setAttributeConfig("numPages", {
readOnly : true,
getter : carousel._getNumPages
});
/**
* @attribute lastVisible
* @description The last item visible in the carousel.
* @type Number
*/
carousel.setAttributeConfig("lastVisible", {
readOnly : true,
getter : carousel._getLastVisible
});
},
/**
* Initialize and bind the event handlers.
*
* @method initEvents
* @public
*/
initEvents: function () {
var carousel = this,
cssClass = carousel.CLASSES,
focussedLi;
carousel.on("keydown", carousel._keyboardEventHandler);
carousel.on(afterScrollEvent, syncNavigation);
carousel.on(itemAddedEvent, syncUi);
carousel.on(itemRemovedEvent, syncUi);
carousel.on(itemReplacedEvent, syncUi);
carousel.on(itemSelectedEvent, carousel._focusHandler);
carousel.on(loadItemsEvent, syncUi);
carousel.on(allItemsRemovedEvent, function (ev) {
carousel.scrollTo(0);
syncNavigation.call(carousel);
syncPagerUi.call(carousel);
});
carousel.on(pageChangeEvent, syncPagerUi, carousel);
carousel.on(renderEvent, function (ev) {
if (carousel.get("selectedItem") === null ||
carousel.get("selectedItem") <= 0) { //in either case
carousel.set("selectedItem", carousel.get("firstVisible"));
}
syncNavigation.call(carousel, ev);
syncPagerUi.call(carousel, ev);
carousel._setClipContainerSize();
carousel.show();
});
carousel.on("selectedItemChange", function (ev) {
setItemSelection.call(carousel, ev.newValue, ev.prevValue);
if (ev.newValue >= 0) {
carousel._updateTabIndex(
carousel.getElementForItem(ev.newValue));
}
carousel.fireEvent(itemSelectedEvent, ev.newValue);
});
carousel.on(uiUpdateEvent, function (ev) {
syncNavigation.call(carousel, ev);
syncPagerUi.call(carousel, ev);
});
carousel.on("firstVisibleChange", function (ev) {
if (!carousel.get("selectOnScroll")) {
if (ev.newValue >= 0) {
carousel._updateTabIndex(
carousel.getElementForItem(ev.newValue));
}
}
});
// Handle item selection on mouse click
carousel.on("click", function (ev) {
if (carousel.isAutoPlayOn()) {
carousel.stopAutoPlay();
}
carousel._itemClickHandler(ev);
carousel._pagerClickHandler(ev);
});
// Restore the focus on the navigation buttons
Event.onFocus(carousel.get("element"), function (ev, obj) {
var target = Event.getTarget(ev);
if (target && target.nodeName.toUpperCase() == "A" &&
Dom.getAncestorByClassName(target, cssClass.NAVIGATION)) {
if (focussedLi) {
Dom.removeClass(focussedLi, cssClass.PAGE_FOCUS);
}
focussedLi = target.parentNode;
Dom.addClass(focussedLi, cssClass.PAGE_FOCUS);
} else {
if (focussedLi) {
Dom.removeClass(focussedLi, cssClass.PAGE_FOCUS);
}
}
obj._hasFocus = true;
obj._updateNavButtons(Event.getTarget(ev), true);
}, carousel);
Event.onBlur(carousel.get("element"), function (ev, obj) {
obj._hasFocus = false;
obj._updateNavButtons(Event.getTarget(ev), false);
}, carousel);
},
/**
* Return true if the Carousel is still animating, or false otherwise.
*
* @method isAnimating
* @return {Boolean} Return true if animation is still in progress, or
* false otherwise.
* @public
*/
isAnimating: function () {
return this._isAnimationInProgress;
},
/**
* Return true if the auto-scrolling of Carousel is "on", or false
* otherwise.
*
* @method isAutoPlayOn
* @return {Boolean} Return true if autoPlay is "on", or false
* otherwise.
* @public
*/
isAutoPlayOn: function () {
return this._isAutoPlayInProgress;
},
/**
* Return the carouselItemEl at index or null if the index is not
* found.
*
* @method getElementForItem
* @param index {Number} The index of the item to be returned
* @return {Element} Return the item at index or null if not found
* @public
*/
getElementForItem: function (index) {
var carousel = this;
if (index < 0 || index >= carousel.get("numItems")) {
YAHOO.log("Index out of bounds", "error", WidgetName);
return null;
}
if (carousel._itemsTable.items[index]) {
return Dom.get(carousel._itemsTable.items[index].id);
}
return null;
},
/**
* Return the carouselItemEl for all items in the Carousel.
*
* @method getElementForItems
* @return {Array} Return all the items
* @public
*/
getElementForItems: function () {
var carousel = this, els = [], i;
for (i = 0; i < carousel._itemsTable.numItems; i++) {
els.push(carousel.getElementForItem(i));
}
return els;
},
/**
* Return the item at index or null if the index is not found.
*
* @method getItem
* @param index {Number} The index of the item to be returned
* @return {Object} Return the item at index or null if not found
* @public
*/
getItem: function (index) {
var carousel = this;
if (index < 0 || index >= carousel.get("numItems")) {
YAHOO.log("Index out of bounds", "error", WidgetName);
return null;
}
if (carousel._itemsTable.items.length > index) {
if (!JS.isUndefined(carousel._itemsTable.items[index])) {
return carousel._itemsTable.items[index];
}
}
return null;
},
/**
* Return all items as an array.
*
* @method getItems
* @return {Array} Return all items in the Carousel
* @public
*/
getItems: function () {
return this._itemsTable.items;
},
/**
* Return all loading items as an array.
*
* @method getLoadingItems
* @return {Array} Return all items that are loading in the Carousel.
* @public
*/
getLoadingItems: function () {
return this._itemsTable.loading;
},
/**
* For a multirow carousel, return the number of rows specified by user.
*
* @method getItems
* @return {Number} Number of rows
* @public
*/
getRows: function () {
return this._rows;
},
/**
* For a multirow carousel, return the number of cols specified by user.
*
* @method getItems
* @return {Array} Return all items in the Carousel
* @public
*/
getCols: function () {
return this._cols;
},
/**
* Return the position of the Carousel item that has the id "id", or -1
* if the id is not found.
*
* @method getItemPositionById
* @param index {Number} The index of the item to be returned
* @public
*/
getItemPositionById: function (id) {
var carousel = this,
n = carousel.get("numItems"),
i = 0,
items = carousel._itemsTable.items,
item;
while (i < n) {
item = items[i] || {};
if(item.id == id) {
return i;
}
i++;
}
return -1;
},
/**
* Return all visible items as an array.
*
* @method getVisibleItems
* @return {Array} The array of visible items
* @public
*/
getVisibleItems: function () {
var carousel = this,
i = carousel.get("firstVisible"),
n = i + carousel.get("numVisible"),
r = [];
while (i < n) {
r.push(carousel.getElementForItem(i));
i++;
}
return r;
},
/**
* Remove an item at index from the Carousel.
*
* @method removeItem
* @public
* @param index {Number} The position to where in the list (starts from
* zero).
* @return {Boolean} Return true on success, false otherwise
*/
removeItem: function (index) {
var carousel = this,
itemsTable = carousel._itemsTable,
item,
num = carousel.get("numItems");
if (index < 0 || index >= num) {
YAHOO.log("Index out of bounds", "error", WidgetName);
return false;
}
item = itemsTable.items.splice(index, 1);
if (item && item.length == 1) {
if(itemsTable.numItems){
itemsTable.numItems--;
}
carousel.set("numItems", num - 1);
carousel.fireEvent(itemRemovedEvent,
{ item: item[0], pos: index, ev: itemRemovedEvent });
return true;
}
return false;
},
/**
* Replace an item at index witin Carousel.
*
* @method replaceItem
* @public
* @param item {HTML | Object | HTMLElement} The item to be appended
* to the Carousel. If the parameter is a string, it is assumed to be
* the HTML content of the newly created item. If the parameter is an
* object, it is assumed to supply the content and an optional class
* and an optional id of the newly created item.
* @param index {Number} The position to where in the list (starts from
* zero).
* @return {Boolean} Return true on success, false otherwise
*/
replaceItem: function (item, index) {
var carousel = this,
className,
content,
elId,
numItems = carousel.get("numItems"),
oel,
el = item;
if (!item) {
return false;
}
if (JS.isString(item) || item.nodeName) {
content = item.nodeName ? item.innerHTML : item;
} else if (JS.isObject(item)) {
content = item.content;
} else {
YAHOO.log("Invalid argument to replaceItem", "error", WidgetName);
return false;
}
if (JS.isUndefined(index)) {
YAHOO.log("Index must be defined for replaceItem", "error", WidgetName);
return false;
} else {
if (index < 0 || index >= numItems) {
YAHOO.log("Index out of bounds in replaceItem", "error", WidgetName);
return false;
}
oel = carousel._itemsTable.items[index];
if(!oel){
oel = carousel._itemsTable.loading[index];
carousel._itemsTable.items[index] = undefined;
}
elId = oel.id || Dom.generateId();
carousel._itemsTable.items.splice(index, 1, {
item : content,
className : carousel.CLASSES.ITEM + (item.className ? " " + item.className : ""),
id : elId
});
el = carousel._itemsTable.items[index];
}
carousel.fireEvent(itemReplacedEvent,
{ newItem: el, oldItem: oel, pos: index, ev: itemReplacedEvent });
return true;
},
/**
* Replace multiple items at specified indexes.
* NOTE: item at index must already exist.
*
* @method replaceItems
* @public
* @param items {Array} An array containing an array of replacement items each linked to the
* index where the substitution should take place.
* E.g. [[{content:'<img/>'}, index1], [{content:'<img/>'}, index2]]
* @return {Boolean} Return true on success, false otherwise
*/
replaceItems: function (items) {
var i, n, rv = true;
if (!JS.isArray(items)) {
return false;
}
syncUiOnItemInsert = false;
for (i = 0, n = items.length; i < n; i++) {
if (this.replaceItem(items[i][0], items[i][1]) === false) {
rv = false;
}
}
syncUiOnItemInsert = true;
this._syncUiItems();
return rv;
},
/**
* Render the Carousel.
*
* @method render
* @public
* @param appendTo {HTMLElement | String} The element to which the
* Carousel should be appended prior to rendering.
* @return {Boolean} Status of the operation
*/
render: function (appendTo) {
var carousel = this,
cssClass = carousel.CLASSES,
rows = carousel._rows;
carousel.addClass(cssClass.CAROUSEL);
if (!carousel._clipEl) {
carousel._clipEl = carousel._createCarouselClip();
carousel._clipEl.appendChild(carousel._carouselEl);
}
if (appendTo) {
carousel.appendChild(carousel._clipEl);
carousel.appendTo(appendTo);
} else {
if (!Dom.inDocument(carousel.get("element"))) {
YAHOO.log("Nothing to render. The container should be " +
"within the document if appendTo is not " +
"specified", "error", WidgetName);
return false;
}
carousel.appendChild(carousel._clipEl);
}
if (rows) {
Dom.addClass(carousel._clipEl, cssClass.MULTI_ROW);
}
if (carousel.get("isVertical")) {
carousel.addClass(cssClass.VERTICAL);
} else {
carousel.addClass(cssClass.HORIZONTAL);
}
if (carousel.get("numItems") < 1) {
YAHOO.log("No items in the Carousel to render", "warn",
WidgetName);
return false;
}
carousel._refreshUi();
return true;
},
/**
* Scroll the Carousel by an item backward.
*
* @method scrollBackward
* @public
*/
scrollBackward: function () {
var carousel = this;
carousel.scrollTo(carousel._firstItem -
carousel.get("scrollIncrement"));
},
/**
* Scroll the Carousel by an item forward.
*
* @method scrollForward
* @public
*/
scrollForward: function () {
var carousel = this;
carousel.scrollTo(carousel._firstItem +
carousel.get("scrollIncrement"));
},
/**
* Scroll the Carousel by a page backward.
*
* @method scrollPageBackward
* @public
*/
scrollPageBackward: function () {
var carousel = this,
isVertical = carousel.get("isVertical"),
cols = carousel._cols,
firstVisible = carousel.get("firstVisible"),
item = firstVisible - carousel.get("numVisible");
if (item < 0) {
// Only account for multi-row when scrolling backwards from
// item 0
if (cols) {
item = firstVisible - cols;
}
}
carousel.scrollTo(item);
},
/**
* Scroll the Carousel by a page forward.
*
* @method scrollPageForward
* @public
*/
scrollPageForward: function () {
var carousel = this,
item = carousel._firstItem + carousel.get("numVisible");
if (item > carousel.get("numItems")) {
item = 0;
}
if (carousel.get("selectOnScroll")) {
carousel._selectedItem = carousel._getSelectedItem(item);
}
carousel.scrollTo(item);
},
/**
* Scroll the Carousel to make the item the first visible item.
*
* @method scrollTo
* @public
* @param item Number The index of the element to position at.
* @param dontSelect Boolean True if select should be avoided
*/
scrollTo: function (item, dontSelect) {
var carousel = this, animate, animCfg, isCircular, isVertical,
delta, direction, firstItem, lastItem, itemsPerRow,
itemsPerCol, numItems, numPerPage, offset, page, rv, sentinel,
index, stopAutoScroll,
itemsTable = carousel._itemsTable;
if (itemsTable.numItems === 0 || item == carousel._firstItem ||
carousel.isAnimating()) {
return; // nothing to do!
}
animCfg = carousel.get("animation");
isCircular = carousel.get("isCircular");
isVertical = carousel.get("isVertical");
itemsPerRow = carousel._cols;
itemsPerCol = carousel._rows;
firstItem = carousel._firstItem;
numItems = carousel.get("numItems");
numPerPage = carousel.get("numVisible");
page = carousel.get("currentPage");
stopAutoScroll = function () {
if (carousel.isAutoPlayOn()) {
carousel.stopAutoPlay();
}
};
if (item < 0) {
if (isCircular) {
// Normalize the offset so that it doesn't scroll to a
// different index when number of items is not a factor of
// the number of visible items
if (numItems % numPerPage !== 0) {
item = numItems + (numItems%numPerPage) - numPerPage-1;
} else {
item = numItems + item;
}
} else {
stopAutoScroll.call(carousel);
return;
}
} else if (numItems > 0 && item > numItems - 1) {
if (carousel.get("isCircular")) {
item = numItems - item;
} else {
stopAutoScroll.call(carousel);
return;
}
}
if (isNaN(item)) {
return;
}
direction = (carousel._firstItem > item) ? "backward" : "forward";
sentinel = firstItem + numPerPage;
sentinel = (sentinel > numItems - 1) ? numItems - 1 : sentinel;
rv = carousel.fireEvent(beforeScrollEvent,
{ dir: direction, first: firstItem, last: sentinel });
if (rv === false) { // scrolling is prevented
return;
}
carousel.fireEvent(beforePageChangeEvent, { page: page });
// call loaditems to check if we have all the items to display
lastItem = item + numPerPage - 1;
carousel._loadItems(lastItem > numItems-1 ? numItems-1 : lastItem);
// Calculate the delta relative to the first item, the delta is
// always negative.
delta = 0 - item;
if (itemsPerCol) {
// offset calculations for multirow Carousel
if (isVertical) {
delta = parseInt(delta / itemsPerRow, 10);
} else {
delta = parseInt(delta / itemsPerCol, 10);
}
}
carousel._firstItem = item;
carousel.set("firstVisible", item);
if (!dontSelect && carousel.get("selectOnScroll")) {
carousel._selectedItem = item;
}
YAHOO.log("Scrolling to " + item + " delta = " + delta, WidgetName);
sentinel = item + numPerPage;
sentinel = (sentinel > numItems - 1) ? numItems - 1 : sentinel;
offset = getScrollOffset.call(carousel, delta);
YAHOO.log("Scroll offset = " + offset, WidgetName);
animate = animCfg.speed > 0;
if (animate) {
carousel._animateAndSetCarouselOffset(offset, item, sentinel,
dontSelect);
} else {
carousel._setCarouselOffset(offset);
updateStateAfterScroll.call(carousel, item, sentinel);
}
},
/**
* Get the page an item is on within carousel.
*
* @method getPageForItem
* @public
* @param index {Number} Index of item
* @return {Number} Page item is on
*/
getPageForItem : function(item) {
return Math.ceil(
(item+1) / parseInt(this.get("numVisible"),10)
);
},
/**
* Get the first visible item's index on any given page.
*
* @method getFirstVisibleOnpage
* @public
* @param page {Number} Page
* @return {Number} First item's index
*/
getFirstVisibleOnPage : function(page) {
return (page - 1) * this.get("numVisible");
},
/**
* Select the previous item in the Carousel.
*
* @method selectPreviousItem
* @public
*/
selectPreviousItem: function () {
var carousel = this,
newpos = 0,
selected = carousel.get("selectedItem");
if (selected == carousel._firstItem) {
newpos = selected - carousel.get("numVisible");
carousel._selectedItem = carousel._getSelectedItem(selected-1);
// since we have selected the item already
carousel.scrollTo(newpos, true);
} else {
newpos = carousel.get("selectedItem") -
carousel.get("scrollIncrement");
carousel.set("selectedItem",carousel._getSelectedItem(newpos));
}
},
/**
* Select the next item in the Carousel.
*
* @method selectNextItem
* @public
*/
selectNextItem: function () {
var carousel = this, newpos = 0;
newpos = carousel.get("selectedItem") +
carousel.get("scrollIncrement");
carousel.set("selectedItem", carousel._getSelectedItem(newpos));
},
/**
* Display the Carousel.
*
* @method show
* @public
*/
show: function () {
var carousel = this,
cssClass = carousel.CLASSES;
if (carousel.fireEvent(beforeShowEvent) !== false) {
carousel.addClass(cssClass.VISIBLE);
showNavigation.call(carousel);
carousel.fireEvent(showEvent);
}
},
/**
* Start auto-playing the Carousel.
*
* @method startAutoPlay
* @public
*/
startAutoPlay: function () {
var carousel = this, timer;
if (JS.isUndefined(carousel._autoPlayTimer)) {
timer = carousel.get("autoPlayInterval");
if (timer <= 0) {
return;
}
carousel._isAutoPlayInProgress = true;
carousel.fireEvent(startAutoPlayEvent);
carousel._autoPlayTimer = setTimeout(function () {
carousel._autoScroll();
}, timer);
}
},
/**
* Stop auto-playing the Carousel.
*
* @method stopAutoPlay
* @public
*/
stopAutoPlay: function () {
var carousel = this;
if (!JS.isUndefined(carousel._autoPlayTimer)) {
clearTimeout(carousel._autoPlayTimer);
delete carousel._autoPlayTimer;
carousel._isAutoPlayInProgress = false;
carousel.fireEvent(stopAutoPlayEvent);
}
},
/**
* Update interface's pagination data within a registered template.
*
* @method updatePagination
* @public
*/
updatePagination: function () {
var carousel = this,
pagination = carousel._pagination;
if(!pagination.el){ return false; }
var numItems = carousel.get('numItems'),
numVisible = carousel.get('numVisible'),
firstVisible = carousel.get('firstVisible')+1,
currentPage = carousel.get('currentPage')+1,
numPages = carousel.get('numPages'),
replacements = {
'numVisible' : numVisible,
'numPages' : numPages,
'numItems' : numItems,
'selectedItem' : carousel.get('selectedItem')+1,
'currentPage' : currentPage,
'firstVisible' : firstVisible,
'lastVisible' : carousel.get("lastVisible")+1
},
cb = pagination.callback || {},
scope = cb.scope && cb.obj ? cb.obj : carousel;
pagination.el.innerHTML = JS.isFunction(cb.fn) ? cb.fn.apply(scope, [pagination.template, replacements]) : YAHOO.lang.substitute(pagination.template, replacements);
},
/**
* Register carousels pagination template, append to interface, and populate.
*
* @method registerPagination
* @param template {String} Pagination template as passed to lang.substitute
* @public
*/
registerPagination: function (tpl, pos, cb) {
var carousel = this;
carousel._pagination.template = tpl;
carousel._pagination.callback = cb || {};
if(!carousel._pagination.el){
carousel._pagination.el = createElement('DIV', {className:carousel.CLASSES.PAGINATION});
if(pos == "before"){
carousel._navEl.insertBefore(carousel._pagination.el, carousel._navEl.firstChild);
} else {
carousel._navEl.appendChild(carousel._pagination.el);
}
carousel.on('itemSelected', carousel.updatePagination);
carousel.on('pageChange', carousel.updatePagination);
}
carousel.updatePagination();
},
/**
* Return the string representation of the Carousel.
*
* @method toString
* @public
* @return {String}
*/
toString: function () {
return WidgetName + (this.get ? " (#" + this.get("id") + ")" : "");
},
/*
* Protected methods of the Carousel component
*/
/**
* Set the Carousel offset to the passed offset after animating.
*
* @method _animateAndSetCarouselOffset
* @param {Integer} offset The offset to which the Carousel has to be
* scrolled to.
* @param {Integer} item The index to which the Carousel will scroll.
* @param {Integer} sentinel The last element in the view port.
* @protected
*/
_animateAndSetCarouselOffset: function (offset, item, sentinel) {
var carousel = this,
animCfg = carousel.get("animation"),
animObj = null;
if (carousel.get("isVertical")) {
animObj = new YAHOO.util.Motion(carousel._carouselEl,
{ top: { to: offset } },
animCfg.speed, animCfg.effect);
} else {
animObj = new YAHOO.util.Motion(carousel._carouselEl,
{ left: { to: offset } },
animCfg.speed, animCfg.effect);
}
carousel._isAnimationInProgress = true;
animObj.onComplete.subscribe(carousel._animationCompleteHandler,
{ scope: carousel, item: item,
last: sentinel });
animObj.animate();
},
/**
* Handle the animation complete event.
*
* @method _animationCompleteHandler
* @param {Event} ev The event.
* @param {Array} p The event parameters.
* @param {Object} o The object that has the state of the Carousel
* @protected
*/
_animationCompleteHandler: function (ev, p, o) {
o.scope._isAnimationInProgress = false;
updateStateAfterScroll.call(o.scope, o.item, o.last);
},
/**
* Automatically scroll the contents of the Carousel.
* @method _autoScroll
* @protected
*/
_autoScroll: function() {
var carousel = this,
currIndex = carousel._firstItem,
index;
if (currIndex >= carousel.get("numItems") - 1) {
if (carousel.get("isCircular")) {
index = 0;
} else {
carousel.stopAutoPlay();
}
} else {
index = currIndex + carousel.get("numVisible");
}
carousel._selectedItem = carousel._getSelectedItem(index);
carousel.scrollTo.call(carousel, index);
},
/**
* Create the Carousel.
*
* @method createCarousel
* @param elId {String} The id of the element to be created
* @protected
*/
_createCarousel: function (elId) {
var carousel = this,
cssClass = carousel.CLASSES,
el = Dom.get(elId);
if (!el) {
el = createElement("DIV", {
className : cssClass.CAROUSEL,
id : elId
});
}
if (!carousel._carouselEl) {
carousel._carouselEl=createElement(carousel.get("carouselEl"),
{ className: cssClass.CAROUSEL_EL });
}
return el;
},
/**
* Create the Carousel clip container.
*
* @method createCarouselClip
* @protected
*/
_createCarouselClip: function () {
return createElement("DIV", { className: this.CLASSES.CONTENT });
},
/**
* Create the Carousel item.
*
* @method createCarouselItem
* @param obj {Object} The attributes of the element to be created
* @protected
*/
_createCarouselItem: function (obj) {
var attr, carousel = this;
return createElement(carousel.get("carouselItemEl"), {
className : obj.className,
styles : {},
content : obj.content,
id : obj.id
});
},
/**
* Return a valid item for a possibly out of bounds index considering
* the isCircular property.
*
* @method _getValidIndex
* @param index {Number} The index of the item to be returned
* @return {Object} Return a valid item index
* @protected
*/
_getValidIndex: function (index) {
var carousel = this,
isCircular = carousel.get("isCircular"),
numItems = carousel.get("numItems"),
numVisible = carousel.get("numVisible"),
sentinel = numItems - 1;
if (index < 0) {
index = isCircular ?
Math.ceil(numItems/numVisible)*numVisible + index : 0;
} else if (index > sentinel) {
index = isCircular ? 0 : sentinel;
}
return index;
},
/**
* Get the value for the selected item.
*
* @method _getSelectedItem
* @param val {Number} The new value for "selected" item
* @return {Number} The new value that would be set
* @protected
*/
_getSelectedItem: function (val) {
var carousel = this,
isCircular = carousel.get("isCircular"),
numItems = carousel.get("numItems"),
sentinel = numItems - 1;
if (val < 0) {
if (isCircular) {
val = numItems + val;
} else {
val = carousel.get("selectedItem");
}
} else if (val > sentinel) {
if (isCircular) {
val = val - numItems;
} else {
val = carousel.get("selectedItem");
}
}
return val;
},
/**
* The "focus" handler for a Carousel.
*
* @method _focusHandler
* @param {Event} ev The event object
* @protected
*/
_focusHandler: function() {
var carousel = this;
if (carousel._hasFocus) {
carousel.focus();
}
},
/**
* The "click" handler for the item.
*
* @method _itemClickHandler
* @param {Event} ev The event object
* @protected
*/
_itemClickHandler: function (ev) {
var carousel = this,
carouselItem = carousel.get("carouselItemEl"),
container = carousel.get("element"),
el,
item,
target = Event.getTarget(ev),
tag = target.tagName.toUpperCase();
if(tag === "INPUT" ||
tag === "SELECT" ||
tag === "TEXTAREA") {
return;
}
while (target && target != container &&
target.id != carousel._carouselEl) {
el = target.nodeName;
if (el.toUpperCase() == carouselItem) {
break;
}
target = target.parentNode;
}
if ((item = carousel.getItemPositionById(target.id)) >= 0) {
YAHOO.log("Setting selection to " + item, WidgetName);
carousel.set("selectedItem", carousel._getSelectedItem(item));
carousel.focus();
}
},
/**
* The keyboard event handler for Carousel.
*
* @method _keyboardEventHandler
* @param ev {Event} The event that is being handled.
* @protected
*/
_keyboardEventHandler: function (ev) {
var carousel = this,
key = Event.getCharCode(ev),
target = Event.getTarget(ev),
prevent = false;
// do not mess while animation is in progress or naving via select
if (carousel.isAnimating() || target.tagName.toUpperCase() === "SELECT") {
return;
}
switch (key) {
case 0x25: // left arrow
case 0x26: // up arrow
carousel.selectPreviousItem();
prevent = true;
break;
case 0x27: // right arrow
case 0x28: // down arrow
carousel.selectNextItem();
prevent = true;
break;
case 0x21: // page-up
carousel.scrollPageBackward();
prevent = true;
break;
case 0x22: // page-down
carousel.scrollPageForward();
prevent = true;
break;
}
if (prevent) {
if (carousel.isAutoPlayOn()) {
carousel.stopAutoPlay();
}
Event.preventDefault(ev);
}
},
/**
* The load the required set of items that are needed for display.
*
* @method _loadItems
* @protected
*/
_loadItems: function(last) {
var carousel = this,
numItems = carousel.get("numItems"),
numVisible = carousel.get("numVisible"),
reveal = carousel.get("revealAmount"),
first = carousel._itemsTable.items.length,
lastVisible = carousel.get("lastVisible");
// adjust if going backwards
if(first > last && last+1 >= numVisible){
// need to get first a bit differently for the last page
first = last % numVisible || last == lastVisible ? last - last % numVisible : last - numVisible + 1;
}
if(reveal && last < numItems - 1){ last++; }
if (last >= first && (!carousel.getItem(first) || !carousel.getItem(last))) {
carousel.fireEvent(loadItemsEvent, {
ev: loadItemsEvent, first: first, last: last,
num: last - first + 1
});
}
},
/**
* The "onchange" handler for select box pagination.
*
* @method _pagerChangeHandler
* @param {Event} ev The event object
* @protected
*/
_pagerChangeHandler: function (ev) {
var carousel = this,
target = Event.getTarget(ev),
page = target.value,
item;
if (page) {
item = carousel.getFirstVisibleOnPage(page);
carousel._selectedItem = item;
carousel.scrollTo(item);
carousel.focus();
}
},
/**
* The "click" handler for anchor pagination.
*
* @method _pagerClickHandler
* @param {Event} ev The event object
* @protected
*/
_pagerClickHandler: function (ev) {
var carousel = this,
css = carousel.CLASSES,
target = Event.getTarget(ev),
elNode = target.nodeName.toUpperCase(),
val,
stringIndex,
page,
item;
if (Dom.hasClass(target, css.PAGER_ITEM) || Dom.hasClass(target.parentNode, css.PAGER_ITEM)) {
if (elNode == "EM") {
target = target.parentNode;// item is an em and not an anchor (when text is visible)
}
val = target.href;
stringIndex = val.lastIndexOf("#");
page = parseInt(val.substring(stringIndex+1), 10);
if (page != -1) {
item = carousel.getFirstVisibleOnPage(page);
carousel._selectedItem = item;
carousel.scrollTo(item);
carousel.focus();
}
Event.preventDefault(ev);
}
},
/**
* Find the Carousel within a container. The Carousel is identified by
* the first element that matches the carousel element tag or the
* element that has the Carousel class.
*
* @method parseCarousel
* @param parent {HTMLElement} The parent element to look under
* @return {Boolean} True if Carousel is found, false otherwise
* @protected
*/
_parseCarousel: function (parent) {
var carousel = this, child, cssClass, domEl, found, node;
cssClass = carousel.CLASSES;
domEl = carousel.get("carouselEl");
found = false;
for (child = parent.firstChild; child; child = child.nextSibling) {
if (child.nodeType == 1) {
node = child.nodeName;
if (node.toUpperCase() == domEl) {
carousel._carouselEl = child;
Dom.addClass(carousel._carouselEl,
carousel.CLASSES.CAROUSEL_EL);
YAHOO.log("Found Carousel - " + node +
(child.id ? " (#" + child.id + ")" : ""),
WidgetName);
found = true;
}
}
}
return found;
},
/**
* Find the items within the Carousel and add them to the items table.
* A Carousel item is identified by elements that matches the carousel
* item element tag.
*
* @method parseCarouselItems
* @protected
*/
_parseCarouselItems: function () {
var carousel = this,
cssClass = carousel.CLASSES,
i=0,
rows,
child,
domItemEl,
elId,
node,
index = carousel.get("firstVisible"),
parent = carousel._carouselEl;
rows = carousel._rows;
domItemEl = carousel.get("carouselItemEl");
for (child = parent.firstChild; child; child = child.nextSibling) {
if (child.nodeType == 1) {
node = child.nodeName;
if (node.toUpperCase() == domItemEl) {
if (child.id) {
elId = child.id;
} else {
elId = Dom.generateId();
child.setAttribute("id", elId);
Dom.addClass(child, carousel.CLASSES.ITEM);
}
carousel.addItem(child,index);
index++;
}
}
}
},
/**
* Find the Carousel navigation within a container. The navigation
* elements need to match the carousel navigation class names.
*
* @method parseCarouselNavigation
* @param parent {HTMLElement} The parent element to look under
* @return {Boolean} True if at least one is found, false otherwise
* @protected
*/
_parseCarouselNavigation: function (parent) {
var carousel = this,
cfg,
cssClass = carousel.CLASSES,
el,
i,
j,
nav,
rv = false;
nav = Dom.getElementsByClassName(cssClass.PREV_PAGE, "*", parent);
if (nav.length > 0) {
for (i in nav) {
if (nav.hasOwnProperty(i)) {
el = nav[i];
YAHOO.log("Found Carousel previous page navigation - " +
el + (el.id ? " (#" + el.id + ")" : ""),
WidgetName);
if (el.nodeName == "INPUT" ||
el.nodeName == "BUTTON" ||
el.nodeName == "A") {// Anchor support in Nav (for SEO)
carousel._navBtns.prev.push(el);
} else {
j = el.getElementsByTagName("INPUT");
if (JS.isArray(j) && j.length > 0) {
carousel._navBtns.prev.push(j[0]);
} else {
j = el.getElementsByTagName("BUTTON");
if (JS.isArray(j) && j.length > 0) {
carousel._navBtns.prev.push(j[0]);
}
}
}
}
}
cfg = { prev: nav };
}
nav = Dom.getElementsByClassName(cssClass.NEXT_PAGE, "*", parent);
if (nav.length > 0) {
for (i in nav) {
if (nav.hasOwnProperty(i)) {
el = nav[i];
YAHOO.log("Found Carousel next page navigation - " +
el + (el.id ? " (#" + el.id + ")" : ""),
WidgetName);
if (el.nodeName == "INPUT" ||
el.nodeName == "BUTTON" ||
el.nodeName == "A") {// Anchor support in Nav (for SEO)
carousel._navBtns.next.push(el);
} else {
j = el.getElementsByTagName("INPUT");
if (JS.isArray(j) && j.length > 0) {
carousel._navBtns.next.push(j[0]);
} else {
j = el.getElementsByTagName("BUTTON");
if (JS.isArray(j) && j.length > 0) {
carousel._navBtns.next.push(j[0]);
}
}
}
}
}
if (cfg) {
cfg.next = nav;
} else {
cfg = { next: nav };
}
}
if (cfg) {
carousel.set("navigation", cfg);
rv = true;
}
return rv;
},
/**
* Refresh the widget UI if it is not already rendered, on first item
* addition.
*
* @method _refreshUi
* @protected
*/
_refreshUi: function () {
var carousel = this,
isVertical = carousel.get("isVertical"),
firstVisible = carousel.get("firstVisible"),
i, item, n, rsz, sz;
if (carousel._itemsTable.numItems < 1) {
return;
}
sz = getCarouselItemSize.call(carousel,
isVertical ? "height" : "width");
// This fixes the widget to auto-adjust height/width for absolute
// positioned children.
item = carousel._itemsTable.items[firstVisible].id;
sz = isVertical ? getStyle(item, "width") :
getStyle(item, "height");
Dom.setStyle(carousel._carouselEl,
isVertical ? "width" : "height", sz + "px");
// Set the rendered state appropriately.
carousel._hasRendered = true;
carousel.fireEvent(renderEvent);
},
/**
* Set the Carousel offset to the passed offset.
*
* @method _setCarouselOffset
* @protected
*/
_setCarouselOffset: function (offset) {
var carousel = this, which;
which = carousel.get("isVertical") ? "top" : "left";
Dom.setStyle(carousel._carouselEl, which, offset + "px");
},
/**
* Setup/Create the Carousel navigation element (if needed).
*
* @method _setupCarouselNavigation
* @protected
*/
_setupCarouselNavigation: function () {
var carousel = this,
btn, cfg, cssClass, nav, navContainer, nextButton, prevButton;
cssClass = carousel.CLASSES;
// can the _navBtns be tested against instead?
navContainer = Dom.getElementsByClassName(cssClass.NAVIGATION,
"DIV", carousel.get("element"));
if (navContainer.length === 0) {
navContainer = createElement("DIV",
{ className: cssClass.NAVIGATION });
carousel.insertBefore(navContainer,
Dom.getFirstChild(carousel.get("element")));
} else {
navContainer = navContainer[0];
}
carousel._pages.el = createElement("UL");
navContainer.appendChild(carousel._pages.el);
nav = carousel.get("navigation");
if (JS.isString(nav.prev) || JS.isArray(nav.prev)) {
if (JS.isString(nav.prev)) {
nav.prev = [nav.prev];
}
for (btn in nav.prev) {
if (nav.prev.hasOwnProperty(btn)) {
carousel._navBtns.prev.push(Dom.get(nav.prev[btn]));
}
}
} else {
prevButton = createElement("SPAN",
{ className: cssClass.BUTTON + cssClass.FIRST_NAV });
Dom.setStyle(prevButton, "visibility", "visible");
btn = Dom.generateId();
prevButton.innerHTML = "<button type=\"button\" " +
"id=\"" + btn + "\" name=\"" +
carousel.STRINGS.PREVIOUS_BUTTON_TEXT + "\">" +
carousel.STRINGS.PREVIOUS_BUTTON_TEXT + "</button>";
navContainer.appendChild(prevButton);
btn = Dom.get(btn);
carousel._navBtns.prev = [btn];
cfg = { prev: [prevButton] };
}
if (JS.isString(nav.next) || JS.isArray(nav.next)) {
if (JS.isString(nav.next)) {
nav.next = [nav.next];
}
for (btn in nav.next) {
if (nav.next.hasOwnProperty(btn)) {
carousel._navBtns.next.push(Dom.get(nav.next[btn]));
}
}
} else {
nextButton = createElement("SPAN",
{ className: cssClass.BUTTON + cssClass.NEXT_NAV });
Dom.setStyle(nextButton, "visibility", "visible");
btn = Dom.generateId();
nextButton.innerHTML = "<button type=\"button\" " +
"id=\"" + btn + "\" name=\"" +
carousel.STRINGS.NEXT_BUTTON_TEXT + "\">" +
carousel.STRINGS.NEXT_BUTTON_TEXT + "</button>";
navContainer.appendChild(nextButton);
btn = Dom.get(btn);
carousel._navBtns.next = [btn];
if (cfg) {
cfg.next = [nextButton];
} else {
cfg = { next: [nextButton] };
}
}
if (cfg) {
carousel.set("navigation", cfg);
}
return navContainer;
},
/**
* Set the clip container size (based on the new numVisible value).
*
* @method _setClipContainerSize
* @param clip {HTMLElement} The clip container element.
* @param num {Number} optional The number of items per page.
* @protected
*/
_setClipContainerSize: function (clip, num) {
var carousel = this,
isVertical = carousel.get("isVertical"),
rows = carousel._rows,
cols = carousel._cols,
reveal = carousel.get("revealAmount"),
itemHeight = getCarouselItemSize.call(carousel, "height"),
itemWidth = getCarouselItemSize.call(carousel, "width"),
containerHeight,
containerWidth;
carousel._recomputeSize = (containerHeight === 0); // bleh!
if (carousel._recomputeSize) {
carousel._hasRendered = false;
return; // no use going further, bail out!
}
clip = clip || carousel._clipEl;
if (rows) {
containerHeight = itemHeight * rows;
containerWidth = itemWidth * cols;
} else {
num = num || carousel.get("numVisible");
if (isVertical) {
containerHeight = itemHeight * num;
} else {
containerWidth = itemWidth * num;
}
}
reveal = getRevealSize.call(carousel);
if (isVertical) {
containerHeight += (reveal * 2);
} else {
containerWidth += (reveal * 2);
}
if (isVertical) {
containerHeight += getDimensions(carousel._carouselEl,"height");
Dom.setStyle(clip, "height", containerHeight + "px");
// For multi-row Carousel
if (cols) {
containerWidth += getDimensions(carousel._carouselEl,
"width");
Dom.setStyle(clip, "width", containerWidth + (0) + "px");
}
} else {
containerWidth += getDimensions(carousel._carouselEl, "width");
Dom.setStyle(clip, "width", containerWidth + "px");
// For multi-row Carousel
if (rows) {
containerHeight += getDimensions(carousel._carouselEl,
"height");
Dom.setStyle(clip, "height", containerHeight + "px");
}
}
if (clip) {
carousel._setContainerSize(clip); // adjust the container size
}
},
/**
* Set the container size.
*
* @method _setContainerSize
* @param clip {HTMLElement} The clip container element.
* @param attr {String} Either set the height or width.
* @protected
*/
_setContainerSize: function (clip, attr) {
var carousel = this,
config = carousel.CONFIG,
cssClass = carousel.CLASSES,
isVertical,
rows,
cols,
size;
isVertical = carousel.get("isVertical");
rows = carousel._rows;
cols = carousel._cols;
clip = clip || carousel._clipEl;
attr = attr || (isVertical ? "height" : "width");
size = parseFloat(Dom.getStyle(clip, attr), 10);
size = JS.isNumber(size) ? size : 0;
if (isVertical) {
size += getDimensions(carousel._carouselEl, "height") +
getStyle(carousel._navEl, "height");
} else {
size += getDimensions(carousel._carouselEl, "width");
}
if (!isVertical) {
if (size < config.HORZ_MIN_WIDTH) {
size = config.HORZ_MIN_WIDTH;
carousel.addClass(cssClass.MIN_WIDTH);
}
}
carousel.setStyle(attr, size + "px");
// Additionally the width of the container should be set for
// the vertical Carousel
if (isVertical) {
size = getCarouselItemSize.call(carousel, "width");
if(cols) {
size = size * cols;
}
// Bug fix for vertical carousel (goes in conjunction with
// .yui-carousel-element {... 3200px removed from styles), and
// allows for multirows in IEs).
Dom.setStyle(carousel._carouselEl, "width", size + "px");
if (size < config.VERT_MIN_WIDTH) {
size = config.VERT_MIN_WIDTH;
// set a min width on vertical carousel, don't see why this
// shouldn't always be set...
carousel.addClass(cssClass.MIN_WIDTH);
}
carousel.setStyle("width", size + "px");
} else {
/*
* Fix for automatically computing the height and width in IE.
* Many thanks to ErisDS for the fix.
* For more information visit,
* http://erisds.co.uk/code/yui2-javascript-carousel-an-update-about-version-2-8
*/
size = getCarouselItemSize.call(carousel, "height");
if (rows) {
size = size * rows;
}
Dom.setStyle(carousel._carouselEl, "height", size + "px");
}
},
/**
* Set the value for the Carousel's first visible item.
*
* @method _setFirstVisible
* @param val {Number} The new value for firstVisible
* @return {Number} The new value that would be set
* @protected
*/
_setFirstVisible: function (val) {
var carousel = this;
if (val >= 0 && val < carousel.get("numItems")) {
carousel.scrollTo(val);
} else {
val = carousel.get("firstVisible");
}
return val;
},
/**
* Set the value for the Carousel's navigation.
*
* @method _setNavigation
* @param cfg {Object} The navigation configuration
* @return {Object} The new value that would be set
* @protected
*/
_setNavigation: function (cfg) {
var carousel = this;
if (cfg.prev) {
Event.on(cfg.prev, "click", scrollPageBackward, carousel);
}
if (cfg.next) {
Event.on(cfg.next, "click", scrollPageForward, carousel);
}
},
/**
* Clip the container size every time numVisible is set.
*
* @method _setNumVisible
* @param val {Number} The new value for numVisible
* @return {Number} The new value that would be set
* @protected
*/
_setNumVisible: function (val) { // _setNumVisible should just be reserved for setting numVisible.
var carousel = this;
carousel._setClipContainerSize(carousel._clipEl, val);
},
/**
* Set the value for the number of visible items in the Carousel.
*
* @method _numVisibleSetter
* @param val {Number} The new value for numVisible
* @return {Number} The new value that would be set
* @protected
*/
_numVisibleSetter: function (val) {
var carousel = this,
numVisible = val;
if(JS.isArray(val)) {
carousel._cols = val[0];
carousel._rows = val[1];
numVisible = val[0] * val[1];
}
return numVisible;
},
/**
* Set the value for selectedItem.
*
* @method _selectedItemSetter
* @param val {Number} The new value for selectedItem
* @return {Number} The new value that would be set
* @protected
*/
_selectedItemSetter: function (val) {
var carousel = this;
return (val < carousel.get("numItems")) ? val : 0;
},
/**
* Set the number of items in the Carousel.
* Warning: Setting this to a lower number than the current removes
* items from the end.
*
* @method _setNumItems
* @param val {Number} The new value for numItems
* @return {Number} The new value that would be set
* @protected
*/
_setNumItems: function (val) {
var carousel = this,
num = carousel._itemsTable.numItems;
if (JS.isArray(carousel._itemsTable.items)) {
if (carousel._itemsTable.items.length != num) { // out of sync
num = carousel._itemsTable.items.length;
carousel._itemsTable.numItems = num;
}
}
if (val < num) {
while (num > val) {
carousel.removeItem(num - 1);
num--;
}
}
return val;
},
/**
* Set the orientation of the Carousel.
*
* @method _setOrientation
* @param val {Boolean} The new value for isVertical
* @return {Boolean} The new value that would be set
* @protected
*/
_setOrientation: function (val) {
var carousel = this,
cssClass = carousel.CLASSES;
if (val) {
carousel.replaceClass(cssClass.HORIZONTAL, cssClass.VERTICAL);
} else {
carousel.replaceClass(cssClass.VERTICAL, cssClass.HORIZONTAL);
}
/*
The _itemAttrCache need not be emptied since the cache is for
DOM attributes that do not change; not the Carousel dimensions.
*/
return val;
},
/**
* Set the value for the reveal amount percentage in the Carousel.
*
* @method _setRevealAmount
* @param val {Number} The new value for revealAmount
* @return {Number} The new value that would be set
* @protected
*/
_setRevealAmount: function (val) {
var carousel = this;
if (val >= 0 && val <= 100) {
val = parseInt(val, 10);
val = JS.isNumber(val) ? val : 0;
carousel._setClipContainerSize();
} else {
val = carousel.get("revealAmount");
}
return val;
},
/**
* Set the value for the selected item.
*
* @method _setSelectedItem
* @param val {Number} The new value for "selected" item
* @protected
*/
_setSelectedItem: function (val) {
this._selectedItem = val;
},
/**
* Get the total number of pages.
*
* @method _getNumPages
* @protected
*/
_getNumPages: function () {
return Math.ceil(
parseInt(this.get("numItems"),10) / parseInt(this.get("numVisible"),10)
);
},
/**
* Get the last visible item.
*
* @method _getLastVisible
* @protected
*/
_getLastVisible: function () {
var carousel = this;
return carousel.get("currentPage") + 1 == carousel.get("numPages") ?
carousel.get("numItems") - 1:
carousel.get("firstVisible") + carousel.get("numVisible") - 1;
},
/**
* Synchronize and redraw the UI after an item is added.
*
* @method _syncUiForItemAdd
* @protected
*/
_syncUiForItemAdd: function (obj) {
var attr,
carousel = this,
carouselEl = carousel._carouselEl,
el,
item,
itemsTable = carousel._itemsTable,
oel,
pos,
sibling,
styles;
pos = JS.isUndefined(obj.pos) ?
obj.newPos || itemsTable.numItems - 1 : obj.pos;
if (!oel) {
item = itemsTable.items[pos] || {};
el = carousel._createCarouselItem({
className : item.className,
styles : item.styles,
content : item.item,
id : item.id,
pos : pos
});
if (JS.isUndefined(obj.pos)) {
if (!JS.isUndefined(itemsTable.loading[pos])) {
oel = itemsTable.loading[pos];
// if oel is null, it is a problem ...
}
if (oel) {
// replace the node
carouselEl.replaceChild(el, oel);
// ... and remove the item from the data structure
delete itemsTable.loading[pos];
} else {
carouselEl.appendChild(el);
}
} else {
if (!JS.isUndefined(itemsTable.items[obj.pos + 1])) {
sibling = Dom.get(itemsTable.items[obj.pos + 1].id);
}
if (sibling) {
carouselEl.insertBefore(el, sibling);
} else {
YAHOO.log("Unable to find sibling","error",WidgetName);
}
}
} else {
if (JS.isUndefined(obj.pos)) {
if (!Dom.isAncestor(carousel._carouselEl, oel)) {
carouselEl.appendChild(oel);
}
} else {
if (!Dom.isAncestor(carouselEl, oel)) {
if (!JS.isUndefined(itemsTable.items[obj.pos + 1])) {
carouselEl.insertBefore(oel,
Dom.get(itemsTable.items[obj.pos + 1].id));
}
}
}
}
if (!carousel._hasRendered) {
carousel._refreshUi();
}
if (carousel.get("selectedItem") < 0) {
carousel.set("selectedItem", carousel.get("firstVisible"));
}
carousel._syncUiItems();
},
/**
* Synchronize and redraw the UI after an item is replaced.
*
* @method _syncUiForItemReplace
* @protected
*/
_syncUiForItemReplace: function (o) {
var carousel = this,
carouselEl = carousel._carouselEl,
itemsTable = carousel._itemsTable,
pos = o.pos,
item = o.newItem,
oel = o.oldItem,
el;
el = carousel._createCarouselItem({
className : item.className,
styles : item.styles,
content : item.item,
id : oel.id
});
// replace the current item's attributes
if ((oel = Dom.get(oel.id))) { // testing assignment
oel.className = item.className;
oel.styles = item.styles;
oel.innerHTML = item.item;
itemsTable.items[pos] = el;
if (itemsTable.loading[pos]) {
itemsTable.numItems++;
delete itemsTable.loading[pos];
}
}
// sync shouldn't be necessary since we're replacing items that are already positioned
//carousel._syncUiItems();
},
/**
* Synchronize and redraw the UI after an item is removed.
*
* @method _syncUiForItemRemove
* @protected
*/
_syncUiForItemRemove: function (obj) {
var carousel = this,
carouselEl = carousel._carouselEl,
el, item, num, pos;
num = carousel.get("numItems");
item = obj.item;
pos = obj.pos;
if (item && (el = Dom.get(item.id))) {
if (el && Dom.isAncestor(carouselEl, el)) {
Event.purgeElement(el, true);
carouselEl.removeChild(el);
}
// nothing is done w/ pos after this, should we remove it?
if (carousel.get("selectedItem") == pos) {
pos = pos >= num ? num - 1 : pos;
}
} else {
YAHOO.log("Unable to find item", "warn", WidgetName);
}
carousel._syncUiItems();
},
/**
* Find the closest sibling to insert before
*
* @method _findClosestSibling
* @protected
*/
_findClosestSibling: function (pos) {
var carousel = this,
itemsTable = carousel._itemsTable,
len = itemsTable.items.length,
j = pos,
sibling;
// attempt to find the next closest sibling
while (j<len && !sibling) {
sibling = itemsTable.items[++j];
}
return sibling;
},
/**
* Synchronize the items table for lazy loading.
*
* @method _syncUiForLazyLoading
* @protected
*/
_syncUiForLazyLoading: function (obj) {
var carousel = this,
carouselEl = carousel._carouselEl,
itemsTable = carousel._itemsTable,
len = itemsTable.items.length,
sibling = carousel._findClosestSibling(obj.last),
last = obj.last,
// only add DOM nodes for the currently visible items
// this eliminates uneccessary performance overhead
// but still allows loading styles to be applied to the items
first = last - carousel.get("numVisible") + 1,
el,
j;
for (var i = first; i <= last; i++) {
if(!itemsTable.loading[i] && !itemsTable.items[i]){
el = carousel._createCarouselItem({
className : carousel.CLASSES.ITEM + " " + carousel.CLASSES.ITEM_LOADING,
content : carousel.STRINGS.ITEM_LOADING_CONTENT,
id : Dom.generateId()
});
if (el) {
if (sibling) {
sibling = Dom.get(sibling.id);
if (sibling) {
carouselEl.insertBefore(el, sibling);
} else {
YAHOO.log("Unable to find sibling", "error",
WidgetName);
}
} else {
carouselEl.appendChild(el);
}
}
itemsTable.loading[i] = el;
}
}
carousel._syncUiItems();
},
/**
* Redraw the UI for item positioning.
*
* @method _syncUiItems
* @protected
*/
_syncUiItems: function () {
if(!syncUiOnItemInsert) {
return;
}
var attr,
carousel = this,
numItems = carousel.get("numItems"),
i,
itemsTable = carousel._itemsTable,
items = itemsTable.items,
loading = itemsTable.loading,
item,
styles,
updateStyles = false;
for (i = 0; i < numItems; i++) {
item = items[i] || loading[i];
if (item && item.id) {
styles = getCarouselItemPosition.call(carousel, i);
item.styles = item.styles || {};
for (attr in styles) {
if(item.styles[attr] !== styles[attr])
{
updateStyles = true;
item.styles[attr] = styles[attr];
}
}
if(updateStyles)
{
setStyles(Dom.get(item.id), styles);
}
updateStyles = false;
}
}
},
/**
* Set the correct class for the navigation buttons.
*
* @method _updateNavButtons
* @param el {Object} The target button
* @param setFocus {Boolean} True to set focus ring, false otherwise.
* @protected
*/
_updateNavButtons: function (el, setFocus) {
var children,
cssClass = this.CLASSES,
grandParent,
parent = el.parentNode;
if (!parent) {
return;
}
grandParent = parent.parentNode;
if (el.nodeName.toUpperCase() == "BUTTON" &&
Dom.hasClass(parent, cssClass.BUTTON)) {
if (setFocus) {
if (grandParent) {
children = Dom.getChildren(grandParent);
if (children) {
Dom.removeClass(children, cssClass.FOCUSSED_BUTTON);
}
}
Dom.addClass(parent, cssClass.FOCUSSED_BUTTON);
} else {
Dom.removeClass(parent, cssClass.FOCUSSED_BUTTON);
}
}
},
/**
* Update the UI for the pager buttons based on the current page and
* the number of pages.
*
* @method _updatePagerButtons
* @protected
*/
_updatePagerButtons: function () {
if(!syncUiOnItemInsert) {
return;
}
var carousel = this,
css = carousel.CLASSES,
cur = carousel._pages.cur, // current page
el,
html,
i,
item,
n = carousel.get("numVisible"),
num = carousel._pages.num, // total pages
pager = carousel._pages.el; // the pager container element
if (num === 0 || !pager) {
return; // don't do anything if number of pages is 0
}
// Hide the pager before redrawing it
Dom.setStyle(pager, "visibility", "hidden");
// Remove all nodes from the pager
while (pager.firstChild) {
pager.removeChild(pager.firstChild);
}
for (i = 0; i < num; i++) {
el = document.createElement("LI");
if (i === 0) {
Dom.addClass(el, css.FIRST_PAGE);
}
if (i == cur) {
Dom.addClass(el, css.SELECTED_NAV);
}
html = "<a class=" + css.PAGER_ITEM + " href=\"#" + (i+1) + "\" tabindex=\"0\"><em>" +
carousel.STRINGS.PAGER_PREFIX_TEXT + " " + (i+1) +
"</em></a>";
el.innerHTML = html;
pager.appendChild(el);
}
// Show the pager now
Dom.setStyle(pager, "visibility", "visible");
},
/**
* Update the UI for the pager menu based on the current page and
* the number of pages. If the number of pages is greater than
* MAX_PAGER_BUTTONS, then the selection of pages is provided by a drop
* down menu instead of a set of buttons.
*
* @method _updatePagerMenu
* @protected
*/
_updatePagerMenu: function () {
var carousel = this,
css = carousel.CLASSES,
cur = carousel._pages.cur, // current page
el,
i,
item,
n = carousel.get("numVisible"),
num = carousel._pages.num, // total pages
pager = carousel._pages.el, // the pager container element
sel;
if (num === 0 || !pager) {
return;// don't do anything if number of pages is 0
}
sel = document.createElement("SELECT");
if (!sel) {
YAHOO.log("Unable to create the pager menu", "error",
WidgetName);
return;
}
// Hide the pager before redrawing it
Dom.setStyle(pager, "visibility", "hidden");
// Remove all nodes from the pager
while (pager.firstChild) {
pager.removeChild(pager.firstChild);
}
for (i = 0; i < num; i++) {
el = document.createElement("OPTION");
el.value = i+1;
el.innerHTML = carousel.STRINGS.PAGER_PREFIX_TEXT+" "+(i+1);
if (i == cur) {
el.setAttribute("selected", "selected");
}
sel.appendChild(el);
}
el = document.createElement("FORM");
if (!el) {
YAHOO.log("Unable to create the pager menu", "error",
WidgetName);
} else {
el.appendChild(sel);
pager.appendChild(el);
}
// Show the pager now
Event.addListener(sel, "change", carousel._pagerChangeHandler, this, true);
Dom.setStyle(pager, "visibility", "visible");
},
/**
* Set the correct tab index for the Carousel items.
*
* @method _updateTabIndex
* @param el {Object} The element to be focussed
* @protected
*/
_updateTabIndex: function (el) {
var carousel = this;
if (el) {
if (carousel._focusableItemEl) {
carousel._focusableItemEl.tabIndex = -1;
}
carousel._focusableItemEl = el;
el.tabIndex = 0;
}
},
/**
* Validate animation parameters.
*
* @method _validateAnimation
* @param cfg {Object} The animation configuration
* @return {Boolean} The status of the validation
* @protected
*/
_validateAnimation: function (cfg) {
var rv = true;
if (JS.isObject(cfg)) {
if (cfg.speed) {
rv = rv && JS.isNumber(cfg.speed);
}
if (cfg.effect) {
rv = rv && JS.isFunction(cfg.effect);
} else if (!JS.isUndefined(YAHOO.util.Easing)) {
cfg.effect = YAHOO.util.Easing.easeOut;
}
} else {
rv = false;
}
return rv;
},
/**
* Validate the firstVisible value.
*
* @method _validateFirstVisible
* @param val {Number} The first visible value
* @return {Boolean} The status of the validation
* @protected
*/
_validateFirstVisible: function (val) {
var carousel = this, numItems = carousel.get("numItems");
if (JS.isNumber(val)) {
if (numItems === 0 && val == numItems) {
return true;
} else {
return (val >= 0 && val < numItems);
}
}
return false;
},
/**
* Validate and navigation parameters.
*
* @method _validateNavigation
* @param cfg {Object} The navigation configuration
* @return {Boolean} The status of the validation
* @protected
*/
_validateNavigation : function (cfg) {
var i;
if (!JS.isObject(cfg)) {
return false;
}
if (cfg.prev) {
if (!JS.isArray(cfg.prev)) {
return false;
}
for (i in cfg.prev) {
if (cfg.prev.hasOwnProperty(i)) {
if (!JS.isString(cfg.prev[i].nodeName)) {
return false;
}
}
}
}
if (cfg.next) {
if (!JS.isArray(cfg.next)) {
return false;
}
for (i in cfg.next) {
if (cfg.next.hasOwnProperty(i)) {
if (!JS.isString(cfg.next[i].nodeName)) {
return false;
}
}
}
}
return true;
},
/**
* Validate the numItems value.
*
* @method _validateNumItems
* @param val {Number} The numItems value
* @return {Boolean} The status of the validation
* @protected
*/
_validateNumItems: function (val) {
return JS.isNumber(val) && (val >= 0);
},
/**
* Validate the numVisible value.
*
* @method _validateNumVisible
* @param val {Number} The numVisible value
* @return {Boolean} The status of the validation
* @protected
*/
_validateNumVisible: function (val) {
var rv = false;
if (JS.isNumber(val)) {
rv = val > 0 && val <= this.get("numItems");
} else if (JS.isArray(val)) {
if (JS.isNumber(val[0]) && JS.isNumber(val[1])) {
rv = val[0] * val[1] > 0 && val.length == 2;
}
}
return rv;
},
/**
* Validate the revealAmount value.
*
* @method _validateRevealAmount
* @param val {Number} The revealAmount value
* @return {Boolean} The status of the validation
* @protected
*/
_validateRevealAmount: function (val) {
var rv = false;
if (JS.isNumber(val)) {
rv = val >= 0 && val < 100;
}
return rv;
},
/**
* Validate the scrollIncrement value.
*
* @method _validateScrollIncrement
* @param val {Number} The scrollIncrement value
* @return {Boolean} The status of the validation
* @protected
*/
_validateScrollIncrement: function (val) {
var rv = false;
if (JS.isNumber(val)) {
rv = (val > 0 && val < this.get("numItems"));
}
return rv;
}
});
})();
/*
;; Local variables: **
;; mode: js2 **
;; indent-tabs-mode: nil **
;; End: **
*/
YAHOO.register("carousel", YAHOO.widget.Carousel, {version: "2.9.0", build: "2800"});
YAHOO.register("carousel", YAHOO.widget.Carousel, {version: "2.9.0", build: "2800"});