r3497 committed - autocompete: implemented destroy method
Revision: 3497
Author: joern.zaefferer
Date: Wed Dec 16 09:49:06 2009
Log: autocompete: implemented destroy method
http://code.google.com/p/jquery-ui/source/detail?r=3497
Modified:
/branches/dev/tests/visual/autocomplete/default.html
/branches/dev/ui/jquery.ui.autocomplete.js
=======================================
--- /branches/dev/tests/visual/autocomplete/default.html Tue Dec 15
13:13:03 2009
+++ /branches/dev/tests/visual/autocomplete/default.html Wed Dec 16
09:49:06 2009
@@ -23,25 +23,31 @@
$("#log").attr("scrollTop", 0);
}
- $("#tags").autocomplete({
- source:
["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "pearl"],
- delay: 0,
- search: function() {
- log("Searching for: " + this.value);
- },
- open: function() {
- log("Found something");
- },
- focus: function(event, ui) {
- log("Moving focus to " + ui.item.label);
- },
- close: function() {
- log("Hiding suggestions");
- },
- change: function(event, ui) {
- log(ui.item ? ("Selected: " + ui.item.result) : "Nothing selected,
input was " + this.value);
- }
- });
+ function enable() {
+ $("#tags").autocomplete({
+ source:
["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "pearl"],
+ delay: 0,
+ search: function() {
+ log("Searching for: " + this.value);
+ },
+ open: function() {
+ log("Found something");
+ },
+ focus: function(event, ui) {
+ log("Moving focus to " + ui.item.label);
+ },
+ close: function() {
+ log("Hiding suggestions");
+ },
+ change: function(event, ui) {
+ log(ui.item ? ("Selected: " + ui.item.result) : "Nothing selected,
input was " + this.value);
+ }
+ });
+ }
+ enable();
+ $("#toggle").toggle(function() {
+ $("#tags").autocomplete("destroy");
+ }, enable);
});
</script>
</head>
@@ -57,5 +63,7 @@
<div id="log" style="height: 400px; width: 300px; overflow: auto;"
class="ui-widget-content"></div>
</div>
+<button id="toggle">Toggle widget</button>
+
</body>
</html>
=======================================
--- /branches/dev/ui/jquery.ui.autocomplete.js Tue Dec 15 13:13:03 2009
+++ /branches/dev/ui/jquery.ui.autocomplete.js Wed Dec 16 09:49:06 2009
@@ -68,10 +68,10 @@
break;
}
})
- .focus(function() {
+ .bind("focus.autocomplete", function() {
self.previous = self.element.val();
})
- .blur(function() {
+ .bind("blur.autocomplete", function() {
clearTimeout(self.searching);
// clicks on the menu (or a button to trigger a search) will cause a
blur event
// TODO try to implement this without a timeout, see clearTimeout in
search()
@@ -84,7 +84,14 @@
},
destroy: function() {
- // TODO implement
+ this.element
+ .unbind(".autocomplete")
+ .removeClass("ui-autocomplete")
+ .removeAttr("autocomplete")
+ .removeAttr("role")
+ .removeAttr("aria-autocomplete")
+ .removeAttr("aria-haspopup");
+ $.widget.prototype.destroy.call(this);
},
// TODO call when source-option is updated
--