r3463 committed - Menu: formatting cleanup.

r3463 committed - Menu: formatting cleanup.

Revision: 3463
Author: scott.gonzalez
Date: Tue Nov 17 16:48:25 2009
Log: Menu: formatting cleanup.
http://code.google.com/p/jquery-ui/source/detail?r=3463
Modified:
/branches/dev/ui/jquery.ui.menu.js
=======================================
--- /branches/dev/ui/jquery.ui.menu.js    Mon Nov 9 07:52:42 2009
+++ /branches/dev/ui/jquery.ui.menu.js    Tue Nov 17 16:48:25 2009
@@ -15,26 +15,37 @@
$.widget("ui.menu", {
    _init: function() {
        var self = this;
-        this.element.attr("role", "menu")
-        .attr("aria-activedescendant", "ui-active-menuitem")
-        .addClass("ui-menu ui-widget ui-widget-content ui-corner-all")
-        .click(function(e) {
-            // temporary
-            e.preventDefault();
-            self.select();
-        });
-        var items = this.element.children("li");
-        items.addClass("ui-menu-item").attr("role", "menuitem")
-        .children("a").attr("tabindex", "-1").addClass("ui-corner-all")
-        // mouseenter doesn't work with event delegation
-        .mouseenter(function() {
-            self.activate($(this).parent());
-        });
+        this.element
+            .addClass("ui-menu ui-widget ui-widget-content ui-corner-all")
+            .attr({
+                role: "menu",
+                "aria-activedescendant": "ui-active-menuitem"
+            })
+            .click(function(e) {
+                // temporary
+                e.preventDefault();
+                self.select();
+            });
+        var items = this.element.children("li")
+            .addClass("ui-menu-item")
+            .attr("role", "menuitem");
+
+        items.children("a")
+            .addClass("ui-corner-all")
+            .attr("tabindex", -1)
+            // mouseenter doesn't work with event delegation
+            .mouseenter(function() {
+                self.activate($(this).parent());
+            });
    },
-
+
    activate: function(item) {
        this.deactivate();
-        this.active =
item.eq(0).children("a").addClass("ui-state-hover").attr("id", "ui-active-menuitem").end();
+        this.active = item.eq(0)
+            .children("a")
+                .addClass("ui-state-hover")
+                .attr("id", "ui-active-menuitem")
+            .end();
        this._trigger("focus", null, { item: item });
        if (this.hasScroll()) {
            var offset = item.offset().top - this.element.offset().top,
@@ -47,30 +58,32 @@
            }
        }
    },
-
+
    deactivate: function() {
-        if (!this.active)
-            return;
-        
this.active.children("a").removeClass("ui-state-hover").removeAttr("id", "ui-active-menuitem");
+        if (!this.active) { return; }
+
+        this.active.children("a")
+            .removeClass("ui-state-hover")
+            .removeAttr("id");
        this.active = null;
    },
-
+
    next: function() {
        this.move("next", "li:first");
    },
-
+
    previous: function() {
        this.move("prev", "li:last");
    },
-
+
    first: function() {
        return this.active && !this.active.prev().length;
    },
-
+
    last: function() {
        return this.active && !this.active.next().length;
    },
-
+
    move: function(direction, edge) {
        if (!this.active) {
            this.activate(this.element.children(edge));
@@ -83,7 +96,7 @@
            this.activate(this.element.children(edge));
        }
    },
-
+
    // TODO merge with previousPage
    nextPage: function() {
        if (this.hasScroll()) {
@@ -93,21 +106,23 @@
                return;
            }
            var base = this.active.offset().top,
-                height = this.element.height();
-            var result = this.element.children("li").filter(function() {
-                var close = $(this).offset().top - base - height + $(this).height();
-                // TODO improve approximation
-                return close < 10 && close > -10;
-            });
+                height = this.element.height(),
+                result = this.element.children("li").filter(function() {
+                    var close = $(this).offset().top - base - height + $(this).height();
+                    // TODO improve approximation
+                    return close < 10 && close > -10;
+                });
+
            // TODO try to catch this earlier when scrollTop indicates the last
page anyway
-            if (!result.length)
-                result = this.element.children(":last")
+            if (!result.length) {
+                result = this.element.children(":last");
+            }
            this.activate(result);
        } else {
            this.activate(this.element.children(!this.active ||
this.last() ? ":first" : ":last"));
        }
    },
-
+
    // TODO merge with nextPage
    previousPage: function() {
        if (this.hasScroll()) {
@@ -116,31 +131,32 @@
                this.activate(this.element.children(":last"));
                return;
            }
-
+
            var base = this.active.offset().top,
                height = this.element.height();
-            var result = this.element.children("li").filter(function() {
-                var close = $(this).offset().top - base + height - $(this).height();
-                // TODO improve approximation
-                return close < 10 && close > -10;
-            });
+                result = this.element.children("li").filter(function() {
+                    var close = $(this).offset().top - base + height - $(this).height();
+                    // TODO improve approximation
+                    return close < 10 && close > -10;
+                });
+
            // TODO try to catch this earlier when scrollTop indicates the last
page anyway
-            if (!result.length)
-                result = this.element.children(":first")
+            if (!result.length) {
+                result = this.element.children(":first");
+            }
            this.activate(result);
        } else {
            this.activate(this.element.children(!this.active ||
this.first() ? ":last" : ":first"));
        }
    },
-
+
    hasScroll: function() {
        return this.element.height() < this.element.attr("scrollHeight");
    },
-
+
    select: function() {
        this._trigger("selected", null, { item: this.active });
    }
-
});
})(jQuery);
--