bootstrap html编辑器,bootstrap-wysihtml5

This repo is no longer maintained. bootstrap3-wysiwyg is much better

Overview

Bootstrap-wysihtml5 is a javascript plugin that makes it easy to create simple, beautiful wysiwyg editors with the help of wysihtml5 and Twitter Bootstrap.

Examples

Quick Start

If you are using rails use the bootstrap-wysihtml5-rails gem.

gem install bootstrap-wysihtml5-rails

Files to reference

Usage

$('#some-textarea').wysihtml5();

You can get the html generated by getting the value of the text area, e.g.

$('#some-textarea').val();

Advanced

Options

An options object can be passed in to .wysihtml5() to configure the editor:

$('#some-textarea').wysihtml5({someOption: 23, ...})

Buttons

To override which buttons to show, set the appropriate flags:

$('#some-textarea').wysihtml5({

"font-styles": true, //Font styling, e.g. h1, h2, etc. Default true

"emphasis": true, //Italics, bold, etc. Default true

"lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true

"html": false, //Button which allows you to edit the generated HTML. Default false

"link": true, //Button to insert a link. Default true

"image": true, //Button to insert an image. Default true,

"color": false //Button to change color of font

});

Custom Templates for Toolbar Buttons

To define custom templates for buttons, you can submit a customTemplates hash with the new definitions. Each entry should be a function which expects ‘locale’ and optional ‘options’ to manage the translations.

For example, the default template used for the editHtml mode button looks like this (with size fetched from the optional ‘options’)

"

You can change it to not use the pencil icon (for example) by defining the custom template like this:

var myCustomTemplates = {

html : function(locale) {

return "

" +

"

" +

"HTML" +

"

" +

"

";

}

}

// pass in your custom templates on init

$('#some-textarea').wysihtml5({

customTemplates: myCustomTemplates

});

This will override only the toolbar template for html, and all others will use the default.

Stylesheets

It is possible to supply a number of stylesheets for inclusion in the editor ``:

$('#some-textarea').wysihtml5({

"stylesheets": ["/path/to/editor.css"]

});

Events

Wysihtml5 exposes a number of events. You can hook into these events when initialising the editor:

$('#some-textarea').wysihtml5({

"events": {

"load": function() {

console.log("Loaded!");

},

"blur": function() {

console.log("Blured");

}

}

});

Shallow copy by default, deep on request

Options you pass in will be added to the defaults via a shallow copy. (see jQuery.extend for details). You can use a deep copy instead (which is probably what you want if you’re adding tags or classes to parserRules) via ‘deepExtend’, as in the parserRules example below.

Parser Rules

If you find the editor is stripping out tags or attributes you need, then you’ll want to extend (or replace) parserRules. This example extends the defaults to allow the and tags, and the class “middle”:

$('#some-textarea').wysihtml5('deepExtend', {

parserRules: {

classes: {

"middle": 1

},

tags: {

strong: {},

em: {}

}

}

});

There’s quite a bit that can be done with parserRules; see wysihtml5’s advanced parser ruleset for details. bootstrap-wysihtml5’s default parserRules can be found in the source (just search for ‘parserRules’ in the file).

Defaults

You can change bootstrap-wysihtml5’s defaults by altering:

$.fn.wysihtml5.defaultOptions

This object has the same structure as the options object you pass in to .wysihtml5(). You can revert to the original defaults by calling:

$(this).wysihtml5('resetDefaults')

Operations on the defaults are not thread-safe; if you’re going to change the defaults, you probably want to do it only once, after you load the bootstrap-wysihtml plugin and before you start instantiating your editors.

The underlying wysihtml5 object

You can access the wysihtml5 editor object like this:

var wysihtml5Editor = $('#some-textarea').data("wysihtml5").editor;

wysihtml5Editor.composer.commands.exec("bold");

I18n

You can use Bootstrap-wysihtml5 in other languages. There are some translations available in the src/locales directory. You can include your desired one after the plugin and pass its key to the editor. Example:

$('#some-textarea').wysihtml5({locale: "pt-BR"});

It is possible to use custom translations as well. Just add a new key to $.fn.wysihtml5.locale before calling the editor constructor.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值