witten
/
luminotes
Archived
1
0
Fork 0

Improved the detection of whether an existing note has been altered.

* Using the browser's tweaked version of the initial HTML, instead of the HTML that we tell the browser to use.
 * Improved normalize_html() function to handle more cases.
 * Added start_dirty flag to Editor() constructor and made use of it for completely new notes.
This commit is contained in:
Dan Helfman 2008-05-18 01:07:15 -07:00
parent 1722d02317
commit 99c32fa120
2 changed files with 19 additions and 6 deletions

View File

@ -1,7 +1,8 @@
function Editor( id, notebook_id, note_text, deleted_from_id, revision, read_write, startup, highlight, focus, position_after ) {
function Editor( id, notebook_id, note_text, deleted_from_id, revision, read_write, startup, highlight, focus, position_after, start_dirty ) {
this.id = id;
this.notebook_id = notebook_id;
this.initial_text = note_text;
this.start_dirty = start_dirty;
this.deleted_from_id = deleted_from_id || null;
this.revision = revision;
this.user_revisions = new Array(); // cache for this note's list of revisions, loaded from the server on-demand
@ -136,7 +137,10 @@ Editor.prototype.finish_init = function () {
// since the browser may subtly tweak the html when it's inserted, save off the browser's version
// of the html here. this yields more accurate comparisons within the dirty() method
this.initial_text = this.document.body.innerHTML;
if ( this.start_dirty )
this.initial_text = "";
else
this.initial_text = this.document.body.innerHTML;
var self = this; // necessary so that the member functions of this editor object are used
if ( this.edit_enabled ) {
@ -714,10 +718,16 @@ Editor.prototype.summarize = function () {
// return the given html in a normal form. this makes html string comparisons more accurate
normalize_html = function ( html ) {
// remove any "pulldown" attributes
html = html.replace( /\s+pulldown="[^"]"/g, "" );
// remove any "pulldown" attributes, which get added in IE whenever link.pulldown is set
var normal_html = html.replace( /\s+pulldown="null"/g, "" );
return html;
// convert absolute URLs to the server into relative URLs. accomplish this by removing, for
// instance, "https://luminotes.com" from any URLs. this is necessary becuase IE insists on
// converting relative link URLs to absolute URLs
var base_url = window.location.protocol + "//" + window.location.host;
normal_html = normal_html.replace( '="' + base_url + '/', '="/' );
return normal_html;
}
Editor.prototype.dirty = function () {

View File

@ -685,9 +685,12 @@ Wiki.prototype.parse_loaded_editor = function ( result, note_title, requested_re
Wiki.prototype.create_editor = function ( id, note_text, deleted_from_id, revision, creation, read_write, highlight, focus, position_after ) {
var self = this;
var dirty = false;
if ( isUndefinedOrNull( id ) ) {
if ( this.notebook.read_write ) {
id = this.next_id;
dirty = true;
this.invoker.invoke( "/next_id", "POST", null,
function( result ) { self.update_next_id( result ); }
);
@ -708,7 +711,7 @@ Wiki.prototype.create_editor = function ( id, note_text, deleted_from_id, revisi
}
var startup = this.startup_notes[ id ];
var editor = new Editor( id, this.notebook_id, note_text, deleted_from_id, revision, read_write, startup, highlight, focus, position_after );
var editor = new Editor( id, this.notebook_id, note_text, deleted_from_id, revision, read_write, startup, highlight, focus, position_after, dirty );
if ( this.notebook.read_write ) {
connect( editor, "state_changed", this, "editor_state_changed" );