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

Commit

Permalink
Core: Added new event
Browse files Browse the repository at this point in the history
This helps identify when the browser is not capable enough to run ZeroClipboard, e.g. IE<9 without polyfills.

Fixes #546
  • Loading branch information
JamesMGreene committed Nov 15, 2016
1 parent 3aefadb commit 5beb963
Show file tree
Hide file tree
Showing 14 changed files with 246 additions and 36 deletions.
49 changes: 39 additions & 10 deletions dist/ZeroClipboard.Core.js
Expand Up @@ -12,7 +12,7 @@
* Store references to critically important global functions that may be
* overridden on certain web pages.
*/
var _window = window, _document = _window.document, _navigator = _window.navigator, _setTimeout = _window.setTimeout, _clearTimeout = _window.clearTimeout, _setInterval = _window.setInterval, _clearInterval = _window.clearInterval, _getComputedStyle = _window.getComputedStyle, _encodeURIComponent = _window.encodeURIComponent, _ActiveXObject = _window.ActiveXObject, _Error = _window.Error, _parseInt = _window.Number.parseInt || _window.parseInt, _parseFloat = _window.Number.parseFloat || _window.parseFloat, _isNaN = _window.Number.isNaN || _window.isNaN, _now = _window.Date.now, _keys = _window.Object.keys, _defineProperty = _window.Object.defineProperty, _hasOwn = _window.Object.prototype.hasOwnProperty, _slice = _window.Array.prototype.slice, _unwrap = function() {
var _window = window, _document = _window.document, _navigator = _window.navigator, _setTimeout = _window.setTimeout, _clearTimeout = _window.clearTimeout, _setInterval = _window.setInterval, _clearInterval = _window.clearInterval, _getComputedStyle = _window.getComputedStyle, _encodeURIComponent = _window.encodeURIComponent, _ActiveXObject = _window.ActiveXObject, _Error = _window.Error, _parseInt = _window.Number.parseInt || _window.parseInt, _parseFloat = _window.Number.parseFloat || _window.parseFloat, _isNaN = _window.Number.isNaN || _window.isNaN, _now = _window.Date.now, _keys = _window.Object.keys, _hasOwn = _window.Object.prototype.hasOwnProperty, _slice = _window.Array.prototype.slice, _unwrap = function() {
var unwrapper = function(el) {
return el;
};
Expand Down Expand Up @@ -367,7 +367,8 @@
"version-mismatch": "ZeroClipboard JS version number does not match ZeroClipboard SWF version number",
"clipboard-error": "At least one error was thrown while ZeroClipboard was attempting to inject your data into the clipboard",
"config-mismatch": "ZeroClipboard configuration does not match Flash's reality",
"swf-not-found": "The ZeroClipboard SWF object could not be loaded, so please check your `swfPath` configuration and/or network connectivity"
"swf-not-found": "The ZeroClipboard SWF object could not be loaded, so please check your `swfPath` configuration and/or network connectivity",
"browser-unsupported": "The browser does not support the required HTML DOM and JavaScript features"
}
};
/**
Expand Down Expand Up @@ -458,7 +459,9 @@
var _state = function() {
_detectSandbox();
return {
browser: _pick(_navigator, [ "userAgent", "platform", "appName", "appVersion" ]),
browser: _extend(_pick(_navigator, [ "userAgent", "platform", "appName", "appVersion" ]), {
isSupported: _isBrowserSupported()
}),
flash: _omit(_flashState, [ "bridge" ]),
zeroclipboard: {
version: ZeroClipboard.version,
Expand All @@ -467,6 +470,13 @@
};
};
/**
* Does this browser support all of the necessary DOM and JS features necessary?
* @private
*/
var _isBrowserSupported = function() {
return !!(_document.addEventListener && _window.Object.keys && _window.Array.prototype.map);
};
/**
* The underlying implementation of `ZeroClipboard.isFlashUnusable`.
* @private
*/
Expand Down Expand Up @@ -503,6 +513,12 @@
});
}
if (added.error) {
if (!_isBrowserSupported()) {
ZeroClipboard.emit({
type: "error",
name: "browser-unsupported"
});
}
for (i = 0, len = _flashStateErrorNames.length; i < len; i++) {
if (_flashState[_flashStateErrorNames[i].replace(/^flash-/, "")] === true) {
ZeroClipboard.emit({
Expand Down Expand Up @@ -607,6 +623,14 @@
*/
var _create = function() {
var previousState = _flashState.sandboxed;
if (!_isBrowserSupported()) {
_flashState.ready = false;
ZeroClipboard.emit({
type: "error",
name: "browser-unsupported"
});
return;
}
_detectSandbox();
if (typeof _flashState.ready !== "boolean") {
_flashState.ready = false;
Expand Down Expand Up @@ -957,7 +981,17 @@
if (typeof isSandboxed === "boolean") {
_flashState.sandboxed = isSandboxed;
}
if (_flashStateErrorNames.indexOf(event.name) !== -1) {
if (event.name === "browser-unsupported") {
_extend(_flashState, {
disabled: false,
outdated: false,
unavailable: false,
degraded: false,
deactivated: false,
overdue: false,
ready: false
});
} else if (_flashStateErrorNames.indexOf(event.name) !== -1) {
_extend(_flashState, {
disabled: event.name === "flash-disabled",
outdated: event.name === "flash-outdated",
Expand Down Expand Up @@ -1881,12 +1915,7 @@
* @readonly
* @property {string}
*/
_defineProperty(ZeroClipboard, "version", {
value: "2.3.0-beta.1",
writable: false,
configurable: true,
enumerable: true
});
ZeroClipboard.version = "2.3.0-beta.1";
/**
* Update or get a copy of the ZeroClipboard global configuration.
* Returns a copy of the current/updated configuration.
Expand Down
2 changes: 1 addition & 1 deletion dist/ZeroClipboard.Core.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ZeroClipboard.Core.min.map

Large diffs are not rendered by default.

49 changes: 39 additions & 10 deletions dist/ZeroClipboard.js
Expand Up @@ -12,7 +12,7 @@
* Store references to critically important global functions that may be
* overridden on certain web pages.
*/
var _window = window, _document = _window.document, _navigator = _window.navigator, _setTimeout = _window.setTimeout, _clearTimeout = _window.clearTimeout, _setInterval = _window.setInterval, _clearInterval = _window.clearInterval, _getComputedStyle = _window.getComputedStyle, _encodeURIComponent = _window.encodeURIComponent, _ActiveXObject = _window.ActiveXObject, _Error = _window.Error, _parseInt = _window.Number.parseInt || _window.parseInt, _parseFloat = _window.Number.parseFloat || _window.parseFloat, _isNaN = _window.Number.isNaN || _window.isNaN, _now = _window.Date.now, _keys = _window.Object.keys, _defineProperty = _window.Object.defineProperty, _hasOwn = _window.Object.prototype.hasOwnProperty, _slice = _window.Array.prototype.slice, _unwrap = function() {
var _window = window, _document = _window.document, _navigator = _window.navigator, _setTimeout = _window.setTimeout, _clearTimeout = _window.clearTimeout, _setInterval = _window.setInterval, _clearInterval = _window.clearInterval, _getComputedStyle = _window.getComputedStyle, _encodeURIComponent = _window.encodeURIComponent, _ActiveXObject = _window.ActiveXObject, _Error = _window.Error, _parseInt = _window.Number.parseInt || _window.parseInt, _parseFloat = _window.Number.parseFloat || _window.parseFloat, _isNaN = _window.Number.isNaN || _window.isNaN, _now = _window.Date.now, _keys = _window.Object.keys, _hasOwn = _window.Object.prototype.hasOwnProperty, _slice = _window.Array.prototype.slice, _unwrap = function() {
var unwrapper = function(el) {
return el;
};
Expand Down Expand Up @@ -367,7 +367,8 @@
"version-mismatch": "ZeroClipboard JS version number does not match ZeroClipboard SWF version number",
"clipboard-error": "At least one error was thrown while ZeroClipboard was attempting to inject your data into the clipboard",
"config-mismatch": "ZeroClipboard configuration does not match Flash's reality",
"swf-not-found": "The ZeroClipboard SWF object could not be loaded, so please check your `swfPath` configuration and/or network connectivity"
"swf-not-found": "The ZeroClipboard SWF object could not be loaded, so please check your `swfPath` configuration and/or network connectivity",
"browser-unsupported": "The browser does not support the required HTML DOM and JavaScript features"
}
};
/**
Expand Down Expand Up @@ -458,7 +459,9 @@
var _state = function() {
_detectSandbox();
return {
browser: _pick(_navigator, [ "userAgent", "platform", "appName", "appVersion" ]),
browser: _extend(_pick(_navigator, [ "userAgent", "platform", "appName", "appVersion" ]), {
isSupported: _isBrowserSupported()
}),
flash: _omit(_flashState, [ "bridge" ]),
zeroclipboard: {
version: ZeroClipboard.version,
Expand All @@ -467,6 +470,13 @@
};
};
/**
* Does this browser support all of the necessary DOM and JS features necessary?
* @private
*/
var _isBrowserSupported = function() {
return !!(_document.addEventListener && _window.Object.keys && _window.Array.prototype.map);
};
/**
* The underlying implementation of `ZeroClipboard.isFlashUnusable`.
* @private
*/
Expand Down Expand Up @@ -503,6 +513,12 @@
});
}
if (added.error) {
if (!_isBrowserSupported()) {
ZeroClipboard.emit({
type: "error",
name: "browser-unsupported"
});
}
for (i = 0, len = _flashStateErrorNames.length; i < len; i++) {
if (_flashState[_flashStateErrorNames[i].replace(/^flash-/, "")] === true) {
ZeroClipboard.emit({
Expand Down Expand Up @@ -607,6 +623,14 @@
*/
var _create = function() {
var previousState = _flashState.sandboxed;
if (!_isBrowserSupported()) {
_flashState.ready = false;
ZeroClipboard.emit({
type: "error",
name: "browser-unsupported"
});
return;
}
_detectSandbox();
if (typeof _flashState.ready !== "boolean") {
_flashState.ready = false;
Expand Down Expand Up @@ -957,7 +981,17 @@
if (typeof isSandboxed === "boolean") {
_flashState.sandboxed = isSandboxed;
}
if (_flashStateErrorNames.indexOf(event.name) !== -1) {
if (event.name === "browser-unsupported") {
_extend(_flashState, {
disabled: false,
outdated: false,
unavailable: false,
degraded: false,
deactivated: false,
overdue: false,
ready: false
});
} else if (_flashStateErrorNames.indexOf(event.name) !== -1) {
_extend(_flashState, {
disabled: event.name === "flash-disabled",
outdated: event.name === "flash-outdated",
Expand Down Expand Up @@ -1881,12 +1915,7 @@
* @readonly
* @property {string}
*/
_defineProperty(ZeroClipboard, "version", {
value: "2.3.0-beta.1",
writable: false,
configurable: true,
enumerable: true
});
ZeroClipboard.version = "2.3.0-beta.1";
/**
* Update or get a copy of the ZeroClipboard global configuration.
* Returns a copy of the current/updated configuration.
Expand Down
2 changes: 1 addition & 1 deletion dist/ZeroClipboard.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ZeroClipboard.min.map

Large diffs are not rendered by default.

Binary file modified dist/ZeroClipboard.swf
Binary file not shown.
21 changes: 21 additions & 0 deletions docs/api/ZeroClipboard.Core.md
Expand Up @@ -403,6 +403,27 @@ itself to implode by calling `ZeroClipboard.destroy()` under error conditions.
want to do just that.


##### `error[name = "browser-unsupported"]`

This type of `error` event fires when the browser does not support the required HTML DOM and JavaScript features. Check the ["Support" section of the README](../../README.md#support) for the browser support expectations.

```js
ZeroClipboard.on("error", function(e) {
/*
e = {
type: "error",
name: "browser-unsupported",
messsage: "The browser does not support the required HTML DOM and JavaScript features",
target: null,
relatedTarget: null,
currentTarget: null,
timeStamp: Date.now()
};
*/
});
```


##### `error[name = "flash-disabled"]`

This type of `error` event fires when Flash Player is either not installed or not enabled in the browser.
Expand Down
21 changes: 21 additions & 0 deletions docs/api/ZeroClipboard.md
Expand Up @@ -403,6 +403,27 @@ itself to implode by calling `ZeroClipboard.destroy()` under error conditions.
want to do just that.


##### `error[name = "browser-unsupported"]`

This type of `error` event fires when the browser does not support the required HTML DOM and JavaScript features. Check the ["Support" section of the README](../../README.md#support) for the browser support expectations.

```js
ZeroClipboard.on("error", function(e) {
/*
e = {
type: "error",
name: "browser-unsupported",
messsage: "The browser does not support the required HTML DOM and JavaScript features",
target: null,
relatedTarget: null,
currentTarget: null,
timeStamp: Date.now()
};
*/
});
```


##### `error[name = "flash-disabled"]`

This type of `error` event fires when Flash Player is either not installed or not enabled in the browser.
Expand Down
7 changes: 1 addition & 6 deletions src/js/core/api.js
Expand Up @@ -28,12 +28,7 @@ var ZeroClipboard = function() {
* @readonly
* @property {string}
*/
_defineProperty(ZeroClipboard, "version", {
value: "<%= version %>",
writable: false,
configurable: true,
enumerable: true
});
ZeroClipboard.version = "<%= version %>";


/**
Expand Down
44 changes: 41 additions & 3 deletions src/js/core/private.js
Expand Up @@ -55,7 +55,7 @@ var _state = function() {
_detectSandbox();

return {
browser: _pick(_navigator, ["userAgent", "platform", "appName", "appVersion"]),
browser: _extend(_pick(_navigator, ["userAgent", "platform", "appName", "appVersion"]), { "isSupported": _isBrowserSupported() }),
flash: _omit(_flashState, ["bridge"]),
zeroclipboard: {
version: ZeroClipboard.version,
Expand All @@ -65,6 +65,21 @@ var _state = function() {
};


/**
* Does this browser support all of the necessary DOM and JS features necessary?
* @private
*/
var _isBrowserSupported = function() {
return !!(
// DOM Level 2
_document.addEventListener &&
// ECMAScript 5.1
_window.Object.keys &&
_window.Array.prototype.map
);
};


/**
* The underlying implementation of `ZeroClipboard.isFlashUnusable`.
* @private
Expand Down Expand Up @@ -120,6 +135,12 @@ var _on = function(eventType, listener) {
});
}
if (added.error) {
if (!_isBrowserSupported()) {
ZeroClipboard.emit({
type: "error",
name: "browser-unsupported"
});
}
for (i = 0, len = _flashStateErrorNames.length; i < len; i++) {
if (_flashState[_flashStateErrorNames[i].replace(/^flash-/, "")] === true) {
ZeroClipboard.emit({
Expand Down Expand Up @@ -251,6 +272,12 @@ var _create = function() {
// Make note of the most recent sandbox assessment
var previousState = _flashState.sandboxed;

if (!_isBrowserSupported()) {
_flashState.ready = false;
ZeroClipboard.emit({ type: "error", name: "browser-unsupported" });
return;
}

// Always reassess the `sandboxed` state of the page at important Flash-related moments
_detectSandbox();

Expand Down Expand Up @@ -741,7 +768,7 @@ var _getSandboxStatusFromErrorEvent = function(event) {
* @private
*/
var _preprocessEvent = function(event) {
/*jshint maxstatements:27 */
/*jshint maxstatements:28 */

var element = event.target || _currentElement || null;

Expand All @@ -755,7 +782,18 @@ var _preprocessEvent = function(event) {
_flashState.sandboxed = isSandboxed;
}

if (_flashStateErrorNames.indexOf(event.name) !== -1) {
if (event.name === "browser-unsupported") {
_extend(_flashState, {
disabled: false,
outdated: false,
unavailable: false,
degraded: false,
deactivated: false,
overdue: false,
ready: false
});
}
else if (_flashStateErrorNames.indexOf(event.name) !== -1) {
_extend(_flashState, {
disabled: event.name === "flash-disabled",
outdated: event.name === "flash-outdated",
Expand Down
3 changes: 2 additions & 1 deletion src/js/core/state.js
Expand Up @@ -118,7 +118,8 @@ var _eventMessages = {
"version-mismatch": "ZeroClipboard JS version number does not match ZeroClipboard SWF version number",
"clipboard-error": "At least one error was thrown while ZeroClipboard was attempting to inject your data into the clipboard",
"config-mismatch": "ZeroClipboard configuration does not match Flash's reality",
"swf-not-found": "The ZeroClipboard SWF object could not be loaded, so please check your `swfPath` configuration and/or network connectivity"
"swf-not-found": "The ZeroClipboard SWF object could not be loaded, so please check your `swfPath` configuration and/or network connectivity",
"browser-unsupported": "The browser does not support the required HTML DOM and JavaScript features"
}
};

Expand Down
1 change: 0 additions & 1 deletion src/js/shared/state.js
Expand Up @@ -20,7 +20,6 @@ var _window = window,
_isNaN = _window.Number.isNaN || _window.isNaN,
_now = _window.Date.now,
_keys = _window.Object.keys,
_defineProperty = _window.Object.defineProperty,
_hasOwn = _window.Object.prototype.hasOwnProperty,
_slice = _window.Array.prototype.slice,
_unwrap = (function() {
Expand Down

0 comments on commit 5beb963

Please sign in to comment.