app.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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-toggle=tab]');
  42. $tabs.tab("show");
  43. $tabs.find("li:eq(" + index + ") a").tab("show");
  44. }
  45. })(jQuery);
  46. // ajax utils
  47. (function ($) {
  48. Gogits.ajaxDelete = function (url, data, success) {
  49. data = data || {};
  50. data._method = "DELETE";
  51. $.ajax({
  52. url: url,
  53. data: data,
  54. method: "POST",
  55. dataType: "json",
  56. success: function (json) {
  57. if (success) {
  58. success(json);
  59. }
  60. }
  61. })
  62. }
  63. })(jQuery);
  64. function initCore() {
  65. Gogits.initTooltips();
  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. minlength: 5,
  75. maxlength: 30
  76. },
  77. "email": {
  78. required: true,
  79. email: true
  80. },
  81. "passwd": {
  82. required: true,
  83. minlength: 6,
  84. maxlength: 30
  85. },
  86. "re-passwd": {
  87. required: true,
  88. equalTo: "input[name=passwd]"
  89. }
  90. }
  91. });
  92. });
  93. }
  94. function initUserSetting(){
  95. $('#gogs-ssh-keys').on("click",".delete",function(){
  96. var $this = $(this);
  97. Gogits.ajaxDelete("",{"id":$this.data("del")},function(json){
  98. if(json.ok){
  99. window.location.reload();
  100. }else{
  101. alert(json.err);
  102. }
  103. });
  104. return false;
  105. });
  106. }