You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.0 KiB

  1. var Gogits = {
  2. "PageIsSignup": false
  3. };
  4. (function ($) {
  5. Gogits.showTab = function (selector, index) {
  6. if (!index) {
  7. index = 0;
  8. }
  9. $(selector).tab("show");
  10. $(selector).find("li:eq(" + index + ") a").tab("show");
  11. };
  12. Gogits.validateForm = function (selector, options) {
  13. var $form = $(selector);
  14. options = options || {};
  15. options.showErrors = function (map, list) {
  16. var $error = $form.find('.form-error').addClass('hidden');
  17. $('.has-error').removeClass("has-error");
  18. $error.text(list[0].message).show().removeClass("hidden");
  19. $(list[0].element).parents(".form-group").addClass("has-error");
  20. };
  21. $form.validate(options);
  22. };
  23. // ----- init elements
  24. Gogits.initModals = function () {
  25. var modals = $("[data-toggle=modal]");
  26. if (modals.length < 1) {
  27. return;
  28. }
  29. $.each(modals, function (i, item) {
  30. var hide = $(item).data('modal');
  31. $(item).modal(hide ? hide : "hide");
  32. });
  33. };
  34. Gogits.initTooltips = function () {
  35. $("body").tooltip({
  36. selector: "[data-toggle=tooltip]"
  37. //container: "body"
  38. });
  39. };
  40. Gogits.initTabs = function () {
  41. var $tabs = $('[data-init=tabs]');
  42. $tabs.find("li:eq(0) a").tab("show");
  43. }
  44. })(jQuery);
  45. // ajax utils
  46. (function ($) {
  47. Gogits.ajaxDelete = function (url, data, success) {
  48. data = data || {};
  49. data._method = "DELETE";
  50. $.ajax({
  51. url: url,
  52. data: data,
  53. method: "POST",
  54. dataType: "json",
  55. success: function (json) {
  56. if (success) {
  57. success(json);
  58. }
  59. }
  60. })
  61. }
  62. })(jQuery);
  63. function initCore() {
  64. Gogits.initTooltips();
  65. Gogits.initTabs();
  66. Gogits.initModals();
  67. }
  68. function initRegister() {
  69. $.getScript("/js/jquery.validate.min.js", function () {
  70. Gogits.validateForm("#gogs-login-card", {
  71. rules: {
  72. "username": {
  73. required: true,
  74. maxlength: 30
  75. },
  76. "email": {
  77. required: true,
  78. email: true
  79. },
  80. "passwd": {
  81. required: true,
  82. minlength: 6,
  83. maxlength: 30
  84. },
  85. "re-passwd": {
  86. required: true,
  87. equalTo: "input[name=passwd]"
  88. }
  89. }
  90. });
  91. });
  92. }
  93. function initUserSetting(){
  94. $('#gogs-ssh-keys').on("click",".delete",function(){
  95. var $this = $(this);
  96. Gogits.ajaxDelete("",{"id":$this.data("del")},function(json){
  97. if(json.ok){
  98. window.location.reload();
  99. }else{
  100. alert(json.err);
  101. }
  102. });
  103. return false;
  104. });
  105. }