comment-ripper 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/Gemfile +3 -0
- data/Rakefile +1 -19
- data/VERSION +1 -0
- data/bin/DEADJOE +40 -0
- data/bin/rip-comments +20 -17
- data/bin/rip-comments~ +21 -19
- data/lib/exceptions.rb +11 -0
- data/lib/javascript/comment_stripper.rb +25 -0
- data/lib/javascript/lexer.rb +182 -0
- data/lib/tokens/comments.rb +24 -0
- data/lib/tokens/quotes.rb +12 -0
- data/lib/tokens/special.rb +5 -0
- data/lib/tokens/token.rb +80 -0
- data/lib/tokens/whitespace.rb +11 -0
- data/lib/tokens/words.rb +13 -0
- data/spec/comment-ripper_spec.rb +213 -11
- data/spec/sample_data/swfobject_src.expected.js +708 -0
- data/spec/sample_data/swfobject_src.js +777 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +1 -2
- metadata +28 -21
- data/lib/grammars/javascript.tt +0 -35
@@ -0,0 +1,24 @@
|
|
1
|
+
class Comment < Token; end
|
2
|
+
|
3
|
+
class SingleLineCommentStart < Comment
|
4
|
+
self.symbol = "//"
|
5
|
+
end
|
6
|
+
|
7
|
+
class MultiLineCommentStart < Comment
|
8
|
+
self.symbol = "/*"
|
9
|
+
end
|
10
|
+
|
11
|
+
class MultiLineCommentEnd < Comment
|
12
|
+
self.symbol = "*/"
|
13
|
+
end
|
14
|
+
|
15
|
+
class PreservedCommentStart < Comment
|
16
|
+
self.symbol = "/*!"
|
17
|
+
end
|
18
|
+
|
19
|
+
class MultiLineComment < Comment; end
|
20
|
+
|
21
|
+
class PreservedComment < Comment; end
|
22
|
+
|
23
|
+
class SingleLineComment < Comment; end
|
24
|
+
|
data/lib/tokens/token.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
class Token
|
2
|
+
attr_reader :value
|
3
|
+
attr_reader :subtokens
|
4
|
+
attr_reader :position
|
5
|
+
|
6
|
+
def initialize(line=nil, character=nil, value=nil)
|
7
|
+
@subtokens = []
|
8
|
+
|
9
|
+
p = Position.new
|
10
|
+
p.line = line
|
11
|
+
p.character = character
|
12
|
+
@position = p
|
13
|
+
end
|
14
|
+
|
15
|
+
def ==(other)
|
16
|
+
if(false && other.is_a?(Token))
|
17
|
+
return @id == other.id
|
18
|
+
elsif(other.is_a?(String))
|
19
|
+
return @value == other
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def <<(subtoken)
|
26
|
+
@subtokens << subtoken
|
27
|
+
end
|
28
|
+
|
29
|
+
def unshift(subtoken)
|
30
|
+
@subtokens.unshift subtoken
|
31
|
+
end
|
32
|
+
|
33
|
+
def symbol
|
34
|
+
@symbol || self.class.symbol
|
35
|
+
end
|
36
|
+
|
37
|
+
def symbol=(sym)
|
38
|
+
@symbol = sym
|
39
|
+
end
|
40
|
+
|
41
|
+
class << self
|
42
|
+
def match(other)
|
43
|
+
other == @symbol
|
44
|
+
end
|
45
|
+
|
46
|
+
def symbol
|
47
|
+
@symbol
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
def symbol=(sym)
|
52
|
+
@symbol = sym
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_s
|
57
|
+
ret = [symbol]
|
58
|
+
ret += subtokens.map{|t| t.symbol} unless subtokens.nil?
|
59
|
+
ret.join
|
60
|
+
end
|
61
|
+
|
62
|
+
def inspect
|
63
|
+
ins = ["<"]
|
64
|
+
ins << self.class.to_s
|
65
|
+
ins << ":'"
|
66
|
+
ins << symbol
|
67
|
+
ins << "':["
|
68
|
+
unless subtokens.nil? or subtokens.empty?
|
69
|
+
ins << subtokens.map{|d| d.symbol}.join
|
70
|
+
end
|
71
|
+
ins << "]>"
|
72
|
+
|
73
|
+
ins.join
|
74
|
+
end
|
75
|
+
|
76
|
+
class Position
|
77
|
+
attr_accessor :line
|
78
|
+
attr_accessor :character
|
79
|
+
end
|
80
|
+
end
|
data/lib/tokens/words.rb
ADDED
data/spec/comment-ripper_spec.rb
CHANGED
@@ -1,36 +1,238 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
require 'javascript'
|
2
|
+
require 'javascript/comment_stripper'
|
3
3
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
4
|
+
describe CommentRipper do
|
5
|
+
def get_output(input)
|
6
|
+
CommentRipper::Javascript.new.strip(input)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "shouldn't touch non-comment code" do
|
10
10
|
input = <<-JS
|
11
11
|
alert("cat");
|
12
12
|
JS
|
13
|
-
output = @p.parse(input).text_value
|
14
13
|
expected_output = input
|
15
|
-
|
14
|
+
output = get_output(input)
|
16
15
|
output.should == expected_output
|
17
16
|
end
|
18
17
|
|
19
18
|
it "should handle single-line comments on their own line" do
|
20
19
|
input = %Q{// monkey!\nalert("cat");\n// tree!}
|
21
20
|
|
22
|
-
expected_output = %q{alert("cat");}
|
23
|
-
output =
|
21
|
+
expected_output = %q{alert("cat");} + "\n"
|
22
|
+
output = get_output(input)
|
24
23
|
|
25
|
-
output.
|
24
|
+
output.should == expected_output
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should handle multi-line comments on their own line" do
|
28
|
+
input = %Q{/* commento */\nnewLine();}
|
29
|
+
|
30
|
+
expected_output = %Q{newLine();}
|
31
|
+
output = get_output(input)
|
32
|
+
|
33
|
+
output.should == expected_output
|
26
34
|
end
|
27
35
|
|
28
36
|
it "should handle single-line comments at the end of regular lines" do
|
29
37
|
input = %Q{alert("cat"); // monkey! // banana!}
|
30
38
|
|
31
39
|
expected_output = %Q{alert("cat");}
|
32
|
-
output =
|
40
|
+
output = get_output(input)
|
41
|
+
|
42
|
+
output.should == expected_output
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
it "should handle indented single-line comments correctly" do
|
47
|
+
input = <<JS
|
48
|
+
// monkey
|
49
|
+
function(){
|
50
|
+
// some logic
|
51
|
+
code();
|
52
|
+
// end logic
|
53
|
+
bar();
|
54
|
+
}
|
55
|
+
JS
|
56
|
+
expected_output = <<JS
|
57
|
+
function(){
|
58
|
+
code();
|
59
|
+
bar();
|
60
|
+
}
|
61
|
+
JS
|
62
|
+
output = get_output(input)
|
63
|
+
output.should == expected_output
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should handle indented multi-line comments correctly" do
|
67
|
+
input = <<JS
|
68
|
+
function red(){
|
69
|
+
/* multi-comment */
|
70
|
+
baz();
|
71
|
+
}
|
72
|
+
JS
|
73
|
+
expected_output = <<JS
|
74
|
+
function red(){
|
75
|
+
baz();
|
76
|
+
}
|
77
|
+
JS
|
78
|
+
output = get_output(input)
|
79
|
+
output.should == expected_output
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should handle comments at the end of code lines" do
|
83
|
+
input = <<JS
|
84
|
+
function(){
|
85
|
+
end_of_the_line(); // yes, these work too.
|
86
|
+
}
|
87
|
+
JS
|
88
|
+
expected_output = <<JS
|
89
|
+
function(){
|
90
|
+
end_of_the_line();
|
91
|
+
}
|
92
|
+
JS
|
93
|
+
output = get_output(input)
|
94
|
+
output.should == expected_output
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should handle nested comments correctly" do
|
98
|
+
input = <<JS
|
99
|
+
function disabled_code(){
|
100
|
+
/*
|
101
|
+
alert("hi");
|
102
|
+
//*/
|
103
|
+
}
|
104
|
+
|
105
|
+
function actually_active_code(){
|
106
|
+
//*
|
107
|
+
alert("bye");
|
108
|
+
//*/
|
109
|
+
}
|
110
|
+
JS
|
111
|
+
expected_output = <<JS
|
112
|
+
function disabled_code(){
|
113
|
+
}
|
33
114
|
|
34
|
-
|
115
|
+
function actually_active_code(){
|
116
|
+
alert("bye");
|
117
|
+
}
|
118
|
+
JS
|
119
|
+
output = get_output(input)
|
120
|
+
output.should == expected_output
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should handle single-line comments in the middle of strings" do
|
124
|
+
input = <<JS
|
125
|
+
var red = "tilted//lines";
|
126
|
+
var green = 'single//quotes';
|
127
|
+
JS
|
128
|
+
expected_output = input
|
129
|
+
output = get_output(input)
|
130
|
+
output.should == expected_output
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should handle multi-line comments in the middle of strings" do
|
134
|
+
input = <<JS
|
135
|
+
var red = "foo /*bar*/ baz";
|
136
|
+
var green = 'foo /* bar */ baz';
|
137
|
+
JS
|
138
|
+
expected_output = input
|
139
|
+
output = get_output(input)
|
140
|
+
output.should == expected_output
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should leave important multi-line comments intact" do
|
144
|
+
input = <<JS
|
145
|
+
/*! Some license agreement or other! */
|
146
|
+
function coolCode() {}
|
147
|
+
JS
|
148
|
+
expected_output = input
|
149
|
+
output = get_output(input)
|
150
|
+
output.should == expected_output
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should handle multi-line comments in the middle of the line" do
|
154
|
+
input = <<JS
|
155
|
+
function poorlyNamedFunction(/* thing1 */arg1, /* thing2 */arg2){
|
156
|
+
doNothing();
|
157
|
+
}
|
158
|
+
JS
|
159
|
+
expected_output = <<JS
|
160
|
+
function poorlyNamedFunction(arg1,arg2){
|
161
|
+
doNothing();
|
162
|
+
}
|
163
|
+
JS
|
164
|
+
output = get_output(input)
|
165
|
+
output.should == expected_output
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should handle comments in the middle of nefarious multiline strings" do
|
169
|
+
input = <<JS
|
170
|
+
var animals = "chicken \
|
171
|
+
bear // kodiak \
|
172
|
+
pig // a pink one";
|
173
|
+
JS
|
174
|
+
expected_output = input
|
175
|
+
output = get_output(input)
|
176
|
+
output.should == expected_output
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should handle special characters in the middle of regular expressions" do
|
180
|
+
input = <<JS
|
181
|
+
function urlEncodeIfNecessary(s) {
|
182
|
+
var regex = /[\\\"<>\.;]/;
|
183
|
+
var hasBadChars = regex.exec(s) != null;
|
184
|
+
return hasBadChars && typeof encodeURIComponent != UNDEF ? encodeURIComponent(s) : s;
|
185
|
+
}
|
186
|
+
JS
|
187
|
+
expected_output = input
|
188
|
+
output = get_output(input)
|
189
|
+
output.should == expected_output
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should handle divisions" do
|
193
|
+
input = <<JS
|
194
|
+
var milli = Math.floor(diff % 1000 / 100).toString();
|
195
|
+
JS
|
196
|
+
expected_output = input
|
197
|
+
output = get_output(input)
|
198
|
+
output.should == expected_output
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "Unmatched symbol matching" do
|
202
|
+
it "should give good error reporting for unmatched single quotes" do
|
203
|
+
input = [<<JS, <<JS2, <<JS3]
|
204
|
+
var animals = ';
|
205
|
+
JS
|
206
|
+
//foo
|
207
|
+
var moo = ';
|
208
|
+
JS2
|
209
|
+
/*
|
210
|
+
multiline
|
211
|
+
*/
|
212
|
+
function(){ var dog = ' };
|
213
|
+
JS3
|
214
|
+
output = ["L1 C15", "L2 C11", "L4 C23"]
|
215
|
+
(0...input.length).each do |i|
|
216
|
+
lambda { get_output(input[i]) }.should raise_exception(CommentRipper::UnmatchedTokenException, "Unmatched token: ' at #{output[i]}")
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should provide good error reporting for unmatched double quotes" do
|
221
|
+
input = [<<JS, <<JS2, <<JS3]
|
222
|
+
var animals = ";
|
223
|
+
JS
|
224
|
+
//foo
|
225
|
+
var moo = ";
|
226
|
+
JS2
|
227
|
+
/*
|
228
|
+
multiline
|
229
|
+
*/
|
230
|
+
function(){ var dog = " };
|
231
|
+
JS3
|
232
|
+
output = ["L1 C15", "L2 C11", "L4 C23"]
|
233
|
+
(0...input.length).each do |i|
|
234
|
+
lambda { get_output(input[i]) }.should raise_exception(CommentRipper::UnmatchedTokenException, "Unmatched token: \" at #{output[i]}")
|
235
|
+
end
|
236
|
+
end
|
35
237
|
end
|
36
238
|
end
|
@@ -0,0 +1,708 @@
|
|
1
|
+
/*! SWFObject v2.2 <http://code.google.com/p/swfobject/>
|
2
|
+
is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
|
3
|
+
*/
|
4
|
+
|
5
|
+
var swfobject = function() {
|
6
|
+
|
7
|
+
var UNDEF = "undefined",
|
8
|
+
OBJECT = "object",
|
9
|
+
SHOCKWAVE_FLASH = "Shockwave Flash",
|
10
|
+
SHOCKWAVE_FLASH_AX = "ShockwaveFlash.ShockwaveFlash",
|
11
|
+
FLASH_MIME_TYPE = "application/x-shockwave-flash",
|
12
|
+
EXPRESS_INSTALL_ID = "SWFObjectExprInst",
|
13
|
+
ON_READY_STATE_CHANGE = "onreadystatechange",
|
14
|
+
|
15
|
+
win = window,
|
16
|
+
doc = document,
|
17
|
+
nav = navigator,
|
18
|
+
|
19
|
+
plugin = false,
|
20
|
+
domLoadFnArr = [main],
|
21
|
+
regObjArr = [],
|
22
|
+
objIdArr = [],
|
23
|
+
listenersArr = [],
|
24
|
+
storedAltContent,
|
25
|
+
storedAltContentId,
|
26
|
+
storedCallbackFn,
|
27
|
+
storedCallbackObj,
|
28
|
+
isDomLoaded = false,
|
29
|
+
isExpressInstallActive = false,
|
30
|
+
dynamicStylesheet,
|
31
|
+
dynamicStylesheetMedia,
|
32
|
+
autoHideShow = true,
|
33
|
+
|
34
|
+
ua = function() {
|
35
|
+
var w3cdom = typeof doc.getElementById != UNDEF && typeof doc.getElementsByTagName != UNDEF && typeof doc.createElement != UNDEF,
|
36
|
+
u = nav.userAgent.toLowerCase(),
|
37
|
+
p = nav.platform.toLowerCase(),
|
38
|
+
windows = p ? /win/.test(p) : /win/.test(u),
|
39
|
+
mac = p ? /mac/.test(p) : /mac/.test(u),
|
40
|
+
webkit = /webkit/.test(u) ? parseFloat(u.replace(/^.*webkit\/(\d+(\.\d+)?).*$/, "$1")) : false,
|
41
|
+
ie = !+"\v1",
|
42
|
+
playerVersion = [0,0,0],
|
43
|
+
d = null;
|
44
|
+
if (typeof nav.plugins != UNDEF && typeof nav.plugins[SHOCKWAVE_FLASH] == OBJECT) {
|
45
|
+
d = nav.plugins[SHOCKWAVE_FLASH].description;
|
46
|
+
if (d && !(typeof nav.mimeTypes != UNDEF && nav.mimeTypes[FLASH_MIME_TYPE] && !nav.mimeTypes[FLASH_MIME_TYPE].enabledPlugin)) {
|
47
|
+
plugin = true;
|
48
|
+
ie = false;
|
49
|
+
d = d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
|
50
|
+
playerVersion[0] = parseInt(d.replace(/^(.*)\..*$/, "$1"), 10);
|
51
|
+
playerVersion[1] = parseInt(d.replace(/^.*\.(.*)\s.*$/, "$1"), 10);
|
52
|
+
playerVersion[2] = /[a-zA-Z]/.test(d) ? parseInt(d.replace(/^.*[a-zA-Z]+(.*)$/, "$1"), 10) : 0;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
else if (typeof win.ActiveXObject != UNDEF) {
|
56
|
+
try {
|
57
|
+
var a = new ActiveXObject(SHOCKWAVE_FLASH_AX);
|
58
|
+
if (a) {
|
59
|
+
d = a.GetVariable("$version");
|
60
|
+
if (d) {
|
61
|
+
ie = true;
|
62
|
+
d = d.split(" ")[1].split(",");
|
63
|
+
playerVersion = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
catch(e) {}
|
68
|
+
}
|
69
|
+
return { w3:w3cdom, pv:playerVersion, wk:webkit, ie:ie, win:windows, mac:mac };
|
70
|
+
}(),
|
71
|
+
|
72
|
+
onDomLoad = function() {
|
73
|
+
if (!ua.w3) { return; }
|
74
|
+
if ((typeof doc.readyState != UNDEF && doc.readyState == "complete") || (typeof doc.readyState == UNDEF && (doc.getElementsByTagName("body")[0] || doc.body))) {
|
75
|
+
callDomLoadFunctions();
|
76
|
+
}
|
77
|
+
if (!isDomLoaded) {
|
78
|
+
if (typeof doc.addEventListener != UNDEF) {
|
79
|
+
doc.addEventListener("DOMContentLoaded", callDomLoadFunctions, false);
|
80
|
+
}
|
81
|
+
if (ua.ie && ua.win) {
|
82
|
+
doc.attachEvent(ON_READY_STATE_CHANGE, function() {
|
83
|
+
if (doc.readyState == "complete") {
|
84
|
+
doc.detachEvent(ON_READY_STATE_CHANGE, arguments.callee);
|
85
|
+
callDomLoadFunctions();
|
86
|
+
}
|
87
|
+
});
|
88
|
+
if (win == top) {
|
89
|
+
(function(){
|
90
|
+
if (isDomLoaded) { return; }
|
91
|
+
try {
|
92
|
+
doc.documentElement.doScroll("left");
|
93
|
+
}
|
94
|
+
catch(e) {
|
95
|
+
setTimeout(arguments.callee, 0);
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
callDomLoadFunctions();
|
99
|
+
})();
|
100
|
+
}
|
101
|
+
}
|
102
|
+
if (ua.wk) {
|
103
|
+
(function(){
|
104
|
+
if (isDomLoaded) { return; }
|
105
|
+
if (!/loaded|complete/.test(doc.readyState)) {
|
106
|
+
setTimeout(arguments.callee, 0);
|
107
|
+
return;
|
108
|
+
}
|
109
|
+
callDomLoadFunctions();
|
110
|
+
})();
|
111
|
+
}
|
112
|
+
addLoadEvent(callDomLoadFunctions);
|
113
|
+
}
|
114
|
+
}();
|
115
|
+
|
116
|
+
function callDomLoadFunctions() {
|
117
|
+
if (isDomLoaded) { return; }
|
118
|
+
try {
|
119
|
+
var t = doc.getElementsByTagName("body")[0].appendChild(createElement("span"));
|
120
|
+
t.parentNode.removeChild(t);
|
121
|
+
}
|
122
|
+
catch (e) { return; }
|
123
|
+
isDomLoaded = true;
|
124
|
+
var dl = domLoadFnArr.length;
|
125
|
+
for (var i = 0; i < dl; i++) {
|
126
|
+
domLoadFnArr[i]();
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
function addDomLoadEvent(fn) {
|
131
|
+
if (isDomLoaded) {
|
132
|
+
fn();
|
133
|
+
}
|
134
|
+
else {
|
135
|
+
domLoadFnArr[domLoadFnArr.length] = fn;
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
function addLoadEvent(fn) {
|
140
|
+
if (typeof win.addEventListener != UNDEF) {
|
141
|
+
win.addEventListener("load", fn, false);
|
142
|
+
}
|
143
|
+
else if (typeof doc.addEventListener != UNDEF) {
|
144
|
+
doc.addEventListener("load", fn, false);
|
145
|
+
}
|
146
|
+
else if (typeof win.attachEvent != UNDEF) {
|
147
|
+
addListener(win, "onload", fn);
|
148
|
+
}
|
149
|
+
else if (typeof win.onload == "function") {
|
150
|
+
var fnOld = win.onload;
|
151
|
+
win.onload = function() {
|
152
|
+
fnOld();
|
153
|
+
fn();
|
154
|
+
};
|
155
|
+
}
|
156
|
+
else {
|
157
|
+
win.onload = fn;
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
function main() {
|
162
|
+
if (plugin) {
|
163
|
+
testPlayerVersion();
|
164
|
+
}
|
165
|
+
else {
|
166
|
+
matchVersions();
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
function testPlayerVersion() {
|
171
|
+
var b = doc.getElementsByTagName("body")[0];
|
172
|
+
var o = createElement(OBJECT);
|
173
|
+
o.setAttribute("type", FLASH_MIME_TYPE);
|
174
|
+
var t = b.appendChild(o);
|
175
|
+
if (t) {
|
176
|
+
var counter = 0;
|
177
|
+
(function(){
|
178
|
+
if (typeof t.GetVariable != UNDEF) {
|
179
|
+
var d = t.GetVariable("$version");
|
180
|
+
if (d) {
|
181
|
+
d = d.split(" ")[1].split(",");
|
182
|
+
ua.pv = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
|
183
|
+
}
|
184
|
+
}
|
185
|
+
else if (counter < 10) {
|
186
|
+
counter++;
|
187
|
+
setTimeout(arguments.callee, 10);
|
188
|
+
return;
|
189
|
+
}
|
190
|
+
b.removeChild(o);
|
191
|
+
t = null;
|
192
|
+
matchVersions();
|
193
|
+
})();
|
194
|
+
}
|
195
|
+
else {
|
196
|
+
matchVersions();
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
function matchVersions() {
|
201
|
+
var rl = regObjArr.length;
|
202
|
+
if (rl > 0) {
|
203
|
+
for (var i = 0; i < rl; i++) {
|
204
|
+
var id = regObjArr[i].id;
|
205
|
+
var cb = regObjArr[i].callbackFn;
|
206
|
+
var cbObj = {success:false, id:id};
|
207
|
+
if (ua.pv[0] > 0) {
|
208
|
+
var obj = getElementById(id);
|
209
|
+
if (obj) {
|
210
|
+
if (hasPlayerVersion(regObjArr[i].swfVersion) && !(ua.wk && ua.wk < 312)) {
|
211
|
+
setVisibility(id, true);
|
212
|
+
if (cb) {
|
213
|
+
cbObj.success = true;
|
214
|
+
cbObj.ref = getObjectById(id);
|
215
|
+
cb(cbObj);
|
216
|
+
}
|
217
|
+
}
|
218
|
+
else if (regObjArr[i].expressInstall && canExpressInstall()) {
|
219
|
+
var att = {};
|
220
|
+
att.data = regObjArr[i].expressInstall;
|
221
|
+
att.width = obj.getAttribute("width") || "0";
|
222
|
+
att.height = obj.getAttribute("height") || "0";
|
223
|
+
if (obj.getAttribute("class")) { att.styleclass = obj.getAttribute("class"); }
|
224
|
+
if (obj.getAttribute("align")) { att.align = obj.getAttribute("align"); }
|
225
|
+
var par = {};
|
226
|
+
var p = obj.getElementsByTagName("param");
|
227
|
+
var pl = p.length;
|
228
|
+
for (var j = 0; j < pl; j++) {
|
229
|
+
if (p[j].getAttribute("name").toLowerCase() != "movie") {
|
230
|
+
par[p[j].getAttribute("name")] = p[j].getAttribute("value");
|
231
|
+
}
|
232
|
+
}
|
233
|
+
showExpressInstall(att, par, id, cb);
|
234
|
+
}
|
235
|
+
else {
|
236
|
+
displayAltContent(obj);
|
237
|
+
if (cb) { cb(cbObj); }
|
238
|
+
}
|
239
|
+
}
|
240
|
+
}
|
241
|
+
else {
|
242
|
+
setVisibility(id, true);
|
243
|
+
if (cb) {
|
244
|
+
var o = getObjectById(id);
|
245
|
+
if (o && typeof o.SetVariable != UNDEF) {
|
246
|
+
cbObj.success = true;
|
247
|
+
cbObj.ref = o;
|
248
|
+
}
|
249
|
+
cb(cbObj);
|
250
|
+
}
|
251
|
+
}
|
252
|
+
}
|
253
|
+
}
|
254
|
+
}
|
255
|
+
|
256
|
+
function getObjectById(objectIdStr) {
|
257
|
+
var r = null;
|
258
|
+
var o = getElementById(objectIdStr);
|
259
|
+
if (o && o.nodeName == "OBJECT") {
|
260
|
+
if (typeof o.SetVariable != UNDEF) {
|
261
|
+
r = o;
|
262
|
+
}
|
263
|
+
else {
|
264
|
+
var n = o.getElementsByTagName(OBJECT)[0];
|
265
|
+
if (n) {
|
266
|
+
r = n;
|
267
|
+
}
|
268
|
+
}
|
269
|
+
}
|
270
|
+
return r;
|
271
|
+
}
|
272
|
+
|
273
|
+
function canExpressInstall() {
|
274
|
+
return !isExpressInstallActive && hasPlayerVersion("6.0.65") && (ua.win || ua.mac) && !(ua.wk && ua.wk < 312);
|
275
|
+
}
|
276
|
+
|
277
|
+
function showExpressInstall(att, par, replaceElemIdStr, callbackFn) {
|
278
|
+
isExpressInstallActive = true;
|
279
|
+
storedCallbackFn = callbackFn || null;
|
280
|
+
storedCallbackObj = {success:false, id:replaceElemIdStr};
|
281
|
+
var obj = getElementById(replaceElemIdStr);
|
282
|
+
if (obj) {
|
283
|
+
if (obj.nodeName == "OBJECT") {
|
284
|
+
storedAltContent = abstractAltContent(obj);
|
285
|
+
storedAltContentId = null;
|
286
|
+
}
|
287
|
+
else {
|
288
|
+
storedAltContent = obj;
|
289
|
+
storedAltContentId = replaceElemIdStr;
|
290
|
+
}
|
291
|
+
att.id = EXPRESS_INSTALL_ID;
|
292
|
+
if (typeof att.width == UNDEF || (!/%$/.test(att.width) && parseInt(att.width, 10) < 310)) { att.width = "310"; }
|
293
|
+
if (typeof att.height == UNDEF || (!/%$/.test(att.height) && parseInt(att.height, 10) < 137)) { att.height = "137"; }
|
294
|
+
doc.title = doc.title.slice(0, 47) + " - Flash Player Installation";
|
295
|
+
var pt = ua.ie && ua.win ? "ActiveX" : "PlugIn",
|
296
|
+
fv = "MMredirectURL=" + win.location.toString().replace(/&/g,"%26") + "&MMplayerType=" + pt + "&MMdoctitle=" + doc.title;
|
297
|
+
if (typeof par.flashvars != UNDEF) {
|
298
|
+
par.flashvars += "&" + fv;
|
299
|
+
}
|
300
|
+
else {
|
301
|
+
par.flashvars = fv;
|
302
|
+
}
|
303
|
+
if (ua.ie && ua.win && obj.readyState != 4) {
|
304
|
+
var newObj = createElement("div");
|
305
|
+
replaceElemIdStr += "SWFObjectNew";
|
306
|
+
newObj.setAttribute("id", replaceElemIdStr);
|
307
|
+
obj.parentNode.insertBefore(newObj, obj);
|
308
|
+
obj.style.display = "none";
|
309
|
+
(function(){
|
310
|
+
if (obj.readyState == 4) {
|
311
|
+
obj.parentNode.removeChild(obj);
|
312
|
+
}
|
313
|
+
else {
|
314
|
+
setTimeout(arguments.callee, 10);
|
315
|
+
}
|
316
|
+
})();
|
317
|
+
}
|
318
|
+
createSWF(att, par, replaceElemIdStr);
|
319
|
+
}
|
320
|
+
}
|
321
|
+
|
322
|
+
function displayAltContent(obj) {
|
323
|
+
if (ua.ie && ua.win && obj.readyState != 4) {
|
324
|
+
var el = createElement("div");
|
325
|
+
obj.parentNode.insertBefore(el, obj);
|
326
|
+
el.parentNode.replaceChild(abstractAltContent(obj), el);
|
327
|
+
obj.style.display = "none";
|
328
|
+
(function(){
|
329
|
+
if (obj.readyState == 4) {
|
330
|
+
obj.parentNode.removeChild(obj);
|
331
|
+
}
|
332
|
+
else {
|
333
|
+
setTimeout(arguments.callee, 10);
|
334
|
+
}
|
335
|
+
})();
|
336
|
+
}
|
337
|
+
else {
|
338
|
+
obj.parentNode.replaceChild(abstractAltContent(obj), obj);
|
339
|
+
}
|
340
|
+
}
|
341
|
+
|
342
|
+
function abstractAltContent(obj) {
|
343
|
+
var ac = createElement("div");
|
344
|
+
if (ua.win && ua.ie) {
|
345
|
+
ac.innerHTML = obj.innerHTML;
|
346
|
+
}
|
347
|
+
else {
|
348
|
+
var nestedObj = obj.getElementsByTagName(OBJECT)[0];
|
349
|
+
if (nestedObj) {
|
350
|
+
var c = nestedObj.childNodes;
|
351
|
+
if (c) {
|
352
|
+
var cl = c.length;
|
353
|
+
for (var i = 0; i < cl; i++) {
|
354
|
+
if (!(c[i].nodeType == 1 && c[i].nodeName == "PARAM") && !(c[i].nodeType == 8)) {
|
355
|
+
ac.appendChild(c[i].cloneNode(true));
|
356
|
+
}
|
357
|
+
}
|
358
|
+
}
|
359
|
+
}
|
360
|
+
}
|
361
|
+
return ac;
|
362
|
+
}
|
363
|
+
|
364
|
+
function createSWF(attObj, parObj, id) {
|
365
|
+
var r, el = getElementById(id);
|
366
|
+
if (ua.wk && ua.wk < 312) { return r; }
|
367
|
+
if (el) {
|
368
|
+
if (typeof attObj.id == UNDEF) {
|
369
|
+
attObj.id = id;
|
370
|
+
}
|
371
|
+
if (ua.ie && ua.win) {
|
372
|
+
var att = "";
|
373
|
+
for (var i in attObj) {
|
374
|
+
if (attObj[i] != Object.prototype[i]) {
|
375
|
+
if (i.toLowerCase() == "data") {
|
376
|
+
parObj.movie = attObj[i];
|
377
|
+
}
|
378
|
+
else if (i.toLowerCase() == "styleclass") {
|
379
|
+
att += ' class="' + attObj[i] + '"';
|
380
|
+
}
|
381
|
+
else if (i.toLowerCase() != "classid") {
|
382
|
+
att += ' ' + i + '="' + attObj[i] + '"';
|
383
|
+
}
|
384
|
+
}
|
385
|
+
}
|
386
|
+
var par = "";
|
387
|
+
for (var j in parObj) {
|
388
|
+
if (parObj[j] != Object.prototype[j]) {
|
389
|
+
par += '<param name="' + j + '" value="' + parObj[j] + '" />';
|
390
|
+
}
|
391
|
+
}
|
392
|
+
el.outerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + att + '>' + par + '</object>';
|
393
|
+
objIdArr[objIdArr.length] = attObj.id;
|
394
|
+
r = getElementById(attObj.id);
|
395
|
+
}
|
396
|
+
else {
|
397
|
+
var o = createElement(OBJECT);
|
398
|
+
o.setAttribute("type", FLASH_MIME_TYPE);
|
399
|
+
for (var m in attObj) {
|
400
|
+
if (attObj[m] != Object.prototype[m]) {
|
401
|
+
if (m.toLowerCase() == "styleclass") {
|
402
|
+
o.setAttribute("class", attObj[m]);
|
403
|
+
}
|
404
|
+
else if (m.toLowerCase() != "classid") {
|
405
|
+
o.setAttribute(m, attObj[m]);
|
406
|
+
}
|
407
|
+
}
|
408
|
+
}
|
409
|
+
for (var n in parObj) {
|
410
|
+
if (parObj[n] != Object.prototype[n] && n.toLowerCase() != "movie") {
|
411
|
+
createObjParam(o, n, parObj[n]);
|
412
|
+
}
|
413
|
+
}
|
414
|
+
el.parentNode.replaceChild(o, el);
|
415
|
+
r = o;
|
416
|
+
}
|
417
|
+
}
|
418
|
+
return r;
|
419
|
+
}
|
420
|
+
|
421
|
+
function createObjParam(el, pName, pValue) {
|
422
|
+
var p = createElement("param");
|
423
|
+
p.setAttribute("name", pName);
|
424
|
+
p.setAttribute("value", pValue);
|
425
|
+
el.appendChild(p);
|
426
|
+
}
|
427
|
+
|
428
|
+
function removeSWF(id) {
|
429
|
+
var obj = getElementById(id);
|
430
|
+
if (obj && obj.nodeName == "OBJECT") {
|
431
|
+
if (ua.ie && ua.win) {
|
432
|
+
obj.style.display = "none";
|
433
|
+
(function(){
|
434
|
+
if (obj.readyState == 4) {
|
435
|
+
removeObjectInIE(id);
|
436
|
+
}
|
437
|
+
else {
|
438
|
+
setTimeout(arguments.callee, 10);
|
439
|
+
}
|
440
|
+
})();
|
441
|
+
}
|
442
|
+
else {
|
443
|
+
obj.parentNode.removeChild(obj);
|
444
|
+
}
|
445
|
+
}
|
446
|
+
}
|
447
|
+
|
448
|
+
function removeObjectInIE(id) {
|
449
|
+
var obj = getElementById(id);
|
450
|
+
if (obj) {
|
451
|
+
for (var i in obj) {
|
452
|
+
if (typeof obj[i] == "function") {
|
453
|
+
obj[i] = null;
|
454
|
+
}
|
455
|
+
}
|
456
|
+
obj.parentNode.removeChild(obj);
|
457
|
+
}
|
458
|
+
}
|
459
|
+
|
460
|
+
function getElementById(id) {
|
461
|
+
var el = null;
|
462
|
+
try {
|
463
|
+
el = doc.getElementById(id);
|
464
|
+
}
|
465
|
+
catch (e) {}
|
466
|
+
return el;
|
467
|
+
}
|
468
|
+
|
469
|
+
function createElement(el) {
|
470
|
+
return doc.createElement(el);
|
471
|
+
}
|
472
|
+
|
473
|
+
function addListener(target, eventType, fn) {
|
474
|
+
target.attachEvent(eventType, fn);
|
475
|
+
listenersArr[listenersArr.length] = [target, eventType, fn];
|
476
|
+
}
|
477
|
+
|
478
|
+
function hasPlayerVersion(rv) {
|
479
|
+
var pv = ua.pv, v = rv.split(".");
|
480
|
+
v[0] = parseInt(v[0], 10);
|
481
|
+
v[1] = parseInt(v[1], 10) || 0;
|
482
|
+
v[2] = parseInt(v[2], 10) || 0;
|
483
|
+
return (pv[0] > v[0] || (pv[0] == v[0] && pv[1] > v[1]) || (pv[0] == v[0] && pv[1] == v[1] && pv[2] >= v[2])) ? true : false;
|
484
|
+
}
|
485
|
+
|
486
|
+
function createCSS(sel, decl, media, newStyle) {
|
487
|
+
if (ua.ie && ua.mac) { return; }
|
488
|
+
var h = doc.getElementsByTagName("head")[0];
|
489
|
+
if (!h) { return; }
|
490
|
+
var m = (media && typeof media == "string") ? media : "screen";
|
491
|
+
if (newStyle) {
|
492
|
+
dynamicStylesheet = null;
|
493
|
+
dynamicStylesheetMedia = null;
|
494
|
+
}
|
495
|
+
if (!dynamicStylesheet || dynamicStylesheetMedia != m) {
|
496
|
+
var s = createElement("style");
|
497
|
+
s.setAttribute("type", "text/css");
|
498
|
+
s.setAttribute("media", m);
|
499
|
+
dynamicStylesheet = h.appendChild(s);
|
500
|
+
if (ua.ie && ua.win && typeof doc.styleSheets != UNDEF && doc.styleSheets.length > 0) {
|
501
|
+
dynamicStylesheet = doc.styleSheets[doc.styleSheets.length - 1];
|
502
|
+
}
|
503
|
+
dynamicStylesheetMedia = m;
|
504
|
+
}
|
505
|
+
if (ua.ie && ua.win) {
|
506
|
+
if (dynamicStylesheet && typeof dynamicStylesheet.addRule == OBJECT) {
|
507
|
+
dynamicStylesheet.addRule(sel, decl);
|
508
|
+
}
|
509
|
+
}
|
510
|
+
else {
|
511
|
+
if (dynamicStylesheet && typeof doc.createTextNode != UNDEF) {
|
512
|
+
dynamicStylesheet.appendChild(doc.createTextNode(sel + " {" + decl + "}"));
|
513
|
+
}
|
514
|
+
}
|
515
|
+
}
|
516
|
+
|
517
|
+
function setVisibility(id, isVisible) {
|
518
|
+
if (!autoHideShow) { return; }
|
519
|
+
var v = isVisible ? "visible" : "hidden";
|
520
|
+
if (isDomLoaded && getElementById(id)) {
|
521
|
+
getElementById(id).style.visibility = v;
|
522
|
+
}
|
523
|
+
else {
|
524
|
+
createCSS("#" + id, "visibility:" + v);
|
525
|
+
}
|
526
|
+
}
|
527
|
+
|
528
|
+
function urlEncodeIfNecessary(s) {
|
529
|
+
var regex = /[\\\"<>\.;]/;
|
530
|
+
var hasBadChars = regex.exec(s) != null;
|
531
|
+
return hasBadChars && typeof encodeURIComponent != UNDEF ? encodeURIComponent(s) : s;
|
532
|
+
}
|
533
|
+
|
534
|
+
var cleanup = function() {
|
535
|
+
if (ua.ie && ua.win) {
|
536
|
+
window.attachEvent("onunload", function() {
|
537
|
+
var ll = listenersArr.length;
|
538
|
+
for (var i = 0; i < ll; i++) {
|
539
|
+
listenersArr[i][0].detachEvent(listenersArr[i][1], listenersArr[i][2]);
|
540
|
+
}
|
541
|
+
var il = objIdArr.length;
|
542
|
+
for (var j = 0; j < il; j++) {
|
543
|
+
removeSWF(objIdArr[j]);
|
544
|
+
}
|
545
|
+
for (var k in ua) {
|
546
|
+
ua[k] = null;
|
547
|
+
}
|
548
|
+
ua = null;
|
549
|
+
for (var l in swfobject) {
|
550
|
+
swfobject[l] = null;
|
551
|
+
}
|
552
|
+
swfobject = null;
|
553
|
+
});
|
554
|
+
}
|
555
|
+
}();
|
556
|
+
|
557
|
+
return {
|
558
|
+
registerObject: function(objectIdStr, swfVersionStr, xiSwfUrlStr, callbackFn) {
|
559
|
+
if (ua.w3 && objectIdStr && swfVersionStr) {
|
560
|
+
var regObj = {};
|
561
|
+
regObj.id = objectIdStr;
|
562
|
+
regObj.swfVersion = swfVersionStr;
|
563
|
+
regObj.expressInstall = xiSwfUrlStr;
|
564
|
+
regObj.callbackFn = callbackFn;
|
565
|
+
regObjArr[regObjArr.length] = regObj;
|
566
|
+
setVisibility(objectIdStr, false);
|
567
|
+
}
|
568
|
+
else if (callbackFn) {
|
569
|
+
callbackFn({success:false, id:objectIdStr});
|
570
|
+
}
|
571
|
+
},
|
572
|
+
|
573
|
+
getObjectById: function(objectIdStr) {
|
574
|
+
if (ua.w3) {
|
575
|
+
return getObjectById(objectIdStr);
|
576
|
+
}
|
577
|
+
},
|
578
|
+
|
579
|
+
embedSWF: function(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn) {
|
580
|
+
var callbackObj = {success:false, id:replaceElemIdStr};
|
581
|
+
if (ua.w3 && !(ua.wk && ua.wk < 312) && swfUrlStr && replaceElemIdStr && widthStr && heightStr && swfVersionStr) {
|
582
|
+
setVisibility(replaceElemIdStr, false);
|
583
|
+
addDomLoadEvent(function() {
|
584
|
+
widthStr += "";
|
585
|
+
heightStr += "";
|
586
|
+
var att = {};
|
587
|
+
if (attObj && typeof attObj === OBJECT) {
|
588
|
+
for (var i in attObj) {
|
589
|
+
att[i] = attObj[i];
|
590
|
+
}
|
591
|
+
}
|
592
|
+
att.data = swfUrlStr;
|
593
|
+
att.width = widthStr;
|
594
|
+
att.height = heightStr;
|
595
|
+
var par = {};
|
596
|
+
if (parObj && typeof parObj === OBJECT) {
|
597
|
+
for (var j in parObj) {
|
598
|
+
par[j] = parObj[j];
|
599
|
+
}
|
600
|
+
}
|
601
|
+
if (flashvarsObj && typeof flashvarsObj === OBJECT) {
|
602
|
+
for (var k in flashvarsObj) {
|
603
|
+
if (typeof par.flashvars != UNDEF) {
|
604
|
+
par.flashvars += "&" + k + "=" + flashvarsObj[k];
|
605
|
+
}
|
606
|
+
else {
|
607
|
+
par.flashvars = k + "=" + flashvarsObj[k];
|
608
|
+
}
|
609
|
+
}
|
610
|
+
}
|
611
|
+
if (hasPlayerVersion(swfVersionStr)) {
|
612
|
+
var obj = createSWF(att, par, replaceElemIdStr);
|
613
|
+
if (att.id == replaceElemIdStr) {
|
614
|
+
setVisibility(replaceElemIdStr, true);
|
615
|
+
}
|
616
|
+
callbackObj.success = true;
|
617
|
+
callbackObj.ref = obj;
|
618
|
+
}
|
619
|
+
else if (xiSwfUrlStr && canExpressInstall()) {
|
620
|
+
att.data = xiSwfUrlStr;
|
621
|
+
showExpressInstall(att, par, replaceElemIdStr, callbackFn);
|
622
|
+
return;
|
623
|
+
}
|
624
|
+
else {
|
625
|
+
setVisibility(replaceElemIdStr, true);
|
626
|
+
}
|
627
|
+
if (callbackFn) { callbackFn(callbackObj); }
|
628
|
+
});
|
629
|
+
}
|
630
|
+
else if (callbackFn) { callbackFn(callbackObj); }
|
631
|
+
},
|
632
|
+
|
633
|
+
switchOffAutoHideShow: function() {
|
634
|
+
autoHideShow = false;
|
635
|
+
},
|
636
|
+
|
637
|
+
ua: ua,
|
638
|
+
|
639
|
+
getFlashPlayerVersion: function() {
|
640
|
+
return { major:ua.pv[0], minor:ua.pv[1], release:ua.pv[2] };
|
641
|
+
},
|
642
|
+
|
643
|
+
hasFlashPlayerVersion: hasPlayerVersion,
|
644
|
+
|
645
|
+
createSWF: function(attObj, parObj, replaceElemIdStr) {
|
646
|
+
if (ua.w3) {
|
647
|
+
return createSWF(attObj, parObj, replaceElemIdStr);
|
648
|
+
}
|
649
|
+
else {
|
650
|
+
return undefined;
|
651
|
+
}
|
652
|
+
},
|
653
|
+
|
654
|
+
showExpressInstall: function(att, par, replaceElemIdStr, callbackFn) {
|
655
|
+
if (ua.w3 && canExpressInstall()) {
|
656
|
+
showExpressInstall(att, par, replaceElemIdStr, callbackFn);
|
657
|
+
}
|
658
|
+
},
|
659
|
+
|
660
|
+
removeSWF: function(objElemIdStr) {
|
661
|
+
if (ua.w3) {
|
662
|
+
removeSWF(objElemIdStr);
|
663
|
+
}
|
664
|
+
},
|
665
|
+
|
666
|
+
createCSS: function(selStr, declStr, mediaStr, newStyleBoolean) {
|
667
|
+
if (ua.w3) {
|
668
|
+
createCSS(selStr, declStr, mediaStr, newStyleBoolean);
|
669
|
+
}
|
670
|
+
},
|
671
|
+
|
672
|
+
addDomLoadEvent: addDomLoadEvent,
|
673
|
+
|
674
|
+
addLoadEvent: addLoadEvent,
|
675
|
+
|
676
|
+
getQueryParamValue: function(param) {
|
677
|
+
var q = doc.location.search || doc.location.hash;
|
678
|
+
if (q) {
|
679
|
+
if (/\?/.test(q)) { q = q.split("?")[1]; }
|
680
|
+
if (param == null) {
|
681
|
+
return urlEncodeIfNecessary(q);
|
682
|
+
}
|
683
|
+
var pairs = q.split("&");
|
684
|
+
for (var i = 0; i < pairs.length; i++) {
|
685
|
+
if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
|
686
|
+
return urlEncodeIfNecessary(pairs[i].substring((pairs[i].indexOf("=") + 1)));
|
687
|
+
}
|
688
|
+
}
|
689
|
+
}
|
690
|
+
return "";
|
691
|
+
},
|
692
|
+
|
693
|
+
expressInstallCallback: function() {
|
694
|
+
if (isExpressInstallActive) {
|
695
|
+
var obj = getElementById(EXPRESS_INSTALL_ID);
|
696
|
+
if (obj && storedAltContent) {
|
697
|
+
obj.parentNode.replaceChild(storedAltContent, obj);
|
698
|
+
if (storedAltContentId) {
|
699
|
+
setVisibility(storedAltContentId, true);
|
700
|
+
if (ua.ie && ua.win) { storedAltContent.style.display = "block"; }
|
701
|
+
}
|
702
|
+
if (storedCallbackFn) { storedCallbackFn(storedCallbackObj); }
|
703
|
+
}
|
704
|
+
isExpressInstallActive = false;
|
705
|
+
}
|
706
|
+
}
|
707
|
+
};
|
708
|
+
}();
|