Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
in Plugins by

I'm using AutoSave plugin of CKEditor to save the typed contents automatically. There is a setting for this to kill the typed contents on some actions like clicking on the Save or Cancel button. For Q2A  what would be the correct values for these? 

config.autosave_saveDetectionSelectors = "a[href^='javascript:__doPostBack'][id*='Save'],a[id*='Cancel']";


Q2A version: 1.8

1 Answer

+1 vote
selected by
Best answer

I've just tried it and it doesn't work for some reason. I've added the selector but still content is not cleared.

Theoretically, for the ask page, it should be:

config.autosave_saveDetectionSelectors = "input[value='Ask the Question']";

As the documentation of the plugin is almost non-existent it is hard to figure out why it isn't working.

Anyway, you can do the following.

1. Edit file qa-plugin/wysiwyg-editor/qa-wysiwyg-editor.php

2. Replace the load_script() function with this one:

public function load_script($fieldname)
    $extra = <<<JS
        $("input[value='Ask the Question']").click(function() { localStorage.removeItem("autosavecke_1"); });
        "if (qa_ckeditor_" . $fieldname . " = CKEDITOR.replace(" . qa_js($fieldname) . ", qa_wysiwyg_editor_config)) { " .
        "qa_ckeditor_" . $fieldname . ".setData(document.getElementById(" . qa_js($fieldname . '_ckeditor_data') . ").value); " .
        "document.getElementById(" . qa_js($fieldname . '_ckeditor_ok') . ").value = 1; " .
        $extra .

Clear cache and try again in the ask page. It should clear the saved data when the button is clicked. The thing is that, in any approach (even in the original that is not working for me) you will have to locate the buttons you want to save and add them to the selector.

For example, when answering you should use Add answer or even the button class which, might depend on your theme, which in this site, is qa-form-tall-button-answer. If you want to be more specific you can even use the classes of the body tag which usually filter by section, e.g., qa-template-ask.


I've just realized the link you provided links to 0.2 which is an old version. Current version is hosted here: https://github.com/w8tcha/CKEditor-AutoSave-Plugin/releases . Using that version made the selector work (it wasn't implemented in the old one I tried!). This means there is no need to modify the load_script() function.

edited by
Thank you Pupi :)