[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.mzph.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…

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;都要让您的…

响应式网格项目动画布局_响应式网格及其实际使用方式:常见的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…

时间轴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 …

移动端分步注册_移动应用程序的可用性测试:分步指南

移动端分步注册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 …

插图 引用 同一行两个插图_提出食物主题中的插图

插图 引用 同一行两个插图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.我的投资组合中有一个页面与搜索功能有关。 我希望该页面…

脸部细微表情识别_您可以仅使用面部表情来控制字体吗?

脸部细微表情识别原型 (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…

uva10891Game of sum

题意:经典的取石子游戏是这样的:有一堆石子&#xff0c;A、B两个人轮流取&#xff0c;每次取一颗&#xff0c;只能从边上取&#xff0c;每个石子有相应的价值&#xff0c;A、B两人都想使得自己的价值最多&#xff0c;两个人足够聪明&#xff0c;问最后价值分别是多少 本题则是可…

用户体验设计师能为seo做_用户体验设计师可以从产品设计历史中学到什么

用户体验设计师能为seo做Many things have changed from tool design in the prehistoric era to today’s digital product design. However, we can see surprisingly many similarities. Especially when it comes down to one particular aspect: usability.从史前时代的工…

orton效果_如何使图片发光:Orton效果

orton效果Have you ever seen an impossibly dream-like landscape photo? One with a slow burning, glowing sunset. That’s really the best way to describe it, the image looks as if it’s glowing. You might be thinking, “wow, I wish I was that good and could …

UVA10785 The Mad Numerologist

虽然是sorting的压轴&#xff0c;但是比起前面真心水题。这个专题结合前面string的很多&#xff0c;排序相对简单了&#xff0c;qsort基本解决。 题目&#xff1a; The Mad Numerologist Numerology is a science that is used by many people to find out a mans personality,…

苹果人机交互指南_苹果人机界面设计指南的10个见解

苹果人机交互指南重点 (Top highlight)I’ve been developing an IOS app for the past few months and have been constantly referring to Apple’s Human Interface Design Guidelines. I would consider it a must-read for any aspiring or current UI/UX designer.在过去…

也来学学插件式开发

上一家公司有用到插件式开发来做一个工具箱&#xff0c;类似于QQ电脑管家&#xff0c;有很多工具列表&#xff0c;点一下工具下载后就可以开始使用了。可惜在那家公司待的时候有点短&#xff0c;没有好好研究一下。现在有空&#xff0c;自己在网上找了些资料&#xff0c;也来试…

同态加法_我对同态的想法

同态加法Early February, I uploaded this shot onto Dribbble. Nothing fancy –– just two screens experimenting with “2月初&#xff0c;我将这张照片上传到Dribbble。 没什么幻想–只有两个屏幕在尝试“ Neumorphism,” or soft UI. Little did I know that this post…

php内核探索

引自&#xff1a;http://www.nowamagic.net/librarys/veda/detail/1285 SAPI:Server Application Programming Interface 服务器端应用编程端口。研究过PHP架构的同学应该知道这个东东的重要性&#xff0c;它提供了一个接口&#xff0c;使得PHP可以和其他应用进行交互数据。 本…

hp-ux锁定用户密码_UX设计101:用户研究-入门需要了解的一切

hp-ux锁定用户密码这是什么&#xff1f; (What is this?) This session is part of a learning curriculum that I designed to incrementally skill up and empower a team of Designers and Researchers whose skillset and ways of working needed to evolve to keep up wi…