Merge pull request #3998 from rockandror/ckeditor-browser-history-back

Destroy and intialize ckeditor on browser history back
This commit is contained in:
Javier Martín
2020-05-11 14:29:39 +02:00
committed by GitHub
3 changed files with 24 additions and 7 deletions

View File

@@ -1,7 +0,0 @@
$(document).on("page:change", function() {
if (typeof(CKEDITOR) != "undefined"){
for(name in CKEDITOR.instances){
try{CKEDITOR.replace(name);}catch(err){};
}
}
});

View File

@@ -1,6 +1,11 @@
(function() {
"use strict";
App.HTMLEditor = {
destroy: function() {
for (var name in CKEDITOR.instances) {
CKEDITOR.instances[name].destroy();
}
},
initialize: function() {
$("textarea.html-area").each(function() {
if ($(this).hasClass("admin")) {
@@ -11,4 +16,7 @@
});
}
};
$(document).on("page:before-unload", App.HTMLEditor.destroy);
$(document).on("page:restore", App.HTMLEditor.initialize);
}).call(this);

View File

@@ -51,4 +51,20 @@ describe "CKEditor" do
expect(page).not_to have_link "Upload"
expect(page).not_to have_link "Browse Server"
end
context "When navigating back to editor page using browser history back" do
scenario "display ckeditor unsaved contents", :js do
login_as(create(:administrator).user)
visit new_admin_newsletter_path
fill_in_ckeditor "Email content", with: "This is an unsaved body"
click_link "Newsletters"
expect(page).to have_link "New newsletter"
go_back
expect(page).to have_ckeditor "Email content", with: "This is an unsaved body"
end
end
end