Element_wev8.js
110 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
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/**
* @class Ext.Element
* Represents an Element in the DOM.<br><br>
* Usage:<br>
<pre><code>
var el = Ext.get("my-div");
// or with getEl
var el = getEl("my-div");
// or with a DOM element
var el = Ext.get(myDivElement);
</code></pre>
* Using Ext.get() or getEl() instead of calling the constructor directly ensures you get the same object
* each call instead of constructing a new one.<br><br>
* <b>Animations</b><br />
* Many of the functions for manipulating an element have an optional "animate" parameter. The animate parameter
* should either be a boolean (true) or an object literal with animation options. Note that the supported Element animation
* options are a subset of the {@link Ext.Fx} animation options specific to Fx effects. The Element animation options are:
<pre>
Option Default Description
--------- -------- ---------------------------------------------
duration .35 The duration of the animation in seconds
easing easeOut The easing method
callback none A function to execute when the anim completes
scope this The scope (this) of the callback function
</pre>
* Also, the Anim object being used for the animation will be set on your options object as "anim", which allows you to stop or
* manipulate the animation. Here's an example:
<pre><code>
var el = Ext.get("my-div");
// no animation
el.setWidth(100);
// default animation
el.setWidth(100, true);
// animation with some options set
el.setWidth(100, {
duration: 1,
callback: this.foo,
scope: this
});
// using the "anim" property to get the Anim object
var opt = {
duration: 1,
callback: this.foo,
scope: this
};
el.setWidth(100, opt);
...
if(opt.anim.isAnimated()){
opt.anim.stop();
}
</code></pre>
* <b> Composite (Collections of) Elements</b><br />
* For working with collections of Elements, see {@link Ext.CompositeElement}
* @constructor Create a new Element directly.
* @param {String/HTMLElement} element
* @param {Boolean} forceNew (optional) By default the constructor checks to see if there is already an instance of this element in the cache and if there is it returns the same instance. This will skip that check (useful for extending this class).
*/
(function(){
var D = Ext.lib.Dom;
var E = Ext.lib.Event;
var A = Ext.lib.Anim;
// local style camelizing for speed
var propCache = {};
var camelRe = /(-[a-z])/gi;
var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
var view = document.defaultView;
Ext.Element = function(element, forceNew){
var dom = typeof element == "string" ?
document.getElementById(element) : element;
if(!dom){ // invalid id/element
return null;
}
var id = dom.id;
if(forceNew !== true && id && Ext.Element.cache[id]){ // element object already exists
return Ext.Element.cache[id];
}
/**
* The DOM element
* @type HTMLElement
*/
this.dom = dom;
/**
* The DOM element ID
* @type String
*/
this.id = id || Ext.id(dom);
};
var El = Ext.Element;
El.prototype = {
/**
* The element's default display mode (defaults to "")
* @type String
*/
originalDisplay : "",
visibilityMode : 1,
/**
* The default unit to append to CSS values where a unit isn't provided (defaults to px).
* @type String
*/
defaultUnit : "px",
/**
* Sets the element's visibility mode. When setVisible() is called it
* will use this to determine whether to set the visibility or the display property.
* @param visMode Element.VISIBILITY or Element.DISPLAY
* @return {Ext.Element} this
*/
setVisibilityMode : function(visMode){
this.visibilityMode = visMode;
return this;
},
/**
* Convenience method for setVisibilityMode(Element.DISPLAY)
* @param {String} display (optional) What to set display to when visible
* @return {Ext.Element} this
*/
enableDisplayMode : function(display){
this.setVisibilityMode(El.DISPLAY);
if(typeof display != "undefined") this.originalDisplay = display;
return this;
},
/**
* Looks at this node and then at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
* @param {String} selector The simple selector to test
* @param {Number/Mixed} maxDepth (optional) The max depth to
search as a number or element (defaults to 10 || document.body)
* @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
* @return {HTMLElement} The matching DOM node (or null if no match was found)
*/
findParent : function(simpleSelector, maxDepth, returnEl){
var p = this.dom, b = document.body, depth = 0, dq = Ext.DomQuery, stopEl;
maxDepth = maxDepth || 50;
if(typeof maxDepth != "number"){
stopEl = Ext.getDom(maxDepth);
maxDepth = 10;
}
while(p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl){
if(dq.is(p, simpleSelector)){
return returnEl ? Ext.get(p) : p;
}
depth++;
p = p.parentNode;
}
return null;
},
/**
* Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
* @param {String} selector The simple selector to test
* @param {Number/Mixed} maxDepth (optional) The max depth to
search as a number or element (defaults to 10 || document.body)
* @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
* @return {HTMLElement} The matching DOM node (or null if no match was found)
*/
findParentNode : function(simpleSelector, maxDepth, returnEl){
var p = Ext.fly(this.dom.parentNode, '_internal');
return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
},
/**
* Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child).
* This is a shortcut for findParentNode() that always returns an Ext.Element.
* @param {String} selector The simple selector to test
* @param {Number/Mixed} maxDepth (optional) The max depth to
search as a number or element (defaults to 10 || document.body)
* @return {Ext.Element} The matching DOM node (or null if no match was found)
*/
up : function(simpleSelector, maxDepth){
return this.findParentNode(simpleSelector, maxDepth, true);
},
/**
* Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
* @param {String} selector The simple selector to test
* @return {Boolean} True if this element matches the selector, else false
*/
is : function(simpleSelector){
return Ext.DomQuery.is(this.dom, simpleSelector);
},
/**
* Perform animation on this element.
* @param {Object} args The animation control args
* @param {Float} duration (optional) How long the animation lasts in seconds (defaults to .35)
* @param {Function} onComplete (optional) Function to call when animation completes
* @param {String} easing (optional) Easing method to use (defaults to 'easeOut')
* @param {String} animType (optional) 'run' is the default. Can also be 'color', 'motion', or 'scroll'
* @return {Ext.Element} this
*/
animate : function(args, duration, onComplete, easing, animType){
this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType);
return this;
},
/*
* @private Internal animation call
*/
anim : function(args, opt, animType, defaultDur, defaultEase, cb){
animType = animType || 'run';
opt = opt || {};
var anim = Ext.lib.Anim[animType](
this.dom, args,
(opt.duration || defaultDur) || .35,
(opt.easing || defaultEase) || 'easeOut',
function(){
Ext.callback(cb, this);
Ext.callback(opt.callback, opt.scope || this, [this, opt]);
},
this
);
opt.anim = anim;
return anim;
},
// private legacy anim prep
preanim : function(a, i){
return !a[i] ? false : (typeof a[i] == "object" ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]});
},
/**
* Removes worthless text nodes
* @param {Boolean} forceReclean (optional) By default the element
* keeps track if it has been cleaned already so
* you can call this over and over. However, if you update the element and
* need to force a reclean, you can pass true.
*/
clean : function(forceReclean){
if(this.isCleaned && forceReclean !== true){
return this;
}
var ns = /\S/;
var d = this.dom, n = d.firstChild, ni = -1;
while(n){
var nx = n.nextSibling;
if(n.nodeType == 3 && !ns.test(n.nodeValue)){
d.removeChild(n);
}else{
n.nodeIndex = ++ni;
}
n = nx;
}
this.isCleaned = true;
return this;
},
/**
* Scrolls this element into view within the passed container.
* @param {Mixed} container (optional) The container element to scroll (defaults to document.body)
* @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
* @return {Ext.Element} this
*/
scrollIntoView : function(container, hscroll){
var c = Ext.getDom(container) || Ext.getBody().dom;
var el = this.dom;
var o = this.getOffsetsTo(c),
l = o[0] + c.scrollLeft,
t = o[1] + c.scrollTop,
b = t+el.offsetHeight,
r = l+el.offsetWidth;
var ch = c.clientHeight;
var ct = parseInt(c.scrollTop, 10);
var cl = parseInt(c.scrollLeft, 10);
var cb = ct + ch;
var cr = cl + c.clientWidth;
if(el.offsetHeight > ch || t < ct){
c.scrollTop = t;
}else if(b > cb){
c.scrollTop = b-ch;
}
c.scrollTop = c.scrollTop; // corrects IE, other browsers will ignore
if(hscroll !== false){
if(el.offsetWidth > c.clientWidth || l < cl){
c.scrollLeft = l;
}else if(r > cr){
c.scrollLeft = r-c.clientWidth;
}
c.scrollLeft = c.scrollLeft;
}
return this;
},
// private
scrollChildIntoView : function(child, hscroll){
Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
},
/**
* Measures the element's content height and updates height to match. Note: this function uses setTimeout so
* the new height may not be available immediately.
* @param {Boolean} animate (optional) Animate the transition (defaults to false)
* @param {Float} duration (optional) Length of the animation in seconds (defaults to .35)
* @param {Function} onComplete (optional) Function to call when animation completes
* @param {String} easing (optional) Easing method to use (defaults to easeOut)
* @return {Ext.Element} this
*/
autoHeight : function(animate, duration, onComplete, easing){
var oldHeight = this.getHeight();
this.clip();
this.setHeight(1); // force clipping
setTimeout(function(){
var height = parseInt(this.dom.scrollHeight, 10); // parseInt for Safari
if(!animate){
this.setHeight(height);
this.unclip();
if(typeof onComplete == "function"){
onComplete();
}
}else{
this.setHeight(oldHeight); // restore original height
this.setHeight(height, animate, duration, function(){
this.unclip();
if(typeof onComplete == "function") onComplete();
}.createDelegate(this), easing);
}
}.createDelegate(this), 0);
return this;
},
/**
* Returns true if this element is an ancestor of the passed element
* @param {HTMLElement/String} el The element to check
* @return {Boolean} True if this element is an ancestor of el, else false
*/
contains : function(el){
if(!el){return false;}
return D.isAncestor(this.dom, el.dom ? el.dom : el);
},
/**
* Checks whether the element is currently visible using both visibility and display properties.
* @param {Boolean} deep (optional) True to walk the dom and see if parent elements are hidden (defaults to false)
* @return {Boolean} True if the element is currently visible, else false
*/
isVisible : function(deep) {
var vis = !(this.getStyle("visibility") == "hidden" || this.getStyle("display") == "none");
if(deep !== true || !vis){
return vis;
}
var p = this.dom.parentNode;
while(p && p.tagName.toLowerCase() != "body"){
if(!Ext.fly(p, '_isVisible').isVisible()){
return false;
}
p = p.parentNode;
}
return true;
},
/**
* Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
* @param {String} selector The CSS selector
* @param {Boolean} unique (optional) True to create a unique Ext.Element for each child (defaults to false, which creates a single shared flyweight object)
* @return {CompositeElement/CompositeElementLite} The composite element
*/
select : function(selector, unique){
return El.select(selector, unique, this.dom);
},
/**
* Selects child nodes based on the passed CSS selector (the selector should not contain an id).
* @param {String} selector The CSS selector
* @return {Array} An array of the matched nodes
*/
query : function(selector, unique){
return Ext.DomQuery.select(selector, this.dom);
},
/**
* Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
* @param {String} selector The CSS selector
* @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
* @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
*/
child : function(selector, returnDom){
var n = Ext.DomQuery.selectNode(selector, this.dom);
return returnDom ? n : Ext.get(n);
},
/**
* Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
* @param {String} selector The CSS selector
* @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
* @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
*/
down : function(selector, returnDom){
var n = Ext.DomQuery.selectNode(" > " + selector, this.dom);
return returnDom ? n : Ext.get(n);
},
/**
* Initializes a {@link Ext.dd.DD} drag drop object for this element.
* @param {String} group The group the DD object is member of
* @param {Object} config The DD config object
* @param {Object} overrides An object containing methods to override/implement on the DD object
* @return {Ext.dd.DD} The DD object
*/
initDD : function(group, config, overrides){
var dd = new Ext.dd.DD(Ext.id(this.dom), group, config);
return Ext.apply(dd, overrides);
},
/**
* Initializes a {@link Ext.dd.DDProxy} object for this element.
* @param {String} group The group the DDProxy object is member of
* @param {Object} config The DDProxy config object
* @param {Object} overrides An object containing methods to override/implement on the DDProxy object
* @return {Ext.dd.DDProxy} The DDProxy object
*/
initDDProxy : function(group, config, overrides){
var dd = new Ext.dd.DDProxy(Ext.id(this.dom), group, config);
return Ext.apply(dd, overrides);
},
/**
* Initializes a {@link Ext.dd.DDTarget} object for this element.
* @param {String} group The group the DDTarget object is member of
* @param {Object} config The DDTarget config object
* @param {Object} overrides An object containing methods to override/implement on the DDTarget object
* @return {Ext.dd.DDTarget} The DDTarget object
*/
initDDTarget : function(group, config, overrides){
var dd = new Ext.dd.DDTarget(Ext.id(this.dom), group, config);
return Ext.apply(dd, overrides);
},
/**
* Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
* the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
* @param {Boolean} visible Whether the element is visible
* @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
* @return {Ext.Element} this
*/
setVisible : function(visible, animate){
if(!animate || !A){
if(this.visibilityMode == El.DISPLAY){
this.setDisplayed(visible);
}else{
this.fixDisplay();
this.dom.style.visibility = visible ? "visible" : "hidden";
}
}else{
// closure for composites
var dom = this.dom;
var visMode = this.visibilityMode;
if(visible){
this.setOpacity(.01);
this.setVisible(true);
}
this.anim({opacity: { to: (visible?1:0) }},
this.preanim(arguments, 1),
null, .35, 'easeIn', function(){
if(!visible){
if(visMode == El.DISPLAY){
dom.style.display = "none";
}else{
dom.style.visibility = "hidden";
}
Ext.get(dom).setOpacity(1);
}
});
}
return this;
},
/**
* Returns true if display is not "none"
* @return {Boolean}
*/
isDisplayed : function() {
return this.getStyle("display") != "none";
},
/**
* Toggles the element's visibility or display, depending on visibility mode.
* @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
* @return {Ext.Element} this
*/
toggle : function(animate){
this.setVisible(!this.isVisible(), this.preanim(arguments, 0));
return this;
},
/**
* Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
* @param {Mixed} value Boolean value to display the element using its default display, or a string to set the display directly.
* @return {Ext.Element} this
*/
setDisplayed : function(value) {
if(typeof value == "boolean"){
value = value ? this.originalDisplay : "none";
}
this.setStyle("display", value);
return this;
},
/**
* Tries to focus the element. Any exceptions are caught and ignored.
* @return {Ext.Element} this
*/
focus : function() {
try{
this.dom.focus();
}catch(e){}
return this;
},
/**
* Tries to blur the element. Any exceptions are caught and ignored.
* @return {Ext.Element} this
*/
blur : function() {
try{
this.dom.blur();
}catch(e){}
return this;
},
/**
* Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
* @param {String/Array} className The CSS class to add, or an array of classes
* @return {Ext.Element} this
*/
addClass : function(className){
if(Ext.isArray(className)){
for(var i = 0, len = className.length; i < len; i++) {
this.addClass(className[i]);
}
}else{
if(className && !this.hasClass(className)){
this.dom.className = this.dom.className + " " + className;
}
}
return this;
},
/**
* Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
* @param {String/Array} className The CSS class to add, or an array of classes
* @return {Ext.Element} this
*/
radioClass : function(className){
var siblings = this.dom.parentNode.childNodes;
for(var i = 0; i < siblings.length; i++) {
var s = siblings[i];
if(s.nodeType == 1){
Ext.get(s).removeClass(className);
}
}
this.addClass(className);
return this;
},
/**
* Removes one or more CSS classes from the element.
* @param {String/Array} className The CSS class to remove, or an array of classes
* @return {Ext.Element} this
*/
removeClass : function(className){
if(!className || !this.dom.className){
return this;
}
if(Ext.isArray(className)){
for(var i = 0, len = className.length; i < len; i++) {
this.removeClass(className[i]);
}
}else{
if(this.hasClass(className)){
var re = this.classReCache[className];
if (!re) {
re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', "g");
this.classReCache[className] = re;
}
this.dom.className =
this.dom.className.replace(re, " ");
}
}
return this;
},
// private
classReCache: {},
/**
* Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
* @param {String} className The CSS class to toggle
* @return {Ext.Element} this
*/
toggleClass : function(className){
if(this.hasClass(className)){
this.removeClass(className);
}else{
this.addClass(className);
}
return this;
},
/**
* Checks if the specified CSS class exists on this element's DOM node.
* @param {String} className The CSS class to check for
* @return {Boolean} True if the class exists, else false
*/
hasClass : function(className){
return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1;
},
/**
* Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
* @param {String} oldClassName The CSS class to replace
* @param {String} newClassName The replacement CSS class
* @return {Ext.Element} this
*/
replaceClass : function(oldClassName, newClassName){
this.removeClass(oldClassName);
this.addClass(newClassName);
return this;
},
/**
* Returns an object with properties matching the styles requested.
* For example, el.getStyles('color', 'font-size', 'width') might return
* {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
* @param {String} style1 A style name
* @param {String} style2 A style name
* @param {String} etc.
* @return {Object} The style object
*/
getStyles : function(){
var a = arguments, len = a.length, r = {};
for(var i = 0; i < len; i++){
r[a[i]] = this.getStyle(a[i]);
}
return r;
},
/**
* Normalizes currentStyle and computedStyle.
* @param {String} property The style property whose value is returned.
* @return {String} The current value of the style property for this element.
*/
getStyle : function(){
return view && view.getComputedStyle ?
function(prop){
var el = this.dom, v, cs, camel;
if(prop == 'float'){
prop = "cssFloat";
}
if(v = el.style[prop]){
return v;
}
if(cs = view.getComputedStyle(el, "")){
if(!(camel = propCache[prop])){
camel = propCache[prop] = prop.replace(camelRe, camelFn);
}
return cs[camel];
}
return null;
} :
function(prop){
var el = this.dom, v, cs, camel;
if(prop == 'opacity'){
if(typeof el.style.filter == 'string'){
var m = el.style.filter.match(/alpha\(opacity=(.*)\)/i);
if(m){
var fv = parseFloat(m[1]);
if(!isNaN(fv)){
return fv ? fv / 100 : 0;
}
}
}
return 1;
}else if(prop == 'float'){
prop = "styleFloat";
}
if(!(camel = propCache[prop])){
camel = propCache[prop] = prop.replace(camelRe, camelFn);
}
if(v = el.style[camel]){
return v;
}
if(cs = el.currentStyle){
return cs[camel];
}
return null;
};
}(),
/**
* Wrapper for setting style properties, also takes single object parameter of multiple styles.
* @param {String/Object} property The style property to be set, or an object of multiple styles.
* @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
* @return {Ext.Element} this
*/
setStyle : function(prop, value){
if(typeof prop == "string"){
var camel;
if(!(camel = propCache[prop])){
camel = propCache[prop] = prop.replace(camelRe, camelFn);
}
if(camel == 'opacity') {
this.setOpacity(value);
}else{
this.dom.style[camel] = value;
}
}else{
for(var style in prop){
if(typeof prop[style] != "function"){
this.setStyle(style, prop[style]);
}
}
}
return this;
},
/**
* More flexible version of {@link #setStyle} for setting style properties.
* @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
* a function which returns such a specification.
* @return {Ext.Element} this
*/
applyStyles : function(style){
Ext.DomHelper.applyStyles(this.dom, style);
return this;
},
/**
* Gets the current X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @return {Number} The X position of the element
*/
getX : function(){
return D.getX(this.dom);
},
/**
* Gets the current Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @return {Number} The Y position of the element
*/
getY : function(){
return D.getY(this.dom);
},
/**
* Gets the current position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @return {Array} The XY position of the element
*/
getXY : function(){
return D.getXY(this.dom);
},
/**
* Returns the offsets of this element from the passed element. Both element must be part of the DOM tree and not have display:none to have page coordinates.
* @param {Mixed} element The element to get the offsets from.
* @return {Array} The XY page offsets (e.g. [100, -200])
*/
getOffsetsTo : function(el){
var o = this.getXY();
var e = Ext.fly(el, '_internal').getXY();
return [o[0]-e[0],o[1]-e[1]];
},
/**
* Sets the X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @param {Number} The X position of the element
* @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
* @return {Ext.Element} this
*/
setX : function(x, animate){
if(!animate || !A){
D.setX(this.dom, x);
}else{
this.setXY([x, this.getY()], this.preanim(arguments, 1));
}
return this;
},
/**
* Sets the Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @param {Number} The Y position of the element
* @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
* @return {Ext.Element} this
*/
setY : function(y, animate){
if(!animate || !A){
D.setY(this.dom, y);
}else{
this.setXY([this.getX(), y], this.preanim(arguments, 1));
}
return this;
},
/**
* Sets the element's left position directly using CSS style (instead of {@link #setX}).
* @param {String} left The left CSS property value
* @return {Ext.Element} this
*/
setLeft : function(left){
this.setStyle("left", this.addUnits(left));
return this;
},
/**
* Sets the element's top position directly using CSS style (instead of {@link #setY}).
* @param {String} top The top CSS property value
* @return {Ext.Element} this
*/
setTop : function(top){
this.setStyle("top", this.addUnits(top));
return this;
},
/**
* Sets the element's CSS right style.
* @param {String} right The right CSS property value
* @return {Ext.Element} this
*/
setRight : function(right){
this.setStyle("right", this.addUnits(right));
return this;
},
/**
* Sets the element's CSS bottom style.
* @param {String} bottom The bottom CSS property value
* @return {Ext.Element} this
*/
setBottom : function(bottom){
this.setStyle("bottom", this.addUnits(bottom));
return this;
},
/**
* Sets the position of the element in page coordinates, regardless of how the element is positioned.
* The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
* @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
* @return {Ext.Element} this
*/
setXY : function(pos, animate){
if(!animate || !A){
D.setXY(this.dom, pos);
}else{
this.anim({points: {to: pos}}, this.preanim(arguments, 1), 'motion');
}
return this;
},
/**
* Sets the position of the element in page coordinates, regardless of how the element is positioned.
* The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @param {Number} x X value for new position (coordinates are page-based)
* @param {Number} y Y value for new position (coordinates are page-based)
* @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
* @return {Ext.Element} this
*/
setLocation : function(x, y, animate){
this.setXY([x, y], this.preanim(arguments, 2));
return this;
},
/**
* Sets the position of the element in page coordinates, regardless of how the element is positioned.
* The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
* @param {Number} x X value for new position (coordinates are page-based)
* @param {Number} y Y value for new position (coordinates are page-based)
* @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
* @return {Ext.Element} this
*/
moveTo : function(x, y, animate){
this.setXY([x, y], this.preanim(arguments, 2));
return this;
},
/**
* Returns the region of the given element.
* The element must be part of the DOM tree to have a region (display:none or elements not appended return false).
* @return {Region} A Ext.lib.Region containing "top, left, bottom, right" member data.
*/
getRegion : function(){
return D.getRegion(this.dom);
},
/**
* Returns the offset height of the element
* @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
* @return {Number} The element's height
*/
getHeight : function(contentHeight){
var h = this.dom.offsetHeight || 0;
h = contentHeight !== true ? h : h-this.getBorderWidth("tb")-this.getPadding("tb");
return h < 0 ? 0 : h;
},
/**
* Returns the offset width of the element
* @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
* @return {Number} The element's width
*/
getWidth : function(contentWidth){
var w = this.dom.offsetWidth || 0;
w = contentWidth !== true ? w : w-this.getBorderWidth("lr")-this.getPadding("lr");
return w < 0 ? 0 : w;
},
/**
* Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
* when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
* if a height has not been set using CSS.
* @return {Number}
*/
getComputedHeight : function(){
var h = Math.max(this.dom.offsetHeight, this.dom.clientHeight);
if(!h){
h = parseInt(this.getStyle('height'), 10) || 0;
if(!this.isBorderBox()){
h += this.getFrameWidth('tb');
}
}
return h;
},
/**
* Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
* when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
* if a width has not been set using CSS.
* @return {Number}
*/
getComputedWidth : function(){
var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth);
if(!w){
w = parseInt(this.getStyle('width'), 10) || 0;
if(!this.isBorderBox()){
w += this.getFrameWidth('lr');
}
}
return w;
},
/**
* Returns the size of the element.
* @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
* @return {Object} An object containing the element's size {width: (element width), height: (element height)}
*/
getSize : function(contentSize){
return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
},
getStyleSize : function(){
var w, h, d = this.dom, s = d.style;
if(s.width && s.width != 'auto'){
w = parseInt(s.width, 10);
if(Ext.isBorderBox){
w -= this.getFrameWidth('lr');
}
}
if(s.height && s.height != 'auto'){
h = parseInt(s.height, 10);
if(Ext.isBorderBox){
h -= this.getFrameWidth('tb');
}
}
return {width: w || this.getWidth(true), height: h || this.getHeight(true)};
},
/**
* Returns the width and height of the viewport.
* @return {Object} An object containing the viewport's size {width: (viewport width), height: (viewport height)}
*/
getViewSize : function(){
var d = this.dom, doc = document, aw = 0, ah = 0;
if(d == doc || d == doc.body){
return {width : D.getViewWidth(), height: D.getViewHeight()};
}else{
return {
width : d.clientWidth,
height: d.clientHeight
};
}
},
/**
* Returns the value of the "value" attribute
* @param {Boolean} asNumber true to parse the value as a number
* @return {String/Number}
*/
getValue : function(asNumber){
return asNumber ? parseInt(this.dom.value, 10) : this.dom.value;
},
// private
adjustWidth : function(width){
if(typeof width == "number"){
if(this.autoBoxAdjust && !this.isBorderBox()){
width -= (this.getBorderWidth("lr") + this.getPadding("lr"));
}
if(width < 0){
width = 0;
}
}
return width;
},
// private
adjustHeight : function(height){
if(typeof height == "number"){
if(this.autoBoxAdjust && !this.isBorderBox()){
height -= (this.getBorderWidth("tb") + this.getPadding("tb"));
}
if(height < 0){
height = 0;
}
}
return height;
},
/**
* Set the width of the element
* @param {Number} width The new width
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Ext.Element} this
*/
setWidth : function(width, animate){
width = this.adjustWidth(width);
if(!animate || !A){
this.dom.style.width = this.addUnits(width);
}else{
this.anim({width: {to: width}}, this.preanim(arguments, 1));
}
return this;
},
/**
* Set the height of the element
* @param {Number} height The new height
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Ext.Element} this
*/
setHeight : function(height, animate){
height = this.adjustHeight(height);
if(!animate || !A){
this.dom.style.height = this.addUnits(height);
}else{
this.anim({height: {to: height}}, this.preanim(arguments, 1));
}
return this;
},
/**
* Set the size of the element. If animation is true, both width an height will be animated concurrently.
* @param {Number} width The new width
* @param {Number} height The new height
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Ext.Element} this
*/
setSize : function(width, height, animate){
if(typeof width == "object"){ // in case of object from getSize()
height = width.height; width = width.width;
}
width = this.adjustWidth(width); height = this.adjustHeight(height);
if(!animate || !A){
this.dom.style.width = this.addUnits(width);
this.dom.style.height = this.addUnits(height);
}else{
this.anim({width: {to: width}, height: {to: height}}, this.preanim(arguments, 2));
}
return this;
},
/**
* Sets the element's position and size in one shot. If animation is true then width, height, x and y will be animated concurrently.
* @param {Number} x X value for new position (coordinates are page-based)
* @param {Number} y Y value for new position (coordinates are page-based)
* @param {Number} width The new width
* @param {Number} height The new height
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Ext.Element} this
*/
setBounds : function(x, y, width, height, animate){
if(!animate || !A){
this.setSize(width, height);
this.setLocation(x, y);
}else{
width = this.adjustWidth(width); height = this.adjustHeight(height);
this.anim({points: {to: [x, y]}, width: {to: width}, height: {to: height}},
this.preanim(arguments, 4), 'motion');
}
return this;
},
/**
* Sets the element's position and size the the specified region. If animation is true then width, height, x and y will be animated concurrently.
* @param {Ext.lib.Region} region The region to fill
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Ext.Element} this
*/
setRegion : function(region, animate){
this.setBounds(region.left, region.top, region.right-region.left, region.bottom-region.top, this.preanim(arguments, 1));
return this;
},
/**
* Appends an event handler to this element. The shorthand version {@link #on} is equivalent.
* @param {String} eventName The type of event to handle
* @param {Function} fn The handler function the event invokes
* @param {Object} scope (optional) The scope (this element) of the handler function
* @param {Object} options (optional) An object containing handler configuration properties.
* This may contain any of the following properties:<ul>
* <li>scope {Object} : The scope in which to execute the handler function. The handler function's "this" context.</li>
* <li>delegate {String} : A simple selector to filter the target or look for a descendant of the target</li>
* <li>stopEvent {Boolean} : True to stop the event. That is stop propagation, and prevent the default action.</li>
* <li>preventDefault {Boolean} : True to prevent the default action</li>
* <li>stopPropagation {Boolean} : True to prevent event propagation</li>
* <li>normalized {Boolean} : False to pass a browser event to the handler function instead of an Ext.EventObject</li>
* <li>delay {Number} : The number of milliseconds to delay the invocation of the handler after te event fires.</li>
* <li>single {Boolean} : True to add a handler to handle just the next firing of the event, and then remove itself.</li>
* <li>buffer {Number} : Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
* by the specified number of milliseconds. If the event fires again within that time, the original
* handler is <em>not</em> invoked, but the new handler is scheduled in its place.</li>
* </ul><br>
* <p>
* <b>Combining Options</b><br>
* In the following examples, the shorthand form {@link #on} is used rather than the more verbose
* addListener. The two are equivalent. Using the options argument, it is possible to combine different
* types of listeners:<br>
* <br>
* A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)<div style="margin: 5px 20px 20px;">
* Code:<pre><code>
el.on('click', this.onClick, this, {
single: true,
delay: 100,
stopEvent : true,
forumId: 4
});</code></pre>
* <p>
* <b>Attaching multiple handlers in 1 call</b><br>
* The method also allows for a single argument to be passed which is a config object containing properties
* which specify multiple handlers.
* <p>
* Code:<pre><code>
el.on({
'click' : {
fn: this.onClick,
scope: this,
delay: 100
},
'mouseover' : {
fn: this.onMouseOver,
scope: this
},
'mouseout' : {
fn: this.onMouseOut,
scope: this
}
});</code></pre>
* <p>
* Or a shorthand syntax:<br>
* Code:<pre><code>
el.on({
'click' : this.onClick,
'mouseover' : this.onMouseOver,
'mouseout' : this.onMouseOut,
scope: this
});</code></pre>
*/
addListener : function(eventName, fn, scope, options){
Ext.EventManager.on(this.dom, eventName, fn, scope || this, options);
},
/**
* Removes an event handler from this element. The shorthand version {@link #un} is equivalent. Example:
* <pre><code>
el.removeListener('click', this.handlerFn);
// or
el.un('click', this.handlerFn);
</code></pre>
* @param {String} eventName the type of event to remove
* @param {Function} fn the method the event invokes
* @return {Ext.Element} this
*/
removeListener : function(eventName, fn){
Ext.EventManager.removeListener(this.dom, eventName, fn);
return this;
},
/**
* Removes all previous added listeners from this element
* @return {Ext.Element} this
*/
removeAllListeners : function(){
E.purgeElement(this.dom);
return this;
},
/**
* Create an event handler on this element such that when the event fires and is handled by this element,
* it will be relayed to another object (i.e., fired again as if it originated from that object instead).
* @param {String} eventName The type of event to relay
* @param {Object} object Any object that extends {@link Ext.util.Observable} that will provide the context
* for firing the relayed event
*/
relayEvent : function(eventName, observable){
this.on(eventName, function(e){
observable.fireEvent(eventName, e);
});
},
/**
* Set the opacity of the element
* @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Ext.Element} this
*/
setOpacity : function(opacity, animate){
if(!animate || !A){
var s = this.dom.style;
if(Ext.isIE){
s.zoom = 1;
s.filter = (s.filter || '').replace(/alpha\([^\)]*\)/gi,"") +
(opacity == 1 ? "" : " alpha(opacity=" + opacity * 100 + ")");
}else{
s.opacity = opacity;
}
}else{
this.anim({opacity: {to: opacity}}, this.preanim(arguments, 1), null, .35, 'easeIn');
}
return this;
},
/**
* Gets the left X coordinate
* @param {Boolean} local True to get the local css position instead of page coordinate
* @return {Number}
*/
getLeft : function(local){
if(!local){
return this.getX();
}else{
return parseInt(this.getStyle("left"), 10) || 0;
}
},
/**
* Gets the right X coordinate of the element (element X position + element width)
* @param {Boolean} local True to get the local css position instead of page coordinate
* @return {Number}
*/
getRight : function(local){
if(!local){
return this.getX() + this.getWidth();
}else{
return (this.getLeft(true) + this.getWidth()) || 0;
}
},
/**
* Gets the top Y coordinate
* @param {Boolean} local True to get the local css position instead of page coordinate
* @return {Number}
*/
getTop : function(local) {
if(!local){
return this.getY();
}else{
return parseInt(this.getStyle("top"), 10) || 0;
}
},
/**
* Gets the bottom Y coordinate of the element (element Y position + element height)
* @param {Boolean} local True to get the local css position instead of page coordinate
* @return {Number}
*/
getBottom : function(local){
if(!local){
return this.getY() + this.getHeight();
}else{
return (this.getTop(true) + this.getHeight()) || 0;
}
},
/**
* Initializes positioning on this element. If a desired position is not passed, it will make the
* the element positioned relative IF it is not already positioned.
* @param {String} pos (optional) Positioning to use "relative", "absolute" or "fixed"
* @param {Number} zIndex (optional) The zIndex to apply
* @param {Number} x (optional) Set the page X position
* @param {Number} y (optional) Set the page Y position
*/
position : function(pos, zIndex, x, y){
if(!pos){
if(this.getStyle('position') == 'static'){
this.setStyle('position', 'relative');
}
}else{
this.setStyle("position", pos);
}
if(zIndex){
this.setStyle("z-index", zIndex);
}
if(x !== undefined && y !== undefined){
this.setXY([x, y]);
}else if(x !== undefined){
this.setX(x);
}else if(y !== undefined){
this.setY(y);
}
},
/**
* Clear positioning back to the default when the document was loaded
* @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'.
* @return {Ext.Element} this
*/
clearPositioning : function(value){
value = value ||'';
this.setStyle({
"left": value,
"right": value,
"top": value,
"bottom": value,
"z-index": "",
"position" : "static"
});
return this;
},
/**
* Gets an object with all CSS positioning properties. Useful along with setPostioning to get
* snapshot before performing an update and then restoring the element.
* @return {Object}
*/
getPositioning : function(){
var l = this.getStyle("left");
var t = this.getStyle("top");
return {
"position" : this.getStyle("position"),
"left" : l,
"right" : l ? "" : this.getStyle("right"),
"top" : t,
"bottom" : t ? "" : this.getStyle("bottom"),
"z-index" : this.getStyle("z-index")
};
},
/**
* Gets the width of the border(s) for the specified side(s)
* @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
* passing lr would get the border (l)eft width + the border (r)ight width.
* @return {Number} The width of the sides passed added together
*/
getBorderWidth : function(side){
return this.addStyles(side, El.borders);
},
/**
* Gets the width of the padding(s) for the specified side(s)
* @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
* passing lr would get the padding (l)eft + the padding (r)ight.
* @return {Number} The padding of the sides passed added together
*/
getPadding : function(side){
return this.addStyles(side, El.paddings);
},
/**
* Set positioning with an object returned by getPositioning().
* @param {Object} posCfg
* @return {Ext.Element} this
*/
setPositioning : function(pc){
this.applyStyles(pc);
if(pc.right == "auto"){
this.dom.style.right = "";
}
if(pc.bottom == "auto"){
this.dom.style.bottom = "";
}
return this;
},
// private
fixDisplay : function(){
if(this.getStyle("display") == "none"){
this.setStyle("visibility", "hidden");
this.setStyle("display", this.originalDisplay); // first try reverting to default
if(this.getStyle("display") == "none"){ // if that fails, default to block
this.setStyle("display", "block");
}
}
},
// private
setOverflow : function(v){
if(v=='auto' && Ext.isMac && Ext.isGecko){ // work around stupid FF 2.0/Mac scroll bar bug
this.dom.style.overflow = 'hidden';
(function(){this.dom.style.overflow = 'auto';}).defer(1, this);
}else{
this.dom.style.overflow = v;
}
},
/**
* Quick set left and top adding default units
* @param {String} left The left CSS property value
* @param {String} top The top CSS property value
* @return {Ext.Element} this
*/
setLeftTop : function(left, top){
this.dom.style.left = this.addUnits(left);
this.dom.style.top = this.addUnits(top);
return this;
},
/**
* Move this element relative to its current position.
* @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".
* @param {Number} distance How far to move the element in pixels
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Ext.Element} this
*/
move : function(direction, distance, animate){
var xy = this.getXY();
direction = direction.toLowerCase();
switch(direction){
case "l":
case "left":
this.moveTo(xy[0]-distance, xy[1], this.preanim(arguments, 2));
break;
case "r":
case "right":
this.moveTo(xy[0]+distance, xy[1], this.preanim(arguments, 2));
break;
case "t":
case "top":
case "up":
this.moveTo(xy[0], xy[1]-distance, this.preanim(arguments, 2));
break;
case "b":
case "bottom":
case "down":
this.moveTo(xy[0], xy[1]+distance, this.preanim(arguments, 2));
break;
}
return this;
},
/**
* Store the current overflow setting and clip overflow on the element - use {@link #unclip} to remove
* @return {Ext.Element} this
*/
clip : function(){
if(!this.isClipped){
this.isClipped = true;
this.originalClip = {
"o": this.getStyle("overflow"),
"x": this.getStyle("overflow-x"),
"y": this.getStyle("overflow-y")
};
this.setStyle("overflow", "hidden");
this.setStyle("overflow-x", "hidden");
this.setStyle("overflow-y", "hidden");
}
return this;
},
/**
* Return clipping (overflow) to original clipping before clip() was called
* @return {Ext.Element} this
*/
unclip : function(){
if(this.isClipped){
this.isClipped = false;
var o = this.originalClip;
if(o.o){this.setStyle("overflow", o.o);}
if(o.x){this.setStyle("overflow-x", o.x);}
if(o.y){this.setStyle("overflow-y", o.y);}
}
return this;
},
/**
* Gets the x,y coordinates specified by the anchor position on the element.
* @param {String} anchor (optional) The specified anchor position (defaults to "c"). See {@link #alignTo}
* for details on supported anchor positions.
* @param {Boolean} local (optional) True to get the local (element top/left-relative) anchor position instead
* of page coordinates
* @param {Object} size (optional) An object containing the size to use for calculating anchor position
* {width: (target width), height: (target height)} (defaults to the element's current size)
* @return {Array} [x, y] An array containing the element's x and y coordinates
*/
getAnchorXY : function(anchor, local, s){
//Passing a different size is useful for pre-calculating anchors,
//especially for anchored animations that change the el size.
var w, h, vp = false;
if(!s){
var d = this.dom;
if(d == document.body || d == document){
vp = true;
w = D.getViewWidth(); h = D.getViewHeight();
}else{
w = this.getWidth(); h = this.getHeight();
}
}else{
w = s.width; h = s.height;
}
var x = 0, y = 0, r = Math.round;
switch((anchor || "tl").toLowerCase()){
case "c":
x = r(w*.5);
y = r(h*.5);
break;
case "t":
x = r(w*.5);
y = 0;
break;
case "l":
x = 0;
y = r(h*.5);
break;
case "r":
x = w;
y = r(h*.5);
break;
case "b":
x = r(w*.5);
y = h;
break;
case "tl":
x = 0;
y = 0;
break;
case "bl":
x = 0;
y = h;
break;
case "br":
x = w;
y = h;
break;
case "tr":
x = w;
y = 0;
break;
}
if(local === true){
return [x, y];
}
if(vp){
var sc = this.getScroll();
return [x + sc.left, y + sc.top];
}
//Add the element's offset xy
var o = this.getXY();
return [x+o[0], y+o[1]];
},
/**
* Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the
* supported position values.
* @param {Mixed} element The element to align to.
* @param {String} position The position to align to.
* @param {Array} offsets (optional) Offset the positioning by [x, y]
* @return {Array} [x, y]
*/
getAlignToXY : function(el, p, o){
el = Ext.get(el);
if(!el || !el.dom){
throw "Element.alignToXY with an element that doesn't exist";
}
var d = this.dom;
var c = false; //constrain to viewport
var p1 = "", p2 = "";
o = o || [0,0];
if(!p){
p = "tl-bl";
}else if(p == "?"){
p = "tl-bl?";
}else if(p.indexOf("-") == -1){
p = "tl-" + p;
}
p = p.toLowerCase();
var m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/);
if(!m){
throw "Element.alignTo with an invalid alignment " + p;
}
p1 = m[1]; p2 = m[2]; c = !!m[3];
//Subtract the aligned el's internal xy from the target's offset xy
//plus custom offset to get the aligned el's new offset xy
var a1 = this.getAnchorXY(p1, true);
var a2 = el.getAnchorXY(p2, false);
var x = a2[0] - a1[0] + o[0];
var y = a2[1] - a1[1] + o[1];
if(c){
//constrain the aligned el to viewport if necessary
var w = this.getWidth(), h = this.getHeight(), r = el.getRegion();
// 5px of margin for ie
var dw = D.getViewWidth()-5, dh = D.getViewHeight()-5;
//If we are at a viewport boundary and the aligned el is anchored on a target border that is
//perpendicular to the vp border, allow the aligned el to slide on that border,
//otherwise swap the aligned el to the opposite border of the target.
var p1y = p1.charAt(0), p1x = p1.charAt(p1.length-1);
var p2y = p2.charAt(0), p2x = p2.charAt(p2.length-1);
var swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t"));
var swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r"));
var doc = document;
var scrollX = (doc.documentElement.scrollLeft || doc.body.scrollLeft || 0)+5;
var scrollY = (doc.documentElement.scrollTop || doc.body.scrollTop || 0)+5;
if((x+w) > dw + scrollX){
x = swapX ? r.left-w : dw+scrollX-w;
}
if(x < scrollX){
x = swapX ? r.right : scrollX;
}
if((y+h) > dh + scrollY){
y = swapY ? r.top-h : dh+scrollY-h;
}
if (y < scrollY){
y = swapY ? r.bottom : scrollY;
}
}
return [x,y];
},
// private
getConstrainToXY : function(){
var os = {top:0, left:0, bottom:0, right: 0};
return function(el, local, offsets, proposedXY){
el = Ext.get(el);
offsets = offsets ? Ext.applyIf(offsets, os) : os;
var vw, vh, vx = 0, vy = 0;
if(el.dom == document.body || el.dom == document){
vw = Ext.lib.Dom.getViewWidth();
vh = Ext.lib.Dom.getViewHeight();
}else{
vw = el.dom.clientWidth;
vh = el.dom.clientHeight;
if(!local){
var vxy = el.getXY();
vx = vxy[0];
vy = vxy[1];
}
}
var s = el.getScroll();
vx += offsets.left + s.left;
vy += offsets.top + s.top;
vw -= offsets.right;
vh -= offsets.bottom;
var vr = vx+vw;
var vb = vy+vh;
var xy = proposedXY || (!local ? this.getXY() : [this.getLeft(true), this.getTop(true)]);
var x = xy[0], y = xy[1];
var w = this.dom.offsetWidth, h = this.dom.offsetHeight;
// only move it if it needs it
var moved = false;
// first validate right/bottom
if((x + w) > vr){
x = vr - w;
moved = true;
}
if((y + h) > vb){
y = vb - h;
moved = true;
}
// then make sure top/left isn't negative
if(x < vx){
x = vx;
moved = true;
}
if(y < vy){
y = vy;
moved = true;
}
return moved ? [x, y] : false;
};
}(),
// private
adjustForConstraints : function(xy, parent, offsets){
return this.getConstrainToXY(parent || document, false, offsets, xy) || xy;
},
/**
* Aligns this element with another element relative to the specified anchor points. If the other element is the
* document it aligns it to the viewport.
* The position parameter is optional, and can be specified in any one of the following formats:
* <ul>
* <li><b>Blank</b>: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").</li>
* <li><b>One anchor (deprecated)</b>: The passed anchor position is used as the target element's anchor point.
* The element being aligned will position its top-left corner (tl) to that point. <i>This method has been
* deprecated in favor of the newer two anchor syntax below</i>.</li>
* <li><b>Two anchors</b>: If two values from the table below are passed separated by a dash, the first value is used as the
* element's anchor point, and the second value is used as the target's anchor point.</li>
* </ul>
* In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of
* the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to
* the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than
* that specified in order to enforce the viewport constraints.
* Following are all of the supported anchor positions:
<pre>
Value Description
----- -----------------------------
tl The top left corner (default)
t The center of the top edge
tr The top right corner
l The center of the left edge
c In the center of the element
r The center of the right edge
bl The bottom left corner
b The center of the bottom edge
br The bottom right corner
</pre>
Example Usage:
<pre><code>
// align el to other-el using the default positioning ("tl-bl", non-constrained)
el.alignTo("other-el");
// align the top left corner of el with the top right corner of other-el (constrained to viewport)
el.alignTo("other-el", "tr?");
// align the bottom right corner of el with the center left edge of other-el
el.alignTo("other-el", "br-l?");
// align the center of el with the bottom left corner of other-el and
// adjust the x position by -6 pixels (and the y position by 0)
el.alignTo("other-el", "c-bl", [-6, 0]);
</code></pre>
* @param {Mixed} element The element to align to.
* @param {String} position The position to align to.
* @param {Array} offsets (optional) Offset the positioning by [x, y]
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Ext.Element} this
*/
alignTo : function(element, position, offsets, animate){
var xy = this.getAlignToXY(element, position, offsets);
this.setXY(xy, this.preanim(arguments, 3));
return this;
},
/**
* Anchors an element to another element and realigns it when the window is resized.
* @param {Mixed} element The element to align to.
* @param {String} position The position to align to.
* @param {Array} offsets (optional) Offset the positioning by [x, y]
* @param {Boolean/Object} animate (optional) True for the default animation or a standard Element animation config object
* @param {Boolean/Number} monitorScroll (optional) True to monitor body scroll and reposition. If this parameter
* is a number, it is used as the buffer delay (defaults to 50ms).
* @param {Function} callback The function to call after the animation finishes
* @return {Ext.Element} this
*/
anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback){
var action = function(){
this.alignTo(el, alignment, offsets, animate);
Ext.callback(callback, this);
};
Ext.EventManager.onWindowResize(action, this);
var tm = typeof monitorScroll;
if(tm != 'undefined'){
Ext.EventManager.on(window, 'scroll', action, this,
{buffer: tm == 'number' ? monitorScroll : 50});
}
action.call(this); // align immediately
return this;
},
/**
* Clears any opacity settings from this element. Required in some cases for IE.
* @return {Ext.Element} this
*/
clearOpacity : function(){
if (window.ActiveXObject) {
if(typeof this.dom.style.filter == 'string' && (/alpha/i).test(this.dom.style.filter)){
this.dom.style.filter = "";
}
} else {
this.dom.style.opacity = "";
this.dom.style["-moz-opacity"] = "";
this.dom.style["-khtml-opacity"] = "";
}
return this;
},
/**
* Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Ext.Element} this
*/
hide : function(animate){
this.setVisible(false, this.preanim(arguments, 0));
return this;
},
/**
* Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Ext.Element} this
*/
show : function(animate){
this.setVisible(true, this.preanim(arguments, 0));
return this;
},
/**
* @private Test if size has a unit, otherwise appends the default
*/
addUnits : function(size){
return Ext.Element.addUnits(size, this.defaultUnit);
},
/**
* Update the innerHTML of this element, optionally searching for and processing scripts
* @param {String} html The new HTML
* @param {Boolean} loadScripts (optional) True to look for and process scripts (defaults to false)
* @param {Function} callback (optional) For async script loading you can be notified when the update completes
* @return {Ext.Element} this
*/
update : function(html, loadScripts, callback){
if(typeof html == "undefined"){
html = "";
}
if(loadScripts !== true){
this.dom.innerHTML = html;
if(typeof callback == "function"){
callback();
}
return this;
}
var id = Ext.id();
var dom = this.dom;
html += '<span id="' + id + '"></span>';
E.onAvailable(id, function(){
var hd = document.getElementsByTagName("head")[0];
var re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig;
var srcRe = /\ssrc=([\'\"])(.*?)\1/i;
var typeRe = /\stype=([\'\"])(.*?)\1/i;
var match;
while(match = re.exec(html)){
var attrs = match[1];
var srcMatch = attrs ? attrs.match(srcRe) : false;
if(srcMatch && srcMatch[2]){
var s = document.createElement("script");
s.src = srcMatch[2];
var typeMatch = attrs.match(typeRe);
if(typeMatch && typeMatch[2]){
s.type = typeMatch[2];
}
hd.appendChild(s);
}else if(match[2] && match[2].length > 0){
if(window.execScript) {
window.execScript(match[2]);
} else {
window.eval(match[2]);
}
}
}
var el = document.getElementById(id);
if(el){Ext.removeNode(el);}
if(typeof callback == "function"){
callback();
}
});
dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");
return this;
},
/**
* Direct access to the Updater {@link Ext.Updater#update} method (takes the same parameters).
* @param {String/Function} url The url for this request or a function to call to get the url
* @param {String/Object} params (optional) The parameters to pass as either a url encoded string "param1=1&param2=2" or an object {param1: 1, param2: 2}
* @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
* @param {Boolean} discardUrl (optional) By default when you execute an update the defaultUrl is changed to the last used url. If true, it will not store the url.
* @return {Ext.Element} this
*/
load : function(){
var um = this.getUpdater();
um.update.apply(um, arguments);
return this;
},
/**
* Gets this element's Updater
* @return {Ext.Updater} The Updater
*/
getUpdater : function(){
if(!this.updateManager){
this.updateManager = new Ext.Updater(this);
}
return this.updateManager;
},
/**
* Disables text selection for this element (normalized across browsers)
* @return {Ext.Element} this
*/
unselectable : function(){
this.dom.unselectable = "on";
this.swallowEvent("selectstart", true);
this.applyStyles("-moz-user-select:none;-khtml-user-select:none;");
this.addClass("x-unselectable");
return this;
},
/**
* Calculates the x, y to center this element on the screen
* @return {Array} The x, y values [x, y]
*/
getCenterXY : function(){
return this.getAlignToXY(document, 'c-c');
},
/**
* Centers the Element in either the viewport, or another Element.
* @param {Mixed} centerIn (optional) The element in which to center the element.
*/
center : function(centerIn){
this.alignTo(centerIn || document, 'c-c');
return this;
},
/**
* Tests various css rules/browsers to determine if this element uses a border box
* @return {Boolean}
*/
isBorderBox : function(){
return noBoxAdjust[this.dom.tagName.toLowerCase()] || Ext.isBorderBox;
},
/**
* Return a box {x, y, width, height} that can be used to set another elements
* size/location to match this element.
* @param {Boolean} contentBox (optional) If true a box for the content of the element is returned.
* @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y.
* @return {Object} box An object in the format {x, y, width, height}
*/
getBox : function(contentBox, local){
var xy;
if(!local){
xy = this.getXY();
}else{
var left = parseInt(this.getStyle("left"), 10) || 0;
var top = parseInt(this.getStyle("top"), 10) || 0;
xy = [left, top];
}
var el = this.dom, w = el.offsetWidth, h = el.offsetHeight, bx;
if(!contentBox){
bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};
}else{
var l = this.getBorderWidth("l")+this.getPadding("l");
var r = this.getBorderWidth("r")+this.getPadding("r");
var t = this.getBorderWidth("t")+this.getPadding("t");
var b = this.getBorderWidth("b")+this.getPadding("b");
bx = {x: xy[0]+l, y: xy[1]+t, 0: xy[0]+l, 1: xy[1]+t, width: w-(l+r), height: h-(t+b)};
}
bx.right = bx.x + bx.width;
bx.bottom = bx.y + bx.height;
return bx;
},
/**
* Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
for more information about the sides.
* @param {String} sides
* @return {Number}
*/
getFrameWidth : function(sides, onlyContentBox){
return onlyContentBox && Ext.isBorderBox ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
},
/**
* Sets the element's box. Use getBox() on another element to get a box obj. If animate is true then width, height, x and y will be animated concurrently.
* @param {Object} box The box to fill {x, y, width, height}
* @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Ext.Element} this
*/
setBox : function(box, adjust, animate){
var w = box.width, h = box.height;
if((adjust && !this.autoBoxAdjust) && !this.isBorderBox()){
w -= (this.getBorderWidth("lr") + this.getPadding("lr"));
h -= (this.getBorderWidth("tb") + this.getPadding("tb"));
}
this.setBounds(box.x, box.y, w, h, this.preanim(arguments, 2));
return this;
},
/**
* Forces the browser to repaint this element
* @return {Ext.Element} this
*/
repaint : function(){
var dom = this.dom;
this.addClass("x-repaint");
setTimeout(function(){
Ext.get(dom).removeClass("x-repaint");
}, 1);
return this;
},
/**
* Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
* then it returns the calculated width of the sides (see getPadding)
* @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
* @return {Object/Number}
*/
getMargins : function(side){
if(!side){
return {
top: parseInt(this.getStyle("margin-top"), 10) || 0,
left: parseInt(this.getStyle("margin-left"), 10) || 0,
bottom: parseInt(this.getStyle("margin-bottom"), 10) || 0,
right: parseInt(this.getStyle("margin-right"), 10) || 0
};
}else{
return this.addStyles(side, El.margins);
}
},
// private
addStyles : function(sides, styles){
var val = 0, v, w;
for(var i = 0, len = sides.length; i < len; i++){
v = this.getStyle(styles[sides.charAt(i)]);
if(v){
w = parseInt(v, 10);
if(w){ val += (w >= 0 ? w : -1 * w); }
}
}
return val;
},
/**
* Creates a proxy element of this element
* @param {String/Object} config The class name of the proxy element or a DomHelper config object
* @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
* @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
* @return {Ext.Element} The new proxy element
*/
createProxy : function(config, renderTo, matchBox){
config = typeof config == "object" ?
config : {tag : "div", cls: config};
var proxy;
if(renderTo){
proxy = Ext.DomHelper.append(renderTo, config, true);
}else {
proxy = Ext.DomHelper.insertBefore(this.dom, config, true);
}
if(matchBox){
proxy.setBox(this.getBox());
}
return proxy;
},
/**
* Puts a mask over this element to disable user interaction. Requires core.css.
* This method can only be applied to elements which accept child nodes.
* @param {String} msg (optional) A message to display in the mask
* @param {String} msgCls (optional) A css class to apply to the msg element
* @return {Element} The mask element
*/
mask : function(msg, msgCls){
if(this.getStyle("position") == "static"){
this.setStyle("position", "relative");
}
if(this._maskMsg){
this._maskMsg.remove();
}
if(this._mask){
this._mask.remove();
}
this._mask = Ext.DomHelper.append(this.dom, {cls:"ext-el-mask"}, true);
this.addClass("x-masked");
this._mask.setDisplayed(true);
if(typeof msg == 'string'){
this._maskMsg = Ext.DomHelper.append(this.dom, {cls:"ext-el-mask-msg", cn:{tag:'div'}}, true);
var mm = this._maskMsg;
mm.dom.className = msgCls ? "ext-el-mask-msg " + msgCls : "ext-el-mask-msg";
mm.dom.firstChild.innerHTML = msg;
mm.setDisplayed(true);
mm.center(this);
}
if(Ext.isIE && !(Ext.isIE7 && Ext.isStrict) && this.getStyle('height') == 'auto'){ // ie will not expand full height automatically
this._mask.setSize(this.dom.clientWidth, this.getHeight());
}
return this._mask;
},
/**
* Removes a previously applied mask.
*/
unmask : function(){
if(this._mask){
if(this._maskMsg){
this._maskMsg.remove();
delete this._maskMsg;
}
this._mask.remove();
delete this._mask;
}
this.removeClass("x-masked");
},
/**
* Returns true if this element is masked
* @return {Boolean}
*/
isMasked : function(){
return this._mask && this._mask.isVisible();
},
/**
* Creates an iframe shim for this element to keep selects and other windowed objects from
* showing through.
* @return {Ext.Element} The new shim element
*/
createShim : function(){
var el = document.createElement('iframe');
el.frameBorder = 'no';
el.className = 'ext-shim';
if(Ext.isIE && Ext.isSecure){
el.src = Ext.SSL_SECURE_URL;
}
var shim = Ext.get(this.dom.parentNode.insertBefore(el, this.dom));
shim.autoBoxAdjust = false;
return shim;
},
/**
* Removes this element from the DOM and deletes it from the cache
*/
remove : function(){
Ext.removeNode(this.dom);
delete El.cache[this.dom.id];
},
/**
* Sets up event handlers to call the passed functions when the mouse is over this element. Automatically
* filters child element mouse events.
* @param {Function} overFn
* @param {Function} outFn
* @param {Object} scope (optional)
* @return {Ext.Element} this
*/
hover : function(overFn, outFn, scope){
var preOverFn = function(e){
if(!e.within(this, true)){
overFn.apply(scope || this, arguments);
}
};
var preOutFn = function(e){
if(!e.within(this, true)){
outFn.apply(scope || this, arguments);
}
};
this.on("mouseover", preOverFn, this.dom);
this.on("mouseout", preOutFn, this.dom);
return this;
},
/**
* Sets up event handlers to add and remove a css class when the mouse is over this element
* @param {String} className
* @param {Boolean} preventFlicker (optional) If set to true, it prevents flickering by filtering
* mouseout events for children elements
* @return {Ext.Element} this
*/
addClassOnOver : function(className, preventFlicker){
this.hover(
function(){
Ext.fly(this, '_internal').addClass(className);
},
function(){
Ext.fly(this, '_internal').removeClass(className);
}
);
return this;
},
/**
* Sets up event handlers to add and remove a css class when this element has the focus
* @param {String} className
* @return {Ext.Element} this
*/
addClassOnFocus : function(className){
this.on("focus", function(){
Ext.fly(this, '_internal').addClass(className);
}, this.dom);
this.on("blur", function(){
Ext.fly(this, '_internal').removeClass(className);
}, this.dom);
return this;
},
/**
* Sets up event handlers to add and remove a css class when the mouse is down and then up on this element (a click effect)
* @param {String} className
* @return {Ext.Element} this
*/
addClassOnClick : function(className){
var dom = this.dom;
this.on("mousedown", function(){
Ext.fly(dom, '_internal').addClass(className);
var d = Ext.getDoc();
var fn = function(){
Ext.fly(dom, '_internal').removeClass(className);
d.removeListener("mouseup", fn);
};
d.on("mouseup", fn);
});
return this;
},
/**
* Stops the specified event from bubbling and optionally prevents the default action
* @param {String} eventName
* @param {Boolean} preventDefault (optional) true to prevent the default action too
* @return {Ext.Element} this
*/
swallowEvent : function(eventName, preventDefault){
var fn = function(e){
e.stopPropagation();
if(preventDefault){
e.preventDefault();
}
};
if(Ext.isArray(eventName)){
for(var i = 0, len = eventName.length; i < len; i++){
this.on(eventName[i], fn);
}
return this;
}
this.on(eventName, fn);
return this;
},
/**
* Gets the parent node for this element, optionally chaining up trying to match a selector
* @param {String} selector (optional) Find a parent node that matches the passed simple selector
* @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
* @return {Ext.Element/HTMLElement} The parent node or null
*/
parent : function(selector, returnDom){
return this.matchNode('parentNode', 'parentNode', selector, returnDom);
},
/**
* Gets the next sibling, skipping text nodes
* @param {String} selector (optional) Find the next sibling that matches the passed simple selector
* @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
* @return {Ext.Element/HTMLElement} The next sibling or null
*/
next : function(selector, returnDom){
return this.matchNode('nextSibling', 'nextSibling', selector, returnDom);
},
/**
* Gets the previous sibling, skipping text nodes
* @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
* @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
* @return {Ext.Element/HTMLElement} The previous sibling or null
*/
prev : function(selector, returnDom){
return this.matchNode('previousSibling', 'previousSibling', selector, returnDom);
},
/**
* Gets the first child, skipping text nodes
* @param {String} selector (optional) Find the next sibling that matches the passed simple selector
* @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
* @return {Ext.Element/HTMLElement} The first child or null
*/
first : function(selector, returnDom){
return this.matchNode('nextSibling', 'firstChild', selector, returnDom);
},
/**
* Gets the last child, skipping text nodes
* @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
* @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
* @return {Ext.Element/HTMLElement} The last child or null
*/
last : function(selector, returnDom){
return this.matchNode('previousSibling', 'lastChild', selector, returnDom);
},
matchNode : function(dir, start, selector, returnDom){
var n = this.dom[start];
while(n){
if(n.nodeType == 1 && (!selector || Ext.DomQuery.is(n, selector))){
return !returnDom ? Ext.get(n) : n;
}
n = n[dir];
}
return null;
},
/**
* Appends the passed element(s) to this element
* @param {String/HTMLElement/Array/Element/CompositeElement} el
* @return {Ext.Element} this
*/
appendChild: function(el){
el = Ext.get(el);
el.appendTo(this);
return this;
},
/**
* Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
* @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
* automatically generated with the specified attributes.
* @param {HTMLElement} insertBefore (optional) a child element of this element
* @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
* @return {Ext.Element} The new child element
*/
createChild: function(config, insertBefore, returnDom){
config = config || {tag:'div'};
if(insertBefore){
return Ext.DomHelper.insertBefore(insertBefore, config, returnDom !== true);
}
return Ext.DomHelper[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config, returnDom !== true);
},
/**
* Appends this element to the passed element
* @param {Mixed} el The new parent element
* @return {Ext.Element} this
*/
appendTo: function(el){
el = Ext.getDom(el);
el.appendChild(this.dom);
return this;
},
/**
* Inserts this element before the passed element in the DOM
* @param {Mixed} el The element before which this element will be inserted
* @return {Ext.Element} this
*/
insertBefore: function(el){
el = Ext.getDom(el);
el.parentNode.insertBefore(this.dom, el);
return this;
},
/**
* Inserts this element after the passed element in the DOM
* @param {Mixed} el The element to insert after
* @return {Ext.Element} this
*/
insertAfter: function(el){
el = Ext.getDom(el);
el.parentNode.insertBefore(this.dom, el.nextSibling);
return this;
},
/**
* Inserts (or creates) an element (or DomHelper config) as the first child of this element
* @param {Mixed/Object} el The id or element to insert or a DomHelper config to create and insert
* @return {Ext.Element} The new child
*/
insertFirst: function(el, returnDom){
el = el || {};
if(typeof el == 'object' && !el.nodeType && !el.dom){ // dh config
return this.createChild(el, this.dom.firstChild, returnDom);
}else{
el = Ext.getDom(el);
this.dom.insertBefore(el, this.dom.firstChild);
return !returnDom ? Ext.get(el) : el;
}
},
/**
* Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element
* @param {Mixed/Object/Array} el The id, element to insert or a DomHelper config to create and insert *or* an array of any of those.
* @param {String} where (optional) 'before' or 'after' defaults to before
* @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element
* @return {Ext.Element} the inserted Element
*/
insertSibling: function(el, where, returnDom){
var rt;
if(Ext.isArray(el)){
for(var i = 0, len = el.length; i < len; i++){
rt = this.insertSibling(el[i], where, returnDom);
}
return rt;
}
where = where ? where.toLowerCase() : 'before';
el = el || {};
var refNode = where == 'before' ? this.dom : this.dom.nextSibling;
if(typeof el == 'object' && !el.nodeType && !el.dom){ // dh config
if(where == 'after' && !this.dom.nextSibling){
rt = Ext.DomHelper.append(this.dom.parentNode, el, !returnDom);
}else{
rt = Ext.DomHelper[where == 'after' ? 'insertAfter' : 'insertBefore'](this.dom, el, !returnDom);
}
}else{
rt = this.dom.parentNode.insertBefore(Ext.getDom(el), refNode);
if(!returnDom){
rt = Ext.get(rt);
}
}
return rt;
},
/**
* Creates and wraps this element with another element
* @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
* @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element
* @return {HTMLElement/Element} The newly created wrapper element
*/
wrap: function(config, returnDom){
if(!config){
config = {tag: "div"};
}
var newEl = Ext.DomHelper.insertBefore(this.dom, config, !returnDom);
newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);
return newEl;
},
/**
* Replaces the passed element with this element
* @param {Mixed} el The element to replace
* @return {Ext.Element} this
*/
replace: function(el){
el = Ext.get(el);
this.insertBefore(el);
el.remove();
return this;
},
/**
* Replaces this element with the passed element
* @param {Mixed/Object} el The new element or a DomHelper config of an element to create
* @return {Ext.Element} this
*/
replaceWith: function(el){
if(typeof el == 'object' && !el.nodeType && !el.dom){ // dh config
el = this.insertSibling(el, 'before');
}else{
el = Ext.getDom(el);
this.dom.parentNode.insertBefore(el, this.dom);
}
El.uncache(this.id);
this.dom.parentNode.removeChild(this.dom);
this.dom = el;
this.id = Ext.id(el);
El.cache[this.id] = this;
return this;
},
/**
* Inserts an html fragment into this element
* @param {String} where Where to insert the html in relation to this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
* @param {String} html The HTML fragment
* @param {Boolean} returnEl (optional) True to return an Ext.Element (defaults to false)
* @return {HTMLElement/Ext.Element} The inserted node (or nearest related if more than 1 inserted)
*/
insertHtml : function(where, html, returnEl){
var el = Ext.DomHelper.insertHtml(where, this.dom, html);
return returnEl ? Ext.get(el) : el;
},
/**
* Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
* @param {Object} o The object with the attributes
* @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.
* @return {Ext.Element} this
*/
set : function(o, useSet){
var el = this.dom;
useSet = typeof useSet == 'undefined' ? (el.setAttribute ? true : false) : useSet;
for(var attr in o){
if(attr == "style" || typeof o[attr] == "function") continue;
if(attr=="cls"){
el.className = o["cls"];
}else if(o.hasOwnProperty(attr)){
if(useSet) el.setAttribute(attr, o[attr]);
else el[attr] = o[attr];
}
}
if(o.style){
Ext.DomHelper.applyStyles(el, o.style);
}
return this;
},
/**
* Convenience method for constructing a KeyMap
* @param {Number/Array/Object/String} key Either a string with the keys to listen for, the numeric key code, array of key codes or an object with the following options:
* {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
* @param {Function} fn The function to call
* @param {Object} scope (optional) The scope of the function
* @return {Ext.KeyMap} The KeyMap created
*/
addKeyListener : function(key, fn, scope){
var config;
if(typeof key != "object" || Ext.isArray(key)){
config = {
key: key,
fn: fn,
scope: scope
};
}else{
config = {
key : key.key,
shift : key.shift,
ctrl : key.ctrl,
alt : key.alt,
fn: fn,
scope: scope
};
}
return new Ext.KeyMap(this, config);
},
/**
* Creates a KeyMap for this element
* @param {Object} config The KeyMap config. See {@link Ext.KeyMap} for more details
* @return {Ext.KeyMap} The KeyMap created
*/
addKeyMap : function(config){
return new Ext.KeyMap(this, config);
},
/**
* Returns true if this element is scrollable.
* @return {Boolean}
*/
isScrollable : function(){
var dom = this.dom;
return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth;
},
/**
* Scrolls this element the specified scroll point. It does NOT do bounds checking so if you scroll to a weird value it will try to do it. For auto bounds checking, use scroll().
* @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
* @param {Number} value The new scroll value
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Element} this
*/
scrollTo : function(side, value, animate){
var prop = side.toLowerCase() == "left" ? "scrollLeft" : "scrollTop";
if(!animate || !A){
this.dom[prop] = value;
}else{
var to = prop == "scrollLeft" ? [value, this.dom.scrollTop] : [this.dom.scrollLeft, value];
this.anim({scroll: {"to": to}}, this.preanim(arguments, 2), 'scroll');
}
return this;
},
/**
* Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
* within this element's scrollable range.
* @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".
* @param {Number} distance How far to scroll the element in pixels
* @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
* @return {Boolean} Returns true if a scroll was triggered or false if the element
* was scrolled as far as it could go.
*/
scroll : function(direction, distance, animate){
if(!this.isScrollable()){
return;
}
var el = this.dom;
var l = el.scrollLeft, t = el.scrollTop;
var w = el.scrollWidth, h = el.scrollHeight;
var cw = el.clientWidth, ch = el.clientHeight;
direction = direction.toLowerCase();
var scrolled = false;
var a = this.preanim(arguments, 2);
switch(direction){
case "l":
case "left":
if(w - l > cw){
var v = Math.min(l + distance, w-cw);
this.scrollTo("left", v, a);
scrolled = true;
}
break;
case "r":
case "right":
if(l > 0){
var v = Math.max(l - distance, 0);
this.scrollTo("left", v, a);
scrolled = true;
}
break;
case "t":
case "top":
case "up":
if(t > 0){
var v = Math.max(t - distance, 0);
this.scrollTo("top", v, a);
scrolled = true;
}
break;
case "b":
case "bottom":
case "down":
if(h - t > ch){
var v = Math.min(t + distance, h-ch);
this.scrollTo("top", v, a);
scrolled = true;
}
break;
}
return scrolled;
},
/**
* Translates the passed page coordinates into left/top css values for this element
* @param {Number/Array} x The page x or an array containing [x, y]
* @param {Number} y The page y
* @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
*/
translatePoints : function(x, y){
if(typeof x == 'object' || Ext.isArray(x)){
y = x[1]; x = x[0];
}
var p = this.getStyle('position');
var o = this.getXY();
var l = parseInt(this.getStyle('left'), 10);
var t = parseInt(this.getStyle('top'), 10);
if(isNaN(l)){
l = (p == "relative") ? 0 : this.dom.offsetLeft;
}
if(isNaN(t)){
t = (p == "relative") ? 0 : this.dom.offsetTop;
}
return {left: (x - o[0] + l), top: (y - o[1] + t)};
},
/**
* Returns the current scroll position of the element.
* @return {Object} An object containing the scroll position in the format {left: (scrollLeft), top: (scrollTop)}
*/
getScroll : function(){
var d = this.dom, doc = document;
if(d == doc || d == doc.body){
var l, t;
if(Ext.isIE && Ext.isStrict){
l = doc.documentElement.scrollLeft || (doc.body.scrollLeft || 0);
t = doc.documentElement.scrollTop || (doc.body.scrollTop || 0);
}else{
l = window.pageXOffset || (doc.body.scrollLeft || 0);
t = window.pageYOffset || (doc.body.scrollTop || 0);
}
return {left: l, top: t};
}else{
return {left: d.scrollLeft, top: d.scrollTop};
}
},
/**
* Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
* are convert to standard 6 digit hex color.
* @param {String} attr The css attribute
* @param {String} defaultValue The default value to use when a valid color isn't found
* @param {String} prefix (optional) defaults to #. Use an empty string when working with
* color anims.
*/
getColor : function(attr, defaultValue, prefix){
var v = this.getStyle(attr);
if(!v || v == "transparent" || v == "inherit") {
return defaultValue;
}
var color = typeof prefix == "undefined" ? "#" : prefix;
if(v.substr(0, 4) == "rgb("){
var rvs = v.slice(4, v.length -1).split(",");
for(var i = 0; i < 3; i++){
var h = parseInt(rvs[i]);
var s = h.toString(16);
if(h < 16){
s = "0" + s;
}
color += s;
}
} else {
if(v.substr(0, 1) == "#"){
if(v.length == 4) {
for(var i = 1; i < 4; i++){
var c = v.charAt(i);
color += c + c;
}
}else if(v.length == 7){
color += v.substr(1);
}
}
}
return(color.length > 5 ? color.toLowerCase() : defaultValue);
},
/**
* Wraps the specified element with a special markup/CSS block that renders by default as a gray container with a
* gradient background, rounded corners and a 4-way shadow. Example usage:
* <pre><code>
// Basic box wrap
Ext.get("foo").boxWrap();
// You can also add a custom class and use CSS inheritance rules to customize the box look.
// 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example
// for how to create a custom box wrap style.
Ext.get("foo").boxWrap().addClass("x-box-blue");
</pre></code>
* @param {String} class (optional) A base CSS class to apply to the containing wrapper element (defaults to 'x-box').
* Note that there are a number of CSS rules that are dependent on this name to make the overall effect work,
* so if you supply an alternate base class, make sure you also supply all of the necessary rules.
* @return {Ext.Element} this
*/
boxWrap : function(cls){
cls = cls || 'x-box';
var el = Ext.get(this.insertHtml('beforeBegin', String.format('<div class="{0}">'+El.boxMarkup+'</div>', cls)));
el.child('.'+cls+'-mc').dom.appendChild(this.dom);
return el;
},
/**
* Returns the value of a namespaced attribute from the element's underlying DOM node.
* @param {String} namespace The namespace in which to look for the attribute
* @param {String} name The attribute name
* @return {String} The attribute value
*/
getAttributeNS : Ext.isIE ? function(ns, name){
var d = this.dom;
var type = typeof d[ns+":"+name];
if(type != 'undefined' && type != 'unknown'){
return d[ns+":"+name];
}
return d[name];
} : function(ns, name){
var d = this.dom;
return d.getAttributeNS(ns, name) || d.getAttribute(ns+":"+name) || d.getAttribute(name) || d[name];
},
getTextWidth : function(text, min, max){
return (Ext.util.TextMetrics.measure(this.dom, Ext.value(text, this.dom.innerHTML, true)).width).constrain(min || 0, max || 1000000);
}
};
var ep = El.prototype;
/**
* Appends an event handler (shorthand for {@link #addListener}).
* @param {String} eventName The type of event to handle
* @param {Function} fn The handler function the event invokes
* @param {Object} scope (optional) The scope (this element) of the handler function
* @param {Object} options (optional) An object containing standard {@link #addListener} options
* @member Ext.Element
* @method on
*/
ep.on = ep.addListener;
// backwards compat
ep.mon = ep.addListener;
ep.getUpdateManager = ep.getUpdater;
/**
* Removes an event handler from this element (shorthand for {@link #removeListener}).
* @param {String} eventName the type of event to remove
* @param {Function} fn the method the event invokes
* @return {Ext.Element} this
* @member Ext.Element
* @method un
*/
ep.un = ep.removeListener;
/**
* true to automatically adjust width and height settings for box-model issues (default to true)
*/
ep.autoBoxAdjust = true;
// private
El.unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i;
// private
El.addUnits = function(v, defaultUnit){
if(v === "" || v == "auto"){
return v;
}
if(v === undefined){
return '';
}
if(typeof v == "number" || !El.unitPattern.test(v)){
return v + (defaultUnit || 'px');
}
return v;
};
// special markup used throughout Ext when box wrapping elements
El.boxMarkup = '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div><div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div><div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
/**
* Visibility mode constant - Use visibility to hide element
* @static
* @type Number
*/
El.VISIBILITY = 1;
/**
* Visibility mode constant - Use display to hide element
* @static
* @type Number
*/
El.DISPLAY = 2;
El.borders = {l: "border-left-width", r: "border-right-width", t: "border-top-width", b: "border-bottom-width"};
El.paddings = {l: "padding-left", r: "padding-right", t: "padding-top", b: "padding-bottom"};
El.margins = {l: "margin-left", r: "margin-right", t: "margin-top", b: "margin-bottom"};
/**
* @private
*/
El.cache = {};
var docEl;
/**
* Static method to retrieve Element objects. Uses simple caching to consistently return the same object.
* Automatically fixes if an object was recreated with the same id via AJAX or DOM.
* @param {Mixed} el The id of the node, a DOM Node or an existing Element.
* @return {Element} The Element object (or null if no matching element was found)
* @static
*/
El.get = function(el){
var ex, elm, id;
if(!el){ return null; }
if(typeof el == "string"){ // element id
if(!(elm = document.getElementById(el))){
return null;
}
if(ex = El.cache[el]){
ex.dom = elm;
}else{
ex = El.cache[el] = new El(elm);
}
return ex;
}else if(el.tagName){ // dom element
if(!(id = el.id)){
id = Ext.id(el);
}
if(ex = El.cache[id]){
ex.dom = el;
}else{
ex = El.cache[id] = new El(el);
}
return ex;
}else if(el instanceof El){
if(el != docEl){
el.dom = document.getElementById(el.id) || el.dom; // refresh dom element in case no longer valid,
// catch case where it hasn't been appended
El.cache[el.id] = el; // in case it was created directly with Element(), let's cache it
}
return el;
}else if(el.isComposite){
return el;
}else if(Ext.isArray(el)){
return El.select(el);
}else if(el == document){
// create a bogus element object representing the document object
if(!docEl){
var f = function(){};
f.prototype = El.prototype;
docEl = new f();
docEl.dom = document;
}
return docEl;
}
return null;
};
// private
El.uncache = function(el){
for(var i = 0, a = arguments, len = a.length; i < len; i++) {
if(a[i]){
delete El.cache[a[i].id || a[i]];
}
}
};
// private
// Garbage collection - uncache elements/purge listeners on orphaned elements
// so we don't hold a reference and cause the browser to retain them
El.garbageCollect = function(){
if(!Ext.enableGarbageCollector){
clearInterval(El.collectorThread);
return;
}
for(var eid in El.cache){
var el = El.cache[eid], d = el.dom;
// -------------------------------------------------------
// Determining what is garbage:
// -------------------------------------------------------
// !d
// dom node is null, definitely garbage
// -------------------------------------------------------
// !d.parentNode
// no parentNode == direct orphan, definitely garbage
// -------------------------------------------------------
// !d.offsetParent && !document.getElementById(eid)
// display none elements have no offsetParent so we will
// also try to look it up by it's id. However, check
// offsetParent first so we don't do unneeded lookups.
// This enables collection of elements that are not orphans
// directly, but somewhere up the line they have an orphan
// parent.
// -------------------------------------------------------
if(!d || !d.parentNode || (!d.offsetParent && !document.getElementById(eid))){
delete El.cache[eid];
if(d && Ext.enableListenerCollection){
E.purgeElement(d);
}
}
}
}
El.collectorThreadId = setInterval(El.garbageCollect, 30000);
var flyFn = function(){};
flyFn.prototype = El.prototype;
var _cls = new flyFn();
// dom is optional
El.Flyweight = function(dom){
this.dom = dom;
};
El.Flyweight.prototype = _cls;
El.Flyweight.prototype.isFlyweight = true;
El._flyweights = {};
/**
* Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
* the dom node can be overwritten by other code.
* @param {String/HTMLElement} el The dom node or id
* @param {String} named (optional) Allows for creation of named reusable flyweights to
* prevent conflicts (e.g. internally Ext uses "_internal")
* @static
* @return {Element} The shared Element object (or null if no matching element was found)
*/
El.fly = function(el, named){
named = named || '_global';
el = Ext.getDom(el);
if(!el){
return null;
}
if(!El._flyweights[named]){
El._flyweights[named] = new El.Flyweight();
}
El._flyweights[named].dom = el;
return El._flyweights[named];
};
/**
* Static method to retrieve Element objects. Uses simple caching to consistently return the same object.
* Automatically fixes if an object was recreated with the same id via AJAX or DOM.
* Shorthand of {@link Ext.Element#get}
* @param {Mixed} el The id of the node, a DOM Node or an existing Element.
* @return {Element} The Element object
* @member Ext
* @method get
*/
Ext.get = El.get;
/**
* Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
* the dom node can be overwritten by other code.
* Shorthand of {@link Ext.Element#fly}
* @param {String/HTMLElement} el The dom node or id
* @param {String} named (optional) Allows for creation of named reusable flyweights to
* prevent conflicts (e.g. internally Ext uses "_internal")
* @static
* @return {Element} The shared Element object
* @member Ext
* @method fly
*/
Ext.fly = El.fly;
// speedy lookup for elements never to box adjust
var noBoxAdjust = Ext.isStrict ? {
select:1
} : {
input:1, select:1, textarea:1
};
if(Ext.isIE || Ext.isGecko){
noBoxAdjust['button'] = 1;
}
Ext.EventManager.on(window, 'unload', function(){
delete El.cache;
delete El._flyweights;
});
})();