[ckeditor系列]ckeditor 自己寫的一個簡單的image上傳js 運用iframe的ajax上傳

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

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

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


1.index.html調用頁面

.html代碼?復制代碼?收藏代碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml">   
<head>   <title>Using API to customize dialogs - CKEditor Sample</title>   <meta content="text/html; charset=utf-8" http-equiv="content-type" />   <script type="text/javascript" src="./ckeditor.js"></script>   <script type="text/javascript" src="./mydialog.js"></script>   
</head>   
<body>   <h1>   CKEditor Sample   </h1>   <textarea cols="80" id="editor1" name="editor1" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea>   <script type="text/javascript">   //調用封裝的函數   
            makeEditor('editor1');   </script>   
</body>   
</html>  

2. mydialog.js

?

//外部調用函數   
function makeEditor(id) {   CKEDITOR.on( 'dialogDefinition', function( ev )   {   var dialogName = ev.data.name;   var dialogDefinition = ev.data.definition;   if ( dialogName == 'link' )   {   var infoTab = dialogDefinition.getContents( 'info' );   //刪除不要的標簽頁中選項   infoTab.remove( 'linkType' );   infoTab.remove( 'browse' );   var urlField = infoTab.get( 'url' );   //更改鏈接的文字   urlField['label'] = '鏈接地址';   //刪除不要的tab標簽頁   dialogDefinition.removeContents( 'target' );   dialogDefinition.removeContents( 'advanced' );   //由于filebrowserUploadUrl的使用,刪除鏈接dialog中出現的upload標簽頁   dialogDefinition.removeContents( 'upload' );   }   });   var editor = CKEDITOR.replace( id,   {   toolbar : [[ 'Source','-','Bold','Italic','Underline','Strike','-','Link','-','Unlink','-','AddImage']],   //引入上傳   filebrowserUploadUrl : 'http://127.0.0.1/editor/upload.php'  });   editor.on( 'pluginsLoaded', function( ev )   {   if ( !CKEDITOR.dialog.exists( 'myAddImage' ) )   {   //生成調用js的地址 窗體函數   var href = 'http://' + window.location.host + '/editor/myAddImage.js';   CKEDITOR.dialog.add( 'myAddImage', href );   }   editor.addCommand( 'myImageCmd', new CKEDITOR.dialogCommand( 'myAddImage' ) );   editor.ui.addButton( 'AddImage',   {   label : '圖片',   icon:'images/images.jpg', //增加按鈕圖標   command : 'myImageCmd'  });   });   
}   //獲取CKEditorFuncNum的值   
function getUrlParam(url)   
{   var reParam = new RegExp('(?:[\?&]|&amp;)CKEditorFuncNum=([^&]+)', 'i') ;   var match = url.match(reParam) ;   return (match && match.length > 1) ? match[1] : '' ;   
}   
/*  * iframe的onload  * params:  *        t   obj iframe  *        num int anonymous function number used to pass the url of a file to CKEditor (random number)  */  
function iframeLoad(t, num){   t.style.display = 'none';   var ret = t.contentWindow.document.body.innerHTML;   var fchild = t.contentWindow.document.body.firstChild;   // fchild.nodeType { 1 => form, 3 => textNode}    if (fchild.nodeType == 3) {   //我返回的ret是json數據,進行處理   var data = eval("("+ret+")");    if(data.picurl) {    picurl = data.picurl;   //觸發filebrowser   
            CKEDITOR.tools.callFunction(num, picurl);   } else if(data.error) {    CKEDITOR.tools.callFunction(num, '', '上傳失敗'+data.error);   }      }   t.style.display = '';   

3. myAddImage.js

CKEDITOR.dialog.add( 'myAddImage', function( editor )   
{   var ADDIMAGE = 1,   regexGetSizeOrEmpty = /(^\s*(\d+)((px)|\%)?\s*$)|^$/i;   return {   title : '添加圖片',   minWidth : 400,   minHeight : 200,   contents :    [   {   id : 'addImage',   label : '添加圖片',   title : '添加圖片',   filebrowser : 'uploadButton',   elements :   [   {       id : 'txtUrl',   type : 'text',   label : '圖片網址',   required: true  },   {   id : 'photo',   type : 'file',   label : '上傳圖片',   style: 'height:40px',   size : 38   },   {   type : 'fileButton',   id : 'uploadButton',   label : '上傳',   filebrowser :   {   action : 'QuickUpload',   target : 'addImage:txtUrl'//更新的文本標簽   
                           },   onClick: function(){   var d = this.getDialog();   var _txtUrl = d.getContentElement('addImage','txtUrl');   var _photo =  d.getContentElement('addImage','photo');   var _frameId = _photo._.frameId;   var _iframe =  CKEDITOR.document.getById(_frameId);   //給iframe添加onload事件   _iframe.setAttribute('onload',    'getAjaxResult(this,'+getUrlParam(_photo.action)+')');   },   'for' : [ 'addImage', 'photo']   }   ]   }   ],   onOk : function(){   _src = this.getContentElement('addImage', 'txtUrl').getValue();   if (_src.match(regexGetSizeOrEmpty)) {   alert('請輸入網址或者上傳文件');   return false;   }   this.imageElement = editor.document.createElement( 'img' );   this.imageElement.setAttribute( 'alt', '' );   this.imageElement.setAttribute( 'src', _src );   editor.insertElement( this.imageElement );   }   };   });  

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

?

Php代碼?復制代碼?收藏代碼
  1. <?php ??
  2. $str?=?'{"picurl":/l.jpg"}'; ??
  3. $str?=?'{"error":-304}'; ??
  4. echo?$str; ??
  5. ?>??

?

生成的dialog的樣子和editor

?

?

?

原文地址:http://www.cnblogs.com/hannover/archive/2011/07/29/2121545.html

轉載于:https://www.cnblogs.com/101rico/archive/2013/01/20/2868398.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/274381.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274381.shtml
英文地址,請注明出處:http://en.pswp.cn/news/274381.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

sql 避免除0錯誤_設計簡歷時避免這3個常見的UX錯誤

sql 避免除0錯誤重點 (Top highlight)Having a great looking resume on hand is very important when you’re looking for a job. It is your ticket to land the interview that will get you one step closer to that one job you’ve been dreaming of.在找工作時&#xf…

一個網站自動化測試程序的設計與實現

CSDN博客不再經常更新&#xff0c;更多優質文章請來 粉絲聯盟網 FansUnion.cn! (FansUnion) 代碼 下載地址&#xff1a;http://download.csdn.net/detail/fansunion/5018357(免積分) 代碼亮點&#xff1a;可讀性很好&#xff0c;注釋詳盡 背景 工作中&#xff0c;在維護一…

如何編寫數據庫可視化界面_編寫用于數據可視化的替代文本

如何編寫數據庫可視化界面什么是替代文字 (What is Alt Text) Alt text (sometimes called Alt tags or alternative text) are written descriptions added to images that convey the meaning of the visual. Good alt text helps more people understand the content. Assis…

(轉)swc與swf的區別

在Flash Builder中用Actionscript寫的類可以打包成swc或swf&#xff0c; 在Flash CS中制作的元件也可以打包成swc或swf文件&#xff0c; 一個swc或swf文件中可以包含多個類或元件&#xff0c; 每個元件會映射成一個類&#xff0c; 因此&#xff0c;在Flash Builder中的類和在Fl…

js 驗證各種格式類型的正則表達式

<script src"scripts/jquery-1.4.1.js" type"text/javascript"></script> <script language"javascript" type"text/javascript"> /** * 定義驗證各種格式類型的正則表達式對象 */ var Regexs { email: …

reloaddata 跳動_紙跳動像素

reloaddata 跳動I would like to open with a problem.我想開一個問題。 Why are so many designer going straight to pixels?為什么這么多設計師直接使用像素&#xff1f; Over the past few years i’ve witnessed this in my team, my clients and others throughout th…

使用自定義RadioButton和ViewPager實現TabHost效果和帶滑動的頁卡效果。

參考自http://www.apkbus.com/android-86125-1-1.html 這篇文章技術含量一般&#xff0c;大家別見笑。源碼我以測試&#xff0c;在底部可下載。 好了先上效果圖&#xff1a; 以下是實現步驟&#xff1a; 1、準備自定義RadioButton控件的樣式圖片等&#xff0c;就是準…

利益相關者軟件工程_改善開發人員團隊與非技術利益相關者之間交流的方法

利益相關者軟件工程Whether you’re working on a startup or a big company, keeping your stakeholders and non-technical partners engaged and up to date on what the tech team has been building can be hard.無論您是在初創公司還是大公司中工作&#xff0c;都要讓您的…

Hibernate的檢索策略

Hibernate的Session在加載一個Java對象時&#xff0c;可以將與這個對象相關聯的其他Java對象都加載到緩存中&#xff0c;以便程序及時調用。但有些情況下&#xff0c;我們不需要加載太多無用的對象到緩存中&#xff0c;一來這樣會撐爆內存&#xff0c;二來增加了訪問數據庫的次…

響應式網格項目動畫布局_響應式網格及其實際使用方式:常見的UI布局

響應式網格項目動畫布局重點 (Top highlight)第二部分 (Part II) Now that you have a basic understanding of how to use grids, you might be wondering how to apply them to layouts you see on the web. Responsive grids are a method to systematically align your des…

SQL函數大全

SQL函數大全 --聚合函數use pubsgoselect avg(distinct price) --算平均數from titleswhere typebusinessgo use pubsgoselect max(ytd_sales) --最大數from titlesgo use pubsgoselect min(ytd_sales) --最小數from titlesgo use pubsgoselect type,sum(price),sum(advanc…

時間軸ui設計_我應該在UI設計上花更多時間嗎?

時間軸ui設計Let’s start with an example of communication skills: they are important for any profession, and you expect any professional to have a decent level. However, excellent communication skills won’t make up for the lack of core expertise. Imagine …

一、Oracle介紹

Oracle學習筆記 一、 Oracle介紹 選擇數據庫的標準 項目的規模 負載量多大&#xff0c;用戶量多少 成本 安全性 Oracle 認證 初級&#xff1a;OCA&#xff1a;Oracle Certificated Associate 中級&#xff1a;OCP&#xff1a;Oracle Certificated Professional 高級&#xff…

移動端分步注冊_移動應用程序的可用性測試:分步指南

移動端分步注冊Written by Justin Mifsud由賈斯汀米夫蘇德 ( Justin Mifsud)撰寫 The mobile market is huge and growing at a very fast rate. With an estimated 4.5 billion subscribers worldwide, it is forecasted that the number of mobile phones will surpass the …

ldd隨筆(1)-linux設備模型

一下只是個人學習后的理解&#xff0c;可能有很多不對的地方。 要學習linux的設備驅動模型&#xff0c;首先必須要知道kobject和kset的概念&#xff0c;下面是kobject在2.6.38的源碼中的實現。 struct kobject {const char *name; //名稱&#xff0c;可能在sysfs中創…

插圖 引用 同一行兩個插圖_提出食物主題中的插圖

插圖 引用 同一行兩個插圖I have a page in my portfolio, which is about search functionality. I wanted that page to feel fun and engaging, to convey a positive vibe, so I decided to add illustrations to it.我的投資組合中有一個頁面與搜索功能有關。 我希望該頁面…

Hadoop的SequenceFile讀寫實例

1 SequenceFile可以處理hdfs上大量小文件&#xff0c;它可以作為大量小文件的容器。HDFS和MapReduce是針對大文件優化的&#xff0c;所以通過SequenceFile類型將小文件包裝起來可以獲得更高效的存儲和處理。存儲2 在SequenceFile中的鍵和值并不一定是Writable類型&#xff…

臉部細微表情識別_您可以僅使用面部表情來控制字體嗎?

臉部細微表情識別原型 (The prototype) Facetype is the name of Adam’s interactive project, in which the emotions detected from a person’s facial gestures control a variable font. To each detected emotion corresponds a specific typeface, which keeps transfo…

ssky-keygen + ssh-copy-id 無密碼登陸遠程LINUX主機

使用下例中ssky-keygen和ssh-copy-id&#xff0c;僅需通過3個步驟的簡單設置而無需輸入密碼就能登錄遠程Linux主機。 ssh-keygen 創建公鑰和密鑰。 ssh-copy-id 把本地主機的公鑰復制到遠程主機的authorized_keys文件上。ssh-copy-id 也會給遠程主機的用戶主目錄&#xff08;ho…

uva10891Game of sum

題意:經典的取石子游戲是這樣的:有一堆石子&#xff0c;A、B兩個人輪流取&#xff0c;每次取一顆&#xff0c;只能從邊上取&#xff0c;每個石子有相應的價值&#xff0c;A、B兩人都想使得自己的價值最多&#xff0c;兩個人足夠聰明&#xff0c;問最后價值分別是多少 本題則是可…