Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

When dispatching MouseEvents to JS, should include pertinent Event details #27

Merged
merged 5 commits into from

2 participants

James M. Greene Jon Rohan
James M. Greene

When ZeroClipboard dispatches MouseEvents to JavaScript, it is only sending an argument of null rather than including any useful information. I'd love to see it pass along any pertinent Event details instead (e.g. ctrlKey, etc.), though we may need to rely on the JS dispatcher to "correct" some of the properties, e.g. pass the Client's id for the event target but have the dispatcher change that into a DOM element.

ActionScript MouseEvent details for events we currently dispatch:

JavaScript MouseEvent details:

  • Modern browsers: MouseEvent
    • Also inherits properties from Event
  • IIRC, old IE (6-8) has a different event but I can't find the docs on it at the moment
Jon Rohan
Owner

This shouldn't be merged until #37 ships.

Jon Rohan jonrohan merged commit 4c6ee9d into from
James M. Greene

You know, thinking back to my proprietary ClipboardInjector... if we didn't capture those other mouse events (everything except CLICK) in the ActionScript, the mouse events will naturally propagate down to the HTML below anyway (as they do in my web apps). Wouldn't that be preferable to our current model of capturing the events in Flash and then dispatching incomplete versions of them back to JavaScript?

Not sure offhand if anyone is using those events in ZeroClipboard today. Alternatively, we could provide a either a loader parameter or another ExternalInterface callback to add those handlers (but default them to off), thus allowing any existing users that might utilize that functionality to still be able to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
BIN  ZeroClipboard.swf
View
Binary file not shown
3  docs/releases.md
View
@@ -1,7 +1,10 @@
### ZeroClipboard 1.1.0
+This release re-writes a lot of how zeroclipboard client works. Check the docs for more details.
+
* [FEATURE] Replace dom selector with simple sizzler query selector
* [FEATURE] Indicate via an event when there is no flash or flash is wrong version
+* [FEATURE] More meta info passed with each flash event.
### ZeroClipboard 1.0.9
51 src/flash/ZeroClipboard.as
View
@@ -30,35 +30,26 @@
button.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
button.alpha = 0.0;
addChild(button);
- button.addEventListener(MouseEvent.CLICK, function(event:Event): void {
+ button.addEventListener(MouseEvent.CLICK, function(event:MouseEvent): void {
// user click copies text to clipboard
// as of flash player 10, this MUST happen from an in-movie flash click event
System.setClipboard( clipText );
- ExternalInterface.call( 'ZeroClipboard.dispatch', 'complete', {
- flashVersion : Capabilities.version,
+ ExternalInterface.call( 'ZeroClipboard.dispatch', 'complete', metaData(event, {
text: clipText
- } );
+ }));
});
- button.addEventListener(MouseEvent.MOUSE_OVER, function(event:Event): void {
- ExternalInterface.call( 'ZeroClipboard.dispatch', 'mouseOver', {
- flashVersion : Capabilities.version
- } );
+ button.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent): void {
+ ExternalInterface.call( 'ZeroClipboard.dispatch', 'mouseOver', metaData(event) );
} );
- button.addEventListener(MouseEvent.MOUSE_OUT, function(event:Event): void {
- ExternalInterface.call( 'ZeroClipboard.dispatch', 'mouseOut', {
- flashVersion : Capabilities.version
- } );
+ button.addEventListener(MouseEvent.MOUSE_OUT, function(event:MouseEvent): void {
+ ExternalInterface.call( 'ZeroClipboard.dispatch', 'mouseOut', metaData(event) );
} );
- button.addEventListener(MouseEvent.MOUSE_DOWN, function(event:Event): void {
- ExternalInterface.call( 'ZeroClipboard.dispatch', 'mouseDown', {
- flashVersion : Capabilities.version
- } );
+ button.addEventListener(MouseEvent.MOUSE_DOWN, function(event:MouseEvent): void {
+ ExternalInterface.call( 'ZeroClipboard.dispatch', 'mouseDown', metaData(event) );
} );
- button.addEventListener(MouseEvent.MOUSE_UP, function(event:Event): void {
- ExternalInterface.call( 'ZeroClipboard.dispatch', 'mouseUp', {
- flashVersion : Capabilities.version
- } );
+ button.addEventListener(MouseEvent.MOUSE_UP, function(event:MouseEvent): void {
+ ExternalInterface.call( 'ZeroClipboard.dispatch', 'mouseUp', metaData(event) );
} );
// external functions
@@ -67,9 +58,25 @@
ExternalInterface.addCallback("setSize", setSize);
// signal to the browser that we are ready
- ExternalInterface.call( 'ZeroClipboard.dispatch', 'load', {
+ ExternalInterface.call( 'ZeroClipboard.dispatch', 'load', metaData() );
+ }
+
+ private function metaData(event:MouseEvent = void, extra:Object = void):Object {
+ var normalOptions:Object = {
flashVersion : Capabilities.version
- } );
+ }
+
+ if (event) {
+ normalOptions.altKey = event.altKey;
+ normalOptions.ctrlKey = event.ctrlKey;
+ normalOptions.shiftKey = event.shiftKey;
+ }
+
+ for(var i:String in extra) {
+ normalOptions[i] = extra[i];
+ }
+
+ return normalOptions;
}
public function setText(newText:String): void {
Something went wrong with that request. Please try again.