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

app.js 3.6 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. // render markdown
  45. Gogits.renderMarkdown = function () {
  46. var $pre = $('.markdown').find('pre > code').parent();
  47. $pre.addClass("prettyprint");
  48. prettyPrint();
  49. }
  50. })(jQuery);
  51. // ajax utils
  52. (function ($) {
  53. Gogits.ajaxDelete = function (url, data, success) {
  54. data = data || {};
  55. data._method = "DELETE";
  56. $.ajax({
  57. url: url,
  58. data: data,
  59. method: "POST",
  60. dataType: "json",
  61. success: function (json) {
  62. if (success) {
  63. success(json);
  64. }
  65. }
  66. })
  67. }
  68. })(jQuery);
  69. function initCore() {
  70. Gogits.initTooltips();
  71. Gogits.initTabs();
  72. Gogits.initModals();
  73. Gogits.renderMarkdown();
  74. }
  75. function initRegister() {
  76. $.getScript("/js/jquery.validate.min.js", function () {
  77. Gogits.validateForm("#gogs-login-card", {
  78. rules: {
  79. "username": {
  80. required: true,
  81. maxlength: 30
  82. },
  83. "email": {
  84. required: true,
  85. email: true
  86. },
  87. "passwd": {
  88. required: true,
  89. minlength: 6,
  90. maxlength: 30
  91. },
  92. "re-passwd": {
  93. required: true,
  94. equalTo: "input[name=passwd]"
  95. }
  96. }
  97. });
  98. });
  99. }
  100. function initUserSetting() {
  101. $('#gogs-ssh-keys .delete').confirmation({
  102. singleton: true,
  103. onConfirm: function (e, $this) {
  104. Gogits.ajaxDelete("", {"id": $this.data("del")}, function (json) {
  105. if (json.ok) {
  106. window.location.reload();
  107. } else {
  108. alert(json.err);
  109. }
  110. });
  111. }
  112. });
  113. }
  114. (function ($) {
  115. $(function () {
  116. initCore();
  117. var body = $("#gogs-body");
  118. if (body.data("page") == "user-signup") {
  119. initRegister();
  120. }
  121. if (body.data("page") == "user") {
  122. initUserSetting();
  123. }
  124. });
  125. })(jQuery);