ref: master
public/javascripts/vendor/jquery-ui-1.10.4/development-bundle/docs/jQuery.widget.html
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 |
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI jQuery documentation</title> <style> body { font-family: "Trebuchet MS", "Arial", "Helvetica", "Verdana", "sans-serif" } .gutter { display: none; } </style> </head> <body> <script>{ "title": "Widget Factory", "excerpt": "Create stateful jQuery plugins using the same abstraction as all jQuery UI widgets.", "termSlugs": { "category": [ "utilities","widgets" ] } }</script><div class="toc"> <h4><span>Contents:</span></h4> <ul class="toc-list"> <li> <a href="#jQuery-widget1">jQuery.widget( name [, base ], prototype )</a><ul><li><a href="#jQuery-widget-name-base-prototype">jQuery.widget( name [, base ], prototype )</a></li></ul> </li> <li><a href="#jQuery-Widget2">jQuery.Widget</a></li> </ul> </div><article id="jQuery-widget1" class="entry method"><h2 class="section-title"><span class="name">jQuery.widget( name [, base ], prototype )</span></h2> <div class="entry-wrapper"> <p class="desc"><strong>Description: </strong>Create stateful jQuery plugins using the same abstraction as all jQuery UI widgets.</p> <ul class="signatures"><li class="signature"> <h4 class="name"><a id="jQuery-widget-name-base-prototype" href="#jQuery-widget-name-base-prototype"><span class="icon-link"></span>jQuery.widget( name [, base ], prototype )</a></h4> <ul> <li> <div><strong>name</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#String">String</a> </div> <div>The name of the widget to create, including the namespace.</div> </li> <li> <div><strong>base</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Function">Function</a>()</div> <div>The base widget to inherit from. This must be a constructor that can be instantiated with the `new` keyword. Defaults to <code>jQuery.Widget</code>.</div> </li> <li> <div><strong>prototype</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#PlainObject">PlainObject</a> </div> <div>The object to use as a prototype for the widget.</div> </li> </ul> </li></ul> <div class="longdesc" id="entry-longdesc"> <p>You can create new widgets from scratch, using just the <code>$.Widget</code> object as a base to inherit from, or you can explicitly inherit from existing jQuery UI or third-party widgets. Defining a widget with the same name as you inherit from even allows you to extend widgets in place.</p> <p>jQuery UI contains many widgets that maintain state and therefore have a slightly different usage pattern than typical jQuery plugins. All of jQuery UI's widgets use the same patterns, which is defined by the widget factory. So if you learn how to use one widget, then you'll know how to use all of them.</p> <p class="note">Looking for tutorials about the widget factory? Check out <a href="http://learn.jquery.com/jquery-ui/widget-factory/">the articles on the jQuery Learning Center</a>.</p> <p><em>Note: This documentation shows examples using the <a href="/progressbar/">progressbar widget</a> but the syntax is the same for every widget.</em></p> <h3>Initialization</h3> <p>In order to track the state of the widget, we must introduce a full life cycle for the widget. The life cycle starts when the widget is initialized. To initialize a widget, we simply call the plugin on one or more elements.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">"#elem"</span> ).progressbar();</code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>This will initialize each element in the jQuery object, in this case the element with an id of <code>"elem"</code>.</p> <h3>Options</h3> <p>Because <code>progressbar()</code> was called with no parameters, the widget was initialized with its default options. We can pass a set of options during initialization to override the defaults:</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">"#elem"</span> ).progressbar({ value: <span class="number">20</span> });</code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>We can pass as many or as few options as we want during initialization. Any options that we don't pass will just use their default values.</p> <p>You can pass multiple options arguments. Those arguments will be merged into one object (similar to <a href="//api.jquery.com/jQuery.extend/"><code>$.extend( true, target, object1, objectN )</code></a>). This is useful for sharing options between instances, while overriding some settings for each one:</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">var</span> options = { modal: <span class="literal">true</span>, show: <span class="string">"slow"</span> };</code></div></div><div class="container"><div class="line"><code>$( <span class="string">"#dialog1"</span> ).dialog( options );</code></div></div><div class="container"><div class="line"><code>$( <span class="string">"#dialog2"</span> ).dialog( options, { autoOpen: <span class="literal">false</span> });</code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>All options passed on init are deep-copied to ensure the objects can be modified later without affecting the widget. Arrays are the only exception, they are referenced as-is. This exception is in place to support data-binding, where the data source has to be kept as a reference.</p> <p>The default values are stored on the widget's prototype, therefore we have the ability to override the values that jQuery UI sets. For example, after setting the following, all future progressbar instances will default to a value of 80:</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$.ui.progressbar.prototype.options.value = <span class="number">80</span>;</code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>The options are part of the widget's state, so we can set options after initialization as well. We'll see this later with the option method.</p> <h3>Methods</h3> <p>Now that the widget is initialized, we can query its state or perform actions on the widget. All actions after initialization take the form of a method call. To call a method on a widget, we pass the name of the method to the jQuery plugin. For example, to call the <code>value()</code> method on our progressbar widget, we would use:</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">"#elem"</span> ).progressbar( <span class="string">"value"</span> );</code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>If the method accepts parameters, we can pass them after the method name. For example, to pass the parameter <code>40</code> to the <code>value()</code> method, we can use:</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">"#elem"</span> ).progressbar( <span class="string">"value"</span>, <span class="number">40</span> );</code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>Just like other methods in jQuery, most widget methods return the jQuery object for chaining.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">"#elem"</span> )</code></div></div><div class="container"><div class="line"><code> .progressbar( <span class="string">"value"</span>, <span class="number">90</span> )</code></div></div><div class="container"><div class="line"><code> .addClass( <span class="string">"almost-done"</span> );</code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>Each widget will have its own set of methods based on the functionality that the widget provides. However, there are a few methods that exist on all widgets, which are documented below.</p> <h3>Events</h3> <p>All widgets have events associated with their various behaviors to notify you when the state is changing. For most widgets, when the events are triggered, the names are prefixed with the widget name and lowercased. For example, we can bind to progressbar's <code>change</code> event which is triggered whenever the value changes.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">"#elem"</span> ).bind( <span class="string">"progressbarchange"</span>, <span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code> alert( <span class="string">"The value has changed!"</span> );</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>Each event has a corresponding callback, which is exposed as an option. We can hook into progressbar's <code>change</code> callback instead of binding to the <code>progressbarchange</code> event, if we want to.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">"#elem"</span> ).progressbar({</code></div></div><div class="container"><div class="line"><code> change: <span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code> alert( <span class="string">"The value has changed!"</span> );</code></div></div><div class="container"><div class="line"><code> }</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>All widgets have a <code>create</code> event which is triggered upon instantiation.</p> <h3>Instance</h3> <p>The widget's instance is stored using <a href="//api.jquery.com/jQuery.data/"><code>jQuery.data()</code></a> with the widget's full name as the key. Therefore, you can use the following to retrieve the progressbar widget's instance object from the element.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">"#elem"</span> ).data( <span class="string">"ui-progressbar"</span> );</code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>Whether an element has a given widget bound to it can be determined using the <a href="/data-selector/"><code>:data</code></a> selector.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">"#elem"</span> ).is( <span class="string">":data( 'ui-progressbar' )"</span> ); <span class="comment">// true</span></code></div></div><div class="container"><div class="line"><code>$( <span class="string">"#elem"</span> ).is( <span class="string">":data( 'ui-draggable' )"</span> ); <span class="comment">// false</span></code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>You can also use <code>:data</code> to get a list of all elements that are instances of a given widget.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">":data( 'ui-progressbar' )"</span> );</code></div></div></pre> </td> </tr> </tbody> </table> </div> <h3>Properties</h3> <p>All widgets have the following set of properties:</p> <ul> <li> <strong>defaultElement</strong>: An element to use when a widget instance is constructed without providing an element. For example, since the progressbar's <code>defaultElement</code> is <code>"<div></code>", <code>$.ui.progressbar({ value: 50 })</code> instantiates a progressbar widget instance on a newly created <code><div></code>. </li> <li> <strong>document</strong>: The <code>document</code> that the widget's element is within. Useful if you need to interact with widgets within iframes. </li> <li> <strong>element</strong>: A jQuery object containing the element used to instantiate the widget. If you select multiple elements and call <code>.myWidget()</code>, a separate widget instance will be created for each element. Therefore, this property will always contain one element. </li> <li> <strong>namespace</strong>: The location on the global jQuery object that the widget's prototype is stored on. For example a <code>namespace</code> of <code>"ui"</code> indicates that the widget's prototype is stored on <code>$.ui</code>. </li> <li> <strong>options</strong>: An object containing the options currently being used by the widget. On instantiation, any options provided by the user will automatically be merged with any default values defined in <code>$.myNamespace.myWidget.prototype.options</code>. User specified options override the defaults. </li> <li> <strong>uuid</strong>: A unique integer identifier for the widget. </li> <li> <strong>version</strong>: The string version of the widget. For jQuery UI widgets this will be set to the version of jQuery UI the widget is using. Widget developers have to set this property in their prototype explicitly. </li> <li> <strong>widgetEventPrefix</strong>: The prefix prepended to the name of events fired from this widget. For example the <code>widgetEventPrefix</code> of the <a href="/draggable/">draggable widget</a> is <code>"drag"</code>, therefore when a draggable is created, the name of the event fired is <code>"dragcreate"</code>. By default the <code>widgetEventPrefix</code> of a widget is its name. <em>Note: This property is deprecated and will be removed in a later release. Event names will be changed to widgetName:eventName (e.g. <code>"draggable:create"</code>).</em> </li> <li> <strong>widgetFullName</strong>: The full name of the widget including the namespace. For <code>$.widget( "myNamespace.myWidget", {} )</code>, <code>widgetFullName</code> will be <code>"myNamespace-myWidget"</code>. </li> <li> <strong>widgetName</strong>: The name of the widget. For <code>$.widget( "myNamespace.myWidget", {} )</code>, <code>widgetName</code> will be <code>"myWidget"</code>. </li> <li> <strong>window</strong>: The <code>window</code> that the widget's element is within. Useful if you need to interact with widgets within iframes. </li> </ul> </div> </div></article><article id="jQuery-Widget2" class="entry widget"><h2 class="section-title"><span>Base Widget</span></h2> <div class="entry-wrapper"> <p class="desc"><strong>Description: </strong>The base widget used by the widget factory.</p> <section id="quick-nav"><header><h2>QuickNav</h2></header><div class="quick-nav-section"> <h3>Options</h3> <div><a href="#option-disabled">disabled</a></div> <div><a href="#option-hide">hide</a></div> <div><a href="#option-show">show</a></div> </div> <div class="quick-nav-section"> <h3>Methods</h3> <div><a href="#method-_create">_create</a></div> <div><a href="#method-_delay">_delay</a></div> <div><a href="#method-_destroy">_destroy</a></div> <div><a href="#method-_focusable">_focusable</a></div> <div><a href="#method-_getCreateEventData">_getCreateEventData</a></div> <div><a href="#method-_getCreateOptions">_getCreateOptions</a></div> <div><a href="#method-_hide">_hide</a></div> <div><a href="#method-_hoverable">_hoverable</a></div> <div><a href="#method-_init">_init</a></div> <div><a href="#method-_off">_off</a></div> <div><a href="#method-_on">_on</a></div> <div><a href="#method-_setOption">_setOption</a></div> <div><a href="#method-_setOptions">_setOptions</a></div> <div><a href="#method-_show">_show</a></div> <div><a href="#method-_super">_super</a></div> <div><a href="#method-_superApply">_superApply</a></div> <div><a href="#method-_trigger">_trigger</a></div> <div><a href="#method-destroy">destroy</a></div> <div><a href="#method-disable">disable</a></div> <div><a href="#method-enable">enable</a></div> <div><a href="#method-option">option</a></div> <div><a href="#method-widget">widget</a></div> </div> <div class="quick-nav-section"> <h3>Events</h3> <div><a href="#event-create">create</a></div> </div></section><section id="options"><header><h2>Options</h2></header><div id="option-disabled" class="api-item first-item"> <h3>disabled<span class="option-type"><strong>Type: </strong><a href="http://api.jquery.com/Types/#Boolean">Boolean</a></span> </h3> <div class="default"> <strong>Default: </strong><code>false</code> </div> <div>Disables the widget if set to <code>true</code>.</div> <strong>Code examples:</strong><p>Initialize the widget with the <code>disabled</code> option specified:</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">".selector"</span> ).widget({ disabled: <span class="literal">true</span> });</code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>Get or set the <code>disabled</code> option, after initialization:</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="comment">// getter</span></code></div></div><div class="container"><div class="line"><code><span class="keyword">var</span> disabled = $( <span class="string">".selector"</span> ).widget( <span class="string">"option"</span>, <span class="string">"disabled"</span> );</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="comment">// setter</span></code></div></div><div class="container"><div class="line"><code>$( <span class="string">".selector"</span> ).widget( <span class="string">"option"</span>, <span class="string">"disabled"</span>, <span class="literal">true</span> );</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> <div id="option-hide" class="api-item"> <h3>hide<span class="option-type"><strong>Type: </strong><a href="http://api.jquery.com/Types/#Boolean">Boolean</a> or <a href="http://api.jquery.com/Types/#Number">Number</a> or <a href="http://api.jquery.com/Types/#String">String</a> or <a href="http://api.jquery.com/Types/#Object">Object</a></span> </h3> <div class="default"> <strong>Default: </strong><code>null</code> </div> <div>If and how to animate the hiding of the element.</div> <strong>Multiple types supported:</strong><ul> <li> <strong>Boolean</strong>: When set to <code>false</code>, no animation will be used and the element will be hidden immediately. When set to <code>true</code>, the element will fade out with the default duration and the default easing. </li> <li> <strong>Number</strong>: The element will fade out with the specified duration and the default easing. </li> <li> <strong>String</strong>: The element will be hidden using the specified effect. The value can either be the name of a built-in jQuery animation method, such as <code>"slideUp"</code>, or the name of a <a href="/category/effects/">jQuery UI effect</a>, such as <code>"fold"</code>. In either case the effect will be used with the default duration and the default easing. </li> <li> <strong>Object</strong>: If the value is an object, then <code>effect</code>, <code>delay</code>, <code>duration</code>, and <code>easing</code> properties may be provided. If the <code>effect</code> property contains the name of a jQuery method, then that method will be used; otherwise it is assumed to be the name of a jQuery UI effect. When using a jQuery UI effect that supports additional settings, you may include those settings in the object and they will be passed to the effect. If <code>duration</code> or <code>easing</code> is omitted, then the default values will be used. If <code>effect</code> is omitted, then <code>"fadeOut"</code> will be used. If <code>delay</code> is omitted, then no delay is used.</li> </ul> <strong>Code examples:</strong><p>Initialize the widget with the <code>hide</code> option specified:</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">".selector"</span> ).widget({ hide: { effect: <span class="string">"explode"</span>, duration: <span class="number">1000</span> } });</code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>Get or set the <code>hide</code> option, after initialization:</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="comment">// getter</span></code></div></div><div class="container"><div class="line"><code><span class="keyword">var</span> hide = $( <span class="string">".selector"</span> ).widget( <span class="string">"option"</span>, <span class="string">"hide"</span> );</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="comment">// setter</span></code></div></div><div class="container"><div class="line"><code>$( <span class="string">".selector"</span> ).widget( <span class="string">"option"</span>, <span class="string">"hide"</span>, { effect: <span class="string">"explode"</span>, duration: <span class="number">1000</span> } );</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> <div id="option-show" class="api-item"> <h3>show<span class="option-type"><strong>Type: </strong><a href="http://api.jquery.com/Types/#Boolean">Boolean</a> or <a href="http://api.jquery.com/Types/#Number">Number</a> or <a href="http://api.jquery.com/Types/#String">String</a> or <a href="http://api.jquery.com/Types/#Object">Object</a></span> </h3> <div class="default"> <strong>Default: </strong><code>null</code> </div> <div>If and how to animate the showing of the element.</div> <strong>Multiple types supported:</strong><ul> <li> <strong>Boolean</strong>: When set to <code>false</code>, no animation will be used and the element will be shown immediately. When set to <code>true</code>, the element will fade in with the default duration and the default easing. </li> <li> <strong>Number</strong>: The element will fade in with the specified duration and the default easing. </li> <li> <strong>String</strong>: The element will be shown using the specified effect. The value can either be the name of a built-in jQuery animation method, such as <code>"slideDown"</code>, or the name of a <a href="/category/effects/">jQuery UI effect</a>, such as <code>"fold"</code>. In either case the effect will be used with the default duration and the default easing. </li> <li> <strong>Object</strong>: If the value is an object, then <code>effect</code>, <code>delay</code>, <code>duration</code>, and <code>easing</code> properties may be provided. If the <code>effect</code> property contains the name of a jQuery method, then that method will be used; otherwise it is assumed to be the name of a jQuery UI effect. When using a jQuery UI effect that supports additional settings, you may include those settings in the object and they will be passed to the effect. If <code>duration</code> or <code>easing</code> is omitted, then the default values will be used. If <code>effect</code> is omitted, then <code>"fadeIn"</code> will be used. If <code>delay</code> is omitted, then no delay is used.</li> </ul> <strong>Code examples:</strong><p>Initialize the widget with the <code>show</code> option specified:</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">".selector"</span> ).widget({ show: { effect: <span class="string">"blind"</span>, duration: <span class="number">800</span> } });</code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>Get or set the <code>show</code> option, after initialization:</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="comment">// getter</span></code></div></div><div class="container"><div class="line"><code><span class="keyword">var</span> show = $( <span class="string">".selector"</span> ).widget( <span class="string">"option"</span>, <span class="string">"show"</span> );</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code><span class="comment">// setter</span></code></div></div><div class="container"><div class="line"><code>$( <span class="string">".selector"</span> ).widget( <span class="string">"option"</span>, <span class="string">"show"</span>, { effect: <span class="string">"blind"</span>, duration: <span class="number">800</span> } );</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div></section><section id="methods"><header><h2>Methods</h2></header><div id="method-_create"><div class="api-item first-item"> <h3>_create()<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> The <code>_create()</code> method is the widget's constructor. There are no parameters, but <code>this.element</code> and <code>this.options</code> are already set. </div> <ul><li><div class="null-signature">This method does not accept any arguments.</div></li></ul> <div> <strong>Code examples:</strong><p>Set the background color of the widget's element based on an option.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>_create: <span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>.element.css( <span class="string">"background-color"</span>, <span class="keyword">this</span>.options.color );</code></div></div><div class="container"><div class="line"><code>}</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_delay"><div class="api-item"> <h3>_delay( fn [, delay ] )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#Number">Number</a></span> </h3> <div> Invokes the provided function after a specified delay. Keeps <code>this</code> context correct. Essentially <code>setTimeout()</code>. <p>Returns the timeout ID for use with <code>clearTimeout()</code>.</p> </div> <ul> <li> <div><strong>fn</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Function">Function</a>() or <a href="http://api.jquery.com/Types/#String">String</a> </div> <div>The function to invoke. Can also be the name of a method on the widget.</div> </li> <li> <div><strong>delay</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Number">Number</a> </div> <div>The number of milliseconds to wait before invoking the function. Defaults to <code>0</code>.</div> </li> </ul> <div> <strong>Code examples:</strong><p>Call the <code>_foo()</code> method on the widget after 100 milliseconds.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">this</span>._delay( <span class="keyword">this</span>._foo, <span class="number">100</span> );</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_destroy"><div class="api-item"> <h3>_destroy()<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> The public <a href="#method-destroy"><code>destroy()</code></a> method cleans up all common data, events, etc. and then delegates out to <code>_destroy()</code> for custom, widget-specific, cleanup. </div> <ul><li><div class="null-signature">This method does not accept any arguments.</div></li></ul> <div> <strong>Code examples:</strong><p>Remove a class from the widget's element when the wiget is destroyed.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>_destroy: <span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>.element.removeClass( <span class="string">"my-widget"</span> );</code></div></div><div class="container"><div class="line"><code>}</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_focusable"><div class="api-item"> <h3>_focusable( element )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> Sets up <code>element</code> to apply the <code>ui-state-focus</code> class on focus. <p>The event handlers are automatically cleaned up on destroy.</p> </div> <ul><li> <div><strong>element</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> </div> <div>The element(s) to apply the focusable behavior to.</div> </li></ul> <div> <strong>Code examples:</strong><p>Apply focusable styling to a set of elements within the widget.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">this</span>._focusable( <span class="keyword">this</span>.element.find( <span class="string">".my-items"</span> ) );</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_getCreateEventData"><div class="api-item"> <h3>_getCreateEventData()<span class="returns">Returns: <a href="http://api.jquery.com/Types/#Object">Object</a></span> </h3> <div> All widgets trigger the <a href="#event-create"><code>create</code></a> event. By default, no data is provided in the event, but this method can return an object which will be passed as the <code>create</code> event's data. </div> <ul><li><div class="null-signature">This method does not accept any arguments.</div></li></ul> <div> <strong>Code examples:</strong><p>Pass the widget's options to <code>create</code> event handlers as an argument.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>_getCreateEventData: <span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">return</span> <span class="keyword">this</span>.options;</code></div></div><div class="container"><div class="line"><code>}</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_getCreateOptions"><div class="api-item"> <h3>_getCreateOptions()<span class="returns">Returns: <a href="http://api.jquery.com/Types/#Object">Object</a></span> </h3> <div> This method allows the widget to define a custom method for defining options during instantiation. The user-provided options override the options returned by this method, which override the default options. </div> <ul><li><div class="null-signature">This method does not accept any arguments.</div></li></ul> <div> <strong>Code examples:</strong><p>Make the widget element's id attribute available as an option.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>_getCreateOptions: <span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">return</span> { id: <span class="keyword">this</span>.element.attr( <span class="string">"id"</span> ) };</code></div></div><div class="container"><div class="line"><code>}</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_hide"><div class="api-item"> <h3>_hide( element, option [, callback ] )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> Hides an element immediately, using built-in animation methods, or using custom effects. See the <a href="#option-hide">hide</a> option for possible <code>option</code> values. </div> <ul> <li> <div><strong>element</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> </div> <div>The element(s) to hide.</div> </li> <li> <div><strong>option</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Object">Object</a> </div> <div>The settings defining how to hide the element.</div> </li> <li> <div><strong>callback</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Function">Function</a>()</div> <div>Callback to invoke after the element has been fully hidden.</div> </li> </ul> <div> <strong>Code examples:</strong><p>Pass along the <code>hide</code> option for custom animations.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">this</span>._hide( <span class="keyword">this</span>.element, <span class="keyword">this</span>.options.hide, <span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code> <span class="comment">// Remove the element from the DOM when it's fully hidden.</span></code></div></div><div class="container"><div class="line"><code> $( <span class="keyword">this</span> ).remove();</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_hoverable"><div class="api-item"> <h3>_hoverable( element )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> Sets up <code>element</code> to apply the <code>ui-state-hover</code> class on hover. <p>The event handlers are automatically cleaned up on destroy.</p> </div> <ul><li> <div><strong>element</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> </div> <div>The element(s) to apply the hoverable behavior to.</div> </li></ul> <div> <strong>Code examples:</strong><p>Apply hoverable styling to all <code><div></code>s within the element on hover.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">this</span>._hoverable( <span class="keyword">this</span>.element.find( <span class="string">"div"</span> ) );</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_init"><div class="api-item"> <h3>_init()<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> Widgets have the concept of initialization that is distinct from creation. Any time the plugin is called with no arguments or with only an option hash, the widget is initialized; this includes when the widget is created. <p><em>Note: Initialization should only be handled if there is a logical action to perform on successive calls to the widget with no arguments.</em></p> </div> <ul><li><div class="null-signature">This method does not accept any arguments.</div></li></ul> <div> <strong>Code examples:</strong><p>Call the <code>open()</code> method if the <code>autoOpen</code> option is set.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>_init: <span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">if</span> ( <span class="keyword">this</span>.options.autoOpen ) {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>.open();</code></div></div><div class="container"><div class="line"><code> }</code></div></div><div class="container"><div class="line"><code>}</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_off"><div class="api-item"> <h3>_off( element, eventName )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> Unbinds event handlers from the specified element(s). </div> <ul> <li> <div><strong>element</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> </div> <div> The element(s) to unbind the event handlers from. Unlike the <code>_on()</code> method, the elements are required for <code>_off()</code>. </div> </li> <li> <div><strong>eventName</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#String">String</a> </div> <div>One or more space-separated event types.</div> </li> </ul> <div> <strong>Code examples:</strong><p>Unbind all click events from the widget's element.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">this</span>._off( <span class="keyword">this</span>.element, <span class="string">"click"</span> );</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_on"><div class="api-item"> <h3>_on( [suppressDisabledCheck ] [, element ], handlers )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> Binds event handlers to the specified element(s). Delegation is supported via selectors inside the event names, e.g., "<code>click .foo</code>". The <code>_on()</code> method provides several benefits of direct event binding: <ul> <li>Maintains proper <code>this</code> context inside the handlers.</li> <li>Automatically handles disabled widgets: If the widget is disabled or the event occurs on an element with the <code>ui-state-disabled</code> class, the event handler is not invoked. Can be overridden with the <code>suppressDisabledCheck</code> parameter.</li> <li>Event handlers are automatically namespaced and cleaned up on destroy.</li> </ul> </div> <ul> <li> <div> <strong>suppressDisabledCheck</strong> (default: <code>false</code>)</div> <div>Type: <a href="http://api.jquery.com/Types/#Boolean">Boolean</a> </div> <div>Whether or not to bypass the disabled check.</div> </li> <li> <div><strong>element</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> </div> <div>Which element(s) to bind the event handlers to. If no element is provided, <code>this.element</code> is used for non-delegated events and <a href="#method-widget">the widget element</a> is used for delegated events.</div> </li> <li> <div><strong>handlers</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Object">Object</a> </div> <div> A map in which the string keys represent the event type and optional selector for delegation, and the values represent a handler function to be called for the event. </div> </li> </ul> <div> <strong>Code examples:</strong><p>Prevent the default action of all links clicked within the widget's element.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">this</span>._on( <span class="keyword">this</span>.element, {</code></div></div><div class="container"><div class="line"><code> <span class="string">"click a"</span>: <span class="keyword">function</span>( event ) {</code></div></div><div class="container"><div class="line"><code> event.preventDefault();</code></div></div><div class="container"><div class="line"><code> }</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_setOption"><div class="api-item"> <h3>_setOption( key, value )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> Called from the <a href="#method-_setOptions"><code>_setOptions()</code></a> method for each individual option. Widget state should be updated based on changes. </div> <ul> <li> <div><strong>key</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#String">String</a> </div> <div>The name of the option to set.</div> </li> <li> <div><strong>value</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Object">Object</a> </div> <div>A value to set for the option.</div> </li> </ul> <div> <strong>Code examples:</strong><p>Update a widget's element when its <code>height</code> or <code>width</code> option changes.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> <div class="line n6">6</div> <div class="line n7">7</div> <div class="line n8">8</div> <div class="line n9">9</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>_setOption: <span class="keyword">function</span>( key, value ) {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">if</span> ( key === <span class="string">"width"</span> ) {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>.element.width( value );</code></div></div><div class="container"><div class="line"><code> }</code></div></div><div class="container"><div class="line"><code> <span class="keyword">if</span> ( key === <span class="string">"height"</span> ) {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>.element.height( value );</code></div></div><div class="container"><div class="line"><code> }</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>._super( key, value );</code></div></div><div class="container"><div class="line"><code>}</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_setOptions"><div class="api-item"> <h3>_setOptions( options )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> Called whenever the <a href="#method-option"><code>option()</code></a> method is called, regardless of the form in which the <code>option()</code> method was called. <p>Overriding this is useful if you can defer processor-intensive changes for multiple option changes.</p> </div> <ul><li> <div><strong>options</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Object">Object</a> </div> <div>A map of option-value pairs to set.</div> </li></ul> <div> <strong>Code examples:</strong><p>Call a <code>resize()</code> method if the <code>height</code> or <code>width</code> options change.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> <div class="line n6">6</div> <div class="line n7">7</div> <div class="line n8">8</div> <div class="line n9">9</div> <div class="line n10">10</div> <div class="line n11">11</div> <div class="line n12">12</div> <div class="line n13">13</div> <div class="line n14">14</div> <div class="line n15">15</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>_setOptions: <span class="keyword">function</span>( options ) {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">var</span> that = <span class="keyword">this</span>,</code></div></div><div class="container"><div class="line"><code> resize = <span class="literal">false</span>;</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code> $.each( options, <span class="keyword">function</span>( key, value ) {</code></div></div><div class="container"><div class="line"><code> that._setOption( key, value );</code></div></div><div class="container"><div class="line"><code> <span class="keyword">if</span> ( key === <span class="string">"height"</span> || key === <span class="string">"width"</span> ) {</code></div></div><div class="container"><div class="line"><code> resize = <span class="literal">true</span>;</code></div></div><div class="container"><div class="line"><code> }</code></div></div><div class="container"><div class="line"><code> });</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code> <span class="keyword">if</span> ( resize ) {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>.resize();</code></div></div><div class="container"><div class="line"><code> }</code></div></div><div class="container"><div class="line"><code>}</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_show"><div class="api-item"> <h3>_show( element, option [, callback ] )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> Shows an element immediately, using built-in animation methods, or using custom effects. See the <a href="#option-show">show</a> option for possible <code>option</code> values. </div> <ul> <li> <div><strong>element</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> </div> <div>The element(s) to show.</div> </li> <li> <div><strong>option</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Object">Object</a> </div> <div>The settings defining how to show the element.</div> </li> <li> <div><strong>callback</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Function">Function</a>()</div> <div>Callback to invoke after the element has been fully shown.</div> </li> </ul> <div> <strong>Code examples:</strong><p>Pass along the <code>show</code> option for custom animations.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">this</span>._show( <span class="keyword">this</span>.element, <span class="keyword">this</span>.options.show, <span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code> <span class="comment">// Focus the element when it's fully visible.</span></code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>.focus();</code></div></div><div class="container"><div class="line"><code>}</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_super"><div class="api-item"> <h3>_super( [arg ] [, ... ] )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> Invokes the method of the same name from the parent widget, with any specified arguments. Essentially <code>.call()</code>. </div> <ul><li> <div><strong>arg</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Object">Object</a> </div> <div> Zero to many arguments to pass to the parent widget's method. </div> </li></ul> <div> <strong>Code examples:</strong><p>Handle <code>title</code> option updates and call the parent widget's <code>_setOption()</code> to update the internal storage of the option.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> <div class="line n6">6</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>_setOption: <span class="keyword">function</span>( key, value ) {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">if</span> ( key === <span class="string">"title"</span> ) {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>.element.find( <span class="string">"h3"</span> ).text( value );</code></div></div><div class="container"><div class="line"><code> }</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>._super( key, value );</code></div></div><div class="container"><div class="line"><code>}</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_superApply"><div class="api-item"> <h3>_superApply( arguments )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> Invokes the method of the same name from the parent widget, with the array of arguments. Essentially <code>.apply()</code>. </div> <ul><li> <div><strong>arguments</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Array">Array</a> </div> <div>Array of arguments to pass to the parent method.</div> </li></ul> <div> <strong>Code examples:</strong><p>Handle <code>title</code> option updates and call the parent widget's <code>_setOption()</code> to update the internal storage of the option.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> <div class="line n6">6</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>_setOption: <span class="keyword">function</span>( key, value ) {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">if</span> ( key === <span class="string">"title"</span> ) {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>.element.find( <span class="string">"h3"</span> ).text( value );</code></div></div><div class="container"><div class="line"><code> }</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>._superApply( arguments );</code></div></div><div class="container"><div class="line"><code>}</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-_trigger"><div class="api-item"> <h3>_trigger( type [, event ] [, data ] )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#Boolean">Boolean</a></span> </h3> <div> Triggers an event and its associated callback. <p>The option with the name equal to type is invoked as the callback.</p> <p>The event name is the lowercase concatenation of the widget name and type.</p> <p><em>Note: When providing data, you must provide all three parameters. If there is no event to pass along, just pass <code>null</code>.</em></p> <p>If the default action is prevented, <code>false</code> will be returned, otherwise <code>true</code>. Preventing the default action happens when the handler returns <code>false</code> or calls <code>event.preventDefault()</code>.</p> </div> <ul> <li> <div><strong>type</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#String">String</a> </div> <div>The <code>type</code> should match the name of a callback option. The full event type will be generated automatically.</div> </li> <li> <div><strong>event</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Event">Event</a> </div> <div>The original event that caused this event to occur; useful for providing context to the listener.</div> </li> <li> <div><strong>data</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Object">Object</a> </div> <div>A hash of data associated with the event.</div> </li> </ul> <div> <strong>Code examples:</strong><p>Trigger a <code>search</code> event whenever a key is pressed.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> <div class="line n6">6</div> <div class="line n7">7</div> <div class="line n8">8</div> <div class="line n9">9</div> <div class="line n10">10</div> <div class="line n11">11</div> <div class="line n12">12</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">this</span>._on( <span class="keyword">this</span>.element, {</code></div></div><div class="container"><div class="line"><code> keydown: <span class="keyword">function</span>( event ) {</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code> <span class="comment">// Pass the original event so that the custom search event has</span></code></div></div><div class="container"><div class="line"><code> <span class="comment">// useful information, such as keyCode</span></code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>._trigger( <span class="string">"search"</span>, event, {</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code> <span class="comment">// Pass additional information unique to this event</span></code></div></div><div class="container"><div class="line"><code> value: <span class="keyword">this</span>.element.val()</code></div></div><div class="container"><div class="line"><code> });</code></div></div><div class="container"><div class="line"><code> }</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-destroy"><div class="api-item"> <h3>destroy()<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> Removes the widget functionality completely. This will return the element back to its pre-init state. </div> <ul><li><div class="null-signature">This method does not accept any arguments.</div></li></ul> <div> <strong>Code examples:</strong><p>Destroy the widget when any of its anchors are clicked.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> <div class="line n6">6</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">this</span>._on( <span class="keyword">this</span>.element, {</code></div></div><div class="container"><div class="line"><code> <span class="string">"click a"</span>: <span class="keyword">function</span>( event ) {</code></div></div><div class="container"><div class="line"><code> event.preventDefault();</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>.destroy();</code></div></div><div class="container"><div class="line"><code> }</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-disable"><div class="api-item"> <h3>disable()<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> Disables the widget. </div> <ul><li><div class="null-signature">This method does not accept any arguments.</div></li></ul> <div> <strong>Code examples:</strong><p>Disable the widget when any of its anchors are clicked.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> <div class="line n6">6</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">this</span>._on( <span class="keyword">this</span>.element, {</code></div></div><div class="container"><div class="line"><code> <span class="string">"click a"</span>: <span class="keyword">function</span>( event ) {</code></div></div><div class="container"><div class="line"><code> event.preventDefault();</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>.disable();</code></div></div><div class="container"><div class="line"><code> }</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-enable"><div class="api-item"> <h3>enable()<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div> Enables the widget. </div> <ul><li><div class="null-signature">This method does not accept any arguments.</div></li></ul> <div> <strong>Code examples:</strong><p>Enable the widget when any of its anchors are clicked.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> <div class="line n5">5</div> <div class="line n6">6</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">this</span>._on( <span class="keyword">this</span>.element, {</code></div></div><div class="container"><div class="line"><code> <span class="string">"click a"</span>: <span class="keyword">function</span>( event ) {</code></div></div><div class="container"><div class="line"><code> event.preventDefault();</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>.enable();</code></div></div><div class="container"><div class="line"><code> }</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div> <div id="method-option"> <div class="api-item"> <h3>option( optionName )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#Object">Object</a></span> </h3> <div>Gets the value currently associated with the specified <code>optionName</code>.</div> <ul><li> <div><strong>optionName</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#String">String</a> </div> <div>The name of the option to get.</div> </li></ul> <div> <strong>Code examples:</strong><p>Retrieve the value of the <code>width</code> option.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">this</span>.option( <span class="string">"width"</span> );</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div> <div class="api-item"> <h3>option()<span class="returns">Returns: <a href="http://api.jquery.com/Types/#PlainObject">PlainObject</a></span> </h3> <div>Gets an object containing key/value pairs representing the current widget options hash.</div> <ul><li><div class="null-signature">This signature does not accept any arguments.</div></li></ul> <div> <strong>Code examples:</strong><p>Log the key and value of each of the widget's options for debugging.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">var</span> options = <span class="keyword">this</span>.option();</code></div></div><div class="container"><div class="line"><code><span class="keyword">for</span> ( <span class="keyword">var</span> key <span class="keyword">in</span> options ) {</code></div></div><div class="container"><div class="line"><code> console.log( key, options[ key ] );</code></div></div><div class="container"><div class="line"><code>}</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div> <div class="api-item"> <h3>option( optionName, value )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div>Sets the value of the widget option associated with the specified <code>optionName</code>.</div> <ul> <li> <div><strong>optionName</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#String">String</a> </div> <div>The name of the option to set.</div> </li> <li> <div><strong>value</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Object">Object</a> </div> <div>A value to set for the option.</div> </li> </ul> <div> <strong>Code examples:</strong><p>Set the <code>width</code> option to <code>500</code>.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">this</span>.option( <span class="string">"width"</span>, <span class="number">500</span> );</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div> <div class="api-item"> <h3>option( options )<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a> (<a href="http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/">plugin only</a>)</span> </h3> <div>Sets one or more options for the widget.</div> <ul><li> <div><strong>options</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Object">Object</a> </div> <div>A map of option-value pairs to set.</div> </li></ul> <div> <strong>Code examples:</strong><p>Set the <code>height</code> and <code>width</code> options to <code>500</code>.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> <div class="line n4">4</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code><span class="keyword">this</span>.option({</code></div></div><div class="container"><div class="line"><code> width: <span class="number">500</span>,</code></div></div><div class="container"><div class="line"><code> height: <span class="number">500</span></code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div> </div> <div id="method-widget"><div class="api-item"> <h3>widget()<span class="returns">Returns: <a href="http://api.jquery.com/Types/#jQuery">jQuery</a></span> </h3> <div> Returns a <code>jQuery</code> object containing the original element or other relevant generated element. </div> <ul><li><div class="null-signature">This method does not accept any arguments.</div></li></ul> <div> <strong>Code examples:</strong><p>Place a red border around the widget's original element when it's created.</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>_create: <span class="keyword">function</span>() {</code></div></div><div class="container"><div class="line"><code> <span class="keyword">this</span>.widget().css( <span class="string">"border"</span>, <span class="string">"2px solid red"</span> );</code></div></div><div class="container"><div class="line"><code>}</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></div></section><section id="events"><header><h2>Events</h2></header><div id="event-create" class="api-item first-item"> <h3>create( event, ui )<span class="returns">Type: <code>widgetcreate</code></span> </h3> <div> Triggered when the widget is created. </div> <ul> <li> <div><strong>event</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Event">Event</a> </div> <div></div> </li> <li> <div><strong>ui</strong></div> <div>Type: <a href="http://api.jquery.com/Types/#Object">Object</a> </div> <div></div> </li> </ul> <p><em>Note: The <code>ui</code> object is empty but included for consistency with other events.</em></p> <div> <strong>Code examples:</strong><p>Initialize the widget with the create callback specified:</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> <div class="line n2">2</div> <div class="line n3">3</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">".selector"</span> ).widget({</code></div></div><div class="container"><div class="line"><code> create: <span class="keyword">function</span>( event, ui ) {}</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre> </td> </tr> </tbody> </table> </div> <p>Bind an event listener to the widgetcreate event:</p> <div class="syntaxhighlighter javascript nogutter"> <table> <tbody> <tr> <td class="gutter"> <div class="line n1">1</div> </td> <td class="code"> <pre><div class="container"><div class="line"><code>$( <span class="string">".selector"</span> ).on( <span class="string">"widgetcreate"</span>, <span class="keyword">function</span>( event, ui ) {} );</code></div></div></pre> </td> </tr> </tbody> </table> </div> </div> </div></section> </div></article> </body> </html> |