您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

lubusy.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * Created by robin on 10/24/15.
  3. */
  4. angular.module('luticateUtils')
  5. .directive('luBusy', ['$compile', '$http', 'luticatePromises', '$templateCache', function($compile, $http, luticatePromises, $templateCache){
  6. return {
  7. restrict: 'A',
  8. scope: {
  9. luBusy: '&'
  10. },
  11. link: function($scope, element, attrs) {
  12. var position = element.css('position');
  13. if (position === 'static' || position === '' || typeof position === 'undefined'){
  14. element.css('position','relative');
  15. }
  16. $scope.isLoading = false;
  17. $scope.hasError = false;
  18. var options = {
  19. group: attrs.luBusy,
  20. templateLoader: "luticate-loader.html",
  21. templateError: "luticate-error.html"
  22. };
  23. var o = $scope.luBusy();
  24. if (o != null) {
  25. angular.extend(options, o);
  26. }
  27. $scope.update = function()
  28. {
  29. var loaders = luticatePromises.getLoadersGroup(options.group);
  30. $scope.isLoading = false;
  31. if (loaders != null) {
  32. $scope.isLoading = loaders.some(function (promise) {
  33. return promise.status == 0;
  34. });
  35. }
  36. var errors = luticatePromises.getErrorsGroup(options.group);
  37. $scope.hasError = false;
  38. if (errors != null) {
  39. $scope.hasError = errors.some(function (promise) {
  40. return promise.status == 2;
  41. });
  42. }
  43. };
  44. $scope.loaderSplashIsActive = function() {
  45. $scope.update();
  46. return $scope.isLoading && !$scope.hasError;
  47. };
  48. $scope.errorSplashIsActive = function() {
  49. $scope.update();
  50. return $scope.hasError;
  51. };
  52. function addTemplate(template, ngShow) {
  53. $http.get(template, {cache: $templateCache}).success(function (indicatorTemplate) {
  54. var templateScope = $scope.$new();
  55. var backdrop = '<div class="lu-busy lu-busy-backdrop lu-busy-backdrop-animation ng-hide" ng-show="' + ngShow + '"></div>';
  56. var backdropElement = $compile(backdrop)(templateScope);
  57. element.append(backdropElement);
  58. var template = '<div class="lu-busy lu-busy-animation" ng-show="' + ngShow + '">' + indicatorTemplate + '</div>';
  59. var templateElement = $compile(template)(templateScope);
  60. element.append(templateElement);
  61. }).error(function (data) {
  62. throw new Error('Template specified for luBusy (' + template + ') could not be loaded. ' + data);
  63. });
  64. }
  65. addTemplate(options.templateLoader, 'loaderSplashIsActive()');
  66. addTemplate(options.templateError, 'errorSplashIsActive()');
  67. }
  68. };
  69. }
  70. ]);
  71. angular.module('luticateUtils').run(['$templateCache', function($templateCache) {
  72. 'use strict';
  73. $templateCache.put('luticate-loader.html',
  74. "<div class=\"lu-busy-default-wrapper\" style=\"position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px;\">\n" +
  75. "\n" +
  76. " <div class=\"lu-busy-default-sign\">\n" +
  77. "\n" +
  78. " <div class=\"lu-busy-default-spinner\">\n" +
  79. " <div class=\"bar1\"></div>\n" +
  80. " <div class=\"bar2\"></div>\n" +
  81. " <div class=\"bar3\"></div>\n" +
  82. " <div class=\"bar4\"></div>\n" +
  83. " <div class=\"bar5\"></div>\n" +
  84. " <div class=\"bar6\"></div>\n" +
  85. " <div class=\"bar7\"></div>\n" +
  86. " <div class=\"bar8\"></div>\n" +
  87. " <div class=\"bar9\"></div>\n" +
  88. " <div class=\"bar10\"></div>\n" +
  89. " <div class=\"bar11\"></div>\n" +
  90. " <div class=\"bar12\"></div>\n" +
  91. " </div>\n" +
  92. "\n" +
  93. " <div class=\"lu-busy-default-text\">Please wait...</div>\n" +
  94. "\n" +
  95. " </div>\n" +
  96. "\n" +
  97. "</div>"
  98. );
  99. $templateCache.put('luticate-error.html',
  100. "<div class=\"lu-busy-default-wrapper\" style=\"position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px;\">\n" +
  101. "\n" +
  102. " <div class=\"lu-busy-default-sign\">\n" +
  103. "\n" +
  104. " <div class=\"lu-busy-default-error-text\">Error</div>\n" +
  105. "\n" +
  106. " </div>\n" +
  107. "\n" +
  108. "</div>"
  109. );
  110. }]);