富文本编辑器Summernote增加图片居中(转载)

本文介绍如何为Summernote编辑器添加图片居中功能,通过修改JS文件实现更美观的网页排版效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

使用了一段时间的Tipask,这是一个非常好的建站程序,现在为Tipask共享一些功能 Tipask使用Summernote编辑器,使用中发现没有图片居中的功能,而对于一般的网页正文部分,图片居中排版会美观一些,所以本次通过修改Summernote,添加图片居中功能。

使用了一段时间的Tipask,这是一个非常好的建站程序,现在为Tipask贡献一些功能

Tipask使用Summernote编辑器,使用中发现没有图片居中的功能,而对于一般的网页正文部分,图片居中排版会美观一些,所以本次通过修改Summernote,添加图片居中功能。

1、修改Summernote.min.js

popover: {
        image: [
          ['imagesize', ['imageSize100', 'imageSize50', 'imageSize25']],
          ['float', ['floatLeft', 'floatRight', 'floatCenter', 'floatNone']],
          ['remove', ['removeMedia']]

在上述代码的Float后面,加上floatCenter

image: {
        image: 'Picture',
        insert: 'Insert Image',
        resizeFull: 'Resize Full',
        resizeHalf: 'Resize Half',
        resizeQuarter: 'Resize Quarter',
        floatLeft: 'Float Left',
        floatRight: 'Float Right',
        floatNone: 'Float None',
	floatCenter: 'Float Center',
        shapeRounded: 'Shape: Rounded',
        shapeCircle: 'Shape: Circle',
        shapeThumbnail: 'Shape: Thumbnail',
        shapeNone: 'Shape: None',
        dragImageHere: 'Drag image or text here',
        dropImage: 'Drop image or Text',
        selectFromFiles: 'Select from files',
        maximumFileSize: 'Maximum file size',
        maximumFileSizeError: 'Maximum file size exceeded.',
        url: 'Image URL',
        remove: 'Remove Image'
      },

在上述代码中加入floatCenter: 'Float Center'

然后修改:this.addImagePopoverButtons = function () 函数,添加如下代码:

context.memo('button.floatCenter', function () {
        return ui.button({
          contents: ui.icon(options.icons.alignCenter),
          tooltip: lang.image.floatCenter,
          click: context.createInvokeHandler('editor.floatMe', 'center')
        }).render();
      });

还没有结束,需要修改 this.floatMe = this.wrapCommand(function (value) 函数,改为如下代码

this.floatMe = this.wrapCommand(function (value) {
      var $target = $(this.restoreTarget());
	  if(value=='center'){$target.css('margin', '0 auto');$target.css('float', 'none');$target.css('display', 'block')}else{$target.css('float', value);$target.css('margin', '')}
    });

2、修改summernote-zh-CN.min.js

floatRight:"靠右浮动",后面添加floatCenter:"水平居中"

OK,Summernote中包含图片居中按钮,如图所示:

attachments-2017-09-9br4KKkh59bbdb2bb1486.png

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值