JiHan Kim 2014-03-21
Commits: add button for copy commitId
@6d77a3e9654dd3ac534e6351e564d8e06390632e
app/assets/stylesheets/less/_page.less
--- app/assets/stylesheets/less/_page.less
+++ app/assets/stylesheets/less/_page.less
@@ -3492,23 +3492,38 @@
     .commit-wrap {
         background-color: @white;
 
-        .commit-id { text-align:center; vertical-align: top; }
+        .commit-id { text-align:center; vertical-align: top; padding:0; }
 
         .tbody {
             td { padding:10px 15px 10px 5px; }
+
             .messages { /* see .commitMsg */ }
 
             .commit-id {
-                width: 70px; text-align:center;
+                position:relative;
+                text-align:center;
                 vertical-align:top;
-                padding-top:15px;
-                font-family:Consolas;
+                padding:12px 3px;
+                font-family:@fixed-font-family;
                 font-size:12px;
 
                 a {
                     color:@secondary;
                     &:hover { color:@link-hover-color; text-decoration:underline; }
                 }
+
+                .btn-copy-commitId {
+                    display:none;
+                    &.hover { background:#f1f1f1; }
+                }
+
+                &:hover {
+                    .btn-copy-commitId {
+                        position:absolute; display:block;
+                        top:15px; left:-15px;
+                        color:@secondary;
+                    }
+                }
             }
             .messages { vertical-align:top;}
             .author {
app/views/code/history.scala.html
--- app/views/code/history.scala.html
+++ app/views/code/history.scala.html
@@ -123,6 +123,10 @@
                             @defining(getShowCommitURL(project, commit, path)){ showCommitURL =>
                             <tr>
                                 <td class="commit-id">
+                                    <button type="button" class="ybtn ybtn-mini btn-copy-commitId"
+                                            title="@Messages("code.copyCommitId")" data-commitId="@commit.getId()">
+                                        <i class="yobicon-copy"></i>
+                                    </button>
                                     <a href="@showCommitURL" title="@Messages("code.showCommit")">
                                         @commit.getShortId()
                                     </a>
@@ -198,6 +202,28 @@
         $(this).next("pre.commitMsg.desc").toggleClass("hidden");
     });
 
+    // Copy CommitId
+    $("#history").find(".btn-copy-commitId").each(function(i, el){
+        var welBtnCopy = $(el);
+
+        // zclip() works only in visible element
+        welBtnCopy.on("mouseenter", function(){
+            if(!welBtnCopy.data("zclipped")){
+                welBtnCopy.data("zclipped", true);
+
+                $(this).zclip({
+                    "path": "@routes.Assets.at("javascripts/lib/jquery/ZeroClipboard.swf")",
+                    "copy": function(){
+                        return $(this).data("commitid");
+                    },
+                    "afterCopy": function(){
+                        $yobi.notify("@Messages("code.copyCommitId.copied")", 1000);
+                    }
+                });
+            }
+        });
+    });
+
     var htKeyMap = {};
     @if(page > 0){
     htKeyMap.A = "@getHistoryURL(path)?page=@(page - 1)";
conf/messages
--- conf/messages
+++ conf/messages
@@ -78,6 +78,8 @@
 code.commitMsg.empty = No commit message
 code.commits = Commits
 code.copiedPath = {1} (Copied from {0})
+code.copyCommitId = Copy commit ID
+code.copyCommitId.copied = Commit ID has copied
 code.copyUrl = Copy URL
 code.copyUrl.copied = Url copied
 code.deletedPath = {0} (Deleted)
conf/messages.ko
--- conf/messages.ko
+++ conf/messages.ko
@@ -78,6 +78,8 @@
 code.commitMsg.empty = No commit message
 code.commits = 커밋
 code.copiedPath = {1} ({0}로부터 복사됨)
+code.copyCommitId = 커밋 ID 복사
+code.copyCommitId.copied = 커밋 ID가 복사되었습니다
 code.copyUrl = 주소 복사
 code.copyUrl.copied = 주소가 복사 되었습니다. 
 code.deletedPath = {0} (삭제됨)
Add a comment
List