如何把这段语句加入js代码中

yyychn 2018-07-16 05:18:53
ckeditor 3.6.2的插入媒体插件,其media.js的代码如下,
/*
Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/

(function(){(function(){var a={id:{name:'id'},src:{name:'src'},width:{name:'width'},height:{name:'height'},autostart:{name:'autostart'}};function b(e){var i=this;var f=a[i.id];if(!f)return;var g=i instanceof CKEDITOR.ui.dialog.checkbox,h=f;if(e.getAttribute(h.name)){value=e.getAttribute(h.name);if(i.id=='src')if(value.indexOf('player_flv_maxi.swf')>0)value=e.getAttribute('FlashVars').replace('file=','').replace('&showplayer=always&showiconplay=true&usefullscreen=true','').replace('&autostart=true','').replace('&autostart=1','');if(g)i.setValue(value.toLowerCase()=='true');else i.setValue(value);return;}else if(g)i.setValue(!!h['default']);};function c(e){var l=this;var f=a[l.id];if(!f)return;var g=l.getValue()==='',h=l instanceof CKEDITOR.ui.dialog.checkbox,i=f;value=l.getValue();if(l.id=='src'){var j=d(value);if(j=='flv'||j=='fla'||j=='f4v')if(j=='flv'||j=='f4v'){if(g||h&&value===i['default'])e.removeAttribute(i.name);else{var k='/Editor/plugins/media/swf/player_flv_maxi.swf';e.setAttribute(i.name,k);e.setAttribute('allowFullScreen','true');e.setAttribute('FlashVars','file='+value+'&showplayer=always&showiconplay=true&usefullscreen=true');return;}}else if(value.indexOf('youtube.com/')>0)value=value.replace(/youtube\.com\/watch\?v=/i,'youtube.com/v/');}if(g||h&&value===i['default'])e.removeAttribute(i.name);else e.setAttribute(i.name,value);if(l.id=='autostart'){if(l.getValue()){e.setAttribute('FlashVars',e.getAttribute('FlashVars')+'&autostart=1')}}};function d(e){var f=e.match(/\.(avi|asf|fla|flv|mov|mp3|mp4|mpg|mpeg|qt|swf|wma|wmv|f4v)$/i);if(f!=null&&f.length&&f.length>0)f=f[1];else if(e.indexOf('youtube.com/')>0)f='swf';else f='';return f;};CKEDITOR.dialog.add('media',function(e){var f,g='<div>'+CKEDITOR.tools.htmlEncode(e.lang.common.preview)+'<br>'+'<div id="cke_FlashPreviewLoader'+CKEDITOR.tools.getNextNumber()+'" style="display:none"><div class="loading"> </div></div>'+'<div id="cke_FlashPreviewBox'+CKEDITOR.tools.getNextNumber()+'" class="FlashPreviewBox"></div></div>';return{title:'媒体属性',minWidth:420,minHeight:310,onShow:function(){var l=this;l.fakeImage=l.objectNode=l.embedNode=null;f=new CKEDITOR.dom.element('embed',e.document);var h=l.getSelectedElement();if(h&&h.data('cke-real-element-type')&&h.data('cke-real-element-type')=='media'){l.fakeImage=h;var i=e.restoreRealElement(h),j=null,k=null;if(i.getName()=='cke:embed')k=i;l.objectNode=j;l.embedNode=k;l.setupContent(k,h);}},onOk:function(){var k=this;var h=null;if(!k.fakeImage)h=CKEDITOR.dom.element.createFromHtml('<cke:embed></cke:embed>',e.document);else h=k.embedNode;var i={};k.commitContent(h,i);var j=e.createFakeElement(h,'cke_media','media',true);
j.setStyles(i);if(k.fakeImage){j.replace(k.fakeImage);e.getSelection().selectElement(j);}else e.insertElement(j);},onHide:function(){if(this.preview)this.preview.setHtml('');},contents:[{id:'info',label:e.lang.common.generalTab,accessKey:'I',elements:[{type:'vbox',padding:0,children:[{type:'hbox',widths:['280px','110px'],align:'right',children:[{id:'src',type:'text',label:e.lang.common.url,required:true,validate:CKEDITOR.dialog.validate.notEmpty('源文件地址不能为空'),setup:b,commit:c,onLoad:function(){var h=this.getDialog(),i=function(j){var k=j,l=d(j);if(l=='flv'||l=='fla'||l=='f4v')if(l=='flv'||l=='f4v')k='/Editor/plugins/media/swf/player_flv_maxi.swf';else if(k.indexOf('youtube.com/')>0)j=j.replace(/youtube\.com\/watch\?v=/i,'youtube.com/v/');var m='<embed height="100%" width="100%" src="'+CKEDITOR.tools.htmlEncode(k);if(k.indexOf('player_flv_maxi.swf')>0)m+='" flashVars="file='+j+'&showplayer=always&showiconplay=true&usefullscreen=true';m+='" autostart="true"></embed>';h.preview.setHtml(m);};h.preview=h.getContentElement('info','preview').getElement().getChild(3);this.on('change',function(j){if(j.data&&j.data.value)i(j.data.value);});this.getInputElement().on('change',function(j){i(this.getValue());},this);}}]}]},{type:'hbox',widths:['25%','25%','25%','25%','25%'],children:[{type:'text',id:'width',style:'width:95px',label:e.lang.common.width,validate:CKEDITOR.dialog.validate.integer(e.lang.flash.validateWidth),setup:function(h,i){b.apply(this,arguments);if(i){var j=parseInt(i.$.style.width,10);if(!isNaN(j))this.setValue(j);}},commit:function(h,i){c.apply(this,arguments);if(this.getValue())i.width=this.getValue()+'px';}},{type:'text',id:'height',style:'width:95px',label:e.lang.common.height,validate:CKEDITOR.dialog.validate.integer(e.lang.flash.validateHeight),setup:function(h,i){b.apply(this,arguments);if(i){var j=parseInt(i.$.style.height,10);if(!isNaN(j))this.setValue(j);}},commit:function(h,i){c.apply(this,arguments);if(this.getValue())i.height=this.getValue()+'px';}},{type:'vbox',padding:0,children:[{type:'html',html:'选项'},{type:'checkbox',id:'autostart',label:'自动播放','default':true,setup:b,commit:c}]}]},{type:'vbox',children:[{type:'html',id:'preview',style:'width:95%;',html:g}]}]},{id:'Upload',hidden:true,filebrowser:'uploadButton',label:e.lang.common.upload,enabledUpload:e.config.flashUpload,elements:[{type:'file',id:'upload',label:e.lang.common.upload,size:38},{type:'fileButton',id:'uploadButton',filebrowser:{action:'QuickUpload',target:'info:src',params:{type:'flash',modelId:e.config.modelId,nodeId:e.config.nodeId,moduleName:e.config.moduleName,fieldName:e.config.fieldName,wordPic:e.config.wordPic,foreground:e.config.foreground,watermark:e.config.watermark,thumbnail:e.config.thumbnail,fileRecord:e.config.fileRecord,departmentUploader:e.config.departmentUploader}},label:e.lang.common.uploadSubmit,'for':['Upload','upload']}]},{id:'fileUpload',hidden:!e.config.imageUpload,label:'上传',expand:true,elements:[{type:'iframe',src:CKEDITOR.basePath+'FileUpload.aspx?type=media&CKEditor='+encodeURIComponent(e.name)+'&CKEditorFuncNum='+encodeURIComponent(e._.filebrowserFn)+'&modelId='+encodeURIComponent(e.config.modelId)+'&nodeId='+encodeURIComponent(e.config.nodeId)+'&moduleName='+encodeURIComponent(e.config.moduleName)+'&fieldName='+encodeURIComponent(e.config.fieldName)+'&wordPic='+encodeURIComponent(e.config.wordPic)+'&foreground='+encodeURIComponent(e.config.foreground)+'&watermark='+encodeURIComponent(e.config.watermark)+'&thumbnail='+encodeURIComponent(e.config.thumbnail)+'&fileRecord='+encodeURIComponent(e.config.fileRecord)+'&departmentUploader='+encodeURIComponent(e.config.departmentUploader),width:'100%',height:'100%',onContentLoad:function(){var h=this.getDialog(),i=h.getParentEditor();
i._.filebrowserSe=h.getContentElement('Upload','upload');}}]},{id:'browseUploaded',label:'从已上传中选择',hidden:!e.config.flashUpload,elements:[{type:'iframe',src:CKEDITOR.basePath.replace('/Editor/','/')+(e.config.foreground?'user/Accessories/ShowUploadFiles.aspx':e.config.manageDir+'/Accessories/ShowUploadFiles.aspx')+'?type=flash&CKEditor='+encodeURIComponent(e.name)+'&CKEditorFuncNum='+encodeURIComponent(e._.filebrowserFn),width:'100%',height:'340px',onContentLoad:function(){var h=this.getDialog(),i=h.getParentEditor();i._.filebrowserSe=h.getContentElement('Upload','upload');}}]}]};});})();})();

原来插入flv文件的html代码是
<embed allowfullscreen="true" autostart="true" flashvars="file=/UploadFiles/abc.mp4&showplayer=always&showiconplay=true&usefullscreen=true&autostart=1" height="480" src="/Editor/plugins/media/swf/player_flv_maxi.swf" width="640"></embed>
现在想变成
<embed allowfullscreen="true" flashvars="file=/UploadFiles/abc.mp4&showplayer=always&showiconplay=true&usefullscreen=true&autostart=1" height="360" menu="false" pluginspage="http://www.adobe.com/go/getflashplayer" quality="high" src="/Editor/plugins/media/swf/player_flv_maxi.swf" type="application/x-shockwave-flash" width="640"></embed>
也就是想增加红色部分的内容。因本人不懂语法,请高手不吝赐教。
...全文
187 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
风中的少年 2018-07-17
  • 打赏
  • 举报
回复
var m = '<embed height="100%" width="100%" menu="false" pluginspage="http://www.adobe.com/go/getflashplayer" quality="high" src="' + CKEDITOR.tools.htmlEncode(k);
if (k.indexOf('player_flv_maxi.swf') > 0)
m += '" flashVars="file=' + j + '&showplayer=always&showiconplay=true&usefullscreen=true';
m += '" autostart="true"></embed>';
h.preview.setHtml(m);
yyychn 2018-07-17
  • 打赏
  • 举报
回复
找到了,应该加的地方是
if (g || h && value === i['default']) e.removeAttribute(i.name);
else {
var k = '/Editor/plugins/media/swf/player_flv_maxi.swf';
e.setAttribute(i.name, k);
e.setAttribute('allowFullScreen', 'true');
e.setAttribute('FlashVars', 'file=' + value + '&showplayer=always&showiconplay=true&usefullscreen=true');
return;
}
变成
if (g || h && value === i['default']) e.removeAttribute(i.name);
else {
var k = '/Editor/plugins/media/swf/player_flv_maxi.swf';
e.setAttribute(i.name, k);
e.setAttribute('allowFullScreen', 'true');
e.setAttribute('menu','false');
e.setAttribute('pluginspage','http://www.adobe.com/go/getflashplayer');
e.setAttribute('quality','high');
e.setAttribute('FlashVars', 'file=' + value + '&showplayer=always&showiconplay=true&usefullscreen=true');
e.setAttribute('type','application/x-shockwave-flash');
return;
}
yyychn 2018-07-17
  • 打赏
  • 举报
回复
没有报错信息,就是插入后的内容不包括红色字体部分。本人非专业,不知道是不是有哪部分代码将这段省略掉了。
usecf 2018-07-17
  • 打赏
  • 举报
回复
报什么错误,楼上的写法应该没什么问题
yyychn 2018-07-17
  • 打赏
  • 举报
回复
谢谢楼上的。我在这个位置试过很多次了,结果都没有用,加上去的内容被无视了。

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧