1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277
|
QUnit.module( "event", {
beforeEach: function() {
document.body.focus();
},
afterEach: moduleTeardown
} );
QUnit.test( "null or undefined handler", function( assert ) {
assert.expect( 4 );
// Supports Fixes bug #7229
try {
jQuery( "#firstp" ).on( "click", null );
assert.ok( true, "Passing a null handler will not throw an exception" );
} catch ( e ) {}
try {
jQuery( "#firstp" ).on( "click", undefined );
assert.ok( true, "Passing an undefined handler will not throw an exception" );
} catch ( e ) {}
var expectedElem = jQuery( "#firstp" );
var actualElem = expectedElem.on( "click", null );
assert.equal( actualElem, expectedElem, "Passing a null handler should return the original element" );
actualElem = expectedElem.on( "click", undefined );
assert.equal( actualElem, expectedElem, "Passing a null handler should return the original element" );
} );
QUnit.test( "on() with non-null,defined data", function( assert ) {
assert.expect( 2 );
var handler = function( event, data ) {
assert.equal( data, 0, "non-null, defined data (zero) is correctly passed" );
};
jQuery( "#foo" ).on( "foo.on", handler );
jQuery( "div" ).on( "foo.delegate", "#foo", handler );
jQuery( "#foo" ).trigger( "foo", 0 );
jQuery( "#foo" ).off( "foo.on", handler );
jQuery( "div" ).off( "foo.delegate", "#foo" );
} );
QUnit.test( "Handler changes and .trigger() order", function( assert ) {
assert.expect( 1 );
var markup = jQuery(
"<div><div><p><span><b class=\"a\">b</b></span></p></div></div>"
),
path = "";
markup
.find( "*" ).addBack().on( "click", function() {
path += this.nodeName.toLowerCase() + " ";
} )
.filter( "b" ).on( "click", function( e ) {
// Removing span should not stop propagation to original parents
if ( e.target === this ) {
jQuery( this ).parent().remove();
}
} );
markup.find( "b" ).trigger( "click" );
assert.equal( path, "b p div div ", "Delivered all events" );
markup.remove();
} );
QUnit.test( "on(), with data", function( assert ) {
assert.expect( 4 );
var test, handler, handler2;
handler = function( event ) {
assert.ok( event.data, "on() with data, check passed data exists" );
assert.equal( event.data.foo, "bar", "on() with data, Check value of passed data" );
};
jQuery( "#firstp" ).on( "click", { "foo": "bar" }, handler ).trigger( "click" ).off( "click", handler );
assert.ok( !jQuery._data( jQuery( "#firstp" )[ 0 ], "events" ), "Event handler unbound when using data." );
test = function() {};
handler2 = function( event ) {
assert.equal( event.data, test, "on() with function data, Check value of passed data" );
};
jQuery( "#firstp" ).on( "click", test, handler2 ).trigger( "click" ).off( "click", handler2 );
} );
QUnit.test( "click(), with data", function( assert ) {
assert.expect( 3 );
var handler = function( event ) {
assert.ok( event.data, "on() with data, check passed data exists" );
assert.equal( event.data.foo, "bar", "on() with data, Check value of passed data" );
};
jQuery( "#firstp" ).on( "click", { "foo": "bar" }, handler ).trigger( "click" ).off( "click", handler );
assert.ok( !jQuery._data( jQuery( "#firstp" )[ 0 ], "events" ), "Event handler unbound when using data." );
} );
QUnit.test( "on(), with data, trigger with data", function( assert ) {
assert.expect( 4 );
var handler = function( event, data ) {
assert.ok( event.data, "check passed data exists" );
assert.equal( event.data.foo, "bar", "Check value of passed data" );
assert.ok( data, "Check trigger data" );
assert.equal( data.bar, "foo", "Check value of trigger data" );
};
jQuery( "#firstp" ).on( "click", { foo: "bar" }, handler ).trigger( "click", [ { bar: "foo" } ] ).off( "click", handler );
} );
QUnit.test( "on(), multiple events at once", function( assert ) {
assert.expect( 2 );
var handler,
clickCounter = 0,
mouseoverCounter = 0;
handler = function( event ) {
if ( event.type === "click" ) {
clickCounter += 1;
} else if ( event.type === "mouseover" ) {
mouseoverCounter += 1;
}
};
jQuery( "#firstp" ).on( "click mouseover", handler ).trigger( "click" ).trigger( "mouseover" );
assert.equal( clickCounter, 1, "on() with multiple events at once" );
assert.equal( mouseoverCounter, 1, "on() with multiple events at once" );
} );
QUnit.test( "on(), five events at once", function( assert ) {
assert.expect( 1 );
var count = 0,
handler = function() {
count++;
};
jQuery( "#firstp" ).on( "click mouseover foo bar baz", handler )
.trigger( "click" ).trigger( "mouseover" )
.trigger( "foo" ).trigger( "bar" )
.trigger( "baz" );
assert.equal( count, 5, "on() five events at once" );
} );
QUnit.test( "on(), multiple events at once and namespaces", function( assert ) {
assert.expect( 7 );
var cur, div,
obj = {};
div = jQuery( "<div></div>" ).on( "focusin.a", function( e ) {
assert.equal( e.type, cur, "Verify right single event was fired." );
} );
cur = "focusin";
div.trigger( "focusin.a" );
// manually clean up detached elements
div.remove();
div = jQuery( "<div></div>" ).on( "click mouseover", obj, function( e ) {
assert.equal( e.type, cur, "Verify right multi event was fired." );
assert.equal( e.data, obj, "Make sure the data came in correctly." );
} );
cur = "click";
div.trigger( "click" );
cur = "mouseover";
div.trigger( "mouseover" );
// manually clean up detached elements
div.remove();
div = jQuery( "<div></div>" ).on( "focusin.a focusout.b", function( e ) {
assert.equal( e.type, cur, "Verify right multi event was fired." );
} );
cur = "focusin";
div.trigger( "focusin.a" );
cur = "focusout";
div.trigger( "focusout.b" );
// manually clean up detached elements
div.remove();
} );
QUnit.test( "on(), namespace with special add", function( assert ) {
assert.expect( 27 );
var i = 0,
div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).on( "test", function() {
assert.ok( true, "Test event fired." );
} );
jQuery.event.special.test = {
_default: function( e, data ) {
assert.equal( e.type, "test", "Make sure we're dealing with a test event." );
assert.ok( data, "And that trigger data was passed." );
assert.strictEqual( e.target, div[ 0 ], "And that the target is correct." );
assert.equal( this, window, "And that the context is correct." );
},
setup: function() {},
teardown: function() {
assert.ok( true, "Teardown called." );
},
add: function( handleObj ) {
var handler = handleObj.handler;
handleObj.handler = function( e ) {
e.xyz = ++i;
handler.apply( this, arguments );
};
},
remove: function() {
assert.ok( true, "Remove called." );
}
};
div.on( "test.a", { x: 1 }, function( e ) {
assert.ok( !!e.xyz, "Make sure that the data is getting passed through." );
assert.equal( e.data[ "x" ], 1, "Make sure data is attached properly." );
} );
div.on( "test.b", { x: 2 }, function( e ) {
assert.ok( !!e.xyz, "Make sure that the data is getting passed through." );
assert.equal( e.data[ "x" ], 2, "Make sure data is attached properly." );
} );
// Should trigger 5
div.trigger( "test", 33.33 );
// Should trigger 2
div.trigger( "test.a", "George Harrison" );
// Should trigger 2
div.trigger( "test.b", { year: 1982 } );
// Should trigger 4
div.off( "test" );
div = jQuery( "<div></div>" ).on( "test", function() {
assert.ok( true, "Test event fired." );
} );
// Should trigger 2
div.appendTo( "#qunit-fixture" ).remove();
delete jQuery.event.special.test;
} );
QUnit.test( "on(), no data", function( assert ) {
assert.expect( 1 );
var handler = function( event ) {
assert.ok( !event.data, "Check that no data is added to the event object" );
};
jQuery( "#firstp" ).on( "click", handler ).trigger( "click" );
} );
QUnit.test( "on/one/off(Object)", function( assert ) {
assert.expect( 6 );
var $elem,
clickCounter = 0,
mouseoverCounter = 0;
function handler( event ) {
if ( event.type === "click" ) {
clickCounter++;
} else if ( event.type === "mouseover" ) {
mouseoverCounter++;
}
}
function handlerWithData( event ) {
if ( event.type === "click" ) {
clickCounter += event.data;
} else if ( event.type === "mouseover" ) {
mouseoverCounter += event.data;
}
}
function trigger() {
$elem.trigger( "click" ).trigger( "mouseover" );
}
$elem = jQuery( "#firstp" )
// Regular bind
.on( {
"click":handler,
"mouseover":handler
} )
// Bind with data
.one( {
"click":handlerWithData,
"mouseover":handlerWithData
}, 2 );
trigger();
assert.equal( clickCounter, 3, "on(Object)" );
assert.equal( mouseoverCounter, 3, "on(Object)" );
trigger();
assert.equal( clickCounter, 4, "on(Object)" );
assert.equal( mouseoverCounter, 4, "on(Object)" );
jQuery( "#firstp" ).off( {
"click":handler,
"mouseover":handler
} );
trigger();
assert.equal( clickCounter, 4, "on(Object)" );
assert.equal( mouseoverCounter, 4, "on(Object)" );
} );
QUnit.test( "on/off(Object), on/off(Object, String)", function( assert ) {
assert.expect( 6 );
var events,
clickCounter = 0,
mouseoverCounter = 0,
$p = jQuery( "#firstp" ),
$a = $p.find( "a" ).eq( 0 );
events = {
"click": function( event ) {
clickCounter += ( event.data || 1 );
},
"mouseover": function( event ) {
mouseoverCounter += ( event.data || 1 );
}
};
function trigger() {
$a.trigger( "click" ).trigger( "mouseover" );
}
jQuery( document ).on( events, "#firstp a" );
$p.on( events, "a", 2 );
trigger();
assert.equal( clickCounter, 3, "on" );
assert.equal( mouseoverCounter, 3, "on" );
$p.off( events, "a" );
trigger();
assert.equal( clickCounter, 4, "off" );
assert.equal( mouseoverCounter, 4, "off" );
jQuery( document ).off( events, "#firstp a" );
trigger();
assert.equal( clickCounter, 4, "off" );
assert.equal( mouseoverCounter, 4, "off" );
} );
QUnit.test( "on immediate propagation", function( assert ) {
assert.expect( 2 );
var lastClick,
$p = jQuery( "#firstp" ),
$a = $p.find( "a" ).eq( 0 );
lastClick = "";
jQuery( document ).on( "click", "#firstp a", function( e ) {
lastClick = "click1";
e.stopImmediatePropagation();
} );
jQuery( document ).on( "click", "#firstp a", function() {
lastClick = "click2";
} );
$a.trigger( "click" );
assert.equal( lastClick, "click1", "on stopImmediatePropagation" );
jQuery( document ).off( "click", "#firstp a" );
lastClick = "";
$p.on( "click", "a", function( e ) {
lastClick = "click1";
e.stopImmediatePropagation();
} );
$p.on( "click", "a", function() {
lastClick = "click2";
} );
$a.trigger( "click" );
assert.equal( lastClick, "click1", "on stopImmediatePropagation" );
$p.off( "click", "**" );
} );
QUnit.test( "on bubbling, isDefaultPrevented, stopImmediatePropagation", function( assert ) {
assert.expect( 3 );
var $anchor2 = jQuery( "#anchor2" ),
$main = jQuery( "#qunit-fixture" ),
neverCallMe = function() {
assert.ok( false, "immediate propagation should have been stopped" );
},
fakeClick = function( $jq ) {
// Use a native click so we don't get jQuery simulated bubbling
var e = document.createEvent( "MouseEvents" );
e.initEvent( "click", true, true );
$jq[ 0 ].dispatchEvent( e );
};
$anchor2.on( "click", function( e ) {
e.preventDefault();
} );
$main.on( "click", "#foo", function( e ) {
assert.equal( e.isDefaultPrevented(), true, "isDefaultPrevented true passed to bubbled event" );
} );
fakeClick( $anchor2 );
$anchor2.off( "click" );
$main.off( "click", "**" );
$anchor2.on( "click", function() {
// Let the default action occur
} );
$main.on( "click", "#foo", function( e ) {
assert.equal( e.isDefaultPrevented(), false, "isDefaultPrevented false passed to bubbled event" );
} );
fakeClick( $anchor2 );
$anchor2.off( "click" );
$main.off( "click", "**" );
$anchor2.on( "click", function( e ) {
e.stopImmediatePropagation();
assert.ok( true, "anchor was clicked and prop stopped" );
} );
$anchor2[ 0 ].addEventListener( "click", neverCallMe, false );
fakeClick( $anchor2 );
$anchor2[ 0 ].removeEventListener( "click", neverCallMe );
} );
QUnit.test( "triggered events stopPropagation() for natively-bound events", function( assert ) {
assert.expect( 1 );
var $button = jQuery( "#button" ),
$parent = $button.parent(),
neverCallMe = function() {
assert.ok( false, "propagation should have been stopped" );
},
stopPropagationCallback = function( e ) {
assert.ok( true, "propagation is stopped" );
e.stopPropagation();
};
$parent[ 0 ].addEventListener( "click", neverCallMe );
$button.on( "click", stopPropagationCallback );
$button.trigger( "click" );
$parent[ 0 ].removeEventListener( "click", neverCallMe );
$button.off( "click", stopPropagationCallback );
} );
QUnit.test( "trigger() works with events that were previously stopped", function( assert ) {
assert.expect( 0 );
var $button = jQuery( "#button" ),
$parent = $button.parent(),
neverCallMe = function() {
assert.ok( false, "propagation should have been stopped" );
};
$parent[ 0 ].addEventListener( "click", neverCallMe );
$button.on( "click", neverCallMe );
var clickEvent = jQuery.Event( "click" );
clickEvent.stopPropagation();
$button.trigger( clickEvent );
$parent[ 0 ].removeEventListener( "click", neverCallMe );
$button.off( "click", neverCallMe );
} );
QUnit.test( "on(), iframes", function( assert ) {
assert.expect( 1 );
// events don't work with iframes, see #939 - this test fails in IE because of contentDocument
var doc = jQuery( "#loadediframe" ).contents();
jQuery( "div", doc ).on( "click", function() {
assert.ok( true, "Binding to element inside iframe" );
} ).trigger( "click" ).off( "click" );
} );
QUnit.test( "on(), trigger change on select", function( assert ) {
assert.expect( 5 );
var counter = 0;
function selectOnChange( event ) {
assert.equal( event.data, counter++, "Event.data is not a global event object" );
}
jQuery( "#form select" ).each( function( i ) {
jQuery( this ).on( "change", i, selectOnChange );
} ).trigger( "change" );
} );
QUnit.test( "on(), namespaced events, cloned events", function( assert ) {
assert.expect( 18 );
var firstp = jQuery( "#firstp" );
firstp.on( "custom.test", function() {
assert.ok( false, "Custom event triggered" );
} );
firstp.on( "click", function( e ) {
assert.ok( true, "Normal click triggered" );
assert.equal( e.type + e.namespace, "click", "Check that only click events trigger this fn" );
} );
firstp.on( "click.test", function( e ) {
var check = "click";
assert.ok( true, "Namespaced click triggered" );
if ( e.namespace ) {
check += "test";
}
assert.equal( e.type + e.namespace, check, "Check that only click/click.test events trigger this fn" );
} );
//clone(true) element to verify events are cloned correctly
firstp = firstp.add( firstp.clone( true ).attr( "id", "firstp2" ).insertBefore( firstp ) );
// Trigger both bound fn (8)
firstp.trigger( "click" );
// Trigger one bound fn (4)
firstp.trigger( "click.test" );
// Remove only the one fn
firstp.off( "click.test" );
// Trigger the remaining fn (4)
firstp.trigger( "click" );
// Remove the remaining namespaced fn
firstp.off( ".test" );
// Try triggering the custom event (0)
firstp.trigger( "custom" );
// using contents will get comments regular, text, and comment nodes
jQuery( "#nonnodes" ).contents().on( "tester", function() {
assert.equal( this.nodeType, 1, "Check node,textnode,comment on just does real nodes" );
} ).trigger( "tester" );
// Make sure events stick with appendTo'd elements (which are cloned) #2027
jQuery( "<a href='#fail' class='test'>test</a>" ).on( "click", function() { return false; } ).appendTo( "#qunit-fixture" );
assert.ok( jQuery( "a.test" ).eq( 0 ).triggerHandler( "click" ) === false, "Handler is bound to appendTo'd elements" );
} );
QUnit.test( "on(), multi-namespaced events", function( assert ) {
assert.expect( 6 );
var order = [
"click.test.abc",
"click.test.abc",
"click.test",
"click.test.abc",
"click.test",
"custom.test2"
];
function check( name, msg ) {
assert.deepEqual( name, order.shift(), msg );
}
jQuery( "#firstp" ).on( "custom.test", function() {
check( "custom.test", "Custom event triggered" );
} );
jQuery( "#firstp" ).on( "custom.test2", function() {
check( "custom.test2", "Custom event triggered" );
} );
jQuery( "#firstp" ).on( "click.test", function() {
check( "click.test", "Normal click triggered" );
} );
jQuery( "#firstp" ).on( "click.test.abc", function() {
check( "click.test.abc", "Namespaced click triggered" );
} );
// Those would not trigger/off (#5303)
jQuery( "#firstp" ).trigger( "click.a.test" );
jQuery( "#firstp" ).off( "click.a.test" );
// Trigger both bound fn (1)
jQuery( "#firstp" ).trigger( "click.test.abc" );
// Trigger one bound fn (1)
jQuery( "#firstp" ).trigger( "click.abc" );
// Trigger two bound fn (2)
jQuery( "#firstp" ).trigger( "click.test" );
// Remove only the one fn
jQuery( "#firstp" ).off( "click.abc" );
// Trigger the remaining fn (1)
jQuery( "#firstp" ).trigger( "click" );
// Remove the remaining fn
jQuery( "#firstp" ).off( ".test" );
// Trigger the remaining fn (1)
jQuery( "#firstp" ).trigger( "custom" );
} );
QUnit.test( "namespace-only event binding is a no-op", function( assert ) {
assert.expect( 2 );
jQuery( "#firstp" )
.on( ".whoops", function() {
assert.ok( false, "called a namespace-only event" );
} )
.on( "whoops", function() {
assert.ok( true, "called whoops" );
} )
.trigger( "whoops" ) // 1
.off( ".whoops" )
.trigger( "whoops" ) // 2
.off( "whoops" );
} );
QUnit.test( "Empty namespace is ignored", function( assert ) {
assert.expect( 1 );
jQuery( "#firstp" )
.on( "meow.", function( e ) {
assert.equal( e.namespace, "", "triggered a namespace-less meow event" );
} )
.trigger( "meow." )
.off( "meow." );
} );
QUnit.test( "on(), with same function", function( assert ) {
assert.expect( 2 );
var count = 0, func = function() {
count++;
};
jQuery( "#liveHandlerOrder" ).on( "foo.bar", func ).on( "foo.zar", func );
jQuery( "#liveHandlerOrder" ).trigger( "foo.bar" );
assert.equal( count, 1, "Verify binding function with multiple namespaces." );
jQuery( "#liveHandlerOrder" ).off( "foo.bar", func ).off( "foo.zar", func );
jQuery( "#liveHandlerOrder" ).trigger( "foo.bar" );
assert.equal( count, 1, "Verify that removing events still work." );
} );
QUnit.test( "on(), make sure order is maintained", function( assert ) {
assert.expect( 1 );
var elem = jQuery( "#firstp" ), log = [], check = [];
jQuery.each( new Array( 100 ), function( i ) {
elem.on( "click", function() {
log.push( i );
} );
check.push( i );
} );
elem.trigger( "click" );
assert.equal( log.join( "," ), check.join( "," ), "Make sure order was maintained." );
elem.off( "click" );
} );
QUnit.test( "on(), with different this object", function( assert ) {
assert.expect( 4 );
var thisObject = { myThis: true },
data = { myData: true },
handler1 = function() {
assert.equal( this, thisObject, "on() with different this object" );
}.bind( thisObject ),
handler2 = function( event ) {
assert.equal( this, thisObject, "on() with different this object and data" );
assert.equal( event.data, data, "on() with different this object and data" );
}.bind( thisObject );
jQuery( "#firstp" )
.on( "click", handler1 ).trigger( "click" ).off( "click", handler1 )
.on( "click", data, handler2 ).trigger( "click" ).off( "click", handler2 );
assert.ok( !jQuery._data( jQuery( "#firstp" )[ 0 ], "events" ), "Event handler unbound when using different this object and data." );
} );
QUnit.test( "on(name, false), off(name, false)", function( assert ) {
assert.expect( 3 );
var main = 0;
jQuery( "#qunit-fixture" ).on( "click", function() { main++; } );
jQuery( "#ap" ).trigger( "click" );
assert.equal( main, 1, "Verify that the trigger happened correctly." );
main = 0;
jQuery( "#ap" ).on( "click", false );
jQuery( "#ap" ).trigger( "click" );
assert.equal( main, 0, "Verify that no bubble happened." );
main = 0;
jQuery( "#ap" ).off( "click", false );
jQuery( "#ap" ).trigger( "click" );
assert.equal( main, 1, "Verify that the trigger happened correctly." );
// manually clean up events from elements outside the fixture
jQuery( "#qunit-fixture" ).off( "click" );
} );
QUnit.test( "on(name, selector, false), off(name, selector, false)", function( assert ) {
assert.expect( 3 );
var main = 0;
jQuery( "#qunit-fixture" ).on( "click", "#ap", function() { main++; } );
jQuery( "#ap" ).trigger( "click" );
assert.equal( main, 1, "Verify that the trigger happened correctly." );
main = 0;
jQuery( "#ap" ).on( "click", "#groups", false );
jQuery( "#groups" ).trigger( "click" );
assert.equal( main, 0, "Verify that no bubble happened." );
main = 0;
jQuery( "#ap" ).off( "click", "#groups", false );
jQuery( "#groups" ).trigger( "click" );
assert.equal( main, 1, "Verify that the trigger happened correctly." );
jQuery( "#qunit-fixture" ).off( "click", "#ap" );
} );
QUnit.test( "on()/trigger()/off() on plain object", function( assert ) {
assert.expect( 7 );
var events,
obj = {};
// Make sure it doesn't complain when no events are found
jQuery( obj ).trigger( "test" );
// Make sure it doesn't complain when no events are found
jQuery( obj ).off( "test" );
jQuery( obj ).on( {
"test": function() {
assert.ok( true, "Custom event run." );
},
"submit": function() {
assert.ok( true, "Custom submit event run." );
}
} );
events = jQuery._data( obj, "events" );
assert.ok( events, "Object has events bound." );
assert.equal( obj[ "events" ], undefined, "Events object on plain objects is not events" );
assert.equal( obj.test, undefined, "Make sure that test event is not on the plain object." );
assert.equal( obj.handle, undefined, "Make sure that the event handler is not on the plain object." );
// Should trigger 1
jQuery( obj ).trigger( "test" );
jQuery( obj ).trigger( "submit" );
jQuery( obj ).off( "test" );
jQuery( obj ).off( "submit" );
// Should trigger 0
jQuery( obj ).trigger( "test" );
// Make sure it doesn't complain when no events are found
jQuery( obj ).off( "test" );
assert.equal( obj && obj[ jQuery.expando ] &&
obj[ jQuery.expando ][ jQuery.expando ] &&
obj[ jQuery.expando ][ jQuery.expando ][ "events" ], undefined, "Make sure events object is removed" );
} );
QUnit.test( "off(type)", function( assert ) {
assert.expect( 1 );
var message, func,
$elem = jQuery( "#firstp" );
function error() {
assert.ok( false, message );
}
message = "unbind passing function";
$elem.on( "error1", error ).off( "error1", error ).triggerHandler( "error1" );
message = "unbind all from event";
$elem.on( "error1", error ).off( "error1" ).triggerHandler( "error1" );
message = "unbind all";
$elem.on( "error1", error ).off().triggerHandler( "error1" );
message = "unbind many with function";
$elem.on( "error1 error2", error )
.off( "error1 error2", error )
.trigger( "error1" ).triggerHandler( "error2" );
message = "unbind many"; // #3538
$elem.on( "error1 error2", error )
.off( "error1 error2" )
.trigger( "error1" ).triggerHandler( "error2" );
message = "unbind without a type or handler";
$elem.on( "error1 error2.test", error )
.off()
.trigger( "error1" ).triggerHandler( "error2" );
// Should only unbind the specified function
jQuery( document ).on( "click", function() {
assert.ok( true, "called handler after selective removal" );
} );
func = function() {};
jQuery( document )
.on( "click", func )
.off( "click", func )
.trigger( "click" )
.off( "click" );
} );
QUnit.test( "off(eventObject)", function( assert ) {
assert.expect( 4 );
var $elem = jQuery( "#firstp" ),
num;
function check( expected ) {
num = 0;
$elem.trigger( "foo" ).triggerHandler( "bar" );
assert.equal( num, expected, "Check the right handlers are triggered" );
}
$elem
// This handler shouldn't be unbound
.on( "foo", function() {
num += 1;
} )
.on( "foo", function( e ) {
$elem.off( e );
num += 2;
} )
// Neither this one
.on( "bar", function() {
num += 4;
} );
check( 7 );
check( 5 );
$elem.off( "bar" );
check( 1 );
$elem.off();
check( 0 );
} );
QUnit.test( "mouseover triggers mouseenter", function( assert ) {
assert.expect( 1 );
var count = 0,
elem = jQuery( "<a></a>" );
elem.on( "mouseenter", function() {
count++;
} );
elem.trigger( "mouseover" );
assert.equal( count, 1, "make sure mouseover triggers a mouseenter" );
elem.remove();
} );
QUnit.test( "pointerover triggers pointerenter", function( assert ) {
assert.expect( 1 );
var count = 0,
elem = jQuery( "<a></a>" );
elem.on( "pointerenter", function() {
count++;
} );
elem.trigger( "pointerover" );
assert.equal( count, 1, "make sure pointerover triggers a pointerenter" );
elem.remove();
} );
QUnit.test( "withinElement implemented with jQuery.contains()", function( assert ) {
assert.expect( 1 );
jQuery( "#qunit-fixture" ).append( "<div id='jc-outer'><div id='jc-inner'></div></div>" );
jQuery( "#jc-outer" ).on( "mouseenter mouseleave", function( event ) {
assert.equal( this.id, "jc-outer", this.id + " " + event.type );
} );
jQuery( "#jc-inner" ).trigger( "mouseenter" );
} );
QUnit.test( "mouseenter, mouseleave don't catch exceptions", function( assert ) {
assert.expect( 2 );
var elem = jQuery( "#firstp" ).on( "mouseenter mouseleave", function() {
throw "an Exception";
} );
try {
elem.trigger( "mouseenter" );
} catch ( e ) {
assert.equal( e, "an Exception", "mouseenter doesn't catch exceptions" );
}
try {
elem.trigger( "mouseleave" );
} catch ( e ) {
assert.equal( e, "an Exception", "mouseleave doesn't catch exceptions" );
}
} );
QUnit.test( "trigger() bubbling", function( assert ) {
assert.expect( 18 );
var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0;
jQuery( window ).on( "click", function() { win++; } );
jQuery( document ).on( "click", function( e ) { if ( e.target !== document ) { doc++; } } );
jQuery( "html" ).on( "click", function() { html++; } );
jQuery( "body" ).on( "click", function() { body++; } );
jQuery( "#qunit-fixture" ).on( "click", function() { main++; } );
jQuery( "#ap" ).on( "click", function() { ap++; return false; } );
jQuery( "html" ).trigger( "click" );
assert.equal( win, 1, "HTML bubble" );
assert.equal( doc, 1, "HTML bubble" );
assert.equal( html, 1, "HTML bubble" );
jQuery( "body" ).trigger( "click" );
assert.equal( win, 2, "Body bubble" );
assert.equal( doc, 2, "Body bubble" );
assert.equal( html, 2, "Body bubble" );
assert.equal( body, 1, "Body bubble" );
jQuery( "#qunit-fixture" ).trigger( "click" );
assert.equal( win, 3, "Main bubble" );
assert.equal( doc, 3, "Main bubble" );
assert.equal( html, 3, "Main bubble" );
assert.equal( body, 2, "Main bubble" );
assert.equal( main, 1, "Main bubble" );
jQuery( "#ap" ).trigger( "click" );
assert.equal( doc, 3, "ap bubble" );
assert.equal( html, 3, "ap bubble" );
assert.equal( body, 2, "ap bubble" );
assert.equal( main, 1, "ap bubble" );
assert.equal( ap, 1, "ap bubble" );
jQuery( document ).trigger( "click" );
assert.equal( win, 4, "doc bubble" );
// manually clean up events from elements outside the fixture
jQuery( window ).off( "click" );
jQuery( document ).off( "click" );
jQuery( "html, body, #qunit-fixture" ).off( "click" );
} );
QUnit.test( "trigger(type, [data], [fn])", function( assert ) {
assert.expect( 16 );
var $elem, pass, form, elem2,
handler = function( event, a, b, c ) {
assert.equal( event.type, "click", "check passed data" );
assert.equal( a, 1, "check passed data" );
assert.equal( b, "2", "check passed data" );
assert.equal( c, "abc", "check passed data" );
return "test";
};
$elem = jQuery( "#firstp" );
// Simulate a "native" click
$elem[ 0 ].click = function() {
assert.ok( true, "Native call was triggered" );
};
jQuery( document ).on( "mouseenter", "#firstp", function() {
assert.ok( true, "Trigger mouseenter bound by on" );
} );
jQuery( document ).on( "mouseleave", "#firstp", function() {
assert.ok( true, "Trigger mouseleave bound by on" );
} );
$elem.trigger( "mouseenter" );
$elem.trigger( "mouseleave" );
jQuery( document ).off( "mouseenter mouseleave", "#firstp" );
// Triggers handlers and native
// Trigger 5
$elem.on( "click", handler ).trigger( "click", [ 1, "2", "abc" ] );
// Simulate a "native" click
$elem[ 0 ].click = function() {
assert.ok( false, "Native call was triggered" );
};
// Trigger only the handlers (no native)
// Triggers 5
assert.equal( $elem.triggerHandler( "click", [ 1, "2", "abc" ] ), "test", "Verify handler response" );
pass = true;
try {
elem2 = jQuery( "#form input" ).eq( 0 );
elem2.get( 0 ).style.display = "none";
elem2.trigger( "focus" );
} catch ( e ) {
pass = false;
}
assert.ok( pass, "Trigger focus on hidden element" );
pass = true;
try {
jQuery( "#qunit-fixture table" ).eq( 0 ).on( "test:test", function() {} ).trigger( "test:test" );
} catch ( e ) {
pass = false;
}
assert.ok( pass, "Trigger on a table with a colon in the even type, see #3533" );
form = jQuery( "<form action=''></form>" ).appendTo( "body" );
// Make sure it can be prevented locally
form.on( "submit", function() {
assert.ok( true, "Local `on` still works." );
return false;
} );
// Trigger 1
form.trigger( "submit" );
form.off( "submit" );
jQuery( document ).on( "submit", function() {
assert.ok( true, "Make sure bubble works up to document." );
return false;
} );
// Trigger 1
form.trigger( "submit" );
jQuery( document ).off( "submit" );
form.remove();
} );
QUnit.test( "submit event bubbles on copied forms (#11649)", function( assert ) {
assert.expect( 3 );
var $formByClone, $formByHTML,
$testForm = jQuery( "#testForm" ),
$fixture = jQuery( "#qunit-fixture" ),
$wrapperDiv = jQuery( "<div></div>" ).appendTo( $fixture );
function noSubmit( e ) {
e.preventDefault();
}
function delegatedSubmit() {
assert.ok( true, "Make sure submit event bubbles up." );
return false;
}
// Attach a delegated submit handler to the parent element
$fixture.on( "submit", "form", delegatedSubmit );
// Trigger form submission to introduce the _submit_attached property
$testForm.on( "submit", noSubmit ).find( "input[name=sub1]" ).trigger( "click" );
// Copy the form via .clone() and .html()
$formByClone = $testForm.clone( true, true ).removeAttr( "id" );
$formByHTML = jQuery( jQuery.parseHTML( $fixture.html() ) ).filter( "#testForm" ).removeAttr( "id" );
$wrapperDiv.append( $formByClone, $formByHTML );
// Check submit bubbling on the copied forms
$wrapperDiv.find( "form" ).on( "submit", noSubmit ).find( "input[name=sub1]" ).trigger( "click" );
// Clean up
$wrapperDiv.remove();
$fixture.off( "submit", "form", delegatedSubmit );
$testForm.off( "submit", noSubmit );
} );
QUnit.test( "change event bubbles on copied forms (#11796)", function( assert ) {
assert.expect( 3 );
var $formByClone, $formByHTML,
$form = jQuery( "#form" ),
$fixture = jQuery( "#qunit-fixture" ),
$wrapperDiv = jQuery( "<div></div>" ).appendTo( $fixture );
function delegatedChange() {
assert.ok( true, "Make sure change event bubbles up." );
return false;
}
// Attach a delegated change handler to the form
$fixture.on( "change", "form", delegatedChange );
// Trigger change event to introduce the _change_attached property
$form.find( "select[name=select1]" ).val( "1" ).trigger( "change" );
// Copy the form via .clone() and .html()
$formByClone = $form.clone( true, true ).removeAttr( "id" );
$formByHTML = jQuery( jQuery.parseHTML( $fixture.html() ) ).filter( "#form" ).removeAttr( "id" );
$wrapperDiv.append( $formByClone, $formByHTML );
// Check change bubbling on the copied forms
$wrapperDiv.find( "form select[name=select1]" ).val( "2" ).trigger( "change" );
// Clean up
$wrapperDiv.remove();
$fixture.off( "change", "form", delegatedChange );
} );
QUnit.test( "trigger(eventObject, [data], [fn])", function( assert ) {
assert.expect( 28 );
var event,
$parent = jQuery( "<div id='par'></div>" ).appendTo( "body" ),
$child = jQuery( "<p id='child'>foo</p>" ).appendTo( $parent );
$parent.get( 0 ).style.display = "none";
event = jQuery.Event( "noNew" );
assert.ok( event !== window, "Instantiate jQuery.Event without the 'new' keyword" );
assert.equal( event.type, "noNew", "Verify its type" );
assert.equal( event.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
assert.equal( event.isPropagationStopped(), false, "Verify isPropagationStopped" );
assert.equal( event.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
event.preventDefault();
assert.equal( event.isDefaultPrevented(), true, "Verify isDefaultPrevented" );
event.stopPropagation();
assert.equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
event.isPropagationStopped = function() { return false; };
event.stopImmediatePropagation();
assert.equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
assert.equal( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
$parent.on( "foo", function( e ) {
// Tries bubbling
assert.equal( e.type, "foo", "Verify event type when passed passing an event object" );
assert.equal( e.target.id, "child", "Verify event.target when passed passing an event object" );
assert.equal( e.currentTarget.id, "par", "Verify event.currentTarget when passed passing an event object" );
assert.equal( e.secret, "boo!", "Verify event object's custom attribute when passed passing an event object" );
} );
// test with an event object
event = new jQuery.Event( "foo" );
event.secret = "boo!";
$child.trigger( event );
// test with a literal object
$child.trigger( { "type": "foo", "secret": "boo!" } );
$parent.off();
function error() {
assert.ok( false, "This assertion shouldn't be reached" );
}
$parent.on( "foo", error );
$child.on( "foo", function( e, a, b, c ) {
assert.equal( arguments.length, 4, "Check arguments length" );
assert.equal( a, 1, "Check first custom argument" );
assert.equal( b, 2, "Check second custom argument" );
assert.equal( c, 3, "Check third custom argument" );
assert.equal( e.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
assert.equal( e.isPropagationStopped(), false, "Verify isPropagationStopped" );
assert.equal( e.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
// Skips both errors
e.stopImmediatePropagation();
return "result";
} );
// We should add this back in when we want to test the order
// in which event handlers are iterated.
//$child.on("foo", error );
event = new jQuery.Event( "foo" );
$child.trigger( event, [ 1, 2, 3 ] ).off();
assert.equal( event.result, "result", "Check event.result attribute" );
// Will error if it bubbles
$child.triggerHandler( "foo" );
$child.off();
$parent.off().remove();
// Ensure triggerHandler doesn't molest its event object (#xxx)
event = jQuery.Event( "zowie" );
jQuery( document ).triggerHandler( event );
assert.equal( event.type, "zowie", "Verify its type" );
assert.equal( event.isPropagationStopped(), false, "propagation not stopped" );
assert.equal( event.isDefaultPrevented(), false, "default not prevented" );
} );
QUnit.test( ".trigger() bubbling on disconnected elements (#10489)", function( assert ) {
assert.expect( 2 );
jQuery( window ).on( "click", function() {
assert.ok( false, "click fired on window" );
} );
jQuery( "<div><p>hi</p></div>" )
.on( "click", function() {
assert.ok( true, "click fired on div" );
} )
.find( "p" )
.on( "click", function() {
assert.ok( true, "click fired on p" );
} )
.trigger( "click" )
.off( "click" )
.end()
.off( "click" )
.remove();
jQuery( window ).off( "click" );
} );
QUnit.test( ".trigger() doesn't bubble load event (#10717)", function( assert ) {
assert.expect( 1 );
jQuery( window ).on( "load", function() {
assert.ok( false, "load fired on window" );
} );
jQuery( "<img src='" + baseURL + "1x1.jpg' />" )
.appendTo( "body" )
.on( "load", function() {
assert.ok( true, "load fired on img" );
} )
.trigger( "load" )
.remove();
jQuery( window ).off( "load" );
} );
QUnit.test( "Delegated events in SVG (#10791; #13180)", function( assert ) {
assert.expect( 2 );
var useElem, e,
svg = jQuery(
"<svg height='1' version='1.1' width='1' xmlns='http://www.w3.org/2000/svg'>" +
"<defs><rect id='ref' x='10' y='20' width='100' height='60' r='10' rx='10' ry='10'></rect></defs>" +
"<rect class='svg-by-class' x='10' y='20' width='100' height='60' r='10' rx='10' ry='10'></rect>" +
"<rect id='svg-by-id' x='10' y='20' width='100' height='60' r='10' rx='10' ry='10'></rect>" +
"<use id='use' xlink:href='#ref'></use>" +
"</svg>"
);
jQuery( "#qunit-fixture" )
.append( svg )
.on( "click", "#svg-by-id", function() {
assert.ok( true, "delegated id selector" );
} )
.on( "click", "[class~='svg-by-class']", function() {
assert.ok( true, "delegated class selector" );
} )
.find( "#svg-by-id, [class~='svg-by-class']" )
.trigger( "click" )
.end();
// Fire a native click on an SVGElementInstance (the instance tree of an SVG <use>)
// to confirm that it doesn't break our event delegation handling (#13180)
useElem = svg.find( "#use" )[ 0 ];
if ( document.createEvent && useElem && useElem.instanceRoot ) {
e = document.createEvent( "MouseEvents" );
e.initEvent( "click", true, true );
useElem.instanceRoot.dispatchEvent( e );
}
jQuery( "#qunit-fixture" ).off( "click" );
} );
QUnit.test( "Delegated events with malformed selectors (gh-3071)", function( assert ) {
assert.expect( 3 );
assert.throws( function() {
jQuery( "#foo" ).on( "click", ":not", function() {} );
}, "malformed selector throws on attach" );
assert.throws( function() {
jQuery( "#foo" ).on( "click", "nonexistent:not", function() {} );
}, "short-circuitable malformed selector throws on attach" );
jQuery( "#foo > :first-child" ).trigger( "click" );
assert.ok( true, "malformed selector does not throw on event" );
} );
QUnit.test( "Delegated events in forms (#10844; #11145; #8165; #11382, #11764)", function( assert ) {
assert.expect( 5 );
// Alias names like "id" cause havoc
var form = jQuery(
"<form id='myform'>" +
"<input type='text' name='id' value='secret agent man' />" +
"</form>"
)
.on( "submit", function( event ) {
event.preventDefault();
} )
.appendTo( "body" );
jQuery( "body" )
.on( "submit", "#myform", function() {
assert.ok( true, "delegated id selector with aliased id" );
} )
.find( "#myform" )
.trigger( "submit" )
.end()
.off( "submit" );
form.append( "<input type='text' name='disabled' value='differently abled' />" );
jQuery( "body" )
.on( "submit", "#myform", function() {
assert.ok( true, "delegated id selector with aliased disabled" );
} )
.find( "#myform" )
.trigger( "submit" )
.end()
.off( "submit" );
form
.append( "<button id='nestyDisabledBtn'><span>Zing</span></button>" )
.on( "click", "#nestyDisabledBtn", function() {
assert.ok( true, "click on enabled/disabled button with nesty elements" );
} )
.on( "mouseover", "#nestyDisabledBtn", function() {
assert.ok( true, "mouse on enabled/disabled button with nesty elements" );
} )
.find( "span" )
.trigger( "click" ) // yep
.trigger( "mouseover" ) // yep
.end()
.find( "#nestyDisabledBtn" ).prop( "disabled", true ).end()
.find( "span" )
.trigger( "click" ) // nope
.trigger( "mouseover" ) // yep
.end()
.off( "click" );
form.remove();
} );
QUnit.test( "Submit event can be stopped (#11049)", function( assert ) {
assert.expect( 1 );
// Since we manually bubble in IE, make sure inner handlers get a chance to cancel
var form = jQuery(
"<form id='myform'>" +
"<input type='text' name='sue' value='bawls' />" +
"<input type='submit' />" +
"</form>"
)
.appendTo( "body" );
jQuery( "body" )
.on( "submit", function() {
assert.ok( true, "submit bubbled on first handler" );
return false;
} )
.find( "#myform input[type=submit]" )
.each( function() { this.click(); } )
.end()
.on( "submit", function() {
assert.ok( false, "submit bubbled on second handler" );
return false;
} )
.find( "#myform input[type=submit]" )
.each( function() {
jQuery( this.form ).on( "submit", function( e ) {
e.preventDefault();
e.stopPropagation();
} );
this.click();
} )
.end()
.off( "submit" );
form.remove();
} );
// Support: iOS 7 - 9
// iOS has the window.onbeforeunload field but doesn't support the beforeunload
// handler making it impossible to feature-detect the support.
QUnit[ /(ipad|iphone|ipod)/i.test( navigator.userAgent ) ? "skip" : "test" ](
"on(beforeunload)", function( assert ) {
assert.expect( 1 );
var iframe = jQuery( jQuery.parseHTML( "<iframe src='" + baseURL + "event/onbeforeunload.html'><iframe>" ) );
var done = assert.async();
window.onmessage = function( event ) {
var payload = JSON.parse( event.data );
assert.ok( payload.event, "beforeunload", "beforeunload event" );
iframe.remove();
window.onmessage = null;
done();
};
iframe.appendTo( "#qunit-fixture" );
} );
QUnit.test( "jQuery.Event( type, props )", function( assert ) {
assert.expect( 6 );
var event = jQuery.Event( "keydown", { keyCode: 64 } ),
handler = function( event ) {
assert.ok( "keyCode" in event, "Special property 'keyCode' exists" );
assert.equal( event.keyCode, 64, "event.keyCode has explicit value '64'" );
};
// Supports jQuery.Event implementation
assert.equal( event.type, "keydown", "Verify type" );
// ensure "type" in props won't clobber the one set by constructor
assert.equal( jQuery.inArray( "type", jQuery.event.props ), -1, "'type' property not in props (#10375)" );
assert.ok( "keyCode" in event, "Special 'keyCode' property exists" );
assert.strictEqual( jQuery.isPlainObject( event ), false, "Instances of $.Event should not be identified as a plain object." );
jQuery( "body" ).on( "keydown", handler ).trigger( event );
jQuery( "body" ).off( "keydown" );
} );
QUnit.test( "jQuery.Event properties", function( assert ) {
assert.expect( 12 );
var handler,
$structure = jQuery( "<div id='ancestor'><p id='delegate'><span id='target'>shiny</span></p></div>" ),
$target = $structure.find( "#target" );
handler = function( e ) {
assert.strictEqual( e.currentTarget, this, "currentTarget at " + this.id );
assert.equal( e.isTrigger, 3, "trigger at " + this.id );
};
$structure.one( "click", handler );
$structure.one( "click", "p", handler );
$target.one( "click", handler );
$target[ 0 ].onclick = function( e ) {
assert.strictEqual( e.currentTarget, this, "currentTarget at target (native handler)" );
assert.equal( e.isTrigger, 3, "trigger at target (native handler)" );
};
$target.trigger( "click" );
$target.one( "click", function( e ) {
assert.equal( e.isTrigger, 2, "triggerHandler at target" );
} );
$target[ 0 ].onclick = function( e ) {
assert.equal( e.isTrigger, 2, "triggerHandler at target (native handler)" );
};
$target.triggerHandler( "click" );
handler = function( e ) {
assert.strictEqual( e.isTrigger, undefined, "native event at " + this.id );
};
$target.one( "click", handler );
$target[ 0 ].onclick = function( e ) {
assert.strictEqual( e.isTrigger, undefined, "native event at target (native handler)" );
};
fireNative( $target[ 0 ], "click" );
} );
QUnit.test( ".on()/.off()", function( assert ) {
assert.expect( 65 );
var event, clicked, hash, called, livec, lived, livee,
submit = 0, div = 0, livea = 0, liveb = 0;
jQuery( "#body" ).on( "submit", "#qunit-fixture div", function() { submit++; return false; } );
jQuery( "#body" ).on( "click", "#qunit-fixture div", function() { div++; } );
jQuery( "#body" ).on( "click", "div#nothiddendiv", function() { livea++; } );
jQuery( "#body" ).on( "click", "div#nothiddendivchild", function() { liveb++; } );
// Nothing should trigger on the body
jQuery( "body" ).trigger( "click" );
assert.equal( submit, 0, "Click on body" );
assert.equal( div, 0, "Click on body" );
assert.equal( livea, 0, "Click on body" );
assert.equal( liveb, 0, "Click on body" );
// This should trigger two events
submit = 0; div = 0; livea = 0; liveb = 0;
jQuery( "div#nothiddendiv" ).trigger( "click" );
assert.equal( submit, 0, "Click on div" );
assert.equal( div, 1, "Click on div" );
assert.equal( livea, 1, "Click on div" );
assert.equal( liveb, 0, "Click on div" );
// This should trigger three events (w/ bubbling)
submit = 0; div = 0; livea = 0; liveb = 0;
jQuery( "div#nothiddendivchild" ).trigger( "click" );
assert.equal( submit, 0, "Click on inner div" );
assert.equal( div, 2, "Click on inner div" );
assert.equal( livea, 1, "Click on inner div" );
assert.equal( liveb, 1, "Click on inner div" );
// This should trigger one submit
submit = 0; div = 0; livea = 0; liveb = 0;
jQuery( "div#nothiddendivchild" ).trigger( "submit" );
assert.equal( submit, 1, "Submit on div" );
assert.equal( div, 0, "Submit on div" );
assert.equal( livea, 0, "Submit on div" );
assert.equal( liveb, 0, "Submit on div" );
// Make sure no other events were removed in the process
submit = 0; div = 0; livea = 0; liveb = 0;
jQuery( "div#nothiddendivchild" ).trigger( "click" );
assert.equal( submit, 0, "off Click on inner div" );
assert.equal( div, 2, "off Click on inner div" );
assert.equal( livea, 1, "off Click on inner div" );
assert.equal( liveb, 1, "off Click on inner div" );
// Now make sure that the removal works
submit = 0; div = 0; livea = 0; liveb = 0;
jQuery( "#body" ).off( "click", "div#nothiddendivchild" );
jQuery( "div#nothiddendivchild" ).trigger( "click" );
assert.equal( submit, 0, "off Click on inner div" );
assert.equal( div, 2, "off Click on inner div" );
assert.equal( livea, 1, "off Click on inner div" );
assert.equal( liveb, 0, "off Click on inner div" );
// Make sure that the click wasn't removed too early
submit = 0; div = 0; livea = 0; liveb = 0;
jQuery( "div#nothiddendiv" ).trigger( "click" );
assert.equal( submit, 0, "off Click on inner div" );
assert.equal( div, 1, "off Click on inner div" );
assert.equal( livea, 1, "off Click on inner div" );
assert.equal( liveb, 0, "off Click on inner div" );
// Make sure that stopPropagation doesn't stop live events
submit = 0; div = 0; livea = 0; liveb = 0;
jQuery( "#body" ).on( "click", "div#nothiddendivchild", function( e ) { liveb++; e.stopPropagation(); } );
jQuery( "div#nothiddendivchild" ).trigger( "click" );
assert.equal( submit, 0, "stopPropagation Click on inner div" );
assert.equal( div, 1, "stopPropagation Click on inner div" );
assert.equal( livea, 0, "stopPropagation Click on inner div" );
assert.equal( liveb, 1, "stopPropagation Click on inner div" );
// Make sure click events only fire with primary click
submit = 0; div = 0; livea = 0; liveb = 0;
event = jQuery.Event( "click" );
event.button = 1;
jQuery( "div#nothiddendiv" ).trigger( event );
assert.equal( livea, 0, "on secondary click" );
jQuery( "#body" ).off( "click", "div#nothiddendivchild" );
jQuery( "#body" ).off( "click", "div#nothiddendiv" );
jQuery( "#body" ).off( "click", "#qunit-fixture div" );
jQuery( "#body" ).off( "submit", "#qunit-fixture div" );
// Test binding with a different context
clicked = 0;
jQuery( "#qunit-fixture" ).on( "click", "#foo", function() { clicked++; } );
jQuery( "#qunit-fixture div" ).trigger( "click" );
jQuery( "#foo" ).trigger( "click" );
jQuery( "#qunit-fixture" ).trigger( "click" );
jQuery( "body" ).trigger( "click" );
assert.equal( clicked, 2, "on with a context" );
// Test unbinding with a different context
jQuery( "#qunit-fixture" ).off( "click", "#foo" );
jQuery( "#foo" ).trigger( "click" );
assert.equal( clicked, 2, "off with a context" );
// Test binding with event data
jQuery( "#body" ).on( "click", "#foo", true, function( e ) {
assert.equal( e.data, true, "on with event data" );
} );
jQuery( "#foo" ).trigger( "click" );
jQuery( "#body" ).off( "click", "#foo" );
// Test binding with trigger data
jQuery( "#body" ).on( "click", "#foo", function( e, data ) {
assert.equal( data, true, "on with trigger data" );
} );
jQuery( "#foo" ).trigger( "click", true );
jQuery( "#body" ).off( "click", "#foo" );
// Test binding with different this object
jQuery( "#body" ).on( "click", "#foo", function() {
assert.equal( this.foo, "bar", "on with event scope" );
}.bind( { "foo": "bar" } ) );
jQuery( "#foo" ).trigger( "click" );
jQuery( "#body" ).off( "click", "#foo" );
// Test binding with different this object, event data, and trigger data
jQuery( "#body" ).on( "click", "#foo", true, function( e, data ) {
assert.equal( e.data, true, "on with with different this object, event data, and trigger data" );
assert.equal( this.foo, "bar", "on with with different this object, event data, and trigger data" );
assert.equal( data, true, "on with with different this object, event data, and trigger data" );
}.bind( { "foo": "bar" } ) );
jQuery( "#foo" ).trigger( "click", true );
jQuery( "#body" ).off( "click", "#foo" );
// Verify that return false prevents default action
jQuery( "#body" ).on( "click", "#anchor2", function() { return false; } );
hash = window.location.hash;
jQuery( "#anchor2" ).trigger( "click" );
assert.equal( window.location.hash, hash, "return false worked" );
jQuery( "#body" ).off( "click", "#anchor2" );
// Verify that .preventDefault() prevents default action
jQuery( "#body" ).on( "click", "#anchor2", function( e ) { e.preventDefault(); } );
hash = window.location.hash;
jQuery( "#anchor2" ).trigger( "click" );
assert.equal( window.location.hash, hash, "e.preventDefault() worked" );
jQuery( "#body" ).off( "click", "#anchor2" );
// Test binding the same handler to multiple points
called = 0;
function callback() { called++; return false; }
jQuery( "#body" ).on( "click", "#nothiddendiv", callback );
jQuery( "#body" ).on( "click", "#anchor2", callback );
jQuery( "#nothiddendiv" ).trigger( "click" );
assert.equal( called, 1, "Verify that only one click occurred." );
called = 0;
jQuery( "#anchor2" ).trigger( "click" );
assert.equal( called, 1, "Verify that only one click occurred." );
// Make sure that only one callback is removed
jQuery( "#body" ).off( "click", "#anchor2", callback );
called = 0;
jQuery( "#nothiddendiv" ).trigger( "click" );
assert.equal( called, 1, "Verify that only one click occurred." );
called = 0;
jQuery( "#anchor2" ).trigger( "click" );
assert.equal( called, 0, "Verify that no click occurred." );
// Make sure that it still works if the selector is the same,
// but the event type is different
jQuery( "#body" ).on( "foo", "#nothiddendiv", callback );
// Cleanup
jQuery( "#body" ).off( "click", "#nothiddendiv", callback );
called = 0;
jQuery( "#nothiddendiv" ).trigger( "click" );
assert.equal( called, 0, "Verify that no click occurred." );
called = 0;
jQuery( "#nothiddendiv" ).trigger( "foo" );
assert.equal( called, 1, "Verify that one foo occurred." );
// Cleanup
jQuery( "#body" ).off( "foo", "#nothiddendiv", callback );
// Make sure we don't loose the target by DOM modifications
// after the bubble already reached the liveHandler
livec = 0;
jQuery( "#nothiddendivchild" ).html( "<span></span>" );
jQuery( "#body" ).on( "click", "#nothiddendivchild", function() { jQuery( "#nothiddendivchild" ).html( "" ); } );
jQuery( "#body" ).on( "click", "#nothiddendivchild", function( e ) { if ( e.target ) {livec++;} } );
jQuery( "#nothiddendiv span" ).trigger( "click" );
assert.equal( jQuery( "#nothiddendiv span" ).length, 0, "Verify that first handler occurred and modified the DOM." );
assert.equal( livec, 1, "Verify that second handler occurred even with nuked target." );
// Cleanup
jQuery( "#body" ).off( "click", "#nothiddendivchild" );
// Verify that .live() occurs and cancel bubble in the same order as
// we would expect .on() and .click() without delegation
lived = 0;
livee = 0;
// bind one pair in one order
jQuery( "#body" ).on( "click", "span#liveSpan1 a", function() { lived++; return false; } );
jQuery( "#body" ).on( "click", "span#liveSpan1", function() { livee++; } );
jQuery( "span#liveSpan1 a" ).trigger( "click" );
assert.equal( lived, 1, "Verify that only one first handler occurred." );
assert.equal( livee, 0, "Verify that second handler doesn't." );
// and one pair in inverse
jQuery( "#body" ).on( "click", "span#liveSpan2", function() { livee++; } );
jQuery( "#body" ).on( "click", "span#liveSpan2 a", function() { lived++; return false; } );
lived = 0;
livee = 0;
jQuery( "span#liveSpan2 a" ).trigger( "click" );
assert.equal( lived, 1, "Verify that only one first handler occurred." );
assert.equal( livee, 0, "Verify that second handler doesn't." );
// Cleanup
jQuery( "#body" ).off( "click", "**" );
// Test this, target and currentTarget are correct
jQuery( "#body" ).on( "click", "span#liveSpan1", function( e ) {
assert.equal( this.id, "liveSpan1", "Check the this within a on handler" );
assert.equal( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a on handler" );
assert.equal( e.delegateTarget, document.body, "Check the event.delegateTarget within a on handler" );
assert.equal( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a on handler" );
} );
jQuery( "span#liveSpan1 a" ).trigger( "click" );
jQuery( "#body" ).off( "click", "span#liveSpan1" );
// Work with deep selectors
livee = 0;
function clickB() { livee++; }
jQuery( "#body" ).on( "click", "#nothiddendiv div", function() { livee++; } );
jQuery( "#body" ).on( "click", "#nothiddendiv div", clickB );
jQuery( "#body" ).on( "mouseover", "#nothiddendiv div", function() { livee++; } );
assert.equal( livee, 0, "No clicks, deep selector." );
livee = 0;
jQuery( "#nothiddendivchild" ).trigger( "click" );
assert.equal( livee, 2, "Click, deep selector." );
livee = 0;
jQuery( "#nothiddendivchild" ).trigger( "mouseover" );
assert.equal( livee, 1, "Mouseover, deep selector." );
jQuery( "#body" ).off( "mouseover", "#nothiddendiv div" );
livee = 0;
jQuery( "#nothiddendivchild" ).trigger( "click" );
assert.equal( livee, 2, "Click, deep selector." );
livee = 0;
jQuery( "#nothiddendivchild" ).trigger( "mouseover" );
assert.equal( livee, 0, "Mouseover, deep selector." );
jQuery( "#body" ).off( "click", "#nothiddendiv div", clickB );
livee = 0;
jQuery( "#nothiddendivchild" ).trigger( "click" );
assert.equal( livee, 1, "Click, deep selector." );
jQuery( "#body" ).off( "click", "#nothiddendiv div" );
} );
QUnit.test( "jQuery.off using dispatched jQuery.Event", function( assert ) {
assert.expect( 1 );
var markup = jQuery( "<p><a href='#'>target</a></p>" ),
count = 0;
markup
.on( "click.name", "a", function( event ) {
assert.equal( ++count, 1, "event called once before removal" );
jQuery().off( event );
} )
.find( "a" ).trigger( "click" ).trigger( "click" ).end()
.remove();
} );
QUnit.test( "events with type matching an Object.prototype property (gh-3256)", function( assert ) {
assert.expect( 1 );
var elem = jQuery( "<div></div>" ),
eventFired = false;
elem.appendTo( "#qunit-fixture" );
try {
elem
.one( "hasOwnProperty", function() {
eventFired = true;
} )
.trigger( "hasOwnProperty" );
} finally {
assert.strictEqual( eventFired, true, "trigger fired without crashing" );
}
} );
QUnit.test( "events with type matching an Object.prototype property, cloned element (gh-3256)",
function( assert ) {
assert.expect( 1 );
var elem = jQuery( "<div></div>" ),
eventFired = false;
elem.appendTo( "#qunit-fixture" );
try {
// Make sure the original element has some event data.
elem.on( "click", function() {} );
elem
.clone( true )
.one( "hasOwnProperty", function() {
eventFired = true;
} )
.trigger( "hasOwnProperty" );
} finally {
assert.strictEqual( eventFired, true, "trigger fired without crashing" );
}
} );
// selector-native does not support scope-fixing in delegation
QUnit[ jQuery.find.compile ? "test" : "skip" ]( "delegated event with delegateTarget-relative selector", function( assert ) {
assert.expect( 3 );
var markup = jQuery( "<div><ul><li><a id=\"a0\"></a><ul id=\"ul0\"><li class=test><a id=\"a0_0\"></a></li><li><a id=\"a0_1\"></a></li></ul></li></ul></div>" ).appendTo( "#qunit-fixture" );
// Non-positional selector (#12383)
markup.find( "#ul0" )
.on( "click", "div li a", function() {
assert.ok( false, "div is ABOVE the delegation point!" );
} )
.on( "click", "ul a", function() {
assert.ok( false, "ul IS the delegation point!" );
} )
.on( "click", "li.test a", function() {
assert.ok( true, "li.test is below the delegation point." );
} )
.find( "#a0_0" ).trigger( "click" ).end()
.off( "click" );
// Positional selector (#11315)
markup.find( "ul" ).eq( 0 )
.on( "click", ">li>a", function() {
assert.ok( this.id === "a0", "child li was clicked" );
} )
.find( "#ul0" )
.on( "click", "li:first>a", function() {
assert.ok( this.id === "a0_0", "first li under #u10 was clicked" );
} )
.end()
.find( "a" ).trigger( "click" ).end()
.find( "#ul0" ).off();
markup.remove();
} );
QUnit.test( "delegated event with selector matching Object.prototype property (#13203)", function( assert ) {
assert.expect( 1 );
var matched = 0;
jQuery( "#foo" ).on( "click", "toString", function() {
matched++;
} );
jQuery( "#anchor2" ).trigger( "click" );
assert.equal( matched, 0, "Nothing matched 'toString'" );
} );
QUnit.test( "delegated event with intermediate DOM manipulation (#13208)", function( assert ) {
assert.expect( 1 );
jQuery( "#foo" ).on( "click", "[id=sap]", function() {} );
jQuery( "#sap" ).on( "click", "[id=anchor2]", function() {
document.createDocumentFragment().appendChild( this.parentNode );
assert.ok( true, "Element removed" );
} );
jQuery( "#anchor2" ).trigger( "click" );
} );
QUnit.test( "ignore comment nodes in event delegation (gh-2055)", function( assert ) {
assert.expect( 1 );
// Test if DOMNodeInserted is supported
// This is a back-up for when DOMNodeInserted support
// is eventually removed from browsers
function test() {
var ret = false;
var $fixture = jQuery( "#qunit-fixture" );
$fixture.on( "DOMNodeInserted", function() {
ret = true;
$fixture.off( "DOMNodeInserted" );
} ).append( "<div></div>" );
return ret;
}
var $foo = jQuery( "#foo" ).on( "DOMNodeInserted", "[id]", function() {
assert.ok( true, "No error thrown on comment node" );
} ),
$comment = jQuery( document.createComment( "comment" ) )
.appendTo( $foo.find( "#sap" ) );
if ( !test() ) {
fireNative( $comment[ 0 ], "DOMNodeInserted" );
}
} );
QUnit.test( "stopPropagation() stops directly-bound events on delegated target", function( assert ) {
assert.expect( 1 );
var markup = jQuery( "<div><p><a href=\"#\">target</a></p></div>" );
markup
.on( "click", function() {
assert.ok( false, "directly-bound event on delegate target was called" );
} )
.on( "click", "a", function( e ) {
e.stopPropagation();
assert.ok( true, "delegated handler was called" );
} )
.find( "a" ).trigger( "click" ).end()
.remove();
} );
QUnit.test( "off all bound delegated events", function( assert ) {
assert.expect( 2 );
var count = 0,
clicks = 0,
div = jQuery( "#body" );
div.on( "click submit", "div#nothiddendivchild", function() { count++; } );
div.on( "click", function() { clicks++; } );
div.off( undefined, "**" );
jQuery( "div#nothiddendivchild" ).trigger( "click" );
jQuery( "div#nothiddendivchild" ).trigger( "submit" );
assert.equal( count, 0, "Make sure no events were triggered." );
div.trigger( "click" );
assert.equal( clicks, 2, "Make sure delegated and directly bound event occurred." );
div.off( "click" );
} );
QUnit.test( "on with multiple delegated events", function( assert ) {
assert.expect( 1 );
var count = 0,
div = jQuery( "#body" );
div.on( "click submit", "div#nothiddendivchild", function() { count++; } );
jQuery( "div#nothiddendivchild" ).trigger( "click" );
jQuery( "div#nothiddendivchild" ).trigger( "submit" );
assert.equal( count, 2, "Make sure both the click and submit were triggered." );
jQuery( "#body" ).off( undefined, "**" );
} );
QUnit.test( "delegated on with change", function( assert ) {
assert.expect( 8 );
var select, checkbox, checkboxFunction,
text, textChange, oldTextVal,
password, passwordChange, oldPasswordVal,
selectChange = 0,
checkboxChange = 0;
select = jQuery( "select[name='S1']" );
jQuery( "#body" ).on( "change", "select[name='S1']", function() {
selectChange++;
} );
checkbox = jQuery( "#check2" );
checkboxFunction = function() {
checkboxChange++;
};
jQuery( "#body" ).on( "change", "#check2", checkboxFunction );
// test click on select
// second click that changed it
selectChange = 0;
select[ 0 ].selectedIndex = select[ 0 ].selectedIndex ? 0 : 1;
select.trigger( "change" );
assert.equal( selectChange, 1, "Change on click." );
// test keys on select
selectChange = 0;
select[ 0 ].selectedIndex = select[ 0 ].selectedIndex ? 0 : 1;
select.trigger( "change" );
assert.equal( selectChange, 1, "Change on keyup." );
// test click on checkbox
checkbox.trigger( "change" );
assert.equal( checkboxChange, 1, "Change on checkbox." );
// test blur/focus on text
text = jQuery( "#name" );
textChange = 0;
oldTextVal = text.val();
jQuery( "#body" ).on( "change", "#name", function() {
textChange++;
} );
text.val( oldTextVal + "foo" );
text.trigger( "change" );
assert.equal( textChange, 1, "Change on text input." );
text.val( oldTextVal );
jQuery( "#body" ).off( "change", "#name" );
// test blur/focus on password
password = jQuery( "#name" );
passwordChange = 0;
oldPasswordVal = password.val();
jQuery( "#body" ).on( "change", "#name", function() {
passwordChange++;
} );
password.val( oldPasswordVal + "foo" );
password.trigger( "change" );
assert.equal( passwordChange, 1, "Change on password input." );
password.val( oldPasswordVal );
jQuery( "#body" ).off( "change", "#name" );
// make sure die works
// die all changes
selectChange = 0;
jQuery( "#body" ).off( "change", "select[name='S1']" );
select[ 0 ].selectedIndex = select[ 0 ].selectedIndex ? 0 : 1;
select.trigger( "change" );
assert.equal( selectChange, 0, "Die on click works." );
selectChange = 0;
select[ 0 ].selectedIndex = select[ 0 ].selectedIndex ? 0 : 1;
select.trigger( "change" );
assert.equal( selectChange, 0, "Die on keyup works." );
// die specific checkbox
jQuery( "#body" ).off( "change", "#check2", checkboxFunction );
checkbox.trigger( "change" );
assert.equal( checkboxChange, 1, "Die on checkbox." );
} );
QUnit.test( "delegated on with submit", function( assert ) {
assert.expect( 2 );
var count1 = 0, count2 = 0;
jQuery( "#body" ).on( "submit", "#testForm", function( ev ) {
count1++;
ev.preventDefault();
} );
jQuery( document ).on( "submit", "body", function( ev ) {
count2++;
ev.preventDefault();
} );
jQuery( "#testForm input[name=sub1]" ).trigger( "submit" );
assert.equal( count1, 1, "Verify form submit." );
assert.equal( count2, 1, "Verify body submit." );
jQuery( "#body" ).off( undefined, "**" );
jQuery( document ).off( undefined, "**" );
} );
QUnit.test( "delegated off() with only namespaces", function( assert ) {
assert.expect( 2 );
var $delegate = jQuery( "#liveHandlerOrder" ),
count = 0;
$delegate.on( "click.ns", "a", function() {
count++;
} );
jQuery( "a", $delegate ).eq( 0 ).trigger( "click.ns" );
assert.equal( count, 1, "delegated click.ns" );
$delegate.off( ".ns", "**" );
jQuery( "a", $delegate ).eq( 1 ).trigger( "click.ns" );
assert.equal( count, 1, "no more .ns after off" );
} );
QUnit.test( "Non DOM element events", function( assert ) {
assert.expect( 1 );
var o = {};
jQuery( o ).on( "nonelementobj", function() {
assert.ok( true, "Event on non-DOM object triggered" );
} );
jQuery( o ).trigger( "nonelementobj" ).off( "nonelementobj" );
} );
QUnit.test( "inline handler returning false stops default", function( assert ) {
assert.expect( 1 );
var markup = jQuery( "<div><a href=\"#\" onclick=\"return false\">x</a></div>" );
markup.on( "click", function( e ) {
assert.ok( e.isDefaultPrevented(), "inline handler prevented default" );
return false;
} );
markup.find( "a" ).trigger( "click" );
markup.off( "click" );
} );
QUnit.test( "window resize", function( assert ) {
assert.expect( 2 );
jQuery( window ).off();
jQuery( window ).on( "resize", function() {
assert.ok( true, "Resize event fired." );
} ).trigger( "resize" ).off( "resize" );
assert.ok( !jQuery._data( window, "events" ), "Make sure all the events are gone." );
} );
QUnit.test( "focusin bubbles", function( assert ) {
assert.expect( 2 );
var input = jQuery( "<input type='text' />" ).prependTo( "body" ),
order = 0;
// focus the element so DOM focus won't fire
input[ 0 ].focus();
jQuery( "body" ).on( "focusin.focusinBubblesTest", function() {
assert.equal( 1, order++, "focusin on the body second" );
} );
input.on( "focusin.focusinBubblesTest", function() {
assert.equal( 0, order++, "focusin on the element first" );
} );
// Removed since DOM focus is unreliable on test swarm
// DOM focus method
// input[0].focus();
// To make the next focus test work, we need to take focus off the input.
// This will fire another focusin event, so set order to reflect that.
// order = 1;
// jQuery("#text1")[0].focus();
// jQuery trigger, which calls DOM focus
order = 0;
input.trigger( "focus" );
input.remove();
jQuery( "body" ).off( "focusin.focusinBubblesTest" );
} );
QUnit.test( "custom events with colons (#3533, #8272)", function( assert ) {
assert.expect( 1 );
var tab = jQuery( "<table><tr><td>trigger</td></tr></table>" ).appendTo( "body" );
try {
tab.trigger( "back:forth" );
assert.ok( true, "colon events don't throw" );
} catch ( e ) {
assert.ok( false, "colon events die" );
}
tab.remove();
} );
QUnit.test( ".on and .off", function( assert ) {
assert.expect( 9 );
var counter, mixfn, data,
$onandoff = jQuery( "<div id=\"onandoff\"><p>on<b>and</b>off</p><div>worked<em>or</em>borked?</div></div>" ).appendTo( "body" );
// Simple case
jQuery( "#onandoff" )
.on( "whip", function() {
assert.ok( true, "whipped it good" );
} )
.trigger( "whip" )
.off();
// Direct events only
counter = 0;
jQuery( "#onandoff b" )
.on( "click", 5, function( e, trig ) {
counter += e.data + ( trig || 9 ); // twice, 5+9+5+17=36
} )
.one( "click", 7, function( e, trig ) {
counter += e.data + ( trig || 11 ); // once, 7+11=18
} )
.trigger( "click" )
.trigger( "click", 17 )
.off( "click" );
assert.equal( counter, 54, "direct event bindings with data" );
// Delegated events only
counter = 0;
jQuery( "#onandoff" )
.on( "click", "em", 5, function( e, trig ) {
counter += e.data + ( trig || 9 ); // twice, 5+9+5+17=36
} )
.one( "click", "em", 7, function( e, trig ) {
counter += e.data + ( trig || 11 ); // once, 7+11=18
} )
.find( "em" )
.trigger( "click" )
.trigger( "click", 17 )
.end()
.off( "click", "em" );
assert.equal( counter, 54, "delegated event bindings with data" );
// Mixed event bindings and types
counter = 0;
mixfn = function( e, trig ) {
counter += ( e.data || 0 ) + ( trig || 1 );
};
jQuery( "#onandoff" )
.on( " click clack cluck ", "em", 2, mixfn )
.on( "cluck", "b", 7, mixfn )
.on( "cluck", mixfn )
.trigger( "what!" )
.each( function() {
assert.equal( counter, 0, "nothing triggered yet" );
} )
.find( "em" )
.one( "cluck", 3, mixfn )
.trigger( "cluck", 8 ) // 3+8 2+8 + 0+8 = 29
.off()
.trigger( "cluck", 9 ) // 2+9 + 0+9 = 20
.end()
.each( function() {
assert.equal( counter, 49, "after triggering em element" );
} )
.off( "cluck", function() {} ) // shouldn't remove anything
.trigger( "cluck", 2 ) // 0+2 = 2
.each( function() {
assert.equal( counter, 51, "after triggering #onandoff cluck" );
} )
.find( "b" )
.on( "click", 95, mixfn )
.on( "clack", "p", 97, mixfn )
.one( "cluck", 3, mixfn )
.trigger( "quack", 19 ) // 0
.off( "click clack cluck" )
.end()
.each( function() {
assert.equal( counter, 51, "after triggering b" );
} )
.trigger( "cluck", 3 ) // 0+3 = 3
.off( "clack", "em", mixfn )
.find( "em" )
.trigger( "clack" ) // 0
.end()
.each( function() {
assert.equal( counter, 54, "final triggers" );
} )
.off( "click cluck" );
// We should have removed all the event handlers ... kinda hacky way to check this
data = jQuery.data[ jQuery( "#onandoff" )[ 0 ].expando ] || {};
assert.equal( data[ "events" ], undefined, "no events left" );
$onandoff.remove();
} );
QUnit.test( "special on name mapping", function( assert ) {
assert.expect( 7 );
jQuery.event.special.slap = {
bindType: "click",
delegateType: "swing",
handle: function( event ) {
assert.equal( event.handleObj.origType, "slap", "slapped your mammy, " + event.type );
}
};
var comeback = function( event ) {
assert.ok( true, "event " + event.type + " triggered" );
};
jQuery( "<div><button id=\"mammy\">Are We Not Men?</button></div>" )
.on( "slap", "button", jQuery.noop )
.on( "swing", "button", comeback )
.find( "button" )
.on( "slap", jQuery.noop )
.on( "click", comeback )
.trigger( "click" ) // bindType-slap and click
.off( "slap" )
.trigger( "click" ) // click
.off( "click" )
.trigger( "swing" ) // delegateType-slap and swing
.end()
.off( "slap swing", "button" )
.find( "button" ) // everything should be gone
.trigger( "slap" )
.trigger( "click" )
.trigger( "swing" )
.end()
.remove();
delete jQuery.event.special.slap;
jQuery.event.special.gutfeeling = {
bindType: "click",
delegateType: "click",
handle: function( event ) {
assert.equal( event.handleObj.origType, "gutfeeling", "got a gutfeeling" );
// Need to call the handler since .one() uses it to unbind
return event.handleObj.handler.call( this, event );
}
};
// Ensure a special event isn't removed by its mapped type
jQuery( "<p>Gut Feeling</p>" )
.on( "click", jQuery.noop )
.on( "gutfeeling", jQuery.noop )
.off( "click" )
.trigger( "gutfeeling" )
.remove();
// Ensure special events are removed when only a namespace is provided
jQuery( "<p>Gut Feeling</p>" )
.on( "gutfeeling.Devo", jQuery.noop )
.off( ".Devo" )
.trigger( "gutfeeling" )
.remove();
// Ensure .one() events are removed after their maiden voyage
jQuery( "<p>Gut Feeling</p>" )
.one( "gutfeeling", jQuery.noop )
.trigger( "gutfeeling" ) // This one should
.trigger( "gutfeeling" ) // This one should not
.remove();
delete jQuery.event.special[ "gutfeeling" ];
} );
QUnit.test( ".on and .off, selective mixed removal (#10705)", function( assert ) {
assert.expect( 7 );
var timingx = function( e ) {
assert.ok( true, "triggered " + e.type );
};
jQuery( "<p>Strange Pursuit</p>" )
.on( "click", timingx )
.on( "click.duty", timingx )
.on( "click.now", timingx )
.on( "devo", timingx )
.on( "future", timingx )
.trigger( "click" ) // 3
.trigger( "devo" ) // 1
.off( ".duty devo " ) // trailing space
.trigger( "future" ) // 1
.trigger( "click" ) // 2
.off( "future click" )
.trigger( "click" ); // 0
} );
QUnit.test( ".on( event-map, null-selector, data ) #11130", function( assert ) {
assert.expect( 1 );
var $p = jQuery( "<p>Strange Pursuit</p>" ),
data = "bar",
map = {
"foo": function( event ) {
assert.equal( event.data, "bar", "event.data correctly relayed with null selector" );
$p.remove();
}
};
$p.on( map, null, data ).trigger( "foo" );
} );
QUnit.test( "clone() delegated events (#11076)", function( assert ) {
assert.expect( 3 );
var counter = { "center": 0, "fold": 0, "centerfold": 0 },
clicked = function() {
counter[ jQuery( this ).text().replace( /\s+/, "" ) ]++;
},
table =
jQuery( "<table><tr><td>center</td><td>fold</td></tr></table>" )
.on( "click", "tr", clicked )
.on( "click", "td:first-child", clicked )
.on( "click", "td:last-child", clicked ),
clone = table.clone( true );
clone.find( "td" ).trigger( "click" );
assert.equal( counter.center, 1, "first child" );
assert.equal( counter.fold, 1, "last child" );
assert.equal( counter.centerfold, 2, "all children" );
table.remove();
clone.remove();
} );
QUnit.test( "checkbox state (trac-3827)", function( assert ) {
assert.expect( 16 );
var markup = jQuery( "<div class='parent'><input type=checkbox><div>" ),
cb = markup.find( "input" )[ 0 ];
markup.appendTo( "#qunit-fixture" );
jQuery( cb ).on( "click", function() {
assert.equal( this.checked, false, "just-clicked checkbox is not checked" );
} );
markup.on( "click", function() {
assert.equal( cb.checked, false, "checkbox is not checked in bubbled event" );
} );
// Native click
cb.checked = true;
assert.equal( cb.checked, true, "native event - checkbox is initially checked" );
cb.click();
assert.equal( cb.checked, false, "native event - checkbox is no longer checked" );
// jQuery click
cb.checked = true;
assert.equal( cb.checked, true, "jQuery event - checkbox is initially checked" );
jQuery( cb ).trigger( "click" );
assert.equal( cb.checked, false, "jQuery event - checkbox is no longer checked" );
// Handlers only; checkbox state remains false
jQuery( cb ).triggerHandler( "click" );
assert.equal( cb.checked, false, "handlers only - checkbox is still unchecked" );
// Trigger parameters are preserved (trac-13353, gh-4139)
cb.checked = true;
assert.equal( cb.checked, true, "jQuery event with data - checkbox is initially checked" );
jQuery( cb ).on( "click", function( e, data ) {
assert.equal( data, "clicked", "trigger data passed to handler" );
} );
markup.on( "click", function( e, data ) {
assert.equal( data, "clicked", "trigger data passed to bubbled handler" );
} );
jQuery( cb ).trigger( "click", [ "clicked" ] );
assert.equal( cb.checked, false, "jQuery event with data - checkbox is no longer checked" );
} );
QUnit.test( "event object properties on natively-triggered event", function( assert ) {
assert.expect( 3 );
var link = document.createElement( "a" ),
$link = jQuery( link ),
evt = document.createEvent( "MouseEvents" );
// Support: IE <=9 - 11 only
// IE requires element to be in the body before it will dispatch
$link.appendTo( "body" ).on( "click", function( e ) {
// Not trying to assert specific values here, just ensure the property exists
assert.equal( "detail" in e, true, "has .detail" );
assert.equal( "cancelable" in e, true, "has .cancelable" );
assert.equal( "bubbles" in e, true, "has .bubbles" );
} );
evt.initEvent( "click", true, true );
link.dispatchEvent( evt );
$link.off( "click" ).remove();
} );
QUnit.test( "addProp extensions", function( assert ) {
assert.expect( 2 );
var $fixture = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
// Ensure the property doesn't exist
$fixture.on( "click", function( event ) {
assert.ok( !( "testProperty" in event ), "event.testProperty does not exist" );
} );
fireNative( $fixture[ 0 ], "click" );
$fixture.off( "click" );
jQuery.event.addProp( "testProperty", function() { return 42; } );
// Trigger a native click and ensure the property is set
$fixture.on( "click", function( event ) {
assert.equal( event.testProperty, 42, "event.testProperty getter was invoked" );
} );
fireNative( $fixture[ 0 ], "click" );
$fixture.off( "click" );
$fixture.remove();
} );
QUnit.test( "drag/drop events copy mouse-related event properties (gh-1925, gh-2009)", function( assert ) {
assert.expect( 4 );
var $fixture = jQuery( "<div id='drag-fixture'></div>" ).appendTo( "body" );
$fixture.on( "dragmove", function( evt ) {
assert.ok( "pageX" in evt, "checking for pageX property on dragmove" );
assert.ok( "pageY" in evt, "checking for pageY property on dragmove" );
} );
fireNative( $fixture[ 0 ], "dragmove" );
$fixture.on( "drop", function( evt ) {
assert.ok( "pageX" in evt, "checking for pageX property on drop" );
assert.ok( "pageY" in evt, "checking for pageY property on drop" );
} );
fireNative( $fixture[ 0 ], "drop" );
$fixture.off( "dragmove drop" ).remove();
} );
QUnit.test( "focusin using non-element targets", function( assert ) {
assert.expect( 2 );
jQuery( document ).on( "focusin", function( e ) {
assert.ok( e.type === "focusin", "got a focusin event on a document" );
} ).trigger( "focusin" ).off( "focusin" );
jQuery( window ).on( "focusin", function( e ) {
assert.ok( e.type === "focusin", "got a focusin event on a window" );
} ).trigger( "focusin" ).off( "focusin" );
} );
testIframe(
"focusin from an iframe",
"event/focusinCrossFrame.html",
function( assert, framejQuery, frameWin, frameDoc ) {
assert.expect( 1 );
var done = assert.async(),
focus = false,
input = jQuery( frameDoc ).find( "#frame-input" );
// Create a focusin handler on the parent; shouldn't affect the iframe's fate
jQuery( "body" ).on( "focusin.iframeTest", function() {
// Support: IE 9 - 11+
// IE does propagate the event to the parent document. In this test
// we mainly care about the inner element so we'll just skip this one
// assertion in IE.
if ( !document.documentMode ) {
assert.ok( false, "fired a focusin event in the parent document" );
}
} );
input.on( "focusin", function() {
focus = true;
assert.ok( true, "fired a focusin event in the iframe" );
} );
// Avoid a native event; Chrome can't force focus to another frame
input[ 0 ].focus();
// Remove body handler manually since it's outside the fixture
jQuery( "body" ).off( "focusin.iframeTest" );
setTimeout( function() {
// DOM focus is unreliable in TestSwarm
if ( QUnit.isSwarm && !focus ) {
assert.ok( true, "GAP: Could not observe focus change" );
}
done();
}, 50 );
}
);
QUnit.test( "focusin on document & window", function( assert ) {
assert.expect( 1 );
var counter = 0,
input = jQuery( "<input />" );
function increment() {
counter++;
}
input.appendTo( "#qunit-fixture" );
input[ 0 ].focus();
jQuery( window ).on( "focusout", increment );
jQuery( document ).on( "focusout", increment );
input[ 0 ].blur();
// DOM focus is unreliable in TestSwarm
if ( QUnit.isSwarm && counter === 0 ) {
assert.ok( true, "GAP: Could not observe focus change" );
}
assert.strictEqual( counter, 2,
"focusout handlers on document/window fired once only" );
jQuery( window ).off( "focusout", increment );
jQuery( document ).off( "focusout", increment );
} );
testIframe(
"jQuery.ready promise",
"event/promiseReady.html",
function( assert, jQuery, window, document, isOk ) {
assert.expect( 1 );
assert.ok( isOk, "$.when( $.ready ) works" );
},
jQuery.when ? QUnit.test : QUnit.skip
);
// need PHP here to make the incepted IFRAME hang
if ( hasPHP ) {
testIframe(
"jQuery.ready uses interactive",
"event/interactiveReady.html",
function( assert, jQuery, window, document, isOk ) {
assert.expect( 1 );
assert.ok( isOk, "jQuery fires ready when the DOM can truly be interacted with" );
}
);
}
testIframe(
"Focusing iframe element",
"event/focusElem.html",
function( assert, jQuery, window, document, isOk ) {
assert.expect( 1 );
assert.ok( isOk, "Focused an element in an iframe" );
}
);
testIframe(
"triggerHandler(onbeforeunload)",
"event/triggerunload.html",
function( assert, jQuery, window, document, isOk ) {
assert.expect( 1 );
assert.ok( isOk, "Triggered onbeforeunload without an error" );
}
);
// need PHP here to make the incepted IFRAME hang
if ( hasPHP ) {
testIframe(
"jQuery.ready synchronous load with long loading subresources",
"event/syncReady.html",
function( assert, jQuery, window, document, isOk ) {
assert.expect( 1 );
assert.ok( isOk, "jQuery loaded synchronously fires ready when the DOM can truly be interacted with" );
}
);
}
QUnit.test( "change handler should be detached from element", function( assert ) {
assert.expect( 2 );
var $fixture = jQuery( "<input type='text' id='change-ie-leak' />" ).appendTo( "body" ),
originRemoveEvent = jQuery.removeEvent,
wrapperRemoveEvent = function( elem, type, handle ) {
assert.equal( "change", type, "Event handler for 'change' event should be removed" );
assert.equal( "change-ie-leak", jQuery( elem ).attr( "id" ), "Event handler for 'change' event should be removed from appropriate element" );
originRemoveEvent( elem, type, handle );
};
jQuery.removeEvent = wrapperRemoveEvent;
$fixture.on( "change", function() {} );
$fixture.off( "change" );
$fixture.remove();
jQuery.removeEvent = originRemoveEvent;
} );
QUnit.test( "trigger click on checkbox, fires change event", function( assert ) {
assert.expect( 1 );
var check = jQuery( "#check2" );
var done = assert.async();
check.on( "change", function() {
// get it?
check.off( "change" );
assert.ok( true, "Change event fired as a result of triggered click" );
done();
} ).trigger( "click" );
} );
QUnit.test( "Namespace preserved when passed an Event (#12739)", function( assert ) {
assert.expect( 4 );
var markup = jQuery(
"<div id='parent'><div id='child'></div></div>"
),
triggered = 0,
fooEvent;
markup.find( "div" )
.addBack()
.on( "foo.bar", function( e ) {
if ( !e.handled ) {
triggered++;
e.handled = true;
assert.equal( e.namespace, "bar", "namespace is bar" );
jQuery( e.target ).find( "div" ).each( function() {
jQuery( this ).triggerHandler( e );
} );
}
} )
.on( "foo.bar2", function() {
assert.ok( false, "foo.bar2 called on trigger " + triggered + " id " + this.id );
} );
markup.trigger( "foo.bar" );
markup.trigger( jQuery.Event( "foo.bar" ) );
fooEvent = jQuery.Event( "foo" );
fooEvent.namespace = "bar";
markup.trigger( fooEvent );
markup.remove();
assert.equal( triggered, 3, "foo.bar triggered" );
} );
QUnit.test( "make sure events cloned correctly", function( assert ) {
assert.expect( 18 );
var clone,
fixture = jQuery( "#qunit-fixture" ),
checkbox = jQuery( "#check1" ),
p = jQuery( "#firstp" );
fixture.on( "click change", function( event, result ) {
assert.ok( result, event.type + " on original element is fired" );
} ).on( "click", "#firstp", function( event, result ) {
assert.ok( result, "Click on original child element though delegation is fired" );
} ).on( "change", "#check1", function( event, result ) {
assert.ok( result, "Change on original child element though delegation is fired" );
} );
p.on( "click", function() {
assert.ok( true, "Click on original child element is fired" );
} );
checkbox.on( "change", function() {
assert.ok( true, "Change on original child element is fired" );
} );
fixture.clone().trigger( "click" ).trigger( "change" ); // 0 events should be fired
clone = fixture.clone( true );
clone.find( "p" ).eq( 0 ).trigger( "click", true ); // 3 events should fire
clone.find( "#check1" ).trigger( "change", true ); // 3 events should fire
clone.remove();
clone = fixture.clone( true, true );
clone.find( "p" ).eq( 0 ).trigger( "click", true ); // 3 events should fire
clone.find( "#check1" ).trigger( "change", true ); // 3 events should fire
fixture.off();
p.off();
checkbox.off();
p.trigger( "click" ); // 0 should be fired
checkbox.trigger( "change" ); // 0 should be fired
clone.find( "p" ).eq( 0 ).trigger( "click", true ); // 3 events should fire
clone.find( "#check1" ).trigger( "change", true ); // 3 events should fire
clone.remove();
clone.find( "p" ).eq( 0 ).trigger( "click" ); // 0 should be fired
clone.find( "#check1" ).trigger( "change" ); // 0 events should fire
} );
QUnit.test( "String.prototype.namespace does not cause trigger() to throw (#13360)", function( assert ) {
assert.expect( 1 );
var errored = false;
String.prototype.namespace = function() {};
try {
jQuery( "<p>" ).trigger( "foo.bar" );
} catch ( e ) {
errored = true;
}
assert.equal( errored, false, "trigger() did not throw exception" );
delete String.prototype.namespace;
} );
QUnit.test( "Inline event result is returned (#13993)", function( assert ) {
assert.expect( 1 );
var result = jQuery( "<p onclick='return 42'>hello</p>" ).triggerHandler( "click" );
assert.equal( result, 42, "inline handler returned value" );
} );
QUnit.test( ".off() removes the expando when there's no more data", function( assert ) {
assert.expect( 2 );
var key,
div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" );
div.on( "click", false );
div.on( "custom", function() {
assert.ok( true, "Custom event triggered" );
} );
div.trigger( "custom" );
div.off( "click custom" );
// Make sure the expando is gone
for ( key in div[ 0 ] ) {
if ( /^jQuery/.test( key ) ) {
assert.strictEqual(
div[ 0 ][ key ], undefined,
"Expando was not removed when there was no more data"
);
}
}
} );
QUnit.test( "jQuery.Event( src ) does not require a target property", function( assert ) {
assert.expect( 2 );
var event = jQuery.Event( { type: "offtarget" } );
assert.equal( event.type, "offtarget", "correct type" );
assert.equal( event.target, undefined, "no target" );
} );
QUnit.test( "preventDefault() on focusin does not throw exception", function( assert ) {
assert.expect( 1 );
var done = assert.async(),
input = jQuery( "<input/>" ).appendTo( "#form" );
input.on( "focusin", function( event ) {
if ( !done ) {
return;
}
var exceptionCaught;
try {
event.preventDefault();
} catch ( theException ) {
exceptionCaught = theException;
}
assert.strictEqual( exceptionCaught, undefined,
"Preventing default on focusin throws no exception" );
done();
done = null;
} );
input.trigger( "focus" );
// DOM focus is unreliable in TestSwarm; set a simulated event workaround timeout
setTimeout( function() {
if ( !done ) {
return;
}
input[ 0 ].addEventListener( "click", function( nativeEvent ) {
jQuery.event.simulate( "focusin", this, jQuery.event.fix( nativeEvent ) );
} );
input[ 0 ].click();
}, QUnit.config.testTimeout / 4 || 1000 );
} );
QUnit.test( ".on('focus', fn) on a text node doesn't throw", function( assert ) {
assert.expect( 1 );
jQuery( document.createTextNode( "text" ) )
.on( "focus", function() {} );
assert.ok( true, "No crash" );
} );
QUnit.test( "Donor event interference", function( assert ) {
assert.expect( 8 );
var outer = jQuery(
"<div id='donor-outer'>" +
"<form id='donor-form'>" +
"<input id='donor-input' type='checkbox' />" +
"</form>" +
"</div>"
).appendTo( "#qunit-fixture" ),
input = jQuery( "#donor-input" );
input.on( "click", function( event ) {
assert.equal( event.type, "click", "click event at input" );
assert.ok( !event.isPropagationStopped(), "click event at input is still propagating" );
assert.equal( typeof event.originalEvent, "object",
"click event at input has originalEvent property" );
} );
outer.on( "click", function( event ) {
assert.equal( event.type, "click", "click event at ancestor" );
assert.ok( !event.isPropagationStopped(), "click event at ancestor is still propagating" );
assert.equal( typeof event.originalEvent, "object",
"click event at ancestor has originalEvent property" );
} );
input.on( "change", function( event ) {
assert.equal( event.type, "change", "change event at input" );
assert.equal( typeof event.originalEvent, "object",
"change event at input has originalEvent property" );
event.stopPropagation();
} );
input[ 0 ].click();
} );
QUnit.test(
"simulated events shouldn't forward stopPropagation/preventDefault methods",
function( assert ) {
assert.expect( 3 );
var outer = jQuery(
"<div id='donor-outer'>" +
"<form id='donor-form'>" +
"<input id='donor-input' type='checkbox' />" +
"</form>" +
"</div>"
).appendTo( "#qunit-fixture" ),
input = jQuery( "#donor-input" ),
spy = {};
jQuery( "#donor-form" )
.on( "simulated", function( event ) {
spy.prevent = sinon.stub( event.originalEvent, "preventDefault" );
event.preventDefault();
} )
.on( "simulated", function( event ) {
spy.stop = sinon.stub( event.originalEvent, "stopPropagation" );
event.stopPropagation();
} )
.on( "simulated", function( event ) {
spy.immediate = sinon.stub( event.originalEvent, "stopImmediatePropagation" );
event.stopImmediatePropagation();
} )
.on( "simulated", function( event ) {
assert.ok( false, "simulated event immediate propagation stopped" );
} );
outer
.on( "simulated", function( event ) {
assert.ok( false, "simulated event propagation stopped" );
} );
// Force a simulated event
input[ 0 ].addEventListener( "click", function( nativeEvent ) {
jQuery.event.simulate( "simulated", this, jQuery.event.fix( nativeEvent ) );
} );
input[ 0 ].click();
assert.strictEqual( spy.prevent.called, false, "Native preventDefault not called" );
assert.strictEqual( spy.stop.called, false, "Native stopPropagation not called" );
assert.strictEqual( spy.immediate.called, false,
"Native stopImmediatePropagation not called" );
}
);
QUnit.test( "originalEvent type of simulated event", function( assert ) {
assert.expect( 2 );
var outer = jQuery(
"<div id='donor-outer'>" +
"<form id='donor-form'>" +
"<input id='donor-input' type='text' />" +
"</form>" +
"</div>"
).appendTo( "#qunit-fixture" ),
input = jQuery( "#donor-input" ),
done = assert.async(),
finish = function() {
// Remove jQuery handlers to ensure removal of capturing handlers on the document
outer.off( "focusin" );
done();
};
outer.on( "focusin", function( event ) {
assert.equal( event.type, "focusin", "focusin event at ancestor" );
assert.equal( event.originalEvent.type, "click",
"focus event at ancestor has correct originalEvent type" );
setTimeout( finish );
} );
input[ 0 ].addEventListener( "click", function( nativeEvent ) {
jQuery.event.simulate( "focusin", this, jQuery.event.fix( nativeEvent ) );
} );
input[ 0 ].click();
} );
QUnit.test( "trigger('click') on radio passes extra params", function( assert ) {
assert.expect( 1 );
var $radio = jQuery( "<input type='radio' />" ).appendTo( "#qunit-fixture" )
.on( "click", function( e, data ) {
assert.ok( data, "Trigger data is passed to radio click handler" );
} );
$radio.trigger( "click", [ true ] );
} );
// Support: IE <=9 only
// https://msdn.microsoft.com/en-us/library/hh801223(v=vs.85).aspx
QUnit.test( "VML with special event handlers (trac-7071)", function( assert ) {
assert.expect( 1 );
var ns = jQuery( "<xml:namespace ns='urn:schemas-microsoft-com:vml' prefix='v' />" ).appendTo( "head" );
jQuery( "<v:oval id='oval' style='width:100pt;height:75pt;' fillcolor='red'> </v:oval>" ).appendTo( "#form" );
jQuery( "#form" ).on( "keydown", function() {
assert.ok( true, "no error was thrown" );
} );
jQuery( "#oval" ).trigger( "click" ).trigger( "keydown" );
ns.remove();
} );
QUnit.test( "Check order of focusin/focusout events", function( assert ) {
assert.expect( 2 );
var focus, blur,
input = jQuery( "#name" );
input
.on( "focus", function() {
focus = true;
} )
.on( "focusin", function() {
assert.ok( !focus, "Focusin event should fire before focus does" );
focus = true;
} )
.on( "blur", function() {
blur = true;
} )
.on( "focusout", function() {
assert.ok( !blur, "Focusout event should fire before blur does" );
blur = true;
} );
// gain focus
input.trigger( "focus" );
// then lose it
jQuery( "#search" ).trigger( "focus" );
// cleanup
input.off();
// DOM focus is unreliable in TestSwarm
if ( !focus ) {
assert.ok( true, "GAP: Could not observe focus change" );
assert.ok( true, "GAP: Could not observe focus change" );
}
} );
QUnit.test( "focus-blur order (#12868)", function( assert ) {
assert.expect( 5 );
var order,
$text = jQuery( "#text1" ),
$radio = jQuery( "#radio1" ),
// Support: IE <=9 - 11+
// focus and blur events are asynchronous; this is the resulting mess.
// The browser window must be topmost for this to work properly!!
done = assert.async();
$radio[ 0 ].focus();
setTimeout( function() {
$text
.on( "focus", function() {
assert.equal( order++, 1, "text focus" );
} )
.on( "blur", function() {
assert.equal( order++, 0, "text blur" );
} );
$radio
.on( "focus", function() {
assert.equal( order++, 1, "radio focus" );
} )
.on( "blur", function() {
assert.equal( order++, 0, "radio blur" );
} );
// Enabled input getting focus
order = 0;
assert.equal( document.activeElement, $radio[ 0 ], "radio has focus" );
$text.trigger( "focus" );
setTimeout( function() {
// DOM focus is unreliable in TestSwarm
if ( order === 0 ) {
assert.ok( true, "GAP: Could not observe focus change" );
assert.ok( true, "GAP: Could not observe focus change" );
}
assert.equal( document.activeElement, $text[ 0 ], "text has focus" );
// Run handlers without native method on an input
order = 1;
$radio.triggerHandler( "focus" );
// Clean up
$text.off();
$radio.off();
done();
}, 50 );
}, 50 );
} );
QUnit.test( "Event handling works with multiple async focus events (gh-4350)", function( assert ) {
assert.expect( 3 );
var remaining = 3,
input = jQuery( "#name" ),
// Support: IE <=9 - 11+
// focus and blur events are asynchronous; this is the resulting mess.
// The browser window must be topmost for this to work properly!!
done = assert.async();
input
.on( "focus", function() {
remaining--;
assert.ok( true, "received focus event, expecting " + remaining + " more" );
if ( remaining > 0 ) {
input.trigger( "blur" );
} else {
done();
}
} )
.on( "blur", function() {
setTimeout( function() {
input.trigger( "focus" );
} );
} );
// gain focus
input.trigger( "focus" );
// DOM focus is unreliable in TestSwarm
setTimeout( function() {
if ( QUnit.isSwarm && remaining === 3 ) {
assert.ok( true, "GAP: Could not observe focus change" );
assert.ok( true, "GAP: Could not observe focus change" );
assert.ok( true, "GAP: Could not observe focus change" );
setTimeout( function() {
done();
} );
}
} );
} );
QUnit.test( "native-backed events preserve trigger data (gh-1741, gh-4139)", function( assert ) {
assert.expect( 17 );
var parent = supportjQuery(
"<div class='parent'><input type='checkbox'><input type='radio'></div>"
).appendTo( "#qunit-fixture" ),
targets = jQuery( parent[ 0 ].childNodes ),
checkbox = jQuery( targets[ 0 ] ),
data = [ "arg1", "arg2" ],
slice = data.slice,
// Support: IE <=9 - 11+
// focus and blur events are asynchronous; this is the resulting mess.
// The browser window must be topmost for this to work properly!!
done = assert.async();
// click (gh-4139)
assert.strictEqual( targets[ 0 ].checked, false, "checkbox unchecked before click" );
assert.strictEqual( targets[ 1 ].checked, false, "radio unchecked before click" );
targets.add( parent ).on( "click", function( event ) {
var type = event.target.type,
level = event.currentTarget === parent[ 0 ] ? "parent" : "";
assert.strictEqual( event.target.checked, true,
type + " toggled before invoking " + level + " handler" );
assert.deepEqual( slice.call( arguments, 1 ), data,
type + " " + level + " handler received correct data" );
} );
targets.trigger( "click", data );
assert.strictEqual( targets[ 0 ].checked, true,
"checkbox toggled after click (default action)" );
assert.strictEqual( targets[ 1 ].checked, true,
"radio toggled after event (default action)" );
// focus (gh-1741)
assert.notEqual( document.activeElement, checkbox[ 0 ],
"element not focused before focus event" );
checkbox.on( "focus blur", function( event ) {
var type = event.type;
assert.deepEqual( slice.call( arguments, 1 ), data,
type + " handler received correct data" );
} );
checkbox.trigger( "focus", data );
setTimeout( function() {
assert.strictEqual( document.activeElement, checkbox[ 0 ],
"element focused after focus event (default action)" );
checkbox.trigger( "blur", data );
setTimeout( function() {
assert.notEqual( document.activeElement, checkbox[ 0 ],
"element not focused after blur event (default action)" );
done();
}, 50 );
}, 50 );
} );
// TODO replace with an adaptation of
// https://github.com/jquery/jquery/pull/1367/files#diff-a215316abbaabdf71857809e8673ea28R2464
( function() {
supportjQuery.each(
{
checkbox: "<input type='checkbox'>",
radio: "<input type='radio'>"
},
makeTestFor3751
);
function makeTestFor3751( type, html ) {
var testName = "native-backed namespaced clicks are handled correctly (gh-3751) - " + type;
QUnit.test( testName, function( assert ) {
assert.expect( 2 );
var parent = supportjQuery( "<div class='parent'>" + html + "</div>" ),
target = jQuery( parent[ 0 ].firstChild );
parent.appendTo( "#qunit-fixture" );
target.add( parent )
.on( "click.notFired", function( event ) {
assert.ok( false, "namespaced event should not be received" +
" by wrong-namespace listener at " + event.currentTarget.nodeName );
} )
.on( "click.fired", function( event ) {
assert.equal( event.target.checked, true,
"toggled before invoking handler at " + event.currentTarget.nodeName );
} )
.on( "click", function( event ) {
assert.ok( false, "namespaced event should not be received" +
" by non-namespaced listener at " + event.currentTarget.nodeName );
} );
target.trigger( "click.fired" );
} );
}
} )();
|