witten
/
luminotes
Archived
1
0
Fork 0

Refactored Wiki.toggle_button to work mostly correctly, as the previous revision broke it.

This commit is contained in:
Dan Helfman 2007-11-30 01:43:06 +00:00
parent d9b36fa613
commit 83b3fb5baa
3 changed files with 14 additions and 39 deletions

5
NEWS
View File

@ -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.

View File

@ -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;
}

View File

@ -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 );