See bottom of question for an improved solution to this problem
I have been trying for some time now to get a directive for the pagedown working. This is the exact same editor used by stackoverflow. Stackoverflow make this code available here:
https://code.google.com/p/pagedown/
There are some versions out there on the internet but none work well. What I need is one that will appear with all the editor buttons just like stackoverflow both when coded inline and also when it's inline as part of an ngRepeat.
I would like to make this directive work when it's coded inline and also inside an ng-repeat using Angular version 1.2.7. What's needed is that when the model data changes the directive needs to update the pagedown views to show the new question and answers. When the user changes the pagedown edit area the directive needs to be able to update the model. When the user clicks [save] the model data needs to be saved to the database (or at least to another object to confirm it worked).
The directive needs to be able to respond to changes in the model and also save it's raw data to the model on keyup or when the 'change' button is pressed in the editing paned. Here is what I have so far. Note that this version does not have the $wmdInput.on('change' but it's a start for what is needed.
Most important I would like to have this working with version 1.2.7 of Angular and jQuery 2.0.3 Please note that I found differences with my non-working code between versions 1.2.2 and 1.2.7. I think it's best if any solution works for the latest (1.2.7) release.
Update
I now this directive which is simpler and solves some recent problems I had with the content not showing. I would highly recommend using this directive which is based on the answer accepted plus a few improvements: https://github.com/kennyki/angular-pagedown
Here is a working link:
http://cssdeck.com/labs/qebukp9k
UPDATE
Angular.js & Performance
Solution:
Demo: http://plnkr.co/edit/FyywJS?p=preview
Summary
I removed
keyup
and added a hook ononPreviewRefresh
to ensure clicking on toolbar will properly updateng-model
.Functions on
$rootScope
will demonstrate the ability to updateng-model
from outside of pagedown.save functionality purely depends on your choice, since you can access
ng-model
anywhere now.You can change this:
For this:
Additionally can try commenting this code out:
}
I think it may be associated with the odd behavior.
It might not be the answer, but all the problem occurs when you start using Markdown.Editor which does not gives you a lot of benefits.
Of course, you need to use it for markdown editor beginners, but when use markdown, they are already not beginners anyway(I might be wrong).
What I approached to this problem was to make fully working version of this without using editor.
It has preview also.
It's also very simple.
https://github.com/allenhwkim/wiki
---- edit ----
removed
---- edit ----
removed
---- edit ----
To provide a fully working editor, after few hours of trial and asking questions, the following is the simplest I can get. This does require any $watch nor $formatters. It just wraps the given element with all attributes given by the textarea.
http://plnkr.co/edit/jeZ5EdLwOfwo6HzcTAOR?p=preview