diff options
Diffstat (limited to 'public/js/gogs.js')
-rw-r--r-- | public/js/gogs.js | 158 |
1 files changed, 157 insertions, 1 deletions
diff --git a/public/js/gogs.js b/public/js/gogs.js index 4ac0013b..e9714926 100644 --- a/public/js/gogs.js +++ b/public/js/gogs.js @@ -2,6 +2,107 @@ var csrf; +function initCommentForm() { + if ($('.comment.form').length == 0) { + return + } + + var $form = $('.comment.form'); + $form.find('.tabular.menu .item').tab(); + $form.find('.tabular.menu .item[data-tab="preview"]').click(function () { + var $this = $(this); + $.post($this.data('url'), { + "_csrf": csrf, + "mode": "gfm", + "context": $this.data('context'), + "text": $form.find('.tab.segment[data-tab="write"] textarea').val() + }, + function (data) { + $form.find('.tab.segment[data-tab="preview"]').html(data); + } + ); + }); + + // Labels + var $list = $('.ui.labels.list'); + var $no_select = $list.find('.no-select'); + $('.select-label .menu .item:not(.no-select)').click(function () { + if ($(this).hasClass('checked')) { + $(this).removeClass('checked') + $(this).find('.octicon').removeClass('octicon-check') + } else { + $(this).addClass('checked') + $(this).find('.octicon').addClass('octicon-check') + } + + var label_ids = ""; + $(this).parent().find('.item').each(function () { + if ($(this).hasClass('checked')) { + label_ids += $(this).data('id') + ","; + $($(this).data('id-selector')).removeClass('hide'); + } else { + $($(this).data('id-selector')).addClass('hide'); + } + }); + if (label_ids.length == 0) { + $no_select.removeClass('hide'); + } else { + $no_select.addClass('hide'); + } + $($(this).parent().data('id')).val(label_ids); + return false; + }); + $('.select-label .menu .no-select.item').click(function () { + $(this).parent().find('.item').each(function () { + $(this).removeClass('checked'); + $(this).find('.octicon').removeClass('octicon-check'); + }); + + $list.find('.item').each(function () { + $(this).addClass('hide'); + }); + $no_select.removeClass('hide'); + $($(this).parent().data('id')).val(''); + }); + + function selectItem(select_id, input_id) { + var $menu = $(select_id + ' .menu'); + var $list = $('.ui' + select_id + '.list') + $menu.find('.item:not(.no-select)').click(function () { + $(this).parent().find('.item').each(function () { + $(this).removeClass('selected active') + }); + + $(this).addClass('selected active'); + switch (input_id) { + case '#milestone_id': + $list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' + + $(this).text() + '</a>'); + break; + case '#assignee_id': + $list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' + + '<img class="ui avatar image" src=' + $(this).data('avatar') + '>' + + $(this).text() + '</a>'); + } + $('.ui' + select_id + '.list .no-select').addClass('hide'); + $(input_id).val($(this).data('id')); + }); + $menu.find('.no-select.item').click(function () { + $(this).parent().find('.item:not(.no-select)').each(function () { + $(this).removeClass('selected active') + }); + + $list.find('.selected').html(''); + $list.find('.no-select').removeClass('hide'); + $(input_id).val(''); + }); + } + + // Milestone and assignee + selectItem('.select-milestone', '#milestone_id'); + selectItem('.select-assignee', '#assignee_id'); +} + function initInstall() { if ($('.install').length == 0) { return; @@ -101,6 +202,18 @@ function initRepository() { $('#add-deploy-key-panel').show(); }); } + + // Pull request + if ($('.repository.compare.pull').length > 0) { + var $branch_dropdown = $('.choose.branch .dropdown') + $branch_dropdown.dropdown({ + fullTextSearch: true, + onChange: function (text, value, $choice) { + window.location.href = $choice.data('url'); + }, + message: {noResults: $branch_dropdown.data('no-results')} + }); + } }; $(document).ready(function () { @@ -109,7 +222,10 @@ $(document).ready(function () { // Semantic UI modules. $('.dropdown').dropdown(); $('.jump.dropdown').dropdown({ - action: 'hide' + action: 'hide', + onShow: function () { + $('.poping.up').popup('hide'); + } }); $('.slide.up.dropdown').dropdown({ transition: 'slide up' @@ -120,6 +236,45 @@ $(document).ready(function () { showActivity: false }); $('.poping.up').popup(); + $('.top.menu .poping.up').popup({ + onShow: function () { + if ($('.top.menu .menu.transition').hasClass('visible')) { + return false; + } + } + }); + + // Dropzone + if ($('#dropzone').length > 0) { + // Disable auto discover for all elements: + Dropzone.autoDiscover = false; + + var filenameDict = {}; + var $dropz = $('#dropzone'); + $dropz.dropzone({ + url: $dropz.data('upload-url'), + headers: {"X-Csrf-Token": csrf}, + maxFiles: $dropz.data('max-file'), + maxFilesize: $dropz.data('max-size'), + acceptedFiles: $dropz.data('accepts'), + addRemoveLinks: true, + dictDefaultMessage: $dropz.data('default-message'), + dictInvalidFileType: $dropz.data('invalid-input-type'), + dictFileTooBig: $dropz.data('file-too-big'), + dictRemoveFile: $dropz.data('remove-file'), + init: function () { + this.on("success", function (file, data) { + filenameDict[file.name] = data.uuid; + $('.attachments').append('<input id="' + data.uuid + '" name="attachments" type="hidden" value="' + data.uuid + '">'); + }) + this.on("removedfile", function (file) { + if (file.name in filenameDict) { + $('#' + filenameDict[file.name]).remove(); + } + }) + } + }); + } // Helpers. $('.delete-button').click(function () { @@ -138,6 +293,7 @@ $(document).ready(function () { return false; }); + initCommentForm(); initInstall(); initRepository(); });
\ No newline at end of file |