From e0dd72328c7e1db9a9e653644a6048aa72aa5d67 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Sat, 7 Feb 2015 08:37:12 -0800 Subject: [PATCH] more shim cleanup --- src/UI/Mixins/jquery.ajax.js | 46 ----------------------------------- src/UI/Shared/ApiData.js | 1 - src/UI/Shared/piwikCheck.js | 0 src/UI/Shims/backbone.js | 6 ++--- src/UI/Shims/jquery.js | 9 ++++--- src/UI/index.html | 1 - src/UI/jQuery/jquery.ajax.js | 47 ++++++++++++++++++++++++++++++++++++ src/UI/jQuery/jquery.spin.js | 9 ++++--- src/UI/main.js | 2 +- src/UI/piwikCheck.js | 11 --------- 10 files changed, 61 insertions(+), 71 deletions(-) delete mode 100644 src/UI/Mixins/jquery.ajax.js create mode 100644 src/UI/Shared/piwikCheck.js create mode 100644 src/UI/jQuery/jquery.ajax.js delete mode 100644 src/UI/piwikCheck.js diff --git a/src/UI/Mixins/jquery.ajax.js b/src/UI/Mixins/jquery.ajax.js deleted file mode 100644 index 70adf6110..000000000 --- a/src/UI/Mixins/jquery.ajax.js +++ /dev/null @@ -1,46 +0,0 @@ -var $ = require('jquery'); -//var vent = require('../vent'); -//var messenger = require('../Shared/Messenger'); - -var original = $.ajax; -$.ajax = function(xhr){ - 'use strict'; - if(xhr && xhr.data && xhr.type === 'DELETE') { - if(xhr.url.contains('?')) { - xhr.url += '&'; - } - else { - xhr.url += '?'; - } - xhr.url += $.param(xhr.data); - delete xhr.data; - } - if(xhr) { - xhr.headers = xhr.headers || {}; - xhr.headers['X-Api-Key'] = window.NzbDrone.ApiKey; - } - return original.apply(this, arguments); - /* .done(function (response, status, xhr) { - var version = xhr.getResponseHeader('X-ApplicationVersion'); - if (!window.NzbDrone || !window.NzbDrone.Version) { - return; - } - if (version !== window.NzbDrone.Version) { - var vent = require('../vent'); - var messenger = require('../Shared/Messenger'); - if (!vent || !messenger) { - return; - } - messenger.show({ - message : 'Sonarr has been updated', hideAfter : 0, id : 'droneUpdated', actions : { - viewChanges : { - label : 'View Changes', action : function () { - window.location = window.NzbDrone.UrlBase + '/system/updates'; - } - } - } - }); - vent.trigger(vent.Events.ServerUpdated); - } - });*/ -}; \ No newline at end of file diff --git a/src/UI/Shared/ApiData.js b/src/UI/Shared/ApiData.js index ce5a0b44a..34dee0e7c 100644 --- a/src/UI/Shared/ApiData.js +++ b/src/UI/Shared/ApiData.js @@ -1,5 +1,4 @@ var $ = require('jquery'); -require('../Mixins/jquery.ajax'); module.exports = { get : function(resource){ diff --git a/src/UI/Shared/piwikCheck.js b/src/UI/Shared/piwikCheck.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/UI/Shims/backbone.js b/src/UI/Shims/backbone.js index 4568a2a69..c1a1fc060 100644 --- a/src/UI/Shims/backbone.js +++ b/src/UI/Shims/backbone.js @@ -1,9 +1,7 @@ -require('jquery'); -require('../JsLibraries/backbone'); - var jquery = require('jquery'); + var backbone = require('../JsLibraries/backbone'); +window.Backbone = backbone; backbone.$ = jquery; -window.Backbone = backbone; module.exports = backbone; \ No newline at end of file diff --git a/src/UI/Shims/jquery.js b/src/UI/Shims/jquery.js index 1b3baf15b..4a343c4ff 100644 --- a/src/UI/Shims/jquery.js +++ b/src/UI/Shims/jquery.js @@ -1,8 +1,11 @@ -require('../JsLibraries/jquery'); -require('../Instrumentation/StringFormat'); - var jquery = require('../JsLibraries/jquery'); require('../Instrumentation/StringFormat'); +var spin = require('../jQuery/jquery.spin'); +var ajax = require('../jquery/jquery.ajax'); + +spin.call(jquery); +ajax.call(jquery); + window.$ = jquery; window.jQuery = jquery; module.exports = jquery; \ No newline at end of file diff --git a/src/UI/index.html b/src/UI/index.html index dbd04bb36..889298b6b 100644 --- a/src/UI/index.html +++ b/src/UI/index.html @@ -86,7 +86,6 @@ }; - diff --git a/src/UI/jQuery/jquery.ajax.js b/src/UI/jQuery/jquery.ajax.js new file mode 100644 index 000000000..24eded7e9 --- /dev/null +++ b/src/UI/jQuery/jquery.ajax.js @@ -0,0 +1,47 @@ +module.exports = function(){ + + var $ = this; + + var original = $.ajax; + $.ajax = function(xhr){ + 'use strict'; + if(xhr && xhr.data && xhr.type === 'DELETE') { + if(xhr.url.contains('?')) { + xhr.url += '&'; + } + else { + xhr.url += '?'; + } + xhr.url += $.param(xhr.data); + delete xhr.data; + } + if(xhr) { + xhr.headers = xhr.headers || {}; + xhr.headers['X-Api-Key'] = window.NzbDrone.ApiKey; + } + return original.apply(this, arguments); + /* .done(function (response, status, xhr) { + var version = xhr.getResponseHeader('X-ApplicationVersion'); + if (!window.NzbDrone || !window.NzbDrone.Version) { + return; + } + if (version !== window.NzbDrone.Version) { + var vent = require('../vent'); + var messenger = require('../Shared/Messenger'); + if (!vent || !messenger) { + return; + } + messenger.show({ + message : 'Sonarr has been updated', hideAfter : 0, id : 'droneUpdated', actions : { + viewChanges : { + label : 'View Changes', action : function () { + window.location = window.NzbDrone.UrlBase + '/system/updates'; + } + } + } + }); + vent.trigger(vent.Events.ServerUpdated); + } + });*/ + }; +}; \ No newline at end of file diff --git a/src/UI/jQuery/jquery.spin.js b/src/UI/jQuery/jquery.spin.js index eb66e99d1..3a2874fa0 100644 --- a/src/UI/jQuery/jquery.spin.js +++ b/src/UI/jQuery/jquery.spin.js @@ -1,7 +1,8 @@ -var $ = require('jquery'); - -module.exports = (function(){ +module.exports = function(){ 'use strict'; + + var $ = this; + $.fn.spinForPromise = function(promise){ var self = this; if(!promise || promise.state() !== 'pending') { @@ -43,4 +44,4 @@ module.exports = (function(){ } return this; }; -}).call(this); \ No newline at end of file +}; \ No newline at end of file diff --git a/src/UI/main.js b/src/UI/main.js index 3d341ebc6..42342bf7a 100644 --- a/src/UI/main.js +++ b/src/UI/main.js @@ -16,7 +16,7 @@ require('./jQuery/ToTheTop'); require('./Instrumentation/StringFormat'); require('./LifeCycle'); require('./Hotkeys/Hotkeys'); -require('./Mixins/jquery.ajax'); +require('./Shared/piwikCheck'); new SeriesController(); new ModalController(); diff --git a/src/UI/piwikCheck.js b/src/UI/piwikCheck.js deleted file mode 100644 index 31e9c14f8..000000000 --- a/src/UI/piwikCheck.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; -if(window.NzbDrone.Analytics) { - var d = document; - var g = d.createElement('script'); - var s = d.getElementsByTagName('script')[0]; - g.type = 'text/javascript'; - g.async = true; - g.defer = true; - g.src = 'http://piwik.nzbdrone.com/piwik.js'; - s.parentNode.insertBefore(g, s); -} \ No newline at end of file