From f385ebaa9c049e79e003c435bc2da83710774cbc Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 15 Dec 2008 18:10:38 -0800 Subject: [PATCH] In the font pulldown, now showing the current font with a check mark. --- static/js/Editor.js | 4 ++++ static/js/Wiki.js | 30 +++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/static/js/Editor.js b/static/js/Editor.js index 4f5659f..1c7c4e0 100644 --- a/static/js/Editor.js +++ b/static/js/Editor.js @@ -285,6 +285,10 @@ Editor.prototype.insert_html = function ( html ) { } } +Editor.prototype.query_command_value = function ( command ) { + return this.document.queryCommandValue( command ); +} + // resize the editor's frame to fit the dimensions of its content Editor.prototype.resize = function () { if ( !this.document ) return; diff --git a/static/js/Wiki.js b/static/js/Wiki.js index 26145e9..68b4f9d 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -4226,6 +4226,7 @@ function Font_pulldown( wiki, notebook_id, invoker, anchor, editor ) { anchor.pulldown = this; this.anchor = anchor; this.editor = editor; + this.initial_check_mark = null; Pulldown.call( this, wiki, notebook_id, "font_pulldown", anchor ); @@ -4252,8 +4253,20 @@ function Font_pulldown( wiki, notebook_id, invoker, anchor, editor ) { var label = createDOM( "label", { "class": "pulldown_label font_label", "style": "font-family: " + font_family + ";" }, font_name ); + + var check_mark_char = document.createTextNode( "\u2714" ); + if ( editor.query_command_value( "fontname" ) == font_family ) { + var check_mark = createDOM( "span", {}, check_mark_char ); + this.initial_check_mark = check_mark; + } else { + var check_mark = createDOM( "span", { "class": "invisible" }, check_mark_char ); + } + + var div = createDOM( "div", {}, check_mark, " ", label ); + label.font_family = font_family; - appendChildNodes( this.div, createDOM( "div", {}, label ) ); + label.check_mark = check_mark; + appendChildNodes( this.div, div ); connect( label, "onclick", function ( event ) { self.font_name_clicked( event ); } ); } @@ -4265,10 +4278,17 @@ Font_pulldown.prototype.constructor = Font_pulldown; Font_pulldown.prototype.font_name_clicked = function ( event ) { var label = event.src(); - this.editor.focus(); - // FIXME: this doesn't work in IE 7 from this click handler, but it works elsewhere (like in the constructor) - this.editor.exec_command( "fontname", label.font_family ); - this.shutdown(); + if ( this.initial_check_mark ) + addElementClass( this.initial_check_mark, "invisible" ); + removeElementClass( label.check_mark, "invisible" ); + + var self = this; + setTimeout( function () { + self.editor.focus(); + // FIXME: this doesn't work in IE 7 from this click handler, but it works elsewhere (like in the constructor) + self.editor.exec_command( "fontname", label.font_family ); + self.shutdown(); + }, 100 ); } Font_pulldown.prototype.shutdown = function () {