Skip to content

Commit

Permalink
ADD: option cleanPaste for pasting plain text #363 #366
Browse files Browse the repository at this point in the history
  • Loading branch information
farthinker committed Dec 21, 2015
1 parent 31fcb8d commit 1d7d792
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/simditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2211,7 +2211,8 @@ Clipboard = (function(superClass) {
Clipboard.pluginName = 'Clipboard';

Clipboard.prototype.opts = {
pasteImage: false
pasteImage: false,
cleanPaste: false
};

Clipboard.prototype._init = function() {
Expand Down Expand Up @@ -2302,7 +2303,7 @@ Clipboard = (function(superClass) {
_this.editor.selection.reset();
_this.editor.selection.range();
_this._pasteInBlockEl = _this.editor.selection.blockNodes().last();
_this._pastePlainText = _this._pasteInBlockEl.is('pre, table');
_this._pastePlainText = _this.opts.cleanPaste || _this._pasteInBlockEl.is('pre, table');
if (_this._pastePlainText) {
pasteContent = _this.editor.formatter.clearHtml(_this._pasteBin.html(), true);
} else {
Expand Down
6 changes: 6 additions & 0 deletions site/_data/configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@
description: |
Support uploading by pasting images from the clipboard. Work together with `upload` and only supported by Firefox and Chrome.
- name: "cleanPaste"
type: "Boolean"
default: "false"
description: |
Remove all styles in paste content automatically.
- name: "imageButton"
type: "Array/String"
default: "['upload', 'external']"
Expand Down
5 changes: 3 additions & 2 deletions site/assets/scripts/simditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,8 @@ Clipboard = (function(superClass) {
Clipboard.pluginName = 'Clipboard';

Clipboard.prototype.opts = {
pasteImage: false
pasteImage: false,
cleanPaste: false
};

Clipboard.prototype._init = function() {
Expand Down Expand Up @@ -2297,7 +2298,7 @@ Clipboard = (function(superClass) {
_this.editor.selection.reset();
_this.editor.selection.range();
_this._pasteInBlockEl = _this.editor.selection.blockNodes().last();
_this._pastePlainText = _this._pasteInBlockEl.is('pre, table');
_this._pastePlainText = _this.opts.cleanPaste || _this._pasteInBlockEl.is('pre, table');
if (_this._pastePlainText) {
pasteContent = _this.editor.formatter.clearHtml(_this._pasteBin.html(), true);
} else {
Expand Down
3 changes: 2 additions & 1 deletion site/docs/doc-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ root: ../
#Options

You can customize Simditor by passing optional options when initializing Simditor.
Here are all the optional options and their default values:
Here are some optional options and their default values:

```coffee
editor = new Simditor
Expand All @@ -23,6 +23,7 @@ editor = new Simditor
toolbarFloatOffset: 0
toolbarHidden: false
pasteImage: false
cleanPaste: false
```


Expand Down
3 changes: 2 additions & 1 deletion src/clipboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Clipboard extends SimpleModule

opts:
pasteImage: false
cleanPaste: false

_init: ->
@editor = @_module
Expand Down Expand Up @@ -84,7 +85,7 @@ class Clipboard extends SimpleModule
@editor.selection.range()

@_pasteInBlockEl = @editor.selection.blockNodes().last()
@_pastePlainText = @_pasteInBlockEl.is 'pre, table'
@_pastePlainText = @opts.cleanPaste || @_pasteInBlockEl.is('pre, table')

if @_pastePlainText
pasteContent = @editor.formatter.clearHtml @_pasteBin.html(), true
Expand Down

0 comments on commit 1d7d792

Please sign in to comment.