Discourse Copy/Paste problems in Opera

Continuing the discussion from Are we in a scripting-dependency backlash? - #64 by felgall

select - right-click - Copy Paste test Windows 7 Opera 12.17

TopicLink.order(“clicks DESC”).limit(1)
=> [#<TopicLink id: 80, topic_id: 86, post_id: 128, user_id: 27, url: “http://co
mmunity.sitepoint.com/”, domain: “community.sitepoint.com”, internal: false, lin
k_topic_id: nil, created_at: “2015-03-27 18:14:34”, updated_at: “2015-03-27 18:1
4:34”, reflection: false, clicks: 4, link_post_id: nil, title: nil, crawled_at:
nil, quote: false>]

EDIT

I wonder what the difference might be?

I have been trying to use ctrl-C and ctrl-V for copy paste. Didn’t think of trying the mouse ones as I never use those anywhere else. As you suggest the mouse copy/paste works in Discourse while the keyboard ones don’t

I just tried that (ctrl+c ctrl+v) and did have the problem.

Something to do with Opera’s support of the clipboard API (intent is access to OS security).

http://caniuse.com/#feat=clipboard (showing all)

Support unknown

A known problem with ver 11, but according to this was fixed in Opera Presto 2.10 (April 23, 2012)

Clipboard API

Added the following support for Clipboard API (Presto/2.10.292)
    Implemented copy, cut, and paste events for text/plain and text/html content.
    Implemented support for copy, cut, and paste arguments to document.execCommand(), if allowed by site-specific preference.
    See: Clipboard API and events

I have a strong feeling the problem is Discourses use of Mousetrap.js

Browser Support

Mousetrap has been tested and should work in

Internet Explorer 6+
Safari
Firefox
Chrome

If so, it looks like it should be possible to fix things

Extending Mousetrap

Any of the public methods can be overwritten to extend Mousetrap.

Well, @felgall I’m sure you have more experience with Opera userscripts than I do and that you could clean up and further develop this messy alpha version. But I have confirmed that Discourse does use Mousetrap for key bindings.

(function () {
	if (window.location.href.indexOf('www.sitepoint.com/community/t/') != -1) {
		window.opera.addEventListener('AfterEvent.load', function (e) {
			if (e.event.target instanceof HTMLScriptElement) {
				if (typeof HTMLScriptElement == 'function') {
					if (typeof Mousetrap != 'undefined') {
						for (var prop in Mousetrap) {
							if (prop == 'handleKey') {
								console.log(prop + " ~ " + Mousetrap[prop]);
							}
						}
					}
				}
			}
		}, false);
	}
})();

.

Ah, this restores the ability to use ctrl+c and ctrl+v for my tests. I’ll leave it to you to clean up as I’m on my way out to run a few errands.

(function () {
	if (window.location.href.indexOf('www.sitepoint.com/community/t/') != -1) {
		window.opera.addEventListener('AfterEvent.load', function (e) {
			if (e.event.target instanceof HTMLScriptElement) {
				if (typeof HTMLScriptElement == 'function') {
					if (typeof Mousetrap != 'undefined') {
						for (var prop in Mousetrap) {
							if (prop == 'handleKey') {
								Mousetrap.bindGlobal('ctrl+c', function() {
								    return;
								});
								Mousetrap.bindGlobal('ctrl+v', function() {
								    return;
								});
							}
						}
					}
				}
			}
		}, false);
	}
})();

Since it works but only needs to run on a specific site, the only change worth making is to get rid of the outermost if statement that tests whether it is SitePoint and specify that in the userscript @include header instead.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.