1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-04 14:46:57 -05:00
gitea/public/js/min/gogs-min.js
2015-11-13 12:11:45 -05:00

1 line
12 KiB
JavaScript

"use strict";function initCommentPreviewTab(t){var e=t.find(".tabular.menu");e.find(".item").tab(),e.find('.item[data-tab="'+e.data("preview")+'"]').click(function(){var i=$(this);$.post(i.data("url"),{_csrf:csrf,mode:"gfm",context:i.data("context"),text:t.find('.tab.segment[data-tab="'+e.data("write")+'"] textarea').val()},function(i){var a=t.find('.tab.segment[data-tab="'+e.data("preview")+'"]');a.html(i),emojify.run(a[0])})}),buttonsClickOnEnter()}function initCommentForm(){function t(t,e,i){$.post(t,{_csrf:csrf,action:e,id:i})}function e(e,i){var a=$(e+" .menu"),n=$(".ui"+e+".list"),o="update"==a.data("action");a.find(".item:not(.no-select)").click(function(){switch($(this).parent().find(".item").each(function(){$(this).removeClass("selected active")}),$(this).addClass("selected active"),o&&t(a.data("update-url"),"",$(this).data("id")),i){case"#milestone_id":n.find(".selected").html('<a class="item" href='+$(this).data("href")+">"+$(this).text()+"</a>");break;case"#assignee_id":n.find(".selected").html('<a class="item" href='+$(this).data("href")+'><img class="ui avatar image" src='+$(this).data("avatar")+">"+$(this).text()+"</a>")}$(".ui"+e+".list .no-select").addClass("hide"),$(i).val($(this).data("id"))}),a.find(".no-select.item").click(function(){$(this).parent().find(".item:not(.no-select)").each(function(){$(this).removeClass("selected active")}),o&&t(a.data("update-url"),"",""),n.find(".selected").html(""),n.find(".no-select").removeClass("hide"),$(i).val("")})}if(0!=$(".comment.form").length){initCommentPreviewTab($(".comment.form"));var i=$(".ui.labels.list"),a=i.find(".no-select"),n=$(".select-label .menu"),o="update"==n.data("action");n.find(".item:not(.no-select)").click(function(){$(this).hasClass("checked")?($(this).removeClass("checked"),$(this).find(".octicon").removeClass("octicon-check"),o&&t(n.data("update-url"),"detach",$(this).data("id"))):($(this).addClass("checked"),$(this).find(".octicon").addClass("octicon-check"),o&&t(n.data("update-url"),"attach",$(this).data("id")));var e="";return $(this).parent().find(".item").each(function(){$(this).hasClass("checked")?(e+=$(this).data("id")+",",$($(this).data("id-selector")).removeClass("hide")):$($(this).data("id-selector")).addClass("hide")}),0==e.length?a.removeClass("hide"):a.addClass("hide"),$($(this).parent().data("id")).val(e),!1}),n.find(".no-select.item").click(function(){o&&t(n.data("update-url"),"clear",""),$(this).parent().find(".item").each(function(){$(this).removeClass("checked"),$(this).find(".octicon").removeClass("octicon-check")}),i.find(".item").each(function(){$(this).addClass("hide")}),a.removeClass("hide"),$($(this).parent().data("id")).val("")}),e(".select-milestone","#milestone_id"),e(".select-assignee","#assignee_id")}}function initInstall(){0!=$(".install").length&&($("#db_type").change(function(){var t="data/gogs.db",e="data/gogs_tidb",i=$(this).val();if("SQLite3"===i||"TiDB"===i)return $("#sql_settings").hide(),$("#pgsql_settings").hide(),$("#sqlite_settings").show(),void("SQLite3"===i&&$("#db_path").val()==e?$("#db_path").val(t):"TiDB"===i&&$("#db_path").val()==t&&$("#db_path").val(e));var a="127.0.0.1:3306",n="127.0.0.1:5432";$("#sqlite_settings").hide(),$("#sql_settings").show(),"PostgreSQL"===i?($("#pgsql_settings").show(),$("#db_host").val()==a&&$("#db_host").val(n)):($("#pgsql_settings").hide(),$("#db_host").val()==n&&$("#db_host").val(a))}),$("#offline-mode input").change(function(){$(this).is(":checked")&&$("#disable-gravatar").checkbox("check")}),$("#disable-registration input").change(function(){$(this).is(":checked")&&$("#enable-captcha").checkbox("uncheck")}),$("#enable-captcha input").change(function(){$(this).is(":checked")&&$("#disable-registration").checkbox("uncheck")}))}function initRepository(){if(0!=$(".repository").length){if($(".repository.settings.options").length>0&&$("#repo_name").keyup(function(){var t=$("#repo-name-change-prompt");$(this).val().toString().toLowerCase()!=$(this).data("repo-name").toString().toLowerCase()?t.show():t.hide()}),$(".repository.labels").length>0){var t=$(".new-label.segment");$(".new-label.button").click(function(){t.show()}),$(".new-label.segment .cancel").click(function(){t.hide()}),$(".color-picker").each(function(){$(this).minicolors()}),$(".precolors .color").click(function(){var t=$(this).data("color-hex");$(".color-picker").val(t),$(".minicolors-swatch-color").css("background-color",t)}),$(".edit-label-button").click(function(){return $("#label-modal-id").val($(this).data("id")),$(".edit-label .new-label-input").val($(this).data("title")),$(".edit-label .color-picker").val($(this).data("color")),$(".minicolors-swatch-color").css("background-color",$(this).data("color")),$(".edit-label.modal").modal({onApprove:function(){$(".edit-label.form").submit()}}).modal("show"),!1})}if($(".repository.milestones").length>0,$(".repository.new.milestone").length>0){var e=$(".milestone.datepicker");e.datetimepicker({lang:e.data("lang"),inline:!0,timepicker:!1,startDate:e.data("start-date"),formatDate:"Y-m-d",onSelectDate:function(t){$("#deadline").val(t.dateFormat("Y-m-d"))}}),$("#clear-date").click(function(){return $("#deadline").val(""),!1})}if($(".repository.view.issue").length>0){var i=$("#issue-title"),a=$("#edit-title-input input"),n=function(){return i.toggle(),$(".not-in-edit").toggle(),$("#edit-title-input").toggle(),$(".in-edit").toggle(),a.focus(),!1};$("#edit-title").click(n),$("#cancel-edit-title").click(n),$("#save-edit-title").click(n).click(function(){return 0==a.val().length||a.val()==i.text()?(a.val(i.text()),!1):($.post($(this).data("update-url"),{_csrf:csrf,title:a.val()},function(t){a.val(t.title),i.text(t.title)}),!1)}),$(".edit-content").click(function(){var t=$(this).parent().parent().next(),e=t.find(".edit-content-zone"),i=t.find(".render-content"),a=t.find(".raw-content"),n;if(0==e.html().length){e.html($("#edit-content-form").html()),n=t.find("textarea");var o=e.find(".ui.comment.form"),s=o.find(".tabular.menu");s.attr("data-write",e.data("write")),s.attr("data-preview",e.data("preview")),s.find(".write.item").attr("data-tab",e.data("write")),s.find(".preview.item").attr("data-tab",e.data("preview")),o.find(".write.segment").attr("data-tab",e.data("write")),o.find(".preview.segment").attr("data-tab",e.data("preview")),initCommentPreviewTab(o),e.find(".cancel.button").click(function(){i.show(),e.hide()}),e.find(".save.button").click(function(){i.show(),e.hide(),$.post(e.data("update-url"),{_csrf:csrf,content:n.val(),context:e.data("context")},function(t){0==t.length?i.html($("#no-content").html()):(i.html(t.content),emojify.run(i[0]))})})}else n=t.find("textarea");return e.show(),i.hide(),0==n.val().length&&n.val(a.text()),n.focus(),!1});var o=$("#status-button");$("#content").keyup(function(){0==$(this).val().length?o.text(o.data("status")):o.text(o.data("status-and-comment"))}),o.click(function(){$("#status").val(o.data("status-val")),$("#comment-form").submit()})}if($(".repository.diff").length>0){var s=$(".diff-counter");s.length>=1&&s.each(function(t,e){var i=$(e),a=i.find("span[data-line].add").data("line"),n=i.find("span[data-line].del").data("line"),o=parseFloat(a)/(parseFloat(a)+parseFloat(n))*100;i.find(".bar .add").css("width",o+"%")})}if($(".repository.quickstart").length>0&&($("#repo-clone-ssh").click(function(){$(".clone-url").text($(this).data("link")),$("#repo-clone-url").val($(this).data("link")),$(this).addClass("blue"),$("#repo-clone-https").removeClass("blue")}),$("#repo-clone-https").click(function(){$(".clone-url").text($(this).data("link")),$("#repo-clone-url").val($(this).data("link")),$(this).addClass("blue"),$("#repo-clone-ssh").removeClass("blue")})),$(".repository.compare.pull").length>0){var r=$(".choose.branch .dropdown");r.dropdown({fullTextSearch:!0,onChange:function(t,e,i){window.location.href=i.data("url"),console.log(i.data("url"))},message:{noResults:r.data("no-results")}})}}}function initOrganization(){0!=$(".organization").length&&$(".organization.settings.options").length>0&&$("#org_name").keyup(function(){var t=$("#org-name-change-prompt");$(this).val().toString().toLowerCase()!=$(this).data("org-name").toString().toLowerCase()?t.show():t.hide()})}function initUser(){0!=$(".user").length&&$(".user.settings.profile").length>0&&$("#username").keyup(function(){var t=$("#name-change-prompt");$(this).val().toString().toLowerCase()!=$(this).data("name").toString().toLowerCase()?t.show():t.hide()})}function initWebhook(){0!=$(".new.webhook").length&&($(".events.checkbox input").change(function(){$(this).is(":checked")&&$(".events.fields").show()}),$(".non-events.checkbox input").change(function(){$(this).is(":checked")&&$(".events.fields").hide()}))}function initAdmin(){0!=$(".admin").length&&(($(".admin.new.user").length>0||$(".admin.edit.user").length>0)&&$("#login_type").change(function(){"0"==$(this).val().substring(0,1)?($("#login_name").removeAttr("required"),$(".non-local").hide(),$(".local").show(),$("#user_name").focus(),"required"==$(this).data("password")&&$("#password").attr("required","required")):($("#login_name").attr("required","required"),$(".non-local").show(),$(".local").hide(),$("#login_name").focus(),$("#password").removeAttr("required"))}),$(".admin.new.authentication").length>0&&$("#auth_type").change(function(){$(".ldap").hide(),$(".dldap").hide(),$(".smtp").hide(),$(".pam").hide();var t=$(this).val();switch(t){case"2":$(".ldap").show();break;case"3":$(".smtp").show();break;case"4":$(".pam").show();break;case"5":$(".dldap").show()}}))}function buttonsClickOnEnter(){$(".ui.button").keypress(function(t){(13==t.keyCode||32==t.keyCode)&&$(this).click()})}var csrf,suburl;$(document).ready(function(){if(csrf=$("meta[name=_csrf]").attr("content"),suburl=$("meta[name=_suburl]").attr("content"),$(".time-since").each(function(){$(this).addClass("poping up").attr("data-content",$(this).attr("title")).attr("data-variation","inverted tiny").attr("title","")}),$(".dropdown").dropdown(),$(".jump.dropdown").dropdown({action:"hide",onShow:function(){$(".poping.up").popup("hide")}}),$(".slide.up.dropdown").dropdown({transition:"slide up"}),$(".ui.accordion").accordion(),$(".ui.checkbox").checkbox(),$(".ui.progress").progress({showActivity:!1}),$(".poping.up").popup(),$(".top.menu .poping.up").popup({onShow:function(){return $(".top.menu .menu.transition").hasClass("visible")?!1:void 0}}),$(".tabular.menu .item").tab(),$(".tabable.menu .item").tab(),$(".toggle.button").click(function(){$($(this).data("target")).slideToggle(100)}),"undefined"!=typeof hljs&&hljs.initHighlightingOnLoad(),$("#dropzone").length>0){Dropzone.autoDiscover=!1;var t={},e=$("#dropzone");e.dropzone({url:e.data("upload-url"),headers:{"X-Csrf-Token":csrf},maxFiles:e.data("max-file"),maxFilesize:e.data("max-size"),acceptedFiles:e.data("accepts"),addRemoveLinks:!0,dictDefaultMessage:e.data("default-message"),dictInvalidFileType:e.data("invalid-input-type"),dictFileTooBig:e.data("file-too-big"),dictRemoveFile:e.data("remove-file"),init:function(){this.on("success",function(e,i){t[e.name]=i.uuid,$(".attachments").append('<input id="'+i.uuid+'" name="attachments" type="hidden" value="'+i.uuid+'">')}),this.on("removedfile",function(e){e.name in t&&$("#"+t[e.name]).remove()})}})}emojify.setConfig({img_dir:suburl+"/img/emoji"}),emojify.run();var i=new Clipboard(".clipboard");i.on("success",function(t){t.clearSelection(),$("#"+t.trigger.getAttribute("id")).popup("destroy"),t.trigger.setAttribute("data-content",t.trigger.getAttribute("data-success")),$("#"+t.trigger.getAttribute("id")).popup("show"),t.trigger.setAttribute("data-content",t.trigger.getAttribute("data-original"))}),i.on("error",function(t){$("#"+t.trigger.getAttribute("id")).popup("destroy"),t.trigger.setAttribute("data-content",t.trigger.getAttribute("data-error")),$("#"+t.trigger.getAttribute("id")).popup("show"),t.trigger.setAttribute("data-content",t.trigger.getAttribute("data-original"))}),$(".delete-button").click(function(){var t=$(this);return $(".delete.modal").modal({closable:!1,onApprove:function(){return"form"==t.data("type")?void $(t.data("form")).submit():void $.post(t.data("url"),{_csrf:csrf,id:t.data("id")}).done(function(t){window.location.href=t.redirect})}}).modal("show"),!1}),$(".show-panel.button").click(function(){$($(this).data("panel")).show()}),$(".show-modal.button").click(function(){$($(this).data("modal")).modal("show")}),buttonsClickOnEnter(),initCommentForm(),initInstall(),initRepository(),initOrganization(),initUser(),initWebhook(),initAdmin()});