summaryrefslogtreecommitdiffstats
path: root/extensions/BugModal/web/bug_modal.js
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2018-08-04 18:24:15 +0200
committerDylan William Hardison <dylan@hardison.net>2018-08-04 18:24:15 +0200
commitf44392e8cdbea85ac308b2472f813ee605ebae4b (patch)
tree6e7adaf99a0e5a43eb1bf5a0d673d86b60f34f99 /extensions/BugModal/web/bug_modal.js
parent5be3a7fd0061aa0bc3059e09079741873b9b833f (diff)
parent4528b21bc922f8b1e0ba8581d230a492aa43c9cf (diff)
downloadbugzilla-f44392e8cdbea85ac308b2472f813ee605ebae4b.tar.gz
bugzilla-f44392e8cdbea85ac308b2472f813ee605ebae4b.tar.xz
Merge branch 'mojo-poc'
Diffstat (limited to 'extensions/BugModal/web/bug_modal.js')
-rw-r--r--extensions/BugModal/web/bug_modal.js80
1 files changed, 14 insertions, 66 deletions
diff --git a/extensions/BugModal/web/bug_modal.js b/extensions/BugModal/web/bug_modal.js
index 4a770e66c..a4ae83d72 100644
--- a/extensions/BugModal/web/bug_modal.js
+++ b/extensions/BugModal/web/bug_modal.js
@@ -339,10 +339,6 @@ $(function() {
// copy summary to clipboard
- function clipboardSummary() {
- return 'Bug ' + BUGZILLA.bug_id + ' - ' + $('#field-value-short_desc').text();
- }
-
if ($('#copy-summary').length) {
var hasExecCopy = false;
try {
@@ -352,11 +348,24 @@ $(function() {
}
if (hasExecCopy) {
+ const url = BUGZILLA.bug_url;
+ const text = `Bug ${BUGZILLA.bug_id} - ${BUGZILLA.bug_summary}`;
+ const html = `<a href="${url}">${text}</a>`;
+
+ document.addEventListener('copy', event => {
+ if (event.target.nodeType === 1 && event.target.matches('#clip')) {
+ event.clipboardData.setData('text/uri-list', url);
+ event.clipboardData.setData('text/plain', text);
+ event.clipboardData.setData('text/html', html);
+ event.preventDefault();
+ }
+ });
+
$('#copy-summary')
.click(function() {
// execCommand("copy") only works on selected text
$('#clip-container').show();
- $('#clip').val(clipboardSummary()).select();
+ $('#clip').val(text).select();
$('#floating-message-text')
.text(document.execCommand("copy") ? 'Bug summary copied!' : 'Couldn’t copy bug summary');
$('#floating-message').fadeIn(250).delay(2500).fadeOut();
@@ -377,27 +386,6 @@ $(function() {
lb_show(this);
});
- // when copying the bug id and summary, reformat to remove \n and alias
- $(document).on(
- 'copy', function(event) {
- var selection = document.getSelection().toString().trim();
- var match = selection.match(/^(Bug \d+)\s*\n(.+)$/) ||
- selection.match(/^(Bug \d+)\s+\([^\)]+\)\s*\n(.+)$/);
- if (match) {
- var content = match[1] + ' - ' + match[2].trim();
- if (event.originalEvent.clipboardData) {
- event.originalEvent.clipboardData.setData('text/plain', content);
- }
- else if (window.clipboardData) {
- window.clipboardData.setData('Text', content);
- }
- else {
- return;
- }
- event.preventDefault();
- }
- });
-
// action button actions
// reset
@@ -1446,46 +1434,6 @@ if (history && history.replaceState) {
}
}
-// ajax wrapper, to simplify error handling and auth
-function bugzilla_ajax(request, done_fn, error_fn) {
- $('#xhr-error').hide('');
- $('#xhr-error').html('');
- request.url += (request.url.match('\\?') ? '&' : '?') +
- 'Bugzilla_api_token=' + encodeURIComponent(BUGZILLA.api_token);
- if (request.type != 'GET') {
- request.contentType = 'application/json';
- request.processData = false;
- if (request.data && request.data.constructor === Object) {
- request.data = JSON.stringify(request.data);
- }
- }
- return $.ajax(request)
- .done(function(data) {
- if (data.error) {
- if (!request.hideError) {
- $('#xhr-error').html(data.message);
- $('#xhr-error').show('fast');
- }
- if (error_fn)
- error_fn(data.message);
- }
- else if (done_fn) {
- done_fn(data);
- }
- })
- .fail(function(data) {
- if (data.statusText === 'abort')
- return;
- var message = data.responseJSON ? data.responseJSON.message : 'Unexpected Error'; // all errors are unexpected :)
- if (!request.hideError) {
- $('#xhr-error').html(message);
- $('#xhr-error').show('fast');
- }
- if (error_fn)
- error_fn(message);
- });
-}
-
// lightbox
function lb_show(el) {