Pony.fm/public/scripts/app/directives/src-loader.coffee

22 lines
562 B
CoffeeScript
Raw Normal View History

2013-09-01 22:04:30 +02:00
angular.module('ponyfm').directive 'pfmSrcLoader', () ->
(scope, element, attrs) ->
size = attrs.pfmSrcSize || 'normal'
2013-09-02 00:51:51 +02:00
element.css {opacity: .5}
2013-09-01 22:04:30 +02:00
2013-09-02 00:51:51 +02:00
update = (val) ->
element.attr 'src', '/images/icons/loading_' + size + '.png'
2013-09-01 22:04:30 +02:00
2013-09-02 00:51:51 +02:00
image = element.clone()
image.removeAttr 'pfm-src-loader'
image.removeAttr 'pfm-src-size'
2013-09-01 22:04:30 +02:00
2013-09-02 00:51:51 +02:00
image[0].onload = ->
element.attr 'src', val
element.css {opacity: 0}
element.animate {opacity: 1}, 250
2013-09-01 22:04:30 +02:00
2013-09-02 00:51:51 +02:00
image[0].src = val
update scope.$eval attrs.pfmSrcLoader
scope.$watch attrs.pfmSrcLoader, update