Destroy Annotator app before storing page into brwoser cache
If we do not destroy annotator app before storing the page at browser cache we will unnecesarily initialize annotations twice (or more) duplicating Annotator HTML markup and causing unexpected errors. Without this commit you will find an error when restoring a page with annotator, you can click on any annotation and you will see the annotation comments are being loaded twice. IMO this is an idempotency issue within Annotator JS library.
This commit is contained in:
@@ -172,6 +172,7 @@ var destroy_non_idempotent_modules = function() {
|
||||
|
||||
App.Datepicker.destroy();
|
||||
App.HTMLEditor.destroy();
|
||||
App.LegislationAnnotatable.destroy();
|
||||
};
|
||||
|
||||
$(document).on("turbolinks:load", initialize_modules);
|
||||
|
||||
@@ -226,6 +226,11 @@
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
destroy: function() {
|
||||
if ($(".legislation-annotatable").length > 0) {
|
||||
App.LegislationAnnotatable.app.destroy();
|
||||
}
|
||||
}
|
||||
};
|
||||
}).call(this);
|
||||
|
||||
@@ -237,6 +237,23 @@ describe "Legislation Draft Versions" do
|
||||
|
||||
expect(page).to have_content "Comment can't be blank"
|
||||
end
|
||||
|
||||
scenario "When page is restored from browser cache do not duplicate annotation handlers" do
|
||||
create(:legislation_annotation, draft_version: draft_version, text: "my annotation")
|
||||
|
||||
visit legislation_process_draft_version_path(draft_version.process, draft_version)
|
||||
|
||||
expect(page).to have_css(".annotator-hl", count: 1)
|
||||
|
||||
click_link "Help"
|
||||
|
||||
expect(page).to have_content "CONSUL is a platform for citizen participation"
|
||||
|
||||
go_back
|
||||
|
||||
expect(page).to have_content "A collaborative legislation process"
|
||||
expect(page).to have_css(".annotator-hl", count: 1)
|
||||
end
|
||||
end
|
||||
|
||||
context "Merged annotations", :js do
|
||||
|
||||
Reference in New Issue
Block a user