-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackbone.jwplayer.js.coffee
More file actions
21 lines (19 loc) · 1.06 KB
/
backbone.jwplayer.js.coffee
File metadata and controls
21 lines (19 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
JWPlayer = (options) ->
@cid = _.uniqueId("backbone.jwplayer")
@initialize.apply(@, arguments)
@delegateJWPlayer()
_.extend JWPlayer.prototype, Backbone.Events,
initialize: ->
@eventslist = ['onTime','onBufferChange','onBeforePlay','onPlay','onPause','onBuffer','onIddle','onSeek','onMute','onVolume','onFullscreen','onResize','onError','onQualityLevels','onQualityChange','onCaptionsList','onCaptionsChange','onControls','onDisplayClick','onMeta']
delegateJWPlayer: (jwplayer=null) ->
return unless @jwplayerevents
throw new Error("You have to give jwplayer instance as argument") unless jwplayer
for jwplayerevent, callback of @jwplayerevents
method = @[callback] unless _.isFunction(callback)
method = _.bind(method, @)
throw new Error("Method #{callback} does not exist") unless method
eventname = jwplayerevent.split(':')[1]
throw new Error("Event #{eventname} does not exist") if !(eventname in @eventslist)
jwplayer[eventname](method)
Backbone.JWPlayer = JWPlayer
Backbone.JWPlayer.extend = Backbone.View.extend