e75efa1a3240c44a58ee1eb59473309113c3ace0.svn-base 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // ================================================================
  2. // Movie
  3. // ================================================================
  4. var button = [
  5. { alt : '', img : 'play.gif', cmd : doPlay },
  6. { alt : '', img : 'submit.gif', cmd : doSubmit },
  7. { alt : '', img : 'cancel.gif', cmd : popupClose }
  8. ],
  9. oEditor = null,
  10. iframeSource = null,
  11. showMovie = false,
  12. defaultMovieWidth = 640,
  13. defaultMovieHeight = 360;
  14. function init(dialog) {
  15. var dlg = new Dialog(this);
  16. oEditor = this;
  17. oEditor.dialog = dialog;
  18. dlg.showButton(button);
  19. dlg.setDialogHeight();
  20. }
  21. function getSource() {
  22. return oEditor.trimSpace(document.getElementById("fm_source").value);
  23. }
  24. function doPlay() {
  25. var embed = null,
  26. div = document.createElement('div'),
  27. pos, str, object, child, movieHeight, movieWidth, params = [], showWrapper,
  28. source = getSource(), iframe;
  29. showMovie = true;
  30. if (source === '') {
  31. return;
  32. }
  33. showWrapper = document.getElementById('fm_player');
  34. if (source.toLowerCase().indexOf("iframe") !== -1) {
  35. showWrapper.innerHTML = source;
  36. iframeSource = source;
  37. return;
  38. }
  39. if (/https?:\/\//.test(source)) {
  40. iframe = createIframeElement(defaultMovieWidth, defaultMovieHeight, source);
  41. if (iframe) {
  42. showWrapper.innerHTML = '';
  43. showWrapper.appendChild(iframe);
  44. iframeSource = iframe;
  45. }
  46. return;
  47. }
  48. pos = source.toLowerCase().indexOf("embed");
  49. if (pos !== -1) {
  50. str = source.substr(pos);
  51. pos = str.indexOf(">");
  52. div.innerHTML = "<" + str.substr(0, pos) + ">";
  53. embed = div.firstChild;
  54. } else {
  55. div.innerHTML = source;
  56. object = div.getElementsByTagName('OBJECT')[0];
  57. if (object && object.hasChildNodes()) {
  58. child = object.firstChild;
  59. movieWidth = (isNaN(object.width) !== true) ? object.width : defaultMovieWidth;
  60. movieHeight = (isNaN(object.height) !== true) ? object.height : defaultMovieHeight;
  61. do {
  62. if (child.nodeName === 'PARAM' && typeof child.name !== 'undefined' && typeof child.value !== 'undefined')
  63. {
  64. params.push({
  65. key: child.name === 'movie' ? 'src' : child.name,
  66. val: child.value
  67. });
  68. }
  69. child = child.nextSibling;
  70. } while (child);
  71. if (params.length > 0) {
  72. embed = createEmbedElement(movieWidth, movieHeight, params, null);
  73. }
  74. }
  75. }
  76. if (embed !== null) {
  77. document.getElementById('fm_player').appendChild(embed);
  78. }
  79. }
  80. function createIframeElement(width, height, src) {
  81. var iframe = document.createElement('iframe'), uri, query, movie = null;
  82. uri = new oEditor.URI(src);
  83. if (uri.path && uri.path.charAt(0) !== '/') {
  84. uri.path = '/' + uri.path;
  85. }
  86. switch (uri.authority) {
  87. case 'youtu.be' :
  88. case 'youtube.com':
  89. case 'www.youtube.com':
  90. if (uri.path === '/watch' && uri.query) {
  91. query = uri.query.split('=');
  92. if (query[0] === 'v') {
  93. movie = '/' + query[1];
  94. }
  95. }
  96. if (!movie && uri.path) {
  97. movie = uri.path;
  98. if (uri.query) {
  99. movie += '?' + uri.query;
  100. }
  101. }
  102. if (movie) {
  103. movie = 'https://www.youtube.com/embed' + movie;
  104. }
  105. break;
  106. case 'vimeo.com' :
  107. if (uri.path) {
  108. movie = 'https://player.vimeo.com/video' + uri.path;
  109. }
  110. break;
  111. case 'afree.ca' :
  112. if (uri.path) {
  113. movie = 'http://play.afreecatv.com' + uri.path + '/embed';
  114. }
  115. break;
  116. default :
  117. movie = null;
  118. }
  119. if (!movie) {
  120. return null;
  121. }
  122. iframe.setAttribute('width', width);
  123. iframe.setAttribute('height', height);
  124. iframe.setAttribute('frameborder', "0");
  125. iframe.setAttribute('allowfullscreen', "true");
  126. iframe.setAttribute('src', movie);
  127. return iframe;
  128. }
  129. function createEmbedElement(width, height, params, src) {
  130. var embed = document.createElement('embed'), i;
  131. embed.setAttribute("type", "application/x-shockwave-flash");
  132. embed.setAttribute('width', width);
  133. embed.setAttribute('height', height);
  134. if (src) {
  135. embed.setAttribute('src', src);
  136. }
  137. for (i = 0; i < params.length; i++) {
  138. embed.setAttribute(params[i].key, params[i].val);
  139. }
  140. return embed;
  141. }
  142. function popupClose() {
  143. document.getElementById('fm_player').innerHTML = '';
  144. oEditor.popupWinCancel();
  145. }
  146. function doSubmit()
  147. {
  148. var source = getSource();
  149. if (source === '') {
  150. popupClose();
  151. }
  152. if (!showMovie) {
  153. document.getElementById('fm_player').style.visibility = 'hidden';
  154. doPlay();
  155. }
  156. if (iframeSource) {
  157. oEditor.insertHtmlPopup(iframeSource);
  158. } else {
  159. oEditor.insertFlash(source);
  160. }
  161. document.getElementById('fm_player').innerHTML = '';
  162. oEditor.popupWinClose();
  163. }