Build a rudimentary placeholder engine into the editor

This commit is contained in:
Eston Bond
2010-11-04 17:06:46 -07:00
parent a24d1ca78e
commit 055e80bbee
2 changed files with 75 additions and 17 deletions
+15 -11
View File
@@ -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;
@@ -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);