cleanup
[KisSync.git] / player / embed.coffee
blob7881b3d2c2f4e53a912847ddb5a1e5e81df9eaf2
1 DEFAULT_ERROR = 'You are currently connected via HTTPS but the embedded content
2     uses non-secure plain HTTP.  Your browser therefore blocks it from
3     loading due to mixed content policy.  To fix this, embed the video using a
4     secure link if available (https://...), or find another source for the content.'
6 genParam = (name, value) ->
7     $('<param/>').attr(
8         name: name
9         value: value
10     )
12 window.EmbedPlayer = class EmbedPlayer extends Player
13     constructor: (data) ->
14         if not (this instanceof EmbedPlayer)
15             return new EmbedPlayer(data)
17         @load(data)
19     load: (data) ->
20         @setMediaProperties(data)
22         embed = data.meta.embed
23         if not embed?
24             console.error('EmbedPlayer::load(): missing meta.embed')
25             return
27         if embed.tag == 'object'
28             @player = @loadObject(embed)
29         else
30             @player = @loadIframe(embed)
32         removeOld(@player)
34     loadObject: (embed) ->
35         object = $('<object/>').attr(
36             type: 'application/x-shockwave-flash'
37             data: embed.src
38             wmode: 'opaque'
39         )
40         genParam('allowfullscreen', 'true').appendTo(object)
41         genParam('allowscriptaccess', 'always').appendTo(object)
43         for key, value of embed.params
44             genParam(key, value).appendTo(object)
46         return object
48     loadIframe: (embed) ->
49         if embed.src.indexOf('http:') == 0 and location.protocol == 'https:'
50             if @__proto__.mixedContentError?
51                 error = @__proto__.mixedContentError
52             else
53                 error = DEFAULT_ERROR
54             alert = makeAlert('Mixed Content Error', error, 'alert-danger')
55                 .removeClass('col-md-12')
56             alert.find('.close').remove()
57             return alert
58         else
59             iframe = $('<iframe/>').attr(
60                 src: embed.src
61                 frameborder: '0'
62                 allowfullscreen: '1'
63             )
65             return iframe