From 99c32fa1206e38e818b6ea0a6198d2b234474180 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sun, 18 May 2008 01:07:15 -0700 Subject: [PATCH] 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. --- static/js/Editor.js | 20 +++++++++++++++----- static/js/Wiki.js | 5 ++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/static/js/Editor.js b/static/js/Editor.js index ecbfb04..305b53a 100644 --- a/static/js/Editor.js +++ b/static/js/Editor.js @@ -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 () { diff --git a/static/js/Wiki.js b/static/js/Wiki.js index 0463b82..c362e3e 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -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" );