From 1c24090c14d5ab27ab919a070d20f835709c1f4b Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Mon, 28 Apr 2014 10:39:32 +0900 Subject: [PATCH] (refs #13)Fix real-time validation for filename and Add line wrap mode switcher --- src/main/twirl/repo/blob.scala.html | 8 ++-- src/main/twirl/repo/editor.scala.html | 48 +++++++++---------- src/main/webapp/assets/common/js/gitbucket.js | 24 +++++++++- 3 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/main/twirl/repo/blob.scala.html b/src/main/twirl/repo/blob.scala.html index b13846b49..06d8234b0 100644 --- a/src/main/twirl/repo/blob.scala.html +++ b/src/main/twirl/repo/blob.scala.html @@ -31,12 +31,12 @@
@if(hasWritePermission){ - Edit + Edit } - Raw - History + Raw + History @if(hasWritePermission){ - Delete + Delete }
diff --git a/src/main/twirl/repo/editor.scala.html b/src/main/twirl/repo/editor.scala.html index 77d10269e..f78b9beb6 100644 --- a/src/main/twirl/repo/editor.scala.html +++ b/src/main/twirl/repo/editor.scala.html @@ -20,31 +20,22 @@ - - @* - *@
- - +
+ +
-
+
@@ -74,17 +65,24 @@ $(function(){ $('#editor').text($('#initial').val()); var editor = ace.edit("editor"); editor.setTheme("ace/theme/monokai"); - editor.getSession().setUseWrapMode(false); + //editor.getSession().setUseWrapMode(false); @if(fileName.isDefined){ editor.getSession().setMode("ace/mode/@editorType(fileName.get)"); } editor.on('change', function(){ - $('#commit').attr('disabled', editor.getValue() == $('#initial').val()); + updateCommitButtonStatus(); }); - @* + function updateCommitButtonStatus(){ + if(editor.getValue() == $('#initial').val() && $('#newFileName').val() == $('#oldFileName').val()){ + $('#commit').attr('disabled', true); + } else { + $('#commit').attr('disabled', false); + } + } + $('#wrap').change(function(){ console.log($('#wrap option:selected').val()); if($('#wrap option:selected').val() == 'true'){ @@ -94,14 +92,12 @@ $(function(){ } }); - $('#indent').change(function(){ - console.log($('#indent option:selected').val()); - editor.getSession().setUseWrapMode(parseInt($('#indent option:selected').val())); + $('#newFileName').watch(function(){ + updateCommitButtonStatus(); }); - *@ $('#commit').click(function(){ $('#content').val(editor.getValue()); }); -}) +}); diff --git a/src/main/webapp/assets/common/js/gitbucket.js b/src/main/webapp/assets/common/js/gitbucket.js index 26df1492e..02529ad0f 100644 --- a/src/main/webapp/assets/common/js/gitbucket.js +++ b/src/main/webapp/assets/common/js/gitbucket.js @@ -44,4 +44,26 @@ function displayErrors(data){ } i++; }); -} \ No newline at end of file +} + +(function($){ + $.fn.watch = function(callback){ + var timer = null; + var prevValue = this.val(); + + this.on('focus', function(e){ + window.clearInterval(timer); + timer = window.setInterval(function(){ + var newValue = $(e.target).val(); + if(prevValue != newValue){ + callback(); + } + prevValue = newValue; + }, 10); + }); + + this.on('blur', function(){ + window.clearInterval(timer); + }); + }; +})(jQuery); \ No newline at end of file