-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplayer.js
240 lines (233 loc) · 7.45 KB
/
player.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
/ _|
__ _ _ _ _ __ ___ _ __ __ _ | |_ ___ ___ ___
/ _` | | | | '__/ _ \| '__/ _` | | _/ _ \/ __/ __|
| (_| | |_| | | | (_) | | | (_| | | || (_) \__ \__ \
\__,_|\__,_|_| \___/|_| \__,_| |_| \___/|___/___/
Copyright (C) 2015 Adrian C Shum
Copyright (C) 2018 Aurora Free Open Source Software.
This file is part of the Aurora Free Open Source Software. This
organization promote free and open source software that you can
redistribute and/or modify under the terms of the GNU General Public
License Version 3 as published by the Free Software Foundation or (at your
option) any later version approved by the Aurora Free Open Source Software
Organization. The license is available in the package root path as
'LICENSE' file. Please review the following information to ensure the GNU
General Public License requirements will be met:
https://www.gnu.org/licenses/gpl-3.0.html .
NOTE: All products, services or anything associated to trademarks and
service marks used or referenced on this file are the property of their
respective companies/owners or its subsidiaries. Other names and brands
may be claimed as the property of others.
For more info about intellectual property visit: aurorafoss.org or
directly send an email to: contact (at) aurorafoss.org .
*/
(function ()
{
var scripts = document.getElementsByTagName('script'),
current = scripts[scripts.length - 1],
rwpsrc = current.getAttribute('src');
if (rwpsrc.indexOf('//') == -1)
if (rwpsrc.substr(0, 1) == '/')
rwpsrc = location.origin + rwpsrc;
else
{
var rwppath = location.pathname;
rwpsrc = location.origin + rwppath.substr(0, rwppath.lastIndexOf("/")) + "/" + rwpsrc;
}
var hasFrame = window.parent != window,
config = current.getAttribute('data-config'),
head = document.getElementsByTagName("head")[0],
dest = location.href.replace(/rwplayer\=true/g, 'rwplayer=false'),
destHost = dest.substr(0, dest.indexOf('/', 10)),
rwp = rwpsrc.replace(/player\.js.*/g, 'player.html') + '#' + dest,
rwpHost = rwp.substr(0, rwp.indexOf('/', 10)),
isOutside = !hasFrame || location.href.indexOf("rwplayer=true") > 0,
postMessage = function (msg)
{
return window.top.document.getElementById('rwpframe')
.contentWindow.postMessage(msg, rwpHost);
},
postFactory = function (obj, keys)
{
var keys = keys.split(','),
post = function (key)
{
return function (arg)
{
var argStr = '';
if (typeof (arg) != 'undefined')
argStr = (key.match(/(play|queue)/) ? 'new Song(' : '(') +
JSON.stringify(arg) + ')';
postMessage('RWP.' + key + '(' + argStr + ')');
}
};
for (var i = 0; i < keys.length; i++)
{
var key = keys[i];
obj[key] = post(key);
}
},
postConfig = function (config)
{
if (!isOutside)
postMessage('RWP.config(' + config + ')');
},
addEvent = function (elm, evType, fn)
{
if (elm.addEventListener)
elm.addEventListener(evType, fn);
else if (elm.attachEvent)
elm.attachEvent('on' + evType, fn);
else
elm['on' + evType] = fn;
},
isIE = (function ()
{
var undef, v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->', all[0]);
return v > 4 ? v : undef;
})(),
init = function ()
{
if (!document.body)
{
setTimeout(init, 10);
return;
}
if (isOutside) outside();
else inside();
},
outside = function ()
{
var css = 'html,body{overflow:hidden;} body{margin:0;padding:0;border:0;} img,a,embed,object,div,address,table,iframe,p,span,form,header,section,footer{ display:none;border:0;margin:0;padding:0; } #tumblr_controls{display:none;} #rwpframe{display:block; background-color:transparent; position:fixed; top:0px; left:0px; width:100%; height:100%; z-index:1667;} ';
var style = document.createElement('style');
style.type = 'text/css';
style.id = 'rwpcss';
if (style.styleSheet) style.styleSheet.cssText = css;
else style.appendChild(document.createTextNode(css));
head.appendChild(style);
var rwpframe = document.createElement('iframe');
rwpframe.frameBorder = 0;
rwpframe.id = "rwpframe";
rwpframe.allowTransparency = true;
rwpframe.src = rwp;
document.body.insertBefore(rwpframe, document.body.firstChild);
var resize = function ()
{
rwpframe.style.height = (function ()
{
if (typeof (window.innerHeight) == 'number')
return window.innerHeight;
else if (document.documentElement && document.documentElement.clientHeight)
return document.documentElement.clientHeight;
else if (document.body && document.body.clientHeight)
return document.body.clientHeight;
})();
};
addEvent(window, 'load', function ()
{
setTimeout(function ()
{
while (document.body.firstChild != rwpframe)
document.body.removeChild(document.body.firstChild);
while (document.body.lastChild != rwpframe)
document.body.removeChild(document.body.lastChild);
resize();
}, 0);
});
addEvent(window, 'resize', resize);
var getPath = function ()
{
return location.href.replace(/#.*/, '');
},
path = getPath(),
hash = location.hash;
setInterval(function ()
{
if (getPath() != path)
{
path = getPath();
window.rwpinside.location.replace(path);
}
if (location.hash != hash)
{
hash = location.hash;
window.rwpinside.location.hash = hash;
}
}, 100);
},
inside = function ()
{
window.top.document.title = document.title;
var filter = function (host)
{
host = host.replace(/blogspot.[a-z.]*/i, 'blogspot.com');
host = host.replace(/^(http(s)?:\/\/)?(www.)?/i, '');
return host;
};
addEvent(document.body, 'click', function (e)
{
var tar = e.target;
while (!tar.tagName.match(/^(a|area)$/i) && tar != document.body)
tar = tar.parentNode;
if (tar.tagName.match(/^(a|area)$/i) && !tar.href.match(/.(jpg|png)$/i) && !tar.href.match(/^javascript:/))
{
if (tar.href.indexOf('#') == 0)
{
if (tar.href != "#")
{
window.top.rwpinside = window;
window.top.location.hash = location.hash;
e.preventDefault();
}
}
else if (tar.title.match(/^(RWP:|\[RWP\])/i))
{
var title = tar.title.replace(/^(RWP:|\[RWP\])( )?/i, '');
var url = tar.href;
RWP.play(
{
title: title,
url: url
});
e.preventDefault();
}
else if (tar.href.match(/\.css$/))
{
window.open('//rwplayer.aurorafoss.org/#skin=' + tar.href, '_blank');
window.focus();
e.preventDefault();
}
else if (filter(tar.href).indexOf(filter(location.host)) == -1)
{
if (tar.href.match(/^http(s)?/))
{
window.open(tar.href, '_blank');
window.focus();
e.preventDefault();
}
}
else if (history.pushState)
{
var url = filter(tar.href).replace(filter(destHost), '');
window.top.rwpinside = window;
window.top.history.pushState(null, null, url);
e.preventDefault();
}
}
});
};
var RWP = {};
postFactory(RWP, 'queue,play,pause,next,previous,volume,skin,placement,' +
'loadPlaylist,repeatMode,isShuffle,showPlaylist,' +
'togglePlaylist,toggleShuffle,changeRepeatMode');
if (window.RWP && window.RWPMusicPlayer) return;
init();
if (config) postConfig(config);
RWP.init = postConfig;
window.RWPMusicPlayer = window.RWPMusicPlayer || RWP;
window.RWP = window.RWP || RWP;
})();