From 1c802475ea8051202c0cfd71f6237e43ac7f50df Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Mon, 29 Jul 2013 23:13:28 -0700 Subject: [PATCH] cleanup data_as_a_function code --- src/EventManager.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/EventManager.js b/src/EventManager.js index e05ca9c..a171a39 100644 --- a/src/EventManager.js +++ b/src/EventManager.js @@ -136,13 +136,22 @@ function EventManager(options, _sources) { var success = source.success; var error = source.error; var complete = source.complete; - var custom_data; + + // retrieve any outbound GET/POST $.ajax data from the options + var customData; if ($.isFunction(source.data)) { - custom_data = source.data(); - } else { - custom_data = source.data; + // supplied as a function that returns a key/value object + customData = source.data(); } - var data = $.extend({}, custom_data || {}); + else { + // supplied as a straight key/value object + customData = source.data; + } + + // use a copy of the custom data so we can modify the parameters + // and not affect the passed-in object. + var data = $.extend({}, customData || {}); + var startParam = firstDefined(source.startParam, options.startParam); var endParam = firstDefined(source.endParam, options.endParam); if (startParam) { @@ -151,6 +160,7 @@ function EventManager(options, _sources) { if (endParam) { data[endParam] = Math.round(+rangeEnd / 1000); } + pushLoading(); $.ajax($.extend({}, ajaxDefaults, source, { data: data,