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
13 changes: 10 additions & 3 deletions src/dom/get_pasted_html.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
/*
* Methods for fetching pasted html before it gets inserted into content
**/

/* Modern event.clipboardData driven approach.
* Advantage is that it does not have to loose selection or modify dom to catch the data.
* Advantage is that it does not have to loose selection or modify dom to catch the data.
* IE does not support though.
**/
wysihtml.dom.getPastedHtml = function(event) {
Expand All @@ -18,13 +18,19 @@ wysihtml.dom.getPastedHtml = function(event) {
return html;
};

wysihtml.dom.cleanerDivs = [];
wysihtml.dom.isCleanerDiv = function(element) {
return this.cleanerDivs.indexOf(element) !== -1;
};
/* Older temprorary contenteditable as paste source catcher method for fallbacks */
wysihtml.dom.getPastedHtmlWithDiv = function (composer, f) {
var selBookmark = composer.selection.getBookmark(),
doc = composer.element.ownerDocument,
cleanerDiv = doc.createElement('DIV'),
scrollPos = composer.getScrollPos();


this.cleanerDivs.push(cleanerDiv);

doc.body.appendChild(cleanerDiv);

cleanerDiv.style.width = "1px";
Expand All @@ -46,6 +52,7 @@ wysihtml.dom.getPastedHtmlWithDiv = function (composer, f) {
html = false;
}
f(html);
wysihtml.dom.cleanerDivs.splice(wysihtml.dom.cleanerDivs.indexOf(cleanerDiv), 1);
cleanerDiv.parentNode.removeChild(cleanerDiv);
}, 0);
};
10 changes: 7 additions & 3 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@
uneditableContainer: "wysihtml-uneditable-container"
},
// Browsers that support copied source handling will get a marking of the origin of the copied source (for determinig code cleanup rules on paste)
// Also copied source is based directly on selection -
// Also copied source is based directly on selection -
// (very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection).
// If falsy value is passed source override is also disabled
copyedFromMarking: '<meta name="copied-from" content="wysihtml">'
},

constructor: function(editableElement, config) {
this.editableElement = typeof(editableElement) === "string" ? document.getElementById(editableElement) : editableElement;
this.config = wysihtml.lang.object({}).merge(this.defaults).merge(config).get();
Expand Down Expand Up @@ -131,7 +131,7 @@
}
this.runEditorExtenders();
},

runEditorExtenders: function() {
wysihtml.editorExtenders.forEach(function(extender) {
extender(this);
Expand Down Expand Up @@ -237,6 +237,10 @@
} else {
this.on("beforepaste:composer", function(event) {
event.preventDefault();
// Ignore second beforepaste fired by IE11.
if(wysihtml.dom.isCleanerDiv(event.target)) {
return;
}
var scrollPos = this.composer.getScrollPos();

wysihtml.dom.getPastedHtmlWithDiv(this.composer, function(pastedHTML) {
Expand Down