2014-03-06 09:55:32 -05:00
|
|
|
var Gogits = {
|
|
|
|
"PageIsSignup": false
|
|
|
|
};
|
2014-03-02 08:47:55 -05:00
|
|
|
|
2014-03-06 09:55:32 -05:00
|
|
|
(function ($) {
|
2014-03-10 03:54:52 -05:00
|
|
|
|
2014-03-02 08:47:55 -05:00
|
|
|
Gogits.showTab = function (selector, index) {
|
|
|
|
if (!index) {
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
$(selector).tab("show");
|
|
|
|
$(selector).find("li:eq(" + index + ") a").tab("show");
|
2014-03-06 09:55:32 -05: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 03:54:52 -05:00
|
|
|
|
|
|
|
// ----- init elements
|
|
|
|
Gogits.initModals = function () {
|
|
|
|
var modals = $("[data-toggle=modal]");
|
|
|
|
if (modals.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$.each(modals, function (i, item) {
|
2014-03-10 08:12:49 -05:00
|
|
|
var hide = $(item).data('modal');
|
|
|
|
$(item).modal(hide ? hide : "hide");
|
2014-03-10 03:54:52 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
Gogits.initTooltips = function () {
|
|
|
|
$("body").tooltip({
|
|
|
|
selector: "[data-toggle=tooltip]"
|
|
|
|
//container: "body"
|
|
|
|
});
|
|
|
|
};
|
2014-03-17 05:13:07 -05:00
|
|
|
Gogits.initPopovers = function () {
|
2014-03-20 07:12:31 -05:00
|
|
|
var hideAllPopovers = function () {
|
|
|
|
$('[data-toggle=popover]').each(function () {
|
2014-03-17 05:13:07 -05:00
|
|
|
$(this).popover('hide');
|
2014-03-20 07:12:31 -05:00
|
|
|
});
|
2014-03-17 05:13:07 -05:00
|
|
|
};
|
|
|
|
|
2014-03-20 07:12:31 -05:00
|
|
|
$(document).on('click', function (e) {
|
2014-03-17 05:13:07 -05:00
|
|
|
var $e = $(e.target);
|
2014-03-20 07:12:31 -05:00
|
|
|
if ($e.data('toggle') == 'popover' || $e.parents("[data-toggle=popover], .popover").length > 0) {
|
2014-03-17 05:13:07 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
hideAllPopovers();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("body").popover({
|
|
|
|
selector: "[data-toggle=popover]"
|
|
|
|
});
|
|
|
|
};
|
2014-03-10 08:12:49 -05:00
|
|
|
Gogits.initTabs = function () {
|
2014-03-13 01:08:49 -05:00
|
|
|
var $tabs = $('[data-init=tabs]');
|
|
|
|
$tabs.find("li:eq(0) a").tab("show");
|
2014-03-17 02:17:44 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// render markdown
|
|
|
|
Gogits.renderMarkdown = function () {
|
|
|
|
var $pre = $('.markdown').find('pre > code').parent();
|
2014-03-20 07:42:06 -05:00
|
|
|
$pre.addClass("prettyprint linenums");
|
2014-03-17 02:17:44 -05:00
|
|
|
prettyPrint();
|
2014-03-10 08:12:49 -05:00
|
|
|
}
|
2014-03-17 02:17:44 -05:00
|
|
|
|
2014-03-10 08:12:49 -05: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 09:40:22 -05:00
|
|
|
})(jQuery);
|
|
|
|
|
|
|
|
|
2014-03-06 09:55:32 -05:00
|
|
|
function initCore() {
|
2014-03-10 03:54:52 -05:00
|
|
|
Gogits.initTooltips();
|
2014-03-17 05:13:07 -05:00
|
|
|
Gogits.initPopovers();
|
2014-03-13 01:08:49 -05:00
|
|
|
Gogits.initTabs();
|
2014-03-10 03:54:52 -05:00
|
|
|
Gogits.initModals();
|
2014-03-17 02:17:44 -05:00
|
|
|
Gogits.renderMarkdown();
|
2014-03-06 09:55:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function initRegister() {
|
|
|
|
$.getScript("/js/jquery.validate.min.js", function () {
|
|
|
|
Gogits.validateForm("#gogs-login-card", {
|
|
|
|
rules: {
|
|
|
|
"username": {
|
|
|
|
required: true,
|
|
|
|
maxlength: 30
|
|
|
|
},
|
|
|
|
"email": {
|
|
|
|
required: true,
|
|
|
|
email: true
|
|
|
|
},
|
|
|
|
"passwd": {
|
|
|
|
required: true,
|
|
|
|
minlength: 6,
|
|
|
|
maxlength: 30
|
|
|
|
},
|
|
|
|
"re-passwd": {
|
|
|
|
required: true,
|
|
|
|
equalTo: "input[name=passwd]"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2014-03-10 08:12:49 -05:00
|
|
|
}
|
|
|
|
|
2014-03-17 02:17:44 -05:00
|
|
|
function initUserSetting() {
|
2014-03-16 08:07:50 -05:00
|
|
|
$('#gogs-ssh-keys .delete').confirmation({
|
|
|
|
singleton: true,
|
2014-03-17 02:17:44 -05:00
|
|
|
onConfirm: function (e, $this) {
|
|
|
|
Gogits.ajaxDelete("", {"id": $this.data("del")}, function (json) {
|
|
|
|
if (json.ok) {
|
2014-03-16 08:07:50 -05:00
|
|
|
window.location.reload();
|
2014-03-17 02:17:44 -05:00
|
|
|
} else {
|
2014-03-16 08:07:50 -05:00
|
|
|
alert(json.err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-03-10 08:12:49 -05:00
|
|
|
});
|
2014-03-16 10:25:01 -05:00
|
|
|
}
|
|
|
|
|
2014-03-20 07:12:31 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-17 02:17:44 -05:00
|
|
|
(function ($) {
|
|
|
|
$(function () {
|
|
|
|
initCore();
|
|
|
|
var body = $("#gogs-body");
|
|
|
|
if (body.data("page") == "user-signup") {
|
|
|
|
initRegister();
|
|
|
|
}
|
|
|
|
if (body.data("page") == "user") {
|
|
|
|
initUserSetting();
|
|
|
|
}
|
2014-03-20 07:12:31 -05:00
|
|
|
if ($('.gogs-repo-nav').length) {
|
|
|
|
initRepository();
|
|
|
|
}
|
2014-03-16 10:25:01 -05:00
|
|
|
});
|
|
|
|
})(jQuery);
|