tinymce.PluginManager.add('o2upimgs', function(editor, url) {
var pluginName='多图片上传';
debugger;
var o2upimgs = window["o2upimgs_"+editor.id]= {}; //扔外部公共变量,也可以扔一个自定义的位置
var baseURL=tinymce.baseURL;
var iframe1 = baseURL+'/plugins/o2upimgs/upfiles.html';
var base64Encode = editor.getParam('base64Encode', false);
var images_upload_handler = editor.getParam('images_upload_handler', undefined, 'function');
if( !images_upload_handler ){
//var enablePreview = editor.getParam('enablePreview', true);
var localImageMaxWidth = editor.getParam('localImageMaxWidth', 2000);
var reference = editor.getParam('reference');
var referenceType = editor.getParam('referenceType');
images_upload_handler = function(blobInfo, success, failure, image){
debugger;
var file = blobInfo.blob();
var formData = new FormData();
formData.append('file', file, file.name );
MWF.xDesktop.uploadImageByScale( reference, referenceType, localImageMaxWidth, formData, file, function (responseData) {
var id = responseData.data ? responseData.data.id : responseData.id;
var orgid = responseData.data ? responseData.data.origId : responseData.origId;
var src = MWF.xDesktop.getImageSrc( id );
var width = image.naturalWidth;
var height = image.naturalHeight;
//按最大宽度比率缩小
if( localImageMaxWidth && localImageMaxWidth < width ){
height = parseInt( height * (localImageMaxWidth / width) );
}
width = Math.min(width, localImageMaxWidth);
var attributes = {
"data-id": id,
"data-orgid": orgid,
"data-height": ''+height,
"data-width": ''+width,
"data-filename": file.name || '',
"style": 'max-width:100%; width:' + width + 'px',
"onerror": 'MWF.xDesktop.setImageSrc()',
"alt": file.name || '',
"data-prv": 'true' //enablePreview ? 'true' : 'false'
};
if(success)success(src, attributes);
}, function () {
if(failure)failure();
return true;
});
}
}
o2upimgs.images_upload_handler = images_upload_handler;
o2upimgs.images_upload_base_path = editor.getParam('images_upload_base_path', '', 'string');
o2upimgs.o2upimgs_filetype = editor.getParam('o2upimgs_filetype', '.png,.gif,.jpg,.jpeg', 'string');
o2upimgs.res=[];
var openDialog = function() {
return editor.windowManager.openUrl({
title: pluginName,
size: 'large',
url:iframe1,
buttons: [
{
type: 'cancel',
text: 'Close'
},
{
type: 'custom',
text: 'Save',
name: 'save',
primary: true
},
],
onAction: function (api, details) {
switch (details.name) {
case 'save':
o2upimgs.iframeWindow.querySave(function () {
var html = '';
var imgs = o2upimgs.res;
var len = imgs.length;
for(var i=0;i';
}
}
editor.insertContent(html);
o2upimgs.res=[];
editor.fire( 'change' );
api.close();
})
break;
default:
break;
}
}
});
};
editor.ui.registry.getAll().icons.o2upimgs || editor.ui.registry.addIcon('o2upimgs','');
editor.ui.registry.addButton('o2upimgs', {
icon: 'o2upimgs',
tooltip: pluginName,
onAction: function() {
openDialog();
}
});
editor.ui.registry.addMenuItem('o2upimgs', {
icon: 'o2upimgs',
text: '图片批量上传...',
onAction: function() {
openDialog();
}
});
return {
getMetadata: function() {
return {
name: pluginName
// url: "http://tinymce.ax-z.cn/more-plugins/axupimgs.php",
};
}
};
});