Replace $.extend

(imported from commit 2c1ee3c2714d388f2a71398fe81c049cc54ff94d)
This commit is contained in:
Scott Feeney
2013-07-29 23:11:50 -04:00
parent 8703134a23
commit a35fff90cc
8 changed files with 38 additions and 36 deletions

View File

@@ -23,7 +23,7 @@ var console = (function () {
var reported_errors = {};
var last_report_attempt = {};
function report_error(msg, stack, opts) {
opts = $.extend({}, {show_ui_msg: false}, opts);
opts = _.extend({show_ui_msg: false}, opts);
if (stack === undefined) {
stack = 'No stacktrace available';

View File

@@ -207,7 +207,7 @@ exports.start = function (msg_type, opts) {
// Set default parameters based on the current narrowed view.
narrow.set_compose_defaults(default_opts);
opts = $.extend(default_opts, opts);
opts = _.extend(default_opts, opts);
if (!(compose.composing() === msg_type &&
((msg_type === "stream" &&
@@ -312,7 +312,7 @@ exports.snapshot_message = function (message) {
}
if (message !== undefined) {
message_snapshot = $.extend({}, message);
message_snapshot = _.extend({}, message);
} else {
// Save what we can.
message_snapshot = create_message_object();
@@ -328,14 +328,13 @@ exports.restore_message = function () {
if (!message_snapshot) {
return;
}
var snapshot_copy = $.extend({}, message_snapshot);
var snapshot_copy = _.extend({}, message_snapshot);
if ((snapshot_copy.type === "stream" &&
snapshot_copy.stream.length > 0 &&
snapshot_copy.subject.length > 0) ||
(snapshot_copy.type === "private" &&
snapshot_copy.reply_to.length > 0)) {
snapshot_copy = $.extend({replying_to_message: snapshot_copy},
snapshot_copy);
_.defaults(snapshot_copy, {replying_to_message: snapshot_copy});
}
clear_message_snapshot();
exports.unfade_messages(true);
@@ -392,7 +391,8 @@ function send_message() {
else {
respond_to_cursor = false;
if (page_params.staging) {
var new_msg = $.extend({replying_to_message: request}, request);
var new_msg = _.extend({replying_to_message: request},
request);
new_msg.content = "";
compose.start(new_msg.type, new_msg);
}

View File

@@ -1,6 +1,6 @@
/*jslint nomen: true */
function MessageList(table_name, filter, opts) {
$.extend(this, {collapse_messages: true}, opts);
_.extend(this, {collapse_messages: true}, opts);
this._items = [];
this._hash = {};
this.table_name = table_name;
@@ -93,7 +93,7 @@ MessageList.prototype = {
},
clear: function MessageList_clear(opts) {
opts = $.extend({}, {clear_selected_id: true}, opts);
opts = _.extend({clear_selected_id: true}, opts);
this._items = [];
this._hash = {};
@@ -109,7 +109,7 @@ MessageList.prototype = {
},
select_id: function MessageList_select_id(id, opts) {
opts = $.extend({
opts = _.extend({
then_scroll: false,
use_closest: false,
mark_read: true

View File

@@ -334,12 +334,12 @@ exports.activate = function (operators, opts) {
return exports.deactivate();
}
opts = $.extend({}, {
opts = _.defaults({}, opts, {
then_select_id: home_msg_list.selected_id(),
select_first_unread: false,
change_hash: true,
trigger: 'unknown'
}, opts);
});
if (opts.then_select_id === -1) {
// If we're loading the page via a narrowed URL, we may not
@@ -481,7 +481,7 @@ exports.by_subject = function (target_id, opts) {
return;
}
mark_message_as_read(original);
opts = $.extend({}, {then_select_id: target_id}, opts);
opts = _.defaults({}, opts, {then_select_id: target_id});
exports.activate([
['stream', original.stream],
['topic', original.subject]
@@ -490,7 +490,7 @@ exports.by_subject = function (target_id, opts) {
// Called for the 'narrow by stream' hotkey.
exports.by_recipient = function (target_id, opts) {
opts = $.extend({}, {then_select_id: target_id}, opts);
opts = _.defaults({}, opts, {then_select_id: target_id});
var message = current_msg_list.get(target_id);
mark_message_as_read(message);
switch (message.type) {
@@ -505,7 +505,7 @@ exports.by_recipient = function (target_id, opts) {
};
exports.by_time_travel = function (target_id, opts) {
opts = $.extend({}, {then_select_id: target_id}, opts);
opts = _.defaults({}, opts, {then_select_id: target_id});
narrow.activate([], opts);
};

View File

@@ -107,10 +107,11 @@ function do_reload_app(send_after_reload, save_state, message) {
}
exports.initiate = function (options) {
var defaults = {immediate: false,
save_state: true,
send_after_reload: false};
options = $.extend(defaults, options);
options = _.defaults({}, options, {
immediate: false,
save_state: true,
send_after_reload: false
});
if (options.immediate) {
do_reload_app(options.send_after_reload, options.save_state, options.message);

View File

@@ -152,12 +152,12 @@ var subscriptions_table_colorpicker_options = {
};
function set_colorpicker_color(colorpicker, color) {
colorpicker.spectrum($.extend(subscriptions_table_colorpicker_options,
colorpicker.spectrum(_.extend(subscriptions_table_colorpicker_options,
{color: color}));
}
function update_stream_color(stream_name, color, opts) {
opts = $.extend({}, {update_historical: false}, opts);
opts = _.defaults({}, opts, {update_historical: false});
var sub = get_sub(stream_name);
sub.color = color;
var id = parseInt(sub.id, 10);
@@ -304,13 +304,16 @@ function create_sub(stream_name, attrs) {
return sub;
}
sub = $.extend({}, {name: stream_name, id: next_sub_id++,
render_subscribers: should_render_subscribers(),
subscribed: true, in_home_view: true, invite_only: false,
notifications: false}, attrs);
if (sub.color === undefined) {
sub.color = pick_color();
}
sub = _.defaults({}, attrs, {
name: stream_name,
id: next_sub_id++,
render_subscribers: should_render_subscribers(),
subscribed: true,
in_home_view: true,
invite_only: false,
notifications: false,
color: pick_color()
});
mark_color_used(sub.color);
add_sub(stream_name, sub);
@@ -548,7 +551,7 @@ function populate_subscriptions(subs, subscribed) {
exports.reload_subscriptions = function (opts) {
var on_success;
opts = $.extend({}, {clear_first: false, custom_callbacks: false}, opts);
opts = _.defaults({}, opts, {clear_first: false, custom_callbacks: false});
if (! opts.custom_callbacks) {
on_success = function (data) {

View File

@@ -33,7 +33,7 @@ exports.set_favicon = function (url) {
};
exports.make_loading_indicator = function (outer_container, opts) {
opts = $.extend({}, opts);
opts = opts || {};
var container = outer_container;
container.empty();

View File

@@ -153,7 +153,8 @@ function keep_pointer_in_view() {
}
function recenter_view(message, opts) {
opts = $.extend({}, opts);
opts = opts || {};
// Barnowl-style recentering: if the pointer is too high, move it to
// the 1/2 marks. If the pointer is too low, move it to the 1/7 mark.
// See keep_pointer_in_view() for related logic to keep the pointer onscreen.
@@ -932,8 +933,7 @@ function get_updates_success(data) {
var get_updates_xhr;
var get_updates_timeout;
function get_updates(options) {
var defaults = {dont_block: false};
options = $.extend({}, defaults, options);
options = _.extend({dont_block: false}, options);
get_updates_params.pointer = furthest_read;
get_updates_params.dont_block = options.dont_block || get_updates_failures > 0;
@@ -1003,9 +1003,7 @@ function force_get_updates() {
}
function load_old_messages(opts) {
opts = $.extend({}, {
cont_will_add_messages: false
}, opts);
opts = _.extend({cont_will_add_messages: false}, opts);
var data = {anchor: opts.anchor,
num_before: opts.num_before,