2014-05-06 04:21:43 +08:00
|
|
|
var Gogits = {};
|
2014-03-02 21:47:55 +08:00
|
|
|
|
2014-03-24 21:27:19 +08:00
|
|
|
(function ($) {
|
2014-03-23 01:44:02 +08:00
|
|
|
// extend jQuery ajax, set csrf token value
|
|
|
|
var ajax = $.ajax;
|
|
|
|
$.extend({
|
2014-03-24 21:27:19 +08:00
|
|
|
ajax: function (url, options) {
|
2014-03-23 01:44:02 +08:00
|
|
|
if (typeof url === 'object') {
|
|
|
|
options = url;
|
|
|
|
url = undefined;
|
|
|
|
}
|
|
|
|
options = options || {};
|
|
|
|
url = options.url;
|
|
|
|
var csrftoken = $('meta[name=_csrf]').attr('content');
|
|
|
|
var headers = options.headers || {};
|
|
|
|
var domain = document.domain.replace(/\./ig, '\\.');
|
|
|
|
if (!/^(http:|https:).*/.test(url) || eval('/^(http:|https:)\\/\\/(.+\\.)*' + domain + '.*/').test(url)) {
|
2014-03-24 21:27:19 +08:00
|
|
|
headers = $.extend(headers, {'X-Csrf-Token': csrftoken});
|
2014-03-23 01:44:02 +08:00
|
|
|
}
|
|
|
|
options.headers = headers;
|
|
|
|
var callback = options.success;
|
2014-03-24 21:27:19 +08:00
|
|
|
options.success = function (data) {
|
|
|
|
if (data.once) {
|
2014-03-23 01:44:02 +08:00
|
|
|
// change all _once value if ajax data.once exist
|
|
|
|
$('[name=_once]').val(data.once);
|
|
|
|
}
|
2014-03-24 21:27:19 +08:00
|
|
|
if (callback) {
|
2014-03-23 01:44:02 +08:00
|
|
|
callback.apply(this, arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return ajax(url, options);
|
2014-03-23 22:14:29 +08:00
|
|
|
},
|
|
|
|
|
2014-03-24 21:27:19 +08:00
|
|
|
changeHash: function (hash) {
|
|
|
|
if (history.pushState) {
|
2014-03-23 22:14:29 +08:00
|
|
|
history.pushState(null, null, hash);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
location.hash = hash;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-03-24 21:27:19 +08:00
|
|
|
deSelect: function () {
|
|
|
|
if (window.getSelection) {
|
2014-03-23 22:14:29 +08:00
|
|
|
window.getSelection().removeAllRanges();
|
|
|
|
} else {
|
|
|
|
document.selection.empty();
|
|
|
|
}
|
2014-03-23 01:44:02 +08:00
|
|
|
}
|
|
|
|
});
|
2014-03-27 23:32:20 +08:00
|
|
|
$.fn.extend({
|
|
|
|
toggleHide: function () {
|
|
|
|
$(this).addClass("hidden");
|
|
|
|
},
|
|
|
|
toggleShow: function () {
|
|
|
|
$(this).removeClass("hidden");
|
2014-03-29 20:46:36 +08:00
|
|
|
},
|
2014-05-12 20:35:26 +08:00
|
|
|
toggleAjax: function (successCallback, errorCallback) {
|
2014-03-29 20:46:36 +08:00
|
|
|
var url = $(this).data("ajax");
|
|
|
|
var method = $(this).data('ajax-method') || 'get';
|
|
|
|
var ajaxName = $(this).data('ajax-name');
|
|
|
|
var data = {};
|
2014-05-06 01:08:01 +08:00
|
|
|
|
|
|
|
if (ajaxName.endsWith("preview")) {
|
|
|
|
data["mode"] = "gfm";
|
|
|
|
data["context"] = $(this).data('ajax-context');
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:46:36 +08:00
|
|
|
$('[data-ajax-rel=' + ajaxName + ']').each(function () {
|
|
|
|
var field = $(this).data("ajax-field");
|
|
|
|
var t = $(this).data("ajax-val");
|
|
|
|
if (t == "val") {
|
|
|
|
data[field] = $(this).val();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (t == "txt") {
|
|
|
|
data[field] = $(this).text();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (t == "html") {
|
|
|
|
data[field] = $(this).html();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (t == "data") {
|
|
|
|
data[field] = $(this).data("ajax-data");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2014-05-21 20:49:47 +08:00
|
|
|
console.log("toggleAjax:", method, url, data);
|
2014-03-29 20:46:36 +08:00
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
method: method.toUpperCase(),
|
|
|
|
data: data,
|
2014-05-12 20:35:26 +08:00
|
|
|
error: errorCallback,
|
2014-03-29 20:46:36 +08:00
|
|
|
success: function (d) {
|
|
|
|
if (successCallback) {
|
|
|
|
successCallback(d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2014-03-27 23:32:20 +08:00
|
|
|
}
|
|
|
|
})
|
2014-03-23 01:44:02 +08:00
|
|
|
}(jQuery));
|
|
|
|
|
2014-03-06 22:55:32 +08:00
|
|
|
(function ($) {
|
2014-03-10 16:54:52 +08:00
|
|
|
|
2014-03-02 21:47:55 +08:00
|
|
|
Gogits.showTab = function (selector, index) {
|
|
|
|
if (!index) {
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
$(selector).tab("show");
|
|
|
|
$(selector).find("li:eq(" + index + ") a").tab("show");
|
2014-03-06 22:55:32 +08:00
|
|
|
};
|
|
|
|
Gogits.validateForm = function (selector, options) {
|
|
|
|
var $form = $(selector);
|
|
|
|
options = options || {};
|
|
|
|
options.showErrors = function (map, list) {
|
|
|
|
var $error = $form.find('.form-error').addClass('hidden');
|
|
|
|
$('.has-error').removeClass("has-error");
|
|
|
|
$error.text(list[0].message).show().removeClass("hidden");
|
|
|
|
$(list[0].element).parents(".form-group").addClass("has-error");
|
|
|
|
};
|
|
|
|
$form.validate(options);
|
|
|
|
};
|
2014-03-10 16:54:52 +08:00
|
|
|
|
|
|
|
// ----- init elements
|
|
|
|
Gogits.initModals = function () {
|
|
|
|
var modals = $("[data-toggle=modal]");
|
|
|
|
if (modals.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$.each(modals, function (i, item) {
|
2014-03-10 21:12:49 +08:00
|
|
|
var hide = $(item).data('modal');
|
|
|
|
$(item).modal(hide ? hide : "hide");
|
2014-03-10 16:54:52 +08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
Gogits.initTooltips = function () {
|
|
|
|
$("body").tooltip({
|
|
|
|
selector: "[data-toggle=tooltip]"
|
|
|
|
//container: "body"
|
|
|
|
});
|
|
|
|
};
|
2014-03-17 18:13:07 +08:00
|
|
|
Gogits.initPopovers = function () {
|
2014-03-20 20:12:31 +08:00
|
|
|
var hideAllPopovers = function () {
|
|
|
|
$('[data-toggle=popover]').each(function () {
|
2014-03-17 18:13:07 +08:00
|
|
|
$(this).popover('hide');
|
2014-03-20 20:12:31 +08:00
|
|
|
});
|
2014-03-17 18:13:07 +08:00
|
|
|
};
|
|
|
|
|
2014-03-20 20:12:31 +08:00
|
|
|
$(document).on('click', function (e) {
|
2014-03-17 18:13:07 +08:00
|
|
|
var $e = $(e.target);
|
2014-03-20 20:12:31 +08:00
|
|
|
if ($e.data('toggle') == 'popover' || $e.parents("[data-toggle=popover], .popover").length > 0) {
|
2014-03-17 18:13:07 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
hideAllPopovers();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("body").popover({
|
|
|
|
selector: "[data-toggle=popover]"
|
|
|
|
});
|
|
|
|
};
|
2014-03-10 21:12:49 +08:00
|
|
|
Gogits.initTabs = function () {
|
2014-03-13 14:08:49 +08:00
|
|
|
var $tabs = $('[data-init=tabs]');
|
2014-03-25 21:14:05 +08:00
|
|
|
$tabs.tab("show");
|
2014-03-13 14:08:49 +08:00
|
|
|
$tabs.find("li:eq(0) a").tab("show");
|
2014-03-17 15:17:44 +08:00
|
|
|
};
|
2014-04-03 00:56:26 +08:00
|
|
|
|
2014-03-21 23:27:33 +08:00
|
|
|
// fix dropdown inside click
|
2014-03-24 21:27:19 +08:00
|
|
|
Gogits.initDropDown = function () {
|
|
|
|
$('.dropdown-menu.no-propagation').on('click', function (e) {
|
2014-03-21 23:27:33 +08:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
};
|
2014-03-17 15:17:44 +08:00
|
|
|
|
2014-04-03 00:56:26 +08:00
|
|
|
|
2014-03-17 15:17:44 +08:00
|
|
|
// render markdown
|
|
|
|
Gogits.renderMarkdown = function () {
|
2014-03-20 17:25:48 +08:00
|
|
|
var $md = $('.markdown');
|
|
|
|
var $pre = $md.find('pre > code').parent();
|
2014-03-20 23:55:27 +08:00
|
|
|
$pre.addClass('prettyprint linenums');
|
2014-03-17 15:17:44 +08:00
|
|
|
prettyPrint();
|
2014-03-20 17:25:48 +08:00
|
|
|
|
|
|
|
// 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;
|
2014-03-20 21:32:08 +08:00
|
|
|
if (headers[val] > 0) {
|
2014-03-20 17:25:48 +08:00
|
|
|
name = val + '-' + headers[val];
|
|
|
|
}
|
2014-03-20 21:32:08 +08:00
|
|
|
if (headers[val] == undefined) {
|
2014-03-20 17:25:48 +08:00
|
|
|
headers[val] = 1;
|
2014-03-20 21:32:08 +08:00
|
|
|
} else {
|
2014-03-20 17:25:48 +08:00
|
|
|
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>');
|
|
|
|
});
|
2014-03-24 21:27:19 +08:00
|
|
|
};
|
2014-03-17 15:17:44 +08:00
|
|
|
|
2014-04-03 00:56:26 +08:00
|
|
|
// render code view
|
2014-03-23 20:58:12 +08:00
|
|
|
Gogits.renderCodeView = function () {
|
2014-03-24 21:27:19 +08:00
|
|
|
function selectRange($list, $select, $from) {
|
2014-03-23 22:14:29 +08:00
|
|
|
$list.removeClass('active');
|
2014-03-24 21:27:19 +08:00
|
|
|
if ($from) {
|
2014-03-23 22:14:29 +08:00
|
|
|
var a = parseInt($select.attr('rel').substr(1));
|
|
|
|
var b = parseInt($from.attr('rel').substr(1));
|
|
|
|
var c;
|
2014-03-24 21:27:19 +08:00
|
|
|
if (a != b) {
|
|
|
|
if (a > b) {
|
2014-03-23 22:14:29 +08:00
|
|
|
c = a;
|
|
|
|
a = b;
|
|
|
|
b = c;
|
|
|
|
}
|
|
|
|
var classes = [];
|
2014-03-24 21:27:19 +08:00
|
|
|
for (i = a; i <= b; i++) {
|
|
|
|
classes.push('.L' + i);
|
2014-03-23 22:14:29 +08:00
|
|
|
}
|
|
|
|
$list.filter(classes.join(',')).addClass('active');
|
|
|
|
$.changeHash('#L' + a + '-' + 'L' + b);
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$select.addClass('active');
|
|
|
|
$.changeHash('#' + $select.attr('rel'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).on('click', '.lines-num span', function (e) {
|
|
|
|
var $select = $(this);
|
|
|
|
var $list = $select.parent().siblings('.lines-code').find('ol.linenums > li');
|
2014-03-24 21:27:19 +08:00
|
|
|
selectRange($list, $list.filter('[rel=' + $select.attr('rel') + ']'), (e.shiftKey ? $list.filter('.active').eq(0) : null));
|
2014-03-23 22:14:29 +08:00
|
|
|
$.deSelect();
|
|
|
|
});
|
|
|
|
|
2014-03-24 21:27:19 +08:00
|
|
|
$('.code-view .lines-code > pre').each(function () {
|
2014-03-23 20:58:12 +08:00
|
|
|
var $pre = $(this);
|
2014-03-23 22:14:29 +08:00
|
|
|
var $lineCode = $pre.parent();
|
|
|
|
var $lineNums = $lineCode.siblings('.lines-num');
|
2014-03-23 20:58:12 +08:00
|
|
|
if ($lineNums.length > 0) {
|
|
|
|
var nums = $pre.find('ol.linenums > li').length;
|
|
|
|
for (var i = 1; i <= nums; i++) {
|
2014-03-23 22:14:29 +08:00
|
|
|
$lineNums.append('<span id="L' + i + '" rel="L' + i + '">' + i + '</span>');
|
2014-03-23 20:58:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-03-23 22:14:29 +08:00
|
|
|
|
2014-05-01 17:44:22 +08:00
|
|
|
$(window).on('hashchange', function (e) {
|
2014-03-23 22:14:29 +08:00
|
|
|
var m = window.location.hash.match(/^#(L\d+)\-(L\d+)$/);
|
|
|
|
var $list = $('.code-view ol.linenums > li');
|
2014-03-24 21:27:19 +08:00
|
|
|
if (m) {
|
|
|
|
var $first = $list.filter('.' + m[1]);
|
|
|
|
selectRange($list, $first, $list.filter('.' + m[2]));
|
|
|
|
$("html, body").scrollTop($first.offset().top - 200);
|
2014-03-23 22:14:29 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
m = window.location.hash.match(/^#(L\d+)$/);
|
2014-03-24 21:27:19 +08:00
|
|
|
if (m) {
|
|
|
|
var $first = $list.filter('.' + m[1]);
|
2014-03-23 22:14:29 +08:00
|
|
|
selectRange($list, $first);
|
2014-03-24 21:27:19 +08:00
|
|
|
$("html, body").scrollTop($first.offset().top - 200);
|
2014-03-23 22:14:29 +08:00
|
|
|
}
|
|
|
|
}).trigger('hashchange');
|
2014-03-23 20:58:12 +08:00
|
|
|
};
|
|
|
|
|
2014-04-03 00:56:26 +08:00
|
|
|
// copy utils
|
|
|
|
Gogits.bindCopy = function (selector) {
|
|
|
|
if ($(selector).hasClass('js-copy-bind')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$(selector).zclip({
|
|
|
|
path: "/js/ZeroClipboard.swf",
|
|
|
|
copy: function () {
|
|
|
|
var t = $(this).data("copy-val");
|
|
|
|
var to = $($(this).data("copy-from"));
|
|
|
|
var str = "";
|
|
|
|
if (t == "txt") {
|
|
|
|
str = to.text();
|
|
|
|
}
|
|
|
|
if (t == 'val') {
|
|
|
|
str = to.val();
|
|
|
|
}
|
|
|
|
if (t == 'html') {
|
|
|
|
str = to.html();
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
},
|
|
|
|
afterCopy: function () {
|
|
|
|
var $this = $(this);
|
|
|
|
$this.tooltip('hide')
|
|
|
|
.attr('data-original-title', 'Copied OK');
|
|
|
|
setTimeout(function () {
|
|
|
|
$this.tooltip("show");
|
|
|
|
}, 200);
|
|
|
|
setTimeout(function () {
|
|
|
|
$this.tooltip('hide')
|
|
|
|
.attr('data-original-title', 'Copy to Clipboard');
|
|
|
|
}, 3000);
|
|
|
|
}
|
|
|
|
}).addClass("js-copy-bind");
|
|
|
|
}
|
|
|
|
|
2014-07-07 18:13:42 +08:00
|
|
|
// api working
|
|
|
|
Gogits.getUsers = function (val, $target) {
|
|
|
|
$.ajax({
|
|
|
|
url: '/api/v1/users/search?q=' + val,
|
|
|
|
dataType: "json",
|
|
|
|
success: function (json) {
|
|
|
|
if (json.ok && json.data.length) {
|
|
|
|
var html = '';
|
|
|
|
$.each(json.data, function (i, item) {
|
|
|
|
html += '<li><img src="' + item.avatar + '">' + item.username + '</li>';
|
|
|
|
});
|
|
|
|
$target.toggleShow();
|
|
|
|
$target.find('ul').html(html);
|
|
|
|
} else {
|
|
|
|
$target.toggleHide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-03-10 21:12:49 +08:00
|
|
|
})(jQuery);
|
|
|
|
|
|
|
|
// ajax utils
|
|
|
|
(function ($) {
|
|
|
|
Gogits.ajaxDelete = function (url, data, success) {
|
|
|
|
data = data || {};
|
|
|
|
data._method = "DELETE";
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
method: "POST",
|
|
|
|
dataType: "json",
|
|
|
|
success: function (json) {
|
|
|
|
if (success) {
|
|
|
|
success(json);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2014-03-03 22:40:22 +08:00
|
|
|
})(jQuery);
|
|
|
|
|
|
|
|
|
2014-03-06 22:55:32 +08:00
|
|
|
function initCore() {
|
2014-03-10 16:54:52 +08:00
|
|
|
Gogits.initTooltips();
|
2014-03-17 18:13:07 +08:00
|
|
|
Gogits.initPopovers();
|
2014-03-13 14:08:49 +08:00
|
|
|
Gogits.initTabs();
|
2014-03-10 16:54:52 +08:00
|
|
|
Gogits.initModals();
|
2014-03-21 23:27:33 +08:00
|
|
|
Gogits.initDropDown();
|
2014-03-17 15:17:44 +08:00
|
|
|
Gogits.renderMarkdown();
|
2014-03-23 20:58:12 +08:00
|
|
|
Gogits.renderCodeView();
|
2014-03-06 22:55:32 +08:00
|
|
|
}
|
|
|
|
|
2014-03-17 15:17:44 +08:00
|
|
|
function initUserSetting() {
|
2014-04-06 16:48:02 +08:00
|
|
|
// ssh confirmation
|
2014-03-25 18:44:37 +08:00
|
|
|
$('#ssh-keys .delete').confirmation({
|
2014-03-16 21:07:50 +08:00
|
|
|
singleton: true,
|
2014-03-17 15:17:44 +08:00
|
|
|
onConfirm: function (e, $this) {
|
|
|
|
Gogits.ajaxDelete("", {"id": $this.data("del")}, function (json) {
|
|
|
|
if (json.ok) {
|
2014-03-16 21:07:50 +08:00
|
|
|
window.location.reload();
|
2014-03-17 15:17:44 +08:00
|
|
|
} else {
|
2014-03-16 21:07:50 +08:00
|
|
|
alert(json.err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-03-10 21:12:49 +08:00
|
|
|
});
|
2014-04-06 16:48:02 +08:00
|
|
|
|
|
|
|
// profile form
|
|
|
|
(function () {
|
|
|
|
$('#user-setting-username').on("keyup", function () {
|
|
|
|
var $this = $(this);
|
|
|
|
if ($this.val() != $this.attr('title')) {
|
|
|
|
$this.next('.help-block').toggleShow();
|
|
|
|
} else {
|
|
|
|
$this.next('.help-block').toggleHide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}())
|
2014-03-16 23:25:01 +08:00
|
|
|
}
|
|
|
|
|
2014-03-20 20:12:31 +08:00
|
|
|
function initRepository() {
|
2014-03-21 23:27:33 +08:00
|
|
|
// clone group button script
|
2014-03-20 21:32:08 +08:00
|
|
|
(function () {
|
2014-03-21 23:27:33 +08:00
|
|
|
var $clone = $('.clone-group-btn');
|
|
|
|
if ($clone.length) {
|
|
|
|
var $url = $('.clone-group-url');
|
2014-05-01 17:44:22 +08:00
|
|
|
$clone.find('button[data-link]').on("click", function (e) {
|
2014-03-20 21:32:08 +08:00
|
|
|
var $this = $(this);
|
|
|
|
if (!$this.hasClass('btn-primary')) {
|
2014-03-24 23:53:26 +08:00
|
|
|
$clone.find('.input-group-btn .btn-primary').removeClass('btn-primary').addClass("btn-default");
|
2014-03-20 21:32:08 +08:00
|
|
|
$(this).addClass('btn-primary').removeClass('btn-default');
|
|
|
|
$url.val($this.data("link"));
|
2014-03-21 23:27:33 +08:00
|
|
|
$clone.find('span.clone-url').text($this.data('link'));
|
2014-03-20 21:32:08 +08:00
|
|
|
}
|
|
|
|
}).eq(0).trigger("click");
|
2014-04-06 16:48:02 +08:00
|
|
|
$("#repo-clone").on("shown.bs.dropdown", function () {
|
2014-04-03 00:56:26 +08:00
|
|
|
Gogits.bindCopy("[data-init=copy]");
|
|
|
|
});
|
|
|
|
Gogits.bindCopy("[data-init=copy]:visible");
|
2014-03-20 21:32:08 +08:00
|
|
|
}
|
|
|
|
})();
|
2014-03-20 22:39:10 +08:00
|
|
|
|
|
|
|
// watching script
|
|
|
|
(function () {
|
2014-03-25 18:44:37 +08:00
|
|
|
var $watch = $('#repo-watching'),
|
2014-07-22 17:56:08 +08:00
|
|
|
watchLink = $watch.attr("data-watch"),
|
|
|
|
// Use $.attr() to work around jQuery not finding $.data("unwatch") in Firefox,
|
|
|
|
// which has a method "unwatch" on `Object` that gets returned instead.
|
|
|
|
unwatchLink = $watch.attr("data-unwatch");
|
2014-05-01 17:44:22 +08:00
|
|
|
$watch.on('click', '.to-watch', function () {
|
2014-03-20 22:39:10 +08:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
})();
|
2014-03-24 21:27:19 +08:00
|
|
|
|
|
|
|
// repo diff counter
|
|
|
|
(function () {
|
|
|
|
var $counter = $('.diff-counter');
|
|
|
|
if ($counter.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$counter.each(function (i, item) {
|
|
|
|
var $item = $(item);
|
|
|
|
var addLine = $item.find('span[data-line].add').data("line");
|
|
|
|
var delLine = $item.find('span[data-line].del').data("line");
|
|
|
|
var addPercent = parseFloat(addLine) / (parseFloat(addLine) + parseFloat(delLine)) * 100;
|
|
|
|
$item.find(".bar .add").css("width", addPercent + "%");
|
|
|
|
});
|
|
|
|
}());
|
2014-04-06 16:48:02 +08:00
|
|
|
|
|
|
|
// repo setting form
|
|
|
|
(function () {
|
|
|
|
$('#repo-setting-name').on("keyup", function () {
|
|
|
|
var $this = $(this);
|
|
|
|
if ($this.val() != $this.attr('title')) {
|
|
|
|
$this.next('.help-block').toggleShow();
|
|
|
|
} else {
|
|
|
|
$this.next('.help-block').toggleHide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}())
|
2014-03-20 20:12:31 +08:00
|
|
|
}
|
|
|
|
|
2014-03-27 23:32:20 +08:00
|
|
|
function initInstall() {
|
|
|
|
// database type change
|
2014-03-29 21:16:06 +08:00
|
|
|
(function () {
|
2014-07-26 05:51:41 +08:00
|
|
|
var mysql_default = '127.0.0.1:3306';
|
|
|
|
var postgres_default = '127.0.0.1:5432';
|
2014-04-30 04:35:25 +08:00
|
|
|
|
2014-03-29 21:16:06 +08:00
|
|
|
$('#install-database').on("change", function () {
|
|
|
|
var val = $(this).val();
|
2014-04-27 12:34:48 +08:00
|
|
|
if (val != "SQLite3") {
|
2014-03-29 21:16:06 +08:00
|
|
|
$('.server-sql').show();
|
|
|
|
$('.sqlite-setting').addClass("hide");
|
2014-04-27 12:34:48 +08:00
|
|
|
if (val == "PostgreSQL") {
|
2014-03-29 21:16:06 +08:00
|
|
|
$('.pgsql-setting').removeClass("hide");
|
2014-04-30 04:35:25 +08:00
|
|
|
|
|
|
|
// Change the host value to the Postgres default, but only
|
|
|
|
// if the user hasn't already changed it from the MySQL
|
|
|
|
// default.
|
|
|
|
if ($('#database-host').val() == mysql_default) {
|
|
|
|
$('#database-host').val(postgres_default);
|
|
|
|
}
|
|
|
|
} else if (val == 'MySQL') {
|
|
|
|
$('.pgsql-setting').addClass("hide");
|
|
|
|
if ($('#database-host').val() == postgres_default) {
|
|
|
|
$('#database-host').val(mysql_default);
|
|
|
|
}
|
2014-03-29 21:16:06 +08:00
|
|
|
} else {
|
|
|
|
$('.pgsql-setting').addClass("hide");
|
|
|
|
}
|
2014-03-27 20:39:18 +08:00
|
|
|
} else {
|
2014-03-29 21:16:06 +08:00
|
|
|
$('.server-sql').hide();
|
|
|
|
$('.sqlite-setting').removeClass("hide");
|
2014-03-27 20:39:18 +08:00
|
|
|
}
|
2014-03-29 21:16:06 +08:00
|
|
|
});
|
|
|
|
}());
|
|
|
|
|
2014-03-27 20:39:18 +08:00
|
|
|
}
|
|
|
|
|
2014-03-27 23:32:20 +08:00
|
|
|
function initIssue() {
|
|
|
|
// close button
|
|
|
|
(function () {
|
|
|
|
var $closeBtn = $('#issue-close-btn');
|
|
|
|
var $openBtn = $('#issue-open-btn');
|
|
|
|
$('#issue-reply-content').on("keyup", function () {
|
|
|
|
if ($(this).val().length) {
|
2014-03-29 20:46:36 +08:00
|
|
|
$closeBtn.val($closeBtn.data("text"));
|
|
|
|
$openBtn.val($openBtn.data("text"));
|
2014-03-27 23:32:20 +08:00
|
|
|
} else {
|
2014-03-29 20:46:36 +08:00
|
|
|
$closeBtn.val($closeBtn.data("origin"));
|
|
|
|
$openBtn.val($openBtn.data("origin"));
|
2014-03-27 23:32:20 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}());
|
|
|
|
|
2014-07-26 02:56:17 +08:00
|
|
|
// store unsend text in session storage.
|
|
|
|
(function() {
|
|
|
|
var $textArea = $("#issue-content,#issue-reply-content");
|
|
|
|
var current = "";
|
|
|
|
|
|
|
|
if ($textArea == null || !('sessionStorage' in window)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var path = location.pathname.split("/");
|
|
|
|
var key = "issue-" + path[1] + "-" + path[2] + "-";
|
|
|
|
|
|
|
|
if (/\/issues\/\d+$/.test(location.pathname)) {
|
|
|
|
key = key + path[4];
|
|
|
|
} else {
|
|
|
|
key = key + "new";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($textArea.val() !== undefined && $textArea.val() !== "") {
|
|
|
|
sessionStorage.setItem(key, $textArea.val());
|
|
|
|
} else {
|
|
|
|
$textArea.val(sessionStorage.getItem(key) || "");
|
|
|
|
|
|
|
|
if ($textArea.attr("id") == "issue-reply-content") {
|
|
|
|
var $closeBtn = $('#issue-close-btn');
|
|
|
|
var $openBtn = $('#issue-open-btn');
|
|
|
|
|
|
|
|
if ($textArea.val().length) {
|
|
|
|
$closeBtn.val($closeBtn.data("text"));
|
|
|
|
$openBtn.val($openBtn.data("text"));
|
|
|
|
} else {
|
|
|
|
$closeBtn.val($closeBtn.data("origin"));
|
|
|
|
$openBtn.val($openBtn.data("origin"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$textArea.on("keyup", function() {
|
|
|
|
if ($textArea.val() !== current) {
|
|
|
|
sessionStorage.setItem(key, current = $textArea.val());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}());
|
|
|
|
|
2014-07-24 19:50:03 +08:00
|
|
|
// Preview for images.
|
|
|
|
(function() {
|
|
|
|
var $hoverElement = $("<div></div>");
|
|
|
|
var $hoverImage = $("<img />");
|
|
|
|
|
|
|
|
$hoverElement.addClass("attachment-preview");
|
|
|
|
$hoverElement.hide();
|
|
|
|
|
|
|
|
$hoverImage.addClass("attachment-preview-img");
|
|
|
|
|
|
|
|
$hoverElement.append($hoverImage);
|
|
|
|
$(document.body).append($hoverElement);
|
|
|
|
|
|
|
|
var over = function() {
|
|
|
|
var $this = $(this);
|
|
|
|
|
2014-07-25 05:19:21 +08:00
|
|
|
if ((/\.(png|jpg|jpeg|gif)$/i).test($this.text()) == false) {
|
2014-07-24 19:50:03 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($hoverImage.attr("src") != $this.attr("href")) {
|
|
|
|
$hoverImage.attr("src", $this.attr("href"));
|
|
|
|
$hoverImage.load(function() {
|
|
|
|
var height = this.height;
|
|
|
|
var width = this.width;
|
|
|
|
|
|
|
|
if (height > 300) {
|
|
|
|
var factor = 300 / height;
|
|
|
|
|
|
|
|
height = factor * height;
|
|
|
|
width = factor * width;
|
|
|
|
}
|
|
|
|
|
|
|
|
$hoverImage.css({"height": height, "width": width});
|
|
|
|
|
|
|
|
var offset = $this.offset();
|
|
|
|
var left = offset.left, top = offset.top + $this.height() + 5;
|
|
|
|
|
|
|
|
$hoverElement.css({"top": top + "px", "left": left + "px"});
|
|
|
|
$hoverElement.css({"height": height + 16, "width": width + 16});
|
|
|
|
$hoverElement.show();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$hoverElement.show();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var out = function() {
|
2014-07-25 21:47:42 +08:00
|
|
|
$hoverElement.hide();
|
2014-07-24 19:50:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
$(".issue-main .attachments .attachment").hover(over, out);
|
|
|
|
}());
|
|
|
|
|
|
|
|
// Upload.
|
2014-07-24 03:15:47 +08:00
|
|
|
(function() {
|
2014-07-24 21:19:59 +08:00
|
|
|
var $attachedList = $("#attached-list");
|
2014-07-26 05:48:26 +08:00
|
|
|
var $addButton = $("#attachments-button");
|
|
|
|
var files = [];
|
|
|
|
var fileInput = document.getElementById("attachments-input");
|
2014-07-25 06:23:46 +08:00
|
|
|
|
|
|
|
if (fileInput === null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-24 21:19:59 +08:00
|
|
|
|
2014-07-25 16:47:37 +08:00
|
|
|
$attachedList.on("click", "span.attachment-remove", function(event) {
|
|
|
|
var $parent = $(this).parent();
|
|
|
|
|
|
|
|
files.splice($parent.data("index"), 1);
|
|
|
|
$parent.remove();
|
|
|
|
});
|
2014-07-26 05:48:26 +08:00
|
|
|
|
|
|
|
var clickedButton;
|
|
|
|
|
2014-07-26 05:47:01 +08:00
|
|
|
$('#issue-reply-btn,input[type="submit"]', fileInput.form).on('click', function() {
|
2014-07-25 16:47:37 +08:00
|
|
|
clickedButton = this;
|
2014-07-25 17:13:42 +08:00
|
|
|
|
|
|
|
var $button = $(this);
|
|
|
|
|
2014-07-26 05:49:51 +08:00
|
|
|
$button.removeClass("btn-success btn-default");
|
2014-07-25 17:13:42 +08:00
|
|
|
$button.addClass("btn-warning");
|
|
|
|
|
2014-07-26 05:50:03 +08:00
|
|
|
$button.text("Submitting…");
|
2014-07-25 16:47:37 +08:00
|
|
|
});
|
|
|
|
|
2014-07-26 05:48:26 +08:00
|
|
|
fileInput.form.addEventListener("submit", function(event) {
|
2014-07-25 16:47:37 +08:00
|
|
|
event.stopImmediatePropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
//var data = new FormData(this);
|
|
|
|
|
|
|
|
// Internet Explorer ... -_-
|
|
|
|
var data = new FormData();
|
|
|
|
|
|
|
|
$.each($("[name]", this), function(i, e) {
|
|
|
|
if (e.name == "attachments" || e.type == "submit") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.append(e.name, $(e).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
data.append(clickedButton.name, $(clickedButton).val());
|
|
|
|
|
|
|
|
files.forEach(function(file) {
|
|
|
|
data.append("attachments", file);
|
|
|
|
});
|
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
|
|
|
|
xhr.addEventListener("error", function() {
|
2014-07-26 05:50:25 +08:00
|
|
|
console.log("Issue submit request failed. xhr.status: " + xhr.status);
|
2014-07-25 16:47:37 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
xhr.addEventListener("load", function() {
|
2014-07-25 17:13:42 +08:00
|
|
|
var response = xhr.response;
|
|
|
|
|
|
|
|
if (typeof response == "string") {
|
|
|
|
try {
|
|
|
|
response = JSON.parse(response);
|
|
|
|
} catch (err) {
|
|
|
|
response = { ok: false, error: "Could not parse JSON" };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.ok === false) {
|
|
|
|
$("#submit-error").text(response.error);
|
|
|
|
$("#submit-error").show();
|
|
|
|
|
|
|
|
var $button = $(clickedButton);
|
|
|
|
|
|
|
|
$button.removeClass("btn-warning");
|
|
|
|
$button.addClass("btn-danger");
|
|
|
|
|
2014-07-26 05:50:03 +08:00
|
|
|
$button.text("An error occurred!");
|
2014-07-25 17:13:42 +08:00
|
|
|
|
2014-07-25 16:47:37 +08:00
|
|
|
return;
|
2014-07-26 02:56:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!('sessionStorage' in window)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var path = location.pathname.split("/");
|
|
|
|
var key = "issue-" + path[1] + "-" + path[2] + "-";
|
|
|
|
|
|
|
|
if (/\/issues\/\d+$/.test(location.pathname)) {
|
|
|
|
key = key + path[4];
|
|
|
|
} else {
|
|
|
|
key = key + "new";
|
|
|
|
}
|
2014-07-25 16:47:37 +08:00
|
|
|
|
2014-07-26 02:56:17 +08:00
|
|
|
sessionStorage.removeItem(key);
|
2014-07-25 17:13:42 +08:00
|
|
|
window.location.href = response.data;
|
2014-07-25 16:47:37 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
xhr.open("POST", this.action, true);
|
|
|
|
xhr.send(data);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2014-07-26 05:51:18 +08:00
|
|
|
fileInput.addEventListener("change", function() {
|
2014-07-24 21:19:59 +08:00
|
|
|
for (var index = 0; index < fileInput.files.length; index++) {
|
|
|
|
var file = fileInput.files[index];
|
|
|
|
|
2014-07-25 16:47:37 +08:00
|
|
|
if (files.indexOf(file) > -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:19:59 +08:00
|
|
|
var $span = $("<span></span>");
|
|
|
|
|
|
|
|
$span.addClass("label");
|
|
|
|
$span.addClass("label-default");
|
|
|
|
|
2014-07-25 16:47:37 +08:00
|
|
|
$span.data("index", files.length);
|
|
|
|
|
|
|
|
$span.append(file.name);
|
|
|
|
$span.append(" <span class=\"attachment-remove fa fa-times-circle\"></span>");
|
|
|
|
|
2014-07-24 21:19:59 +08:00
|
|
|
$attachedList.append($span);
|
2014-07-25 16:47:37 +08:00
|
|
|
|
|
|
|
files.push(file);
|
2014-07-24 21:19:59 +08:00
|
|
|
}
|
2014-07-25 16:47:37 +08:00
|
|
|
|
|
|
|
this.value = "";
|
2014-07-24 21:19:59 +08:00
|
|
|
});
|
2014-07-24 03:15:47 +08:00
|
|
|
|
2014-07-26 05:51:18 +08:00
|
|
|
$addButton.on("click", function(evt) {
|
2014-07-24 21:19:59 +08:00
|
|
|
fileInput.click();
|
2014-07-26 05:51:18 +08:00
|
|
|
evt.preventDefault();
|
2014-07-24 03:15:47 +08:00
|
|
|
});
|
|
|
|
}());
|
|
|
|
|
2014-03-27 23:32:20 +08:00
|
|
|
// issue edit mode
|
|
|
|
(function () {
|
|
|
|
$("#issue-edit-btn").on("click", function () {
|
|
|
|
$('#issue h1.title,#issue .issue-main > .issue-content .content,#issue-edit-btn').toggleHide();
|
2014-05-21 20:49:47 +08:00
|
|
|
$('#issue-edit-title,.issue-edit-content,.issue-edit-cancel,.issue-edit-save').toggleShow();
|
2014-03-27 23:32:20 +08:00
|
|
|
});
|
|
|
|
$('.issue-edit-cancel').on("click", function () {
|
|
|
|
$('#issue h1.title,#issue .issue-main > .issue-content .content,#issue-edit-btn').toggleShow();
|
2014-05-21 20:49:47 +08:00
|
|
|
$('#issue-edit-title,.issue-edit-content,.issue-edit-cancel,.issue-edit-save').toggleHide();
|
2014-07-26 05:51:41 +08:00
|
|
|
});
|
2014-03-27 23:32:20 +08:00
|
|
|
}());
|
2014-03-29 20:46:36 +08:00
|
|
|
|
|
|
|
// issue ajax update
|
2014-03-29 21:16:06 +08:00
|
|
|
(function () {
|
2014-05-21 20:49:47 +08:00
|
|
|
var $cnt = $('#issue-edit-content');
|
2014-03-29 21:16:06 +08:00
|
|
|
$('.issue-edit-save').on("click", function () {
|
2014-05-21 20:49:47 +08:00
|
|
|
$cnt.attr('data-ajax-rel', 'issue-edit-save');
|
2014-03-29 21:16:06 +08:00
|
|
|
$(this).toggleAjax(function (json) {
|
|
|
|
if (json.ok) {
|
|
|
|
$('.issue-head h1.title').text(json.title);
|
|
|
|
$('.issue-main > .issue-content .content').html(json.content);
|
2014-03-29 23:03:01 +08:00
|
|
|
$('.issue-edit-cancel').trigger("click");
|
2014-03-29 21:16:06 +08:00
|
|
|
}
|
|
|
|
});
|
2014-05-21 20:49:47 +08:00
|
|
|
setTimeout(function () {
|
|
|
|
$cnt.attr('data-ajax-rel', 'issue-edit-preview');
|
|
|
|
}, 200)
|
2014-03-29 20:46:36 +08:00
|
|
|
});
|
2014-03-29 21:16:06 +08:00
|
|
|
}());
|
|
|
|
|
|
|
|
// issue ajax preview
|
|
|
|
(function () {
|
2014-05-21 20:49:47 +08:00
|
|
|
$('[data-ajax-name=issue-preview],[data-ajax-name=issue-edit-preview]').on("click", function () {
|
2014-03-29 21:16:06 +08:00
|
|
|
var $this = $(this);
|
2014-05-06 01:08:01 +08:00
|
|
|
$this.toggleAjax(function (resp) {
|
|
|
|
$($this.data("preview")).html(resp);
|
2014-05-14 21:29:54 +08:00
|
|
|
}, function () {
|
2014-05-12 20:35:26 +08:00
|
|
|
$($this.data("preview")).html("no content");
|
2014-03-29 21:16:06 +08:00
|
|
|
})
|
|
|
|
});
|
|
|
|
$('.issue-write a[data-toggle]').on("click", function () {
|
2014-05-21 20:49:47 +08:00
|
|
|
var selector = $(this).parent().next(".issue-preview").find('a').data('preview');
|
|
|
|
$(selector).html("loading...");
|
2014-03-29 21:16:06 +08:00
|
|
|
});
|
2014-05-08 21:01:47 +08:00
|
|
|
}());
|
|
|
|
|
|
|
|
// assignee
|
2014-05-09 20:44:08 +08:00
|
|
|
var is_issue_bar = $('.issue-bar').length > 0;
|
|
|
|
var $a = $('.assignee');
|
2014-05-12 20:35:26 +08:00
|
|
|
if ($a.data("assigned") > 0) {
|
2014-05-09 20:44:08 +08:00
|
|
|
$('.clear-assignee').toggleShow();
|
|
|
|
}
|
2014-05-08 21:01:47 +08:00
|
|
|
$('.assignee', '#issue').on('click', 'li', function () {
|
|
|
|
var uid = $(this).data("uid");
|
2014-05-12 20:35:26 +08:00
|
|
|
if (is_issue_bar) {
|
2014-05-09 20:44:08 +08:00
|
|
|
var assignee = $a.data("assigned");
|
2014-05-12 20:35:26 +08:00
|
|
|
if (uid != assignee) {
|
2014-07-22 21:46:15 +08:00
|
|
|
var text = $(this).text();
|
|
|
|
var img = $("img", this).attr("src");
|
|
|
|
|
2014-05-09 20:44:08 +08:00
|
|
|
$.post($a.data("ajax"), {
|
|
|
|
issue: $('#issue').data("id"),
|
2014-05-12 01:46:36 +08:00
|
|
|
assigneeid: uid
|
2014-05-09 20:44:08 +08:00
|
|
|
}, function (json) {
|
|
|
|
if (json.ok) {
|
2014-07-22 21:46:15 +08:00
|
|
|
//window.location.reload();
|
|
|
|
$a.data("assigned", uid);
|
|
|
|
|
|
|
|
if (uid > 0) {
|
|
|
|
$('.clear-assignee').toggleShow();
|
|
|
|
$(".assignee > p").html('<img src="' + img + '"><strong>' + text + '</strong>');
|
|
|
|
} else {
|
|
|
|
$('.clear-assignee').toggleHide();
|
|
|
|
$(".assignee > p").text("No one assigned");
|
|
|
|
}
|
2014-05-09 20:44:08 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2014-07-22 21:46:15 +08:00
|
|
|
|
2014-05-09 20:44:08 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-05-08 21:01:47 +08:00
|
|
|
$('#assignee').val(uid);
|
|
|
|
if (uid > 0) {
|
|
|
|
$('.clear-assignee').toggleShow();
|
|
|
|
$('#assigned').text($(this).find("strong").text())
|
|
|
|
} else {
|
|
|
|
$('.clear-assignee').toggleHide();
|
|
|
|
$('#assigned').text($('#assigned').data("no-assigned"));
|
|
|
|
}
|
|
|
|
});
|
2014-03-29 21:16:06 +08:00
|
|
|
|
2014-05-14 21:29:54 +08:00
|
|
|
// milestone
|
|
|
|
|
2014-05-14 22:01:20 +08:00
|
|
|
$('#issue .dropdown-menu a[data-toggle="tab"]').on("click", function (e) {
|
2014-05-14 21:29:54 +08:00
|
|
|
e.stopPropagation();
|
|
|
|
$(this).tab('show');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
var $m = $('.milestone');
|
|
|
|
if ($m.data("milestone") > 0) {
|
|
|
|
$('.clear-milestone').toggleShow();
|
|
|
|
}
|
|
|
|
$('.milestone', '#issue').on('click', 'li.milestone-item', function () {
|
2014-07-22 21:46:15 +08:00
|
|
|
var id = $(this).data("id");
|
2014-05-14 21:29:54 +08:00
|
|
|
if (is_issue_bar) {
|
|
|
|
var m = $m.data("milestone");
|
|
|
|
if (id != m) {
|
2014-07-22 21:46:15 +08:00
|
|
|
var text = $(this).text();
|
|
|
|
|
2014-05-14 21:29:54 +08:00
|
|
|
$.post($m.data("ajax"), {
|
|
|
|
issue: $('#issue').data("id"),
|
|
|
|
milestone: id
|
|
|
|
}, function (json) {
|
|
|
|
if (json.ok) {
|
2014-07-22 21:46:15 +08:00
|
|
|
//window.location.reload();
|
|
|
|
$m.data("milestone", id);
|
|
|
|
|
|
|
|
if (id > 0) {
|
2014-05-14 21:29:54 +08:00
|
|
|
$('.clear-milestone').toggleShow();
|
2014-07-22 21:46:15 +08:00
|
|
|
$(".milestone > .name").html('<a href="' + location.pathname + '?milestone=' + id + '"><strong>' + text + '</strong></a>');
|
2014-05-14 21:29:54 +08:00
|
|
|
} else {
|
|
|
|
$('.clear-milestone').toggleHide();
|
2014-07-22 21:46:15 +08:00
|
|
|
$(".milestone > .name").text("No milestone");
|
2014-05-14 21:29:54 +08:00
|
|
|
}
|
|
|
|
}
|
2014-07-22 21:46:15 +08:00
|
|
|
});
|
2014-05-14 21:29:54 +08:00
|
|
|
}
|
2014-07-22 21:46:15 +08:00
|
|
|
|
2014-05-14 22:01:20 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$('#milestone-id').val(id);
|
|
|
|
if (id > 0) {
|
|
|
|
$('.clear-milestone').toggleShow();
|
|
|
|
$('#milestone').text($(this).find("strong").text())
|
|
|
|
} else {
|
|
|
|
$('.clear-milestone').toggleHide();
|
|
|
|
$('#milestone').text($('#milestone').data("no-milestone"));
|
2014-05-14 21:29:54 +08:00
|
|
|
}
|
|
|
|
});
|
2014-05-19 21:55:25 +08:00
|
|
|
|
|
|
|
// labels
|
2014-05-24 13:39:12 +08:00
|
|
|
var removeLabels = [];
|
2014-05-19 21:55:25 +08:00
|
|
|
$('#label-manage-btn').on("click", function () {
|
|
|
|
var $list = $('#label-list');
|
|
|
|
if ($list.hasClass("managing")) {
|
|
|
|
var ids = [];
|
|
|
|
$list.find('li').each(function (i, item) {
|
|
|
|
var id = $(item).data("id");
|
|
|
|
if (id > 0) {
|
|
|
|
ids.push(id);
|
|
|
|
}
|
|
|
|
});
|
2014-05-24 13:39:12 +08:00
|
|
|
$.post($list.data("ajax"), {"ids": ids.join(","), "remove": removeLabels.join(",")}, function (json) {
|
2014-05-19 21:55:25 +08:00
|
|
|
if (json.ok) {
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
$list.addClass("managing");
|
|
|
|
$list.find(".count").hide();
|
|
|
|
$list.find(".del").show();
|
|
|
|
$(this).text("Save Labels");
|
|
|
|
$list.on('click', 'li.label-item', function () {
|
|
|
|
var $this = $(this);
|
|
|
|
$this.after($('.label-change-li').detach().show());
|
|
|
|
$('#label-name-change-ipt').val($this.find('.name').text());
|
|
|
|
var color = $this.find('.color').data("color");
|
|
|
|
$('.label-change-color-picker').colorpicker("setValue", color);
|
2014-05-26 21:21:30 +08:00
|
|
|
$('#label-color-change-ipt,#label-color-change-ipt2').val(color);
|
2014-05-19 21:55:25 +08:00
|
|
|
$('#label-change-id-ipt').val($this.data("id"));
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2014-05-26 21:21:30 +08:00
|
|
|
var colorRegex = new RegExp("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$");
|
|
|
|
$('#label-color-ipt2').on('keyup', function () {
|
|
|
|
var val = $(this).val();
|
|
|
|
if (val.length > 7) {
|
|
|
|
$(this).val(val.substr(0, 7));
|
|
|
|
}
|
|
|
|
if (colorRegex.test(val)) {
|
|
|
|
$('.label-color-picker').colorpicker("setValue", val);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
$('#label-color-change-ipt2').on('keyup', function () {
|
|
|
|
var val = $(this).val();
|
|
|
|
console.log(val);
|
|
|
|
if (val.length > 7) {
|
|
|
|
$(this).val(val.substr(0, 7));
|
|
|
|
}
|
|
|
|
if (colorRegex.test(val)) {
|
|
|
|
$('.label-change-color-picker').colorpicker("setValue", val);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2014-05-19 21:55:25 +08:00
|
|
|
$("#label-list").on('click', '.del', function () {
|
2014-05-24 13:39:12 +08:00
|
|
|
var $p = $(this).parent();
|
|
|
|
removeLabels.push($p.data('id'));
|
|
|
|
$p.remove();
|
2014-05-19 21:55:25 +08:00
|
|
|
return false;
|
|
|
|
});
|
2014-05-26 21:21:30 +08:00
|
|
|
$('.label-selected').each(function (i, item) {
|
|
|
|
var $item = $(item);
|
|
|
|
var color = $item.find('.color').data('color');
|
|
|
|
$item.css('background-color', color);
|
|
|
|
});
|
2014-07-22 21:46:15 +08:00
|
|
|
|
2014-05-19 23:47:11 +08:00
|
|
|
$('.issue-bar .labels .dropdown-menu').on('click', 'li', function (e) {
|
2014-07-22 21:46:15 +08:00
|
|
|
var $labels = $('.issue-bar .labels');
|
|
|
|
var url = $labels.data("ajax");
|
2014-05-19 23:47:11 +08:00
|
|
|
var id = $(this).data('id');
|
|
|
|
var check = $(this).hasClass("checked");
|
2014-07-22 21:46:15 +08:00
|
|
|
var item = this;
|
2014-05-24 13:39:12 +08:00
|
|
|
$.post(url, {id: id, action: check ? 'detach' : "attach", issue: $('#issue').data('id')}, function (json) {
|
2014-05-19 23:47:11 +08:00
|
|
|
if (json.ok) {
|
2014-07-22 21:46:15 +08:00
|
|
|
if (check) {
|
|
|
|
$("span.check.pull-left", item).remove();
|
|
|
|
|
|
|
|
$(item).removeClass("checked");
|
|
|
|
$(item).addClass("no-checked");
|
|
|
|
|
|
|
|
$("#label-" + id, $labels).remove();
|
2014-07-26 02:15:58 +08:00
|
|
|
|
|
|
|
if ($labels.children(".label-item").length == 0) {
|
|
|
|
$labels.append("<p>None yet</p>");
|
|
|
|
}
|
2014-07-22 21:46:15 +08:00
|
|
|
} else {
|
|
|
|
$(item).prepend('<span class="check pull-left"><i class="fa fa-check"></i></span>');
|
|
|
|
|
|
|
|
$(item).removeClass("no-checked");
|
|
|
|
$(item).addClass("checked");
|
2014-07-26 02:15:58 +08:00
|
|
|
|
|
|
|
$("p:not([class])", $labels).remove();
|
2014-07-22 21:46:15 +08:00
|
|
|
|
|
|
|
var $l = $("<p></p>");
|
|
|
|
var c = $("span.color", item).css("background-color");
|
|
|
|
|
|
|
|
$l.attr("id", "label-" + id);
|
|
|
|
$l.attr("class", "label-item label-white");
|
|
|
|
$l.css("background-color", c);
|
|
|
|
|
|
|
|
$l.append("<strong>" + $(item).text() + "</strong>");
|
|
|
|
$labels.append($l);
|
|
|
|
}
|
2014-05-19 23:47:11 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
e.stopPropagation();
|
|
|
|
return false;
|
|
|
|
})
|
2014-03-27 23:32:20 +08:00
|
|
|
}
|
|
|
|
|
2014-04-06 16:29:45 +08:00
|
|
|
function initRelease() {
|
|
|
|
// release new ajax preview
|
|
|
|
(function () {
|
|
|
|
$('[data-ajax-name=release-preview]').on("click", function () {
|
|
|
|
var $this = $(this);
|
2014-06-12 21:35:51 +08:00
|
|
|
$this.toggleAjax(function (resp) {
|
|
|
|
$($this.data("preview")).html(resp);
|
2014-05-12 20:35:26 +08:00
|
|
|
}, function () {
|
|
|
|
$($this.data("preview")).html("no content");
|
2014-04-06 16:29:45 +08:00
|
|
|
})
|
|
|
|
});
|
|
|
|
$('.release-write a[data-toggle]').on("click", function () {
|
|
|
|
$('.release-preview-content').html("loading...");
|
|
|
|
});
|
2014-04-14 20:40:22 +08:00
|
|
|
}());
|
|
|
|
|
|
|
|
// release new target selection
|
|
|
|
(function () {
|
|
|
|
$('#release-new-target-branch-list').on('click', 'a', function () {
|
|
|
|
$('#tag-target').val($(this).text());
|
|
|
|
$('#release-new-target-name').text(" " + $(this).text());
|
|
|
|
});
|
|
|
|
}());
|
2014-04-06 16:29:45 +08:00
|
|
|
}
|
|
|
|
|
2014-05-01 17:44:22 +08:00
|
|
|
function initRepoSetting() {
|
|
|
|
// repo member add
|
|
|
|
$('#repo-collaborator').on('keyup', function () {
|
|
|
|
var $this = $(this);
|
|
|
|
if (!$this.val()) {
|
|
|
|
$this.next().toggleHide();
|
|
|
|
return;
|
|
|
|
}
|
2014-07-07 18:13:42 +08:00
|
|
|
Gogits.getUsers($this.val(), $this.next());
|
|
|
|
/*$.ajax({
|
|
|
|
url: '/api/v1/users/search?q=' + $this.val(),
|
|
|
|
dataType: "json",
|
|
|
|
success: function (json) {
|
|
|
|
if (json.ok && json.data.length) {
|
|
|
|
var html = '';
|
|
|
|
$.each(json.data, function (i, item) {
|
|
|
|
html += '<li><img src="' + item.avatar + '">' + item.username + '</li>';
|
|
|
|
});
|
|
|
|
$this.next().toggleShow();
|
|
|
|
$this.next().find('ul').html(html);
|
|
|
|
} else {
|
|
|
|
$this.next().toggleHide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});*/
|
2014-05-01 17:44:22 +08:00
|
|
|
}).on('focus', function () {
|
|
|
|
if (!$(this).val()) {
|
|
|
|
$(this).next().toggleHide();
|
|
|
|
}
|
2014-05-08 21:01:47 +08:00
|
|
|
}).next().on("click", 'li', function () {
|
2014-05-01 17:44:22 +08:00
|
|
|
$('#repo-collaborator').val($(this).text());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-06-25 13:08:28 +08:00
|
|
|
function initRepoCreating() {
|
|
|
|
// owner switch menu click
|
|
|
|
(function () {
|
|
|
|
$('#repo-owner-switch .dropdown-menu').on("click", "li", function () {
|
|
|
|
var uid = $(this).data('uid');
|
|
|
|
// set to input
|
|
|
|
$('#repo-owner-id').val(uid);
|
|
|
|
// set checked class
|
|
|
|
if (!$(this).hasClass("checked")) {
|
|
|
|
$(this).parent().find(".checked").removeClass("checked");
|
|
|
|
$(this).addClass("checked");
|
|
|
|
}
|
2014-06-25 16:03:29 +08:00
|
|
|
// set button group to show clicked owner
|
2014-07-07 18:13:42 +08:00
|
|
|
$('#repo-owner-avatar').attr("src", $(this).find('img').attr("src"));
|
2014-06-25 16:03:29 +08:00
|
|
|
$('#repo-owner-name').text($(this).text().trim());
|
2014-07-07 18:13:42 +08:00
|
|
|
console.log("set repo owner to uid :", uid, $(this).text().trim());
|
2014-06-25 13:08:28 +08:00
|
|
|
});
|
|
|
|
}());
|
|
|
|
console.log("init repo-creating scripts");
|
|
|
|
}
|
|
|
|
|
2014-07-07 18:13:42 +08:00
|
|
|
function initOrganization() {
|
|
|
|
(function(){
|
|
|
|
$('#org-team-add-user').on('keyup', function () {
|
|
|
|
var $this = $(this);
|
|
|
|
if (!$this.val()) {
|
|
|
|
$this.next().toggleHide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Gogits.getUsers($this.val(), $this.next());
|
|
|
|
}).on('focus', function () {
|
|
|
|
if (!$(this).val()) {
|
|
|
|
$(this).next().toggleHide();
|
|
|
|
}
|
|
|
|
}).next().on("click", 'li', function () {
|
|
|
|
$('#org-team-add-user').val($(this).text());
|
|
|
|
$('#org-team-add-user-form').submit();
|
|
|
|
}).toggleHide();
|
|
|
|
console.log("init script : add user to team");
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function(){
|
|
|
|
$('#org-team-add-repo').next().toggleHide();
|
|
|
|
console.log("init script : add repository to team");
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
|
|
console.log("init script : organization done");
|
|
|
|
}
|
|
|
|
|
2014-07-25 04:31:59 +08:00
|
|
|
function initTimeSwitch() {
|
|
|
|
$(".time-since[title]").on("click", function() {
|
|
|
|
var $this = $(this);
|
|
|
|
|
|
|
|
var title = $this.attr("title");
|
|
|
|
var text = $this.text();
|
|
|
|
|
|
|
|
$this.text(title);
|
|
|
|
$this.attr("title", text);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-03-17 15:17:44 +08:00
|
|
|
(function ($) {
|
|
|
|
$(function () {
|
|
|
|
initCore();
|
2014-03-25 18:44:37 +08:00
|
|
|
var body = $("#body");
|
2014-03-17 15:17:44 +08:00
|
|
|
if (body.data("page") == "user") {
|
|
|
|
initUserSetting();
|
|
|
|
}
|
2014-03-25 18:44:37 +08:00
|
|
|
if ($('.repo-nav').length) {
|
2014-03-20 20:12:31 +08:00
|
|
|
initRepository();
|
|
|
|
}
|
2014-03-27 23:32:20 +08:00
|
|
|
if ($('#install-card').length) {
|
2014-03-27 20:39:18 +08:00
|
|
|
initInstall();
|
|
|
|
}
|
2014-03-27 23:32:20 +08:00
|
|
|
if ($('#issue').length) {
|
|
|
|
initIssue();
|
|
|
|
}
|
2014-04-06 16:29:45 +08:00
|
|
|
if ($('#release').length) {
|
|
|
|
initRelease();
|
|
|
|
}
|
2014-05-01 17:44:22 +08:00
|
|
|
if ($('#repo-setting-container').length) {
|
|
|
|
initRepoSetting();
|
|
|
|
}
|
2014-06-25 13:08:28 +08:00
|
|
|
if ($('#repo-create').length) {
|
|
|
|
initRepoCreating();
|
|
|
|
}
|
2014-07-07 18:13:42 +08:00
|
|
|
if ($('#body-nav').hasClass("org-nav")) {
|
|
|
|
initOrganization();
|
|
|
|
}
|
2014-07-25 04:31:59 +08:00
|
|
|
|
|
|
|
initTimeSwitch();
|
2014-03-16 23:25:01 +08:00
|
|
|
});
|
|
|
|
})(jQuery);
|
2014-05-11 22:37:31 +08:00
|
|
|
|
2014-05-12 20:35:26 +08:00
|
|
|
String.prototype.endsWith = function (suffix) {
|
2014-05-11 22:37:31 +08:00
|
|
|
return this.indexOf(suffix, this.length - suffix.length) !== -1;
|
|
|
|
};
|