├── README.md
├── emotion
├── 01.gif
├── 02.gif
├── 03.gif
├── 04.gif
├── 05.gif
├── 06.gif
├── 07.gif
├── 08.gif
├── 09.gif
├── 10.gif
├── 11.gif
├── 12.gif
├── 13.gif
├── 14.gif
├── 15.gif
├── 16.gif
├── 17.gif
├── 18.gif
├── 19.gif
├── 20.gif
├── 21.gif
├── 22.gif
├── 23.gif
├── 24.gif
├── 25.gif
├── 26.gif
├── 27.gif
├── 28.gif
├── 29.gif
└── 30.gif
├── gulpfile.js
├── index.html
├── static
├── css
│ └── main.css
└── js
│ ├── editor.js
│ └── editor.min.js
└── upload.php
/README.md:
--------------------------------------------------------------------------------
1 | #简介
2 | liteditor是一款小巧的富文本编辑器,无任何依赖,适合那些追求简洁高效的朋友使用。
3 | 演示地址:http://yrdr.github.io/liteditor/
4 | 1. 目前普通功能支持IE9+浏览器
5 | 2. 上传图片比较特殊,需要IE10+支持
6 | 3. 暂不支持跨域上传图片
7 |
8 | #使用方法
9 | 使用方法请参照index.html的配置
10 | 此版本为开发版,请不要直接用于生产环境
11 |
--------------------------------------------------------------------------------
/emotion/01.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/01.gif
--------------------------------------------------------------------------------
/emotion/02.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/02.gif
--------------------------------------------------------------------------------
/emotion/03.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/03.gif
--------------------------------------------------------------------------------
/emotion/04.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/04.gif
--------------------------------------------------------------------------------
/emotion/05.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/05.gif
--------------------------------------------------------------------------------
/emotion/06.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/06.gif
--------------------------------------------------------------------------------
/emotion/07.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/07.gif
--------------------------------------------------------------------------------
/emotion/08.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/08.gif
--------------------------------------------------------------------------------
/emotion/09.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/09.gif
--------------------------------------------------------------------------------
/emotion/10.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/10.gif
--------------------------------------------------------------------------------
/emotion/11.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/11.gif
--------------------------------------------------------------------------------
/emotion/12.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/12.gif
--------------------------------------------------------------------------------
/emotion/13.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/13.gif
--------------------------------------------------------------------------------
/emotion/14.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/14.gif
--------------------------------------------------------------------------------
/emotion/15.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/15.gif
--------------------------------------------------------------------------------
/emotion/16.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/16.gif
--------------------------------------------------------------------------------
/emotion/17.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/17.gif
--------------------------------------------------------------------------------
/emotion/18.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/18.gif
--------------------------------------------------------------------------------
/emotion/19.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/19.gif
--------------------------------------------------------------------------------
/emotion/20.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/20.gif
--------------------------------------------------------------------------------
/emotion/21.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/21.gif
--------------------------------------------------------------------------------
/emotion/22.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/22.gif
--------------------------------------------------------------------------------
/emotion/23.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/23.gif
--------------------------------------------------------------------------------
/emotion/24.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/24.gif
--------------------------------------------------------------------------------
/emotion/25.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/25.gif
--------------------------------------------------------------------------------
/emotion/26.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/26.gif
--------------------------------------------------------------------------------
/emotion/27.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/27.gif
--------------------------------------------------------------------------------
/emotion/28.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/28.gif
--------------------------------------------------------------------------------
/emotion/29.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/29.gif
--------------------------------------------------------------------------------
/emotion/30.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yrdr/liteditor/ee2457ece7464cf348004411bb7d665c75db801f/emotion/30.gif
--------------------------------------------------------------------------------
/gulpfile.js:
--------------------------------------------------------------------------------
1 | var gulp = require('gulp'),
2 | concat = require('gulp-concat'),
3 | uglify = require('gulp-uglify'),
4 | rename = require('gulp-rename'),
5 | del = require('del');
6 |
7 | gulp.task('minifyjs', function() {
8 | return gulp.src('./static/js/editor.js')
9 | .pipe(rename({suffix: '.min'})) //rename压缩后的文件名
10 | .pipe(uglify()) //压缩
11 | .pipe(gulp.dest('./static/js')); //输出
12 | });
13 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ', _this = this;
1040 | Selector.each(color, function(item) {
1041 | html += '
';
1042 | });
1043 | this.data.colorDialog = Dialog({
1044 | title : '调色板',
1045 | width : 200,
1046 | content : html
1047 | });
1048 | Selector.addEvent(this.data.colorDialog.content.querySelector('.color'), 'click', function(e) {
1049 | _this.execCommand('foreColor', false, e.target.style.background);
1050 | });
1051 | }
1052 | this.data.colorDialog.show();
1053 | },
1054 |
1055 | //链接操作框
1056 | createLinkCommand : function(url, target) {
1057 | var selection;
1058 | this.recoveryRange();
1059 | this.execCommand('createLink', false, url);
1060 | selection = this.getSelection();
1061 | if (target && selection.anchorNode.parentNode.tagName == 'A') {
1062 | selection.anchorNode.parentNode.setAttribute('target', '_blank');
1063 | }
1064 | this.data.link.hide();
1065 | },
1066 |
1067 | //添加链接
1068 | createLink : function(url, checked) {
1069 | if (!this.data.link) {
1070 | var _this = this, data = {};
1071 | Selector.extend(data, createLinkDialog());
1072 | data.link.appendChild(data.input);
1073 | data.link.appendChild(data.checkbox);
1074 | data.link.appendChild(data.label);
1075 | this.data.link = Dialog({
1076 | title : '添加链接',
1077 | width : 250,
1078 | height : 80,
1079 | content : data.link,
1080 | confirm : function() {
1081 | if (/\/\//.test(data.input.value)) {
1082 | _this.createLinkCommand(data.input.value, data.checkbox.checked);
1083 | } else {
1084 | Dialog.tip('链接格式错误');
1085 | }
1086 | }
1087 | });
1088 | this.data.linkvar = data;
1089 | }
1090 | url && (this.data.linkvar.input.value = url);
1091 | checked && (this.data.linkvar.checkbox.checked = true);
1092 | this.data.link.show();
1093 | },
1094 |
1095 | //移除链接
1096 | unLink : function() {
1097 | this.execCommand('unLink', false, null);
1098 | return this;
1099 | },
1100 |
1101 | //插入视频
1102 | video : function() {
1103 | if (!this.data.videoDialog) {
1104 | var _this = this, url, id, video;
1105 | this.data.videoDialog = Dialog({
1106 | title : '添加视频',
1107 | width : 400,
1108 | height : 80,
1109 | content : '
'
1110 | });
1111 | this.data.videoDialog.confirm(function() {
1112 | url = _this.data.videoDialog.content.querySelector('.url').value;
1113 | video = '';
1114 | if (url.length < 20) {
1115 | Dialog.tip('链接格式错误');
1116 | } else if (/(https?:\/\/)?\w+\.youku\.com/i.test(url) && (id = url.match(/id_(\w+)/i)) && id[1]) {
1117 | video = 'http://player.youku.com/embed/' + id[1];
1118 | } else if (/(https?:\/\/)?\w+\.qq\.com/i.test(url) && (id = url.match(/vid=(\w+)/i)) && id[1]) {
1119 | video = 'http://v.qq.com/iframe/player.html?vid=' + id[1] + '&tiny=0&auto=0';
1120 | } else {
1121 | Dialog.tip('暂时只支持优酷和腾讯视频');
1122 | }
1123 | if (video) {
1124 | _this.recoveryRange();
1125 | _this.insertAtRange('
');
1126 | }
1127 | });
1128 | }
1129 | this.data.videoDialog.show();
1130 | },
1131 |
1132 | //插入表情
1133 | emotion : function() {
1134 | if (!this.data.emotion) {
1135 | var emotion = Selector.create('div', {
1136 | className : 'emotion',
1137 | innerHTML : createEmotionDialog()
1138 | }), _this = this;
1139 | this.data.emotion = Dialog({
1140 | title : '添加表情',
1141 | width : 240,
1142 | content : emotion
1143 | });
1144 | Selector.addEvent(emotion, 'click', function(e) {
1145 | _this.saveRange();
1146 | if (e.target.tagName == 'IMG') {
1147 | _this.recoveryRange();
1148 | _this.execCommand('insertImage', false, e.target.src);
1149 | }
1150 | });
1151 | }
1152 | this.data.emotion.show();
1153 | },
1154 |
1155 | //撤销操作
1156 | undo : function() {
1157 | //待定功能
1158 | this.execCommand('undo');
1159 | }
1160 | };
1161 |
1162 | global[variable] = function(options) {
1163 | return new Editor(options).focus().saveRange();
1164 | }
1165 |
1166 | }(window, 'Editor'));
1167 |
--------------------------------------------------------------------------------
/static/js/editor.min.js:
--------------------------------------------------------------------------------
1 | !function(t,e){"use strict";function n(e){var n={editor:l(l.create("div",{className:"editor"})),tools:l(l.create("div",{className:"tools",unSelectable:"on",innerHTML:i(e.tools)})),content:l(l.create("div",{className:"content",contentEditable:"true"}))};return n.editor.append(n.tools,n.content),n.content.css("minHeight",t.document.body.clientHeight+"px"),e.textarea.before(n.editor),e.textarea.hide(),n}function i(t){var e,n="";for(e in h)(!t||!t.length||l.inArray(h[e].name,t)>-1)&&(n+='
");return n}function o(t,e){t.bind("click",function(t){"BUTTON"==t.target.tagName&&t.target.name in e&&e[t.target.name](),e.saveRange()})}function a(e,n){var i,o,a;e.bind("click",function(e){for(i=t.getSelection(),o=!1,a=e.target;a!=n.content[0]&&!o;){switch(a.tagName){case"A":i.selectAllChildren(a),n.createLink(a.href,"_blank"==a.target),e.preventDefault(),o=!0}a=a.parentNode}n.saveRange(i.getRangeAt(0))})}function r(){return{link:l.create("div",{className:"link"}),input:l.create("input",{type:"text",placeholder:"请输入链接"}),checkbox:l.create("input",{type:"checkbox"}),label:l.create("label",{innerHTML:"新窗口打开"})}}function s(){var t,e="";for(t=1;31>t;t++)e+='

';return e}function c(){var t="";return t+='
上传图片网络图片
',t+='
',t+='
',t+='',t+='',t+="
",t+='
',t+='',t+='',t+="
"}var l,u,d,h,p,f;l=function(t,e){return new l.prototype.__init__(t,e)},l.prototype={constructor:l,__init__:function(e,n){if("string"===l.type(e))e=(n||t.document).querySelectorAll(e);else{if(!e.nodeType)return this;e=[e]}return l.extend(this,{0:e.length>1?e:e[0],length:e.length,context:n})},each:function(t){return l.each(this.length>1?this[0]:[this[0]],t)},eq:function(t){return 0==t||this.length<2?this:l(this[0][t])},show:function(){return 1==this.length?this[0].style.display="":l.eachCall("show",this[0]),this},hide:function(){return 1==this.length?this[0].style.display="none":l.eachCall("hide",this[0]),this},attr:function(t,e){return"string"!=typeof e?this[0].getAttribute(t):function(n){return"string"==typeof t?n[0].setAttribute(t,e):l.each(t,function(t,e){n[0].setAttribute(e,t)}),n}(this)},css:function(t,e){return"undefined"==typeof e&&"string"==typeof t?this[0].style[t]:function(n){return"string"==typeof t?n[0].style[t]=e:l.each(t,function(t,e){n[0].style[e]=t}),n}(this)},html:function(t){return"string"!=typeof t?this[0].innerHTML:function(e){return e[0].innerHTML=t,e}(this)},append:function(){var t,e;for(t=0;t
-1&&(e="node")),e},l.eachCall=function(t,e){l.each(e,function(e){l.prototype[t].call([e])})},l.isArray=function(t){return"array"===this.type(t)},l.each=function(t,e){for(var n in t)e.apply(t[n],[t[n],n])},l.create=function(e,n){if(e=t.document.createElement(e),"undefined"!=typeof n){var i,o;i=function(t,e){for(o in e)"string"==typeof e[o]||e[o].length?t[o]=e[o]:i(t[o],e[o])},i(e,n)}return e},l.inArray=function(t,e){var n,i=-1;if(Array.prototype.indexOf)e.indexOf(t);else for(n=0;n '}),content:l.create("div",{className:"content"})}),this.dialog.appendChild(this.content),this.title=this.dialog.querySelector(".title span"),l.addEvent(this.dialog.querySelector(".title i"),"click",function(){t.hide()}),this.setContent(this.options.content).setTitle(this.options.title),this.options.confirm&&this.confirm(this.options.confirm),this},setTitle:function(t){return this.title.innerHTML=t,this},setContent:function(t){return"string"==typeof t?this.content.innerHTML=t:(this.content.innerHTML="",this.content.appendChild(t)),this},confirm:function(t){var e;return e=l.create("div",{className:"confirm"}),this.confirm=l.create("input",{type:"button",value:"确定"}),e.appendChild(this.confirm),this.dialog.appendChild(e),l.addEvent(this.confirm,"click",function(){t()}),this},setAttribute:function(){return this.options.height>50&&(this.content.style.height=this.options.height+"px"),l.extend(this.dialog.style,{width:this.options.width+"px",top:"100px",left:(t.screen.availWidth-this.options.width)/2+"px"}),t.document.body.appendChild(this.dialog),!0},show:function(){return this.exist||(this.exist=this.setAttribute()),this.dialog.style.display="",this},hide:function(){return this.dialog.style.display="none",this}},f.prototype.__init__.prototype=f.prototype,f.cover=function(){function e(){return l.create("div",{className:"cover",style:{height:t.screen.availHeight+"px"}})}return{show:function(){e.cover||(e.cover=l(e()).appendTo(t.document.body)),e.cover.show()},hide:function(){e.cover.hide()}}}(),f.tip=function(){function e(){return l.create("div",{className:"tip"})}return function(n){e.tip||(e.tip=l(e()).appendTo(t.document.body)),e.tip.html(n).show().css({top:"100px",left:(t.document.body.offsetWidth-e.tip.width())/2+"px"}),setTimeout(function(){e.tip.hide()},2500)}}(),p=["#000000","#fff","#000066","#000099","#0000CC","#0000FF","#0033CC","#0033FF","#006600","#006633","#006666","#006699","#009966","#009999","#0099CC","#0099FF","#00CC00","#00CC33","#666600","#666666","#6666CC","#669900","#669966","#6699CC","#66CCCC","#66CCFF","#66FF00","#66FF99","#66FFFF","#990000","#996600","#996666","#9966CC","#9966FF","#999900","#999966","red","#CC3366","#CC9966","#CC9999","#CCCC00","#F78B00"],h=[{name:"cleanFormat",icon:"",tip:"清除格式"},{name:"justifyLeft",icon:"",tip:"左对齐"},{name:"justifyCenter",icon:"",tip:"居中对齐"},{name:"justifyRight",icon:"",tip:"右对齐"},{name:"bold",icon:"",tip:"加粗"},{name:"table",icon:"",tip:"表格"},{name:"insertUnorderedList",icon:"",tip:"无序列表"},{name:"insertOrderedList",icon:"",tip:"有序列表"},{name:"insertImage",icon:"",tip:"图片"},{name:"color",icon:"",tip:"文字颜色"},{name:"createLink",icon:"",tip:"超链接"},{name:"unLink",icon:"",tip:"取消超链接"},{name:"video",icon:"",tip:"视频"},{name:"emotion",icon:"",tip:"表情"},{name:"undo",icon:"",tip:"撤销操作"}],d=function(t){this.options=l.extend({textarea:null,width:null,height:null,allowImage:!0,allowUploadImage:!0,uploadImageUrl:null,tools:null},t),this.data={},"string"==typeof this.options.textarea&&(this.options.textarea=l(this.options.textarea)),l.extend(this,n(this.options)),o(this.tools,this),a(this.content,this)},d.prototype={constructor:d,focus:function(){return this.content[0].focus(),this},getSelection:function(){return t.getSelection()},saveRange:function(t){return this.data.range=t?t.cloneRange():function(t,e){return t.rangeCount?t.getRangeAt(0).cloneRange():e.data.range||null}(this.getSelection(),this),this},recoveryRange:function(){return this.focus(),this.data.range&&(this.data.range.commonAncestorContainer==this.content[0]||this.isContains(this.content[0],this.data.range.commonAncestorContainer))&&(this.data.selection=this.getSelection(),this.data.selection.removeAllRanges(),this.data.selection.addRange(this.data.range),this.data.range=this.data.selection.getRangeAt(0)),this},execCommand:function(e,n,i){return t.document.execCommand(e,n||!1,i||null)},insertAtRange:function(t,e){var n;return"string"==typeof t&&(t=l.htmlToFragment(t)),e=e||this.getSelection(),n=e.getRangeAt(0),n.deleteContents(),n.insertNode(t),e.addRange(n),this},searchParent:function(t,e){return"string"==typeof e?(t&&!t.tagName||t.tagName!=e&&t.parentNode)&&(t=this.searchParent(t.parentNode,e)):t!=e&&t.parentNode&&(t=this.searchParent(t.parentNode,e)),("string"==typeof e?t.tagName:t)==e?t:null},isContains:function(t,e){return"string"==typeof e?t.tagName!=e&&t.firstChild?t=t.querySelector(e):t.tagName!=e&&(t=null):t!=e&&(t=l.contains(t,e)),t?!0:!1},getContent:function(){return this.content.html()},setContent:function(t){return this.content.html(t),this},cleanFormat:function(){var t,e,n;return t=this.getSelection(),n=l.htmlToFragment(t.toString()),e=t.getRangeAt(0),e.deleteContents(),e.insertNode(n),t.addRange(e),this.execCommand("RemoveFormat")},justifyLeft:function(){return this.execCommand("justifyLeft"),this},justifyCenter:function(){return this.execCommand("justifyCenter"),this},justifyRight:function(){return this.execCommand("justifyRight"),this},bold:function(){return this.execCommand("bold",!1,[]),this},table:function(){if(!this.data.tableDialog){var t,e,n,i,o=this,a="";this.data.tableDialog=f({title:"表格",width:150,height:60,content:'',e=this;l.each(p,function(e){t+='
'}),this.data.colorDialog=f({title:"调色板",width:200,content:t}),l.addEvent(this.data.colorDialog.content.querySelector(".color"),"click",function(t){e.execCommand("foreColor",!1,t.target.style.background)})}this.data.colorDialog.show()},createLinkCommand:function(t,e){var n;this.recoveryRange(),this.execCommand("createLink",!1,t),n=this.getSelection(),e&&"A"==n.anchorNode.parentNode.tagName&&n.anchorNode.parentNode.setAttribute("target","_blank"),this.data.link.hide()},createLink:function(t,e){if(!this.data.link){var n=this,i={};l.extend(i,r()),i.link.appendChild(i.input),i.link.appendChild(i.checkbox),i.link.appendChild(i.label),this.data.link=f({title:"添加链接",width:250,height:80,content:i.link,confirm:function(){/\/\//.test(i.input.value)?n.createLinkCommand(i.input.value,i.checkbox.checked):f.tip("链接格式错误")}}),this.data.linkvar=i}t&&(this.data.linkvar.input.value=t),e&&(this.data.linkvar.checkbox.checked=!0),this.data.link.show()},unLink:function(){return this.execCommand("unLink",!1,null),this},video:function(){if(!this.data.videoDialog){var t,e,n,i=this;this.data.videoDialog=f({title:"添加视频",width:400,height:80,content:'
'}),this.data.videoDialog.confirm(function(){t=i.data.videoDialog.content.querySelector(".url").value,n="",t.length<20?f.tip("链接格式错误"):/(https?:\/\/)?\w+\.youku\.com/i.test(t)&&(e=t.match(/id_(\w+)/i))&&e[1]?n="http://player.youku.com/embed/"+e[1]:/(https?:\/\/)?\w+\.qq\.com/i.test(t)&&(e=t.match(/vid=(\w+)/i))&&e[1]?n="http://v.qq.com/iframe/player.html?vid="+e[1]+"&tiny=0&auto=0":f.tip("暂时只支持优酷和腾讯视频"),n&&(i.recoveryRange(),i.insertAtRange('
'))})}this.data.videoDialog.show()},emotion:function(){if(!this.data.emotion){var t=l.create("div",{className:"emotion",innerHTML:s()}),e=this;this.data.emotion=f({title:"添加表情",width:240,content:t}),l.addEvent(t,"click",function(t){e.saveRange(),"IMG"==t.target.tagName&&(e.recoveryRange(),e.execCommand("insertImage",!1,t.target.src))})}this.data.emotion.show()},undo:function(){this.execCommand("undo")}},t[e]=function(t){return new d(t).focus().saveRange()}}(window,"Editor");
--------------------------------------------------------------------------------
/upload.php:
--------------------------------------------------------------------------------
1 | $code,
24 | 'msg' => $message,
25 | 'items' => $items
26 | ]);
27 | exit;
28 | }
29 |
30 | /**
31 | * 构造函数,检测目录
32 | */
33 | public function __construct()
34 | {
35 | $this->save_path = __DIR__ . '/' . $this->save_path;
36 | clearstatcache();
37 | if (!is_dir($this->save_path)) {
38 | $this->showMessage(0, $this->save_path . '不存在');
39 | } else if (is_writable($this->save_path)) {
40 | $this->makeDir($this->save_path);
41 | } else {
42 | $this->showMessage(0, '目录权限不足');
43 | }
44 | }
45 |
46 | /**
47 | * 获取文件存储路径
48 | * @param $file
49 | * @param $extension
50 | * @return string
51 | */
52 | private function getFilePath($file, $extension)
53 | {
54 | return $this->save_path . md5($file) . $extension;
55 | }
56 |
57 | /**
58 | * 循环生成目录
59 | * @param $path
60 | * @return bool
61 | */
62 | public function makeDir($path){
63 | return is_dir($path) || ($this->makeDir(dirname($path)) && mkdir($path, 0777));
64 | }
65 |
66 | /**
67 | * 上传图片实现
68 | */
69 | public function start()
70 | {
71 | $file = $_POST['file'];
72 | list($type, $file) = explode(',', $file);
73 | preg_match('/(jpeg|png|gif)/', $type, $extension);
74 | if (!isset($extension[1])) {
75 | $this->showMessage(0, '图片格式错误');
76 | }
77 | if ($extension[1] == 'jpeg') {
78 | $extension[1] = 'jpg';
79 | }
80 | $path = $this->getFilePath($file, $extension[1]);
81 | if (file_put_contents($path, base64_decode($file), true)) {
82 | $this->showMessage(1, '上传成功', str_ireplace($this->save_path, $this->http_path, $path));
83 | } else {
84 | $this->showMessage(0, '文件写入失败,请检查目录权限');
85 | }
86 | }
87 | }
88 |
89 | $upload = new Upload();
90 | $upload->start();
--------------------------------------------------------------------------------