From 651a933a9e7713ea430a946470477965087cc061 Mon Sep 17 00:00:00 2001 From: Simon Nilsson Date: Wed, 27 Jun 2018 14:30:57 +0200 Subject: [PATCH 1/2] UMD format Use UMD to work with AMD and CommonJS --- BinaryTransport/jquery.binarytransport.js | 60 +++++++++++++++++------ 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/BinaryTransport/jquery.binarytransport.js b/BinaryTransport/jquery.binarytransport.js index 67a55fe..2c5e781 100644 --- a/BinaryTransport/jquery.binarytransport.js +++ b/BinaryTransport/jquery.binarytransport.js @@ -1,23 +1,51 @@ - /** - * - * jquery.binarytransport.js - * - * @description. jQuery ajax transport for making binary data type requests. - * @version 1.0 - * @author Henry Algus - * - */ +/** +* +* jquery.binarytransport.js +* +* @description. jQuery ajax transport for making binary data type requests. +* @version 1.0 +* @author Henry Algus +* +*/ -(function($, undefined) { +// Uses CommonJS, AMD or browser globals to create a jQuery plugin. + +(function (factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['jquery'], factory); + } else if (typeof module === 'object' && module.exports) { + // Node/CommonJS + module.exports = function (root, jQuery) { + if (jQuery === undefined) { + // require('jQuery') returns a factory that requires window to + // build a jQuery instance, we normalize how we use modules + // that require this pattern but the window provided is a noop + // if it's defined (how jquery works) + if (typeof window !== 'undefined') { + jQuery = require('jquery'); + } + else { + jQuery = require('jquery')(root); + } + } + factory(jQuery); + return jQuery; + }; + } else { + // Browser globals + factory(jQuery); + } +}(function ($, undefined) { "use strict"; // use this transport for "binary" data type - $.ajaxTransport("+binary", function(options, originalOptions, jqXHR) { + $.ajaxTransport("+binary", function (options, originalOptions, jqXHR) { // check for conditions and support for blob / arraybuffer response type if (window.FormData && ((options.dataType && (options.dataType == 'binary')) || (options.data && ((window.ArrayBuffer && options.data instanceof ArrayBuffer) || (window.Blob && options.data instanceof Blob))))) { return { // create new XMLHttpRequest - send: function(headers, callback) { + send: function (headers, callback) { // setup all variables var xhr = new XMLHttpRequest(), url = options.url, @@ -29,13 +57,13 @@ username = options.username || null, password = options.password || null; - xhr.addEventListener('load', function() { + xhr.addEventListener('load', function () { var data = {}; data[options.dataType] = xhr.response; // make callback and send data callback(xhr.status, xhr.statusText, data, xhr.getAllResponseHeaders()); }); - xhr.addEventListener('error', function() { + xhr.addEventListener('error', function () { var data = {}; data[options.dataType] = xhr.response; // make callback and send data @@ -52,8 +80,8 @@ xhr.responseType = dataType; xhr.send(data); }, - abort: function() {} + abort: function () { } }; } }); -})(window.jQuery); +})); From e9beca983901912d3f100b6e1203a21c020084e1 Mon Sep 17 00:00:00 2001 From: Simon Nilsson Date: Wed, 27 Jun 2018 14:32:54 +0200 Subject: [PATCH 2/2] Removed comment --- BinaryTransport/jquery.binarytransport.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/BinaryTransport/jquery.binarytransport.js b/BinaryTransport/jquery.binarytransport.js index 2c5e781..1e02a03 100644 --- a/BinaryTransport/jquery.binarytransport.js +++ b/BinaryTransport/jquery.binarytransport.js @@ -8,8 +8,6 @@ * */ -// Uses CommonJS, AMD or browser globals to create a jQuery plugin. - (function (factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module.