Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is Simple Audio Plugin for AngularJS
- # service
- class AngularAudio
- constructor:() ->
- @cache = {}
- play:(id) ->
- audio = null
- if (@cache[id]) # check cache
- audio = @cache[id]
- else # load from DOM
- audio = document.querySelector(id)
- @cache[id] = audio
- if audio
- @playSE(audio)
- playSE:(audio) ->
- audio.load()
- audio.play()
- #================
- # Assign modules
- #================
- _module = angular.module('ngAudio', [])
- _module.directive('ngAudio', ($compile, ngAudio) ->
- return {
- restrict: 'AE'
- controller: ($scope, $attrs, $element) ->
- $element.on('click', (e) ->
- ngAudio.play($attrs.ngAudio)
- )
- }
- )
- _module.service('ngAudio', AngularAudio)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement