GithubHelp home page GithubHelp logo

thijsw / angular-medium-editor Goto Github PK

View Code? Open in Web Editor NEW
303.0 303.0 95.0 225 KB

AngularJS directive for Medium.com editor clone

JavaScript 55.94% CSS 20.55% HTML 23.51%
angular javascript medium-editor

angular-medium-editor's People

Contributors

boxxxie avatar brazorf avatar charuru avatar diogobeda avatar flocks avatar khanmaytok avatar klenis avatar pumatiger avatar simison avatar sp90 avatar thijsw 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

angular-medium-editor's Issues

How to use a directive on the input ?

Example: <input type="text" medium-editor my-custom-directive>
This does not seems to work, probably because the widget creates another element.

My use case is to automatically adjust the input height based on the content (like the facebook editor).

#coffeescript
.directive 'myCustomDirective', ->
    ($scope, elem, attrs) ->
       console.log "this is logged"

       elem.bind "keydown", (event) ->
           console.log "this will never be logged"

Options compatibility with medium editor.

Hello there, please take a look at this code:

<div medium-editor options="{forcePlainText: false, buttons: ['italic', 'bold', 'underline', 'anchor', 'unorderedlist', 'quote']}"></div>

This will allow to paste html code into the container, as documented. However, checking through the medium-editor 4.4.0 docs, we should have more settings available like for example

paste: {
        // This example includes the default options for paste, if nothing is passed this is what it used
        forcePlainText: true,
        cleanPastedHtml: false,
        cleanReplacements: [],
        cleanAttrs: ['class', 'style', 'dir']
        cleanTags: ['meta']
    }

see here for reference.

If i try to enable the paste setting using

<div medium-editor options="{paste: {forcePlainText: false}, buttons: ['italic', 'bold', 'underline', 'anchor', 'unorderedlist', 'quote']}"></div>

the forcePlainText setting will be ignored. I didn't went through your code yet, but it seems like you have remapped the options yourself, so we can't use the whole available set. Am i wrong?

medium-editor.directive.ts is missing from the TypeScript compilation

Not able to use angular-medium-editor library in Angular 5

Packages installed are mentioned Below
"angular-medium-editor": "^4.0.0-alpha",
"angular/core": "^5.2.0",
"typescript": "~2.5.3"

During "ng serve" command I get the following error

ERROR in ./node_modules/angular-medium-editor/medium-editor.directive.ts
Module build failed: Error: /Users/K2A/GIT/traveldiary/webapp/node_modules/angular-medium-editor/medium-editor.directive.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
The missing file seems to be part of a third party library. TS files in published libraries are often a sign of a badly packaged library. Please open an issue in the library repository to alert its author and ask them to package the library using the Angular Package Format (https://goo.gl/jB3GVv).
at AngularCompilerPlugin.getCompiledFile (/Users/K2A/GIT/traveldiary/webapp/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:656:23)
at plugin.done.then (/Users/K2A/GIT/traveldiary/webapp/node_modules/@ngtools/webpack/src/loader.js:467:39)
at
at process._tickCallback (internal/process/next_tick.js:188:7)
@ ./src/app/pages/pages.module.ts 18:32-88
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts

Kindly let me know is there is anything that I can do to fix this issue and use the library

Missing "main" key in`package.json` causes simple import failure

Unlike other packages, where the form

import 'angular-medium-editor';

is sufficient to make MediumEditor available, this package requires the specific non-intuitive import form:

import 'angular-medium-editor/dist/angular-medium-editor';

That's because in package.json there's no key such as:

  "main": "dist/angular-medium-editor.js",

(this is done in many other packages)

  • found on a Meteor (1.3) project

Which buttons are supported?

The original Medium editor provides the following list in built-in buttons available to use with the toolbar and editor: https://github.com/yabwe/medium-editor#all-buttons

However, only some of these seem to work with this directive. E.g. when appending 'orderedlist' and 'justifyCenter' to the array of buttons, the ordered list button appears and works fine but not for justify center, any idea why this is or if all the buttons are available?

Inserting text into text area

screen shot 2017-09-27 at 4 33 00 pm

Hi there,

I am trying to figure out how it would be possible to add text at the caret/cursor position. I creative a directive that would allow me to insert a text (which would be a user variable) into the text area section. However, when I added the medium-editor directive I can't access the elementId and inject the text (see the image to see the ux flow.

Do you know how I could potentially work around this?

Thanks!

multiple editor

Hi thijsw, may i know is it possible to make multiple editors in a same page ? i have tried it but it has some bugs when copy and paste content, the content will get multiply

calling onChange on input causes sluggish typing...

Hi...@mbrevoort @thijsw

This commit:

962d2e5

From this pull request:

#5

Changed updating the model from watching just on('blur') to both on('blur') and on('input').

This has quite dramatically affected typing speed. (On on angular 1.2.24, Chrome 39.0.2171.42.)

I see the point of the change. But it does slow typing down a lot (i.e. there is a noticeable second or two pause after each key stroke).

(My usecase requires a a user to click a button after typing, so onBlur covers me.)

Feel free to close this issue if you'd like to keep onInput with the sluggishness.

Support for Angular 2

This is an awesome plugin. However, since everyone is slowly moving on to Angular 2 would be great if there are any plans for Angular 2.

Is this module still supported?

Hey there
I've seen medium-editor supported version is 4.4.0, which dates on april 2015.
Since then, medium-editor upgraded branch 4 up to 4.12 and branch 5 up to 5.10

Should we consider angular-medium-editor fully supported still?

Content dissapears on click

It's a weird behaviour. It must be in someplace inside this library, medium-insert-plugin or medium-editor itself.

See it running: http://codepen.io/Mr-K/pen/vGbaMy

As you can see, we have multiple instances of medium-editor working which each contains an initial value. The content is binded, and it seems ready to edit.

So far so good.
BUT when you click at it, the content is replaced by nothing. It's missing. Gone, completely.
You can see it in the codepen above.

Library stopped working on latest 4.x and 5.x angular

ERROR in Error: Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 404:52 in the original .ts file), resolving symbol Directive in /home/nmartin/Projects/classconnect/classconnect-web/node_modules/angular-medium-editor/node_modules/@angular/core/core.d.ts, resolving symbol MediumEditorDirective in /home/nmartin/Projects/classconnect/classconnect-web/node_modules/angular-medium-editor/medium-editor.directive.ts, resolving symbol MediumEditorDirective in /home/nmartin/Projects/classconnect/classconnect-web/node_modules/angular-medium-editor/medium-editor.directive.ts

This is common across a lot of libraries right now, and supposedly it's because your d.ts doesn't export the'proper' metadata for angular to do AOT compilation, which is default now.

Ref: angular/angular-cli#3707 and https://medium.com/@cyrilletuzi/how-to-build-and-publish-an-angular-module-7ad19c0b4464

Q / feature request: Can contents be compiled?

Hi. I am road-testing angular-medium-editor to see whether I can use (and extend) it to deliver an online editing capability for users to add custom angular directives to their content.

Using the highlighter example, I can see how I can add custom HTML tags, attributes and classes - so I think I'm half-way there!

But is it possible for the contents of the medium-editor (and the custom directives inserted within it) to be compiled when they're changed?

I have tried editing angular-medium-editor.js to compile the contents as part of the ngModel.$render function:

    ngModel.$render = function() {
      iElement.html(ngModel.$viewValue || "");
      $compile(iElement.contents())(scope);
      var placeholder = ngModel.editor.getExtensionByName('placeholder');
      if (placeholder) {
        placeholder.updatePlaceholder(iElement[0]);
      }
    };

This works for custom directives that are already in the medium-editor's HTML model, but does not get re-compiled when the model changes (i.e. directives are added). Any ideas?

Watch/ngChange triggered on initialization

Currently if the model is set to null || undefined ng-change and watch are triggered on initialization.

Most probably has to do with the following line of code:
ngModel.editor.setContent(ngModel.$viewValue || "");

NgModel appears to bind only 1 way.

When I attempt to change the ngModel programmatically within a controller, it seems to only bind one way so after I submit a form and try to set the ngModel to an empty string it is not reflected in the view.

Is there something I am missing or is this a general issue?

Extensions don't apply to text instantly

I made an extension to change the direction of text.
As you can see it in this [ example ],
In pure medium-editor version, when you change the direction ("RTL" button), content of text changes immediately (Please use "Change" button to apply it to textarea).
But when you are using angular version (angular-medium-editor), changing direction don't change content of text until you made another change in text.

Different behaviour while pasting content on Chrome or Firefox

I've noticed this difference in the code processor. Take these cases:

1.a) I copy a paragraph from a web page using Firefox
1.b) I paste that paragraph to a medium-editor in Firefox
The result will be a paragraph without the wrapping <p>

2.a) I copy a paragraph from a web page using Firefox
2.b) I paste that paragraph to a medium-editor in Chrome
The result will be a paragraph properly wrapped in <p> tags.

Assuming the latter is the designed behaviour, i would say this is a bug.

'undefined' is not a function (evaluating 'this.handleDrag.bind(this)') error

When complling the element and then binding it to scope in Jasmine test for testing my directive, for example something like this: $compile(angular.element('

'))($rootScope.$new()) the following error occures: 'undefined' is not a function (evaluating 'this.handleDrag.bind(this)').
When do the same in in directive in main code - everything is ok!

Debounce

Hi. I can't get this working with debounce. In Angular it's a standar, so if I write this:
ng-model="tab.content" ng-model-options="{debounce: 500}"

It should work.
It didn't, & I found this:

ngModel.editor.subscribe('editableInput', function (event, editable) {
          ngModel.$setViewValue(editable.innerHTML.trim());
          var throttledAutoSave = MediumEditor.util.throttle(scope.save(), 2000); // 2 seconds
        });

Not working.
How I can get the debounce running to fire the function a few miliseconds after the last keystroke?

allow a model change function to be passed

ng-change is apparently not supported in non-input elements so there is no way to hook in to updates to the editor so that data can be updated server-side. How is this achieved?

I have played with passing a call to the controller's method by adding an attr in to the directive to accept the function - something like medium-editor model-change="saveSection()". In the directive I then added:

ctrl.$viewChangeListeners.push(function() {
   scope.$eval(iAttrs.modelChange);
});

Whilst things fire as expected it doesn't work how I thought it would - the model updates too often and removes whatever has just been changed.

Any ideas?

Firefox: execCommand throughs NS_ERROR_FAILURE when used with angular

this.options.ownerDocument.execCommand throws an NS_ERROR_FAILURE when wrapped in an angular wrapper whenexecActionInternal() is called for the ordered and unordered list buttons.

It causes some weird behavior that duplicates the medium editor element's parent node several times.

Example:
before:

<div class="parent">
<p medium-editor class="medium-editor">I am an editor and the p tag is my editor element</p>
<div>Some sibling element</div>
</div>

after:

<div class="parent">
<p medium-editor class="medium-editor">I am an editor and the p tag is my editor element</p>
</div>
<div class="parent">
<div>Some sibling element</div>
</div>

Anyone have any idea that is and if there is a solution. It works fine as long as it is not used with Angular.

This is only an issue in Firefox.

release

Hello,

would be possible to do a release ? we found that latest npm version is not working as intended due to #72

thanks!

Textarea div not populated with ngModel.$viewValue when present

From YABWE/medium-editor...

"MediumEditor also supports textarea. If you provide a textarea element, the script will create a new div with contentEditable=true, hide the textarea and link the textarea value to the div HTML content."

...the new div HTML content is not linked to the textarea value (ngModel.$viewValue) when set with iElement.html(), ngModel.editor.setContent() should be used instead.

Make compatible with medium-editor 1.9.*

When I try to upgrade the underlying medium-editor to version 1.9; it gives this error message when the toolbar pops up:

Uncaught TypeError: Cannot read property 'querySelector' of undefined medium-editor.js:739

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.