From 42c7058eccaef8eb6c63ccab08984aa08be47dc2 Mon Sep 17 00:00:00 2001 From: Eston Bond Date: Fri, 12 Nov 2010 14:04:58 -0800 Subject: [PATCH] Fix JSLint issues in Dialog; add revert dialog on history page --- .../public/javascript/gollum.dialog.js | 23 +++++++++++++++---- .../frontend/public/javascript/gollum.js | 22 +++++++++++++++++- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/lib/gollum/frontend/public/javascript/gollum.dialog.js b/lib/gollum/frontend/public/javascript/gollum.dialog.js index ae083049..ef20a195 100644 --- a/lib/gollum/frontend/public/javascript/gollum.dialog.js +++ b/lib/gollum/frontend/public/javascript/gollum.dialog.js @@ -9,6 +9,7 @@ var Dialog = { + debugOn: false, markupCreated: false, attachEvents: function( evtOK ) { @@ -27,10 +28,11 @@ // only text is supported for now case 'text': - case 'code': - default: fieldMarkup += Dialog.createFieldText( fieldArray[i] ); break; + + default: + break; } fieldMarkup += ''; @@ -126,10 +128,14 @@ 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 ); + body += Dialog.createFieldMarkup( argObject.fields ); } if ( argObject.title && typeof argObject.title == 'string' ) { @@ -150,7 +156,7 @@ show: function() { if ( !Dialog.markupCreated ) { - debug('Dialog: No markup to show. Please use init first.') + debug('Dialog: No markup to show. Please use init first.'); } else { debug('Showing dialog'); $('#gollum-dialog-dialog').animate({ opacity: 0 }, { @@ -168,7 +174,6 @@ position: function() { var dialogHeight = $('#gollum-dialog-dialog-inner').height(); - debug(dialogHeight); $('#gollum-dialog-dialog-inner') .css('height', dialogHeight + 'px') .css('margin-top', -1 * parseInt( dialogHeight / 2 )); @@ -176,6 +181,14 @@ }; + var debug = function(m) { + if ( Dialog.debugOn + && typeof console != 'undefined' + && typeof console.log == 'function' ) { + console.log( m ); + } + }; + $.GollumDialog = Dialog; })(jQuery); \ No newline at end of file diff --git a/lib/gollum/frontend/public/javascript/gollum.js b/lib/gollum/frontend/public/javascript/gollum.js index 36fb914a..1f1fab34 100644 --- a/lib/gollum/frontend/public/javascript/gollum.js +++ b/lib/gollum/frontend/public/javascript/gollum.js @@ -29,7 +29,27 @@ $(document).ready(function() { $('#wiki-history td.revert-action a').mouseenter(highlightOn); $('#wiki-history td.revert-action a').mouseleave(highlightOff); - }; + } + + if ($('td.revert-action a').length) { + $('td.revert-action a').click(function(e) { + e.preventDefault(); + + var commitSha = $(this).attr('rel'); + var truncatedSha = commitSha.toString().substr(0, 7) + "…"; + // revert action + $.GollumDialog.init({ + title: 'Revert to ' + truncatedSha + '?', + body: 'Are you sure you wish to revert to revision ' + + truncatedSha + '' + + ' ? This will overwrite any previous changes.', + OK: function() { + // TODO add async endpoint to revert here + } + }); + }); + + } });