diff --git a/lib/gollum/frontend/public/css/editor.css b/lib/gollum/frontend/public/css/editor.css index 604e5c62..fc186164 100755 --- a/lib/gollum/frontend/public/css/editor.css +++ b/lib/gollum/frontend/public/css/editor.css @@ -84,16 +84,23 @@ a { #gollum-editor #gollum-editor-function-bar { border-bottom: 1px solid #ddd; overflow: hidden; - padding: 0 0 1.1em 0; - display: none; + padding: 0; } + #gollum-editor-title-field + #gollum-editor-function-bar { margin-top: 0.6em; } -#gollum-editor #gollum-editor-function-bar.active { +#gollum-editor #gollum-editor-function-bar #gollum-editor-function-buttons { + display: none; +} + +#gollum-editor #gollum-editor-function-bar.active #gollum-editor-function-buttons { display: block; + float: left; + overflow: hidden; + padding: 0 0 1.1em 0; } #gollum-editor #gollum-editor-function-bar a.function-button { @@ -179,6 +186,11 @@ a#function-help:hover span { background-position: -405px -28px; } width: 0.5em; } +#gollum-editor #gollum-editor-function-bar #gollum-editor-format-selector { + overflow: hidden; + padding: 0 0 1.1em 0; +} + #gollum-editor #gollum-editor-function-bar #gollum-editor-format-selector select { background-color: #f9f9f9; diff --git a/lib/gollum/frontend/public/javascript/gollum-editor/gollum.editor.js b/lib/gollum/frontend/public/javascript/gollum-editor/gollum.editor.js old mode 100644 new mode 100755 index 780a9384..bba422db --- a/lib/gollum/frontend/public/javascript/gollum-editor/gollum.editor.js +++ b/lib/gollum/frontend/public/javascript/gollum-editor/gollum.editor.js @@ -80,26 +80,12 @@ if ( htmlSetMarkupLang ) { ActiveOptions.MarkupType = htmlSetMarkupLang; } - - if ( !LanguageDefinition.isLoadedFor(ActiveOptions.MarkupType) ) { - debug('Loading language definition for ' + ActiveOptions.MarkupType); - LanguageDefinition.loadFor( ActiveOptions.MarkupType, - function(data, textStatus) { - if ( textStatus != 'success' ) { - debug('Language definition could not be loaded for markup ' - + 'type ' + ActiveOptions.MarkupType); - return; - } - - if ( EditorHas.formatSelector() ) { - FormatSelector.init( - $('#gollum-editor-format-selector select') ); - } - - // activate the function bar - debug('Activating function bar'); - FunctionBar.activate(); - } ); + + // load language definition + LanguageDefinition.setActiveLanguage( ActiveOptions.MarkupType ); + if ( EditorHas.formatSelector() ) { + FormatSelector.init( + $('#gollum-editor-format-selector select') ); } if ( EditorHas.help() ) { @@ -175,12 +161,25 @@ setActiveLanguage: function( name ) { if ( !LanguageDefinition.isLoadedFor(name) ) { - LanguageDefinition.loadFor( name ); + LanguageDefinition._ACTIVE_LANG = null; + LanguageDefinition.loadFor( name, function(x, t) { + if ( t != 'success' ) { + debug('Failed to load language definition for ' + name); + return; + } + + // update features that rely on the language definition + if ( EditorHas.functionBar() ) + FunctionBar.refresh(); + + if ( LanguageDefinition.isValid() && EditorHas.formatSelector() ) + FormatSelector.updateSelected(); + + } ); } else { LanguageDefinition._ACTIVE_LANG = name; + FunctionBar.refresh(); } - // tell help we switched languages - Help.setActiveHelp(name); }, @@ -245,6 +244,12 @@ return true; } return false; + }, + + isValid: function() { + return ( LanguageDefinition._ACTIVE_LANG && + typeof LanguageDefinition._LANG[LanguageDefinition._ACTIVE_LANG] == + 'object' ); } }; @@ -395,10 +400,14 @@ * */ activate: function() { + debug('Activating function bar'); + // check these out $('#gollum-editor-function-bar a.function-button').each(function() { - if ( LanguageDefinition.getDefinitionFor( $(this).attr('id') ) ) + if ( LanguageDefinition.getDefinitionFor( $(this).attr('id') ) ) { $(this).click( FunctionBar.evtFunctionButtonClick ); + $(this).removeClass('disabled'); + } else if ( $(this).attr('id') != 'function-help' ) $(this).addClass('disabled'); }); @@ -409,6 +418,13 @@ }, + deactivate: function() { + $('#gollum-editor-function-bar a.function-button').unbind('click'); + $('#gollum-editor-function-bar').removeClass( 'active' ); + FunctionBar.isActive = false; + }, + + /** * FunctionBar.evtFunctionButtonClick * Event handler for the function buttons. Traps the click and @@ -517,6 +533,28 @@ }, + isShown: function() { + return ($('#gollum-editor-function-bar').is(':visible')); + }, + + refresh: function() { + if ( EditorHas.functionBar() ) { + if ( LanguageDefinition.isValid() ) { + $('#gollum-editor-function-bar a.function-button').unbind('click'); + FunctionBar.activate(); + if ( Help ) + Help.setActiveHelp( LanguageDefinition.getActiveLanguage() ); + } else { + debug('Language definition is invalid.'); + if ( FunctionBar.isShown() ) { + // deactivate the function bar; it's not gonna work now + FunctionBar.deactivate(); + } + } + } + }, + + /** * replaceFieldSelection * Replaces the currently selected substring of the textarea with @@ -589,13 +627,27 @@ init: function( $sel ) { debug('Initializing format selector'); + // unbind events if init is being called twice for some reason + if ( FormatSelector.$_SELECTOR && + typeof FormatSelector.$_SELECTOR == 'object' ) { + FormatSelector.$_SELECTOR.unbind( 'change' ); + } + FormatSelector.$_SELECTOR = $sel; // set format selector to the current language + FormatSelector.updateSelected(); + FormatSelector.$_SELECTOR.change( FormatSelector.evtChangeFormat ); + }, + + + /** + * FormatSelector.update + */ + updateSelected: function() { var currentLang = LanguageDefinition.getActiveLanguage(); FormatSelector.$_SELECTOR.val( currentLang ); - FormatSelector.$_SELECTOR.change( FormatSelector.evtChangeFormat ); - } + } }; diff --git a/lib/gollum/frontend/templates/editor.mustache b/lib/gollum/frontend/templates/editor.mustache old mode 100644 new mode 100755 index 24d63c5b..4e901a56 --- a/lib/gollum/frontend/templates/editor.mustache +++ b/lib/gollum/frontend/templates/editor.mustache @@ -16,6 +16,7 @@ {{/is_edit_page}}