vendor/assets/javascripts/simditor/simditor.js in simditor-2.3.0 vs vendor/assets/javascripts/simditor/simditor.js in simditor-2.3.2
- old
+ new
@@ -1,9 +1,9 @@
/*!
-* Simditor v2.3.0
+* Simditor v2.3.2
* http://simditor.tower.im/
-* 2015-10-08
+* 2015-10-15
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define('simditor', ["jquery","simple-module","simple-hotkeys","simple-uploader"], function ($, SimpleModule, simpleHotkeys, simpleUploader) {
@@ -51,22 +51,22 @@
Selection.prototype._init = function() {
this.editor = this._module;
this._selection = document.getSelection();
this.editor.on('selectionchanged', (function(_this) {
return function(e) {
- _this._reset();
+ _this.reset();
return _this._range = _this._selection.getRangeAt(0);
};
})(this));
return this.editor.on('blur', (function(_this) {
return function(e) {
return _this.clear();
};
})(this));
};
- Selection.prototype._reset = function() {
+ Selection.prototype.reset = function() {
this._range = null;
this._startNodes = null;
this._endNodes = null;
this._containerNode = null;
this._nodes = null;
@@ -79,11 +79,11 @@
try {
this._selection.removeAllRanges();
} catch (_error) {
e = _error;
}
- return this._reset();
+ return this.reset();
};
Selection.prototype.range = function(range) {
var ffOrIE;
if (range) {
@@ -1687,11 +1687,11 @@
Util.prototype.isDecoratedNode = function(node) {
return $(node).is('[class^="simditor-"]');
};
- Util.prototype.blockNodes = ["div", "p", "ul", "ol", "li", "blockquote", "hr", "pre", "h1", "h2", "h3", "h4", "table"];
+ Util.prototype.blockNodes = ["div", "p", "ul", "ol", "li", "blockquote", "hr", "pre", "h1", "h2", "h3", "h4", "h5", "table"];
Util.prototype.isBlockNode = function(node) {
node = $(node)[0];
if (!node || node.nodeType === 3) {
return false;
@@ -2193,33 +2193,37 @@
if (this.opts.pasteImage && typeof this.opts.pasteImage !== 'string') {
this.opts.pasteImage = 'inline';
}
return this.editor.body.on('paste', (function(_this) {
return function(e) {
- var $blockEl, isPlainText, range;
+ var range;
+ if (_this.pasting || _this._pasteBin) {
+ return;
+ }
if (_this.editor.triggerHandler(e) === false) {
return false;
}
range = _this.editor.selection.deleteRangeContents();
- if (!range.collapsed) {
- range.collapse(true);
+ if (_this.editor.body.html()) {
+ if (!range.collapsed) {
+ range.collapse(true);
+ }
+ } else {
+ _this.editor.formatter.format();
+ _this.editor.selection.setRangeAtStartOf(_this.editor.body.find('p:first'));
}
- _this.editor.selection.range(range);
- $blockEl = _this.editor.selection.blockNodes().last();
- isPlainText = $blockEl.is('pre, table');
- if (!isPlainText && _this._processPasteByClipboardApi(e)) {
+ if (_this._processPasteByClipboardApi(e)) {
return false;
}
- if (_this._pasteBin) {
- return false;
- }
_this.editor.inputManager.throttledValueChanged.clear();
_this.editor.inputManager.throttledSelectionChanged.clear();
_this.editor.undoManager.throttledPushState.clear();
_this.pasting = true;
- return _this._getPasteContent(isPlainText, function(pasteContent) {
- _this._processPasteContent(isPlainText, $blockEl, pasteContent);
+ return _this._getPasteContent(function(pasteContent) {
+ _this._processPasteContent(pasteContent);
+ _this._pasteInBlockEl = null;
+ _this._pastePlainText = null;
return _this.pasting = false;
});
};
})(this));
};
@@ -2250,11 +2254,11 @@
return true;
}
}
};
- Clipboard.prototype._getPasteContent = function(isPlainText, callback) {
+ Clipboard.prototype._getPasteContent = function(callback) {
var state;
this._pasteBin = $('<div contenteditable="true" />').addClass('simditor-paste-bin').attr('tabIndex', '-1').appendTo(this.editor.el);
state = {
html: this.editor.body.html(),
caret: this.editor.undoManager.caretPosition()
@@ -2265,12 +2269,15 @@
var pasteContent;
_this.editor.hidePopover();
_this.editor.body.html(state.html);
_this.editor.undoManager.caretPosition(state.caret);
_this.editor.body.focus();
- _this.editor.selection._reset();
- if (isPlainText) {
+ _this.editor.selection.reset();
+ _this.editor.selection.range();
+ _this._pasteInBlockEl = _this.editor.selection.blockNodes().last();
+ _this._pastePlainText = _this._pasteInBlockEl.is('pre, table');
+ if (_this._pastePlainText) {
pasteContent = _this.editor.formatter.clearHtml(_this._pasteBin.html(), true);
} else {
pasteContent = $('<div/>').append(_this._pasteBin.contents());
pasteContent.find('table colgroup').remove();
_this.editor.formatter.format(pasteContent);
@@ -2283,18 +2290,19 @@
return callback(pasteContent);
};
})(this), 0);
};
- Clipboard.prototype._processPasteContent = function(isPlainText, $blockEl, pasteContent) {
- var $img, blob, children, insertPosition, k, l, lastLine, len, len1, len2, len3, len4, line, lines, m, node, o, q, ref, ref1, ref2, uploadOpt;
+ Clipboard.prototype._processPasteContent = function(pasteContent) {
+ var $blockEl, $img, blob, children, insertPosition, k, l, lastLine, len, len1, len2, len3, len4, line, lines, m, node, o, q, ref, ref1, ref2, uploadOpt;
if (this.editor.triggerHandler('pasting', [pasteContent]) === false) {
return;
}
+ $blockEl = this._pasteInBlockEl;
if (!pasteContent) {
return;
- } else if (isPlainText) {
+ } else if (this._pastePlainText) {
if ($blockEl.is('table')) {
lines = pasteContent.split('\n');
lastLine = lines.pop();
for (k = 0, len = lines.length; k < len; k++) {
line = lines[k];
@@ -3087,11 +3095,11 @@
return TitleButton.__super__.constructor.apply(this, arguments);
}
TitleButton.prototype.name = 'title';
- TitleButton.prototype.htmlTag = 'h1, h2, h3, h4';
+ TitleButton.prototype.htmlTag = 'h1, h2, h3, h4, h5';
TitleButton.prototype.disableTag = 'pre, table';
TitleButton.prototype._init = function() {
this.menu = [
@@ -3127,11 +3135,11 @@
TitleButton.prototype.setActive = function(active, param) {
TitleButton.__super__.setActive.call(this, active);
if (active) {
param || (param = this.node[0].tagName.toLowerCase());
}
- this.el.removeClass('active-p active-h1 active-h2 active-h3');
+ this.el.removeClass('active-p active-h1 active-h2 active-h3 active-h4 active-h5');
if (active) {
return this.el.addClass('active active-' + param);
}
};
@@ -5325,10 +5333,11 @@
throw new Error("simditor alignment button: invalid align " + align);
}
this.nodes.css({
'text-align': align === 'left' ? '' : align
});
- return this.editor.trigger('valuechanged');
+ this.editor.trigger('valuechanged');
+ return this.editor.inputManager.throttledSelectionChanged();
};
return AlignmentButton;
})(Button);