Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

#85 - make event callback by default asynchronous #108

Closed
wants to merge 1 commit into from

2 participants

@exaptis

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

@JamesMGreene
Owner

Looks good in theory. :)

Still needs to be built, and perhaps unit tested.

@JamesMGreene JamesMGreene was assigned
@JamesMGreene
Owner

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

@JamesMGreene JamesMGreene was assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 26, 2013
  1. @exaptis

    #85 - make event callback by default asynchronous (except datarequest…

    exaptis authored
    …ed) in order to prevent browser blocking
This page is out of date. Refresh to see the latest.
View
8 src/javascript/ZeroClipboard/event.js
@@ -60,6 +60,7 @@ ZeroClipboard.prototype.receiveEvent = function (eventName, args) {
eventName = eventName.toString().toLowerCase().replace(/^on/, '');
var element = currentElement;
+ var performCallbackAsync = true;
// special behavior for certain events
switch (eventName) {
@@ -101,6 +102,8 @@ ZeroClipboard.prototype.receiveEvent = function (eventName, args) {
var defaultText = element.getAttribute('data-clipboard-text');
if (defaultText) this.setText(defaultText);
}
+
+ performCallbackAsync = false;
break;
case 'complete':
@@ -114,11 +117,10 @@ ZeroClipboard.prototype.receiveEvent = function (eventName, args) {
if (typeof(func) == 'function') {
// actual function reference
- func.call(element, this, args);
+ _dispatchCallback(func, element, this, args, performCallbackAsync);
}
else if (typeof(func) == 'string') {
- // name of function
- window[func].call(element, this, args);
+ _dispatchCallback(window[func], element, this, args, performCallbackAsync);
}
} // user defined handler for event
};
View
20 src/javascript/ZeroClipboard/utils.js
@@ -251,3 +251,23 @@ var _prepGlue = function (elements) {
return elements;
};
+
+
+/*
+ * private _dispatchCallback
+ * used to control if callback should be executed asyncronus or not
+ *
+ * returns nothing
+ */
+
+var _dispatchCallback = function (func, element, instance, args, async) {
+
+ if (async) {
+ setTimeout(function () {
+ func.call(element, instance, args);
+ }, 0);
+ } else {
+ func.call(element, instance, args);
+ }
+
+};
Something went wrong with that request. Please try again.