Last active
November 3, 2019 02:10
-
-
Save cat-in-136/d7119a6cb521f73956b772095b6db9f4 to your computer and use it in GitHub Desktop.
view-customize workaround of redmine patch #31989 Inline issue auto complete (#) in fields with text-formatting enabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://unpkg.com/[email protected]/dist/tribute.min.js"></script> | |
<link type="text/css" href="https://unpkg.com/[email protected]/dist/tribute.css" rel="stylesheet"> | |
<script> | |
//<![CDATA[ | |
function inlineAutoComplete(element) { | |
'use strict'; | |
// 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 () | |
{ | |
if (xhr.readyState === 4) { | |
if (xhr.status === 200) { | |
var data = JSON.parse(xhr.responseText); | |
cb(data); | |
} else if (xhr.status === 403) { | |
cb([]); | |
} | |
} | |
}; | |
xhr.open("GET", url, true); | |
xhr.send(); | |
}; | |
const tribute = new Tribute({ | |
trigger: '#', | |
values: function (text, cb) { | |
remoteSearch(issuesUrl + text, function (issues) { | |
return cb(issues); | |
}); | |
}, | |
lookup: 'label', | |
fillAttr: 'label', | |
requireLeadingSpace: true, | |
selectTemplate: function (issue) { | |
return '#' + issue.original.id; | |
} | |
}); | |
tribute.attach(element); | |
} | |
$(document).on('focus', '.wiki-edit', function(event) { | |
$(this).attr({'data-auto-complete': 'true', 'data-issues-url': '/issues/auto_complete?project_id' + ViewCustomize.context.project.identifier + '&q='}); | |
inlineAutoComplete(event.target); | |
}); | |
//]]> | |
</script> | |
<style> | |
.tribute-container ul { | |
background-color: #fff; | |
border: 1px solid #ccc; | |
border-radius: 2px; | |
} | |
.tribute-container li.highlight {background-color: #759FCF; color:#fff;} | |
</style> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment