2022-01-29 00:00:11 +03:00
import $ from 'jquery' ;
2022-01-05 15:17:25 +03:00
import { createCommentEasyMDE , getAttachedEasyMDE } from './comp/EasyMDE.js' ;
2021-10-16 20:28:04 +03:00
import { initCompMarkupContentPreviewTab } from './comp/MarkupContentPreview.js' ;
2022-06-28 20:52:58 +03:00
import { initEasyMDEImagePaste } from './comp/ImagePaste.js' ;
2021-10-16 20:28:04 +03:00
import {
initRepoIssueBranchSelect , initRepoIssueCodeCommentCancel ,
initRepoIssueCommentDelete ,
initRepoIssueComments , initRepoIssueDependencyDelete ,
initRepoIssueReferenceIssue , initRepoIssueStatusButton ,
initRepoIssueTitleEdit ,
2022-05-12 16:39:02 +03:00
initRepoIssueWipToggle , initRepoPullRequestUpdate ,
2021-10-16 20:28:04 +03:00
updateIssuesMeta ,
} from './repo-issue.js' ;
2022-01-07 04:18:52 +03:00
import { initUnicodeEscapeButton } from './repo-unicode-escape.js' ;
2021-10-16 20:28:04 +03:00
import { svg } from '../svg.js' ;
import { htmlEscape } from 'escape-goat' ;
import { initRepoBranchTagDropdown } from '../components/RepoBranchTagDropdown.js' ;
import {
2022-03-29 06:21:30 +03:00
initRepoCloneLink ,
2021-10-16 20:28:04 +03:00
initRepoCommonBranchOrTagDropdown ,
initRepoCommonFilterSearchDropdown ,
initRepoCommonLanguageStats ,
} from './repo-common.js' ;
2022-11-11 20:02:50 +03:00
import { initCitationFileCopyContent } from './citation.js' ;
2021-10-16 20:28:04 +03:00
import { initCompLabelEdit } from './comp/LabelEdit.js' ;
import { initRepoDiffConversationNav } from './repo-diff.js' ;
import attachTribute from './tribute.js' ;
import createDropzone from './dropzone.js' ;
import { initCommentContent , initMarkupContent } from '../markup/content.js' ;
import { initCompReactionSelector } from './comp/ReactionSelector.js' ;
import { initRepoSettingBranches } from './repo-settings.js' ;
2022-05-12 16:39:02 +03:00
import initRepoPullRequestMergeForm from './repo-issue-pr-form.js' ;
2021-10-16 20:28:04 +03:00
2021-10-21 10:37:43 +03:00
const { csrfToken } = window . config ;
2021-10-16 20:28:04 +03:00
export function initRepoCommentForm ( ) {
2022-06-28 20:52:58 +03:00
const $commentForm = $ ( '.comment.form' ) ;
if ( $commentForm . length === 0 ) {
2021-10-16 20:28:04 +03:00
return ;
}
function initBranchSelector ( ) {
const $selectBranch = $ ( '.ui.select-branch' ) ;
const $branchMenu = $selectBranch . find ( '.reference-list-menu' ) ;
const $isNewIssue = $branchMenu . hasClass ( 'new-issue' ) ;
$branchMenu . find ( '.item:not(.no-select)' ) . click ( function ( ) {
const selectedValue = $ ( this ) . data ( 'id' ) ;
const editMode = $ ( '#editing_mode' ) . val ( ) ;
2022-01-16 14:19:26 +03:00
$ ( $ ( this ) . data ( 'id-selector' ) ) . val ( selectedValue ) ;
2021-10-16 20:28:04 +03:00
if ( $isNewIssue ) {
$selectBranch . find ( '.ui .branch-name' ) . text ( $ ( this ) . data ( 'name' ) ) ;
return ;
}
if ( editMode === 'true' ) {
const form = $ ( '#update_issueref_form' ) ;
2021-10-21 10:37:43 +03:00
$ . post ( form . attr ( 'action' ) , { _csrf : csrfToken , ref : selectedValue } , ( ) => window . location . reload ( ) ) ;
2021-10-16 20:28:04 +03:00
} else if ( editMode === '' ) {
$selectBranch . find ( '.ui .branch-name' ) . text ( selectedValue ) ;
}
} ) ;
$selectBranch . find ( '.reference.column' ) . on ( 'click' , function ( ) {
$selectBranch . find ( '.scrolling.reference-list-menu' ) . css ( 'display' , 'none' ) ;
$selectBranch . find ( '.reference .text' ) . removeClass ( 'black' ) ;
2022-01-16 14:19:26 +03:00
$ ( $ ( this ) . data ( 'target' ) ) . css ( 'display' , 'block' ) ;
2021-10-16 20:28:04 +03:00
$ ( this ) . find ( '.text' ) . addClass ( 'black' ) ;
return false ;
} ) ;
}
2022-01-08 16:33:32 +03:00
( async ( ) => {
2022-09-02 10:58:49 +03:00
for ( const textarea of $commentForm . find ( 'textarea:not(.review-textarea, .no-easymde)' ) ) {
// Don't initialize EasyMDE for the dormant #edit-content-form
if ( textarea . closest ( '#edit-content-form' ) ) {
continue ;
}
const easyMDE = await createCommentEasyMDE ( textarea ) ;
initEasyMDEImagePaste ( easyMDE , $commentForm . find ( '.dropzone' ) ) ;
}
2022-01-08 16:33:32 +03:00
} ) ( ) ;
2021-10-16 20:28:04 +03:00
initBranchSelector ( ) ;
2022-06-28 20:52:58 +03:00
initCompMarkupContentPreviewTab ( $commentForm ) ;
2021-10-16 20:28:04 +03:00
2021-11-18 19:45:00 +03:00
// List submits
2021-10-16 20:28:04 +03:00
function initListSubmits ( selector , outerSelector ) {
const $list = $ ( ` .ui. ${ outerSelector } .list ` ) ;
const $noSelect = $list . find ( '.no-select' ) ;
const $listMenu = $ ( ` . ${ selector } .menu ` ) ;
let hasUpdateAction = $listMenu . data ( 'action' ) === 'update' ;
const items = { } ;
$ ( ` . ${ selector } ` ) . dropdown ( 'setting' , 'onHide' , ( ) => {
hasUpdateAction = $listMenu . data ( 'action' ) === 'update' ; // Update the var
if ( hasUpdateAction ) {
2021-11-16 05:21:13 +03:00
// TODO: Add batch functionality and make this 1 network request.
( async function ( ) {
for ( const [ elementId , item ] of Object . entries ( items ) ) {
await updateIssuesMeta (
item [ 'update-url' ] ,
item . action ,
item [ 'issue-id' ] ,
elementId ,
) ;
}
window . location . reload ( ) ;
} ) ( ) ;
2021-10-16 20:28:04 +03:00
}
} ) ;
$listMenu . find ( '.item:not(.no-select)' ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
if ( $ ( this ) . hasClass ( 'ban-change' ) ) {
return false ;
}
hasUpdateAction = $listMenu . data ( 'action' ) === 'update' ; // Update the var
if ( $ ( this ) . hasClass ( 'checked' ) ) {
$ ( this ) . removeClass ( 'checked' ) ;
$ ( this ) . find ( '.octicon-check' ) . addClass ( 'invisible' ) ;
if ( hasUpdateAction ) {
if ( ! ( $ ( this ) . data ( 'id' ) in items ) ) {
items [ $ ( this ) . data ( 'id' ) ] = {
'update-url' : $listMenu . data ( 'update-url' ) ,
action : 'detach' ,
'issue-id' : $listMenu . data ( 'issue-id' ) ,
} ;
} else {
delete items [ $ ( this ) . data ( 'id' ) ] ;
}
}
} else {
$ ( this ) . addClass ( 'checked' ) ;
$ ( this ) . find ( '.octicon-check' ) . removeClass ( 'invisible' ) ;
if ( hasUpdateAction ) {
if ( ! ( $ ( this ) . data ( 'id' ) in items ) ) {
items [ $ ( this ) . data ( 'id' ) ] = {
'update-url' : $listMenu . data ( 'update-url' ) ,
action : 'attach' ,
'issue-id' : $listMenu . data ( 'issue-id' ) ,
} ;
} else {
delete items [ $ ( this ) . data ( 'id' ) ] ;
}
}
}
// TODO: Which thing should be done for choosing review requests
// to make chosen items be shown on time here?
if ( selector === 'select-reviewers-modify' || selector === 'select-assignees-modify' ) {
return false ;
}
const listIds = [ ] ;
$ ( this ) . parent ( ) . find ( '.item' ) . each ( function ( ) {
if ( $ ( this ) . hasClass ( 'checked' ) ) {
listIds . push ( $ ( this ) . data ( 'id' ) ) ;
2022-01-16 14:19:26 +03:00
$ ( $ ( this ) . data ( 'id-selector' ) ) . removeClass ( 'hide' ) ;
2021-10-16 20:28:04 +03:00
} else {
2022-01-16 14:19:26 +03:00
$ ( $ ( this ) . data ( 'id-selector' ) ) . addClass ( 'hide' ) ;
2021-10-16 20:28:04 +03:00
}
} ) ;
if ( listIds . length === 0 ) {
$noSelect . removeClass ( 'hide' ) ;
} else {
$noSelect . addClass ( 'hide' ) ;
}
2022-01-16 14:19:26 +03:00
$ ( $ ( this ) . parent ( ) . data ( 'id' ) ) . val ( listIds . join ( ',' ) ) ;
2021-10-16 20:28:04 +03:00
return false ;
} ) ;
$listMenu . find ( '.no-select.item' ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
if ( hasUpdateAction ) {
updateIssuesMeta (
$listMenu . data ( 'update-url' ) ,
'clear' ,
$listMenu . data ( 'issue-id' ) ,
'' ,
2021-12-04 09:43:14 +03:00
) . then ( ( ) => window . location . reload ( ) ) ;
2021-10-16 20:28:04 +03:00
}
$ ( this ) . parent ( ) . find ( '.item' ) . each ( function ( ) {
$ ( this ) . removeClass ( 'checked' ) ;
$ ( this ) . find ( '.octicon' ) . addClass ( 'invisible' ) ;
} ) ;
if ( selector === 'select-reviewers-modify' || selector === 'select-assignees-modify' ) {
return false ;
}
$list . find ( '.item' ) . each ( function ( ) {
$ ( this ) . addClass ( 'hide' ) ;
} ) ;
$noSelect . removeClass ( 'hide' ) ;
2022-01-16 14:19:26 +03:00
$ ( $ ( this ) . parent ( ) . data ( 'id' ) ) . val ( '' ) ;
2021-10-16 20:28:04 +03:00
} ) ;
}
// Init labels and assignees
initListSubmits ( 'select-label' , 'labels' ) ;
initListSubmits ( 'select-assignees' , 'assignees' ) ;
initListSubmits ( 'select-assignees-modify' , 'assignees' ) ;
initListSubmits ( 'select-reviewers-modify' , 'assignees' ) ;
function selectItem ( select _id , input _id ) {
const $menu = $ ( ` ${ select _id } .menu ` ) ;
const $list = $ ( ` .ui ${ select _id } .list ` ) ;
const hasUpdateAction = $menu . data ( 'action' ) === 'update' ;
$menu . find ( '.item:not(.no-select)' ) . on ( 'click' , function ( ) {
$ ( this ) . parent ( ) . find ( '.item' ) . each ( function ( ) {
$ ( this ) . removeClass ( 'selected active' ) ;
} ) ;
$ ( this ) . addClass ( 'selected active' ) ;
if ( hasUpdateAction ) {
updateIssuesMeta (
$menu . data ( 'update-url' ) ,
'' ,
$menu . data ( 'issue-id' ) ,
$ ( this ) . data ( 'id' ) ,
2021-12-04 09:43:14 +03:00
) . then ( ( ) => window . location . reload ( ) ) ;
2021-10-16 20:28:04 +03:00
}
let icon = '' ;
if ( input _id === '#milestone_id' ) {
icon = svg ( 'octicon-milestone' , 18 , 'mr-3' ) ;
} else if ( input _id === '#project_id' ) {
icon = svg ( 'octicon-project' , 18 , 'mr-3' ) ;
} else if ( input _id === '#assignee_id' ) {
icon = ` <img class="ui avatar image mr-3" src= ${ $ ( this ) . data ( 'avatar' ) } > ` ;
}
$list . find ( '.selected' ) . html ( `
< a class = "item muted sidebar-item-link" href = $ { $ ( this ) . data ( 'href' ) } >
$ { icon }
$ { htmlEscape ( $ ( this ) . text ( ) ) }
< / a >
` );
$ ( ` .ui ${ select _id } .list .no-select ` ) . addClass ( 'hide' ) ;
$ ( input _id ) . val ( $ ( this ) . data ( 'id' ) ) ;
} ) ;
$menu . find ( '.no-select.item' ) . on ( 'click' , function ( ) {
$ ( this ) . parent ( ) . find ( '.item:not(.no-select)' ) . each ( function ( ) {
$ ( this ) . removeClass ( 'selected active' ) ;
} ) ;
if ( hasUpdateAction ) {
updateIssuesMeta (
$menu . data ( 'update-url' ) ,
'' ,
$menu . data ( 'issue-id' ) ,
$ ( this ) . data ( 'id' ) ,
2021-12-04 09:43:14 +03:00
) . then ( ( ) => window . location . reload ( ) ) ;
2021-10-16 20:28:04 +03:00
}
$list . find ( '.selected' ) . html ( '' ) ;
$list . find ( '.no-select' ) . removeClass ( 'hide' ) ;
2022-01-16 14:19:26 +03:00
$ ( input _id ) . val ( '' ) ;
2021-10-16 20:28:04 +03:00
} ) ;
}
// Milestone, Assignee, Project
selectItem ( '.select-project' , '#project_id' ) ;
selectItem ( '.select-milestone' , '#milestone_id' ) ;
selectItem ( '.select-assignee' , '#assignee_id' ) ;
}
2021-11-18 19:45:00 +03:00
async function onEditContent ( event ) {
event . preventDefault ( ) ;
2022-01-05 15:17:25 +03:00
2021-11-18 19:45:00 +03:00
$ ( this ) . closest ( '.dropdown' ) . find ( '.menu' ) . toggle ( 'visible' ) ;
const $segment = $ ( this ) . closest ( '.header' ) . next ( ) ;
const $editContentZone = $segment . find ( '.edit-content-zone' ) ;
const $renderContent = $segment . find ( '.render-content' ) ;
const $rawContent = $segment . find ( '.raw-content' ) ;
let $textarea ;
2021-12-10 05:51:27 +03:00
let easyMDE ;
2021-11-18 19:45:00 +03:00
// Setup new form
if ( $editContentZone . html ( ) . length === 0 ) {
$editContentZone . html ( $ ( '#edit-content-form' ) . html ( ) ) ;
$textarea = $editContentZone . find ( 'textarea' ) ;
await attachTribute ( $textarea . get ( ) , { mentions : true , emoji : true } ) ;
let dz ;
const $dropzone = $editContentZone . find ( '.dropzone' ) ;
if ( $dropzone . length === 1 ) {
$dropzone . data ( 'saved' , false ) ;
const fileUuidDict = { } ;
dz = await createDropzone ( $dropzone [ 0 ] , {
url : $dropzone . data ( 'upload-url' ) ,
headers : { 'X-Csrf-Token' : csrfToken } ,
maxFiles : $dropzone . data ( 'max-file' ) ,
maxFilesize : $dropzone . data ( 'max-size' ) ,
acceptedFiles : ( [ '*/*' , '' ] . includes ( $dropzone . data ( 'accepts' ) ) ) ? null : $dropzone . data ( 'accepts' ) ,
addRemoveLinks : true ,
dictDefaultMessage : $dropzone . data ( 'default-message' ) ,
dictInvalidFileType : $dropzone . data ( 'invalid-input-type' ) ,
dictFileTooBig : $dropzone . data ( 'file-too-big' ) ,
dictRemoveFile : $dropzone . data ( 'remove-file' ) ,
timeout : 0 ,
thumbnailMethod : 'contain' ,
thumbnailWidth : 480 ,
thumbnailHeight : 480 ,
init ( ) {
this . on ( 'success' , ( file , data ) => {
2022-06-25 22:49:56 +03:00
file . uuid = data . uuid ;
2021-11-18 19:45:00 +03:00
fileUuidDict [ file . uuid ] = { submitted : false } ;
const input = $ ( ` <input id=" ${ data . uuid } " name="files" type="hidden"> ` ) . val ( data . uuid ) ;
$dropzone . find ( '.files' ) . append ( input ) ;
} ) ;
this . on ( 'removedfile' , ( file ) => {
$ ( ` # ${ file . uuid } ` ) . remove ( ) ;
if ( $dropzone . data ( 'remove-url' ) && ! fileUuidDict [ file . uuid ] . submitted ) {
$ . post ( $dropzone . data ( 'remove-url' ) , {
file : file . uuid ,
_csrf : csrfToken ,
} ) ;
}
} ) ;
this . on ( 'submit' , ( ) => {
$ . each ( fileUuidDict , ( fileUuid ) => {
fileUuidDict [ fileUuid ] . submitted = true ;
} ) ;
} ) ;
this . on ( 'reload' , ( ) => {
$ . getJSON ( $editContentZone . data ( 'attachment-url' ) , ( data ) => {
dz . removeAllFiles ( true ) ;
$dropzone . find ( '.files' ) . empty ( ) ;
$ . each ( data , function ( ) {
const imgSrc = ` ${ $dropzone . data ( 'link-url' ) } / ${ this . uuid } ` ;
dz . emit ( 'addedfile' , this ) ;
dz . emit ( 'thumbnail' , this , imgSrc ) ;
dz . emit ( 'complete' , this ) ;
dz . files . push ( this ) ;
fileUuidDict [ this . uuid ] = { submitted : true } ;
$dropzone . find ( ` img[src=' ${ imgSrc } '] ` ) . css ( 'max-width' , '100%' ) ;
const input = $ ( ` <input id=" ${ this . uuid } " name="files" type="hidden"> ` ) . val ( this . uuid ) ;
$dropzone . find ( '.files' ) . append ( input ) ;
} ) ;
} ) ;
} ) ;
} ,
} ) ;
dz . emit ( 'reload' ) ;
}
// Give new write/preview data-tab name to distinguish from others
const $editContentForm = $editContentZone . find ( '.ui.comment.form' ) ;
const $tabMenu = $editContentForm . find ( '.tabular.menu' ) ;
$tabMenu . attr ( 'data-write' , $editContentZone . data ( 'write' ) ) ;
$tabMenu . attr ( 'data-preview' , $editContentZone . data ( 'preview' ) ) ;
$tabMenu . find ( '.write.item' ) . attr ( 'data-tab' , $editContentZone . data ( 'write' ) ) ;
$tabMenu . find ( '.preview.item' ) . attr ( 'data-tab' , $editContentZone . data ( 'preview' ) ) ;
$editContentForm . find ( '.write' ) . attr ( 'data-tab' , $editContentZone . data ( 'write' ) ) ;
$editContentForm . find ( '.preview' ) . attr ( 'data-tab' , $editContentZone . data ( 'preview' ) ) ;
2022-01-05 15:17:25 +03:00
easyMDE = await createCommentEasyMDE ( $textarea ) ;
2021-11-18 19:45:00 +03:00
initCompMarkupContentPreviewTab ( $editContentForm ) ;
2022-06-28 20:52:58 +03:00
initEasyMDEImagePaste ( easyMDE , $dropzone ) ;
2021-11-18 19:45:00 +03:00
2022-05-20 05:26:04 +03:00
const $saveButton = $editContentZone . find ( '.save.button' ) ;
$textarea . on ( 'ce-quick-submit' , ( ) => {
$saveButton . trigger ( 'click' ) ;
} ) ;
2021-11-18 19:45:00 +03:00
$editContentZone . find ( '.cancel.button' ) . on ( 'click' , ( ) => {
$renderContent . show ( ) ;
$editContentZone . hide ( ) ;
if ( dz ) {
dz . emit ( 'reload' ) ;
}
} ) ;
2022-05-20 05:26:04 +03:00
$saveButton . on ( 'click' , ( ) => {
2021-11-18 19:45:00 +03:00
$renderContent . show ( ) ;
$editContentZone . hide ( ) ;
const $attachments = $dropzone . find ( '.files' ) . find ( '[name=files]' ) . map ( function ( ) {
return $ ( this ) . val ( ) ;
} ) . get ( ) ;
$ . post ( $editContentZone . data ( 'update-url' ) , {
_csrf : csrfToken ,
content : $textarea . val ( ) ,
context : $editContentZone . data ( 'context' ) ,
files : $attachments ,
} , ( data ) => {
if ( data . length === 0 || data . content . length === 0 ) {
$renderContent . html ( $ ( '#no-content' ) . html ( ) ) ;
$rawContent . text ( '' ) ;
} else {
$renderContent . html ( data . content ) ;
$rawContent . text ( $textarea . val ( ) ) ;
}
const $content = $segment ;
if ( ! $content . find ( '.dropzone-attachments' ) . length ) {
if ( data . attachments !== '' ) {
$content . append ( ` <div class="dropzone-attachments"></div> ` ) ;
$content . find ( '.dropzone-attachments' ) . replaceWith ( data . attachments ) ;
}
} else if ( data . attachments === '' ) {
$content . find ( '.dropzone-attachments' ) . remove ( ) ;
} else {
$content . find ( '.dropzone-attachments' ) . replaceWith ( data . attachments ) ;
}
if ( dz ) {
dz . emit ( 'submit' ) ;
dz . emit ( 'reload' ) ;
}
initMarkupContent ( ) ;
initCommentContent ( ) ;
} ) ;
} ) ;
2022-05-20 05:26:04 +03:00
} else { // use existing form
2021-11-18 19:45:00 +03:00
$textarea = $segment . find ( 'textarea' ) ;
2021-12-10 05:51:27 +03:00
easyMDE = getAttachedEasyMDE ( $textarea ) ;
2021-11-18 19:45:00 +03:00
}
// Show write/preview tab and copy raw content as needed
$editContentZone . show ( ) ;
$renderContent . hide ( ) ;
if ( $textarea . val ( ) . length === 0 ) {
$textarea . val ( $rawContent . text ( ) ) ;
2021-12-10 05:51:27 +03:00
easyMDE . value ( $rawContent . text ( ) ) ;
2021-11-18 19:45:00 +03:00
}
requestAnimationFrame ( ( ) => {
$textarea . focus ( ) ;
2021-12-10 05:51:27 +03:00
easyMDE . codemirror . focus ( ) ;
2021-11-18 19:45:00 +03:00
} ) ;
}
2021-11-09 12:27:25 +03:00
export function initRepository ( ) {
2021-10-16 20:28:04 +03:00
if ( $ ( '.repository' ) . length === 0 ) {
return ;
}
// File list and commits
2022-02-09 23:28:55 +03:00
if ( $ ( '.repository.file.list' ) . length > 0 || $ ( '.branch-dropdown' ) . length > 0 ||
2021-10-16 20:28:04 +03:00
$ ( '.repository.commits' ) . length > 0 || $ ( '.repository.release' ) . length > 0 ) {
initRepoBranchTagDropdown ( '.choose.reference .dropdown' ) ;
}
// Wiki
if ( $ ( '.repository.wiki.view' ) . length > 0 ) {
initRepoCommonFilterSearchDropdown ( '.choose.page .dropdown' ) ;
}
// Options
if ( $ ( '.repository.settings.options' ) . length > 0 ) {
// Enable or select internal/external wiki system and issue tracker.
$ ( '.enable-system' ) . on ( 'change' , function ( ) {
if ( this . checked ) {
2022-01-16 14:19:26 +03:00
$ ( $ ( this ) . data ( 'target' ) ) . removeClass ( 'disabled' ) ;
if ( ! $ ( this ) . data ( 'context' ) ) $ ( $ ( this ) . data ( 'context' ) ) . addClass ( 'disabled' ) ;
2021-10-16 20:28:04 +03:00
} else {
2022-01-16 14:19:26 +03:00
$ ( $ ( this ) . data ( 'target' ) ) . addClass ( 'disabled' ) ;
if ( ! $ ( this ) . data ( 'context' ) ) $ ( $ ( this ) . data ( 'context' ) ) . removeClass ( 'disabled' ) ;
2021-10-16 20:28:04 +03:00
}
} ) ;
$ ( '.enable-system-radio' ) . on ( 'change' , function ( ) {
if ( this . value === 'false' ) {
2022-01-16 14:19:26 +03:00
$ ( $ ( this ) . data ( 'target' ) ) . addClass ( 'disabled' ) ;
if ( typeof $ ( this ) . data ( 'context' ) !== 'undefined' ) $ ( $ ( this ) . data ( 'context' ) ) . removeClass ( 'disabled' ) ;
2021-10-16 20:28:04 +03:00
} else if ( this . value === 'true' ) {
2022-01-16 14:19:26 +03:00
$ ( $ ( this ) . data ( 'target' ) ) . removeClass ( 'disabled' ) ;
if ( typeof $ ( this ) . data ( 'context' ) !== 'undefined' ) $ ( $ ( this ) . data ( 'context' ) ) . addClass ( 'disabled' ) ;
2021-10-16 20:28:04 +03:00
}
} ) ;
2022-06-10 08:39:53 +03:00
const $trackerIssueStyleRadios = $ ( '.js-tracker-issue-style' ) ;
$trackerIssueStyleRadios . on ( 'change input' , ( ) => {
const checkedVal = $trackerIssueStyleRadios . filter ( ':checked' ) . val ( ) ;
$ ( '#tracker-issue-style-regex-box' ) . toggleClass ( 'disabled' , checkedVal !== 'regexp' ) ;
} ) ;
2021-10-16 20:28:04 +03:00
}
// Labels
initCompLabelEdit ( '.repository.labels' ) ;
// Milestones
if ( $ ( '.repository.new.milestone' ) . length > 0 ) {
$ ( '#clear-date' ) . on ( 'click' , ( ) => {
$ ( '#deadline' ) . val ( '' ) ;
return false ;
} ) ;
}
// Repo Creation
if ( $ ( '.repository.new.repo' ) . length > 0 ) {
$ ( 'input[name="gitignores"], input[name="license"]' ) . on ( 'change' , ( ) => {
const gitignores = $ ( 'input[name="gitignores"]' ) . val ( ) ;
const license = $ ( 'input[name="license"]' ) . val ( ) ;
if ( gitignores || license ) {
$ ( 'input[name="auto_init"]' ) . prop ( 'checked' , true ) ;
}
} ) ;
}
2021-11-18 19:45:00 +03:00
// Compare or pull request
const $repoDiff = $ ( '.repository.diff' ) ;
if ( $repoDiff . length ) {
initRepoCommonBranchOrTagDropdown ( '.choose.branch .dropdown' ) ;
initRepoCommonFilterSearchDropdown ( '.choose.branch .dropdown' ) ;
}
2022-03-29 06:21:30 +03:00
initRepoCloneLink ( ) ;
2022-11-11 20:02:50 +03:00
initCitationFileCopyContent ( ) ;
2021-11-18 19:45:00 +03:00
initRepoCommonLanguageStats ( ) ;
initRepoSettingBranches ( ) ;
2021-10-16 20:28:04 +03:00
// Issues
if ( $ ( '.repository.view.issue' ) . length > 0 ) {
2021-11-18 19:45:00 +03:00
initRepoIssueCommentEdit ( ) ;
2021-10-16 20:28:04 +03:00
initRepoIssueBranchSelect ( ) ;
initRepoIssueTitleEdit ( ) ;
initRepoIssueWipToggle ( ) ;
initRepoIssueComments ( ) ;
initRepoDiffConversationNav ( ) ;
initRepoIssueReferenceIssue ( ) ;
initRepoIssueCommentDelete ( ) ;
initRepoIssueDependencyDelete ( ) ;
initRepoIssueCodeCommentCancel ( ) ;
initRepoIssueStatusButton ( ) ;
initRepoPullRequestUpdate ( ) ;
initCompReactionSelector ( ) ;
2022-05-12 16:39:02 +03:00
initRepoPullRequestMergeForm ( ) ;
2021-10-16 20:28:04 +03:00
}
// Pull request
const $repoComparePull = $ ( '.repository.compare.pull' ) ;
if ( $repoComparePull . length > 0 ) {
// show pull request form
$repoComparePull . find ( 'button.show-form' ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
$ ( this ) . parent ( ) . hide ( ) ;
2021-11-18 19:45:00 +03:00
const $form = $repoComparePull . find ( '.pullrequest-form' ) ;
$form . show ( ) ;
2022-09-02 10:58:49 +03:00
$form . find ( 'textarea.edit_area' ) . each ( function ( ) {
const easyMDE = getAttachedEasyMDE ( $ ( this ) ) ;
if ( easyMDE ) {
easyMDE . codemirror . refresh ( ) ;
}
} ) ;
2021-10-16 20:28:04 +03:00
} ) ;
}
2022-01-07 04:18:52 +03:00
initUnicodeEscapeButton ( ) ;
2021-10-16 20:28:04 +03:00
}
2021-11-18 19:45:00 +03:00
function initRepoIssueCommentEdit ( ) {
// Issue/PR Context Menus
$ ( '.comment-header-right .context-dropdown' ) . dropdown ( { action : 'hide' } ) ;
// Edit issue or comment content
$ ( document ) . on ( 'click' , '.edit-content' , onEditContent ) ;
2021-10-16 20:28:04 +03:00
// Quote reply
$ ( document ) . on ( 'click' , '.quote-reply' , function ( event ) {
$ ( this ) . closest ( '.dropdown' ) . find ( '.menu' ) . toggle ( 'visible' ) ;
const target = $ ( this ) . data ( 'target' ) ;
const quote = $ ( ` #comment- ${ target } ` ) . text ( ) . replace ( /\n/g , '\n> ' ) ;
const content = ` > ${ quote } \n \n ` ;
2021-12-10 05:51:27 +03:00
let easyMDE ;
2021-10-16 20:28:04 +03:00
if ( $ ( this ) . hasClass ( 'quote-reply-diff' ) ) {
const $parent = $ ( this ) . closest ( '.comment-code-cloud' ) ;
$parent . find ( 'button.comment-form-reply' ) . trigger ( 'click' ) ;
2021-12-10 05:51:27 +03:00
easyMDE = getAttachedEasyMDE ( $parent . find ( '[name="content"]' ) ) ;
2021-11-18 19:45:00 +03:00
} else {
// for normal issue/comment page
2021-12-10 05:51:27 +03:00
easyMDE = getAttachedEasyMDE ( $ ( '#comment-form .edit_area' ) ) ;
2021-10-16 20:28:04 +03:00
}
2021-12-10 05:51:27 +03:00
if ( easyMDE ) {
if ( easyMDE . value ( ) !== '' ) {
easyMDE . value ( ` ${ easyMDE . value ( ) } \n \n ${ content } ` ) ;
2021-10-16 20:28:04 +03:00
} else {
2021-12-10 05:51:27 +03:00
easyMDE . value ( ` ${ content } ` ) ;
2021-10-16 20:28:04 +03:00
}
2021-11-18 19:45:00 +03:00
requestAnimationFrame ( ( ) => {
2021-12-10 05:51:27 +03:00
easyMDE . codemirror . focus ( ) ;
easyMDE . codemirror . setCursor ( easyMDE . codemirror . lineCount ( ) , 0 ) ;
2021-11-18 19:45:00 +03:00
} ) ;
2021-10-16 20:28:04 +03:00
}
event . preventDefault ( ) ;
} ) ;
}