From 6a1d0de3f4970d3b981e14c4963a7cc5108255d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Andr=C3=A9s=20Puertas?= Date: Tue, 15 Nov 2016 15:55:56 +0000 Subject: [PATCH 1/2] fix: commonjs export (#5) Added additional logic to avoid populate the global scope with a module.exports variable. --- src/angular-translate-loader-pluggable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/angular-translate-loader-pluggable.js b/src/angular-translate-loader-pluggable.js index b23c280..1fbd3e0 100644 --- a/src/angular-translate-loader-pluggable.js +++ b/src/angular-translate-loader-pluggable.js @@ -67,7 +67,7 @@ function translatePluggableLoaderProvider() { } // commonjs export -if (typeof exports !== 'undefined') { +if (typeof exports !== 'undefined' && module && typeof module.exports === "object") { module.exports = { name: moduleName }; From dcafe4dced51ec703fb2a853bd8b66efb550b59b Mon Sep 17 00:00:00 2001 From: Juri Strumpflohner Date: Tue, 15 Nov 2016 16:00:09 +0000 Subject: [PATCH 2/2] v1.2.1 --- dist/angular-translate-loader-pluggable.js | 84 +++++++++++++++++++ .../angular-translate-loader-pluggable.min.js | 2 + ...ular-translate-loader-pluggable.min.js.map | 1 + package.json | 5 +- 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 dist/angular-translate-loader-pluggable.js create mode 100644 dist/angular-translate-loader-pluggable.min.js create mode 100644 dist/angular-translate-loader-pluggable.min.js.map diff --git a/dist/angular-translate-loader-pluggable.js b/dist/angular-translate-loader-pluggable.js new file mode 100644 index 0000000..5fac5d4 --- /dev/null +++ b/dist/angular-translate-loader-pluggable.js @@ -0,0 +1,84 @@ +(function (global, factory) { + if (typeof define === 'function' && define.amd) { + define(['exports'], factory); + } else if (typeof exports !== 'undefined') { + factory(exports); + } else { + var mod = { + exports: {} + }; + factory(mod.exports); + global.angularTranslateLoaderPluggable = mod.exports; + } +})(this, function (exports) { + 'use strict'; + + var moduleName = 'angular-translate-loader-pluggable'; + + angular.module(moduleName, ['pascalprecht.translate']).provider('translatePluggableLoader', translatePluggableLoaderProvider); + + function translatePluggableLoaderProvider() { + var loaders = []; + var translationTable = {}; + + this.useLoader = function (loaderName, options) { + loaders.push({ + name: loaderName, + options: options + }); + + return this; + }; + + this.translations = function (language, translations) { + translationTable[language] = angular.extend({}, translationTable[language], translations); + + return this; + }; + + this.$get = ["$q", "$injector", function ($q, $injector) { + return function (options) { + var deferred = $q.defer(); + + var loaderInstances = []; + + // lookup in translation table + loaderInstances.push((function () { + var deferred = $q.defer(); + + deferred.resolve(translationTable[options.key]); + + return deferred.promise; + })()); + + // lookup in loaders + for (var i = 0; i < loaders.length; i++) { + var loader = loaders[i]; + + // get the loader and resolve it, passing in the required options + var loaderPromise = $injector.get(loader.name)(angular.extend(options, loader.options)); + loaderInstances.push(loaderPromise); + } + + $q.all(loaderInstances).then(function (loaders) { + var result; + + for (var i = 0; i < loaders.length; i++) { + result = angular.extend({}, result, loaders[i]); + } + + deferred.resolve(result); + }); + + return deferred.promise; + }; + }]; + } + + // commonjs export + if (typeof exports !== 'undefined' && module && typeof module.exports === "object") { + module.exports = { + name: moduleName + }; + } +}); \ No newline at end of file diff --git a/dist/angular-translate-loader-pluggable.min.js b/dist/angular-translate-loader-pluggable.min.js new file mode 100644 index 0000000..8ee38f9 --- /dev/null +++ b/dist/angular-translate-loader-pluggable.min.js @@ -0,0 +1,2 @@ +!function(e,t){if("function"==typeof define&&define.amd)define(["exports"],t);else if("undefined"!=typeof exports)t(exports);else{var n={exports:{}};t(n.exports),e.angularTranslateLoaderPluggable=n.exports}}(this,function(e){"use strict";function t(){var e=[],t={};this.useLoader=function(t,n){return e.push({name:t,options:n}),this},this.translations=function(e,n){return t[e]=angular.extend({},t[e],n),this},this.$get=["$q","$injector",function(n,r){return function(a){var o=n.defer(),s=[];s.push(function(){var e=n.defer();return e.resolve(t[a.key]),e.promise}());for(var u=0;u