- //https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_dialog_definition.html
- CKEDITOR.plugins.add('dcfile', {
- init: function (editor) {
- var pluginName = 'dcfile';
-
- editor.ui.addButton(pluginName,{
- label: '附件积分',
- command: pluginName,
- icon: this.path + 'images/video.png'
- });
-
- editor.addCommand(pluginName, new CKEDITOR.dialogCommand(pluginName));
-
- CKEDITOR.dialog.add(pluginName, function(editor) {
- return {
- title: "附件上传",
- resizable: CKEDITOR.DIALOG_RESIZE_NONE,
- minWidth: 300,
- minHeight: 80,
- buttons: [{
- id: 'dcfile-button',
- type: 'button',
- label: '上传'
- },
- CKEDITOR.dialog.okButton,
- CKEDITOR.dialog.cancelButton],
- contents: [{
- id: "dcfile-tab",
- label: 'dcfile-label',
- title: "dcfile-title",
- elements: [{
- id: 'score',
- type: "text",
- label: '所需积分',
- className: 'form-control mx-auto w-75',
- //style: 'width: 50%;',
- default: "0",
- required: true,
- //回调函数
- setup: function(editor) {
- //this.setupContent(editor);
- //alert(this.getElement().getId());
- },
- //回调函数
- commit: function(editor) {
- //this.commitContent(editor);
- }
- }]
- }],
- onLoad: function(){
- //this.setupContent(editor);
- var $this = this;
- var $id = '#'+this.getButton('dcfile-button').getElement().getId();
- //this.getContentElement("dcfile-tab","abc").getElement().getHtml()
- daicuo.upload.ajaxLoad(function(){
- daicuo.upload.start({
- element: $($id),
- multiple: true,
- mimeTypes: 'image/*',
- multipart_params: {
- score: 0,
- },
- onInit: function(up){
- $(document).on('change', $($this.getElement()), function(){
- up.setOption("multipart_params", {
- score : $this.getValueOf("dcfile-tab","score")
- })
- });
- },
- onSuccess: function(up, file, xhr){
- //文件名
- if(file.responseTp.data.score){
- var fileName = file.responseTp.data.old_name + '(需要'+file.responseTp.data.score+'个积分)';
- }else{
- var fileName = file.responseTp.data.old_name;
- }
- //插入编辑器
- if(file.responseTp.data.urlId){
- editor.insertHtml('<a class="dc-file" href="'+file.responseTp.data.urlId+'">'+fileName+'</a><br />');
- }else{
- editor.insertHtml('<a class="dc-file" href="'+file.responseTp.data.url+'">'+fileName+'</a><br />');
- }
- //隐藏dialog
- $this.hide();
- }
- });
- });
- },
- onShow: function(){
- //this.setupContent(editor);
- },
- onOk: function() {
- //this.getContentElement( 'tabId', 'elementId' ).setValue( 'Example' );
- //this.commitContent(editor);
- var imgsrc = CKEDITOR.plugins.getPath("dcfile") + "images/play.png";
- editor.insertHtml('<a href="#" data-url="'+this.getValueOf("video","url")+'" class="dc-player"><img src="' + imgsrc + '" alt="点击播放"/></a>');
- }
- };
- });
- }
- });
复制代码
|
|