パッケージの詳細

angular-summernote

outsideris22k0.8.1

AngularJS directive to Summernote

editor, bootstrap, WYSIWYG, angular

readme

angular-summernote - AngularJS directive to Summernote


Build Status Dependency Status Coverage Status

angular-summernote is just a directive to bind summmernote's all features. You can use summernote with angular way.

Since v0.7.x, the version of angular-summernote follows the version of summernote. So, angular-summernote v0.7.x are compatible with summernote v0.7.x and and angular-summernote v0.8.x will be compatible with summernote v0.8.x. Angular-summernote will match only major.minor with summernote. Therefore, angular-summernote v0.7.0 will be compatible with summernote v0.7.0, v0.7.1 and v0.7.2. Angular-summernote will release patch update, such as v0.7.1, if only angular-summernote has changed.

Table of Contents

Demo

See at JSFiddle or run example in projects(need to run bower install before run)

Installation

angular-summernote requires all include files of Summernote. see Summernote's installation.

Project files are also available through your favourite package manager:

  • Bower: bower install angular-summernote

How To Use

When you are done downloading all the dependencies and project files the only remaining part is to add dependencies on the ui.bootstrap AngularJS module:

When you've inclued all js and css files you need to inject a into your angular application:

angular.module('myApp', ['summernote']);

summernote Directive

You can use summernote directive where you want to use summernote editor. And when the scope is destroyed the directive will be destroyed.

As element:

<summernote></summernote>

As attribute:

<div summernote></div>

It will be initialized automatically.

If you put markups in the directive, the markups used as initial text.

<summernote><span style="font-weight: bold;">This is initial text.</span></summernote>

Options

summernote's options can be specified as attributes.

height

<summernote height="300"></summernote>

focus

<summernote focus></summernote>

airmode

<summernote airMode></summernote>

If you use the removeMedia button in popover, like below:

<summernote airMode config="options" on-media-delete="mediaDelete(target)"></summernote>
function DemoController($scope) {
  $scope.options = {
    popover: {
      image: [['remove', ['removeMedia']] ],
      air: [['insert', ['picture']]]
    }
  };
  $scope.mediaDelete = function(target) {
    console.log('media is delted:', target);
  }
}

You can use the 'onMediaDeletecallback. Thetarget` object has information of the DOM that is removed like:

{
  tagName: "IMG",
  attrs: {
    data-filename: "image-name.jpg",
    src: "http://path/to/image",
    style: "width: 100px;"
  }
}

options object

You can specify all options using ngModel in config attribute.

<summernote config="options"></summernote>
function DemoController($scope) {
  $scope.options = {
    height: 300,
    focus: true,
    airMode: true,
    toolbar: [
            ['edit',['undo','redo']],
            ['headline', ['style']],
            ['style', ['bold', 'italic', 'underline', 'superscript', 'subscript', 'strikethrough', 'clear']],
            ['fontface', ['fontname']],
            ['textsize', ['fontsize']],
            ['fontclr', ['color']],
            ['alignment', ['ul', 'ol', 'paragraph', 'lineheight']],
            ['height', ['height']],
            ['table', ['table']],
            ['insert', ['link','picture','video','hr']],
            ['view', ['fullscreen', 'codeview']],
            ['help', ['help']]
        ]
  };
}

NOTE: height and focus attributes have high priority than options object.

NOTE: custom toolbar can be set by options object.

ngModel

summernote's code, that is HTML string in summernote. If you specify ngModel it will be 2-ways binding to HTML string in summernote. Otherwise angular-summernote simply ignore it.

<summernote ng-model="text"></summernote>
function DemoController($scope) {
  $scope.text = "Hello World";
}

And you can use ngModelOptions with Angular v1.3+. So, you can update ngModel when blur event emitted or with a debouncing delay if you want.

Event Listeners

event listeners can be registered as attribute as you want.

function DemoController($scope) {
  $scope.init = function() { console.log('Summernote is launched'); }
  $scope.enter = function() { console.log('Enter/Return key pressed'); }
  $scope.focus = function(e) { console.log('Editable area is focused'); }
  $scope.blur = function(e) { console.log('Editable area loses focus'); }
  $scope.paste = function(e) { console.log('Called event paste'); }
  $scope.change = function(contents) {
    console.log('contents are changed:', contents, $scope.editable);
  };
  $scope.keyup = function(e) { console.log('Key is released:', e.keyCode); }
  $scope.keydown = function(e) { console.log('Key is pressed:', e.keyCode); }
  $scope.imageUpload = function(files) {
    console.log('image upload:', files);
    console.log('image upload\'s editable:', $scope.editable);
  }
}
<summernote on-init="init()" on-enter="enter()" on-focus="focus(evt)"
            on-blur="blur(evt)" on-paste="paste()" on-keyup="keyup(evt)"
            on-keydown="keydown(evt)" on-change="change(contents)"
            on-image-upload="imageUpload(files)" editable="editable" editor="editor">
</summernote>

If you use $editable object in onImageUpload or onChange (see summernote's callback), you should define editable attribute and use it in $scope. (Because AngularJS 1.3.x restricts access to DOM nodes from within expressions)

Since summernote v0.6.4, APIs have been changed. So, If you use the verions, onImageUpload is not return editor object anymore. If you want to user editor object, you should define editor attribute and use it in $scope. Futhermore, you can use summernote's APIs via the editor object.

i18n Support

If you use i18n, you have to include language files. See summernote's document for more details. And then you can specify language like:

<summernote lang="ko-KR"></summernote>

FAQ

  • How to solve compatibility problem with AngularUI Bootstrap?

AngularUI Bootstrap module is written to replace the JavaScript file for bootstrap with its own implementation (ui-bootstrap-tpls.min.js).

Summernote was intended to work with Bootstrap, so the coder implemented features that rely on the bootstrap.js file being present.

  • If you do not include bootstrap.js, summernote throws exceptions.
  • If you do not include ui-bootstrap-tpls.min.js, your angular directives for bootstrap will not work.
  • If you include both, then both JavaScript files try to listen on various events, and otherwise may have incompatibility issues.

If you have a drop down in the navbar, and use data-dropdown directive as bootstrap says to, then two clicks are required to open the drop down (menu) instead of the expected one click.

The solution is to not use data-dropdown directive. However, the real solution is for summernote to be agnostic about which of bootstrap.js or ui-bootstrap-tpls.min.js are loaded and make the right calls. (see #21)

Change Logs

See here.

更新履歴

0.8.1 (2016-03-29)

  • Fix a performance issue that introduced in v0.8.0. There was a reactivating editor problem in case of ngModel is provided and editor's contents updated. #117, #119
  • Support dialogsinbody attribute #121

0.8.0 (2016-02-04)

  • Support Summernote v0.8.x
  • Support [AngularJS 1.5.x]
  • Keep callbacks in the configuration object #112
  • Fix a summernote history stack issue with empty model #109

0.7.1 (2016-01-22)

  • Fix a bug that load 2 editor on IE(it is a workaround) #98
  • Fix a bug when content is empty #105
  • Support placeholder, min height and max height options #97, #104
  • Supoort on-media-delete callback #92

0.7.0 (2015-12-11)

  • Make compatible with summernote v0.7.0

0.5.2 (2015-11-29)

  • fix a broken ngModel binding with angular 1.3 #84

0.5.1 (2015-10-05)

  • Support initial text from inner markup in directive #77

0.5.0 (2015-08-19)

0.4.2 (2015-08-19)

  • bug fixes
    • fix "Maximum call stack size exceeded" error in airmode #62
    • clean ngModel when content is empty #53

0.4.0 (2015-05-25)

Breaking changes

  • Support Summernote v0.6.4+. It's not compatible with the version under v0.6.4. If you use summernote v0.6.3-, use angular-summernote v0.3.2.
  • Now, editor object exposed via editor attribute.

Features

  • Support ngModelOptions
  • Support onToolbarClick event
  • Publish in npm registry

0.3.2 (2015-02-13)

  • bug fixes
    • fix to avoid inprog error with outer scope #34)

0.3.1 (2014-12-25)

  • summernote organization maintains angular-summernote now.
  • Upgrade summernote to v0.6.0
  • bug fixes
    • fix Referencing a DOM node in Expression Error(see #25)

0.3.0 (2014-10-19)

Support AngularJS 1.3.0

  • bug fixes (#20)

0.2.4 (2014-10-04)

  • bug fixes (#19)

0.2.3 (2014-09-04)

Bug fixes

  • ngModel is synchronized with insert images (#15)

0.2.2 (2014-05-11)

Bug Fixes

  • ngModel is synchronized when summernote's codeview mode is enabled. (#7)

0.2.1 (2014-02-23)

Bug Fixes

  • ngModel is syncronized when text is changed using toolbar (#4)

0.2.0 (2014-01-26)

This release adds ngModel support

Features

  • support ngModel attribute(code attribute is removed)

Breaking Changes

  • use ngModel attribute instead code attribute for 2-ways binding.

    To migrate your code change your markup like below.

    Before:

<summernote code="text"></summernote>

After:

<summernote ng-model="text"></summernote>

0.1.1 (2014-01-18)

Very first, initial release.

Features

summernote direcive was released with the following directives:

  • summernote directive
  • height and focus attributes
  • config attribute
  • code attribute
  • on-init, on-enter, on-foucs, on-blur, on-keyup, on-keydown and on-image-upload attributes for event listeners
  • lang attribute for i18n