Skip to content

Commit 41b4d9a

Browse files
committed
Finalized API, added shouldComponentUpdate test
1 parent bdc6dd3 commit 41b4d9a

File tree

8 files changed

+138
-158
lines changed

8 files changed

+138
-158
lines changed

README.md

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# ReactSWF 0.6.0
1+
# ReactSWF 0.7.0
22

33
Shockwave Flash Player component for [React](https://github.com/facebook/react)
44

5-
Easy installation with `react-swf.min.js` or `npm install react-swf`.
5+
Easy installation with `react-swf.min.js`, `npm install react-swf` or `bower install --save react-swf`.
66

77
* Browser bundle has optional CommonJS/AMD module loader support
88
* Only ~1KB gzipped
@@ -37,29 +37,33 @@ ReactSWF({
3737
#### Flash Player detection
3838

3939
```
40-
if (utils.isFPVersionSupported('10.0')) {
40+
if (ReactSWF.isFPVersionSupported('10.0')) {
4141
// success, go ahead and render the ReactSWF-component
4242
} else {
4343
// not supported, use fallback or direct to Flash Player installer
44-
console.log('Flash Player ' + utils.getFPVersion()) + ' is not supported');
44+
console.log('Flash Player ' + ReactSWF.getFPVersion()) + ' is not supported');
4545
}
4646
```
4747

4848
## Instructions
4949

50-
#### NPM-package
51-
52-
Simply install it with `npm install react-swf` and require it with `var ReactSWF = require('react-swf')`, utility functions are available through `require('react-swf/utils')`.
53-
5450
#### Browser bundle (standalone)
5551

5652
You are using `react-swf.min.js`
5753

58-
Simply include it with `<script src="react-swf.min.js"></script>` and it is available through the global `ReactSWF`, utility functions are available through `ReactSWF.utils.*`.
54+
Simply include it with `<script src="react-swf.min.js"></script>`, it will be available through the global `ReactSWF`.
5955

6056
#### Browser bundle (CommonJS/AMD)
6157

62-
Simply include it with `<script src="react-swf.min.js"></script>` if necessary and require it with `var ReactSWF = require('react-swf')`, utility functions are available through `require('react-swf').utils.*`.
58+
Simply include it with `<script src="react-swf.min.js"></script>`, require it with `var ReactSWF = require('react-swf')`.
59+
60+
#### Node, NPM-package
61+
62+
Simply install it with `npm install react-swf`, require it with `var ReactSWF = require('react-swf')`.
63+
64+
#### Bower-package
65+
66+
Simply install it with `bower install --save react-swf`, use your preferred method above.
6367

6468
## Documentation
6569

@@ -68,29 +72,26 @@ Simply include it with `<script src="react-swf.min.js"></script>` if necessary a
6872
Detailed explanation of each attribute is found on [Flash OBJECT and EMBED tag attributes](http://helpx.adobe.com/flash/kb/flash-object-embed-tag-attributes.html).
6973

7074
```
71-
require('react-swf')
72-
73-
src {string} [required]
74-
width {number}
75-
height {number}
76-
77-
wmode {enum}
78-
flashVars {object|string}
79-
80-
base {string}
81-
menu {boolean}
82-
play {boolean}
83-
loop {boolean}
84-
quality {enum}
85-
scale {enum}
86-
align {enum}
87-
salign {enum}
88-
bgColor {color}
89-
fullScreenAspectRatio {enum}
90-
91-
allowFullScreen {boolean}
92-
allowScriptAccess {boolean}
93-
75+
src {string} [required]
76+
width {number}
77+
height {number}
78+
79+
wmode {enum}
80+
flashVars {object|string}
81+
82+
base {string}
83+
menu {boolean}
84+
play {boolean}
85+
loop {boolean}
86+
quality {enum}
87+
scale {enum}
88+
align {enum}
89+
salign {enum}
90+
bgColor {color}
91+
fullScreenAspectRatio {enum}
92+
93+
allowFullScreen {boolean}
94+
allowScriptAccess {boolean}
9495
```
9596

9697
##### wmode = transparent
@@ -109,18 +110,15 @@ Prevents untrusted Flash-content from accessing sensitive information through br
109110

110111
#### Utility functions
111112

112-
These functions are available through `ReactSWF.utils.*`, `require('react-swf').utils.*` or `require('react-swf/utils').*`, read the instructions at the top if you are unsure which is right for you.
113+
These functions are available statically through `ReactSWF.*`.
113114

114115
```
115-
require('react-swf/utils')
116-
117-
getFPVersion()
118-
Detect installed Flash Player version. Result is cached.
119-
{?string} return 'X.Y.Z'-version, or null.
120-
121-
isFPVersionSupported(version)
122-
Detect if installed Flash Player version meets requirements.
123-
{string} version 'X.Y.Z' or 'X.Y' or 'X'-version.
124-
{boolean} return True if version is supported.
125-
116+
getFPVersion()
117+
Detect installed Flash Player version. Result is cached.
118+
{?string} return 'X.Y.Z'-version, or null.
119+
120+
isFPVersionSupported(version)
121+
Detect if installed Flash Player version meets requirements.
122+
{string} version 'X.Y.Z' or 'X.Y' or 'X'-version.
123+
{boolean} return True if version is supported.
126124
```

build/react-swf.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
}
4141
}(this, function (React) {
4242

43+
var cachedFPVersion;
44+
4345
var encodeFlashKeyValueRegex = /[\r%&+]/g;
4446
var encodeFlashKeyValueLookup = {
4547
'\r': '%0D', '%': '%25', '&': '%26', '+': '%2B', '=': '%3D'
@@ -91,6 +93,9 @@
9193
id: nextUniqueObjectSwfId++
9294
};
9395
},
96+
shouldComponentUpdate: function(nextProps) {
97+
return this.props.src !== this.props.nextProps;
98+
},
9499
componentWillUnmount: function() {
95100
// IE8: leaks memory if all ExternalInterface-callbacks have not been
96101
// removed. Only IE implements readyState, hasOwnProperty does not exist
@@ -164,7 +169,7 @@
164169
});
165170

166171

167-
var cachedFPVersion;
172+
168173

169174
/**
170175
* Detect installed Flash Player version. Result is cached.
@@ -232,10 +237,8 @@
232237
}
233238

234239

235-
ReactSWF.utils = {
236-
getFPVersion: getFPVersion,
237-
isFPVersionSupported: isFPVersionSupported
238-
};
240+
ReactSWF.getFPVersion = getFPVersion;
241+
ReactSWF.isFPVersionSupported = isFPVersionSupported;
239242

240243

241244
return ReactSWF;

build/react-swf.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm-react-swf/ReactSWF.js

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
'use strict';
2323

2424

25-
var React = require('react');
26-
25+
var cachedFPVersion;
2726

2827
var encodeFlashKeyValueRegex = /[\r%&+]/g;
2928
var encodeFlashKeyValueLookup = {
@@ -76,6 +75,9 @@ var ReactSWF = React.createClass({
7675
id: nextUniqueObjectSwfId++
7776
};
7877
},
78+
shouldComponentUpdate: function(nextProps) {
79+
return this.props.src !== this.props.nextProps;
80+
},
7981
componentWillUnmount: function() {
8082
// IE8: leaks memory if all ExternalInterface-callbacks have not been
8183
// removed. Only IE implements readyState, hasOwnProperty does not exist
@@ -149,4 +151,74 @@ var ReactSWF = React.createClass({
149151
});
150152

151153

154+
/**
155+
* Detect installed Flash Player version. Result is cached.
156+
*
157+
* @return {?string} 'X.Y.Z'-version, or null.
158+
*/
159+
function getFPVersion() {
160+
if (cachedFPVersion === undefined) {
161+
cachedFPVersion = null;
162+
163+
if (navigator.plugins) {
164+
var plugin = navigator.plugins['Shockwave Flash'];
165+
if (plugin) {
166+
var mimeType = navigator.mimeTypes['application/x-shockwave-flash'];
167+
if (mimeType && mimeType.enabledPlugin) {
168+
var matches = plugin.description
169+
.match(/^Shockwave Flash (\d+)(?:\.(\d+))?(?: r(\d+))?/);
170+
171+
cachedFPVersion =
172+
matches[1] + '.' + (matches[2] || 0) + '.' + (matches[3] || 0);
173+
}
174+
}
175+
}
176+
if (window.ActiveXObject) {
177+
try {
178+
var axObject = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
179+
if (axObject) {
180+
cachedFPVersion = axObject.GetVariable('$version')
181+
.match(/^WIN (\d+),(\d+),(\d+)/).slice(1).join('.');
182+
}
183+
}
184+
catch (e) {}
185+
}
186+
}
187+
188+
return cachedFPVersion;
189+
}
190+
191+
/**
192+
* Detect if installed Flash Player version meets requirements.
193+
*
194+
* @param {string} version 'X.Y.Z' or 'X.Y' or 'X'-version.
195+
* @return {boolean} True if version is supported.
196+
*/
197+
function isFPVersionSupported(version) {
198+
var supportedVersion = getFPVersion();
199+
200+
if (supportedVersion === null) {
201+
return false;
202+
}
203+
204+
var supportedVersionArray = supportedVersion.split('.');
205+
var requiredVersionArray = version.split('.');
206+
207+
for (var i = 0; i < requiredVersionArray.length; i++) {
208+
if (+supportedVersionArray[i] > +requiredVersionArray[i]) {
209+
return true;
210+
}
211+
if (+supportedVersionArray[i] < +requiredVersionArray[i]) {
212+
return false;
213+
}
214+
}
215+
216+
return true;
217+
}
218+
219+
220+
ReactSWF.getFPVersion = getFPVersion;
221+
ReactSWF.isFPVersionSupported = isFPVersionSupported;
222+
223+
152224
modules.exports = ReactSWF;

npm-react-swf/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-swf",
33
"title": "ReactSWF",
4-
"version": "0.6.0",
4+
"version": "0.7.0",
55
"author": "Andreas Svensson <[email protected]>",
66
"description": "Shockwave Flash Player component for React",
77
"homepage": "https://github.com/syranide/react-swf",

npm-react-swf/utils.js

Lines changed: 0 additions & 96 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-swf",
33
"title": "ReactSWF",
4-
"version": "0.5.0",
4+
"version": "0.7.0",
55
"author": "Andreas Svensson <[email protected]>",
66
"description": "Shockwave Flash Player component for React",
77
"homepage": "https://github.com/syranide/react-swf",
@@ -37,5 +37,5 @@
3737
"engines": {
3838
"node": ">=0.10.0"
3939
},
40-
"main": "src/react-swf.js"
40+
"main": "src/ReactSWF.js"
4141
}

0 commit comments

Comments
 (0)