求助替换js中的某段代码

yyychn 2018-07-15 08:34:29
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');}}]}]};});})();})();

通过该插件插入视频,插入成功后其html代码是:
<embed autostart="true" flashvars="null&autostart=1" height="360" src="/UploadFiles/shejianshang.mp4" width="640"></embed></p>
因为该代码有些局限性,现在想成功后的代码变成:
<embed allowfullscreen="true" flashvars="vcastr_file=/UploadFiles/shejianshang.mp4&BufferTime=3&IsAutoPlay=1&IsContinue=1" height="360" menu="false" pluginspage="http://www.adobe.com/go/getflashplayer" quality="high" src="/editor/plugins/flvplayer.swf" type="application/x-shockwave-flash" width="640"></embed>
求教高手,该如何修改上面的js文件(注:红色字体为变量,可以从表单域获得)
...全文
260 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
风中的少年 2018-07-17
  • 打赏
  • 举报
回复
修改。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>
';
风中的少年 2018-07-17
  • 打赏
  • 举报
回复


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);
};
丰云 2018-07-16
  • 打赏
  • 举报
回复
引用 2 楼 yyychn 的回复:
不是问要修改哪个文件,而是修改指定的这个js文件,让插入后生成的代码符合要求。


走点心,认真整理下你的表述吧。。。。。

搞得好像比人不懂你的意思一样。。。。虽然你的表达本身很有问题。。。。
奔跑的小鱼儿 2018-07-16
  • 打赏
  • 举报
回复
http://tool.chinaz.com/Tools/jsformat.aspx
用上面的工具把原来的代码格式化之后再插入
yyychn 2018-07-16
  • 打赏
  • 举报
回复
不是问要修改哪个文件,而是修改指定的这个js文件,让插入后生成的代码符合要求。
丰云 2018-07-16
  • 打赏
  • 举报
回复


打开图中红框标识的文件夹,去里面找你的js

87,922

社区成员

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

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