Project

General

Profile

Feature #33425 » 33425_v3.patch

Mizuki ISHIKAWA, 2020-08-05 06:38

View differences:

public/javascripts/application.js
// do not attach if Tribute is already initialized
if (element.dataset.tribute === 'true') {return;}
const issuesUrl = element.dataset.issuesUrl;
const usersUrl = element.dataset.usersUrl;
const remoteSearch = function(url, cb) {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function ()
......
xhr.send();
};
const tribute = new Tribute({
trigger: '#',
values: function (text, cb) {
if (event.target.type === 'text' && $(element).attr('autocomplete') != 'off') {
$(element).attr('autocomplete', 'off');
const AutoCompleteIssueId =
{
trigger: '#',
values: function (text, cb) {
if (event.target.type === 'text' && $(element).attr('autocomplete') != 'off') {
$(element).attr('autocomplete', 'off');
}
remoteSearch(element.dataset.issuesUrl + text, function (issues) {
return cb(issues);
});
},
lookup: 'label',
fillAttr: 'label',
requireLeadingSpace: true,
selectTemplate: function (issue) {
return '#' + issue.original.id;
},
noMatchTemplate: function () {
return '<span style:"visibility: hidden;"></span>';
}
remoteSearch(issuesUrl + text, function (issues) {
return cb(issues);
});
},
lookup: 'label',
fillAttr: 'label',
requireLeadingSpace: true,
selectTemplate: function (issue) {
return '#' + issue.original.id;
},
noMatchTemplate: function () {
return '<span style:"visibility: hidden;"></span>';
}
});
const AutoCompleteWikiSyntax =
{
trigger: '{{',
values: [
{name: 'collapse', value: '{{collapse\nThis is a block of text that is collapsed by default.\n}}'},
{name: 'child_pages', value: '{{child_pages}}'},
{name: 'include', value: '{{include(WikiPageName)}}'},
{name: 'thumbnail', value: '{{thumbnail(image.png, size=300, title=Thumbnail)}}'},
{name: 'issue', value: '{{issue(123, subject=true, project=true)}}'}
],
lookup: 'name',
fillAttr: 'value',
requireLeadingSpace: true,
selectTemplate: function(item) {
return item.original.value;
},
noMatchTemplate: function () {
return '<span style:"visibility: hidden;"></span>';
}
}
const tribute = new Tribute({
collection: [
AutoCompleteIssueId,
($(element).closest('.jstEditor').length ? AutoCompleteWikiSyntax : {})
]});
tribute.attach(element);
}
$(document).ready(setupAjaxIndicator);
$(document).ready(hideOnLoad);
$(document).ready(addFormObserversForDoubleSubmit);
(4-4/5)