Skip to content

Commit

Permalink
编辑器添加 drag 上传功能
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhiliang committed Jan 28, 2016
1 parent c208e43 commit 2ebfc1f
Show file tree
Hide file tree
Showing 2,960 changed files with 114,182 additions and 1,823 deletions.
27 changes: 22 additions & 5 deletions App/Admin/Controller/FileController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,30 @@ public function upload() {
$result['code'] = 10015;
$result['message'] = '请先选择图片!';
}
$type = I('get.type', 'file');
switch ($type) {
case 'ck_image':
$funcNum = $_GET['CKEditorFuncNum'];
$url = IMAGE_DOMAIN . $attach_info['url'];
$message = $result['message'];
$this->ajaxReturn("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum, '$url', '$message');</script>", 'EVAL');
break;
case 'ck_drag':
if ($result['code'] === 0) {
$ck_drag_res = array('uploaded' => 1, 'fileName' => $result['data']['title'], 'url' => IMAGE_DOMAIN . $result['data']['url']);
} else {
$ck_drag_res = array('uploaded' => 1, 'error' => array('message' => $result['message']));
}
$this->ajaxReturn($ck_drag_res);
break;
case 'file':
default:
$this->ajaxReturn($result);
break;
}
if (isset($_GET['CKEditor'])) {
$funcNum = $_GET['CKEditorFuncNum'];
$url = IMAGE_DOMAIN . $attach_info['url'];
$message = $result['message'];
$this->ajaxReturn("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction($funcNum, '$url', '$message');</script>", 'EVAL');

} else {
$this->ajaxReturn($result);
}
} else {
$args = $_GET['args'];
Expand Down
38 changes: 27 additions & 11 deletions Framework/Library/Org/Util/Form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Form {
* @param string $disabled_page 是否禁用分页和子标题
*/
public static function editor($textareaid = 'content', $toolbar_type = 'basic', $module = '', $catid = '', $color = '', $allowupload = 0, $allowbrowser = 1,$alowuploadexts = '',$height = 200,$disabled_page = 0, $allowuploadnum = '10') {
$str ='';
$str .= "<script type=\"text/javascript\">\r\n";
$str .= "if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) { CKEDITOR.tools.enableHtml5Elements( document ) };\r\n";
if($toolbar_type == 'basic') {
$toolbar = "[\r\n";
$toolbar .= defined('IN_ADMIN') ? "{ name: 'document', items: [ 'Source' ] },\r\n" : '';
Expand Down Expand Up @@ -55,22 +56,37 @@ public static function editor($textareaid = 'content', $toolbar_type = 'basic',
} else {
$toolbar = '';
}
$str .= "<script type=\"text/javascript\">\r\n";
$str .= "CKEDITOR.replace( '$textareaid',\r\n{\r\nheight:{$height},\r\n";
$ck_options = "{\r\nheight:{$height},\r\n";
if($allowupload) {
$str .="flashupload:true,\r\n" .
/*$ck_options .="flashupload:true,\r\n" .
"alowuploadexts:'".$alowuploadexts."',\r\n" .
"allowbrowser:'".$allowbrowser."',\r\n" .
"allowuploadnum:'".$allowuploadnum."',\r\n";
$str .= "filebrowserUploadUrl : '" . __MODULE__ . "/File/upload',\r\n";
$str .= "filebrowserBrowseUrl: '" . __MODULE__ . "/Attachment/album_list',\r\n";
"allowuploadnum:'".$allowuploadnum."',\r\n";*/
$ck_options .= "imageUploadUrl : '" . __MODULE__ . "/File/upload?type=ck_drag',\r\n";
$ck_options .= "filebrowserUploadUrl : '" . __MODULE__ . "/File/upload?type=ck_image',\r\n";
$ck_options .= "filebrowserBrowseUrl: '" . __MODULE__ . "/Attachment/album_list',\r\n";
}
if($color) {
$str .= "extraPlugins : 'uicolor',uiColor: '$color',";
$ck_options .= "extraPlugins : 'uicolor',uiColor: '$color',";
}
$str .= "toolbar :\r\n";
$str .= $toolbar;
$str .= "});\r\n";
$ck_options .= "toolbar :\r\n";
$ck_options .= $toolbar;
$ck_options .= "}\r\n";
$str .= "( function() {\r\nvar wysiwygareaAvailable = isWysiwygareaAvailable();\r\n" .
"if ( wysiwygareaAvailable ) {\r\n" .
"CKEDITOR.replace( '".$textareaid."', ". $ck_options ." );\r\n" .
"} else {\r\n" .
"var editorElement = CKEDITOR.document.getById( '".$textareaid."' );\r\n" .
"editorElement.setAttribute( 'contenteditable', 'true' );\r\n" .
"CKEDITOR.inline( '".$textareaid."', ". $ck_options ." );\r\n" .
"}\r\n" .
"function isWysiwygareaAvailable() {\r\n" .
"if ( CKEDITOR.revision == ( '%RE' + 'V%' ) ) {\r\n" .
"return true;\r\n" .
"}" .
"return !!CKEDITOR.plugins.get( 'wysiwygarea' );\r\n" .
"}\r\n" .
"} )();";
$str .= '</script>';
return $str;
}
Expand Down
1 change: 1 addition & 0 deletions Public/assets/js/ckeditor/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CKEDITOR.editorConfig = function( config ) {
// config.uiColor = '#AADC6E';
config.defaultLanguage = "zh-cn";
config.skin = 'moonocolor';
config.extraPlugins = 'uploadimage';
config.toolbar = [
{ name: 'document', items: [ 'Source' ] },
{ name: 'basicstyles', items: [ 'Bold', 'Italic', 'Underline', 'Strike', '-', 'RemoveFormat' ] },
Expand Down
226 changes: 216 additions & 10 deletions Public/assets/js/ckeditor/plugins/a11yhelp/dialogs/a11yhelp.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,216 @@
/*
Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.dialog.add("a11yHelp",function(l){var a=l.lang.a11yhelp,n=CKEDITOR.tools.getNextId(),e={8:a.backspace,9:a.tab,13:a.enter,16:a.shift,17:a.ctrl,18:a.alt,19:a.pause,20:a.capslock,27:a.escape,33:a.pageUp,34:a.pageDown,35:a.end,36:a.home,37:a.leftArrow,38:a.upArrow,39:a.rightArrow,40:a.downArrow,45:a.insert,46:a["delete"],91:a.leftWindowKey,92:a.rightWindowKey,93:a.selectKey,96:a.numpad0,97:a.numpad1,98:a.numpad2,99:a.numpad3,100:a.numpad4,101:a.numpad5,102:a.numpad6,103:a.numpad7,104:a.numpad8,
105:a.numpad9,106:a.multiply,107:a.add,109:a.subtract,110:a.decimalPoint,111:a.divide,112:a.f1,113:a.f2,114:a.f3,115:a.f4,116:a.f5,117:a.f6,118:a.f7,119:a.f8,120:a.f9,121:a.f10,122:a.f11,123:a.f12,144:a.numLock,145:a.scrollLock,186:a.semiColon,187:a.equalSign,188:a.comma,189:a.dash,190:a.period,191:a.forwardSlash,192:a.graveAccent,219:a.openBracket,220:a.backSlash,221:a.closeBracket,222:a.singleQuote};e[CKEDITOR.ALT]=a.alt;e[CKEDITOR.SHIFT]=a.shift;e[CKEDITOR.CTRL]=a.ctrl;var f=[CKEDITOR.ALT,CKEDITOR.SHIFT,
CKEDITOR.CTRL],p=/\$\{(.*?)\}/g,t=function(){var a=l.keystrokeHandler.keystrokes,g={},c;for(c in a)g[a[c]]=c;return function(a,c){var b;if(g[c]){b=g[c];for(var h,k,m=[],d=0;d<f.length;d++)k=f[d],h=b/f[d],1<h&&2>=h&&(b-=k,m.push(e[k]));m.push(e[b]||String.fromCharCode(b));b=m.join("+")}else b=a;return b}}();return{title:a.title,minWidth:600,minHeight:400,contents:[{id:"info",label:l.lang.common.generalTab,expand:!0,elements:[{type:"html",id:"legends",style:"white-space:normal;",focus:function(){this.getElement().focus()},
html:function(){for(var e='\x3cdiv class\x3d"cke_accessibility_legend" role\x3d"document" aria-labelledby\x3d"'+n+'_arialbl" tabIndex\x3d"-1"\x3e%1\x3c/div\x3e\x3cspan id\x3d"'+n+'_arialbl" class\x3d"cke_voice_label"\x3e'+a.contents+" \x3c/span\x3e",g=[],c=a.legend,l=c.length,f=0;f<l;f++){for(var b=c[f],h=[],k=b.items,m=k.length,d=0;d<m;d++){var q=k[d],r=q.legend.replace(p,t);r.match(p)||h.push("\x3cdt\x3e%1\x3c/dt\x3e\x3cdd\x3e%2\x3c/dd\x3e".replace("%1",q.name).replace("%2",r))}g.push("\x3ch1\x3e%1\x3c/h1\x3e\x3cdl\x3e%2\x3c/dl\x3e".replace("%1",
b.name).replace("%2",h.join("")))}return e.replace("%1",g.join(""))}()+'\x3cstyle type\x3d"text/css"\x3e.cke_accessibility_legend{width:600px;height:400px;padding-right:5px;overflow-y:auto;overflow-x:hidden;}.cke_browser_quirks .cke_accessibility_legend,{height:390px}.cke_accessibility_legend *{white-space:normal;}.cke_accessibility_legend h1{font-size: 20px;border-bottom: 1px solid #AAA;margin: 5px 0px 15px;}.cke_accessibility_legend dl{margin-left: 5px;}.cke_accessibility_legend dt{font-size: 13px;font-weight: bold;}.cke_accessibility_legend dd{margin:10px}\x3c/style\x3e'}]}],
buttons:[CKEDITOR.dialog.cancelButton]}});
/**
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/

CKEDITOR.dialog.add( 'a11yHelp', function( editor ) {
var lang = editor.lang.a11yhelp,
id = CKEDITOR.tools.getNextId();

// CharCode <-> KeyChar.
var keyMap = {
8: lang.backspace,
9: lang.tab,
13: lang.enter,
16: lang.shift,
17: lang.ctrl,
18: lang.alt,
19: lang.pause,
20: lang.capslock,
27: lang.escape,
33: lang.pageUp,
34: lang.pageDown,
35: lang.end,
36: lang.home,
37: lang.leftArrow,
38: lang.upArrow,
39: lang.rightArrow,
40: lang.downArrow,
45: lang.insert,
46: lang[ 'delete' ],
91: lang.leftWindowKey,
92: lang.rightWindowKey,
93: lang.selectKey,
96: lang.numpad0,
97: lang.numpad1,
98: lang.numpad2,
99: lang.numpad3,
100: lang.numpad4,
101: lang.numpad5,
102: lang.numpad6,
103: lang.numpad7,
104: lang.numpad8,
105: lang.numpad9,
106: lang.multiply,
107: lang.add,
109: lang.subtract,
110: lang.decimalPoint,
111: lang.divide,
112: lang.f1,
113: lang.f2,
114: lang.f3,
115: lang.f4,
116: lang.f5,
117: lang.f6,
118: lang.f7,
119: lang.f8,
120: lang.f9,
121: lang.f10,
122: lang.f11,
123: lang.f12,
144: lang.numLock,
145: lang.scrollLock,
186: lang.semiColon,
187: lang.equalSign,
188: lang.comma,
189: lang.dash,
190: lang.period,
191: lang.forwardSlash,
192: lang.graveAccent,
219: lang.openBracket,
220: lang.backSlash,
221: lang.closeBracket,
222: lang.singleQuote
};

// Modifier keys override.
keyMap[ CKEDITOR.ALT ] = lang.alt;
keyMap[ CKEDITOR.SHIFT ] = lang.shift;
keyMap[ CKEDITOR.CTRL ] = lang.ctrl;

// Sort in desc.
var modifiers = [ CKEDITOR.ALT, CKEDITOR.SHIFT, CKEDITOR.CTRL ];

function representKeyStroke( keystroke ) {
var quotient, modifier,
presentation = [];

for ( var i = 0; i < modifiers.length; i++ ) {
modifier = modifiers[ i ];
quotient = keystroke / modifiers[ i ];
if ( quotient > 1 && quotient <= 2 ) {
keystroke -= modifier;
presentation.push( keyMap[ modifier ] );
}
}

presentation.push( keyMap[ keystroke ] || String.fromCharCode( keystroke ) );

return presentation.join( '+' );
}

var variablesPattern = /\$\{(.*?)\}/g;

var replaceVariables = ( function() {
// Swaps keystrokes with their commands in object literal.
// This makes searching keystrokes by command much easier.
var keystrokesByCode = editor.keystrokeHandler.keystrokes,
keystrokesByName = {};

for ( var i in keystrokesByCode )
keystrokesByName[ keystrokesByCode[ i ] ] = i;

return function( match, name ) {
// Return the keystroke representation or leave match untouched
// if there's no keystroke for such command.
return keystrokesByName[ name ] ? representKeyStroke( keystrokesByName[ name ] ) : match;
};
} )();

// Create the help list directly from lang file entries.
function buildHelpContents() {
var pageTpl = '<div class="cke_accessibility_legend" role="document" aria-labelledby="' + id + '_arialbl" tabIndex="-1">%1</div>' +
'<span id="' + id + '_arialbl" class="cke_voice_label">' + lang.contents + ' </span>',
sectionTpl = '<h1>%1</h1><dl>%2</dl>',
itemTpl = '<dt>%1</dt><dd>%2</dd>';

var pageHtml = [],
sections = lang.legend,
sectionLength = sections.length;

for ( var i = 0; i < sectionLength; i++ ) {
var section = sections[ i ],
sectionHtml = [],
items = section.items,
itemsLength = items.length;

for ( var j = 0; j < itemsLength; j++ ) {
var item = items[ j ],
itemLegend = item.legend.replace( variablesPattern, replaceVariables );

// (#9765) If some commands haven't been replaced in the legend,
// most likely their keystrokes are unavailable and we shouldn't include
// them in our help list.
if ( itemLegend.match( variablesPattern ) )
continue;

sectionHtml.push( itemTpl.replace( '%1', item.name ).replace( '%2', itemLegend ) );
}

pageHtml.push( sectionTpl.replace( '%1', section.name ).replace( '%2', sectionHtml.join( '' ) ) );
}

return pageTpl.replace( '%1', pageHtml.join( '' ) );
}

return {
title: lang.title,
minWidth: 600,
minHeight: 400,
contents: [ {
id: 'info',
label: editor.lang.common.generalTab,
expand: true,
elements: [
{
type: 'html',
id: 'legends',
style: 'white-space:normal;',
focus: function() {
this.getElement().focus();
},
html: buildHelpContents() + '<style type="text/css">' +
'.cke_accessibility_legend' +
'{' +
'width:600px;' +
'height:400px;' +
'padding-right:5px;' +
'overflow-y:auto;' +
'overflow-x:hidden;' +
'}' +
// Some adjustments are to be done for Quirks to work "properly" (#5757)
'.cke_browser_quirks .cke_accessibility_legend,' +
'{' +
'height:390px' +
'}' +
// Override non-wrapping white-space rule in reset css.
'.cke_accessibility_legend *' +
'{' +
'white-space:normal;' +
'}' +
'.cke_accessibility_legend h1' +
'{' +
'font-size: 20px;' +
'border-bottom: 1px solid #AAA;' +
'margin: 5px 0px 15px;' +
'}' +
'.cke_accessibility_legend dl' +
'{' +
'margin-left: 5px;' +
'}' +
'.cke_accessibility_legend dt' +
'{' +
'font-size: 13px;' +
'font-weight: bold;' +
'}' +
'.cke_accessibility_legend dd' +
'{' +
'margin:10px' +
'}' +
'</style>'
}
]
} ],
buttons: [ CKEDITOR.dialog.cancelButton ]
};
} );
Loading

0 comments on commit 2ebfc1f

Please sign in to comment.