diff --git a/lib/gollum/frontend/public/javascript/editor/gollum.editor.js b/lib/gollum/frontend/public/javascript/editor/gollum.editor.js index 7dd6d3da..d260041f 100755 --- a/lib/gollum/frontend/public/javascript/editor/gollum.editor.js +++ b/lib/gollum/frontend/public/javascript/editor/gollum.editor.js @@ -233,7 +233,7 @@ } // attempt to load the definition for this language - var script_uri = '/javascript/editor/langs/' + markup_name + '.js'; + var script_uri = '/javascripts/editor/langs/' + markup_name + '.js'; $.ajax({ url: script_uri, dataType: 'script', @@ -776,226 +776,215 @@ var Help = { _ACTIVE_HELP: '', - _LOADED_HELP_LANGS: [], - _HELP: {}, + _LOADED_HELP_LANGS: [], + _HELP: {}, + + /** + * Help.define + * + * Defines a new help context and enables the help function if it + * exists in the Gollum Function Bar. + * + * @param string name The name you're giving to this help context. + * Generally, this should match the language name. + * @param object definitionObject The definition object being loaded from a + * language / help definition file. + * @return void + */ + define: function( name, definitionObject ) { + if ( Help.isValidHelpFormat( definitionObject ) ) { + debug('help is a valid format'); + + Help._ACTIVE_HELP_LANG = name; + Help._LOADED_HELP_LANGS.push( name ); + Help._HELP[name] = definitionObject; + + if ( $("#function-help").length ) { + if ( $('#function-help').hasClass('disabled') ) { + $('#function-help').removeClass('disabled'); + } + $('#function-help').unbind('click'); + $('#function-help').click( Help.evtHelpButtonClick ); + + // generate help menus + Help.generateHelpMenuFor( name ); + } + } else { + if ( $('#function-help').length ) { + $('#function-help').addClass('disabled'); + } + } + }, + + /** + * Help.generateHelpMenuFor + * Generates the markup for the main help menu given a context name. + * + * @param string name The context name. + * @return void + */ + generateHelpMenuFor: function( name ) { + if ( !Help._HELP[name] ) { + debug('Help is not defined for ' + name.toString()); + return false; + } + var helpData = Help._HELP[name]; + + if ( EditorHas.mathJax() && Help.isLoadedFor('mathjax') ) { + debug('Adding MathJax support to help'); + // TODO + } + + // clear this shiz out + $('#gollum-editor-help-parent').html(''); + $('#gollum-editor-help-list').html(''); + $('#gollum-editor-help-content').html(''); + + // go go inefficient algorithm + for ( var i=0; i < helpData.length; i++ ) { + if ( typeof helpData[i] != 'object' ) { + break; + } + + var $newLi = $('
  • ' + + helpData[i].menuName + '
  • '); + $('#gollum-editor-help-parent').append( $newLi ); + if ( i === 0 ) { + // select on first run + $newLi.children('a').addClass('selected'); + } + $newLi.children('a').click( Help.evtParentMenuClick ); + } + + // generate parent submenu on first run + Help.generateSubMenu( helpData[0], 0 ); + $($('#gollum-editor-help-list li a').get(0)).click(); + + }, + + /** + * Help.generateSubMenu + * Generates the markup for the inline help sub-menu given the data + * object for the submenu and the array index to start at. + * + * @param object subData The data for the sub-menu. + * @param integer index The index clicked on (parent menu index). + * @return void + */ + generateSubMenu: function( subData, index ) { + $('#gollum-editor-help-list').html(''); + $('#gollum-editor-help-content').html(''); + for ( var i=0; i < subData.content.length; i++ ) { + if ( typeof subData.content[i] != 'object' ) { + break; + } + + var $subLi = $('
  • ' + + subData.content[i].menuName + '
  • '); - /** - * Help.define - * - * Defines a new help context and enables the help function if it - * exists in the Gollum Function Bar. - * - * @param string name The name you're giving to this help context. - * Generally, this should match the language name. - * @param object definitionObject The definition object being loaded from a - * language / help definition file. - * @return void - */ - define: function( name, definitionObject ) { - if ( Help.isValidHelpFormat( definitionObject ) ) { - debug('help is a valid format'); + $('#gollum-editor-help-list').append( $subLi ); + $subLi.children('a').click( Help.evtSubMenuClick ); + } + }, - Help._ACTIVE_HELP_LANG = name; - Help._LOADED_HELP_LANGS.push( name ); - Help._HELP[name] = definitionObject; + hide: function() { + if ( $.browser.msie ) { + $('#gollum-editor-help').css('display', 'none'); + } else { + $('#gollum-editor-help').animate({ + opacity: 0 + }, 200, function() { + $('#gollum-editor-help') + .animate({ height: 'hide' }, 200); + }); + } + }, - if ( $("#function-help").length ) { - if ( $('#function-help').hasClass('disabled') ) { - $('#function-help').removeClass('disabled'); - } - $('#function-help').unbind('click'); - $('#function-help').click( Help.evtHelpButtonClick ); + show: function() { + if ( $.browser.msie ) { + // bypass effects for internet explorer, since it does weird crap + // to text antialiasing with opacity animations + $('#gollum-editor-help').css('display', 'block'); + } else { + $('#gollum-editor-help').animate({ + height: 'show' + }, 200, function() { + $('#gollum-editor-help') + .animate({ opacity: 1 }, 300); + }); + } + }, - // generate help menus - Help.generateHelpMenuFor( name ); - } - } else { - if ( $('#function-help').length ) { - $('#function-help').addClass('disabled'); - } - } - }, + /** + * Help.showHelpFor + * Displays the actual help content given the two menu indexes, which are + * rendered in the rel="" attributes of the help menus + * + * @param integer index1 parent index + * @param integer index2 submenu index + * @return void + */ + showHelpFor: function( index1, index2 ) { + var html = + Help._HELP[Help._ACTIVE_HELP_LANG][index1].content[index2].data; + $('#gollum-editor-help-content').html(html); + }, + /** + * Help.isLoadedFor + * Returns true if help is loaded for a specific markup language, + * false otherwise. + * + * @param string name The name of the markup language. + * @return boolean + */ + isLoadedFor: function( name ) { + for ( var i=0; i < Help._LOADED_HELP_LANGS.length; i++ ) { + if ( name == Help._LOADED_HELP_LANGS[i] ) { + return true; + } + } + return false; + }, - /** - * Help.generateHelpMenuFor - * Generates the markup for the main help menu given a context name. - * - * @param string name The context name. - * @return void - */ - generateHelpMenuFor: function( name ) { - if ( !Help._HELP[name] ) { - debug('Help is not defined for ' + name.toString()); - return false; - } - var helpData = Help._HELP[name]; + isShown: function() { + return ($('#gollum-editor-help').is(':visible')); + }, - if ( EditorHas.mathJax() && Help.isLoadedFor('mathjax') ) { - debug('Adding MathJax support to help'); - // TODO - } + /** + * Help.isValidHelpFormat + * Does a quick check to make sure that the help definition isn't in a + * completely messed-up format. + * + * @param object (Array) helpArr The help definition array. + * @return boolean + */ + isValidHelpFormat: function( helpArr ) { + return ( typeof helpArr == 'object' && + helpArr.length && + typeof helpArr[0].menuName == 'string' && + typeof helpArr[0].content == 'object' && + helpArr[0].content.length ); + }, - // clear this shiz out - $('#gollum-editor-help-parent').html(''); - $('#gollum-editor-help-list').html(''); - $('#gollum-editor-help-content').html(''); - - // go go inefficient algorithm - for ( var i=0; i < helpData.length; i++ ) { - if ( typeof helpData[i] != 'object' ) { - break; - } - - var $newLi = $('
  • ' + - helpData[i].menuName + '
  • '); - $('#gollum-editor-help-parent').append( $newLi ); - if ( i === 0 ) { - // select on first run - $newLi.children('a').addClass('selected'); - } - $newLi.children('a').click( Help.evtParentMenuClick ); - } - - // generate parent submenu on first run - Help.generateSubMenu( helpData[0], 0 ); - $($('#gollum-editor-help-list li a').get(0)).click(); - - }, - - - /** - * Help.generateSubMenu - * Generates the markup for the inline help sub-menu given the data - * object for the submenu and the array index to start at. - * - * @param object subData The data for the sub-menu. - * @param integer index The index clicked on (parent menu index). - * @return void - */ - generateSubMenu: function( subData, index ) { - $('#gollum-editor-help-list').html(''); - $('#gollum-editor-help-content').html(''); - for ( var i=0; i < subData.content.length; i++ ) { - if ( typeof subData.content[i] != 'object' ) { - break; - } - - var $subLi = $('
  • ' + - subData.content[i].menuName + '
  • '); - - - $('#gollum-editor-help-list').append( $subLi ); - $subLi.children('a').click( Help.evtSubMenuClick ); - } - }, - - - hide: function() { - if ( $.browser.msie ) { - $('#gollum-editor-help').css('display', 'none'); - } else { - $('#gollum-editor-help').animate({ - opacity: 0 - }, 200, - function() { - $('#gollum-editor-help') - .animate({ height: 'hide' }, 200); - }); - } - }, - - show: function() { - if ( $.browser.msie ) { - // bypass effects for internet explorer, since it does weird crap - // to text antialiasing with opacity animations - $('#gollum-editor-help').css('display', 'block'); - } else { - $('#gollum-editor-help').animate({ - height: 'show' - }, 200, - function() { - $('#gollum-editor-help') - .animate({ opacity: 1 }, 300); - }); - } - }, - - - /** - * Help.showHelpFor - * Displays the actual help content given the two menu indexes, which are - * rendered in the rel="" attributes of the help menus - * - * @param integer index1 parent index - * @param integer index2 submenu index - * @return void - */ - showHelpFor: function( index1, index2 ) { - var html = - Help._HELP[Help._ACTIVE_HELP_LANG][index1].content[index2].data; - $('#gollum-editor-help-content').html(html); - }, - - - /** - * Help.isLoadedFor - * Returns true if help is loaded for a specific markup language, - * false otherwise. - * - * @param string name The name of the markup language. - * @return boolean - */ - isLoadedFor: function( name ) { - for ( var i=0; i < Help._LOADED_HELP_LANGS.length; i++ ) { - if ( name == Help._LOADED_HELP_LANGS[i] ) { - return true; - } - } - return false; - }, - - - isShown: function() { - return ( $('#gollum-editor-help').is(':visible') ); - }, - - - /** - * Help.isValidHelpFormat - * Does a quick check to make sure that the help definition isn't in a - * completely messed-up format. - * - * @param object (Array) helpArr The help definition array. - * @return boolean - */ - isValidHelpFormat: function( helpArr ) { - return ( typeof helpArr == 'object' && - helpArr.length && - typeof helpArr[0].menuName == 'string' && - typeof helpArr[0].content == 'object' && - helpArr[0].content.length ); - }, - - - /** - * Help.setActiveHelp - * Sets the active help definition to the one defined in the argument, - * re-rendering the help menu to match the new definition. - * - * @param string name The name of the help definition. - * @return void - */ - setActiveHelp: function( name ) { - if ( !Help.isLoadedFor( name ) ) { - if ( $('#function-help').length ) { - $('#function-help').addClass('disabled'); - } - if ( Help.isShown() ) { - Help.hide(); - } - } else { + /** + * Help.setActiveHelp + * Sets the active help definition to the one defined in the argument, + * re-rendering the help menu to match the new definition. + * + * @param string name The name of the help definition. + * @return void + */ + setActiveHelp: function( name ) { + if ( !Help.isLoadedFor( name ) ) { + if ( $('#function-help').length ) { + $('#function-help').addClass('disabled'); + } + if ( Help.isShown() ) { + Help.hide(); + } + } else { Help._ACTIVE_HELP_LANG = name; if ( $("#function-help").length ) { if ( $('#function-help').hasClass('disabled') ) { @@ -1005,80 +994,76 @@ $('#function-help').click( Help.evtHelpButtonClick ); Help.generateHelpMenuFor( name ); } - } - }, + } + }, + /** + * Help.evtHelpButtonClick + * Event handler for clicking the help button in the function bar. + * + * @param jQuery.Event e The jQuery event object. + * @return void + */ + evtHelpButtonClick: function( e ) { + e.preventDefault(); + if ( Help.isShown() ) { Help.hide(); } + else { Help.show(); } + }, - /** - * Help.evtHelpButtonClick - * Event handler for clicking the help button in the function bar. - * - * @param jQuery.Event e The jQuery event object. - * @return void - */ - evtHelpButtonClick: function( e ) { - e.preventDefault(); - if ( Help.isShown() ) { Help.hide(); } - else { Help.show(); } - }, + /** + * Help.evtParentMenuClick + * Event handler for clicking on an item in the parent menu. Automatically + * renders the submenu for the parent menu as well as the first result for + * the actual plain text. + * + * @param jQuery.Event e The jQuery event object. + * @return void + */ + evtParentMenuClick: function( e ) { + e.preventDefault(); + // short circuit if we've selected this already + if ( $(this).hasClass('selected') ) { return; } + // populate from help data for this + var helpIndex = $(this).attr('rel'); + var subData = Help._HELP[Help._ACTIVE_HELP_LANG][helpIndex]; - /** - * Help.evtParentMenuClick - * Event handler for clicking on an item in the parent menu. Automatically - * renders the submenu for the parent menu as well as the first result for - * the actual plain text. - * - * @param jQuery.Event e The jQuery event object. - * @return void - */ - evtParentMenuClick: function( e ) { - e.preventDefault(); - // short circuit if we've selected this already - if ( $(this).hasClass('selected') ) { return; } + $('#gollum-editor-help-parent li a').removeClass('selected'); + $(this).addClass('selected'); + Help.generateSubMenu( subData, helpIndex ); + $($('#gollum-editor-help-list li a').get(0)).click(); + }, - // populate from help data for this - var helpIndex = $(this).attr('rel'); - var subData = Help._HELP[Help._ACTIVE_HELP_LANG][helpIndex]; + /** + * Help.evtSubMenuClick + * Event handler for clicking an item in a help submenu. Renders the + * appropriate text for the submenu link. + * + * @param jQuery.Event e The jQuery event object. + * @return void + */ + evtSubMenuClick: function( e ) { + e.preventDefault(); + if ( $(this).hasClass('selected') ) { return; } - $('#gollum-editor-help-parent li a').removeClass('selected'); - $(this).addClass('selected'); - Help.generateSubMenu( subData, helpIndex ); - $($('#gollum-editor-help-list li a').get(0)).click(); - }, + // split index rel data + var rawIndex = $(this).attr('rel').split(':'); + $('#gollum-editor-help-list li a').removeClass('selected'); + $(this).addClass('selected'); + Help.showHelpFor( rawIndex[0], rawIndex[1] ); + } + }; + // Publicly-accessible function to Help.define + $.GollumEditor.defineHelp = Help.define; - /** - * Help.evtSubMenuClick - * Event handler for clicking an item in a help submenu. Renders the - * appropriate text for the submenu link. - * - * @param jQuery.Event e The jQuery event object. - * @return void - */ - evtSubMenuClick: function( e ) { - e.preventDefault(); - if ( $(this).hasClass('selected') ) { return; } + // Dialog exists as its own thing now + $.GollumEditor.Dialog = $.GollumDialog; + $.GollumEditor.replaceSelection = function( repText ) { + FunctionBar.replaceFieldSelection( $('#gollum-editor-body'), repText ); + }; - // split index rel data - var rawIndex = $(this).attr('rel').split(':'); - $('#gollum-editor-help-list li a').removeClass('selected'); - $(this).addClass('selected'); - Help.showHelpFor( rawIndex[0], rawIndex[1] ); - } - }; - - - // Publicly-accessible function to Help.define - $.GollumEditor.defineHelp = Help.define; - - // Dialog exists as its own thing now - $.GollumEditor.Dialog = $.GollumDialog; - $.GollumEditor.replaceSelection = function( repText ) { - FunctionBar.replaceFieldSelection( $('#gollum-editor-body'), repText ); - }; - - // Placeholder exists as its own thing now - $.GollumEditor.Placeholder = $.GollumPlaceholder; + // Placeholder exists as its own thing now + $.GollumEditor.Placeholder = $.GollumPlaceholder; })(jQuery);