Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. # This is Simple Audio Plugin for AngularJS
  2.  
  3. # service
  4. class AngularAudio
  5. constructor:() ->
  6. @cache = {}
  7.  
  8. play:(id) ->
  9. audio = null
  10.  
  11. if (@cache[id]) # check cache
  12. audio = @cache[id]
  13. else # load from DOM
  14. audio = document.querySelector(id)
  15. @cache[id] = audio
  16.  
  17. if audio
  18. @playSE(audio)
  19.  
  20. playSE:(audio) ->
  21. audio.load()
  22. audio.play()
  23.  
  24.  
  25. #================
  26. # Assign modules
  27. #================
  28.  
  29. _module = angular.module('ngAudio', [])
  30. _module.directive('ngAudio', ($compile, ngAudio) ->
  31. return {
  32. restrict: 'AE'
  33. controller: ($scope, $attrs, $element) ->
  34. $element.on('click', (e) ->
  35. ngAudio.play($attrs.ngAudio)
  36. )
  37. }
  38. )
  39. _module.service('ngAudio', AngularAudio)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement