From 83b3fb5baafc55c92f89eeb35e1ccc5cbc8f51fb Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 30 Nov 2007 01:43:06 +0000 Subject: [PATCH] Refactored Wiki.toggle_button to work mostly correctly, as the previous revision broke it. --- NEWS | 5 +++++ static/js/Editor.js | 33 --------------------------------- static/js/Wiki.js | 15 +++++++++------ 3 files changed, 14 insertions(+), 39 deletions(-) diff --git a/NEWS b/NEWS index d738abb..53605bd 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +1.0.4: November ??, 2007 + * When the web browser is resized, all notes are automatically resized as well. + * Fixed note focusing in Safari. + * Fixed note state detection (bold, italic, etc.) in Safari. + 1.0.3: November 28, 2007 * Updated logo, which is now an image and could be theoretically replaced for branding purposes. diff --git a/static/js/Editor.js b/static/js/Editor.js index 497c7ee..b40a543 100644 --- a/static/js/Editor.js +++ b/static/js/Editor.js @@ -491,39 +491,6 @@ Editor.prototype.focus = function () { this.iframe.contentWindow.focus(); } -// return true if the specified state is enabled -Editor.prototype.state_enabled = function ( state_name ) { - if ( !this.read_write ) return false; - - var node_name = state_name.toLowerCase(); - - if ( state_name == "b" && this.state_enabled( "h3" ) ) - return false; - - // to determine whether the specified state is enabled, see whether the current selection is - // contained (directly or indirectly) by a node of the appropriate type (e.g. "h3", "a", etc.) - var node; - if ( window.getSelection ) { // browsers such as Firefox - var selection = this.iframe.contentWindow.getSelection(); - var range = selection.getRangeAt( 0 ); - node = range.endContainer; - } else if ( this.document.selection ) { // browsers such as IE - var range = this.document.selection.createRange(); - node = range.parentElement(); - } - - while ( node.nodeName.toLowerCase() != node_name ) { - node = node.parentNode; - if ( !node ) - return false; - } - - if ( state_name == "a" && !node.href ) - return false; - - return true; -} - Editor.prototype.contents = function () { return this.document.body.innerHTML; } diff --git a/static/js/Wiki.js b/static/js/Wiki.js index fc4fab5..005961d 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -247,7 +247,7 @@ Wiki.prototype.populate = function ( startup_notes, current_notes, note_read_wri connect( "bold", "onclick", function ( event ) { self.toggle_button( event, "bold" ); } ); connect( "italic", "onclick", function ( event ) { self.toggle_button( event, "italic" ); } ); connect( "underline", "onclick", function ( event ) { self.toggle_button( event, "underline" ); } ); - connect( "title", "onclick", function ( event ) { self.toggle_button( event, "title", "h3" ); } ); + connect( "title", "onclick", function ( event ) { self.toggle_button( event, "title" ); } ); connect( "insertUnorderedList", "onclick", function ( event ) { self.toggle_button( event, "insertUnorderedList" ); } ); connect( "insertOrderedList", "onclick", function ( event ) { self.toggle_button( event, "insertOrderedList" ); } ); @@ -733,7 +733,7 @@ Wiki.prototype.editor_key_pressed = function ( editor, event ) { this.toggle_button( event, "underline" ); // ctrl-t: title } else if ( code == 84 ) { - this.toggle_button( event, "title", "h3" ); + this.toggle_button( event, "title" ); // ctrl-period: unordered list } else if ( code == 190 ) { this.toggle_button( event, "insertUnorderedList" ); @@ -845,22 +845,25 @@ Wiki.prototype.toggle_image_button = function ( name ) { } } -Wiki.prototype.toggle_button = function ( event, button_id, state_name ) { +Wiki.prototype.toggle_button = function ( event, button_id ) { this.clear_messages(); this.clear_pulldowns(); if ( this.focused_editor && this.focused_editor.read_write ) { this.focused_editor.focus(); - this.focused_editor.exec_command( state_name || button_id ); + if ( button_id == "title" ) + this.focused_editor.exec_command( "h3" ); + else + this.focused_editor.exec_command( button_id ); this.focused_editor.resize(); - this.update_button( button_id, state_name ); + this.toggle_image_button( button_id ); } event.stop(); } Wiki.prototype.update_button = function ( button_id, state_name, node_names ) { - if ( this.focused_editor.state_enabled( state_name || button_id, node_names ) ) + if ( this.focused_editor.state_enabled( state_name, node_names ) ) this.down_image_button( button_id ); else this.up_image_button( button_id );