From 055e80bbee52ef7b0b0f9bfa626a42eddfd925f4 Mon Sep 17 00:00:00 2001 From: Eston Bond Date: Thu, 4 Nov 2010 17:06:46 -0700 Subject: [PATCH] Build a rudimentary placeholder engine into the editor --- lib/gollum/frontend/public/css/editor.css | 26 ++++---- .../javascript/gollum-editor/gollum.editor.js | 66 +++++++++++++++++-- 2 files changed, 75 insertions(+), 17 deletions(-) diff --git a/lib/gollum/frontend/public/css/editor.css b/lib/gollum/frontend/public/css/editor.css index a6833e9d..525f1fe0 100644 --- a/lib/gollum/frontend/public/css/editor.css +++ b/lib/gollum/frontend/public/css/editor.css @@ -33,17 +33,6 @@ width: 100%; } -#gollum-editor-title-field input { - font-weight: bold; -} - -#gollum-editor-title-field.active { - border-bottom: 1px solid #ddd; - display: block; - margin: 0 0 0.3em 0; - padding: 0 0 0.5em 0; -} - #gollum-editor .singleline { display: block; margin: 0 0 0.7em 0; @@ -66,6 +55,21 @@ color: #999; } +#gollum-editor-title-field input { + font-weight: bold; +} + +#gollum-editor-title-field.active { + border-bottom: 1px solid #ddd; + display: block; + margin: 0 0 0.3em 0; + padding: 0 0 0.5em 0; +} + +#gollum-editor-title-field input#gollum-editor-page-title.ph { + color: #000; +} + /* @control editor-view-tab */ #gollum-editor #gollum-editor-type-switcher { display: none; diff --git a/lib/gollum/frontend/public/javascript/gollum-editor/gollum.editor.js b/lib/gollum/frontend/public/javascript/gollum-editor/gollum.editor.js index 7b0906db..1e027bf9 100644 --- a/lib/gollum/frontend/public/javascript/gollum-editor/gollum.editor.js +++ b/lib/gollum/frontend/public/javascript/gollum-editor/gollum.editor.js @@ -25,18 +25,18 @@ */ $.GollumEditor = function( IncomingOptions ) { - ActiveOptions = $.extend( DefaultOptions, IncomingOptions ); - + ActiveOptions = $.extend( DefaultOptions, IncomingOptions ); debug('GollumEditor loading'); if ( EditorHas.baseEditorMarkup() ) { - if ( ActiveOptions.NewFile ) { + if ( EditorHas.titleDisplayed() ) { $('#gollum-editor-title-field').addClass('active'); - $('#gollum-editor-title-field input').focus(function() { - $(this)[0].select(); - }); + } + + if ( EditorHas.editSummaryMarkup() ) { + Placeholder.add( $('#gollum-editor-edit-summary input') ) } // Initialize the function bar by loading proper definitions @@ -238,6 +238,10 @@ return ( ua.test( navigator.userAgent ) ); }, + editSummaryMarkup: function() { + return ( $('input#gollum-editor-message-field').length > 0 ); + }, + titleDisplayed: function() { return ( ActiveOptions.NewFile ); } @@ -609,5 +613,55 @@ $.GollumEditor.replaceSelection = function( repText ) { FunctionBar.replaceFieldSelection( $('#gollum-editor-body'), repText ); } + + + var Placeholder = { + + _PLACEHOLDERS : [], + + _p : function( $field ) { + + this.fieldObject = $field; + this.placeholderText = $field.val(); + var placeholderText = $field.val(); + + $field.addClass('ph'); + + $field.blur(function() { + if ( $(this).val() == '' ) { + $(this).val( placeholderText ); + $(this).addClass('ph'); + } + }); + + $field.focus(function() { + $(this).removeClass('ph'); + if ( $(this).val() == placeholderText ) { + $(this).val(''); + } else { + $(this)[0].select(); + } + }); + + }, + + add : function( $field ) { + Placeholder._PLACEHOLDERS.push( new Placeholder._p( $field ) ); + }, + + clearAll: function() { + for ( var i=0; i < Placeholder._PLACEHOLDERS.length; i++ ) { + if ( Placeholder._PLACEHOLDERS[i].fieldObject.val() == + Placeholder._PLACEHOLDERS[i].placeholderText ) { + Placeholder._PLACEHOLDERS[i].fieldObject.val(''); + } + } + }, + + exists : function() { + return ( _PLACEHOLDERS.length ); + } + + } // })(jQuery);