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

Deprecated 'moviePath', add 'swfPath'. #327

Merged
merged 1 commit into from
Jan 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 41 additions & 1 deletion ZeroClipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,45 @@
var _elementMeta = {};
var _amdModuleId = null;
var _cjsModuleId = null;
var _swfPath = function() {
var i, jsDir, tmpJsPath, jsPath, swfPath = "ZeroClipboard.swf";
if (document.currentScript && (jsPath = document.currentScript.src)) {} else {
var scripts = Array.prototype.slice.call(document.getElementsByTagName("script"), 0);
if ("readyState" in scripts[0]) {
for (i = scripts.length; i--; ) {
if (scripts[i].readyState === "interactive" && (jsPath = scripts[i].src)) {
break;
}
}
} else if (document.readyState === "loading") {
jsPath = scripts[scripts.length - 1].src;
} else {
for (i = scripts.length; i--; ) {
tmpJsPath = scripts[i].src;
if (!tmpJsPath) {
jsDir = null;
break;
}
tmpJsPath = tmpJsPath.split("#")[0].split("?")[0];
tmpJsPath = tmpJsPath.slice(0, tmpJsPath.lastIndexOf("/") + 1);
if (jsDir == null) {
jsDir = tmpJsPath;
} else if (jsDir !== tmpJsPath) {
jsDir = null;
break;
}
}
if (jsDir !== null) {
jsPath = jsDir;
}
}
}
if (jsPath) {
jsPath = jsPath.split("#")[0].split("?")[0];
swfPath = jsPath.slice(0, jsPath.lastIndexOf("/") + 1) + swfPath;
}
return swfPath;
}();
var _camelizeCssPropName = function() {
var matcherRegex = /\-([a-z])/g, replacerFn = function(match, group) {
return group.toUpperCase();
Expand Down Expand Up @@ -495,7 +534,7 @@
};
ZeroClipboard.version = "1.3.0-beta.2";
var _globalConfig = {
moviePath: "ZeroClipboard.swf",
swfPath: _swfPath,
trustedDomains: window.location.host ? [ window.location.host ] : [],
cacheBust: true,
forceHandCursor: false,
Expand Down Expand Up @@ -895,6 +934,7 @@
_globalConfig.trustedOrigins = null;
_globalConfig.allowScriptAccess = null;
_globalConfig.useNoCache = true;
_globalConfig.moviePath = "ZeroClipboard.swf";
ZeroClipboard.detectFlashSupport = function() {
_deprecationWarning("ZeroClipboard.detectFlashSupport", _globalConfig.debug);
return _detectFlashSupport();
Expand Down
2 changes: 1 addition & 1 deletion ZeroClipboard.min.js

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ These are default values for the global configurations options. You should gener

```js
var _globalConfig = {
// URL to movie
moviePath: "ZeroClipboard.swf",
// NOTE: For versions >= v1.3.x and < v2.x, you must use `swfPath` by setting `moviePath`:
// `ZeroClipboard.config({ moviePath: ZeroClipboard.config("swfPath") });`
// URL to movie, relative to the page. Default value will be "ZeroClipboard.swf" under the
// same path as the ZeroClipboard JS file.
swfPath: "path/to/ZeroClipboard.swf",

// SWF inbound scripting policy: page domains that the SWF should trust. (single string or array of strings)
trustedDomains: [window.location.host],
Expand Down Expand Up @@ -109,6 +112,10 @@ var _globalConfig = {
/** @deprecated */
// Include a "nocache" query parameter on requests for the SWF
useNoCache: true,

/** @deprecated */
// URL to movie
moviePath: "ZeroClipboard.swf"
};
```

Expand Down Expand Up @@ -716,4 +723,7 @@ The current list of deprecations includes:
- `ZeroClipboard.prototype.unglue` &rarr; as of [v1.3.0], removing in [v2.0.0]
- Use `ZeroClipboard.prototype.unclip` instead!
- The `useNoCache` config option &rarr; as of [v1.3.0], removing in [v2.0.0]
- Use the `cacheBust` config option instead!
- Use the `cacheBust` config option instead!
- The `moviePath` config option &rarr; as of [v1.3.0], removing in [v2.0.0]
- Use the `swfPath` config option instead!
- For v1.3.x usage, do: `ZeroClipboard.config({ moviePath: ZeroClipboard.config("swfPath") });`
8 changes: 6 additions & 2 deletions src/javascript/ZeroClipboard/core.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
ZeroClipboard.version = "<%= version %>";

// ZeroClipboard options defaults
var _globalConfig = {
// URL to movie
moviePath: "ZeroClipboard.swf",
// NOTE: For versions >= v1.3.x and < v2.x, you must use `swfPath` by setting `moviePath`:
// `ZeroClipboard.config({ moviePath: ZeroClipboard.config("swfPath") });`
// URL to movie, relative to the page. Default value will be "ZeroClipboard.swf" under the
// same path as the ZeroClipboard JS file.
swfPath: _swfPath,

// SWF inbound scripting policy: page domains that the SWF should trust. (single string or array of strings)
trustedDomains: window.location.host ? [window.location.host] : [],
Expand Down
10 changes: 10 additions & 0 deletions src/javascript/ZeroClipboard/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ _globalConfig.allowScriptAccess = null;
_globalConfig.useNoCache = true;


/*
* @deprecated in [v1.3.0], slated for removal in [v2.0.0]. See docs for alternatives.
*
* URL to movie
*
* Originally from "core.js"
*/
_globalConfig.moviePath = "ZeroClipboard.swf";


/*
* @deprecated in [v1.2.0], slated for removal in [v2.0.0]. See docs for more info.
*
Expand Down
56 changes: 55 additions & 1 deletion src/javascript/ZeroClipboard/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,58 @@ var _elementMeta = {};
var _amdModuleId = null;

/* CommonJS module ID or path to access the ZeroClipboard object */
var _cjsModuleId = null;
var _cjsModuleId = null;

/* The presumed location of the "ZeroClipboard.swf" file based on the location of the JS. */
var _swfPath = (function() {
var i, jsDir, tmpJsPath, jsPath,
swfPath = "ZeroClipboard.swf";
// If this browser offers the `currentScript` feature
if (document.currentScript && (jsPath = document.currentScript.src)) {
// Do nothing, assignment occurred during condition
}
else {
var scripts = Array.prototype.slice.call(document.getElementsByTagName("script"), 0);
// If `script` elements have the `readyState` property in this browser
if ("readyState" in scripts[0]) {
for (i = scripts.length; i--; ) {
if (scripts[i].readyState === "interactive" && (jsPath = scripts[i].src)) {
// Do nothing, assignment occurred during condition
break;
}
}
}
// If the document is still parsing, then the last script in the document is the one that is currently loading
else if (document.readyState === "loading") {
jsPath = scripts[scripts.length - 1].src;
}
// If every `script` has a `src` attribute AND they all come from the same directory
else {
for (i = scripts.length; i--; ) {
tmpJsPath = scripts[i].src;
if (!tmpJsPath) {
jsDir = null;
break;
}
tmpJsPath = tmpJsPath.split("#")[0].split("?")[0];
tmpJsPath = tmpJsPath.slice(0, tmpJsPath.lastIndexOf("/") + 1);
if (jsDir == null) {
jsDir = tmpJsPath;
}
else if (jsDir !== tmpJsPath) {
jsDir = null;
break;
}
}
if (jsDir !== null) {
jsPath = jsDir;
}
}
// Otherwise we cannot reliably know what script is executing....
}
if (jsPath) {
jsPath = jsPath.split("#")[0].split("?")[0];
swfPath = jsPath.slice(0, jsPath.lastIndexOf("/") + 1) + swfPath;
}
return swfPath;
})();
17 changes: 17 additions & 0 deletions test/ZeroClipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@
}
});


test("`swfPath` finds the expected default URL", function(assert) {
assert.expect(1);

// Assert, act, assert
var pageUrl = window.location.href.split("#")[0].split("?")[0];
var protocolIndex = pageUrl.lastIndexOf("//");
var protocol = pageUrl.slice(0, protocolIndex + 2);
var rootDir = protocol + pageUrl.slice(protocolIndex + 2).split("/").slice(0, -2).join("/") + "/";
//var zcJsUrl = rootDir + "ZeroClipboard.js";
var swfPathBasedOnZeroClipboardJsPath = rootDir + "ZeroClipboard.swf";

// Test that the client has the expected default URL [even if it's not correct]
assert.strictEqual(ZeroClipboard.config("swfPath"), swfPathBasedOnZeroClipboardJsPath);
});


test("`destroy` destroys the bridge", function(assert) {
assert.expect(3);

Expand Down
39 changes: 27 additions & 12 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@
});


test("Changing `moviePath` works", function(assert) {
assert.expect(5);
test("`swfPath` finds the expected default URL", function(assert) {
assert.expect(1);

// Assert, act, assert

// Test that the client has the default path
assert.strictEqual(ZeroClipboard.config("moviePath"), "ZeroClipboard.swf");
assert.strictEqual(ZeroClipboard.config().moviePath, "ZeroClipboard.swf");
// Change the path
var updatedConfig = ZeroClipboard.config({ moviePath: "new/movie/path.swf" });
// Test that the client has the changed path
assert.strictEqual(updatedConfig.moviePath, "new/movie/path.swf");
assert.strictEqual(ZeroClipboard.config("moviePath"), "new/movie/path.swf");
assert.strictEqual(ZeroClipboard.config().moviePath, "new/movie/path.swf");
var pageUrl = window.location.href.split("#")[0].split("?")[0];
var protocolIndex = pageUrl.lastIndexOf("//");
var protocol = pageUrl.slice(0, protocolIndex + 2);
var rootDir = protocol + pageUrl.slice(protocolIndex + 2).split("/").slice(0, -2).join("/") + "/";
//var stateJsUrl = rootDir + "src/javascript/ZeroClipboard/state.js";
var swfPathBasedOnStateJsPath = rootDir + "src/javascript/ZeroClipboard/ZeroClipboard.swf";

// Test that the client has the expected default URL [even if it's not correct]
assert.strictEqual(ZeroClipboard.config("swfPath"), swfPathBasedOnStateJsPath);
});


Expand Down Expand Up @@ -66,6 +65,22 @@
});


test("Changing `moviePath` works", function(assert) {
assert.expect(5);

// Assert, act, assert

// Test that the client has the default path
assert.strictEqual(ZeroClipboard.config("moviePath"), "ZeroClipboard.swf");
assert.strictEqual(ZeroClipboard.config().moviePath, "ZeroClipboard.swf");
// Change the path
var updatedConfig = ZeroClipboard.config({ moviePath: "new/movie/path.swf" });
// Test that the client has the changed path
assert.strictEqual(updatedConfig.moviePath, "new/movie/path.swf");
assert.strictEqual(ZeroClipboard.config("moviePath"), "new/movie/path.swf");
assert.strictEqual(ZeroClipboard.config().moviePath, "new/movie/path.swf");
});

/** @deprecated */
test("Changing `trustedOrigins` works", function(assert) {
assert.expect(5);
Expand Down
2 changes: 2 additions & 0 deletions test/core.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// Prevent against Firefox/Firebug failing the global pollution check
var getInterface = null;
</script>
<script src="../src/javascript/ZeroClipboard/state.js"></script>
<script src="../src/javascript/ZeroClipboard/utils.js"></script>
<script>
function ZeroClipboard(elements, options) {
Expand All @@ -27,6 +28,7 @@
}
</script>
<script src="../src/javascript/ZeroClipboard/core.js"></script>
<script src="../src/javascript/ZeroClipboard/deprecated.js"></script>
<script src="core.js"></script>
</head>
<body>
Expand Down