angular-translate-loader-static-files.js 919 B

12345678910111213141516171819202122232425262728293031
  1. /*!
  2. * angular-translate - v2.4.2 - 2014-10-21
  3. * http://github.com/angular-translate/angular-translate
  4. * Copyright (c) 2014 ; Licensed MIT
  5. */
  6. angular.module('pascalprecht.translate').factory('$translateStaticFilesLoader', [
  7. '$q',
  8. '$http',
  9. function ($q, $http) {
  10. return function (options) {
  11. if (!options || (!angular.isString(options.prefix) || !angular.isString(options.suffix))) {
  12. throw new Error('Couldn\'t load static files, no prefix or suffix specified!');
  13. }
  14. var deferred = $q.defer();
  15. $http(angular.extend({
  16. url: [
  17. options.prefix,
  18. options.key,
  19. options.suffix
  20. ].join(''),
  21. method: 'GET',
  22. params: ''
  23. }, options.$http)).success(function (data) {
  24. deferred.resolve(data);
  25. }).error(function (data) {
  26. deferred.reject(options.key);
  27. });
  28. return deferred.promise;
  29. };
  30. }
  31. ]);