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-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 .delete').confirmation({
  95. singleton: true,
  96. onConfirm: function(e, $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. }
  105. });
  106. }