From 16598a21ca3374ab57408654529ea43dd49e871d Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 17 Aug 2015 16:56:47 +0000 Subject: [PATCH] Fix most of erratic copy behaviour using clipboard in Chrome --- phpgwapi/js/egw_action/egw_action_popup.js | 72 ++++++++-------------- 1 file changed, 24 insertions(+), 48 deletions(-) diff --git a/phpgwapi/js/egw_action/egw_action_popup.js b/phpgwapi/js/egw_action/egw_action_popup.js index 9df97c536f..d8d63b5a67 100644 --- a/phpgwapi/js/egw_action/egw_action_popup.js +++ b/phpgwapi/js/egw_action/egw_action_popup.js @@ -351,44 +351,6 @@ function egwPopupActionImplementation() var menu = ai._buildMenu(_links, _selected, _target); menu.showAt(_context.posx, _context.posy); - // Bindings for copy to system clipboard - menu.instance.dhtmlxmenu.attachEvent("onShow", function(zoneId,ev) { - var client = new ZeroClipboard($j('#'+this.idPrefix+'egw_os_clipboard', this.base)); - - // We need to check if the browser settings for Flash player is set to click-to-play - // then prompting user in order to allow or block Flash player - jQuery('#global-zeroclipboard-html-bridge').hover(function (){ - var $zeroClip = jQuery(this); - if ($zeroClip.hasClass('flash-deactivated')) - { - $zeroClip.addClass('flash-click-to-play-dialog'); - egw.message("In order to copy to clipboard, you need to allow Flash player by clicking on gray box.\nYou can permanently allow Flash player for EGroupware in your browser settings.","info") - } - else - { - $zeroClip.removeClass('flash-click-to-play-dialog') - } - }); - client.on({ - error:function (e){ - // Detect if the Flash player is on click-to-play mode or is deactivated - if (e.name == "flash-deactivated") - { - // Indicate both flash-deactivated and click-to-play mode - jQuery('#global-zeroclipboard-html-bridge').addClass('flash-deactivated'); - } - else - { - jQuery('#global-zeroclipboard-html-bridge').removeClass('flash-deactivated'); - } - } - }) - - client.on("copy",function(event) { - event.clipboardData.setData('text/plain', $j(_links.egw_os_clipboard.actionObj.data.target).text().trim()); - event.clipboardData.setData('text/html', $j(_links.egw_os_clipboard.actionObj.data.target).html()); - }); - }); return true; } else @@ -758,26 +720,40 @@ function egwPopupActionImplementation() var os_clipboard_caption = this._context.event.originalEvent.target.innerHTML.trim(); clipboard_action.set_caption(egw.lang('Copy "%1"', os_clipboard_caption.length>20 ? os_clipboard_caption.substring(0,20)+'...':os_clipboard_caption)); clipboard_action.data.target = this._context.event.originalEvent.target; - $j(clipboard_action.data.target).on('copy', function(event) { + $j(clipboard_action.data.target).off('copy').on('copy', function(event) { + // Cancel any no-select css + var target = $j(clipboard_action.data.target); + var old_select = target.css('user-select'); + target.css('user-select','all'); + var range = document.createRange(); range.selectNode(clipboard_action.data.target); window.getSelection().removeAllRanges(); window.getSelection().addRange(range); - + target.css('user-select',old_select); + + var successful = false; try { if(event.clipboardData) { - event.clipboardData.setData('text/plain', $j(_links.egw_os_clipboard.actionObj.data.target).text().trim()); - event.clipboardData.setData('text/html', $j(_links.egw_os_clipboard.actionObj.data.target).html()); - } - var successful = document.execCommand('copy'); - if(successful) - { - egw.message(egw.lang('Copied')); - return false; + event.clipboardData.setData('text/plain', $j(clipboard_action.data.target).text().trim()); + event.clipboardData.setData('text/html', $j(clipboard_action.data.target).html()); } + // Show fail message, just in case + egw.message(egw.lang('Use Ctrl-C/Cmd-C to copy')); + + successful = document.execCommand('copy'); } catch(err) {} + + if(successful) + { + // Clear fail message + egw.message(''); + window.getSelection().removeAllRanges(); + target.css('user-select',old_select); + return false; + } }); if(typeof _links[copy_action.id] == 'undefined') {