add IsDirty() function
Status: Beta
Brought to you by:
fermads
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
Logged In: YES
user_id=1695796
Originator: NO
something like ?
isDirty = function() {
return textarea.innerHTML == cp.getCode();
}
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.
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...
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;
}
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 :)
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 :)