From fedd1e7716fdc012b4f29518f9c76eae34a3247f Mon Sep 17 00:00:00 2001 From: Benjamin Besse Date: Thu, 4 Feb 2016 17:16:31 +0100 Subject: [PATCH 1/2] Fix browserify problem with jquery.toObject --- src/jquery.toObject.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/jquery.toObject.js b/src/jquery.toObject.js index 3e5c9de..ab339ec 100644 --- a/src/jquery.toObject.js +++ b/src/jquery.toObject.js @@ -24,7 +24,34 @@ * Time: 20:09 */ -(function($){ +(function(factory) { + + // Establish the root object, `window` (`self`) in the browser, or `global` on the server. + // We use `self` instead of `window` for `WebWorker` support. + var root = (typeof self == 'object' && self.self == self && self) || + (typeof global == 'object' && global.global == global && global); + + // Set up Backbone appropriately for the environment. Start with AMD. + if (typeof define === 'function' && define.amd) { + define(['form2js', 'jquery'], function(form2js, $) { + // Export global even in AMD case in case this script is loaded with + // others that may still expect a global Backbone. + factory(root, form2js, $); + }); + + // Next for Node.js or CommonJS. jQuery may not be needed as a module. + } else if (typeof exports !== 'undefined') { + var form2js = require('form2js').form2js, $; + try { $ = require('jquery'); } catch(e) {} + + factory(root, form2js, $); + + // Finally, as a browser global. + } else { + factory(root, root.form2js, (root.jQuery || root.Zepto || root.ender || root.$)); + } + +}(function(root, form2js, $){ /** * jQuery wrapper for form2object() @@ -63,4 +90,4 @@ } } -})(jQuery); \ No newline at end of file +})); From 468a5c7960fcd43a5b40593e157b24584a4f620b Mon Sep 17 00:00:00 2001 From: Benjamin Besse Date: Fri, 5 Feb 2016 09:59:10 +0100 Subject: [PATCH 2/2] update comments --- src/jquery.toObject.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/jquery.toObject.js b/src/jquery.toObject.js index ab339ec..111b6e3 100644 --- a/src/jquery.toObject.js +++ b/src/jquery.toObject.js @@ -31,11 +31,9 @@ var root = (typeof self == 'object' && self.self == self && self) || (typeof global == 'object' && global.global == global && global); - // Set up Backbone appropriately for the environment. Start with AMD. + // Start with AMD. if (typeof define === 'function' && define.amd) { define(['form2js', 'jquery'], function(form2js, $) { - // Export global even in AMD case in case this script is loaded with - // others that may still expect a global Backbone. factory(root, form2js, $); });