Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __d("AsyncRequest", ["array-extensions", "event-extensions", "json", "Arbiter", "AsyncDOM", "AsyncResponse", "bootloader", "Cookie", "css-core", "dom", "Env", "JSCC", "Parent", "URI", "Util", "bind", "copyProperties", "evalGlobal", "goURI", "invokeCallbacks", "isEmpty"], function (global, require, requireLazy, module, exports) {
- require("array-extensions");
- require("event-extensions");
- require("json");
- var Arbiter = require("Arbiter");
- var AsyncDOM = require("AsyncDOM");
- var AsyncResponse = require("AsyncResponse");
- var Bootloader = require("bootloader");
- var Cookie = require("Cookie");
- var CSS = require("css-core");
- var DOM = require("dom");
- var Env = require("Env");
- var JSCC = require("JSCC");
- var Parent = require("Parent");
- var URI = require("URI");
- var Util = require("Util");
- var bind = require("bind");
- var copyProperties = require("copyProperties");
- var evalGlobal = require("evalGlobal");
- var goURI = require("goURI");
- var invokeCallbacks = require("invokeCallbacks");
- var isEmpty = require("isEmpty");
- function AsyncRequest(uri) {
- var dispatchResponse = bind(this, function (asyncResponse) {
- try {
- this.clearStatusIndicator();
- if (!this.isRelevant()) {
- invokeErrorHandler(1010);
- return;
- }
- if (this.initialHandler(asyncResponse) !== false) {
- clearTimeout(this.timer);
- if (asyncResponse.jscc_map) {
- var jscc_map = eval(asyncResponse.jscc_map);
- JSCC.init(jscc_map);
- }
- if (this.handler) try {
- var suppress_onload = this.handler(asyncResponse);
- } catch (exception) {
- asyncResponse.is_last && this.finallyHandler(asyncResponse);
- throw exception;
- }
- if (suppress_onload !== AsyncRequest.suppressOnloadToken) {
- var domOps = asyncResponse.domops;
- if (domOps) AsyncDOM.invoke(domOps, this.getRelativeTo());
- asyncResponse.jscalls && invokeCallbacks([asyncResponse.jscalls]);
- var onload = asyncResponse.onload;
- if (onload) for (var ii = 0; ii < onload.length; ii++) try {
- (new Function(onload[ii])).apply(this);
- } catch (exception) {}
- if (this.lid) Arbiter.inform('tti_ajax', {
- s: this.lid,
- d: [this._sendTimeStamp || 0, (this._sendTimeStamp && this._responseTime) ? (this._responseTime - this._sendTimeStamp) : 0]
- }, Arbiter.BEHAVIOR_EVENT);
- var onafterload = asyncResponse.onafterload;
- if (onafterload) for (var ii = 0; ii < onafterload.length; ii++) try {
- (new Function(onafterload[ii])).apply(this);
- } catch (exception) {}
- }
- asyncResponse.is_last && this.finallyHandler(asyncResponse);
- }
- } catch (exception) {}
- });
- var dispatchErrorResponse = bind(this, function (asyncResponse, isTransport) {
- try {
- this.clearStatusIndicator();
- var async_error = asyncResponse.getError();
- if (this._sendTimeStamp) {
- var _duration = Date.now() - this._sendTimeStamp;
- var xfb_ip = this._xFbServer || '-';
- asyncResponse.logError('async_error', {
- duration: _duration,
- xfb_ip: xfb_ip
- });
- } else asyncResponse.logError('async_error');
- if ((!this.isRelevant()) || async_error === 1010) return;
- if (async_error == 1357008 || async_error == 1357007 || async_error == 1442002 || async_error == 1357001) {
- var is_confirmation = false;
- if (async_error == 1357008 || async_error == 1357007) is_confirmation = true;
- var payload = asyncResponse.getPayload();
- this._displayServerDialog(payload.__dialog, is_confirmation);
- } else if (this.initialHandler(asyncResponse) !== false) {
- clearTimeout(this.timer);
- try {
- if (isTransport) {
- this.transportErrorHandler(asyncResponse);
- } else this.errorHandler(asyncResponse);
- } catch (exception) {
- this.finallyHandler(asyncResponse);
- throw exception;
- }
- this.finallyHandler(asyncResponse);
- }
- } catch (exception) {}
- });
- var _interpretTransportResponse = bind(this, function () {
- if (this.getOption('suppressEvaluation')) {
- var r = new AsyncResponse(this, this.transport);
- return {
- asyncResponse: r
- };
- }
- var _sendError = function (p, error_code, str) {
- if (!window.send_error_signal) return;
- if (this._xFbServer) {
- error_code = '1008_' + error_code;
- } else error_code = '1012_' + error_code;
- send_error_signal('async_xport_resp', error_code + ':' + (this._xFbServer || '-') + ':' + p.getURI() + ':' + str.length + ':' + str.substr(0, 1600));
- };
- var shield = "for (;;);";
- var shieldlen = shield.length;
- var text = this.transport.responseText;
- if (text.length <= shieldlen) {
- _sendError(this, 'empty', text);
- return {
- transportError: 'Response too short on async to ' + this.getURI()
- };
- }
- var offset = 0;
- while (text.charAt(offset) == " " || text.charAt(offset) == "\n") offset++;
- offset && text.substring(offset, offset + shieldlen) == shield;
- var safeResponse = text.substring(offset + shieldlen);
- try {
- var response = eval('(' + safeResponse + ')');
- } catch (exception) {
- _sendError(this, 'excep', text);
- return {
- transportError: 'eval() failed on async to ' + this.getURI()
- };
- }
- return interpretResponse(response);
- });
- var interpretResponse = bind(this, function (response) {
- if (response.redirect) return {
- redirect: response.redirect
- };
- var r = new AsyncResponse(this);
- if (response.__ar != 1) {
- r.payload = response;
- } else {
- copyProperties(r, response);
- if (response.tplts) if (window.DynaTemplate) DynaTemplate.registerTemplates(response.tplts);
- }
- return {
- asyncResponse: r
- };
- });
- var invokeResponseHandler = bind(this, function (interp) {
- if (typeof (interp.redirect) != 'undefined') {
- (function () {
- this.setURI(interp.redirect).send();
- }).bind(this).defer();
- return;
- }
- if (this.handler || this.errorHandler || this.transportErrorHandler) if (typeof (interp.asyncResponse) != 'undefined') {
- var r = interp.asyncResponse;
- if (!this.isRelevant()) {
- invokeErrorHandler(1010);
- return;
- }
- if (r.inlinejs) evalGlobal(r.inlinejs);
- if (r.lid) {
- this._responseTime = Date.now();
- if (window.CavalryLogger) this.cavalry = CavalryLogger.getInstance(r.lid);
- this.lid = r.lid;
- }
- if (r.getError() && !r.getErrorIsWarning()) {
- var fn = dispatchErrorResponse;
- } else var fn = dispatchResponse;
- Bootloader.setResourceMap(r.resource_map);
- if (r.bootloadable) Bootloader.enableBootload(r.bootloadable);
- fn = fn.shield(null, r);
- fn = fn.defer.bind(fn);
- var is_transitional = false;
- if (this.preBootloadHandler) is_transitional = this.preBootloadHandler(r);
- r.css = r.css || [];
- r.js = r.js || [];
- Bootloader.loadResources(r.css.concat(r.js), fn, is_transitional, this.getURI());
- } else if (typeof (interp.transportError) != 'undefined') {
- if (this._xFbServer) {
- invokeErrorHandler(1008);
- } else invokeErrorHandler(1012);
- } else invokeErrorHandler(1007);
- });
- var invokeErrorHandler = bind(this, function (explicitError) {
- try {
- if (!window.loaded && !this.getOption('handleErrorAfterUnload')) return;
- } catch (ex) {
- return;
- }
- var r = new AsyncResponse(this);
- var err;
- try {
- err = explicitError || this.transport.status || 1004;
- } catch (ex) {
- err = 1005;
- }
- if (this._requestAborted) err = 1011;
- try {
- if (this.responseText == '') err = 1002;
- } catch (ignore) {}
- if (this.transportErrorHandler) {
- var desc, summary;
- var silent = true;
- if (false === navigator.onLine) {
- summary = "No network connection";
- desc = "Your browser appears to be offline. Please check your Internet connection and try again.";
- err = 1006;
- } else if (err >= 300 && err <= 399) {
- summary = "Redirection";
- desc = "Your access to Facebook was redirected or blocked by a third party at this time, please contact your ISP or reload. ";
- redir_url = this.transport.getResponseHeader("Location");
- if (redir_url) goURI(redir_url, true);
- silent = true;
- } else {
- summary = "Oops!";
- desc = "Something went wrong. We're working on getting this fixed as soon as we can. You may be able to try again.";
- }!this.getOption('suppressErrorAlerts');
- copyProperties(r, {
- error: err,
- errorSummary: summary,
- errorDescription: desc,
- silentError: silent
- });
- dispatchErrorResponse(r, true);
- }
- });
- var handleResponse = function (response) {
- var asyncResponse = this.interpretResponse(response);
- this.invokeResponseHandler(asyncResponse);
- };
- var onStateChange = function () {
- try {
- if (this.transport.readyState == 4) {
- AsyncRequest._inflightPurge();
- try {
- if (typeof (this.transport.getResponseHeader) != 'undefined' && this.transport.getResponseHeader('X-FB-Debug')) this._xFbServer = this.transport.getResponseHeader('X-FB-Debug');
- } catch (ex) {}
- if (this.transport.status >= 200 && this.transport.status < 300) {
- AsyncRequest.lastSuccessTime = Date.now();
- invokeResponseHandler(_interpretTransportResponse());
- } else if (ua.safari() && (typeof (this.transport.status) == 'undefined')) {
- invokeErrorHandler(1002);
- } else if (window.Env && window.Env.retry_ajax_on_network_error && this.transport.status in {
- 0: 1,
- 12029: 1,
- 12030: 1,
- 12031: 1,
- 12152: 1
- } && this.remainingRetries > 0) {
- --this.remainingRetries;
- delete this.transport;
- this.send(true);
- return;
- } else invokeErrorHandler();
- if (this.getOption('asynchronous') !== false) delete this.transport;
- }
- } catch (exception) {
- try {
- if (!window.loaded) return;
- } catch (ex) {
- return;
- }
- delete this.transport;
- if (this.remainingRetries > 0) {
- --this.remainingRetries;
- this.send(true);
- } else {
- !this.getOption('suppressErrorAlerts');
- if (window.send_error_signal) send_error_signal('async_xport_resp', '1007:' + (this._xFbServer || '-') + ':' + this.getURI() + ':' + exception.message);
- invokeErrorHandler(1007);
- }
- }
- };
- var onJSONPResponse = function (data, more_chunked_response) {
- var is_first = (this.is_first === undefined);
- this.is_first = is_first;
- if (this.transportIframe && !more_chunked_response) {
- if (this.cavalry) this.cavalry.collectBrowserTiming(this.transportIframe.contentWindow);
- (function (x) {
- document.body.removeChild(x);
- }).bind(null, this.transportIframe).defer();
- }
- if (ua.ie() >= 9 && window.JSON) data = window.JSON.parse(window.JSON.stringify(data));
- var r = this.interpretResponse(data);
- r.asyncResponse.is_first = is_first;
- r.asyncResponse.is_last = !more_chunked_response;
- this.invokeResponseHandler(r);
- return more_chunked_response;
- };
- copyProperties(this, {
- onstatechange: onStateChange,
- onjsonpresponse: onJSONPResponse,
- invokeResponseHandler: invokeResponseHandler,
- interpretResponse: interpretResponse,
- handleResponse: handleResponse,
- transport: null,
- method: 'POST',
- uri: '',
- timeout: null,
- timer: null,
- initialHandler: bagofholding,
- handler: null,
- errorHandler: null,
- transportErrorHandler: null,
- timeoutHandler: null,
- finallyHandler: bagofholding,
- serverDialogCancelHandler: bagofholding,
- relativeTo: null,
- statusElement: null,
- statusClass: '',
- data: {},
- file: null,
- context: {},
- readOnly: false,
- writeRequiredParams: ['post_form_id'],
- remainingRetries: 0,
- option: {
- asynchronous: true,
- suppressErrorHandlerWarning: false,
- suppressEvaluation: false,
- suppressErrorAlerts: false,
- retries: 0,
- jsonp: false,
- bundle: false,
- useIframeTransport: false,
- tfbEndpoint: true,
- handleErrorAfterUnload: false
- },
- userActionID: '-'
- });
- this.errorHandler = AsyncResponse.defaultErrorHandler;
- this.transportErrorHandler = bind(this, 'errorHandler');
- if (uri != undefined) this.setURI(uri);
- return this;
- }
- Arbiter.subscribe("page_transition", function (type, message) {
- AsyncRequest._id_threshold = message.id;
- });
- copyProperties(AsyncRequest, {
- receiveJSONPResponse: function (id, data, more_chunked_response) {
- if (this._JSONPReceivers[id]) {
- if (!this._JSONPReceivers[id](data, more_chunked_response)) delete this._JSONPReceivers[id];
- } else if (window.logJSError && !more_chunked_response) {
- var uri = (data.payload && data.payload.uri) || '';
- logJSError('ajax', {
- error: 'UnexpectedJsonResponse',
- extra: {
- id: id,
- uri: uri
- }
- });
- }
- },
- _bundleRequest: function (request) {
- if (request.getOption('jsonp') || request.getOption('useIframeTransport')) {
- request.setOption('bundle', false);
- return false;
- } else if (!request.uri.isFacebookURI()) {
- request.setOption('bundle', false);
- return false;
- } else if (!request.getOption('asynchronous')) {
- request.setOption('bundle', false);
- return false;
- }
- var path = request.uri.getPath();
- if (!AsyncRequest._bundleTimer) AsyncRequest._bundleTimer = setTimeout(function () {
- AsyncRequest._sendBundledRequests();
- }, 0);
- AsyncRequest._allBundledRequests.push([path, request]);
- return true;
- },
- _sendBundledRequests: function () {
- clearTimeout(AsyncRequest._bundleTimer);
- AsyncRequest._bundleTimer = null;
- var bundled_requests = AsyncRequest._allBundledRequests;
- AsyncRequest._allBundledRequests = [];
- if (bundled_requests.length == 1) {
- var request = bundled_requests[0][1];
- request.setOption('bundle', false).send();
- return request;
- }
- if (bundled_requests.length === 0) return null;
- var data = [];
- for (var ii = 0; ii < bundled_requests.length; ii++) data.push([bundled_requests[ii][0], URI.implodeQuery(bundled_requests[ii][1].data)]);
- var query_data = {
- data: data
- };
- var request = new AsyncRequest();
- request.setURI('/ajax/proxy.php').setData(query_data).setMethod('POST').setInitialHandler(bagof(true)).setAllowCrossPageTransition(true).setHandler(function (r) {
- var payload = r.getPayload();
- var responses = payload.responses;
- if (responses.length != bundled_requests.length) {
- return;
- } else for (var ii = 0; ii < bundled_requests.length; ii++) {
- var path = bundled_requests[ii][0];
- var request = bundled_requests[ii][1];
- request.id = this.id;
- if (responses[ii][0] != path) {
- request.invokeResponseHandler({
- transportError: 'Wrong response order in bundled request to ' + path
- });
- continue;
- }
- var asyncResponse = request.interpretResponse(responses[ii][1]);
- request.invokeResponseHandler(asyncResponse);
- }
- }).setTransportErrorHandler(function (response) {
- var paths = [];
- var interp = {
- transportError: response.errorDescription
- };
- for (var ii = 0; ii < bundled_requests.length; ii++) {
- var path = bundled_requests[ii][0];
- var request = bundled_requests[ii][1];
- paths.push(path);
- request.id = this.id;
- request.invokeResponseHandler(interp);
- }
- }).send();
- return request;
- },
- bootstrap: function (href, elem, is_post) {
- var method = 'GET';
- var readonly = true;
- var data = {};
- if (is_post || elem && (elem.rel == 'async-post' || elem.getAttribute && elem.getAttribute('forcemethod') == 'post')) {
- method = 'POST';
- readonly = false;
- if (href) {
- href = URI(href);
- data = href.getQueryData();
- href.setQueryData({});
- }
- }
- var status_elem = Parent.byClass(elem, 'stat_elem') || elem;
- if (status_elem && CSS.hasClass(status_elem, 'async_saving')) return false;
- var async = new AsyncRequest(href).setReadOnly(readonly).setMethod(method).setData(data).setNectarModuleDataSafe(elem).setRelativeTo(elem).setHandler(function (response) {
- Event.fire(elem, 'success', {
- response: response
- });
- }).setErrorHandler(function (response) {
- if (Event.fire(elem, 'error', {
- response: response
- }) !== false) AsyncResponse.defaultErrorHandler(response);
- });
- if (status_elem) {
- async.setStatusElement(status_elem);
- var status_class = status_elem.getAttribute('data-status-class');
- status_class && async.setStatusClass(status_class);
- }
- async.send();
- return false;
- },
- post: function (href, data) {
- new AsyncRequest(href).setReadOnly(false).setMethod('POST').setData(data).send();
- return false;
- },
- getLastId: function () {
- return AsyncRequest._last_id;
- },
- _JSONPReceivers: {},
- _allBundledRequests: [],
- _bundleTimer: null,
- suppressOnloadToken: {},
- _last_id: 2,
- _id_threshold: 2,
- _inflight: [],
- _inflightAdd: bagofholding,
- _inflightPurge: bagofholding,
- _inflightEnable: function () {
- if (ua.ie()) {
- copyProperties(AsyncRequest, {
- _inflightAdd: function (ar) {
- this._inflight.push(ar);
- },
- _inflightPurge: function () {
- AsyncRequest._inflight = AsyncRequest._inflight.filter(function (ar) {
- return ar.transport && ar.transport.readyState < 4;
- });
- }
- });
- onunloadRegister(function () {
- AsyncRequest._inflight.each(function (ar) {
- if (ar.transport && ar.transport.readyState < 4) {
- ar.transport.abort();
- delete ar.transport;
- }
- });
- });
- }
- }
- });
- copyProperties(AsyncRequest.prototype, {
- setMethod: function (m) {
- this.method = m.toString().toUpperCase();
- return this;
- },
- getMethod: function () {
- return this.method;
- },
- setData: function (obj) {
- this.data = obj;
- return this;
- },
- _setDataHash: function () {
- if (this.method != 'POST' || !this.getOption('tfbEndpoint') || this.data.phstamp) return;
- var input_len = URI.implodeQuery(this.data).length;
- var numeric_csrf_value = '';
- for (var ii = 0; ii < this.data.fb_dtsg.length; ii++) numeric_csrf_value += this.data.fb_dtsg.charCodeAt(ii);
- this.data.phstamp = '1' + numeric_csrf_value + input_len;
- },
- setFile: function (file) {
- this.file = file;
- return this;
- },
- getData: function () {
- return this.data;
- },
- setContextData: function (key, value, enabled) {
- enabled = enabled === undefined ? true : enabled;
- if (enabled) this.context['_log_' + key] = value;
- return this;
- },
- _setUserActionID: function () {
- var ue = window.ArbiterMonitor && ArbiterMonitor.getUE() || '-';
- this.userActionID = (window.EagleEye && EagleEye.getSessionID() || '-') + '/' + ue;
- },
- setURI: function (uri) {
- var uri_obj = URI(uri);
- if (this.getOption('useIframeTransport') && !uri_obj.isFacebookURI()) return this;
- if (!this.getOption('jsonp') && !this.getOption('useIframeTransport') && !uri_obj.isSameOrigin()) return this;
- this._setUserActionID();
- if (!uri || uri_obj.isEmpty()) {
- if (window.send_error_signal && window.get_error_stack) {
- var data = {
- err_code: 1013,
- vip: '-',
- duration: 0,
- xfb_ip: '-',
- path: window.location.href,
- aid: this.userActionID
- };
- send_error_signal('async_error', JSON.stringify(data));
- send_error_signal('async_xport_stack', '1013:' + window.location.href + '::' + get_error_stack());
- }
- return this;
- }
- this.uri = uri_obj;
- return this;
- },
- getURI: function () {
- return this.uri.toString();
- },
- setInitialHandler: function (fn) {
- this.initialHandler = fn;
- return this;
- },
- setHandler: function (fn) {
- if (!(typeof (fn) != 'function')) this.handler = fn;
- return this;
- },
- getHandler: function () {
- return this.handler;
- },
- setErrorHandler: function (fn) {
- if (!(typeof (fn) != 'function')) this.errorHandler = fn;
- return this;
- },
- setTransportErrorHandler: function (fn) {
- this.transportErrorHandler = fn;
- return this;
- },
- getErrorHandler: function () {
- return this.errorHandler;
- },
- getTransportErrorHandler: function () {
- return this.transportErrorHandler;
- },
- setTimeoutHandler: function (timeout, fn) {
- if (!(typeof (fn) != 'function')) {
- this.timeout = timeout;
- this.timeoutHandler = fn;
- }
- return this;
- },
- resetTimeout: function (timeout) {
- if (!(this.timeoutHandler === null)) if (timeout === null) {
- this.timeout = null;
- clearTimeout(this.timer);
- this.timer = null;
- } else {
- var clear_on_quickling_event = !this._allowCrossPageTransition;
- this.timeout = timeout;
- clearTimeout(this.timer);
- this.timer = this._handleTimeout.bind(this).defer(this.timeout, clear_on_quickling_event);
- }
- return this;
- },
- _handleTimeout: function () {
- this.abandon();
- this.timeoutHandler(this);
- },
- setNewSerial: function () {
- this.id = ++AsyncRequest._last_id;
- return this;
- },
- setFinallyHandler: function (fn) {
- this.finallyHandler = fn;
- return this;
- },
- setServerDialogCancelHandler: function (fn) {
- this.serverDialogCancelHandler = fn;
- return this;
- },
- setPreBootloadHandler: function (fn) {
- this.preBootloadHandler = fn;
- return this;
- },
- setReadOnly: function (readOnly) {
- if (!(typeof (readOnly) != 'boolean')) this.readOnly = readOnly;
- return this;
- },
- setFBMLForm: function () {
- this.writeRequiredParams = ["fb_sig"];
- return this;
- },
- getReadOnly: function () {
- return this.readOnly;
- },
- setRelativeTo: function (element) {
- this.relativeTo = element;
- return this;
- },
- getRelativeTo: function () {
- return this.relativeTo;
- },
- setStatusClass: function (c) {
- this.statusClass = c;
- return this;
- },
- setStatusElement: function (element) {
- this.statusElement = element;
- return this;
- },
- getStatusElement: function () {
- return ge(this.statusElement);
- },
- isRelevant: function () {
- if (this._allowCrossPageTransition) return true;
- if (!this.id) return true;
- return this.id > AsyncRequest._id_threshold;
- },
- clearStatusIndicator: function () {
- var statusElem = this.getStatusElement();
- if (statusElem) {
- CSS.removeClass(statusElem, 'async_saving');
- CSS.removeClass(statusElem, this.statusClass);
- }
- },
- addStatusIndicator: function () {
- var statusElem = this.getStatusElement();
- if (statusElem) {
- CSS.addClass(statusElem, 'async_saving');
- CSS.addClass(statusElem, this.statusClass);
- }
- },
- specifiesWriteRequiredParams: function () {
- return this.writeRequiredParams.every(function (param) {
- this.data[param] = this.data[param] || Env[param] || (ge(param) || {}).value;
- if (this.data[param] !== undefined) return true;
- return false;
- }, this);
- },
- setOption: function (opt, v) {
- if (typeof (this.option[opt]) != 'undefined') this.option[opt] = v;
- return this;
- },
- getOption: function (opt) {
- typeof (this.option[opt]) == 'undefined';
- return this.option[opt];
- },
- abort: function () {
- if (this.transport) {
- var old_handler = this.getTransportErrorHandler();
- this.setOption('suppressErrorAlerts', true);
- this.setTransportErrorHandler(bagofholding);
- this._requestAborted = 1;
- this.transport.abort();
- this.setTransportErrorHandler(old_handler);
- }
- },
- abandon: function () {
- clearTimeout(this.timer);
- this.setOption('suppressErrorAlerts', true).setHandler(bagofholding).setErrorHandler(bagofholding).setTransportErrorHandler(bagofholding);
- if (this.transport) {
- this._requestAborted = 1;
- this.transport.abort();
- }
- },
- setNectarData: function (nctrParams) {
- if (nctrParams) {
- if (this.data.nctr === undefined) this.data.nctr = {};
- copyProperties(this.data.nctr, nctrParams);
- }
- return this;
- },
- setNectarModuleDataSafe: function (elem) {
- if (this.setNectarModuleData) this.setNectarModuleData(elem);
- return this;
- },
- setNectarImpressionIdSafe: function () {
- if (this.setNectarImpressionId) this.setNectarImpressionId();
- return this;
- },
- setAllowCrossPageTransition: function (allow) {
- this._allowCrossPageTransition = !! allow;
- if (this.timer) this.resetTimeout(this.timeout);
- return this;
- },
- send: function (isRetry) {
- isRetry = isRetry || false;
- if (!this.uri) return false;
- !this.errorHandler && !this.getOption('suppressErrorHandlerWarning');
- if (this.getOption('jsonp') && this.method != 'GET') this.setMethod('GET');
- if (this.getOption('useIframeTransport') && this.method != 'GET') this.setMethod('GET');
- this.timeoutHandler !== null && (this.getOption('jsonp') || this.getOption('useIframeTransport'));
- if (!this.getReadOnly()) {
- this.specifiesWriteRequiredParams();
- if (this.method != 'POST') return false;
- }
- if (this.method == 'POST' && this.getOption('tfbEndpoint')) {
- this.data.fb_dtsg = Env.fb_dtsg;
- this.data.lsd = Cookie.get('lsd');
- }
- if (!isEmpty(this.context) && this.getOption('tfbEndpoint')) {
- copyProperties(this.data, this.context);
- this.data.ajax_log = 1;
- }
- if (window.Env && Env.force_param) copyProperties(this.data, Env.force_param);
- if (!this.getReadOnly() && this.getOption('tfbEndpoint') && this.method == 'POST' && this.data.post_form_id_source === undefined) this.data.post_form_id_source = 'AsyncRequest';
- if (window.Env) this.data.__user = Env.user;
- this._setUserActionID();
- if (this.getOption('bundle') && AsyncRequest._bundleRequest(this)) return true;
- this.setNewSerial();
- if (this.getOption('tfbEndpoint')) {
- this.uri.addQueryData({
- __a: 1
- });
- if (!this.getOption('asynchronous')) this.uri.addQueryData({
- __s: 1
- });
- if (Env.fb_isb) this.uri.addQueryData({
- fb_isb: Env.fb_isb
- });
- }
- this.finallyHandler = async_callback(this.finallyHandler, 'final');
- var uri_str, query;
- if (this.method == 'GET' || this.file) {
- uri_str = this.uri.addQueryData(this.data).toString();
- query = '';
- } else {
- uri_str = this.uri.toString();
- this._setDataHash();
- query = URI.implodeQuery(this.data);
- }
- if (this.getOption('jsonp') || this.getOption('useIframeTransport')) {
- uri_str = this.uri.addQueryData({
- __a: this.id
- }).toString();
- AsyncRequest._JSONPReceivers[this.id] = async_callback(bind(this, 'onjsonpresponse'), 'json');
- if (this.getOption('jsonp')) {
- (function () {
- document.body.appendChild($N('script', {
- src: uri_str,
- type: "text/javascript"
- }));
- }).bind(this).defer();
- } else {
- var style = {
- position: 'absolute',
- top: '-9999999px',
- width: '80px',
- height: '80px'
- };
- this.transportIframe = $N('iframe', {
- src: "javascript:''",
- style: style
- });
- document.body.appendChild(this.transportIframe);
- this.transportIframe.src = uri_str;
- }
- return true;
- }
- if (this.transport) return false;
- var transport = null;
- try {
- transport = new XMLHttpRequest();
- } catch (ignored) {}
- if (!transport) try {
- transport = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (ignored) {}
- if (!transport) try {
- transport = new ActiveXObject("Microsoft.XMLHTTP");
- } catch (ignored) {}
- if (!transport) return false;
- transport.onreadystatechange = async_callback(bind(this, 'onstatechange'), 'xhr');
- if (!isRetry) this.remainingRetries = this.getOption('retries');
- if (window.send_error_signal || window.ArbiterMonitor) this._sendTimeStamp = this._sendTimeStamp || Date.now();
- this.transport = transport;
- try {
- this.transport.open(this.method, uri_str, this.getOption('asynchronous'));
- } catch (ex) {
- return false;
- }
- var svn_rev = Env.svn_rev;
- if (svn_rev) this.transport.setRequestHeader('X-SVN-Rev', String(svn_rev));
- if (this.method == 'POST') this.transport.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- this.addStatusIndicator();
- query = this.file || query;
- this.transport.send(query);
- if (this.timeout !== null) this.resetTimeout(this.timeout);
- AsyncRequest._inflightAdd(this);
- return true;
- },
- _displayServerDialog: function (model, is_confirmation) {
- Bootloader.loadComponents('dialog', function () {
- var dialog = new Dialog(model);
- if (is_confirmation) dialog.setHandler(this._displayConfirmationHandler.bind(this, dialog));
- dialog.setCancelHandler(function () {
- this.serverDialogCancelHandler.apply(this, arguments);
- this.finallyHandler.apply(this, arguments);
- }.bind(this)).setCausalElement(this.relativeTo).setCloseHandler(this.finallyHandler.bind(this)).show();
- }.bind(this));
- },
- _displayConfirmationHandler: function (dialog) {
- this.data.confirmed = 1;
- copyProperties(this.data, dialog.getFormData());
- this.send();
- }
- });
- module.exports = AsyncRequest;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement