/media/jscripts/tiny_mce/plugins/media/js/media.js

https://bitbucket.org/chuns/cms · JavaScript · 630 lines · 498 code · 123 blank · 9 comment · 105 complexity · 5fac3b4e732edda25a2810884f607bdf MD5 · raw file

  1. tinyMCEPopup.requireLangPack();
  2. var oldWidth, oldHeight, ed, url;
  3. if (url = tinyMCEPopup.getParam("media_external_list_url"))
  4. document.write('<script language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></script>');
  5. function init() {
  6. var pl = "", f, val;
  7. var type = "flash", fe, i;
  8. ed = tinyMCEPopup.editor;
  9. tinyMCEPopup.resizeToInnerSize();
  10. f = document.forms[0]
  11. fe = ed.selection.getNode();
  12. if (/mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(ed.dom.getAttrib(fe, 'class'))) {
  13. pl = fe.title;
  14. switch (ed.dom.getAttrib(fe, 'class')) {
  15. case 'mceItemFlash':
  16. type = 'flash';
  17. break;
  18. case 'mceItemFlashVideo':
  19. type = 'flv';
  20. break;
  21. case 'mceItemShockWave':
  22. type = 'shockwave';
  23. break;
  24. case 'mceItemWindowsMedia':
  25. type = 'wmp';
  26. break;
  27. case 'mceItemQuickTime':
  28. type = 'qt';
  29. break;
  30. case 'mceItemRealMedia':
  31. type = 'rmp';
  32. break;
  33. }
  34. document.forms[0].insert.value = ed.getLang('update', 'Insert', true);
  35. }
  36. document.getElementById('filebrowsercontainer').innerHTML = getBrowserHTML('filebrowser','src','media','media');
  37. document.getElementById('qtsrcfilebrowsercontainer').innerHTML = getBrowserHTML('qtsrcfilebrowser','qt_qtsrc','media','media');
  38. document.getElementById('bgcolor_pickcontainer').innerHTML = getColorPickerHTML('bgcolor_pick','bgcolor');
  39. var html = getMediaListHTML('medialist','src','media','media');
  40. if (html == "")
  41. document.getElementById("linklistrow").style.display = 'none';
  42. else
  43. document.getElementById("linklistcontainer").innerHTML = html;
  44. // Resize some elements
  45. if (isVisible('filebrowser'))
  46. document.getElementById('src').style.width = '230px';
  47. // Setup form
  48. if (pl != "") {
  49. pl = tinyMCEPopup.editor.plugins.media._parse(pl);
  50. switch (type) {
  51. case "flash":
  52. setBool(pl, 'flash', 'play');
  53. setBool(pl, 'flash', 'loop');
  54. setBool(pl, 'flash', 'menu');
  55. setBool(pl, 'flash', 'swliveconnect');
  56. setStr(pl, 'flash', 'quality');
  57. setStr(pl, 'flash', 'scale');
  58. setStr(pl, 'flash', 'salign');
  59. setStr(pl, 'flash', 'wmode');
  60. setStr(pl, 'flash', 'base');
  61. setStr(pl, 'flash', 'flashvars');
  62. break;
  63. case "qt":
  64. setBool(pl, 'qt', 'loop');
  65. setBool(pl, 'qt', 'autoplay');
  66. setBool(pl, 'qt', 'cache');
  67. setBool(pl, 'qt', 'controller');
  68. setBool(pl, 'qt', 'correction');
  69. setBool(pl, 'qt', 'enablejavascript');
  70. setBool(pl, 'qt', 'kioskmode');
  71. setBool(pl, 'qt', 'autohref');
  72. setBool(pl, 'qt', 'playeveryframe');
  73. setBool(pl, 'qt', 'tarsetcache');
  74. setStr(pl, 'qt', 'scale');
  75. setStr(pl, 'qt', 'starttime');
  76. setStr(pl, 'qt', 'endtime');
  77. setStr(pl, 'qt', 'tarset');
  78. setStr(pl, 'qt', 'qtsrcchokespeed');
  79. setStr(pl, 'qt', 'volume');
  80. setStr(pl, 'qt', 'qtsrc');
  81. break;
  82. case "shockwave":
  83. setBool(pl, 'shockwave', 'sound');
  84. setBool(pl, 'shockwave', 'progress');
  85. setBool(pl, 'shockwave', 'autostart');
  86. setBool(pl, 'shockwave', 'swliveconnect');
  87. setStr(pl, 'shockwave', 'swvolume');
  88. setStr(pl, 'shockwave', 'swstretchstyle');
  89. setStr(pl, 'shockwave', 'swstretchhalign');
  90. setStr(pl, 'shockwave', 'swstretchvalign');
  91. break;
  92. case "wmp":
  93. setBool(pl, 'wmp', 'autostart');
  94. setBool(pl, 'wmp', 'enabled');
  95. setBool(pl, 'wmp', 'enablecontextmenu');
  96. setBool(pl, 'wmp', 'fullscreen');
  97. setBool(pl, 'wmp', 'invokeurls');
  98. setBool(pl, 'wmp', 'mute');
  99. setBool(pl, 'wmp', 'stretchtofit');
  100. setBool(pl, 'wmp', 'windowlessvideo');
  101. setStr(pl, 'wmp', 'balance');
  102. setStr(pl, 'wmp', 'baseurl');
  103. setStr(pl, 'wmp', 'captioningid');
  104. setStr(pl, 'wmp', 'currentmarker');
  105. setStr(pl, 'wmp', 'currentposition');
  106. setStr(pl, 'wmp', 'defaultframe');
  107. setStr(pl, 'wmp', 'playcount');
  108. setStr(pl, 'wmp', 'rate');
  109. setStr(pl, 'wmp', 'uimode');
  110. setStr(pl, 'wmp', 'volume');
  111. break;
  112. case "rmp":
  113. setBool(pl, 'rmp', 'autostart');
  114. setBool(pl, 'rmp', 'loop');
  115. setBool(pl, 'rmp', 'autogotourl');
  116. setBool(pl, 'rmp', 'center');
  117. setBool(pl, 'rmp', 'imagestatus');
  118. setBool(pl, 'rmp', 'maintainaspect');
  119. setBool(pl, 'rmp', 'nojava');
  120. setBool(pl, 'rmp', 'prefetch');
  121. setBool(pl, 'rmp', 'shuffle');
  122. setStr(pl, 'rmp', 'console');
  123. setStr(pl, 'rmp', 'controls');
  124. setStr(pl, 'rmp', 'numloop');
  125. setStr(pl, 'rmp', 'scriptcallbacks');
  126. break;
  127. }
  128. setStr(pl, null, 'src');
  129. setStr(pl, null, 'id');
  130. setStr(pl, null, 'name');
  131. setStr(pl, null, 'vspace');
  132. setStr(pl, null, 'hspace');
  133. setStr(pl, null, 'bgcolor');
  134. setStr(pl, null, 'align');
  135. setStr(pl, null, 'width');
  136. setStr(pl, null, 'height');
  137. if ((val = ed.dom.getAttrib(fe, "width")) != "")
  138. pl.width = f.width.value = val;
  139. if ((val = ed.dom.getAttrib(fe, "height")) != "")
  140. pl.height = f.height.value = val;
  141. oldWidth = pl.width ? parseInt(pl.width) : 0;
  142. oldHeight = pl.height ? parseInt(pl.height) : 0;
  143. } else
  144. oldWidth = oldHeight = 0;
  145. selectByValue(f, 'media_type', type);
  146. changedType(type);
  147. updateColor('bgcolor_pick', 'bgcolor');
  148. TinyMCE_EditableSelects.init();
  149. generatePreview();
  150. }
  151. function insertMedia() {
  152. var fe, f = document.forms[0], h;
  153. tinyMCEPopup.restoreSelection();
  154. if (!AutoValidator.validate(f)) {
  155. tinyMCEPopup.alert(ed.getLang('invalid_data'));
  156. return false;
  157. }
  158. f.width.value = f.width.value == "" ? 100 : f.width.value;
  159. f.height.value = f.height.value == "" ? 100 : f.height.value;
  160. fe = ed.selection.getNode();
  161. if (fe != null && /mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(ed.dom.getAttrib(fe, 'class'))) {
  162. switch (f.media_type.options[f.media_type.selectedIndex].value) {
  163. case "flash":
  164. fe.className = "mceItemFlash";
  165. break;
  166. case "flv":
  167. fe.className = "mceItemFlashVideo";
  168. break;
  169. case "shockwave":
  170. fe.className = "mceItemShockWave";
  171. break;
  172. case "qt":
  173. fe.className = "mceItemQuickTime";
  174. break;
  175. case "wmp":
  176. fe.className = "mceItemWindowsMedia";
  177. break;
  178. case "rmp":
  179. fe.className = "mceItemRealMedia";
  180. break;
  181. }
  182. if (fe.width != f.width.value || fe.height != f.height.value)
  183. ed.execCommand('mceRepaint');
  184. fe.title = serializeParameters();
  185. fe.width = f.width.value;
  186. fe.height = f.height.value;
  187. fe.style.width = f.width.value + (f.width.value.indexOf('%') == -1 ? 'px' : '');
  188. fe.style.height = f.height.value + (f.height.value.indexOf('%') == -1 ? 'px' : '');
  189. fe.align = f.align.options[f.align.selectedIndex].value;
  190. } else {
  191. h = '<img src="' + tinyMCEPopup.getWindowArg("plugin_url") + '/img/trans.gif"' ;
  192. switch (f.media_type.options[f.media_type.selectedIndex].value) {
  193. case "flash":
  194. h += ' class="mceItemFlash"';
  195. break;
  196. case "flv":
  197. h += ' class="mceItemFlashVideo"';
  198. break;
  199. case "shockwave":
  200. h += ' class="mceItemShockWave"';
  201. break;
  202. case "qt":
  203. h += ' class="mceItemQuickTime"';
  204. break;
  205. case "wmp":
  206. h += ' class="mceItemWindowsMedia"';
  207. break;
  208. case "rmp":
  209. h += ' class="mceItemRealMedia"';
  210. break;
  211. }
  212. h += ' title="' + serializeParameters() + '"';
  213. h += ' width="' + f.width.value + '"';
  214. h += ' height="' + f.height.value + '"';
  215. h += ' align="' + f.align.options[f.align.selectedIndex].value + '"';
  216. h += ' />';
  217. ed.execCommand('mceInsertContent', false, h);
  218. }
  219. tinyMCEPopup.close();
  220. }
  221. function updatePreview() {
  222. var f = document.forms[0], type;
  223. f.width.value = f.width.value || '320';
  224. f.height.value = f.height.value || '240';
  225. type = getType(f.src.value);
  226. selectByValue(f, 'media_type', type);
  227. changedType(type);
  228. generatePreview();
  229. }
  230. function getMediaListHTML() {
  231. if (typeof(tinyMCEMediaList) != "undefined" && tinyMCEMediaList.length > 0) {
  232. var html = "";
  233. html += '<select id="linklist" name="linklist" style="width: 250px" onchange="this.form.src.value=this.options[this.selectedIndex].value;updatePreview();">';
  234. html += '<option value="">---</option>';
  235. for (var i=0; i<tinyMCEMediaList.length; i++)
  236. html += '<option value="' + tinyMCEMediaList[i][1] + '">' + tinyMCEMediaList[i][0] + '</option>';
  237. html += '</select>';
  238. return html;
  239. }
  240. return "";
  241. }
  242. function getType(v) {
  243. var fo, i, c, el, x, f = document.forms[0];
  244. fo = ed.getParam("media_types", "flash=swf;flv=flv;shockwave=dcr;qt=mov,qt,mpg,mp3,mp4,mpeg;shockwave=dcr;wmp=avi,wmv,wm,asf,asx,wmx,wvx;rmp=rm,ra,ram").split(';');
  245. // YouTube
  246. if (v.match(/watch\?v=(.+)(.*)/)) {
  247. f.width.value = '425';
  248. f.height.value = '350';
  249. f.src.value = 'http://www.youtube.com/v/' + v.match(/v=(.*)(.*)/)[0].split('=')[1];
  250. return 'flash';
  251. }
  252. // Google video
  253. if (v.indexOf('http://video.google.com/videoplay?docid=') == 0) {
  254. f.width.value = '425';
  255. f.height.value = '326';
  256. f.src.value = 'http://video.google.com/googleplayer.swf?docId=' + v.substring('http://video.google.com/videoplay?docid='.length) + '&hl=en';
  257. return 'flash';
  258. }
  259. for (i=0; i<fo.length; i++) {
  260. c = fo[i].split('=');
  261. el = c[1].split(',');
  262. for (x=0; x<el.length; x++)
  263. if (v.indexOf('.' + el[x]) != -1)
  264. return c[0];
  265. }
  266. return null;
  267. }
  268. function switchType(v) {
  269. var t = getType(v), d = document, f = d.forms[0];
  270. if (!t)
  271. return;
  272. selectByValue(d.forms[0], 'media_type', t);
  273. changedType(t);
  274. // Update qtsrc also
  275. if (t == 'qt' && f.src.value.toLowerCase().indexOf('rtsp://') != -1) {
  276. alert(ed.getLang("media_qt_stream_warn"));
  277. if (f.qt_qtsrc.value == '')
  278. f.qt_qtsrc.value = f.src.value;
  279. }
  280. }
  281. function changedType(t) {
  282. var d = document;
  283. d.getElementById('flash_options').style.display = 'none';
  284. d.getElementById('flv_options').style.display = 'none';
  285. d.getElementById('qt_options').style.display = 'none';
  286. d.getElementById('shockwave_options').style.display = 'none';
  287. d.getElementById('wmp_options').style.display = 'none';
  288. d.getElementById('rmp_options').style.display = 'none';
  289. if (t)
  290. d.getElementById(t + '_options').style.display = 'block';
  291. }
  292. function serializeParameters() {
  293. var d = document, f = d.forms[0], s = '';
  294. switch (f.media_type.options[f.media_type.selectedIndex].value) {
  295. case "flash":
  296. s += getBool('flash', 'play', true);
  297. s += getBool('flash', 'loop', true);
  298. s += getBool('flash', 'menu', true);
  299. s += getBool('flash', 'swliveconnect', false);
  300. s += getStr('flash', 'quality');
  301. s += getStr('flash', 'scale');
  302. s += getStr('flash', 'salign');
  303. s += getStr('flash', 'wmode');
  304. s += getStr('flash', 'base');
  305. s += getStr('flash', 'flashvars');
  306. break;
  307. case "qt":
  308. s += getBool('qt', 'loop', false);
  309. s += getBool('qt', 'autoplay', true);
  310. s += getBool('qt', 'cache', false);
  311. s += getBool('qt', 'controller', true);
  312. s += getBool('qt', 'correction', false, 'none', 'full');
  313. s += getBool('qt', 'enablejavascript', false);
  314. s += getBool('qt', 'kioskmode', false);
  315. s += getBool('qt', 'autohref', false);
  316. s += getBool('qt', 'playeveryframe', false);
  317. s += getBool('qt', 'targetcache', false);
  318. s += getStr('qt', 'scale');
  319. s += getStr('qt', 'starttime');
  320. s += getStr('qt', 'endtime');
  321. s += getStr('qt', 'target');
  322. s += getStr('qt', 'qtsrcchokespeed');
  323. s += getStr('qt', 'volume');
  324. s += getStr('qt', 'qtsrc');
  325. break;
  326. case "shockwave":
  327. s += getBool('shockwave', 'sound');
  328. s += getBool('shockwave', 'progress');
  329. s += getBool('shockwave', 'autostart');
  330. s += getBool('shockwave', 'swliveconnect');
  331. s += getStr('shockwave', 'swvolume');
  332. s += getStr('shockwave', 'swstretchstyle');
  333. s += getStr('shockwave', 'swstretchhalign');
  334. s += getStr('shockwave', 'swstretchvalign');
  335. break;
  336. case "wmp":
  337. s += getBool('wmp', 'autostart', true);
  338. s += getBool('wmp', 'enabled', false);
  339. s += getBool('wmp', 'enablecontextmenu', true);
  340. s += getBool('wmp', 'fullscreen', false);
  341. s += getBool('wmp', 'invokeurls', true);
  342. s += getBool('wmp', 'mute', false);
  343. s += getBool('wmp', 'stretchtofit', false);
  344. s += getBool('wmp', 'windowlessvideo', false);
  345. s += getStr('wmp', 'balance');
  346. s += getStr('wmp', 'baseurl');
  347. s += getStr('wmp', 'captioningid');
  348. s += getStr('wmp', 'currentmarker');
  349. s += getStr('wmp', 'currentposition');
  350. s += getStr('wmp', 'defaultframe');
  351. s += getStr('wmp', 'playcount');
  352. s += getStr('wmp', 'rate');
  353. s += getStr('wmp', 'uimode');
  354. s += getStr('wmp', 'volume');
  355. break;
  356. case "rmp":
  357. s += getBool('rmp', 'autostart', false);
  358. s += getBool('rmp', 'loop', false);
  359. s += getBool('rmp', 'autogotourl', true);
  360. s += getBool('rmp', 'center', false);
  361. s += getBool('rmp', 'imagestatus', true);
  362. s += getBool('rmp', 'maintainaspect', false);
  363. s += getBool('rmp', 'nojava', false);
  364. s += getBool('rmp', 'prefetch', false);
  365. s += getBool('rmp', 'shuffle', false);
  366. s += getStr('rmp', 'console');
  367. s += getStr('rmp', 'controls');
  368. s += getStr('rmp', 'numloop');
  369. s += getStr('rmp', 'scriptcallbacks');
  370. break;
  371. }
  372. s += getStr(null, 'id');
  373. s += getStr(null, 'name');
  374. s += getStr(null, 'src');
  375. s += getStr(null, 'align');
  376. s += getStr(null, 'bgcolor');
  377. s += getInt(null, 'vspace');
  378. s += getInt(null, 'hspace');
  379. s += getStr(null, 'width');
  380. s += getStr(null, 'height');
  381. s = s.length > 0 ? s.substring(0, s.length - 1) : s;
  382. return s;
  383. }
  384. function setBool(pl, p, n) {
  385. if (typeof(pl[n]) == "undefined")
  386. return;
  387. document.forms[0].elements[p + "_" + n].checked = pl[n] != 'false';
  388. }
  389. function setStr(pl, p, n) {
  390. var f = document.forms[0], e = f.elements[(p != null ? p + "_" : '') + n];
  391. if (typeof(pl[n]) == "undefined")
  392. return;
  393. if (e.type == "text")
  394. e.value = pl[n];
  395. else
  396. selectByValue(f, (p != null ? p + "_" : '') + n, pl[n]);
  397. }
  398. function getBool(p, n, d, tv, fv) {
  399. var v = document.forms[0].elements[p + "_" + n].checked;
  400. tv = typeof(tv) == 'undefined' ? 'true' : "'" + jsEncode(tv) + "'";
  401. fv = typeof(fv) == 'undefined' ? 'false' : "'" + jsEncode(fv) + "'";
  402. return (v == d) ? '' : n + (v ? ':' + tv + ',' : ":\'" + fv + "\',");
  403. }
  404. function getStr(p, n, d) {
  405. var e = document.forms[0].elements[(p != null ? p + "_" : "") + n];
  406. var v = e.type == "text" ? e.value : e.options[e.selectedIndex].value;
  407. if (n == 'src')
  408. v = tinyMCEPopup.editor.convertURL(v, 'src', null);
  409. return ((n == d || v == '') ? '' : n + ":'" + jsEncode(v) + "',");
  410. }
  411. function getInt(p, n, d) {
  412. var e = document.forms[0].elements[(p != null ? p + "_" : "") + n];
  413. var v = e.type == "text" ? e.value : e.options[e.selectedIndex].value;
  414. return ((n == d || v == '') ? '' : n + ":" + v.replace(/[^0-9]+/g, '') + ",");
  415. }
  416. function jsEncode(s) {
  417. s = s.replace(new RegExp('\\\\', 'g'), '\\\\');
  418. s = s.replace(new RegExp('"', 'g'), '\\"');
  419. s = s.replace(new RegExp("'", 'g'), "\\'");
  420. return s;
  421. }
  422. function generatePreview(c) {
  423. var f = document.forms[0], p = document.getElementById('prev'), h = '', cls, pl, n, type, codebase, wp, hp, nw, nh;
  424. p.innerHTML = '<!-- x --->';
  425. nw = parseInt(f.width.value);
  426. nh = parseInt(f.height.value);
  427. if (f.width.value != "" && f.height.value != "") {
  428. if (f.constrain.checked) {
  429. if (c == 'width' && oldWidth != 0) {
  430. wp = nw / oldWidth;
  431. nh = Math.round(wp * nh);
  432. f.height.value = nh;
  433. } else if (c == 'height' && oldHeight != 0) {
  434. hp = nh / oldHeight;
  435. nw = Math.round(hp * nw);
  436. f.width.value = nw;
  437. }
  438. }
  439. }
  440. if (f.width.value != "")
  441. oldWidth = nw;
  442. if (f.height.value != "")
  443. oldHeight = nh;
  444. // After constrain
  445. pl = serializeParameters();
  446. switch (f.media_type.options[f.media_type.selectedIndex].value) {
  447. case "flash":
  448. cls = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
  449. codebase = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';
  450. type = 'application/x-shockwave-flash';
  451. break;
  452. case "shockwave":
  453. cls = 'clsid:166B1BCA-3F9C-11CF-8075-444553540000';
  454. codebase = 'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0';
  455. type = 'application/x-director';
  456. break;
  457. case "qt":
  458. cls = 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B';
  459. codebase = 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0';
  460. type = 'video/quicktime';
  461. break;
  462. case "wmp":
  463. cls = ed.getParam('media_wmp6_compatible') ? 'clsid:05589FA1-C356-11CE-BF01-00AA0055595A' : 'clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6';
  464. codebase = 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701';
  465. type = 'application/x-mplayer2';
  466. break;
  467. case "rmp":
  468. cls = 'clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA';
  469. codebase = 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701';
  470. type = 'audio/x-pn-realaudio-plugin';
  471. break;
  472. }
  473. if (pl == '') {
  474. p.innerHTML = '';
  475. return;
  476. }
  477. pl = tinyMCEPopup.editor.plugins.media._parse(pl);
  478. if (!pl.src) {
  479. p.innerHTML = '';
  480. return;
  481. }
  482. pl.src = tinyMCEPopup.editor.documentBaseURI.toAbsolute(pl.src);
  483. pl.width = !pl.width ? 100 : pl.width;
  484. pl.height = !pl.height ? 100 : pl.height;
  485. pl.id = !pl.id ? 'obj' : pl.id;
  486. pl.name = !pl.name ? 'eobj' : pl.name;
  487. pl.align = !pl.align ? '' : pl.align;
  488. // Avoid annoying warning about insecure items
  489. if (!tinymce.isIE || document.location.protocol != 'https:') {
  490. h += '<object classid="' + cls + '" codebase="' + codebase + '" width="' + pl.width + '" height="' + pl.height + '" id="' + pl.id + '" name="' + pl.name + '" align="' + pl.align + '">';
  491. for (n in pl) {
  492. h += '<param name="' + n + '" value="' + pl[n] + '">';
  493. // Add extra url parameter if it's an absolute URL
  494. if (n == 'src' && pl[n].indexOf('://') != -1)
  495. h += '<param name="url" value="' + pl[n] + '" />';
  496. }
  497. }
  498. h += '<embed type="' + type + '" ';
  499. for (n in pl)
  500. h += n + '="' + pl[n] + '" ';
  501. h += '></embed>';
  502. // Avoid annoying warning about insecure items
  503. if (!tinymce.isIE || document.location.protocol != 'https:')
  504. h += '</object>';
  505. p.innerHTML = "<!-- x --->" + h;
  506. }
  507. tinyMCEPopup.onInit.add(init);