!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.jsonpipe=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o -1) { subChunk = chunk.substring(start, finish); if (subChunk) { parse(subChunk, successFn, errorFn); } start = finish + token.length; // move the start } offset += start; // move the offset // Get the remaning chunk chunk = text.substring(offset); // If final chunk and still unprocessed chunk and no delimiter, then execute the full chunk if (finalChunk && chunk && finish === -1) { parse(chunk, successFn, errorFn); } }; // Assign onChunk to options options.onChunk = onChunk; return xhr.send(url, options); }; module.exports = { flow: ajax }; },{"./net/xhr":2}],2:[function(_dereq_,module,exports){ 'use strict'; function send(url, options) { if (!url || !options) { return; } var xhr = new XMLHttpRequest(), state = { UNSENT: 0, OPENED: 1, HEADERS_RECEIVED: 2, LOADING: 3, DONE: 4 }, noop = function() {}, method = (options.method || '').toUpperCase(), headers = options.headers, onChunk = options.onChunk || noop, errorFn = options.error || noop, completeFn = options.complete || noop, addContentHeader = method === 'POST', isChunked = false, timer; xhr.open(method || 'GET', url, true); // Attach onreadystatechange xhr.onreadystatechange = function() { var encoding, chromeObj, loadTimes, chromeSpdy; if (xhr.readyState === state.HEADERS_RECEIVED) { encoding = xhr.getResponseHeader('Transfer-Encoding') || ''; encoding = encoding.toLowerCase(); isChunked = encoding.indexOf('chunked') > -1 || encoding.indexOf('identity') > -1; // fix for Safari if (!isChunked) { // SPDY inherently uses chunked transfer and does not define a header. // Firefox provides a synthetic header which can be used instead. // For Chrome, a non-standard JS function must be used to determine if // the primary document was loaded with SPDY. If the primary document // was loaded with SPDY, then most likely the XHR will be as well. chromeObj = window.chrome; loadTimes = chromeObj && chromeObj.loadTimes && chromeObj.loadTimes(); chromeSpdy = loadTimes && loadTimes.wasFetchedViaSpdy; isChunked = !!(xhr.getResponseHeader('X-Firefox-Spdy') || chromeSpdy); } } else if (xhr.readyState === state.LOADING) { if (isChunked && xhr.responseText) { onChunk(xhr.responseText); } } else if (xhr.readyState === state.DONE) { // clear timeout first clearTimeout(timer); // Check for error first if (xhr.status < 200 || xhr.status > 299) { errorFn(xhr.statusText); } else { onChunk(xhr.responseText, true); } // Call complete at the end completeFn(xhr.statusText); } }; // Add headers if (headers) { for (var key in headers) { xhr.setRequestHeader(key, headers[key]); if (key.toLowerCase() === 'content-type') { addContentHeader = false; } } } if (addContentHeader) { xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); } // Add timeout if (options.timeout) { timer = setTimeout(function() { xhr.abort(); clearTimeout(timer); }, options.timeout); } // Set credentials if (options.hasOwnProperty("withCredentials")) { xhr.withCredentials = options.withCredentials; } else { xhr.withCredentials = true; } xhr.send(options.data); return xhr; } module.exports = { send: send }; },{}]},{},[1]) (1) });