精品伊人久久大香线蕉,开心久久婷婷综合中文字幕,杏田冲梨,人妻无码aⅴ不卡中文字幕

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
ckeditor 自己寫的一個簡單的image上傳js 運用iframe的ajax上傳

ckeditor最近修改一個上傳的,原來的Image的上傳插件功能很多,但是自己用,沒有必要,就進行了修改,后來就改成了目前的樣子,根據_samples/api_dialog.html 進行了修改,把頁面里面的調用都進行了修改.

1.添加網址和上傳在一個tab中

2.圖片上傳之后會直接把生成的值放到圖片網址的input中。


1.index.html調用頁面

 

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
  2. <html xmlns="http://www.w3.org/1999/xhtml">   
  3. <head>   
  4.     <title>Using API to customize dialogs - CKEditor Sample</title>   
  5.     <meta content="text/html; charset=utf-8" http-equiv="content-type" />   
  6.     <script type="text/javascript" src="./ckeditor.js"></script>   
  7.     <script type="text/javascript" src="./mydialog.js"></script>   
  8. </head>   
  9. <body>   
  10.     <h1>   
  11.         CKEditor Sample   
  12.     </h1>   
  13.     <textarea cols="80" id="editor1" name="editor1" rows="10"><p>This is some <strong>sample text</strong>. You are using <a >CKEditor</a>.</p></textarea>   
  14.     <script type="text/javascript">   
  15.             //調用封裝的函數   
  16.             makeEditor('editor1');   
  17.     </script>   
  18. </body>   
  19. </html>  
 

2. mydialog.js

 

  1. //外部調用函數   
  2. function makeEditor(id) {   
  3.     CKEDITOR.on( 'dialogDefinition', function( ev )   
  4.     {   
  5.             var dialogName = ev.data.name;   
  6.             var dialogDefinition = ev.data.definition;   
  7.             if ( dialogName == 'link' )   
  8.             {   
  9.                     var infoTab = dialogDefinition.getContents( 'info' );   
  10.                     //刪除不要的標簽頁中選項   
  11.                     infoTab.remove( 'linkType' );   
  12.                     infoTab.remove( 'browse' );   
  13.                     var urlField = infoTab.get( 'url' );   
  14.                     //更改鏈接的文字   
  15.                     urlField['label'] = '鏈接地址';   
  16.                     //刪除不要的tab標簽頁   
  17.                     dialogDefinition.removeContents( 'target' );   
  18.                     dialogDefinition.removeContents( 'advanced' );   
  19.                     //由于filebrowserUploadUrl的使用,刪除鏈接dialog中出現的upload標簽頁   
  20.                     dialogDefinition.removeContents( 'upload' );   
  21.             }   
  22.     });   
  23.     var editor = CKEDITOR.replace( id,   
  24.     {   
  25.         toolbar : [[ 'Source','-','Bold','Italic','Underline','Strike','-','Link','-','Unlink','-','AddImage']],   
  26.         //引入上傳   
  27.         filebrowserUploadUrl : 'http://127.0.0.1/editor/upload.php'  
  28.     });   
  29.     editor.on( 'pluginsLoaded', function( ev )   
  30.     {   
  31.         if ( !CKEDITOR.dialog.exists( 'myAddImage' ) )   
  32.         {   
  33.                 //生成調用js的地址 窗體函數   
  34.                 var href = 'http://' + window.location.host + '/editor/myAddImage.js';   
  35.                 CKEDITOR.dialog.add( 'myAddImage', href );   
  36.         }   
  37.         editor.addCommand( 'myImageCmd', new CKEDITOR.dialogCommand( 'myAddImage' ) );   
  38.         editor.ui.addButton( 'AddImage',   
  39.         {   
  40.                 label : '圖片',   
  41.                 icon:'images/images.jpg', //增加按鈕圖標   
  42.                 command : 'myImageCmd'  
  43.         });   
  44.     });   
  45. }   
  46.   
  47. //獲取CKEditorFuncNum的值   
  48. function getUrlParam(url)   
  49. {   
  50.   var reParam = new RegExp('(?:[\?&]|&)CKEditorFuncNum=([^&]+)', 'i') ;   
  51.   var match = url.match(reParam) ;   
  52.     
  53.   return (match && match.length > 1) ? match[1] : '' ;   
  54. }   
  55. /*  
  56.  * iframe的onload  
  57.  * params:  
  58.  *        t   obj iframe  
  59.  *        num int anonymous function number used to pass the url of a file to CKEditor (random number)  
  60.  */  
  61. function iframeLoad(t, num){   
  62.     t.style.display = 'none';   
  63.     var ret = t.contentWindow.document.body.innerHTML;   
  64.     var fchild = t.contentWindow.document.body.firstChild;   
  65.     // fchild.nodeType { 1 => form, 3 => textNode}    
  66.     if (fchild.nodeType == 3) {   
  67.         //我返回的ret是json數據,進行處理   
  68.         var data = eval("("+ret+")");    
  69.         if(data.picurl) {    
  70.             picurl = data.picurl;   
  71.             //觸發filebrowser   
  72.             CKEDITOR.tools.callFunction(num, picurl);   
  73.         } else if(data.error) {    
  74.             CKEDITOR.tools.callFunction(num, '', '上傳失敗'+data.error);   
  75.         }      
  76.     }   
  77.     t.style.display = '';   
  78. }  
 

3. myAddImage.js

 

  1. CKEDITOR.dialog.add( 'myAddImage', function( editor )   
  2. {   
  3.     var ADDIMAGE = 1,   
  4.     regexGetSizeOrEmpty = /(^\s*(\d+)((px)|\%)?\s*$)|^$/i;   
  5.     return {   
  6.             title : '添加圖片',   
  7.             minWidth : 400,   
  8.             minHeight : 200,   
  9.             contents :    
  10.             [   
  11.                 {   
  12.                     id : 'addImage',   
  13.                     label : '添加圖片',   
  14.                     title : '添加圖片',   
  15.                     filebrowser : 'uploadButton',   
  16.                     elements :   
  17.                     [   
  18.                       {       
  19.                           id : 'txtUrl',   
  20.                           type : 'text',   
  21.                           label : '圖片網址',   
  22.                           required: true  
  23.                       },   
  24.                       {   
  25.                             id : 'photo',   
  26.                             type : 'file',   
  27.                             label : '上傳圖片',   
  28.                             style: 'height:40px',   
  29.                             size : 38   
  30.                       },   
  31.                       {   
  32.                            type : 'fileButton',   
  33.                            id : 'uploadButton',   
  34.                            label : '上傳',   
  35.                            filebrowser :   
  36.                            {   
  37.                                 action : 'QuickUpload',   
  38.                                 target : 'addImage:txtUrl'//更新的文本標簽   
  39.                            },   
  40.                            onClick: function(){   
  41.                                 var d = this.getDialog();   
  42.                                 var _txtUrl = d.getContentElement('addImage','txtUrl');   
  43.                                 var _photo =  d.getContentElement('addImage','photo');   
  44.                                 var _frameId = _photo._.frameId;   
  45.                                 var _iframe =  CKEDITOR.document.getById(_frameId);   
  46.                                 //給iframe添加onload事件   
  47.                                 _iframe.setAttribute('onload',    
  48.                                         'getAjaxResult(this,'+getUrlParam(_photo.action)+')');   
  49.                            },   
  50.                            'for' : [ 'addImage', 'photo']   
  51.                       }   
  52.                     ]   
  53.                 }   
  54.            ],   
  55.            onOk : function(){   
  56.                _src = this.getContentElement('addImage', 'txtUrl').getValue();   
  57.                if (_src.match(regexGetSizeOrEmpty)) {   
  58.                    alert('請輸入網址或者上傳文件');   
  59.                    return false;   
  60.                }   
  61.                this.imageElement = editor.document.createElement( 'img' );   
  62.                this.imageElement.setAttribute( 'alt', '' );   
  63.                this.imageElement.setAttribute( 'src', _src );   
  64.                editor.insertElement( this.imageElement );   
  65.            }   
  66.     };   
  67.  });  
 

4. upload.php頁面,就直接返回了些數據,php的上傳程序就略過了

 

  1. <?php   
  2. $str = '{"picurl":/l.jpg"}';   
  3. $str = '{"error":-304}';   
  4. echo $str;   
  5. ?>  
 

生成的dialog的樣子和editor

 

 

 

本站僅提供存儲服務,所有內容均由用戶發布,如發現有害或侵權內容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
CKEditor 多圖片上傳插件(一) (二)
fckeditor配置詳解-易博園
ckeditor 使用、獲取數據、設置數據
在JSP里使用CKEditor和CKFinder
php網頁調用ckeditor
thinkphp下ckeditor+ckfinder的圖片上傳配置 - 美拓blog
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯系客服!

聯系客服

主站蜘蛛池模板: 高碑店市| 水富县| 罗江县| 塔城市| 阳原县| 涿鹿县| 扎赉特旗| 来宾市| 古浪县| 饶河县| 万全县| 闻喜县| 新野县| 牙克石市| 龙陵县| 中超| 宝清县| 石家庄市| 天台县| 南澳县| 彝良县| 耒阳市| 南充市| 六盘水市| 布尔津县| 隆尧县| 仁布县| 萨嘎县| 淅川县| 莒南县| 信阳市| 泊头市| 和平区| 房产| 高碑店市| 封开县| 介休市| 夏河县| 绥德县| 安岳县| 惠州市|