Replace $.each with _.each

In a few cases the $.each was doing something imperatively that was
terser and easier to understand by using a different Underscore method,
so a few of these I rewrote.

Some code was using the fact that jQuery sets `this` in the callback to
be the item; I rewrote those to use an explicit parameter.

Some code was using $(some selector).each(callback). I converted these
to _.each($(some selector), callback).

One function, ui.process_condensing, was written to be a jQuery $.each
callback despite being in a totally different module from code using it.
I noticed this and updated the function's args.

(imported from commit bf5922a35f257c168cc09ec1d077415d6ef19a03)
This commit is contained in:
Scott Feeney
2013-07-29 18:35:44 -04:00
parent 5842d5c335
commit 8703134a23
24 changed files with 113 additions and 143 deletions

View File

@@ -128,7 +128,7 @@ var fake_messages = [
function disable_event_handlers() {
$('body').css({'overflow':'hidden'}); // prevents scrolling the feed
$.each(["keydown", "keyup", "keypress", "scroll"], function (idx, event_name) {
_.each(["keydown", "keyup", "keypress", "scroll"], function (event_name) {
var existing_events = $(document).data("events")[event_name];
if (existing_events === undefined) {
existing_events = [];
@@ -140,7 +140,7 @@ function disable_event_handlers() {
function enable_event_handlers() {
$('body').css({'overflow':'auto'}); // enables scrolling the feed
$.each(["keydown", "keyup", "keypress", "scroll"], function (idx, event_name) {
_.each(["keydown", "keyup", "keypress", "scroll"], function (event_name) {
$(document).data("events")[event_name] = event_handlers[event_name];
});
}
@@ -266,7 +266,7 @@ function home() {
var x = spotlight_message.offset().left;
var y = spotlight_message.offset().top;
var height = 0;
$.each(messages_in_viewport(), function (idx, row) {
_.each(messages_in_viewport(), function (row) {
height += $(row).height();
});