From 1f948e30d868872c70647d6c128879cf2cf9604b Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 27 Sep 2011 14:27:37 -0500 Subject: [PATCH 1/9] Cleanup gollum.js trailing whitespace --- .../frontend/public/javascript/gollum.js | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/lib/gollum/frontend/public/javascript/gollum.js b/lib/gollum/frontend/public/javascript/gollum.js index 85836f3f..c8de28a6 100755 --- a/lib/gollum/frontend/public/javascript/gollum.js +++ b/lib/gollum/frontend/public/javascript/gollum.js @@ -1,6 +1,6 @@ // ua $(document).ready(function() { - + // ua detection if ($.browser.mozilla) { $('body').addClass('ff'); @@ -14,7 +14,7 @@ $(document).ready(function() { $('body').addClass('ie8'); } } - + if ($('#minibutton-new-page').length) { $('#minibutton-new-page').removeClass('jaws'); $('#minibutton-new-page').click(function(e) { @@ -38,7 +38,7 @@ $(document).ready(function() { }); }); } - + if ($('#wiki-wrapper').hasClass('history')) { $('#wiki-history td.checkbox input').each(function() { $(this).click(highlightChecked); @@ -53,9 +53,7 @@ $(document).ready(function() { }); } } - - if ($('#searchbar a#search-submit').length) { $.GollumPlaceholder.add($('#searchbar #search-query')); $('#searchbar a#search-submit').click(function(e) { @@ -67,8 +65,8 @@ $(document).ready(function() { $(this).unbind('submit'); $(this).submit(); }); - } - + } + if ($('#gollum-revert-form').length && $('.gollum-revert-button').length ) { $('a.gollum-revert-button').click(function(e) { @@ -76,28 +74,28 @@ $(document).ready(function() { $('#gollum-revert-form').submit(); }); } - + }); var nodeSelector = { - + node1: null, node2: null, - + selectNodeRange: function( n1, n2 ) { if ( nodeSelector.node1 && nodeSelector.node2 ) { $('#wiki-history td.selected').removeClass('selected'); nodeSelector.node1.addClass('selected'); nodeSelector.node2.addClass('selected'); - + // swap the nodes around if they went in reverse - if ( nodeSelector.nodeComesAfter( nodeSelector.node1, + if ( nodeSelector.nodeComesAfter( nodeSelector.node1, nodeSelector.node2 ) ) { var n = nodeSelector.node1; nodeSelector.node1 = nodeSelector.node2; nodeSelector.node2 = n; } - + var s = true; var $nextNode = nodeSelector.node1.next(); while ( $nextNode ) { @@ -109,7 +107,7 @@ var nodeSelector = { } } }, - + nodeComesAfter: function ( n1, n2 ) { var s = false; $(n1).prevAll().each(function() { @@ -119,13 +117,13 @@ var nodeSelector = { }); return s; }, - + checkNode: function( nodeCheckbox ) { var $nodeCheckbox = nodeCheckbox; var $node = $(nodeCheckbox).parent().parent(); // if we're unchecking if ( !$nodeCheckbox.is(':checked') ) { - + // remove the range, since we're breaking it $('#wiki-history tr.selected').each(function() { if ( $(this).find('td.checkbox input').is(':checked') ) { @@ -133,7 +131,7 @@ var nodeSelector = { } $(this).removeClass('selected'); }); - + // no longer track this if ( $node[0] == nodeSelector.node1[0] ) { nodeSelector.node1 = null; @@ -144,7 +142,7 @@ var nodeSelector = { } else if ( $node[0] == nodeSelector.node2[0] ) { nodeSelector.node2 = null; } - + } else { if ( !nodeSelector.node1 ) { nodeSelector.node1 = $node; @@ -153,7 +151,7 @@ var nodeSelector = { // okay, we don't have a node 2 but have a node1 nodeSelector.node2 = $node; nodeSelector.node2.addClass('selected'); - nodeSelector.selectNodeRange( nodeSelector.node1, + nodeSelector.selectNodeRange( nodeSelector.node1, nodeSelector.node2 ); } else { // we have two selected already @@ -161,7 +159,7 @@ var nodeSelector = { } } } - + }; function highlightOn() { @@ -187,5 +185,5 @@ function highlightChecked() { } function initMathJax() { - + } From be9529faee9aa31f81811388af8a3b36b1480fe2 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 27 Sep 2011 14:48:38 -0500 Subject: [PATCH 2/9] Remove dead and leaky global functions --- .../frontend/public/javascript/gollum.js | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/lib/gollum/frontend/public/javascript/gollum.js b/lib/gollum/frontend/public/javascript/gollum.js index c8de28a6..7205262f 100755 --- a/lib/gollum/frontend/public/javascript/gollum.js +++ b/lib/gollum/frontend/public/javascript/gollum.js @@ -41,7 +41,9 @@ $(document).ready(function() { if ($('#wiki-wrapper').hasClass('history')) { $('#wiki-history td.checkbox input').each(function() { - $(this).click(highlightChecked); + $(this).click(function() { + nodeSelector.checkNode($(this)); + }); if ( $(this).is(':checked') ) { nodeSelector.checkNode($(this)); } @@ -161,29 +163,3 @@ var nodeSelector = { } }; - -function highlightOn() { - $(this).parent().parent().animate({ - backgroundColor: '#ffffea', - duration: 400 - }); -} - -function highlightOff() { - var color = '#ebf2f6'; - if ($(this).parent().parent().hasClass('alt-row')) { - color = '#f3f7fa'; - } - $(this).parent().parent().animate({ - backgroundColor: color, - duration: 400 - }); -} - -function highlightChecked() { - nodeSelector.checkNode($(this)); -} - -function initMathJax() { - -} From ce770c2e79b084b70bdd09721fe725c3d0374ac5 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 27 Sep 2011 14:51:47 -0500 Subject: [PATCH 3/9] Don't leak nodeSelector --- .../frontend/public/javascript/gollum.js | 168 +++++++++--------- 1 file changed, 82 insertions(+), 86 deletions(-) diff --git a/lib/gollum/frontend/public/javascript/gollum.js b/lib/gollum/frontend/public/javascript/gollum.js index 7205262f..2d832a9c 100755 --- a/lib/gollum/frontend/public/javascript/gollum.js +++ b/lib/gollum/frontend/public/javascript/gollum.js @@ -1,5 +1,87 @@ // ua $(document).ready(function() { + var nodeSelector = { + node1: null, + node2: null, + + selectNodeRange: function( n1, n2 ) { + if ( nodeSelector.node1 && nodeSelector.node2 ) { + $('#wiki-history td.selected').removeClass('selected'); + nodeSelector.node1.addClass('selected'); + nodeSelector.node2.addClass('selected'); + + // swap the nodes around if they went in reverse + if ( nodeSelector.nodeComesAfter( nodeSelector.node1, + nodeSelector.node2 ) ) { + var n = nodeSelector.node1; + nodeSelector.node1 = nodeSelector.node2; + nodeSelector.node2 = n; + } + + var s = true; + var $nextNode = nodeSelector.node1.next(); + while ( $nextNode ) { + $nextNode.addClass('selected'); + if ( $nextNode[0] == nodeSelector.node2[0] ) { + break; + } + $nextNode = $nextNode.next(); + } + } + }, + + nodeComesAfter: function ( n1, n2 ) { + var s = false; + $(n1).prevAll().each(function() { + if ( $(this)[0] == $(n2)[0] ) { + s = true; + } + }); + return s; + }, + + checkNode: function( nodeCheckbox ) { + var $nodeCheckbox = nodeCheckbox; + var $node = $(nodeCheckbox).parent().parent(); + // if we're unchecking + if ( !$nodeCheckbox.is(':checked') ) { + + // remove the range, since we're breaking it + $('#wiki-history tr.selected').each(function() { + if ( $(this).find('td.checkbox input').is(':checked') ) { + return; + } + $(this).removeClass('selected'); + }); + + // no longer track this + if ( $node[0] == nodeSelector.node1[0] ) { + nodeSelector.node1 = null; + if ( nodeSelector.node2 ) { + nodeSelector.node1 = nodeSelector.node2; + nodeSelector.node2 = null; + } + } else if ( $node[0] == nodeSelector.node2[0] ) { + nodeSelector.node2 = null; + } + + } else { + if ( !nodeSelector.node1 ) { + nodeSelector.node1 = $node; + nodeSelector.node1.addClass('selected'); + } else if ( !nodeSelector.node2 ) { + // okay, we don't have a node 2 but have a node1 + nodeSelector.node2 = $node; + nodeSelector.node2.addClass('selected'); + nodeSelector.selectNodeRange( nodeSelector.node1, + nodeSelector.node2 ); + } else { + // we have two selected already + $nodeCheckbox[0].checked = false; + } + } + } + }; // ua detection if ($.browser.mozilla) { @@ -76,90 +158,4 @@ $(document).ready(function() { $('#gollum-revert-form').submit(); }); } - }); - -var nodeSelector = { - - node1: null, - node2: null, - - selectNodeRange: function( n1, n2 ) { - if ( nodeSelector.node1 && nodeSelector.node2 ) { - $('#wiki-history td.selected').removeClass('selected'); - nodeSelector.node1.addClass('selected'); - nodeSelector.node2.addClass('selected'); - - // swap the nodes around if they went in reverse - if ( nodeSelector.nodeComesAfter( nodeSelector.node1, - nodeSelector.node2 ) ) { - var n = nodeSelector.node1; - nodeSelector.node1 = nodeSelector.node2; - nodeSelector.node2 = n; - } - - var s = true; - var $nextNode = nodeSelector.node1.next(); - while ( $nextNode ) { - $nextNode.addClass('selected'); - if ( $nextNode[0] == nodeSelector.node2[0] ) { - break; - } - $nextNode = $nextNode.next(); - } - } - }, - - nodeComesAfter: function ( n1, n2 ) { - var s = false; - $(n1).prevAll().each(function() { - if ( $(this)[0] == $(n2)[0] ) { - s = true; - } - }); - return s; - }, - - checkNode: function( nodeCheckbox ) { - var $nodeCheckbox = nodeCheckbox; - var $node = $(nodeCheckbox).parent().parent(); - // if we're unchecking - if ( !$nodeCheckbox.is(':checked') ) { - - // remove the range, since we're breaking it - $('#wiki-history tr.selected').each(function() { - if ( $(this).find('td.checkbox input').is(':checked') ) { - return; - } - $(this).removeClass('selected'); - }); - - // no longer track this - if ( $node[0] == nodeSelector.node1[0] ) { - nodeSelector.node1 = null; - if ( nodeSelector.node2 ) { - nodeSelector.node1 = nodeSelector.node2; - nodeSelector.node2 = null; - } - } else if ( $node[0] == nodeSelector.node2[0] ) { - nodeSelector.node2 = null; - } - - } else { - if ( !nodeSelector.node1 ) { - nodeSelector.node1 = $node; - nodeSelector.node1.addClass('selected'); - } else if ( !nodeSelector.node2 ) { - // okay, we don't have a node 2 but have a node1 - nodeSelector.node2 = $node; - nodeSelector.node2.addClass('selected'); - nodeSelector.selectNodeRange( nodeSelector.node1, - nodeSelector.node2 ); - } else { - // we have two selected already - $nodeCheckbox[0].checked = false; - } - } - } - -}; From 095a392359e3a68d1a38aec74a42d21588a7fb27 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 27 Sep 2011 16:06:16 -0500 Subject: [PATCH 4/9] Trim trailing whitespace --- lib/gollum/frontend/public/javascript/editor/gollum.editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gollum/frontend/public/javascript/editor/gollum.editor.js b/lib/gollum/frontend/public/javascript/editor/gollum.editor.js index ddc9754b..7dd6d3da 100755 --- a/lib/gollum/frontend/public/javascript/editor/gollum.editor.js +++ b/lib/gollum/frontend/public/javascript/editor/gollum.editor.js @@ -990,7 +990,7 @@ setActiveHelp: function( name ) { if ( !Help.isLoadedFor( name ) ) { if ( $('#function-help').length ) { - $('#function-help').addClass('disabled'); + $('#function-help').addClass('disabled'); } if ( Help.isShown() ) { Help.hide(); From 3a8d65bd3e94f3cf41757c16f342e98ad16bb6ba Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 27 Sep 2011 16:26:03 -0500 Subject: [PATCH 5/9] Fix indenting offset 2 spaces, not 3 --- .../public/javascript/editor/gollum.editor.js | 541 +++++++++--------- 1 file changed, 263 insertions(+), 278 deletions(-) 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); From 41c4801aedee61b5d93707d47b27939fcd7ea27f Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 27 Sep 2011 16:49:52 -0500 Subject: [PATCH 6/9] Backport some JS changes from github.com --- .../public/javascript/editor/gollum.editor.js | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/gollum/frontend/public/javascript/editor/gollum.editor.js b/lib/gollum/frontend/public/javascript/editor/gollum.editor.js index d260041f..9d1fe659 100755 --- a/lib/gollum/frontend/public/javascript/editor/gollum.editor.js +++ b/lib/gollum/frontend/public/javascript/editor/gollum.editor.js @@ -62,7 +62,7 @@ // get form fields var oldAction = $('#gollum-editor form').attr('action'); var $form = $($('#gollum-editor form').get(0)); - $form.attr('action', '/preview'); + $form.attr('action', this.href || '/preview'); $form.attr('target', '_blank'); $form.submit(); @@ -154,7 +154,13 @@ define: function( name, definitionObject ) { LanguageDefinition._ACTIVE_LANG = name; LanguageDefinition._LOADED_LANGS.push( name ); - LanguageDefinition._LANG[name] = definitionObject; + if ( typeof $.GollumEditor.WikiLanguage == 'object' ) { + var definition = {}; + $.extend(definition, $.GollumEditor.WikiLanguage, definitionObject); + LanguageDefinition._LANG[name] = definition; + } else { + LanguageDefinition._LANG[name] = definitionObject; + } }, getActiveLanguage: function() { @@ -808,6 +814,12 @@ // generate help menus Help.generateHelpMenuFor( name ); + + if ( $('#gollum-editor-help').length && + typeof $('#gollum-editor-help').attr('data-autodisplay') !== 'undefined' && + $('#gollum-editor-help').attr('data-autodisplay') === 'true' ) { + Help.show(); + } } } else { if ( $('#function-help').length ) { @@ -1006,7 +1018,15 @@ */ evtHelpButtonClick: function( e ) { e.preventDefault(); - if ( Help.isShown() ) { Help.hide(); } + if ( Help.isShown() ) { + // turn off autodisplay if it's on + if ( $('#gollum-editor-help').length && + $('#gollum-editor-help').attr('data-autodisplay') !== 'undefined' && + $('#gollum-editor-help').attr('data-autodisplay') === 'true' ) { + $.post('/wiki/help?_method=delete'); + $('#gollum-editor-help').attr('data-autodisplay', ''); + } + Help.hide(); } else { Help.show(); } }, From 903ea7c49aa1220c16892a6eafffb696a026e7c1 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 27 Sep 2011 16:50:24 -0500 Subject: [PATCH 7/9] Reindent dialog JS and trim trailing spaces --- .../public/javascript/gollum.dialog.js | 374 +++++++++--------- 1 file changed, 187 insertions(+), 187 deletions(-) diff --git a/lib/gollum/frontend/public/javascript/gollum.dialog.js b/lib/gollum/frontend/public/javascript/gollum.dialog.js index 99cf0890..30f50b8e 100755 --- a/lib/gollum/frontend/public/javascript/gollum.dialog.js +++ b/lib/gollum/frontend/public/javascript/gollum.dialog.js @@ -4,203 +4,203 @@ * Used for dialogs. Duh. * */ - -(function($) { - - var Dialog = { - - debugOn: false, - markupCreated: false, - - attachEvents: function( evtOK ) { - $('#gollum-dialog-action-ok').click(function( e ) { - Dialog.eventOK( e, evtOK ); - }); - $('#gollum-dialog-action-cancel').click( Dialog.eventCancel ); - }, - - createFieldMarkup: function( fieldArray ) { - var fieldMarkup = '
    '; - for ( var i=0; i < fieldArray.length; i++ ) { - if ( typeof fieldArray[i] == 'object' ) { - fieldMarkup += '
    '; - switch ( fieldArray[i].type ) { - - // only text is supported for now - case 'text': - fieldMarkup += Dialog.createFieldText( fieldArray[i] ); - break; - - default: - break; - - } - fieldMarkup += '
    '; - } - - } - fieldMarkup += '
    '; - return fieldMarkup; - }, - - createFieldText: function( fieldAttributes ) { - var html = ''; - - if ( fieldAttributes.name ) { - html += ''; - } - - html += ''; - } - - return html; - }, - - createMarkup: function( title, body ) { - Dialog.markupCreated = true; - return '
    ' + - '
    ' + - '
    ' + - '

    ' + - title +'

    ' + - '
    ' + body + '
    ' + - '
    ' + - 'Cancel' + - 'OK' + - '
    ' + - '
    ' + - '
    ' + - '
    '; - }, - - eventCancel: function( e ) { - e.preventDefault(); - debug('Cancelled dialog.'); - Dialog.hide(); - }, - - eventOK: function( e, evtOK ) { - e.preventDefault(); - - var results = []; - // get the results from each field and build them into the object - $('#gollum-dialog-dialog-body input').each(function() { - results[$(this).attr('name')] = $(this).val(); - }); - - // pass them to evtOK if it exists (which it should) - if ( evtOK && - typeof evtOK == 'function' ) { - evtOK( results ); - } - Dialog.hide(); - }, - hide: function() { - if ( $.browser.msie ) { +(function($) { + + var Dialog = { + + debugOn: false, + markupCreated: false, + + attachEvents: function( evtOK ) { + $('#gollum-dialog-action-ok').click(function( e ) { + Dialog.eventOK( e, evtOK ); + }); + $('#gollum-dialog-action-cancel').click( Dialog.eventCancel ); + }, + + createFieldMarkup: function( fieldArray ) { + var fieldMarkup = '
    '; + for ( var i=0; i < fieldArray.length; i++ ) { + if ( typeof fieldArray[i] == 'object' ) { + fieldMarkup += '
    '; + switch ( fieldArray[i].type ) { + + // only text is supported for now + case 'text': + fieldMarkup += Dialog.createFieldText( fieldArray[i] ); + break; + + default: + break; + + } + fieldMarkup += '
    '; + } + + } + fieldMarkup += '
    '; + return fieldMarkup; + }, + + createFieldText: function( fieldAttributes ) { + var html = ''; + + if ( fieldAttributes.name ) { + html += ''; + } + + html += ''; + } + + return html; + }, + + createMarkup: function( title, body ) { + Dialog.markupCreated = true; + return '
    ' + + '
    ' + + '
    ' + + '

    ' + + title +'

    ' + + '
    ' + body + '
    ' + + '
    ' + + 'Cancel' + + 'OK' + + '
    ' + + '
    ' + + '
    ' + + '
    '; + }, + + eventCancel: function( e ) { + e.preventDefault(); + debug('Cancelled dialog.'); + Dialog.hide(); + }, + + eventOK: function( e, evtOK ) { + e.preventDefault(); + + var results = []; + // get the results from each field and build them into the object + $('#gollum-dialog-dialog-body input').each(function() { + results[$(this).attr('name')] = $(this).val(); + }); + + // pass them to evtOK if it exists (which it should) + if ( evtOK && + typeof evtOK == 'function' ) { + evtOK( results ); + } + Dialog.hide(); + }, + + hide: function() { + if ( $.browser.msie ) { $('#gollum-dialog-dialog').hide().removeClass('active'); - $('select').css('visibility', 'visible'); - } else { - $('#gollum-dialog-dialog').animate({ opacity: 0 }, { - duration: 200, + $('select').css('visibility', 'visible'); + } else { + $('#gollum-dialog-dialog').animate({ opacity: 0 }, { + duration: 200, + complete: function() { + $('#gollum-dialog-dialog').removeClass('active'); + } + }); + } + }, + + init: function( argObject ) { + var title = ''; + var body = ''; + + // bail out if necessary + if ( !argObject || + typeof argObject != 'object' ) { + debug('Editor Dialog: Cannot init; invalid init object'); + return; + } + + if ( argObject.body && typeof argObject.body == 'string' ) { + body = '

    ' + argObject.body + '

    '; + } + + // alright, build out fields + if ( argObject.fields && typeof argObject.fields == 'object' ) { + body += Dialog.createFieldMarkup( argObject.fields ); + } + + if ( argObject.title && typeof argObject.title == 'string' ) { + title = argObject.title; + } + + if ( Dialog.markupCreated ) { + $('#gollum-dialog-dialog').remove(); + } + var $dialog = $( Dialog.createMarkup( title, body ) ); + $('body').append( $dialog ); + if ( argObject.OK && + typeof argObject.OK == 'function' ) { + Dialog.attachEvents( argObject.OK ); + } + Dialog.show(); + }, + + show: function() { + if ( !Dialog.markupCreated ) { + debug('Dialog: No markup to show. Please use init first.'); + } else { + debug('Showing dialog'); + if ( $.browser.msie ) { + $('#gollum-dialog.dialog').addClass('active'); + Dialog.position(); + $('select').css('visibility', 'hidden'); + } else { + $('#gollum-dialog.dialog').css('display', 'none'); + $('#gollum-dialog-dialog').animate({ opacity: 0 }, { + duration: 0, complete: function() { - $('#gollum-dialog-dialog').removeClass('active'); + $('#gollum-dialog-dialog').css('display', 'block'); + Dialog.position(); // position this thing + $('#gollum-dialog-dialog').animate({ opacity: 1 }, { + duration: 500 + }); } }); } - }, - - init: function( argObject ) { - var title = ''; - var body = ''; - - // bail out if necessary - if ( !argObject || - typeof argObject != 'object' ) { - debug('Editor Dialog: Cannot init; invalid init object'); - return; - } - - if ( argObject.body && typeof argObject.body == 'string' ) { - body = '

    ' + argObject.body + '

    '; - } - - // alright, build out fields - if ( argObject.fields && typeof argObject.fields == 'object' ) { - body += Dialog.createFieldMarkup( argObject.fields ); - } - - if ( argObject.title && typeof argObject.title == 'string' ) { - title = argObject.title; - } - - if ( Dialog.markupCreated ) { - $('#gollum-dialog-dialog').remove(); - } - var $dialog = $( Dialog.createMarkup( title, body ) ); - $('body').append( $dialog ); - if ( argObject.OK && - typeof argObject.OK == 'function' ) { - Dialog.attachEvents( argObject.OK ); - } - Dialog.show(); - }, - - show: function() { - if ( !Dialog.markupCreated ) { - debug('Dialog: No markup to show. Please use init first.'); - } else { - debug('Showing dialog'); - if ( $.browser.msie ) { - $('#gollum-dialog.dialog').addClass('active'); - Dialog.position(); - $('select').css('visibility', 'hidden'); - } else { - $('#gollum-dialog.dialog').css('display', 'none'); - $('#gollum-dialog-dialog').animate({ opacity: 0 }, { - duration: 0, - complete: function() { - $('#gollum-dialog-dialog').css('display', 'block'); - Dialog.position(); // position this thing - $('#gollum-dialog-dialog').animate({ opacity: 1 }, { - duration: 500 - }); - } - }); - } - } - }, - - position: function() { - var dialogHeight = $('#gollum-dialog-dialog-inner').height(); - $('#gollum-dialog-dialog-inner') - .css('height', dialogHeight + 'px') - .css('margin-top', -1 * parseInt( dialogHeight / 2 )); - } - - }; - + } + }, + + position: function() { + var dialogHeight = $('#gollum-dialog-dialog-inner').height(); + $('#gollum-dialog-dialog-inner') + .css('height', dialogHeight + 'px') + .css('margin-top', -1 * parseInt( dialogHeight / 2 )); + } + + }; + var debug = function(m) { if ( Dialog.debugOn && typeof console != 'undefined' ) { console.log( m ); } }; - + $.GollumDialog = Dialog; - -})(jQuery); \ No newline at end of file + +})(jQuery); From 381a963971e4c1f320eb1a9774ee5587deb62c16 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 27 Sep 2011 17:13:33 -0500 Subject: [PATCH 8/9] Fix lang script uri --- lib/gollum/frontend/public/javascript/editor/gollum.editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gollum/frontend/public/javascript/editor/gollum.editor.js b/lib/gollum/frontend/public/javascript/editor/gollum.editor.js index 9d1fe659..ed667622 100755 --- a/lib/gollum/frontend/public/javascript/editor/gollum.editor.js +++ b/lib/gollum/frontend/public/javascript/editor/gollum.editor.js @@ -239,7 +239,7 @@ } // attempt to load the definition for this language - var script_uri = '/javascripts/editor/langs/' + markup_name + '.js'; + var script_uri = '/javascript/editor/langs/' + markup_name + '.js'; $.ajax({ url: script_uri, dataType: 'script', From 755c303008da0c6c4ee1900f0fb2fe546c3085e8 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 27 Sep 2011 17:13:53 -0500 Subject: [PATCH 9/9] Use $.facebox for dialog if its available --- .../public/javascript/gollum.dialog.js | 147 ++++++++++++------ 1 file changed, 102 insertions(+), 45 deletions(-) diff --git a/lib/gollum/frontend/public/javascript/gollum.dialog.js b/lib/gollum/frontend/public/javascript/gollum.dialog.js index 30f50b8e..b5402420 100755 --- a/lib/gollum/frontend/public/javascript/gollum.dialog.js +++ b/lib/gollum/frontend/public/javascript/gollum.dialog.js @@ -11,12 +11,23 @@ debugOn: false, markupCreated: false, + markup: '', attachEvents: function( evtOK ) { $('#gollum-dialog-action-ok').click(function( e ) { Dialog.eventOK( e, evtOK ); }); $('#gollum-dialog-action-cancel').click( Dialog.eventCancel ); + $('#gollum-dialog-dialog input[type="text"]').keydown(function( e ) { + if ( e.keyCode == 13 ) { + Dialog.eventOK( e, evtOK ); + } + }); + }, + + detachEvents: function() { + $('#gollum-dialog-action-ok').unbind('click'); + $('#gollum-dialog-action-cancel').unbind('click'); }, createFieldMarkup: function( fieldArray ) { @@ -70,21 +81,35 @@ createMarkup: function( title, body ) { Dialog.markupCreated = true; - return '
    ' + - '
    ' + - '
    ' + - '

    ' + - title +'

    ' + - '
    ' + body + '
    ' + - '
    ' + - 'Cancel' + - 'OK' + - '
    ' + - '
    ' + - '
    ' + - '
    '; + if ($.facebox) { + return '
    ' + + '

    ' + + title +'

    ' + + '
    ' + body + '
    ' + + '
    ' + + 'Cancel' + + 'OK' + + '
    ' + + '
    '; + } else { + return '
    ' + + '
    ' + + '
    ' + + '

    ' + + title +'

    ' + + '
    ' + body + '
    ' + + '
    ' + + 'Cancel' + + 'OK' + + '
    ' + + '
    ' + + '
    ' + + '
    '; + } }, eventCancel: function( e ) { @@ -111,16 +136,22 @@ }, hide: function() { - if ( $.browser.msie ) { - $('#gollum-dialog-dialog').hide().removeClass('active'); - $('select').css('visibility', 'visible'); + if ( $.facebox ) { + Dialog.markupCreated = false; + $(document).trigger('close.facebox'); + Dialog.detachEvents(); } else { - $('#gollum-dialog-dialog').animate({ opacity: 0 }, { - duration: 200, - complete: function() { - $('#gollum-dialog-dialog').removeClass('active'); - } - }); + if ( $.browser.msie ) { + $('#gollum-dialog-dialog').hide().removeClass('active'); + $('select').css('visibility', 'visible'); + } else { + $('#gollum-dialog-dialog').animate({ opacity: 0 }, { + duration: 200, + complete: function() { + $('#gollum-dialog-dialog').removeClass('active'); + } + }); + } } }, @@ -149,14 +180,31 @@ } if ( Dialog.markupCreated ) { - $('#gollum-dialog-dialog').remove(); + if ($.facebox) { + $(document).trigger('close.facebox'); + } else { + $('#gollum-dialog-dialog').remove(); + } } - var $dialog = $( Dialog.createMarkup( title, body ) ); - $('body').append( $dialog ); - if ( argObject.OK && - typeof argObject.OK == 'function' ) { - Dialog.attachEvents( argObject.OK ); + + Dialog.markup = Dialog.createMarkup( title, body ); + + if ($.facebox) { + $(document).bind('reveal.facebox', function() { + if ( argObject.OK && + typeof argObject.OK == 'function' ) { + Dialog.attachEvents( argObject.OK ); + $($('#facebox input[type="text"]').get(0)).focus(); + } + }); + } else { + $('body').append( Dialog.markup ); + if ( argObject.OK && + typeof argObject.OK == 'function' ) { + Dialog.attachEvents( argObject.OK ); + } } + Dialog.show(); }, @@ -165,22 +213,26 @@ debug('Dialog: No markup to show. Please use init first.'); } else { debug('Showing dialog'); - if ( $.browser.msie ) { - $('#gollum-dialog.dialog').addClass('active'); - Dialog.position(); - $('select').css('visibility', 'hidden'); + if ($.facebox) { + $.facebox( Dialog.markup ); } else { - $('#gollum-dialog.dialog').css('display', 'none'); - $('#gollum-dialog-dialog').animate({ opacity: 0 }, { - duration: 0, - complete: function() { - $('#gollum-dialog-dialog').css('display', 'block'); - Dialog.position(); // position this thing - $('#gollum-dialog-dialog').animate({ opacity: 1 }, { + if ( $.browser.msie ) { + $('#gollum-dialog.dialog').addClass('active'); + Dialog.position(); + $('select').css('visibility', 'hidden'); + } else { + $('#gollum-dialog.dialog').css('display', 'none'); + $('#gollum-dialog-dialog').animate({ opacity: 0 }, { + duration: 0, + complete: function() { + $('#gollum-dialog-dialog').css('display', 'block'); + Dialog.position(); // position this thing + $('#gollum-dialog-dialog').animate({ opacity: 1 }, { duration: 500 - }); - } - }); + }); + } + }); + } } } }, @@ -191,9 +243,14 @@ .css('height', dialogHeight + 'px') .css('margin-top', -1 * parseInt( dialogHeight / 2 )); } - }; + if ($.facebox) { + $(document).bind('reveal.facebox', function() { + $('#facebox img.close_image').remove(); + }); + } + var debug = function(m) { if ( Dialog.debugOn && typeof console != 'undefined' ) {