video.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ///import core
  2. ///import plugins/inserthtml.js
  3. ///commands 视频
  4. ///commandsName InsertVideo
  5. ///commandsTitle 插入视频
  6. ///commandsDialog dialogs\video
  7. UE.plugins['video'] = 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 && align !="none" ? ( align == "center"? ' style="text-align:center;" ':' style="float:"'+ align ) : '') + '>'): '') +
  22. '<img align="'+align+'" width="'+ width +'" height="' + height + '" _url="'+url+'" class="edui-faked-video"' +
  23. ' src="' + me.options.UEDITOR_HOME_URL+'themes/default/images/spacer.gif" style="background:url('+me.options.UEDITOR_HOME_URL+'themes/default/images/videologo.gif) no-repeat center center; border:1px solid gray;" />' +
  24. (addParagraph?'</p>':'')
  25. :
  26. '<embed type="application/x-shockwave-flash" class="edui-faked-video" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  27. ' src="' + url + '" width="' + width + '" height="' + height + '" align="' + align + '"' +
  28. ( align && 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-video"){
  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["insertvideo"] = {
  59. execCommand: function (cmd, videoObjs){
  60. videoObjs = utils.isArray(videoObjs)?videoObjs:[videoObjs];
  61. var html = [];
  62. for(var i=0,vi,len = videoObjs.length;i<len;i++){
  63. vi = videoObjs[i];
  64. html.push(creatInsertStr( vi.url, vi.width || 420, vi.height || 280, vi.align||"none",false,true));
  65. }
  66. me.execCommand("inserthtml",html.join(""));
  67. },
  68. queryCommandState : function(){
  69. var img = me.selection.getRange().getClosedNode(),
  70. flag = img && (img.className == "edui-faked-video");
  71. return flag ? 1 : 0;
  72. }
  73. };
  74. };