123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- /**
- * video插件, 为UEditor提供视频插入支持
- * @file
- * @since 1.2.6.1
- */
- UE.plugins['video'] = function (){
- var me =this;
- /**
- * 创建插入视频字符窜
- * @param url 视频地址
- * @param width 视频宽度
- * @param height 视频高度
- * @param align 视频对齐
- * @param toEmbed 是否以flash代替显示
- * @param addParagraph 是否需要添加P 标签
- */
- function creatInsertStr(url,width,height,id,align,classname,type){
- var str;
- switch (type){
- case 'image':
- str = '<img ' + (id ? 'id="' + id+'"' : '') + ' width="'+ width +'" height="' + height + '" _url="'+url+'" class="' + classname.replace(/\bvideo-js\b/, '') + '"' +
- ' 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;'+(align ? 'float:' + align + ';': '')+'" />'
- break;
- case 'embed':
- var ext = url.substr(url.lastIndexOf('.') + 1);
- if(ext == 'mp4' || ext == 'flv'){
- str = '<object id="f4Player" width="' + width + '" height="' + height + '"' + (align ? ' style="float:' + align + '"': '') + ' type="application/x-shockwave-flash" class="' + classname + '" data="/statics/js/ckeditor/plugins/flashplayer/player/player.swf"> <param name="movie" value="/statics/js/ckeditor/plugins/flashplayer/player/player.swf" /> <param name="quality" value="high" /> <param name="menu" value="false" /> <param name="scale" value="noscale" /> <param name="allowfullscreen" value="true"> <param name="allowscriptaccess" value="always"> <param name="swlivevonnect" value="true" /> <param name="cachebusting" value="false"><param name="flashvars" value="autoplay=1&skin=/statics/js/ckeditor/plugins/flashplayer/player/skin.swf&video=' + utils.html(url) + '&thumbnail="/></object>';
- }else{
- str = '<embed type="application/x-shockwave-flash" class="' + classname + '" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
- ' src="' + utils.html(url) + '" width="' + width + '" height="' + height + '"' + (align ? ' style="float:' + align + '"': '') +
- ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
- }
- break;
- case 'video':
- var ext = url.substr(url.lastIndexOf('.') + 1);
- if(ext == 'ogv') ext = 'ogg';
- str = '<video' + (id ? ' id="' + id + '"' : '') + ' class="' + classname + ' video-js" ' + (align ? ' style="float:' + align + '"': '') +
- ' controls preload="none" width="' + width + '" height="' + height + '" src="' + url + '" data-setup="{}">' +
- '<source src="' + url + '" type="video/' + ext + '" /></video>';
- break;
- }
- return str;
- }
- function switchImgAndVideo(root,img2video){
- utils.each(root.getNodesByTagName(img2video ? 'img' : 'embed video'),function(node){
- var className = node.getAttr('class');
- if(className && className.indexOf('edui-faked-video') != -1){
- var html = creatInsertStr( img2video ? node.getAttr('_url') : node.getAttr('src'),node.getAttr('width'),node.getAttr('height'),null,node.getStyle('float') || '',className,img2video ? 'embed':'image');
- node.parentNode.replaceChild(UE.uNode.createElement(html),node);
- }
- if(className && className.indexOf('edui-upload-video') != -1){
- var html = creatInsertStr( img2video ? node.getAttr('_url') : node.getAttr('src'),node.getAttr('width'),node.getAttr('height'),null,node.getStyle('float') || '',className,img2video ? 'video':'image');
- node.parentNode.replaceChild(UE.uNode.createElement(html),node);
- }
- })
- }
- me.addOutputRule(function(root){
- switchImgAndVideo(root,true)
- });
- me.addInputRule(function(root){
- switchImgAndVideo(root)
- });
- /**
- * 插入视频
- * @command insertvideo
- * @method execCommand
- * @param { String } cmd 命令字符串
- * @param { Object } videoAttr 键值对对象, 描述一个视频的所有属性
- * @example
- * ```javascript
- *
- * var videoAttr = {
- * //视频地址
- * url: 'http://www.youku.com/xxx',
- * //视频宽高值, 单位px
- * width: 200,
- * height: 100
- * };
- *
- * //editor 是编辑器实例
- * //向编辑器插入单个视频
- * editor.execCommand( 'insertvideo', videoAttr );
- * ```
- */
- /**
- * 插入视频
- * @command insertvideo
- * @method execCommand
- * @param { String } cmd 命令字符串
- * @param { Array } videoArr 需要插入的视频的数组, 其中的每一个元素都是一个键值对对象, 描述了一个视频的所有属性
- * @example
- * ```javascript
- *
- * var videoAttr1 = {
- * //视频地址
- * url: 'http://www.youku.com/xxx',
- * //视频宽高值, 单位px
- * width: 200,
- * height: 100
- * },
- * videoAttr2 = {
- * //视频地址
- * url: 'http://www.youku.com/xxx',
- * //视频宽高值, 单位px
- * width: 200,
- * height: 100
- * }
- *
- * //editor 是编辑器实例
- * //该方法将会向编辑器内插入两个视频
- * editor.execCommand( 'insertvideo', [ videoAttr1, videoAttr2 ] );
- * ```
- */
- /**
- * 查询当前光标所在处是否是一个视频
- * @command insertvideo
- * @method queryCommandState
- * @param { String } cmd 需要查询的命令字符串
- * @return { int } 如果当前光标所在处的元素是一个视频对象, 则返回1,否则返回0
- * @example
- * ```javascript
- *
- * //editor 是编辑器实例
- * editor.queryCommandState( 'insertvideo' );
- * ```
- */
- me.commands["insertvideo"] = {
- execCommand: function (cmd, videoObjs, type){
- videoObjs = utils.isArray(videoObjs)?videoObjs:[videoObjs];
- if(me.fireEvent('beforeinsertvideo', videoObjs) === true){
- return;
- }
- var html = [],id = 'tmpVedio', cl;
- for(var i=0,vi,len = videoObjs.length;i<len;i++){
- vi = videoObjs[i];
- cl = (type == 'upload' ? 'edui-upload-video video-js vjs-default-skin':'edui-faked-video');
- html.push(creatInsertStr( vi.url, vi.width || 420, vi.height || 280, id + i, null, cl, 'image'));
- }
- me.execCommand("inserthtml",html.join(""),true);
- var rng = this.selection.getRange();
- for(var i= 0,len=videoObjs.length;i<len;i++){
- var img = this.document.getElementById('tmpVedio'+i);
- domUtils.removeAttributes(img,'id');
- rng.selectNode(img).select();
- me.execCommand('imagefloat',videoObjs[i].align)
- }
- me.fireEvent('afterinsertvideo', videoObjs);
- },
- queryCommandState : function(){
- var img = me.selection.getRange().getClosedNode(),
- flag = img && (img.className == "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1);
- return flag ? 1 : 0;
- }
- };
- };
|