From 2e24168dd5094ee72a00bd1f3c4cc7881a20cd7f Mon Sep 17 00:00:00 2001 From: psychowood Date: Sun, 15 May 2016 14:05:31 +0200 Subject: [PATCH] Load translations only one time --- app/scripts/services/translation-loader.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/app/scripts/services/translation-loader.js b/app/scripts/services/translation-loader.js index eb7c204..e20e39b 100644 --- a/app/scripts/services/translation-loader.js +++ b/app/scripts/services/translation-loader.js @@ -10,7 +10,7 @@ angular.module('ngTorrentUiApp') .factory('translationsLoader', function($http, $q) { var languages, constants; - // var loading = false; + var loadingPromise; return function(options) { var deferred = $q.defer(); @@ -56,16 +56,11 @@ angular.module('ngTorrentUiApp') if (languages && constants) { load(options); } else { - // if (loading) { - // if (isGetOptions){ - // return loading.promise; - // } else { - // - // } - // } - // loading = $q.defer(); - - $http.get('langs/utorrent/!base.js').then( + if (!loadingPromise) { + loadingPromise = $http.get('langs/utorrent/!base.js'); + } + + loadingPromise.then( function(response) { var invertDefine = 'Array.prototype.invert = function() { var h = {}; for (var g = 0, f = this.length; g < f; ++g) { h[this[g]] = g } return h; };'; /*jslint evil: true */