Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

#85 - make event callback by default asynchronous #108

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/javascript/ZeroClipboard/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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':
Expand All @@ -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
};
Expand Down
20 changes: 20 additions & 0 deletions src/javascript/ZeroClipboard/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

};