Skip to content
This repository

#85 - make event callback by default asynchronous #108

Closed
wants to merge 1 commit into from

2 participants

David James M. Greene
David

... (except datarequested) in order to prevent browser blocking

James M. Greene
Owner

Looks good in theory. :)

Still needs to be built, and perhaps unit tested.

James M. Greene JamesMGreene closed this in c63de3d
James M. Greene
Owner

Merged with a few tweaks, and added a unit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 26, 2013
David #85 - make event callback by default asynchronous (except datarequest…
…ed) in order to prevent browser blocking
7736992
This page is out of date. Refresh to see the latest.
8  src/javascript/ZeroClipboard/event.js
@@ -60,6 +60,7 @@ ZeroClipboard.prototype.receiveEvent = function (eventName, args) {
60 60
   eventName = eventName.toString().toLowerCase().replace(/^on/, '');
61 61
 
62 62
   var element = currentElement;
  63
+  var performCallbackAsync = true;
63 64
 
64 65
   // special behavior for certain events
65 66
   switch (eventName) {
@@ -101,6 +102,8 @@ ZeroClipboard.prototype.receiveEvent = function (eventName, args) {
101 102
       var defaultText = element.getAttribute('data-clipboard-text');
102 103
       if (defaultText) this.setText(defaultText);
103 104
     }
  105
+
  106
+    performCallbackAsync = false;
104 107
     break;
105 108
 
106 109
   case 'complete':
@@ -114,11 +117,10 @@ ZeroClipboard.prototype.receiveEvent = function (eventName, args) {
114 117
 
115 118
     if (typeof(func) == 'function') {
116 119
       // actual function reference
117  
-      func.call(element, this, args);
  120
+      _dispatchCallback(func, element, this, args, performCallbackAsync);
118 121
     }
119 122
     else if (typeof(func) == 'string') {
120  
-      // name of function
121  
-      window[func].call(element, this, args);
  123
+      _dispatchCallback(window[func], element, this, args, performCallbackAsync);
122 124
     }
123 125
   } // user defined handler for event
124 126
 };
20  src/javascript/ZeroClipboard/utils.js
@@ -251,3 +251,23 @@ var _prepGlue = function (elements) {
251 251
 
252 252
   return elements;
253 253
 };
  254
+
  255
+
  256
+/*
  257
+ * private _dispatchCallback
  258
+ * used to control if callback should be executed asyncronus or not
  259
+ *
  260
+ * returns nothing
  261
+ */
  262
+
  263
+var _dispatchCallback = function (func, element, instance, args, async) {
  264
+
  265
+  if (async) {
  266
+    setTimeout(function () {
  267
+      func.call(element, instance, args);
  268
+    }, 0);
  269
+  } else {
  270
+    func.call(element, instance, args);
  271
+  }
  272
+
  273
+};
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.