From c3532718a79f102f4e19c11868a2c618b482eb6a Mon Sep 17 00:00:00 2001 From: slene Date: Thu, 20 Mar 2014 17:25:48 +0800 Subject: add anchor --- public/js/app.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'public/js/app.js') diff --git a/public/js/app.js b/public/js/app.js index 30296bc3..f3e8d6d1 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -66,9 +66,28 @@ var Gogits = { // render markdown Gogits.renderMarkdown = function () { - var $pre = $('.markdown').find('pre > code').parent(); + var $md = $('.markdown'); + var $pre = $md.find('pre > code').parent(); $pre.addClass("prettyprint"); prettyPrint(); + + // Set anchor. + var headers = {}; + $md.find('h1, h2, h3, h4, h5, h6').each(function () { + var node = $(this); + var val = encodeURIComponent(node.text().toLowerCase().replace(/[^\w\- ]/g, '').replace(/[ ]/g, '-')); + var name = val; + if(headers[val] > 0){ + name = val + '-' + headers[val]; + } + if(headers[val] == undefined){ + headers[val] = 1; + }else{ + headers[val] += 1; + } + node = node.wrap('
'); + node.append(''); + }); } })(jQuery); -- cgit v1.2.3 From cb80111e8923ff9317199dca61509e32408279ca Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Thu, 20 Mar 2014 20:12:31 +0800 Subject: guide page for bare repo some ui fix --- public/css/gogs.css | 14 ++++++++++++++ public/js/app.js | 30 +++++++++++++++++++++++++----- routers/repo/single.go | 6 ++++-- templates/repo/single.tmpl | 2 +- templates/repo/single_bare.tmpl | 31 +++++++++++++++++++++++++++++++ templates/repo/toolbar.tmpl | 3 +-- 6 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 templates/repo/single_bare.tmpl (limited to 'public/js/app.js') diff --git a/public/css/gogs.css b/public/css/gogs.css index a4767c1c..95f44d0f 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -724,6 +724,20 @@ html, body { background-color: #FFF; } +.commit-list .date { + width: 120px; +} + +.guide-box pre, .guide-box .input-group { + margin-top: 20px; + margin-bottom: 30px; + line-height: 24px; +} + +.guide-box input[readonly] { + background-color: #FFF; +} + /* wrapper and footer */ #wrapper { diff --git a/public/js/app.js b/public/js/app.js index 30296bc3..e1aeb8a5 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -41,15 +41,15 @@ var Gogits = { }); }; Gogits.initPopovers = function () { - var hideAllPopovers = function() { - $('[data-toggle=popover]').each(function() { + var hideAllPopovers = function () { + $('[data-toggle=popover]').each(function () { $(this).popover('hide'); - }); + }); }; - $(document).on('click', function(e) { + $(document).on('click', function (e) { var $e = $(e.target); - if($e.data('toggle') == 'popover'||$e.parents("[data-toggle=popover], .popover").length > 0){ + if ($e.data('toggle') == 'popover' || $e.parents("[data-toggle=popover], .popover").length > 0) { return; } hideAllPopovers(); @@ -142,6 +142,23 @@ function initUserSetting() { }); } +function initRepository() { + var $guide = $('.guide-box'); + if ($guide.length) { + var $url = $('#guide-clone-url'); + $guide.find('button[data-url]').on("click",function () { + var $this = $(this); + if (!$this.hasClass('btn-primary')) { + $guide.find('.btn-primary').removeClass('btn-primary').addClass("btn-default"); + $(this).addClass('btn-primary').removeClass('btn-default'); + $url.val($this.data("url")); + $guide.find('span.clone-url').text($this.data('url')); + } + }).eq(0).trigger("click"); + // todo copy to clipboard + } +} + (function ($) { $(function () { initCore(); @@ -152,5 +169,8 @@ function initUserSetting() { if (body.data("page") == "user") { initUserSetting(); } + if ($('.gogs-repo-nav').length) { + initRepository(); + } }); })(jQuery); diff --git a/routers/repo/single.go b/routers/repo/single.go index ebf64dc6..4a6af9ff 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -59,6 +59,8 @@ func Single(ctx *middleware.Context, params martini.Params) { return } + ctx.Data["IsRepoToolbarSource"] = true + // Branches. brs, err := models.GetBranches(params["username"], params["reponame"]) if err != nil { @@ -176,7 +178,6 @@ func Single(ctx *middleware.Context, params martini.Params) { ctx.Data["Paths"] = Paths ctx.Data["Treenames"] = treenames - ctx.Data["IsRepoToolbarSource"] = true ctx.Data["BranchLink"] = branchLink ctx.HTML(200, "repo/single") } @@ -187,6 +188,8 @@ func Setting(ctx *middleware.Context, params martini.Params) { return } + ctx.Data["IsRepoToolbarSetting"] = true + // Branches. brs, err := models.GetBranches(params["username"], params["reponame"]) if err != nil { @@ -205,7 +208,6 @@ func Setting(ctx *middleware.Context, params martini.Params) { } ctx.Data["Title"] = title + " - settings" - ctx.Data["IsRepoToolbarSetting"] = true ctx.HTML(200, "repo/setting") } diff --git a/templates/repo/single.tmpl b/templates/repo/single.tmpl index 60247898..8a7b5e47 100644 --- a/templates/repo/single.tmpl +++ b/templates/repo/single.tmpl @@ -5,7 +5,7 @@
{{if .IsBareRepo}} - Need to fill in some guide. + {{template "repo/single_bare" .}} {{else}}
{{ $n := len .Treenames}} diff --git a/templates/repo/single_bare.tmpl b/templates/repo/single_bare.tmpl new file mode 100644 index 00000000..caf2ef74 --- /dev/null +++ b/templates/repo/single_bare.tmpl @@ -0,0 +1,31 @@ +
+
+

Quick Guide

+
+
+

Clone this repository

+
+ + + + + + + + +
+

We recommend every repository include a README, LICENSE, and .gitignore.

+
+

Create a new repository on the command line

+
touch README.md
+git init
+git add README.md
+git commit -m "first commit"
+git remote add origin https://github.com/fuxiaohei/air.git
+git push -u origin master
+
+

Push an existing repository from the command line

+
git remote add origin https://github.com/fuxiaohei/air.git
+git push -u origin master
+
+
\ No newline at end of file diff --git a/templates/repo/toolbar.tmpl b/templates/repo/toolbar.tmpl index 5cd9f526..b51768a3 100644 --- a/templates/repo/toolbar.tmpl +++ b/templates/repo/toolbar.tmpl @@ -15,9 +15,8 @@
  • Release
  • Wiki
  • - + {{end}} - {{end}}
    \ No newline at end of file -- cgit v1.2.3 From de956c477684f66a9e27ad895efbebae1837b2b1 Mon Sep 17 00:00:00 2001 From: slene Date: Thu, 20 Mar 2014 21:10:37 +0800 Subject: linenums --- public/css/gogs.css | 45 +++++++++++++++++++++++++++++++++++------ public/css/markdown.css | 10 +++++++-- public/js/app.js | 23 ++++++++++++++++++++- public/js/lib.js | 2 +- routers/repo/single.go | 2 ++ templates/repo/single_file.tmpl | 11 ++++++++-- 6 files changed, 81 insertions(+), 12 deletions(-) (limited to 'public/js/app.js') diff --git a/public/css/gogs.css b/public/css/gogs.css index eb5f7ad2..41e4be9a 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -644,7 +644,7 @@ html, body { } .file-content .file-body { - padding: 0; + padding: 30px 30px 50px; border: none; background-color: #FFF; } @@ -654,17 +654,50 @@ html, body { border: none; } -.file-content .markdown > pre > ol.linenums > li:first-child { - padding-top: 0; +.file-content .file-body.file-code { + padding: 0; +} + +.file-content .file-body.file-code .lines-code > pre { + border: none; + background: none; + border-left: 1px solid #ddd; +} + +.file-content .file-body.file-code .lines-code ol.linenums > .active { + background: #ffffdd; +} + +.file-content .file-body.file-code .lines-num { + text-align: right; + color: #999; + background: #fafafa; + width: 1%; +} + +.file-content .file-body.file-code .lines-num span { + font-family: Menlo,Monaco,Consolas,"Courier New",monospace; + line-height: 1.6; + padding: 0 8px 0 10px; + cursor: pointer; + display: block; + margin-top: 6px; + font-size: 90%; +} + +.file-content .file-body.file-code .lines-num span:first-child { margin-top: 0; } -.file-content .file-body.file-code { - padding: 0; +.file-content .file-body.file-code > table { + width: 100%; } -.file-content .file-body.file-code > pre { +.file-content .file-body.file-code > table > tbody > tr, +.file-content .file-body.file-code > table > tbody > tr > td, +.file-content .file-body.file-code > table { border: none; + background: none; } .branch-list th, .commit-list th { diff --git a/public/css/markdown.css b/public/css/markdown.css index 1edc3b62..68094867 100644 --- a/public/css/markdown.css +++ b/public/css/markdown.css @@ -111,7 +111,6 @@ line-height: 1.6; overflow: auto; background: #f8f8f8; - padding: 6px 10px; border: 1px solid #ddd; } @@ -120,6 +119,13 @@ } .markdown > pre > ol.linenums { + list-style: none; + padding: 0; +} + +.markdown > pre.linenums-style > ol.linenums { + list-style-type: decimal; + padding: 0 0 0 40px; -webkit-box-shadow: inset 40px 0 0 #f5f5f5, inset 41px 0 0 #ccc; box-shadow: inset 40px 0 0 #f5f5f5, inset 41px 0 0 #ccc; } @@ -142,7 +148,7 @@ padding-bottom: 12px; } -.markdown > pre > ol.linenums > li { +.markdown > pre.linenums-style > ol.linenums > li { border-left: 1px solid #ddd; } diff --git a/public/js/app.js b/public/js/app.js index 12f9e7f3..93cfbc1f 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -68,9 +68,30 @@ var Gogits = { Gogits.renderMarkdown = function () { var $md = $('.markdown'); var $pre = $md.find('pre > code').parent(); - $pre.addClass("prettyprint"); + $pre.addClass('prettyprint'); prettyPrint(); + var $lineNums = $pre.parent().siblings('.lines-num'); + if($lineNums.length > 0){ + var nums = $pre.find('ol.linenums > li').length; + for(var i=0;i < nums;i++){ + $lineNums.append(''+(i+1)+''); + } + + var last; + $(document).on('click', '.lines-num span', function(){ + var $e = $(this); + console.log($e.parent().siblings('.lines-code').find('ol.linenums > ' + $e.attr('rel'))); + console.log('ol.linenums > ' + $e.attr('rel')); + if(last){ + last.removeClass('active'); + } + last = $e.parent().siblings('.lines-code').find('ol.linenums > ' + $e.attr('rel')); + last.addClass('active'); + window.location.href = '#' + $e.attr('id'); + }); + } + // Set anchor. var headers = {}; $md.find('h1, h2, h3, h4, h5, h6').each(function () { diff --git a/public/js/lib.js b/public/js/lib.js index 2a98f277..b9e07c0c 100644 --- a/public/js/lib.js +++ b/public/js/lib.js @@ -340,7 +340,7 @@ q,"'\"`"]):d.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(? s+")*(?:\\x5D|$))+/")+")")])}(b=a.types)&&g.push(["typ",b]);b=(""+a.keywords).replace(/^ | $/g,"");b.length&&g.push(["kwd",RegExp("^(?:"+b.replace(/[\s,]+/g,"|")+")\\b"),q]);d.push(["pln",/^\s+/,q," \r\n\t\u00a0"]);b="^.[^\\s\\w.$@'\"`/\\\\]*";a.regexLiterals&&(b+="(?!s*/)");g.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/, q],["pun",RegExp(b),q]);return C(d,g)}function J(a,d,g){function b(a){var c=a.nodeType;if(c==1&&!x.test(a.className))if("br"===a.nodeName)s(a),a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)b(a);else if((c==3||c==4)&&g){var d=a.nodeValue,i=d.match(m);if(i)c=d.substring(0,i.index),a.nodeValue=c,(d=d.substring(i.index+i[0].length))&&a.parentNode.insertBefore(j.createTextNode(d),a.nextSibling),s(a),c||a.parentNode.removeChild(a)}}function s(a){function b(a,c){var d= c?a.cloneNode(!1):a,e=a.parentNode;if(e){var e=b(e,1),g=a.nextSibling;e.appendChild(d);for(var i=g;i;i=g)g=i.nextSibling,e.appendChild(i)}return d}for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),d;(d=a.parentNode)&&d.nodeType===1;)a=d;c.push(a)}for(var x=/(?:^|\s)nocode(?:\s|$)/,m=/\r\n?|\n/,j=a.ownerDocument,k=j.createElement("li");a.firstChild;)k.appendChild(a.firstChild);for(var c=[k],i=0;i=0;){var b=d[g];F.hasOwnProperty(b)?D.console&&console.warn("cannot override language handler %s",b):F[b]=a}}function I(a,d){if(!a||!F.hasOwnProperty(a))a=/^\s*=0;){var b=d[g];F.hasOwnProperty(b)?D.console&&console.warn("cannot override language handler %s",b):F[b]=a}}function I(a,d){if(!a||!F.hasOwnProperty(a))a=/^\s*=l&&(b+=2);g>=B&&(r+=2)}}finally{if(f)f.style.display=h}}catch(u){D.console&&console.log(u&&u.stack||u)}}var D=window,y=["break,continue,do,else,for,if,return,while"],E=[[y,"auto,case,char,const,default,double,enum,extern,float,goto,inline,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],M=[E,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,delegate,dynamic_cast,explicit,export,friend,generic,late_check,mutable,namespace,nullptr,property,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],N=[E,"abstract,assert,boolean,byte,extends,final,finally,implements,import,instanceof,interface,null,native,package,strictfp,super,synchronized,throws,transient"], diff --git a/routers/repo/single.go b/routers/repo/single.go index 6eb839c1..49eb55d3 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -5,6 +5,7 @@ package repo import ( + "path" "strings" "github.com/codegangsta/martini" @@ -95,6 +96,7 @@ func Single(ctx *middleware.Context, params martini.Params) { } else { ctx.Data["IsFile"] = true ctx.Data["FileName"] = repoFile.Name + ctx.Data["FileExt"] = path.Ext(repoFile.Name) readmeExist := base.IsMarkdownFile(repoFile.Name) || base.IsReadmeFile(repoFile.Name) ctx.Data["ReadmeExist"] = readmeExist diff --git a/templates/repo/single_file.tmpl b/templates/repo/single_file.tmpl index 0c1c3713..7bca626a 100644 --- a/templates/repo/single_file.tmpl +++ b/templates/repo/single_file.tmpl @@ -16,8 +16,15 @@ {{.FileContent|str2html}}
    {{else}} -
    -
    {{.FileContent}}
    +
    + + + + + + + +
    {{.FileContent}}
    {{end}} {{end}} -- cgit v1.2.3 From c8790eb7d367cec25f1201f923ca017268fe157d Mon Sep 17 00:00:00 2001 From: slene Date: Thu, 20 Mar 2014 21:24:15 +0800 Subject: overflow --- public/css/gogs.css | 3 +++ public/js/app.js | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'public/js/app.js') diff --git a/public/css/gogs.css b/public/css/gogs.css index 41e4be9a..3a8760c3 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -647,6 +647,9 @@ html, body { padding: 30px 30px 50px; border: none; background-color: #FFF; + overflow: auto; + overflow-x: auto; + overflow-y: hidden; } .file-content .file-body pre { diff --git a/public/js/app.js b/public/js/app.js index 93cfbc1f..a3997600 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -81,8 +81,6 @@ var Gogits = { var last; $(document).on('click', '.lines-num span', function(){ var $e = $(this); - console.log($e.parent().siblings('.lines-code').find('ol.linenums > ' + $e.attr('rel'))); - console.log('ol.linenums > ' + $e.attr('rel')); if(last){ last.removeClass('active'); } -- cgit v1.2.3 From 4efd73d37a7e76401ef93982db63b4538013ea23 Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Thu, 20 Mar 2014 21:32:08 +0800 Subject: fix single bare page link --- public/js/app.js | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'public/js/app.js') diff --git a/public/js/app.js b/public/js/app.js index a3997600..2952083e 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -72,16 +72,16 @@ var Gogits = { prettyPrint(); var $lineNums = $pre.parent().siblings('.lines-num'); - if($lineNums.length > 0){ + if ($lineNums.length > 0) { var nums = $pre.find('ol.linenums > li').length; - for(var i=0;i < nums;i++){ - $lineNums.append(''+(i+1)+''); + for (var i = 0; i < nums; i++) { + $lineNums.append('' + (i + 1) + ''); } var last; - $(document).on('click', '.lines-num span', function(){ + $(document).on('click', '.lines-num span', function () { var $e = $(this); - if(last){ + if (last) { last.removeClass('active'); } last = $e.parent().siblings('.lines-code').find('ol.linenums > ' + $e.attr('rel')); @@ -96,12 +96,12 @@ var Gogits = { var node = $(this); var val = encodeURIComponent(node.text().toLowerCase().replace(/[^\w\- ]/g, '').replace(/[ ]/g, '-')); var name = val; - if(headers[val] > 0){ + if (headers[val] > 0) { name = val + '-' + headers[val]; } - if(headers[val] == undefined){ + if (headers[val] == undefined) { headers[val] = 1; - }else{ + } else { headers[val] += 1; } node = node.wrap('
    '); @@ -181,20 +181,22 @@ function initUserSetting() { } function initRepository() { - var $guide = $('.guide-box'); - if ($guide.length) { - var $url = $('#guide-clone-url'); - $guide.find('button[data-url]').on("click",function () { - var $this = $(this); - if (!$this.hasClass('btn-primary')) { - $guide.find('.btn-primary').removeClass('btn-primary').addClass("btn-default"); - $(this).addClass('btn-primary').removeClass('btn-default'); - $url.val($this.data("url")); - $guide.find('span.clone-url').text($this.data('url')); - } - }).eq(0).trigger("click"); - // todo copy to clipboard - } + (function () { + var $guide = $('.guide-box'); + if ($guide.length) { + var $url = $('#guide-clone-url'); + $guide.find('button[data-link]').on("click",function () { + var $this = $(this); + if (!$this.hasClass('btn-primary')) { + $guide.find('.btn-primary').removeClass('btn-primary').addClass("btn-default"); + $(this).addClass('btn-primary').removeClass('btn-default'); + $url.val($this.data("link")); + $guide.find('span.clone-url').text($this.data('link')); + } + }).eq(0).trigger("click"); + // todo copy to clipboard + } + })(); } (function ($) { -- cgit v1.2.3 From 7c6c6125f3846acc633c00bb92c8698c30e761fa Mon Sep 17 00:00:00 2001 From: slene Date: Thu, 20 Mar 2014 21:35:46 +0800 Subject: fix line num --- public/js/app.js | 4 ++-- public/js/lib.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'public/js/app.js') diff --git a/public/js/app.js b/public/js/app.js index 2952083e..55541032 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -74,8 +74,8 @@ var Gogits = { var $lineNums = $pre.parent().siblings('.lines-num'); if ($lineNums.length > 0) { var nums = $pre.find('ol.linenums > li').length; - for (var i = 0; i < nums; i++) { - $lineNums.append('' + (i + 1) + ''); + for (var i = 1; i <= nums; i++) { + $lineNums.append('' + i + ''); } var last; diff --git a/public/js/lib.js b/public/js/lib.js index b9e07c0c..8deb6f72 100644 --- a/public/js/lib.js +++ b/public/js/lib.js @@ -340,7 +340,7 @@ q,"'\"`"]):d.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(? s+")*(?:\\x5D|$))+/")+")")])}(b=a.types)&&g.push(["typ",b]);b=(""+a.keywords).replace(/^ | $/g,"");b.length&&g.push(["kwd",RegExp("^(?:"+b.replace(/[\s,]+/g,"|")+")\\b"),q]);d.push(["pln",/^\s+/,q," \r\n\t\u00a0"]);b="^.[^\\s\\w.$@'\"`/\\\\]*";a.regexLiterals&&(b+="(?!s*/)");g.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/, q],["pun",RegExp(b),q]);return C(d,g)}function J(a,d,g){function b(a){var c=a.nodeType;if(c==1&&!x.test(a.className))if("br"===a.nodeName)s(a),a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)b(a);else if((c==3||c==4)&&g){var d=a.nodeValue,i=d.match(m);if(i)c=d.substring(0,i.index),a.nodeValue=c,(d=d.substring(i.index+i[0].length))&&a.parentNode.insertBefore(j.createTextNode(d),a.nextSibling),s(a),c||a.parentNode.removeChild(a)}}function s(a){function b(a,c){var d= c?a.cloneNode(!1):a,e=a.parentNode;if(e){var e=b(e,1),g=a.nextSibling;e.appendChild(d);for(var i=g;i;i=g)g=i.nextSibling,e.appendChild(i)}return d}for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),d;(d=a.parentNode)&&d.nodeType===1;)a=d;c.push(a)}for(var x=/(?:^|\s)nocode(?:\s|$)/,m=/\r\n?|\n/,j=a.ownerDocument,k=j.createElement("li");a.firstChild;)k.appendChild(a.firstChild);for(var c=[k],i=0;i=0;){var b=d[g];F.hasOwnProperty(b)?D.console&&console.warn("cannot override language handler %s",b):F[b]=a}}function I(a,d){if(!a||!F.hasOwnProperty(a))a=/^\s*=0;){var b=d[g];F.hasOwnProperty(b)?D.console&&console.warn("cannot override language handler %s",b):F[b]=a}}function I(a,d){if(!a||!F.hasOwnProperty(a))a=/^\s*=l&&(b+=2);g>=B&&(r+=2)}}finally{if(f)f.style.display=h}}catch(u){D.console&&console.log(u&&u.stack||u)}}var D=window,y=["break,continue,do,else,for,if,return,while"],E=[[y,"auto,case,char,const,default,double,enum,extern,float,goto,inline,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],M=[E,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,delegate,dynamic_cast,explicit,export,friend,generic,late_check,mutable,namespace,nullptr,property,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],N=[E,"abstract,assert,boolean,byte,extends,final,finally,implements,import,instanceof,interface,null,native,package,strictfp,super,synchronized,throws,transient"], -- cgit v1.2.3 From 1a0d7c54a2abecbe5335ca374fd8a345c2e7d3fd Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Thu, 20 Mar 2014 22:39:10 +0800 Subject: repo watching ajax --- public/css/gogs.css | 8 ++++++-- public/js/app.js | 35 +++++++++++++++++++++++++++++++++++ templates/repo/nav.tmpl | 14 +++++++++----- 3 files changed, 50 insertions(+), 7 deletions(-) (limited to 'public/js/app.js') diff --git a/public/css/gogs.css b/public/css/gogs.css index d1b1e155..f88b3963 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -445,7 +445,7 @@ html, body { padding: 0; } -#gogs-repo-watching .dropdown-menu .dropdown-item:hover .dropdown-header { +#gogs-repo-watching .dropdown-menu .dropdown-item:hover .dropdown-header, #gogs-repo-watching .dropdown-item .dropdown-header.text-primary { color: rgb(65, 131, 196); cursor: pointer; } @@ -678,7 +678,7 @@ html, body { } .file-content .file-body.file-code .lines-num span { - font-family: Menlo,Monaco,Consolas,"Courier New",monospace; + font-family: Menlo, Monaco, Consolas, "Courier New", monospace; line-height: 1.6; padding: 0 8px 0 10px; cursor: pointer; @@ -783,6 +783,10 @@ html, body { width: 120px; } +.commit-list .author { + min-width: 180px; +} + .guide-box pre, .guide-box .input-group { margin-top: 20px; margin-bottom: 30px; diff --git a/public/js/app.js b/public/js/app.js index 55541032..9a5a0d68 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -181,6 +181,7 @@ function initUserSetting() { } function initRepository() { + // guide box script (function () { var $guide = $('.guide-box'); if ($guide.length) { @@ -197,6 +198,40 @@ function initRepository() { // todo copy to clipboard } })(); + + // watching script + (function () { + var $watch = $('#gogs-repo-watching'), + watchLink = $watch.data("watch"), + unwatchLink = $watch.data("unwatch"); + $watch.on('click', '.to-watch',function () { + if ($watch.hasClass("watching")) { + return false; + } + $.get(watchLink, function (json) { + if (json.ok) { + $watch.find('.text-primary').removeClass('text-primary'); + $watch.find('.to-watch h4').addClass('text-primary'); + $watch.find('.fa-eye-slash').removeClass('fa-eye-slash').addClass('fa-eye'); + $watch.removeClass("no-watching").addClass("watching"); + } + }); + return false; + }).on('click', '.to-unwatch', function () { + if ($watch.hasClass("no-watching")) { + return false; + } + $.get(unwatchLink, function (json) { + if (json.ok) { + $watch.find('.text-primary').removeClass('text-primary'); + $watch.find('.to-unwatch h4').addClass('text-primary'); + $watch.find('.fa-eye').removeClass('fa-eye').addClass('fa-eye-slash'); + $watch.removeClass("watching").addClass("no-watching"); + } + }); + return false; + }); + })(); } (function ($) { diff --git a/templates/repo/nav.tmpl b/templates/repo/nav.tmpl index e8685b08..718c429a 100644 --- a/templates/repo/nav.tmpl +++ b/templates/repo/nav.tmpl @@ -13,20 +13,24 @@
    -
    +
    + {{if .IsRepositoryWatching}} + {{else}} + + {{end}}