aboutsummaryrefslogtreecommitdiff
path: root/public/js/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js/app.js')
-rw-r--r--public/js/app.js116
1 files changed, 109 insertions, 7 deletions
diff --git a/public/js/app.js b/public/js/app.js
index 30296bc3..f179342f 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();
@@ -63,12 +63,56 @@ var Gogits = {
var $tabs = $('[data-init=tabs]');
$tabs.find("li:eq(0) a").tab("show");
};
+ // fix dropdown inside click
+ Gogits.initDropDown = function(){
+ $('.dropdown-menu').on('click','a,button,input,select',function(e){
+ e.stopPropagation();
+ });
+ };
// render markdown
Gogits.renderMarkdown = function () {
- var $pre = $('.markdown').find('pre > code').parent();
- $pre.addClass("prettyprint");
+ var $md = $('.markdown');
+ var $pre = $md.find('pre > code').parent();
+ $pre.addClass('prettyprint linenums');
prettyPrint();
+
+ var $lineNums = $pre.parent().siblings('.lines-num');
+ if ($lineNums.length > 0) {
+ var nums = $pre.find('ol.linenums > li').length;
+ for (var i = 1; i <= nums; i++) {
+ $lineNums.append('<span id="L' + i + '" rel=".L' + i + '">' + i + '</span>');
+ }
+
+ var last;
+ $(document).on('click', '.lines-num span', function () {
+ var $e = $(this);
+ 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 () {
+ 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('<div id="' + name + '" class="anchor-wrap" ></div>');
+ node.append('<a class="anchor" href="#' + name + '"><span class="octicon octicon-link"></span></a>');
+ });
}
})(jQuery);
@@ -98,6 +142,7 @@ function initCore() {
Gogits.initPopovers();
Gogits.initTabs();
Gogits.initModals();
+ Gogits.initDropDown();
Gogits.renderMarkdown();
}
@@ -142,6 +187,60 @@ function initUserSetting() {
});
}
+function initRepository() {
+ // clone group button script
+ (function () {
+ var $clone = $('.clone-group-btn');
+ if ($clone.length) {
+ var $url = $('.clone-group-url');
+ $clone.find('button[data-link]').on("click",function (e) {
+ var $this = $(this);
+ if (!$this.hasClass('btn-primary')) {
+ $clone.find('.btn-primary').removeClass('btn-primary').addClass("btn-default");
+ $(this).addClass('btn-primary').removeClass('btn-default');
+ $url.val($this.data("link"));
+ $clone.find('span.clone-url').text($this.data('link'));
+ }
+ }).eq(0).trigger("click");
+ // 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 ($) {
$(function () {
initCore();
@@ -152,5 +251,8 @@ function initUserSetting() {
if (body.data("page") == "user") {
initUserSetting();
}
+ if ($('.gogs-repo-nav').length) {
+ initRepository();
+ }
});
})(jQuery);