From 76c8d3206c64589c16c22fea6f9f93faa1f7022a Mon Sep 17 00:00:00 2001 From: Daniel Kimsey Date: Wed, 7 Nov 2012 17:34:42 -0500 Subject: [PATCH 1/2] Consolidated create and edit page's javascript into the global gollum.js --- .../frontend/public/gollum/javascript/gollum.js | 12 ++++++++++++ lib/gollum/frontend/templates/create.mustache | 10 +--------- lib/gollum/frontend/templates/edit.mustache | 8 -------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/gollum/frontend/public/gollum/javascript/gollum.js b/lib/gollum/frontend/public/gollum/javascript/gollum.js index e0984de4..66733437 100755 --- a/lib/gollum/frontend/public/gollum/javascript/gollum.js +++ b/lib/gollum/frontend/public/gollum/javascript/gollum.js @@ -212,4 +212,16 @@ $(document).ready(function() { $('#gollum-revert-form').submit(); }); } + + if( $('#wiki-wrapper.edit').length ){ + window.onbeforeunload = function(){ return "Leaving will discard all edits!" }; + $("#gollum-editor-submit").click( function() { window.onbeforeunload = null; } ); + $.GollumEditor(); + } + + if( $('#wiki-wrapper.create').length ){ + window.onbeforeunload = function(){ return "Leaving will not create a new page!" }; + $("#gollum-editor-submit").click( function() { window.onbeforeunload = null; } ); + $.GollumEditor({ NewFile: true, MarkupType: '{{default_markup}}' }); + } }); diff --git a/lib/gollum/frontend/templates/create.mustache b/lib/gollum/frontend/templates/create.mustache index 40792fac..1d0697bd 100644 --- a/lib/gollum/frontend/templates/create.mustache +++ b/lib/gollum/frontend/templates/create.mustache @@ -1,4 +1,4 @@ -
+
@@ -8,13 +8,5 @@
- {{something}} diff --git a/lib/gollum/frontend/templates/edit.mustache b/lib/gollum/frontend/templates/edit.mustache index 5063fab0..bccf1584 100644 --- a/lib/gollum/frontend/templates/edit.mustache +++ b/lib/gollum/frontend/templates/edit.mustache @@ -10,11 +10,3 @@
{{>editor}}
- From 05d82c05693960621a43e05107cb9f4640315376 Mon Sep 17 00:00:00 2001 From: Daniel Kimsey Date: Wed, 7 Nov 2012 17:37:29 -0500 Subject: [PATCH 2/2] Attach unsaved changes warning to trigger only after changes are made --- lib/gollum/frontend/public/gollum/javascript/gollum.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/gollum/frontend/public/gollum/javascript/gollum.js b/lib/gollum/frontend/public/gollum/javascript/gollum.js index 66733437..a3273ce4 100755 --- a/lib/gollum/frontend/public/gollum/javascript/gollum.js +++ b/lib/gollum/frontend/public/gollum/javascript/gollum.js @@ -214,14 +214,18 @@ $(document).ready(function() { } if( $('#wiki-wrapper.edit').length ){ - window.onbeforeunload = function(){ return "Leaving will discard all edits!" }; $("#gollum-editor-submit").click( function() { window.onbeforeunload = null; } ); + $("#gollum-editor-body").one('change', function(){ + window.onbeforeunload = function(){ return "Leaving will discard all edits!" }; + }); $.GollumEditor(); } if( $('#wiki-wrapper.create').length ){ - window.onbeforeunload = function(){ return "Leaving will not create a new page!" }; $("#gollum-editor-submit").click( function() { window.onbeforeunload = null; } ); + $("#gollum-editor-body").one('change', function(){ + window.onbeforeunload = function(){ return "Leaving will not create a new page!" }; + )}; $.GollumEditor({ NewFile: true, MarkupType: '{{default_markup}}' }); } });