music.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ///import core
  2. ///import plugins/inserthtml.js
  3. ///commands 音乐
  4. ///commandsName Music
  5. ///commandsTitle 插入音乐
  6. ///commandsDialog dialogs\music
  7. UE.plugins['music'] = function () {
  8. var me = this,
  9. div;
  10. /**
  11. * 创建插入音乐字符窜
  12. * @param url 音乐地址
  13. * @param width 音乐宽度
  14. * @param height 音乐高度
  15. * @param align 阴雨对齐
  16. * @param toEmbed 是否以flash代替显示
  17. * @param addParagraph 是否需要添加P标签
  18. */
  19. function creatInsertStr(url,width,height,align,toEmbed,addParagraph){
  20. return !toEmbed ?
  21. (addParagraph? ('<p '+ (align !="none" ? ( align == "center"? ' style="text-align:center;" ':' style="float:"'+ align ) : '') + '>'): '') +
  22. '<img align="'+align+'" width="'+ width +'" height="' + height + '" _url="'+url+'" class="edui-faked-music"' +
  23. ' src="'+me.options.langPath+me.options.lang+'/images/music.png" />' +
  24. (addParagraph?'</p>':'')
  25. :
  26. '<embed type="application/x-shockwave-flash" class="edui-faked-music" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  27. ' src="' + url + '" width="' + width + '" height="' + height + '" align="' + align + '"' +
  28. ( align !="none" ? ' style= "'+ ( align == "center"? "display:block;":" float: "+ align ) + '"' :'' ) +
  29. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  30. }
  31. function switchImgAndEmbed(img2embed) {
  32. var tmpdiv,
  33. nodes = domUtils.getElementsByTagName(me.document, !img2embed ? "embed" : "img");
  34. for (var i = 0, node; node = nodes[i++];) {
  35. if (node.className != "edui-faked-music") {
  36. continue;
  37. }
  38. tmpdiv = me.document.createElement("div");
  39. //先看float在看align,浮动有的是时候是在float上定义的
  40. var align = domUtils.getComputedStyle(node,'float');
  41. align = align == 'none' ? (node.getAttribute('align') || '') : align;
  42. tmpdiv.innerHTML = creatInsertStr(img2embed ? node.getAttribute("_url") : node.getAttribute("src"), node.width, node.height, align, img2embed);
  43. node.parentNode.replaceChild(tmpdiv.firstChild, node);
  44. }
  45. }
  46. me.addListener("beforegetcontent", function () {
  47. switchImgAndEmbed(true);
  48. });
  49. me.addListener('aftersetcontent', function () {
  50. switchImgAndEmbed(false);
  51. });
  52. me.addListener('aftergetcontent', function (cmdName) {
  53. if (cmdName == 'aftergetcontent' && me.queryCommandState('source')) {
  54. return;
  55. }
  56. switchImgAndEmbed(false);
  57. });
  58. me.commands["music"] = {
  59. execCommand:function (cmd, musicObj) {
  60. var me = this,
  61. str = creatInsertStr(musicObj.url, musicObj.width || 400, musicObj.height || 95, "none", false, true);
  62. me.execCommand("inserthtml",str);
  63. },
  64. queryCommandState:function () {
  65. var me = this,
  66. img = me.selection.getRange().getClosedNode(),
  67. flag = img && (img.className == "edui-faked-music");
  68. return flag ? 1 : 0;
  69. }
  70. };
  71. };