Guest User

Untitled

a guest
Sep 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. top = this
  2. top.logJPlayerCreate ?= true
  3. top.logJPlayerPublishCreate ?= true
  4. top.logAllJPlayerEvents ?= false
  5.  
  6.  
  7. do ($ = jQuery) ->
  8. if !$.subscribe
  9. o = $({})
  10. $.subscribe = ->
  11. o.on.apply o, arguments
  12. $.unsubscribe = ->
  13. o.off.apply o, arguments
  14. $.publish = ->
  15. o.trigger.apply o, arguments
  16.  
  17.  
  18. _extends = (child, parent) ->
  19. for own key, value of parent
  20. child[key] = value
  21. ctor = ->
  22. @constructor = child
  23. @
  24. ctor.prototype = parent.prototype
  25. child.prototype = new ctor
  26. child.__super__ = parent.prototype
  27. child
  28.  
  29.  
  30. initEventPublishing = (jpe) ->
  31. for own evKey, evName of jQuery.jPlayer.event
  32. if top.logJPlayerPublishCreate
  33. console.log("creating publish handler on #{jpe.attr('id')} for /jplayer/#{evKey}")
  34. data =
  35. key: evKey
  36. name: evName
  37. jq: jpe
  38. handler = (event) ->
  39. if top.logAllJPlayerEvents
  40. console.groupCollapsed("#{event.data.jq.attr('id')} #{event.data.key}")
  41. console.log("jPlayer:")
  42. console.dir(event.jPlayer)
  43. console.log("data:")
  44. console.dir(event.data)
  45. console.groupEnd()
  46. $.publish "/jplayer/#{event.data.key}", [event.jPlayer, event.data, event]
  47. jpe.on evName, data, handler
  48.  
  49.  
  50. originalJPlayer = top.jQuery.jPlayer
  51.  
  52. JPlayerDuckPunch = (options, element) ->
  53. options ||= {}
  54.  
  55. if top.logJPlayerCreate
  56. console.groupCollapsed(element.id)
  57. console.log("JPlayerDuckPunch")
  58. console.log("options:")
  59. console.dir(options)
  60. console.log("element:")
  61. console.dir(element)
  62.  
  63. dpopt = jQuery.extend({}, options)
  64. dpopt['solution'] = 'html, flash'
  65. originalReady = options['ready'] || ->
  66. dpopt['ready'] = ->
  67. jpe = $(this);
  68. console.log("jPlayer ready handler for #{jpe.attr('id')}") if top.logJPlayerCreate
  69. initEventPublishing(jpe)
  70. console.log("calling original ready handler...") if top.logJPlayerCreate
  71. originalReady.apply(this, arguments)
  72.  
  73. if top.logJPlayerCreate
  74. console.log("modified options:")
  75. console.dir(dpopt)
  76. console.groupEnd()
  77.  
  78. originalJPlayer.apply(this, [dpopt, element])
  79.  
  80. JPlayerDuckPunch::options.emulateHtml = true
  81. JPlayerDuckPunch::options.solution = 'html, flash'
  82. JPlayerDuckPunch::options.supplied = "m4a, mp3"
  83. JPlayerDuckPunch::options.preload = "auto"
  84. JPlayerDuckPunch::options.errorAlerts = true
  85. JPlayerDuckPunch::options.warningAlerts = true
  86. JPlayerDuckPunch::compatibleEvents = [
  87. 'error', 'warning', 'loadstart', 'progress', 'timeupdate',
  88. 'play', 'pause', 'ended', 'seeking', 'seeked', 'volumechange'
  89. ]
  90. JPlayerDuckPunch::coreEvents = [
  91. 'playing', 'timeupdate', 'loadedmetadata', 'canplaythrough',
  92. 'progress', 'seeked', 'ended', 'error'
  93. ]
  94.  
  95.  
  96. top.jQuery.jPlayer = _extends(JPlayerDuckPunch, originalJPlayer)
Add Comment
Please, Sign In to add comment