ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How could i autosave in CKEDITOR?

November 16, 2009 7:52am

Subscribe [4]
  • #1 / Nov 16, 2009 7:52am

    basty_dread

    107 posts

    Is there a way to autosave my work in ckeditor? i am using the latest ckeditor..

    Can anyone please help me. many thanks.

  • #2 / Nov 16, 2009 9:47am

    Flemming

    270 posts

    this post might help you:

    http://cksource.com/forums/viewtopic.php?f=6&t=14546&start=0

    search the page for ‘autosave’

  • #3 / Nov 16, 2009 9:34pm

    basty_dread

    107 posts

    hello i already saw this topic on that site,,

    but i just dont know how could i implement this code.

    can anyone explain it better?

    Thanks a lot ..

  • #4 / Jan 20, 2012 9:36am

    John56

    2 posts

    There is ready to use Autosave plugin for CKEditor.
    Please have a look at - http://cksource.com/forums/viewtopic.php?f=18&t=24128

    Regards,
    John

  • #5 / Jan 21, 2012 8:39am

    Try this code hopefully it will be helpful for you- 

    1.
        $(document).ready(function() {
    2.
    /* This section is CKEditor specific.
    3.
    It just updates the HTML fields to whatever
    4.
    content is in the CKEditor field.
    5.
    */
    6.
    for(var name in CKEDITOR.instances) {
    7.
    CKEDITOR.instances[name].on("instanceReady", function() {
    8.
    // Set keyup event
    9.
    this.document.on("keyup", updateValue);
    10.
    // Set paste event
    11.
    this.document.on("paste", updateValue);
    12.
    });
      13.
       
      14.
                  function updateValue() {
    15.
    CKEDITOR.instances[name].updateElement();
    16.
    $(‘textarea’).trigger(‘keyup’);
    17.
    }
      18.
              }
      19.
       
      20.
              /* This is the complete jQuery code for autosave.
      21.
              setTimeout() is called every 5 minutes while
      22.
              the inner function checks that the last save
      23.
              was at least 5 minutes ago before deciding
      24.
              to save.
      25.
              */
      26.
              var lastSaveTime = 0;
      27.
              var currentTime = 0;
      28.
              // Edit chapter
      29.
              $(“form”).keyup(function() {
    30.
    $(".autosaved_msg").hide();
    31.
    window.setTimeout(
    32.
    function() {
    33.
    currentTime = new Date().getTime();
    34.
    if ((currentTime - lastSaveTime) > 300000 || lastSaveTime == 0) {
    35.
    $.post("/url/to/post/to", $("form").serialize(),
    36.
    function(response, status) {
    37.
    /* "1" is the response value I chose to return
    38.
    upon a successful save.
    39.
    */
    40.
    if (response == 1 && status == "success") {
    41.
    $(".autosaved_msg").show();
    42.
    }
      43.
                                        }
      44.
                                  );
      45.
                                  lastSaveTime = new Date().getTime();
      46.
                              }
      47.
                        },
      48.
                        300000
      49.
                  );
      50.
              });
      51.
        });

  • #6 / Jan 23, 2012 8:29am

    John56

    2 posts

    @talentsfromindia with all do respect but you code requires user to use jQuery and it does not work for every possible change made in CKEditor.

    IMO this is better option - http://cksource.com/forums/viewtopic.php?f=18&t=24128

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases