Mercurial > hg > env-test-daniele
comparison johndyer-mediaelement-13fa20a/src/js/mep-feature-contextmenu.js @ 0:032bc65ebafc
added core components
author | George Fazekas <gyorgy.fazekas@eecs.qmul.ac.uk> |
---|---|
date | Wed, 06 Mar 2013 15:45:48 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:032bc65ebafc |
---|---|
1 /* | |
2 * ContextMenu Plugin | |
3 * | |
4 * | |
5 */ | |
6 | |
7 | |
8 mejs.MepDefaults.contextMenuItems = [ | |
9 // demo of a fullscreen option | |
10 { | |
11 render: function(player) { | |
12 | |
13 // check for fullscreen plugin | |
14 if (typeof player.enterFullScreen == 'undefined') | |
15 return null; | |
16 | |
17 if (player.isFullScreen) { | |
18 return "Turn off Fullscreen"; | |
19 } else { | |
20 return "Go Fullscreen"; | |
21 } | |
22 }, | |
23 click: function(player) { | |
24 if (player.isFullScreen) { | |
25 player.exitFullScreen(); | |
26 } else { | |
27 player.enterFullScreen(); | |
28 } | |
29 } | |
30 } | |
31 , | |
32 // demo of a mute/unmute button | |
33 { | |
34 render: function(player) { | |
35 if (player.media.muted) { | |
36 return "Unmute"; | |
37 } else { | |
38 return "Mute"; | |
39 } | |
40 }, | |
41 click: function(player) { | |
42 if (player.media.muted) { | |
43 player.setMuted(false); | |
44 } else { | |
45 player.setMuted(true); | |
46 } | |
47 } | |
48 }, | |
49 // separator | |
50 { | |
51 isSeparator: true | |
52 } | |
53 , | |
54 // demo of simple download video | |
55 { | |
56 render: function(player) { | |
57 return "Download Video"; | |
58 }, | |
59 click: function(player) { | |
60 window.location.href = player.media.currentSrc; | |
61 } | |
62 } | |
63 | |
64 ]; | |
65 | |
66 | |
67 (function($) { | |
68 | |
69 | |
70 | |
71 MediaElementPlayer.prototype.buildcontextmenu = function(player, controls, layers, media) { | |
72 | |
73 // create context menu | |
74 player.contextMenu = $('<div class="mejs-contextmenu"></div>') | |
75 .appendTo($('body')) | |
76 .hide(); | |
77 | |
78 // create events for showing context menu | |
79 player.container.bind('contextmenu', function(e) { | |
80 e.preventDefault(); | |
81 player.renderContextMenu(e.clientX, e.clientY); | |
82 return false; | |
83 }); | |
84 player.container.bind('click', function() { | |
85 player.contextMenu.hide(); | |
86 }); | |
87 } | |
88 | |
89 MediaElementPlayer.prototype.renderContextMenu = function(x,y) { | |
90 | |
91 // alway re-render the items so that things like "turn fullscreen on" and "turn fullscreen off" are always written correctly | |
92 var t = this, | |
93 html = '', | |
94 items = t.options.contextMenuItems; | |
95 | |
96 for (var i=0, il=items.length; i<il; i++) { | |
97 | |
98 if (items[i].isSeparator) { | |
99 html += '<div class="mejs-contextmenu-separator"></div>'; | |
100 } else { | |
101 | |
102 var rendered = items[i].render(t); | |
103 | |
104 // render can return null if the item doesn't need to be used at the moment | |
105 if (rendered != null) { | |
106 html += '<div class="mejs-contextmenu-item" data-itemindex="' + i + '">' + rendered + '</div>'; | |
107 } | |
108 } | |
109 } | |
110 | |
111 // position and show the context menu | |
112 t.contextMenu | |
113 .empty() | |
114 .append($(html)) | |
115 .css({top:y, left:x}) | |
116 .show() | |
117 | |
118 // bind events | |
119 t.contextMenu.find('.mejs-contextmenu-item').click(function() { | |
120 // which one is this? | |
121 var itemIndex = parseInt( $(this).data('itemindex'), 10 ); | |
122 | |
123 // perform click action | |
124 t.options.contextMenuItems[itemIndex].click(t); | |
125 | |
126 // close | |
127 t.contextMenu.hide(); | |
128 }); | |
129 | |
130 } | |
131 | |
132 })(mejs.$); |