Giter VIP home page Giter VIP logo

angular-summernote's Introduction

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.

angular-summernote's People

Contributors

bharat-dpd avatar biodiscus avatar cavarzan avatar erikvullings avatar genu avatar insanehong avatar jodinathan avatar kolesnikov-sergey avatar outsideris avatar shadybones avatar thomaslhostis avatar ventajou avatar zogbi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-summernote's Issues

on blur to include toolbar

currently onblur gets called if toolbar is clicked. Is it possible to keep from calling onblur when toolbar is clicked?

Angular ng-model not updating on change

http://jsfiddle.net/n8dt4/150/

An example of the problem I am having can be seen in the fiddle above.

I have a function on my controller that uses $scope.text, but when using ng-model on the summernote directive the text is empty after typing in the textarea.

Typically in Angular, if I had a normal textarea or text input with the ng-model directive and after it has been typed in if I log it to the console it has the contents.

The contents of $scope.text do not appear using ng-model on the summernote directive.

To test it, type text into the textarea above the "alert it" button and then click the alert it button. It should alert with the text but it does not.

depends on bootstrap.min.js

This is an issue because for angular, I would want to use angular-bootstrap. This means I have to include two conflicting scripts: bootstrap.min.js and ui-bootstrap-tpls.js. That is, if I don't include bootstrap.min.js, angular-summernote throws an error - it must be calling something in that javascript directly (summernote is).

The problem is they conflict. I have a dropdown menu on my nav bar and with both those loaded, I have to click twice to open the dropdown. If I remove either, I only have to click once, but summernote stops working.

Suggestions?

Add "name" attribute to textarea

Currently, I cannot add a "name" attribute to the textarea. Since I'm not using the models to submit post requests, I need the "name" attribute on the textarea itself.

Can this be added soon?

browserify/npm?

Hey there โ€” any chance you guys can publish releases to the npm registry as well? Would allow re-use with browserify.

How can I get the editor object outside the on-image-upload event?

Hello.
I like angular-simmernote and I have a question.
I can upload a image using 'editor' object. 'editor' object is on-image-upload's parameter.
This object can be used only inner on-image-upload.
I'd like to use 'editor' object outside the on-image-upload too.

Thanks.

Model Not Updating Last Action

I've noticed a peculiar issue.

When your last action is not a keystroke but an action from the menubar, like adding a link to a selected bit of text or changing font size or what have you, the model isn't being updated. If you type a bit of text and remove it, or something of that nature the model is updated and works as expected. This appears to be a design flaw in how the model is updated.

As I am not an Angular expert quite yet I would appreciate some assistance.

Thanks.

Value of empty summernote is not empty string

The value of a summernote model before entering text is an empty string as expected. But if you enter text and then remove it, the value of the summernote model is <br>. This ruins ngRequired.

Oddly enough, in my testing, if you type text into an empty summernote, then remove it, its value is <br>. But if you add some hard returns to the empty summernote, then delete them, its value is an empty string.

How can I multiple file upload?

anguler-summnote sample page is used single file upload.
I'd like to multiple file upload.
How can I configure to do this?

Adding config="options" causes errors

Once I specify options, the styling on the font colors breaks. Same with other pull down menus, like the justification buttons.

When I highlight text and apply a color by selecting it off the color pallet menus, I get this console error:
Uncaught SyntaxError: Unexpected token u

Seems to be a parsing error.

Using the undo buttons throws:

Uncaught NotFoundError: Failed to execute 'setStart' on 'Range': The node provided was null.

This might be caused by the textsize option. Seems it's been deprecated and rolled into a plugin:

http://summernote.org/#/features#plugin

Speaking of which, does angular-summernote support plug-ins?

Drag image when airMode is active

Would be nice to allow the user drag'n'drop images and other files into the editor when using airMode, like when normal mode is used.

$scope don't work

hello
my code is declared like this
when('/doc/edit/:Id', {templateUrl: '/partials/doc/edit.html', controller: DocEditCtrl}).

function DocEditCtrl( $rootScope, $scope,$routeParams, $location,$http, webStorage) {
$scope.text = "Hello World"; // <-- the value is not displayed in summernote textarea

}

summernote is well activated but no value in it

$scope.options don't works too

why $scope is not active ?

Clean text on paste

How can I use the on-paste event to clean the pasted text (i.e. remove all formatting code)?

When using on-paste="snPaste()", and then
$scope.snPaste = function() {
console.log("Pasted something");
};

The pasted text is the content of the function. How can I fetch the original pasted content, edit it, and then paste it into the editor?

Airmode Bug

Hi, it can't work well in the air mode.
When use airmode in angularjs, it can't upload the html code unless using Space to refresh.
For example, If I text "something" and would like to add Header1 style, then submit the form, the value is 'something', but if I add a space, the value is '

something

'

ng-required

Is it possible to use ng-required with this? currently I'm using a hidden input for this purpose.

Is airmode working normally?

Hello outsideris,
I am using angular-summernode well at my project. thank you.
There is no textbox when using airmode.
Airmode is not working normally too at provided Demo.

This is code below.

<summernote airMode></summernote>

Please check it.

Toolbar Icons undefinded

When setting the toolbar icons in the option I am getting many string of "undefined" behind the icons in the toolbar.

Bugs in the codeview

Hi!
I find that it will not update the code if I submit the form when the editor is in code view. Is it a bug, or I configure incorrectly?
Thanks

how to user video button?

I want to use video toolbar button.

So I add summer note video plugins.
bower_components/summernote/plugin/summernote-ext-video.js

video button show in my summernote editor but it is not working.

What should i do?
Could you tell me What are the things in order to be to work correctly the video button?

defer initialization

Is there a way to defer initialization of Summernote using this? I want to initialize it when the user clicks something, and right now as soon as is seen in the DOM the editor gets initialized.

ngModel not updated with html

First, thanks for this. Very cool.

So I've successfully bound the summernote content to my model...

It updates the text just fine when I save to my database but the formatting doesn't appear to be making it to the model at all.

ngModel not updated on toolbar changes

When the toolbar makes changes to the html the model isn't updated unless you actually type additional key strokes. This is a problem if the user clicks the save button right after making a change from the toolbar.

About the summernote in the ng-repeat

Hi,
It's awesome that you fix the airmode!
But there's a small bug when it's destroyed.
For example, I use it in ng-repeat, and I want to remove one of them. the console will show the bugs like that:

screenshot from 2014-09-14 08 54 29

IE 11/10 large amount of text - crashes

Hi,
on IE 11/10 when you have angular-summernote initialised with a fair amount of text and then you try to hit enter and write other text it crashes (not responding).

Could it be that the binding is too heavy ? I have tried the plain component summer-note and it doesn't seem to have this problem http://summernote.org/#/

Could you please try to figure out the problem?

Cheers mate,
Carlo

ng-model not updated

When I type text in summernote, ng-model isn't updated. When editing the text using toolbar buttons everything works as expected.

how to use form validation?

Currently, I have this:

<div class="form-group" ng-class="{'has-error': form.content.$touched && form.content.$invalid}">
  <textarea required name="content" placeholder="content" ng-model="vm.update.content" class="form-control"></textarea>
  <div class="form-error" ng-messages="form.content.$error" ng-if="form.content.$touched">
    <p ng-message="required">This field is required</p>
  </div>
</div>

I want to use angular-summernote, but it doesn't validate correctly

<div class="form-group" ng-class="{'has-error': form.content.$touched && form.content.$invalid}">
  <summernote name="content" required ng-model="vm.update.content"></summernote>
  <div class="form-error" ng-messages="form.content.$error" ng-if="form.content.$touched">
    <p ng-message="required">This field is required</p>
  </div>
</div>

adding toolbarclick

nothing big. I've added the following to my code to bring in on toolbar click functionality
summernoteConfig.ontoolbarclick = function (evt) { $scope.toolbarclick({ evt: evt }); };

and

.directive('summernote', [function() {
...
scope: {
...
toolbarclick: '&onToolbarclick',
...
},
...
};

Clear the text of a summernote

I am just wondering if there was a way to clear the text of a summernote.

  • innerHTML does not work,
  • calling .code() and passing in an empty string does not work
  • setting the ng-model's value to an empty string or null does not work.

Does anyone have any idea?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.