UNPKG

este-library-oldschool

Version:

Library for github.com/steida/este.git

87 lines (79 loc) 2.17 kB
// Generated by github.com/steida/coffee2closure 900.1.18 /** @fileoverview Chunked pixel request. Payload is divided into max. 2kb chunks. */ goog.provide('este.net.ChunkedPixelRequest'); goog.provide('este.net.ChunkedPixelRequest.create'); goog.require('este.string'); goog.require('este.json'); /** @param {string} uri @param {Function} randomStringFactory @param {Function} srcCallback @constructor */ este.net.ChunkedPixelRequest = function(uri1, randomStringFactory, srcCallback1) { this.uri = uri1; this.randomStringFactory = randomStringFactory; this.srcCallback = srcCallback1; } /** @param {string} uri @return {este.net.ChunkedPixelRequest} */ este.net.ChunkedPixelRequest.create = function(uri) { var srcCallback; srcCallback = function(src) { var img; img = new Image(1, 1); img.src = src; }; return new este.net.ChunkedPixelRequest(uri, goog.string.getRandomString, srcCallback); }; /** http://support.microsoft.com/kb/208427 @type {number} */ este.net.ChunkedPixelRequest.MAX_CHUNK_SIZE = 1900; /** @type {string} */ este.net.ChunkedPixelRequest.prototype.uri = ''; /** @type {Function} */ este.net.ChunkedPixelRequest.prototype.randomStringFactory = null; /** @type {Function} */ este.net.ChunkedPixelRequest.prototype.srcCallback = null; /** @param {Object} payload */ este.net.ChunkedPixelRequest.prototype.send = function(payload) { var chunk, chunks, i, len, message, randomString, stringified; chunks = this.getChunks(payload); randomString = this.randomStringFactory(); for (i = 0, len = chunks.length; i < len; i++) { chunk = chunks[i]; message = { 'u': randomString, 'd': chunk.text, 'i': chunk.index, 't': chunk.total }; stringified = este.json.stringify(message); this.srcCallback(this.uri + '?' + encodeURIComponent(stringified)); } }; /** @param {Object} payload @return {Array.<Object>} @protected */ este.net.ChunkedPixelRequest.prototype.getChunks = function(payload) { var str; str = este.json.stringify(payload); return este.string.chunkToObject(str, este.net.ChunkedPixelRequest.MAX_CHUNK_SIZE); };