Skip to content

Commit

Permalink
CHG: 清理粘贴内容
Browse files Browse the repository at this point in the history
  • Loading branch information
biallo committed Jul 23, 2018
1 parent f9539e8 commit 4df0edc
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simditor",
"version": "2.3.16",
"version": "2.3.17",
"homepage": "http://simditor.tower.im/",
"authors": [
"farthinker <[email protected]>"
Expand Down
22 changes: 17 additions & 5 deletions lib/simditor.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*!
* Simditor v2.3.16
* http://simditor.tower.im/
* 2018-06-14
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
Expand Down Expand Up @@ -2354,6 +2349,7 @@ Clipboard = (function(superClass) {
pasteContent = $('<div/>').append(_this._pasteBin.contents());
pasteContent.find('style').remove();
pasteContent.find('table colgroup').remove();
_this._cleanPasteFontSize(pasteContent);
_this.editor.formatter.format(pasteContent);
_this.editor.formatter.decorate(pasteContent);
_this.editor.formatter.beautify(pasteContent.children());
Expand Down Expand Up @@ -2493,6 +2489,22 @@ Clipboard = (function(superClass) {
return this.editor.inputManager.throttledValueChanged();
};

Clipboard.prototype._cleanPasteFontSize = function(node) {
var $node, sizeMap;
$node = $(node);
if (!($node.length > 0)) {
return;
}
sizeMap = ['1.5em', '1.25em', '0.75em', '0.5em'];
return $node.find('[style*="font-size"]').map(function(i, el) {
var $el;
$el = $(el);
if ($.inArray($el.css('font-size'), sizeMap) < 0) {
return $el.css('font-size', '');
}
});
};

return Clipboard;

})(SimpleModule);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simditor",
"version": "2.3.16",
"version": "2.3.17",
"description": "A simple online editor",
"keywords": "editor simditor",
"repository": {
Expand Down
17 changes: 17 additions & 0 deletions site/assets/scripts/simditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2349,6 +2349,7 @@ Clipboard = (function(superClass) {
pasteContent = $('<div/>').append(_this._pasteBin.contents());
pasteContent.find('style').remove();
pasteContent.find('table colgroup').remove();
_this._cleanPasteFontSize(pasteContent);
_this.editor.formatter.format(pasteContent);
_this.editor.formatter.decorate(pasteContent);
_this.editor.formatter.beautify(pasteContent.children());
Expand Down Expand Up @@ -2488,6 +2489,22 @@ Clipboard = (function(superClass) {
return this.editor.inputManager.throttledValueChanged();
};

Clipboard.prototype._cleanPasteFontSize = function(node) {
var $node, sizeMap;
$node = $(node);
if (!($node.length > 0)) {
return;
}
sizeMap = ['1.5em', '1.25em', '0.75em', '0.5em'];
return $node.find('[style*="font-size"]').map(function(i, el) {
var $el;
$el = $(el);
if ($.inArray($el.css('font-size'), sizeMap) < 0) {
return $el.css('font-size', '');
}
});
};

return Clipboard;

})(SimpleModule);
Expand Down
19 changes: 19 additions & 0 deletions src/clipboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ class Clipboard extends SimpleModule
pasteContent = $('<div/>').append(@_pasteBin.contents())
pasteContent.find('style').remove() # clear style tag
pasteContent.find('table colgroup').remove() # clear table cols width
@_cleanPasteFontSize pasteContent
@editor.formatter.format pasteContent
@editor.formatter.decorate pasteContent
@editor.formatter.beautify pasteContent.children()

pasteContent = pasteContent.contents()

@_pasteBin.remove()
Expand Down Expand Up @@ -209,3 +211,20 @@ class Clipboard extends SimpleModule
@editor.selection.setRangeAtEndOf(pasteContent.last())

@editor.inputManager.throttledValueChanged()

_cleanPasteFontSize: (node) ->
$node = $(node)
return unless $node.length > 0

sizeMap = [
'1.5em'
'1.25em'
'0.75em'
'0.5em'
]

$node.find('[style*="font-size"]')
.map (i, el) ->
$el = $(el)
if $.inArray($el.css('font-size'), sizeMap) < 0
$el.css('font-size', '')
4 changes: 2 additions & 2 deletions styles/simditor.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* Simditor v2.3.16
* Simditor v2.3.17
* http://simditor.tower.im/
* 2018-06-14
* 2018-07-23
*/
@font-face {
font-family: 'Simditor';
Expand Down

0 comments on commit 4df0edc

Please sign in to comment.