r937 - in branches/experimental: tests ui

r937 - in branches/experimental: tests ui


Author: joern.zaefferer
Date: Fri Nov 14 06:29:21 2008
New Revision: 937
Modified:
branches/experimental/tests/autocomplete.js
branches/experimental/ui/ui.autocomplete.js
Log:
autocomplete: added tests for #3581 and fixed it: user specified values for
delay and max are now always preferred over "intelligent" defaults
Modified: branches/experimental/tests/autocomplete.js
==============================================================================
--- branches/experimental/tests/autocomplete.js    (original)
+++ branches/experimental/tests/autocomplete.js    Fri Nov 14 06:29:21 2008
@@ -1,7 +1,7 @@
test("init", function() {
    expect(6);
-    el = $("#autocomplete").autocomplete();
+    var el = $("#autocomplete").autocomplete();
    ok(true, '.autocomplete() called on element');
    $([]).autocomplete();
@@ -45,7 +45,7 @@
test("re-attach", function() {
    expect(2);
-    el =
$("#autocomplete").autocomplete().autocomplete("destroy").autocomplete();
+    var el =
$("#autocomplete").autocomplete().autocomplete("destroy").autocomplete();
    ok(true, '.autocomplete().autocomplete("destroy").autocomplete() called
on element');
    $('<input
id="autocomplete_dis">').autocomplete().autocomplete("destroy").autocomplete().remove();
@@ -68,7 +68,7 @@
test("defaults", function() {
    expect(19);
-    el = $("#autocomplete").autocomplete();
+    var el = $("#autocomplete").autocomplete();
    var formatItem = function (row) { return row[0]; }.toString();
    var highlight = function (value, term) { return value.replace(new
RegExp("(?![^&;]+;)(?!<[^<>]*)(" +
term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1")
+ ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"); }.toString();
@@ -92,6 +92,35 @@
    equals(el.data("highlight.autocomplete"), highlight, "highlight");
    equals(el.data("scroll.autocomplete"), true, "scroll");
    equals(el.data("scrollHeight.autocomplete"), 180, "scrollHeight");
+});
+
+test("defaults with url and no scroll", function() {
+    el = $("#autocomplete").autocomplete({
+        url: "xxx",
+        scroll: false
+    });
+    equals(el.data("delay.autocomplete"), 400, "longer delay when url is
specified");
+    equals(el.data("max.autocomplete"), 10, "smaller max when scrolling is
disabled");
+});
+
+test("defaults with custom delay and max", function() {
+    el = $("#autocomplete").autocomplete({
+        delay: 50,
+        max: 30
+    });
+    equals(el.data("delay.autocomplete"), 50, "custom delay");
+    equals(el.data("max.autocomplete"), 30, "custom max");
+});
+
+test("defaults with custom delay and max and url and no scroll",
function() {
+    el = $("#autocomplete").autocomplete({
+        delay: 50,
+        url: "xxx",
+        scroll: false,
+        max: 30
+    });
+    equals(el.data("delay.autocomplete"), 50, "custom delay");
+    equals(el.data("max.autocomplete"), 30, "custom max");
});
test("set defaults on init", function() {
Modified: branches/experimental/ui/ui.autocomplete.js
==============================================================================
--- branches/experimental/ui/ui.autocomplete.js    (original)
+++ branches/experimental/ui/ui.autocomplete.js    Fri Nov 14 06:29:21 2008
@@ -15,10 +15,9 @@
$.widget("ui.autocomplete", {
    
    _init: function() {
-        
        $.extend(this.options, {
-            delay: this.options.url ? this.options.delay : 10,
-            max: !this.options.scroll ? 10 : 150,
+            delay: this.options.delay != undefined ? this.options.delay :
(this.options.url? this.options.ajaxDelay : this.options.localDelay),
+            max: this.options.max != undefined ? this.options.max :
(this.options.scroll? this.options.scrollMax : this.options.noScrollMax),
            highlight: this.options.highlight || function(value) { return value; },
// if highlight is set to false, replace it with a do-nothing function
            formatMatch: this.options.formatMatch || this.options.formatItem // if
the formatMatch option is not specified, then use formatItem for backwards
compatibility
        });
@@ -406,12 +405,14 @@
        resultsClass: "ui-autocomplete-results",
        loadingClass: "ui-autocomplete-loading",
        minChars: 1,
-        delay: 400,
+        ajaxDelay: 400,
+        localDelay: 10,
        matchCase: false,
        matchSubset: true,
        matchContains: false,
        cacheLength: 10,
-        max: 100,
+        scrollMax: 150,
+        noScrollMax: 10,
        mustMatch: false,
        extraParams: {},
        selectFirst: true,