Menu

#46 add IsDirty() function

open
nobody
None
3
2007-10-17
2007-08-31
Kae Verens
No

I'd like to be able to check the status of a CodePress instance to see if something has changed since it was set.

in FCKeditor, it would involve a call to a .IsDirty() function, which would return true if content was changed.

also, a ResetIsDirty would be nice, to set it back to false if the data was synced with the original textarea

Discussion

  • pyrou

    pyrou - 2007-10-17
    • priority: 5 --> 3
     
  • pyrou

    pyrou - 2007-10-17

    Logged In: YES
    user_id=1695796
    Originator: NO

    something like ?

    isDirty = function() {
    return textarea.innerHTML == cp.getCode();
    }

     
  • Kae Verens

    Kae Verens - 2007-10-17

    Logged In: YES
    user_id=1092482
    Originator: YES

    yup. as simple as that.

    no point me hacking it in myself, as I would forget I'd done it, upgrade CodePress at some point, and not realise that I'd just broken my own code by doing that.

     
  • Martin Daniel Kirk

    Logged In: YES
    user_id=577658
    Originator: NO

    i've made an external isDirty function...

    www.mdk-photo.com/trial

    currently it ignores arrow-keys but possible to upgrade for ignoring more keys...

     
  • Kae Verens

    Kae Verens - 2007-10-17

    Logged In: YES
    user_id=1092482
    Originator: YES

    a more efficient way to check might be to have an actual variable "_dirty" which is true or false. this can be set to true when someone presses a key which changes the codepress content or does something similar with a mouse action.

    that way the check would be:

    isDirty=function(){
    return textarea._dirty || (textarea.innerHTML == cp.getCode() );
    }

    then you could also have a resetDirty function:

    resetDirty=function(){
    textarea.innserHTML=cp.getCode();
    textarea._dirty=false;
    }

     
  • Martin Daniel Kirk

    Logged In: YES
    user_id=577658
    Originator: NO

    i am currently working on a better isDirty function

    my solution will not have a function inside CodePress because i shift code in and out (Tabs)
    however, if you only have one active CP editor, you might move my isDirty from outside to inside CP

    i'll use MD5 Hash instead of a huge variable comparison

    i'll report back when im done :)

     
  • Martin Daniel Kirk

    Logged In: YES
    user_id=577658
    Originator: NO

    just tried MD5... ITS PRETTY HEAVY !!

    and i guess that (OldCode == NewCode) is just as heavy !!

    so now its back to checking for keys :)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.