项目作者: vsymguysung

项目描述 :
ember cli addon for summernote
高级语言: JavaScript
项目地址: git://github.com/vsymguysung/ember-cli-summernote.git
创建时间: 2014-12-06T21:25:22Z
项目社区:https://github.com/vsymguysung/ember-cli-summernote

开源协议:MIT License

下载


Ember-cli-summernote

Build Status
NPM Downlaads
npm version

Ember Observer Score

Description

Ember-cli-summernote is an Ember CLI add-on. This addon actually converts summernote to an Ember component which is
a re-usable unit. This is still a work in progress. Pull requests are welcome.

DEMO

Installation

  1. # install via npm
  2. $ npm install ember-cli-summernote --save-dev
  3. # make ember-cli fetch internal dependencies
  4. $ ember g ember-cli-summernote

Basic Usage

Handlebar Template

As of version 1.1.0, the addon embraces DDAU.
The content property is readonly and onContentChange action is used for updated contents.

  1. import Ember from 'ember';
  2. export default Ember.ObjectController.extend({
  3. contentHeight: 200,
  4. postContent: "Some intial contents go here. Lorem Ipsum is simply dummy text of the printing.",
  5. editingDisabled: false,
  6. actions: {
  7. onContentChange(text) {
  8. set(this, 'postContent', text);
  9. },
  10. changeHeight(someObject) {
  11. let height = someObject.doSomeCalculationToGetHeight();
  12. set(this, 'contentHeight', height)
  13. }
  14. }
  15. });

As a result to follow DDAU, the summernote internall callback onChange will not be supported through the callbacks property in a consumming application.

  1. {{summer-note height=contentHeight
  2. btnSize=bs-sm
  3. airMode=false
  4. focus=false
  5. header="Example"
  6. content=(readonly postContent)
  7. onContentChange=(action 'onContentChange')
  8. disabled=editingDisabled
  9. callbacks=callbackOptions
  10. toolbarOptions=toolbarOptions}}

Example of configuring the toolbar options.

  1. toolbarOptions: {
  2. style: false,
  3. insert: {
  4. picture: false
  5. },
  6. help: false
  7. }

Custom buttons usage

In hbs file

  1. {{summer-note content=article customButtons=customButtons}}

In controller file

  1. import Ember from 'ember';
  2. export default Ember.Controller.extend({
  3. article: 'some text',
  4. customButtons: [],
  5. init() {
  6. let _onNewBlock = this.get('onNewBlock').bind(this);
  7. let newBlockButton = function (context) {
  8. var ui = $.summernote.ui;
  9. var button = ui.button({
  10. contents: '<i class="fa fa-file-text-o"></i> New div',
  11. tooltip: 'New div',
  12. click: _onNewBlock
  13. });
  14. return button.render();
  15. }
  16. this.customButtons.push(newBlockButton);
  17. },
  18. onNewBlock() {
  19. let blocks = '<div class="header" id="headerBlock"></div>';
  20. this.set('article', article + blocks);
  21. }
  22. });

All callbacks except onChange are supported.

The onChange callback are used internally for the onContentChange action.

  1. callbackOptions: {
  2. onInit: function() {
  3. console.log('Summernote is launched');
  4. },
  5. onEnter: function() {
  6. console.log('Enter/Return key pressed');
  7. },
  8. onPaste: function(e) {
  9. console.log('Called event paste');
  10. },
  11. },

config/environment.js

The bootstrap resources will not be imported to your resources by default.

Also you can set lang option for the editor.

  1. var ENV = {
  2. modulePrefix: 'dummy',
  3. environment: environment,
  4. ...
  5. 'ember-cli-summernote': {
  6. "importBootstrapCSS": true,
  7. "importBootstrapJS": true,
  8. "lang": "en-US // "ru-RU" //"lang": "en-US"
  9. }
  10. }

Test Helper

This addon also provides a convenient test helper to interact with the editor
in acceptance tests.

  1. fillInSummernote('.summernote-container', '<p>Test Text Entered.</p>');
  2. getContentFromSummernote('.summernote-container');

Demo

You can clone this repo and run the app

  1. $ sudo npm install -g ember-cli
  2. # clone the codebase
  3. $ git clone http://github.com/vsymguysung/ember-cli-summernote.git
  4. $ cd ember-cli-summernote
  5. # install dependencies
  6. $ npm install; bower install
  7. # fire up local server
  8. $ ember serve
  9. # visit the page with the following url.
  10. http://localhost:4200

Inspired by

License

MIT license.