Permalink
Browse files

show loading image for badge image

  • Loading branch information...
1 parent 290a190 commit 87a1173a084eae05c8d718193a89009022d2d6a1 Gary Paige committed May 6, 2015
Showing with 49 additions and 2 deletions.
  1. +0 −1 Gruntfile.js
  2. +1 −0 app/index.html
  3. +33 −0 app/scripts/directives/loadingsrc.js
  4. +1 −1 app/views/badgeDialog.html
  5. +14 −0 test/spec/directives/loadingsrc.js
View
@@ -511,7 +511,6 @@ module.exports = function (grunt) {
'cdnify',
'cssmin',
'uglify',
- 'filerev',
'usemin',
'htmlmin'
]);
View
@@ -71,6 +71,7 @@
<script src="scripts/directives/about.js"></script>
<script src="scripts/directives/badge.js"></script>
<script src="scripts/controllers/badgedialog.js"></script>
+ <script src="scripts/directives/loadingsrc.js"></script>
<!-- endbuild -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
@@ -0,0 +1,33 @@
+'use strict';
+
+/**
+ * @ngdoc directive
+ * @name iLayers.directive:loadingSrc
+ * @description
+ * # loadingSrc
+ */
+angular.module('iLayers')
+ .directive('loadingSrc', LoadingSrc);
+
+LoadingSrc.$inject = ['errorService'];
+
+function LoadingSrc(errorService) {
+ return {
+ restrict: 'A',
+ link: function postLink(scope, element, attrs) {
+ var img = new Image();
+
+ element[0].src = (attrs.loading) ? attrs.loading : '/images/loading.gif';
+
+ img.onload = function() {
+ element[0].src = img.src;
+ };
+
+ img.onerror = function(e) {
+ errorService.notification('Unable to load badge.');
+ };
+
+ img.src = attrs.loadingSrc;
+ }
+ };
+};
@@ -29,7 +29,7 @@
<section ng-if="selectedImage.selected">
<div class="preview">
<label>Badge Preview</label>
- <img ng-src="https://badge.imagelayers.io/{{ selectedImage.name }}.svg">
+ <img loading-src="https://badge.imagelayers.io/{{ selectedImage.name }}.svg">
</div>
<ul>
<li>
@@ -0,0 +1,14 @@
+'use strict';
+
+describe('Directive: loadingSrc', function () {
+
+ // load the directive's module
+ beforeEach(module('iLayers'));
+
+ var element,
+ scope;
+
+ beforeEach(inject(function ($rootScope) {
+ scope = $rootScope.$new();
+ }));
+});

0 comments on commit 87a1173

Please sign in to comment.