From fbf99e030a5a257c815e91a7d0dec25ee3130aa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20Eycheni=C3=A9?= Date: Mon, 12 Oct 2015 15:29:46 +0200 Subject: [PATCH] Remove explicit dependancy to jQuery Sometimes Backbone is used without jQuery (see https://github.com/akre54/Backbone.NativeAjax) --- backbone-model-file-upload.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/backbone-model-file-upload.js b/backbone-model-file-upload.js index 3b0daac..ac95cd3 100644 --- a/backbone-model-file-upload.js +++ b/backbone-model-file-upload.js @@ -13,21 +13,21 @@ // AMD if (typeof define === 'function' && define.amd) { - define(['underscore', 'jquery', 'backbone'], function(_, $, Backbone){ - factory(root, Backbone, _, $); + define(['underscore', 'backbone'], function(_, Backbone){ + factory(root, Backbone, _); }); // NodeJS/CommonJS } else if (typeof exports !== 'undefined') { - var _ = require('underscore'), $ = require('jquery'), Backbone = require('backbone'); - factory(root, Backbone, _, $); + var _ = require('underscore'), Backbone = require('backbone'); + factory(root, Backbone, _); // Browser global } else { - factory(root, root.Backbone, root._, root.$); + factory(root, root.Backbone, root._); } -}(this, function(root, Backbone, _, $) { +}(this, function(root, Backbone, _) { 'use strict'; // Clone the original Backbone.Model.prototype as superClass @@ -100,12 +100,14 @@ options.processData = false; options.contentType = false; - // Apply custom XHR for processing status & listen to "progress" + // Handle "progress" events var that = this; - options.xhr = function() { - var xhr = $.ajaxSettings.xhr(); + var beforeSend = options.beforeSend; + options.beforeSend = function(xhr){ xhr.upload.addEventListener('progress', that._progressHandler.bind(that), false); - return xhr; + if(beforeSend) { + return beforeSend.apply(this, arguments); + } } }