Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,45 @@ This package comes with 2 directives:
## Editor

```html
<pagedown-editor content="data.content"></pagedown-editor>
<pagedown-editor ng-model="data.content"></pagedown-editor>
```

Options:

#### content
#### ng-model

1. An expression.
1. An expression.
1. *Expression*: Mandatory
1. Example: `<pagedown-editor content="data.content"></pagedown-editor>`
1. Example: `<pagedown-editor content="'**some** _markdown_ text'"></pagedown-editor>`
1. Example: `<pagedown-editor ng-model="data.content"></pagedown-editor>`
1. Example: `<pagedown-editor ng-model="'**some** _markdown_ text'"></pagedown-editor>`

#### ng-change

1. An expression.
1. *Expression*: Optional
1. Example: `<pagedown-editor ng-change="log()"></pagedown-editor>`

#### $dirty

- `<pagedown-editor ng-model="data.content" name="mdInput"></pagedown-editor>`
- ``<dd ng-bind="myForm.mdInput.$dirty"></dd>``

#### show-preview

1. Should a live preview be displayed.
1. Should a live preview be displayed.
1. *Boolean*: Default to true

#### help

1. An expression to invoke upon clicking the help (?) button.
1. An expression to invoke upon clicking the help (?) button.
1. *Expression*: Default to open http://daringfireball.net/projects/markdown/syntax in new window
1. Example: `<pagedown-editor content="data.content" help="showSomeHelp()"></pagedown-editor>`
1. Example: `<pagedown-editor ng-model="data.content" help="showSomeHelp()"></pagedown-editor>`

#### insert-image

1. An expression to invoke upon clicking the "Insert Image" button.
1. An expression to invoke upon clicking the "Insert Image" button.
1. *Expression*: Default to `noop`
1. Example: `<pagedown-editor content="data.content" insert-image="promptImageUrl()"></pagedown-editor>`
1. Example: `<pagedown-editor ng-model="data.content" insert-image="promptImageUrl()"></pagedown-editor>`
1. The parent scope function `promptImageUrl` must return either:
- A string of image URL.
- A promise resolved with a string of image URL.
Expand All @@ -71,15 +82,15 @@ Options:

1. An expression.
1. *Expression*: Default to empty string
1. Example: `<pagedown-editor content="data.content" placeholder="{{data.placeholder}} or anything"></pagedown-editor>`
1. Example: `<pagedown-editor ng-model="data.content" placeholder="{{data.placeholder}} or anything"></pagedown-editor>`

#### editor-class

1. An expression to use as [ngClass](https://docs.angularjs.org/api/ng/directive/ngClass).
1. *Expression*: Default to `wmd-input`
1. Example: `<pagedown-editor content="data.content" editorClass="{'a-class': true}"></pagedown-editor>`
1. Example: `<pagedown-editor content="data.content" editorClass="'a-class another-class'"></pagedown-editor>`
1. Example: `<pagedown-editor content="data.content" editorClass="aScopeVariable"></pagedown-editor>`
1. Example: `<pagedown-editor ng-model="data.content" editorClass="{'a-class': true}"></pagedown-editor>`
1. Example: `<pagedown-editor ng-model="data.content" editorClass="'a-class another-class'"></pagedown-editor>`
1. Example: `<pagedown-editor ng-model="data.content" editorClass="aScopeVariable"></pagedown-editor>`

#### editor-rows

Expand Down
19 changes: 14 additions & 5 deletions angular-pagedown.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ angular.module("ui.pagedown", [])
},
link: function (scope, element, attrs, ngModel) {

scope.changed = function () {
ngModel.$setDirty();
scope.$parent.$eval(attrs.ngChange);
};



var editorUniqueId;
Expand Down Expand Up @@ -84,11 +81,23 @@ angular.module("ui.pagedown", [])

editorElement.val(scope.ngModel);


scope.changed = function () {
var v = editorElement.val();
ngModel.$setViewValue(v);
};

converter.hooks.chain("postConversion", function (text) {
ngModel.$setViewValue(editorElement.val());

var v = editorElement.val();
if (scope.ngModel !== v) {
ngModel.$setViewValue(v);
}


// update
scope.previewContent = text;

return text;
});

Expand Down