diff options
Diffstat (limited to 'public/js/gogs.js')
-rw-r--r-- | public/js/gogs.js | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/public/js/gogs.js b/public/js/gogs.js index dbe791d8..cd804796 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 () { @@ -131,6 +244,7 @@ $(document).ready(function () { } }); + // Helpers. $('.delete-button').click(function () { var $this = $(this); @@ -148,6 +262,7 @@ $(document).ready(function () { return false; }); + initCommentForm(); initInstall(); initRepository(); });
\ No newline at end of file |