This repository was archived by the owner on Sep 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathangular-swfobject.js
More file actions
81 lines (71 loc) · 2.71 KB
/
angular-swfobject.js
File metadata and controls
81 lines (71 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
angular.module('swfobject', [])
.factory('SwfObject', ['$window', function ($window) {
return $window.swfobject;
}])
.directive('swfObject', ['$window', '$timeout', '$interval', 'SwfObject', function ($window, $timeout, $interval, SwfObject) {
'use strict';
return {
restrict: 'EAC',
template: '<div id="{{id}}" ng-transclude></div>',
transclude: true,
scope: {
params: '=swfParams',
attrs: '=swfAttrs',
callbacks: '=swfCallbacks',
vars: '=?swfVars',
expressInstallSwfurl:'=?xiSwfUrlStr',
swfLoad: '&'
},
link: function link(scope, element, attrs) {
scope.id = attrs.swfId ||
// Random hash looking thing
'swf-' + Math.floor(Math.random() * 1000000000000).toString(16);
$timeout(function () {
SwfObject.embedSWF(attrs.swfUrl,
scope.id,
attrs.swfWidth || 800,
attrs.swfHeight || 600,
attrs.swfVersion || '10',
scope.expressInstallSwfurl,
scope.vars,
scope.params,
scope.attrs,
embedHandler);
}, 0);
// Callbacks to be invoked from AS3 ExternalInterface set on `window`
if (!!scope.callbacks) {
Object.keys(scope.callbacks).forEach(function (cbName) {
$window[cbName] = scope.callbacks[cbName];
});
}
// http://learnswfobject.com/advanced-topics/executing-javascript-when-the-swf-has-finished-loading/
function swfLoadEvent(evt, fn) {
//Set up a timer to periodically check value of PercentLoaded
var loadCheckInterval = $interval(function () {
//Ensure Flash Player's PercentLoaded method is available and returns a value
if (typeof evt.ref.PercentLoaded !== "undefined" && evt.ref.PercentLoaded()) {
//Once value == 100 (fully loaded) we can do whatever we want
if (evt.ref.PercentLoaded() === 100) {
//Clear interval
$interval.cancel(loadCheckInterval);
loadCheckInterval = null;
//Execute function
fn({evt: evt});
}
}
}, 200);
}
// https://code.google.com/p/swfobject/wiki/api
function embedHandler(evt) {
if (scope.swfLoad && typeof(scope.swfLoad) === "function") {
// if failure no reason to go and check if flash is 100% loaded
if (!evt.success || !evt.ref) {
scope.swfLoad({evt: evt});
} else {
swfLoadEvent(evt, scope.swfLoad);
}
}
}
}
};
}]);