Push to github

This commit is contained in:
calzoneman 2013-02-15 23:02:42 -06:00
commit 68fc74edd5
26 changed files with 22097 additions and 0 deletions

1109
www/assets/css/bootstrap-responsive.css vendored Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

6158
www/assets/css/bootstrap.css vendored Normal file

File diff suppressed because it is too large Load diff

9
www/assets/css/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

75
www/assets/css/ytsync.css Normal file
View file

@ -0,0 +1,75 @@
.videolist {
list-style: none outside none;
margin-left: 0;
max-height: 500px;
overflow-y: scroll;
}
.videolist li {
margin: 2px 0 0 auto;
padding: 2px;
font-size: 8pt;
border: 1px solid #aaaaaa; // [](/w21)
}
.qe_btn {
height: 20px;
font-family: Monospace;
padding: 0 5px;
margin: auto;
overflow: hidden;
}
.qe_buttons {
float: left;
}
.qe_title {
float: left;
}
.qe_time {
float: right;
}
.qe_clear {
clear: both;
}
#library {
width: 640px;
}
#userlist {
overflow-y: scroll;
overflow-x: hidden;
height: 360px;
float: left;
width: 200px;
border: 1px solid #aaaaaa; // [](/z13)
}
#messagebuffer {
overflow-y: scroll;
height: 360px;
border: 1px solid #aaaaaa; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa
border-left: 0;
}
#chatline {
width: 100%;
}
.userlist_siteadmin {
color: #cc0000;
font-weight: bold;
}
.userlist_owner {
color: #0000cc;
font-weight: bold;
}
.userlist_op {
color: #00cc00;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

2268
www/assets/js/bootstrap.js vendored Normal file

File diff suppressed because it is too large Load diff

6
www/assets/js/bootstrap.min.js vendored Normal file

File diff suppressed because one or more lines are too long

194
www/assets/js/callbacks.js Normal file
View file

@ -0,0 +1,194 @@
// Wrapped in a function so I can ensure that the socket
// is defined before these statements are run
function initCallbacks() {
socket.on('disconnect', function() {
$('<div/>').addClass('alert').addClass('alert-error')
.insertAfter($('.row')[0])[0]
.innerHTML = "<h3>Disconnected from server</h3>";
});
socket.on('rank', function(data) {
if(data.rank >= Rank.Moderator)
$('#playlist_controls').css("display", "block");
RANK = data.rank;
});
socket.on('login', function(data) {
if(!data.success)
alert(data.error);
else {
$('#welcome')[0].innerHTML = "Welcome, " + uname;
$('#loginform').css("display", "none");
$('#loggedin').css("display", "block");
if(pw != "") {
createCookie('sync_uname', uname, 1);
createCookie('sync_pw', pw, 1);
}
}
});
socket.on('register', function(data) {
if(data.error) {
alert(data.error);
}
});
socket.on('chatMsg', function(data) {
var div = document.createElement('div');
var span = document.createElement('span');
$(span).addClass(data.msgclass);
span.innerHTML = "<strong>&lt;" + data.username + "&gt;</strong> " + data.msg;
div.appendChild(span);
$('#messagebuffer')[0].appendChild(div);
// Cap chatbox at most recent 100 messages
if($('#messagebuffer').children().length > 100) {
$($('#messagebufer').children()[0]).remove();
}
$('#messagebuffer').scrollTop($('#messagebuffer').prop("scrollHeight"));
});
socket.on('playlist', function(data) {
var ul = $('#queue')[0];
var n = ul.children.length;
for(var i = 0; i < n; i++) {
ul.removeChild(ul.children[0]);
}
for(var i = 0; i < data.pl.length; i++) {
var li = makeQueueEntry(data.pl[i]);
if(RANK >= Rank.Moderator)
addQueueButtons(li);
$(li).appendTo(ul);
}
});
socket.on('queue', function(data) {
var li = makeQueueEntry(data.media);
if(RANK >= Rank.Moderator)
addQueueButtons(li);
$(li).css('display', 'none');
var idx = data.pos;
var ul = $('#queue')[0];
$(li).appendTo(ul);
if(idx < ul.children.length - 1)
moveVideo(ul.children.length - 1, idx);
$(li).show('blind');
});
socket.on('unqueue', function(data) {
if(data.pos == POSITION && $('#queue').children().length > POSITION + 1) {
$($('#queue').children()[POSITION+1]).addClass("alert alert-info");
}
var li = $('#queue').children()[data.pos];
$(li).hide('blind', function() {
$(li).remove();
});
});
socket.on('moveVideo', function(data) {
moveVideo(data.src, data.dest);
});
socket.on('updatePlaylistIdx', function(data) {
var liold = $('#queue').children()[POSITION];
$(liold).removeClass("alert alert-info");
var linew = $('#queue').children()[data.idx];
$(linew).addClass("alert alert-info");
POSITION= data.idx;
});
socket.on('mediaUpdate', function(data) {
if(data.type == "yt")
updateYT(data);
else if(data.type == "tw")
loadTwitch(data.id);
else if(data.type == "sc")
updateSC(data);
else if(data.type == "vi")
updateVI(data);
});
socket.on('userlist', function(data) {
for(var i = 0; i < data.length; i++) {
addUser(data[i].name, data[i].rank, data[i].leader);
}
});
socket.on('addUser', function(data) {
addUser(data.name, data.rank, data.leader);
});
socket.on('updateUser', function(data) {
if(data.name == uname) {
LEADER = data.leader;
if(LEADER) {
// I'm a leader! Set up sync function
sendVideoUpdate = function() {
if(MEDIATYPE == "yt") {
socket.emit('mediaUpdate', {
id: parseYTURL(PLAYER.getVideoUrl()),
seconds: PLAYER.getCurrentTime(),
paused: PLAYER.getPlayerState() == YT.PlayerState.PAUSED,
type: "yt"
});
}
else if(MEDIATYPE == "sc") {
PLAYER.getPosition(function(pos) {
socket.emit('mediaUpdate', {
id: PLAYER.mediaId,
seconds: pos / 1000,
paused: false,
type: "sc"
});
});
}
else if(MEDIATYPE == "vi") {
PLAYER.api('getCurrentTime', function(data) {
socket.emit('mediaUpdate', {
id: PLAYER.videoid,
seconds: data.seconds,
paused: false,
type: "vi"
});
});
}
};
}
// I'm not a leader. Don't send syncs to the server
else {
sendVideoUpdate = function() { }
}
}
var users = $('#userlist').children();
for(var i = 0; i < users.length; i++) {
var name = users[i].children[1].innerText;
// Reformat user
if(name == data.name) {
fmtUserlistItem(users[i], data.rank, data.leader);
}
}
});
socket.on('userLeave', function(data) {
var users = $('#userlist').children();
for(var i = 0; i < users.length; i++) {
var name = users[i].children[1].innerText;
if(name == data.name) {
$('#userlist')[0].removeChild(users[i]);
}
}
});
socket.on('librarySearchResults', function(data) {
var n = $('#library').children().length;
for(var i = 0; i < n; i++) {
$('#library')[0].removeChild($('#library').children()[0]);
}
var ul = $('#library')[0];
for(var i = 0; i < data.results.length; i++) {
var li = makeQueueEntry(data.results[i]);
if(RANK >= Rank.Moderator)
addLibraryButtons(li, data.results[i].id);
$(li).appendTo(ul);
}
});
}

237
www/assets/js/client.js Normal file
View file

@ -0,0 +1,237 @@
const IO_URL = "http://somewebsite:1337";
const SYNC_THRESHOLD = 2;
var LEADER = false;
var PLAYER = false;
var MEDIATYPE = "yt";
var POSITION = -1;
var RANK = 0;
var uname = readCookie('sync_uname');
var pw = readCookie('sync_pw');
var Rank = {
Guest: 0,
Member: 1,
Moderator: 4,
Owner: 8,
Siteadmin: 255
};
var socket = io.connect(IO_URL);
initCallbacks();
var params = {};
if(window.location.search) {
var parameters = window.location.search.substring(1).split('&');
for(var i = 0; i < parameters.length; i++) {
var s = parameters[i].split('=');
if(s.length != 2)
continue;
params[s[0]] = s[1];
}
}
if(params['channel'] == undefined) {
var main = $($('.container')[1]);
var container = $('<div/>').addClass('container').insertBefore(main);
var row = $('<div/>').addClass('row').appendTo(container);
var div = $('<div/>').addClass('span6').appendTo(row);
main.css("display", "none");
var label = $('<label/>').text('Enter Channel:').appendTo(div);
var entry = $('<input/>').attr('type', 'text').appendTo(div);
entry.keydown(function(ev) {
if(ev.keyCode == 13) {
document.location = document.location + "?channel=" + entry.val();
socket.emit('joinChannel', {
name: entry.val()
});
container.remove();
main.css("display", "");
}
});
}
else {
socket.emit('joinChannel', {
name: params['channel']
});
}
// Load the youtube iframe API
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
if(uname != null && pw != null && pw != "false") {
socket.emit('login', {
name: uname,
sha256: pw
});
}
var sendVideoUpdate = function() { }
setInterval(function() {
sendVideoUpdate();
}, 5000);
$('#queue_end').click(function() {
var parsed = parseVideoURL($('#mediaurl').val());
var id = parsed[0];
var type = parsed[1];
if(id) {
$('#mediaurl').val("");
}
socket.emit('queue', {
id: id,
pos: "end",
type: type
});
});
$('#queue_next').click(function() {
var parsed = parseVideoURL($('#mediaurl').val());
var id = parsed[0];
var type = parsed[1];
if(id) {
$('#mediaurl').val("");
}
socket.emit('queue', {
id: id,
pos: "next",
type: type
});
});
$('#play_next').click(function() {
socket.emit('playNext');
});
function loginClick() {
uname = $('#username').val();
if($('#password').val() == "")
pw = "";
else
pw = SHA256($('#password').val());
socket.emit('login', {
name: uname,
sha256: pw
});
};
$('#login').click(loginClick);
$('#username').keydown(function(ev) {
if(ev.key == 13)
loginClick();
});
$('#password').keydown(function(ev) {
if(ev.key == 13)
loginClick();
});
$('#logout').click(function() {
eraseCookie('sync_uname');
eraseCookie('sync_pw');
document.location.reload(true);
});
$('#register').click(function() {
uname = $('#username').val();
if($('#password').val() == "")
pw = "";
else
pw = SHA256($('#password').val());
socket.emit('register', {
name: uname,
sha256: pw
});
});
$('#chatline').keydown(function(ev) {
if(ev.keyCode == 13) {
socket.emit('chatMsg', {
msg: $('#chatline').val()
});
$('#chatline').val('');
}
});
function searchLibrary() {
socket.emit('searchLibrary', {
query: $('#library_query').val()
});
}
$('#library_search').click(searchLibrary);
$('#library_query').keydown(function(ev) {
if(ev.key == 13)
searchLibrary();
});
function onYouTubeIframeAPIReady() {
PLAYER = new YT.Player('ytapiplayer', {
height: '390',
width: '640',
videoId: '',
playerVars: {
'autoplay': 0,
'controls': 1,
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady() {
socket.emit('playerReady');
}
function onPlayerStateChange(state) {
if(LEADER && state.data == YT.PlayerState.ENDED) {
socket.emit('playNext');
}
else if(LEADER && state.data == YT.PlayerState.PAUSED) {
socket.emit('mediaUpdate', {
id: parseYTURL(PLAYER.getVideoUrl()),
seconds: PLAYER.getCurrentTime(),
type: "yt",
paused: true
});
}
if(LEADER && state.data == YT.PlayerState.PLAYING) {
socket.emit('mediaUpdate', {
id: parseYTURL(PLAYER.getVideoUrl()),
seconds: PLAYER.getCurrentTime(),
type: "yt",
paused: false
});
}
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}

4
www/assets/js/froogaloop.min.js vendored Normal file
View file

@ -0,0 +1,4 @@
var Froogaloop=function(){function e(a){return new e.fn.init(a)}function h(a,c,b){if(!b.contentWindow.postMessage)return!1;var f=b.getAttribute("src").split("?")[0],a=JSON.stringify({method:a,value:c});"//"===f.substr(0,2)&&(f=window.location.protocol+f);b.contentWindow.postMessage(a,f)}function j(a){var c,b;try{c=JSON.parse(a.data),b=c.event||c.method}catch(f){}"ready"==b&&!i&&(i=!0);if(a.origin!=k)return!1;var a=c.value,e=c.data,g=""===g?null:c.player_id;c=g?d[g][b]:d[b];b=[];if(!c)return!1;void 0!==
a&&b.push(a);e&&b.push(e);g&&b.push(g);return 0<b.length?c.apply(null,b):c.call()}function l(a,c,b){b?(d[b]||(d[b]={}),d[b][a]=c):d[a]=c}var d={},i=!1,k="";e.fn=e.prototype={element:null,init:function(a){"string"===typeof a&&(a=document.getElementById(a));this.element=a;a=this.element.getAttribute("src");"//"===a.substr(0,2)&&(a=window.location.protocol+a);for(var a=a.split("/"),c="",b=0,f=a.length;b<f;b++){if(3>b)c+=a[b];else break;2>b&&(c+="/")}k=c;return this},api:function(a,c){if(!this.element||
!a)return!1;var b=this.element,f=""!==b.id?b.id:null,d=!c||!c.constructor||!c.call||!c.apply?c:null,e=c&&c.constructor&&c.call&&c.apply?c:null;e&&l(a,e,f);h(a,d,b);return this},addEvent:function(a,c){if(!this.element)return!1;var b=this.element,d=""!==b.id?b.id:null;l(a,c,d);"ready"!=a?h("addEventListener",a,b):"ready"==a&&i&&c.call(null,d);return this},removeEvent:function(a){if(!this.element)return!1;var c=this.element,b;a:{if((b=""!==c.id?c.id:null)&&d[b]){if(!d[b][a]){b=!1;break a}d[b][a]=null}else{if(!d[a]){b=
!1;break a}d[a]=null}b=!0}"ready"!=a&&b&&h("removeEventListener",a,c)}};e.fn.init.prototype=e.fn;window.addEventListener?window.addEventListener("message",j,!1):window.attachEvent("onmessage",j);return window.Froogaloop=window.$f=e}();

385
www/assets/js/functions.js Normal file
View file

@ -0,0 +1,385 @@
// Adds a user to the chatbox userlist
function addUser(name, rank, leader) {
var div = document.createElement('div');
$(div).attr("class", "userlist_item");
var span = document.createElement('span');
var flair = document.createElement('span');
span.innerHTML = name;
div.appendChild(flair);
div.appendChild(span);
fmtUserlistItem(div, rank, leader);
addUserDropdown(div, name);
$('#userlist')[0].appendChild(div);
}
// Format a userlist entry based on a person's rank
function fmtUserlistItem(div, rank, leader) {
var span = div.children[1];
if(rank >= Rank.Siteadmin)
$(span).attr("class", "userlist_siteadmin");
else if(rank >= Rank.Owner)
$(span).attr("class", "userlist_owner");
else if(rank >= Rank.Moderator)
$(span).attr("class", "userlist_op");
var flair = div.children[0];
// denote current leader with [L]
if(leader) {
flair.innerHTML = "[L]";
}
else {
flair.innerHTML = "";
}
}
// Adds a dropdown with user actions (promote/demote/leader)
function addUserDropdown(entry, name) {
var div = $('<div />').addClass("dropdown").appendTo(entry);
var ul = $('<ul />').addClass("dropdown-menu").appendTo(div);
ul.attr("role", "menu");
ul.attr("aria-labelledby", "dropdownMenu");
var makeLeader = $('<li />').appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(makeLeader);
a.text("Make Leader");
a.click(function() {
socket.emit('assignLeader', {
name: name
});
});
var takeLeader = $('<li />').appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(takeLeader);
a.text("Take Leader");
a.click(function() {
socket.emit('assignLeader', {
name: ""
});
});
$('<li />').addClass("divider").appendTo(ul);
var promote = $('<li />').appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(promote);
a.text("Promote");
a.click(function() {
socket.emit('promote', {
name: name
});
});
var demote = $('<li />').appendTo(ul);
var a = $('<a />').attr("tabindex", "-1").attr("href", "#").appendTo(demote);
a.text("Demote");
a.click(function() {
socket.emit('demote', {
name: name
});
});
$(entry).click(function() {
if(ul.css("display") == "none") {
ul.css("display", "block");
}
else {
ul.css("display", "none");
}
});
return ul;
}
// Creates and formats a queue entry
function makeQueueEntry(video) {
var li = $('<li />');
li.attr("class", "well");
var title = $('<span />').attr("class", "qe_title").appendTo(li);
title.text(video.title);
var time = $('<span />').attr("class", "qe_time").appendTo(li);
time.text(video.duration);
var clear = $('<div />').attr("class", "qe_clear").appendTo(li);
return li;
}
// Add buttons to a queue list entry
function addQueueButtons(li) {
var btnstrip = $('<div />').attr("class", "btn-group qe_buttons").prependTo(li);
var btnRemove = $('<button />').attr("class", "btn btn-danger qe_btn").appendTo(btnstrip);
$('<i />').attr("class", "icon-remove").appendTo(btnRemove);
var btnUp = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip);
$('<i />').attr("class", "icon-arrow-up").appendTo(btnUp);
var btnDown = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip);
$('<i />').attr("class", "icon-arrow-down").appendTo(btnDown);
var btnNext = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip);
$('<i />').attr("class", "icon-play").appendTo(btnNext);
// Callback time
$(btnRemove).click(function() {
var idx = $('#queue').children().index(li);
socket.emit('unqueue', { pos: idx });
});
$(btnUp).click(function() {
var idx = $('#queue').children().index(li);
socket.emit('moveMedia', {
src: idx,
dest: idx-1
});
});
$(btnDown).click(function() {
var idx = $('#queue').children().index(li);
socket.emit('moveMedia', {
src: idx,
dest: idx+1
});
});
$(btnNext).click(function() {
var idx = $('#queue').children().index(li);
var dest = idx < POSITION ? POSITION : POSITION + 1;
socket.emit('moveMedia', {
src: idx,
dest: dest
});
});
}
// Add buttons to a list entry for the library search results
function addLibraryButtons(li, id) {
var btnstrip = $('<div />').attr("class", "btn-group qe_buttons").prependTo(li);
var btnNext = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip);
$('<i />').attr("class", "icon-play").appendTo(btnNext);
var btnEnd = $('<button />').attr("class", "btn qe_btn").appendTo(btnstrip);
$('<i />').attr("class", "icon-fast-forward").appendTo(btnEnd);
// Callback time
$(btnNext).click(function() {
socket.emit('queue', {
id: id,
pos: "next"
});
});
$(btnEnd).click(function() {
socket.emit('queue', {
id: id,
pos: "end"
});
});
}
// Rearranges the queue
function moveVideo(src, dest) {
var li = $('#queue').children()[src];
var ul = $('#queue')[0];
$(li).hide('blind', function() {
ul.removeChild(li);
if(dest == ul.children.length) {
ul.appendChild(li);
}
else {
ul.insertBefore(li, ul.getElementsByTagName('li')[dest]);
}
$(li).show('blind');
});
if(src < POSITION && dest >= POSITION)
POSITION--;
if(src > POSITION && dest < POSITION)
POSITION++;
}
// YouTube Synchronization
function updateYT(data) {
if(MEDIATYPE != "yt") {
removeCurrentPlayer();
MEDIATYPE = "yt";
// Note to Soundcloud/Vimeo API designers:
// YouTube's API is actually nice to use
PLAYER = new YT.Player('ytapiplayer', {
height: '390',
width: '640',
videoId: '',
playerVars: {
'autoplay': 0,
'controls': 1,
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// Load new video
if(PLAYER.getVideoUrl && data.id != parseYTURL(PLAYER.getVideoUrl())) {
PLAYER.loadVideoById(data.id, data.currentTime, $('#quality').val());
if(data.paused)
PLAYER.pauseVideo();
}
// Sync playback time
else if(PLAYER.seekTo) {
if(Math.abs(PLAYER.getCurrentTime() - data.currentTime) > SYNC_THRESHOLD)
PLAYER.seekTo(data.currentTime, true);
if(!data.paused)
PLAYER.playVideo();
}
}
// Soundcloud synchronization
function updateSC(data) {
if(MEDIATYPE != "sc") {
var currentEmbed = $("#ytapiplayer");
var iframe = $("<iframe/>").insertBefore(currentEmbed);
currentEmbed.remove();
iframe.attr("id","ytapiplayer");
iframe.attr("src", "https://w.soundcloud.com/player/?url=");
iframe.css("width", "100%").attr("height", "166")
.attr("frameborder", "no");
PLAYER = SC.Widget('ytapiplayer');
MEDIATYPE = "sc";
}
// Server is on a different soundcloud track than client
if(PLAYER.mediaId != data.id) {
PLAYER.load(data.id, {
auto_play: true
});
// Keep track of current ID
PLAYER.mediaId = data.id;
}
// Soundcloud's API is async
// Query the playback position and compare that with the sync packet
PLAYER.getPosition(function(pos) {
if(Math.abs(pos - data.currentTime * 1000) > SYNC_THRESHOLD) {
PLAYER.seekTo(data.currentTime * 1000);
}
});
}
// Vimeo synchronization
// URGH building a synchronizing tool is so frustrating when
// these APIs are designed to be async
function updateVI(data) {
if(MEDIATYPE != "vi") {
initVI(data);
}
// Either vimeo's API doesn't support loading a new video
// or their terrible documentation doesn't document it
else if(data.id != PLAYER.videoid) {
initVI(data);
}
// Hack because of their async api
// Set this and wait for playProgress to fire to compare it
PLAYER.lastUpdate = data;
}
// Loads up a Vimeo player
function initVI(data) {
var currentEmbed = $("#ytapiplayer");
var div = currentEmbed.parent();
currentEmbed.remove();
// Ugly but it's the only way I managed to get the API calls to work
div[0].innerHTML = '<iframe id="ytapiplayer" src="http://player.vimeo.com/video/' + data.id + '" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
// $f() is defined by froogaloop, Vimeo's API wrapper
PLAYER = $f($('iframe')[0]);
// So we can retrieve the ID synchronously instead of waiting for
// getVideoId with a callback
PLAYER.videoid = data.id;
PLAYER.addEvent('ready', function() {
// Autoplay
PLAYER.api('play');
// Watch the progress and compare it with the most recent sync
PLAYER.addEvent('playProgress', function(data, id) {
if(Math.abs(parseInt(data.seconds) - PLAYER.lastUpdate.currentTime) > SYNC_THRESHOLD) {
PLAYER.api('seekTo', PLAYER.lastUpdate.currentTime);
}
});
});
MEDIATYPE = "vi";
}
function loadTwitch(channel) {
MEDIATYPE = "tw";
removeCurrentPlayer();
var url = "http://www.twitch.tv/widgets/live_embed_player.swf?channel="+channel;
var params = {
allowFullScreen:"true",
allowScriptAccess:"always",
allowNetworking:"all",
movie:"http://www.twitch.tv/widgets/live_embed_player.swf",
id: "live_embed_player_flash",
flashvars:"hostname=www.twitch.tv&channel="+channel+"&auto_play=true&start_volume=100"
};
swfobject.embedSWF( url, "ytapiplayer", '640', '390', "8", null, null, params, {} );
}
function removeCurrentPlayer(){
var currentEmbed = $("#ytapiplayer");
var placeholder = $("<div/>").insertBefore(currentEmbed);
currentEmbed.remove();
placeholder.attr("id","ytapiplayer");
}
function parseVideoURL(url){
if(typeof(url) != "string")
return null;
if(url.indexOf("youtu") != -1)
return [parseYTURL(url), "yt"];
else if(url.indexOf("twitch") != -1)
return [parseTwitch(url), "tw"];
else if(url.indexOf("soundcloud") != -1)
return [url, "sc"];
else if(url.indexOf("vimeo") != -1)
return [parseVimeo(url), "vi"];
}
function parseYTURL(url) {
url = url.replace("feature=player_embedded&", "");
if(url.indexOf("&list=") != -1)
url = url.substring(0, url.indexOf("&list="));
var m = url.match(/youtube\.com\/watch\\?v=([^&]*)/);
if(m) {
// Extract ID
return m[1];
}
var m = url.match(/youtu\.be\/([^&]*)/);
if(m) {
// Extract ID
return m[1];
}
// Final try
var m = url.match(/v=([^&]*)/);
if(m) {
// Extract ID
return m[1];
}
return null;
}
function parseTwitch(url) {
var m = url.match(/twitch\.tv\/([a-zA-Z0-9]*)/);
if(m) {
// Extract channel name
return m[1];
}
return null;
}
function parseVimeo(url) {
var m = url.match(/vimeo\.com\/([0-9]+)/);
if(m) {
// Extract video ID
return m[1];
}
return null;
}

9597
www/assets/js/jquery.js vendored Normal file

File diff suppressed because it is too large Load diff

780
www/assets/js/swf.js Normal file
View file

@ -0,0 +1,780 @@
/*! SWFObject v2.2 <http://code.google.com/p/swfobject/>
is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
console.log('swfobject start');
var swfobject = function() {
var UNDEF = "undefined",
OBJECT = "object",
SHOCKWAVE_FLASH = "Shockwave Flash",
SHOCKWAVE_FLASH_AX = "ShockwaveFlash.ShockwaveFlash",
FLASH_MIME_TYPE = "application/x-shockwave-flash",
EXPRESS_INSTALL_ID = "SWFObjectExprInst",
ON_READY_STATE_CHANGE = "onreadystatechange",
win = window,
doc = document,
nav = navigator,
plugin = false,
domLoadFnArr = [main],
regObjArr = [],
objIdArr = [],
listenersArr = [],
storedAltContent,
storedAltContentId,
storedCallbackFn,
storedCallbackObj,
isDomLoaded = false,
isExpressInstallActive = false,
dynamicStylesheet,
dynamicStylesheetMedia,
autoHideShow = true,
/* Centralized function for browser feature detection
- User agent string detection is only used when no good alternative is possible
- Is executed directly for optimal performance
*/
ua = function() {
var w3cdom = typeof doc.getElementById != UNDEF && typeof doc.getElementsByTagName != UNDEF && typeof doc.createElement != UNDEF,
u = nav.userAgent.toLowerCase(),
p = nav.platform.toLowerCase(),
windows = p ? /win/.test(p) : /win/.test(u),
mac = p ? /mac/.test(p) : /mac/.test(u),
webkit = /webkit/.test(u) ? parseFloat(u.replace(/^.*webkit\/(\d+(\.\d+)?).*$/, "$1")) : false, // returns either the webkit version or false if not webkit
ie = !+"\v1", // feature detection based on Andrea Giammarchi's solution: http://webreflection.blogspot.com/2009/01/32-bytes-to-know-if-your-browser-is-ie.html
playerVersion = [0,0,0],
d = null;
if (typeof nav.plugins != UNDEF && typeof nav.plugins[SHOCKWAVE_FLASH] == OBJECT) {
d = nav.plugins[SHOCKWAVE_FLASH].description;
if (d && !(typeof nav.mimeTypes != UNDEF && nav.mimeTypes[FLASH_MIME_TYPE] && !nav.mimeTypes[FLASH_MIME_TYPE].enabledPlugin)) { // navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin indicates whether plug-ins are enabled or disabled in Safari 3+
plugin = true;
ie = false; // cascaded feature detection for Internet Explorer
d = d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
playerVersion[0] = parseInt(d.replace(/^(.*)\..*$/, "$1"), 10);
playerVersion[1] = parseInt(d.replace(/^.*\.(.*)\s.*$/, "$1"), 10);
playerVersion[2] = /[a-zA-Z]/.test(d) ? parseInt(d.replace(/^.*[a-zA-Z]+(.*)$/, "$1"), 10) : 0;
}
}
else if (typeof win.ActiveXObject != UNDEF) {
try {
var a = new ActiveXObject(SHOCKWAVE_FLASH_AX);
if (a) { // a will return null when ActiveX is disabled
d = a.GetVariable("$version");
if (d) {
ie = true; // cascaded feature detection for Internet Explorer
d = d.split(" ")[1].split(",");
playerVersion = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
}
}
}
catch(e) {}
}
return { w3:w3cdom, pv:playerVersion, wk:webkit, ie:ie, win:windows, mac:mac };
}(),
/* Cross-browser onDomLoad
- Will fire an event as soon as the DOM of a web page is loaded
- Internet Explorer workaround based on Diego Perini's solution: http://javascript.nwbox.com/IEContentLoaded/
- Regular onload serves as fallback
*/
onDomLoad = function() {
if (!ua.w3) { return; }
if ((typeof doc.readyState != UNDEF && doc.readyState == "complete") || (typeof doc.readyState == UNDEF && (doc.getElementsByTagName("body")[0] || doc.body))) { // function is fired after onload, e.g. when script is inserted dynamically
callDomLoadFunctions();
}
if (!isDomLoaded) {
if (typeof doc.addEventListener != UNDEF) {
doc.addEventListener("DOMContentLoaded", callDomLoadFunctions, false);
}
if (ua.ie && ua.win) {
doc.attachEvent(ON_READY_STATE_CHANGE, function() {
if (doc.readyState == "complete") {
doc.detachEvent(ON_READY_STATE_CHANGE, arguments.callee);
callDomLoadFunctions();
}
});
if (win == top) { // if not inside an iframe
(function(){
if (isDomLoaded) { return; }
try {
doc.documentElement.doScroll("left");
}
catch(e) {
setTimeout(arguments.callee, 0);
return;
}
callDomLoadFunctions();
})();
}
}
if (ua.wk) {
(function(){
if (isDomLoaded) { return; }
if (!/loaded|complete/.test(doc.readyState)) {
setTimeout(arguments.callee, 0);
return;
}
callDomLoadFunctions();
})();
}
addLoadEvent(callDomLoadFunctions);
}
}();
function callDomLoadFunctions() {
if (isDomLoaded) { return; }
try { // test if we can really add/remove elements to/from the DOM; we don't want to fire it too early
var t = doc.getElementsByTagName("body")[0].appendChild(createElement("span"));
t.parentNode.removeChild(t);
}
catch (e) { return; }
isDomLoaded = true;
var dl = domLoadFnArr.length;
for (var i = 0; i < dl; i++) {
domLoadFnArr[i]();
}
}
function addDomLoadEvent(fn) {
if (isDomLoaded) {
fn();
}
else {
domLoadFnArr[domLoadFnArr.length] = fn; // Array.push() is only available in IE5.5+
}
}
/* Cross-browser onload
- Based on James Edwards' solution: http://brothercake.com/site/resources/scripts/onload/
- Will fire an event as soon as a web page including all of its assets are loaded
*/
function addLoadEvent(fn) {
if (typeof win.addEventListener != UNDEF) {
win.addEventListener("load", fn, false);
}
else if (typeof doc.addEventListener != UNDEF) {
doc.addEventListener("load", fn, false);
}
else if (typeof win.attachEvent != UNDEF) {
addListener(win, "onload", fn);
}
else if (typeof win.onload == "function") {
var fnOld = win.onload;
win.onload = function() {
fnOld();
fn();
};
}
else {
win.onload = fn;
}
}
/* Main function
- Will preferably execute onDomLoad, otherwise onload (as a fallback)
*/
function main() {
if (plugin) {
testPlayerVersion();
}
else {
matchVersions();
}
}
/* Detect the Flash Player version for non-Internet Explorer browsers
- Detecting the plug-in version via the object element is more precise than using the plugins collection item's description:
a. Both release and build numbers can be detected
b. Avoid wrong descriptions by corrupt installers provided by Adobe
c. Avoid wrong descriptions by multiple Flash Player entries in the plugin Array, caused by incorrect browser imports
- Disadvantage of this method is that it depends on the availability of the DOM, while the plugins collection is immediately available
*/
function testPlayerVersion() {
var b = doc.getElementsByTagName("body")[0];
var o = createElement(OBJECT);
o.setAttribute("type", FLASH_MIME_TYPE);
var t = b.appendChild(o);
if (t) {
var counter = 0;
(function(){
if (typeof t.GetVariable != UNDEF) {
var d = t.GetVariable("$version");
if (d) {
d = d.split(" ")[1].split(",");
ua.pv = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
}
}
else if (counter < 10) {
counter++;
setTimeout(arguments.callee, 10);
return;
}
b.removeChild(o);
t = null;
matchVersions();
})();
}
else {
matchVersions();
}
}
/* Perform Flash Player and SWF version matching; static publishing only
*/
function matchVersions() {
var rl = regObjArr.length;
if (rl > 0) {
for (var i = 0; i < rl; i++) { // for each registered object element
var id = regObjArr[i].id;
var cb = regObjArr[i].callbackFn;
var cbObj = {success:false, id:id};
if (ua.pv[0] > 0) {
var obj = getElementById(id);
if (obj) {
if (hasPlayerVersion(regObjArr[i].swfVersion) && !(ua.wk && ua.wk < 312)) { // Flash Player version >= published SWF version: Houston, we have a match!
setVisibility(id, true);
if (cb) {
cbObj.success = true;
cbObj.ref = getObjectById(id);
cb(cbObj);
}
}
else if (regObjArr[i].expressInstall && canExpressInstall()) { // show the Adobe Express Install dialog if set by the web page author and if supported
var att = {};
att.data = regObjArr[i].expressInstall;
att.width = obj.getAttribute("width") || "0";
att.height = obj.getAttribute("height") || "0";
if (obj.getAttribute("class")) { att.styleclass = obj.getAttribute("class"); }
if (obj.getAttribute("align")) { att.align = obj.getAttribute("align"); }
// parse HTML object param element's name-value pairs
var par = {};
var p = obj.getElementsByTagName("param");
var pl = p.length;
for (var j = 0; j < pl; j++) {
if (p[j].getAttribute("name").toLowerCase() != "movie") {
par[p[j].getAttribute("name")] = p[j].getAttribute("value");
}
}
showExpressInstall(att, par, id, cb);
}
else { // Flash Player and SWF version mismatch or an older Webkit engine that ignores the HTML object element's nested param elements: display alternative content instead of SWF
displayAltContent(obj);
if (cb) { cb(cbObj); }
}
}
}
else { // if no Flash Player is installed or the fp version cannot be detected we let the HTML object element do its job (either show a SWF or alternative content)
setVisibility(id, true);
if (cb) {
var o = getObjectById(id); // test whether there is an HTML object element or not
if (o && typeof o.SetVariable != UNDEF) {
cbObj.success = true;
cbObj.ref = o;
}
cb(cbObj);
}
}
}
}
}
function getObjectById(objectIdStr) {
var r = null;
var o = getElementById(objectIdStr);
if (o && o.nodeName == "OBJECT") {
if (typeof o.SetVariable != UNDEF) {
r = o;
}
else {
var n = o.getElementsByTagName(OBJECT)[0];
if (n) {
r = n;
}
}
}
return r;
}
/* Requirements for Adobe Express Install
- only one instance can be active at a time
- fp 6.0.65 or higher
- Win/Mac OS only
- no Webkit engines older than version 312
*/
function canExpressInstall() {
return !isExpressInstallActive && hasPlayerVersion("6.0.65") && (ua.win || ua.mac) && !(ua.wk && ua.wk < 312);
}
/* Show the Adobe Express Install dialog
- Reference: http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75
*/
function showExpressInstall(att, par, replaceElemIdStr, callbackFn) {
isExpressInstallActive = true;
storedCallbackFn = callbackFn || null;
storedCallbackObj = {success:false, id:replaceElemIdStr};
var obj = getElementById(replaceElemIdStr);
if (obj) {
if (obj.nodeName == "OBJECT") { // static publishing
storedAltContent = abstractAltContent(obj);
storedAltContentId = null;
}
else { // dynamic publishing
storedAltContent = obj;
storedAltContentId = replaceElemIdStr;
}
att.id = EXPRESS_INSTALL_ID;
if (typeof att.width == UNDEF || (!/%$/.test(att.width) && parseInt(att.width, 10) < 310)) { att.width = "310"; }
if (typeof att.height == UNDEF || (!/%$/.test(att.height) && parseInt(att.height, 10) < 137)) { att.height = "137"; }
doc.title = doc.title.slice(0, 47) + " - Flash Player Installation";
var pt = ua.ie && ua.win ? "ActiveX" : "PlugIn",
fv = "MMredirectURL=" + win.location.toString().replace(/&/g,"%26") + "&MMplayerType=" + pt + "&MMdoctitle=" + doc.title;
if (typeof par.flashvars != UNDEF) {
par.flashvars += "&" + fv;
}
else {
par.flashvars = fv;
}
// IE only: when a SWF is loading (AND: not available in cache) wait for the readyState of the object element to become 4 before removing it,
// because you cannot properly cancel a loading SWF file without breaking browser load references, also obj.onreadystatechange doesn't work
if (ua.ie && ua.win && obj.readyState != 4) {
var newObj = createElement("div");
replaceElemIdStr += "SWFObjectNew";
newObj.setAttribute("id", replaceElemIdStr);
obj.parentNode.insertBefore(newObj, obj); // insert placeholder div that will be replaced by the object element that loads expressinstall.swf
obj.style.display = "none";
(function(){
if (obj.readyState == 4) {
obj.parentNode.removeChild(obj);
}
else {
setTimeout(arguments.callee, 10);
}
})();
}
createSWF(att, par, replaceElemIdStr);
}
}
/* Functions to abstract and display alternative content
*/
function displayAltContent(obj) {
if (ua.ie && ua.win && obj.readyState != 4) {
// IE only: when a SWF is loading (AND: not available in cache) wait for the readyState of the object element to become 4 before removing it,
// because you cannot properly cancel a loading SWF file without breaking browser load references, also obj.onreadystatechange doesn't work
var el = createElement("div");
obj.parentNode.insertBefore(el, obj); // insert placeholder div that will be replaced by the alternative content
el.parentNode.replaceChild(abstractAltContent(obj), el);
obj.style.display = "none";
(function(){
if (obj.readyState == 4) {
obj.parentNode.removeChild(obj);
}
else {
setTimeout(arguments.callee, 10);
}
})();
}
else {
obj.parentNode.replaceChild(abstractAltContent(obj), obj);
}
}
function abstractAltContent(obj) {
var ac = createElement("div");
if (ua.win && ua.ie) {
ac.innerHTML = obj.innerHTML;
}
else {
var nestedObj = obj.getElementsByTagName(OBJECT)[0];
if (nestedObj) {
var c = nestedObj.childNodes;
if (c) {
var cl = c.length;
for (var i = 0; i < cl; i++) {
if (!(c[i].nodeType == 1 && c[i].nodeName == "PARAM") && !(c[i].nodeType == 8)) {
ac.appendChild(c[i].cloneNode(true));
}
}
}
}
}
return ac;
}
/* Cross-browser dynamic SWF creation
*/
function createSWF(attObj, parObj, id) {
var r, el = getElementById(id);
if (ua.wk && ua.wk < 312) { return r; }
if (el) {
if (typeof attObj.id == UNDEF) { // if no 'id' is defined for the object element, it will inherit the 'id' from the alternative content
attObj.id = id;
}
if (ua.ie && ua.win) { // Internet Explorer + the HTML object element + W3C DOM methods do not combine: fall back to outerHTML
var att = "";
for (var i in attObj) {
if (attObj[i] != Object.prototype[i]) { // filter out prototype additions from other potential libraries
if (i.toLowerCase() == "data") {
parObj.movie = attObj[i];
}
else if (i.toLowerCase() == "styleclass") { // 'class' is an ECMA4 reserved keyword
att += ' class="' + attObj[i] + '"';
}
else if (i.toLowerCase() != "classid") {
att += ' ' + i + '="' + attObj[i] + '"';
}
}
}
var par = "";
for (var j in parObj) {
if (parObj[j] != Object.prototype[j]) { // filter out prototype additions from other potential libraries
par += '<param name="' + j + '" value="' + parObj[j] + '" />';
}
}
el.outerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + att + '>' + par + '</object>';
objIdArr[objIdArr.length] = attObj.id; // stored to fix object 'leaks' on unload (dynamic publishing only)
r = getElementById(attObj.id);
}
else { // well-behaving browsers
var o = createElement(OBJECT);
o.setAttribute("type", FLASH_MIME_TYPE);
for (var m in attObj) {
if (attObj[m] != Object.prototype[m]) { // filter out prototype additions from other potential libraries
if (m.toLowerCase() == "styleclass") { // 'class' is an ECMA4 reserved keyword
o.setAttribute("class", attObj[m]);
}
else if (m.toLowerCase() != "classid") { // filter out IE specific attribute
o.setAttribute(m, attObj[m]);
}
}
}
for (var n in parObj) {
if (parObj[n] != Object.prototype[n] && n.toLowerCase() != "movie") { // filter out prototype additions from other potential libraries and IE specific param element
createObjParam(o, n, parObj[n]);
}
}
el.parentNode.replaceChild(o, el);
r = o;
}
}
return r;
}
function createObjParam(el, pName, pValue) {
var p = createElement("param");
p.setAttribute("name", pName);
p.setAttribute("value", pValue);
el.appendChild(p);
}
/* Cross-browser SWF removal
- Especially needed to safely and completely remove a SWF in Internet Explorer
*/
function removeSWF(id) {
var obj = getElementById(id);
if (obj && obj.nodeName == "OBJECT") {
if (ua.ie && ua.win) {
obj.style.display = "none";
(function(){
if (obj.readyState == 4) {
removeObjectInIE(id);
}
else {
setTimeout(arguments.callee, 10);
}
})();
}
else {
obj.parentNode.removeChild(obj);
}
}
}
function removeObjectInIE(id) {
var obj = getElementById(id);
if (obj) {
for (var i in obj) {
if (typeof obj[i] == "function") {
obj[i] = null;
}
}
obj.parentNode.removeChild(obj);
}
}
/* Functions to optimize JavaScript compression
*/
function getElementById(id) {
var el = null;
try {
el = doc.getElementById(id);
}
catch (e) {}
return el;
}
function createElement(el) {
return doc.createElement(el);
}
/* Updated attachEvent function for Internet Explorer
- Stores attachEvent information in an Array, so on unload the detachEvent functions can be called to avoid memory leaks
*/
function addListener(target, eventType, fn) {
target.attachEvent(eventType, fn);
listenersArr[listenersArr.length] = [target, eventType, fn];
}
/* Flash Player and SWF content version matching
*/
function hasPlayerVersion(rv) {
var pv = ua.pv, v = rv.split(".");
v[0] = parseInt(v[0], 10);
v[1] = parseInt(v[1], 10) || 0; // supports short notation, e.g. "9" instead of "9.0.0"
v[2] = parseInt(v[2], 10) || 0;
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;
}
/* Cross-browser dynamic CSS creation
- Based on Bobby van der Sluis' solution: http://www.bobbyvandersluis.com/articles/dynamicCSS.php
*/
function createCSS(sel, decl, media, newStyle) {
if (ua.ie && ua.mac) { return; }
var h = doc.getElementsByTagName("head")[0];
if (!h) { return; } // to also support badly authored HTML pages that lack a head element
var m = (media && typeof media == "string") ? media : "screen";
if (newStyle) {
dynamicStylesheet = null;
dynamicStylesheetMedia = null;
}
if (!dynamicStylesheet || dynamicStylesheetMedia != m) {
// create dynamic stylesheet + get a global reference to it
var s = createElement("style");
s.setAttribute("type", "text/css");
s.setAttribute("media", m);
dynamicStylesheet = h.appendChild(s);
if (ua.ie && ua.win && typeof doc.styleSheets != UNDEF && doc.styleSheets.length > 0) {
dynamicStylesheet = doc.styleSheets[doc.styleSheets.length - 1];
}
dynamicStylesheetMedia = m;
}
// add style rule
if (ua.ie && ua.win) {
if (dynamicStylesheet && typeof dynamicStylesheet.addRule == OBJECT) {
dynamicStylesheet.addRule(sel, decl);
}
}
else {
if (dynamicStylesheet && typeof doc.createTextNode != UNDEF) {
dynamicStylesheet.appendChild(doc.createTextNode(sel + " {" + decl + "}"));
}
}
}
function setVisibility(id, isVisible) {
if (!autoHideShow) { return; }
var v = isVisible ? "visible" : "hidden";
if (isDomLoaded && getElementById(id)) {
getElementById(id).style.visibility = v;
}
else {
createCSS("#" + id, "visibility:" + v);
}
}
/* Filter to avoid XSS attacks
*/
function urlEncodeIfNecessary(s) {
var regex = /[\\\"<>\.;]/;
var hasBadChars = regex.exec(s) != null;
return hasBadChars && typeof encodeURIComponent != UNDEF ? encodeURIComponent(s) : s;
}
/* Release memory to avoid memory leaks caused by closures, fix hanging audio/video threads and force open sockets/NetConnections to disconnect (Internet Explorer only)
*/
var cleanup = function() {
if (ua.ie && ua.win) {
window.attachEvent("onunload", function() {
// remove listeners to avoid memory leaks
var ll = listenersArr.length;
for (var i = 0; i < ll; i++) {
listenersArr[i][0].detachEvent(listenersArr[i][1], listenersArr[i][2]);
}
// cleanup dynamically embedded objects to fix audio/video threads and force open sockets and NetConnections to disconnect
var il = objIdArr.length;
for (var j = 0; j < il; j++) {
removeSWF(objIdArr[j]);
}
// cleanup library's main closures to avoid memory leaks
for (var k in ua) {
ua[k] = null;
}
ua = null;
for (var l in swfobject) {
swfobject[l] = null;
}
swfobject = null;
});
}
}();
return {
/* Public API
- Reference: http://code.google.com/p/swfobject/wiki/documentation
*/
registerObject: function(objectIdStr, swfVersionStr, xiSwfUrlStr, callbackFn) {
if (ua.w3 && objectIdStr && swfVersionStr) {
var regObj = {};
regObj.id = objectIdStr;
regObj.swfVersion = swfVersionStr;
regObj.expressInstall = xiSwfUrlStr;
regObj.callbackFn = callbackFn;
regObjArr[regObjArr.length] = regObj;
setVisibility(objectIdStr, false);
}
else if (callbackFn) {
callbackFn({success:false, id:objectIdStr});
}
},
getObjectById: function(objectIdStr) {
if (ua.w3) {
return getObjectById(objectIdStr);
}
},
embedSWF: function(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn) {
var callbackObj = {success:false, id:replaceElemIdStr};
if (ua.w3 && !(ua.wk && ua.wk < 312) && swfUrlStr && replaceElemIdStr && widthStr && heightStr && swfVersionStr) {
setVisibility(replaceElemIdStr, false);
addDomLoadEvent(function() {
widthStr += ""; // auto-convert to string
heightStr += "";
var att = {};
if (attObj && typeof attObj === OBJECT) {
for (var i in attObj) { // copy object to avoid the use of references, because web authors often reuse attObj for multiple SWFs
att[i] = attObj[i];
}
}
att.data = swfUrlStr;
att.width = widthStr;
att.height = heightStr;
var par = {};
if (parObj && typeof parObj === OBJECT) {
for (var j in parObj) { // copy object to avoid the use of references, because web authors often reuse parObj for multiple SWFs
par[j] = parObj[j];
}
}
if (flashvarsObj && typeof flashvarsObj === OBJECT) {
for (var k in flashvarsObj) { // copy object to avoid the use of references, because web authors often reuse flashvarsObj for multiple SWFs
if (typeof par.flashvars != UNDEF) {
par.flashvars += "&" + k + "=" + flashvarsObj[k];
}
else {
par.flashvars = k + "=" + flashvarsObj[k];
}
}
}
if (hasPlayerVersion(swfVersionStr)) { // create SWF
var obj = createSWF(att, par, replaceElemIdStr);
if (att.id == replaceElemIdStr) {
setVisibility(replaceElemIdStr, true);
}
callbackObj.success = true;
callbackObj.ref = obj;
}
else if (xiSwfUrlStr && canExpressInstall()) { // show Adobe Express Install
att.data = xiSwfUrlStr;
showExpressInstall(att, par, replaceElemIdStr, callbackFn);
return;
}
else { // show alternative content
setVisibility(replaceElemIdStr, true);
}
if (callbackFn) { callbackFn(callbackObj); }
});
}
else if (callbackFn) { callbackFn(callbackObj); }
},
switchOffAutoHideShow: function() {
autoHideShow = false;
},
ua: ua,
getFlashPlayerVersion: function() {
return { major:ua.pv[0], minor:ua.pv[1], release:ua.pv[2] };
},
hasFlashPlayerVersion: hasPlayerVersion,
createSWF: function(attObj, parObj, replaceElemIdStr) {
if (ua.w3) {
return createSWF(attObj, parObj, replaceElemIdStr);
}
else {
return undefined;
}
},
showExpressInstall: function(att, par, replaceElemIdStr, callbackFn) {
if (ua.w3 && canExpressInstall()) {
showExpressInstall(att, par, replaceElemIdStr, callbackFn);
}
},
removeSWF: function(objElemIdStr) {
if (ua.w3) {
removeSWF(objElemIdStr);
}
},
createCSS: function(selStr, declStr, mediaStr, newStyleBoolean) {
if (ua.w3) {
createCSS(selStr, declStr, mediaStr, newStyleBoolean);
}
},
addDomLoadEvent: addDomLoadEvent,
addLoadEvent: addLoadEvent,
getQueryParamValue: function(param) {
var q = doc.location.search || doc.location.hash;
if (q) {
if (/\?/.test(q)) { q = q.split("?")[1]; } // strip question mark
if (param == null) {
return urlEncodeIfNecessary(q);
}
var pairs = q.split("&");
for (var i = 0; i < pairs.length; i++) {
if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
return urlEncodeIfNecessary(pairs[i].substring((pairs[i].indexOf("=") + 1)));
}
}
}
return "";
},
// For internal usage only
expressInstallCallback: function() {
if (isExpressInstallActive) {
var obj = getElementById(EXPRESS_INSTALL_ID);
if (obj && storedAltContent) {
obj.parentNode.replaceChild(storedAltContent, obj);
if (storedAltContentId) {
setVisibility(storedAltContentId, true);
if (ua.ie && ua.win) { storedAltContent.style.display = "block"; }
}
if (storedCallbackFn) { storedCallbackFn(storedCallbackObj); }
}
isExpressInstallActive = false;
}
}
};
}();
console.log('swfobject');

View file

@ -0,0 +1,127 @@
/**
*
* Secure Hash Algorithm (SHA256)
* http://www.webtoolkit.info/
*
* Original code by Angel Marin, Paul Johnston.
*
**/
function SHA256(s){
var chrsz = 8;
var hexcase = 0;
function safe_add (x, y) {
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}
function S (X, n) { return ( X >>> n ) | (X << (32 - n)); }
function R (X, n) { return ( X >>> n ); }
function Ch(x, y, z) { return ((x & y) ^ ((~x) & z)); }
function Maj(x, y, z) { return ((x & y) ^ (x & z) ^ (y & z)); }
function Sigma0256(x) { return (S(x, 2) ^ S(x, 13) ^ S(x, 22)); }
function Sigma1256(x) { return (S(x, 6) ^ S(x, 11) ^ S(x, 25)); }
function Gamma0256(x) { return (S(x, 7) ^ S(x, 18) ^ R(x, 3)); }
function Gamma1256(x) { return (S(x, 17) ^ S(x, 19) ^ R(x, 10)); }
function core_sha256 (m, l) {
var K = new Array(0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0xFC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x6CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2);
var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19);
var W = new Array(64);
var a, b, c, d, e, f, g, h, i, j;
var T1, T2;
m[l >> 5] |= 0x80 << (24 - l % 32);
m[((l + 64 >> 9) << 4) + 15] = l;
for ( var i = 0; i<m.length; i+=16 ) {
a = HASH[0];
b = HASH[1];
c = HASH[2];
d = HASH[3];
e = HASH[4];
f = HASH[5];
g = HASH[6];
h = HASH[7];
for ( var j = 0; j<64; j++) {
if (j < 16) W[j] = m[j + i];
else W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);
T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);
T2 = safe_add(Sigma0256(a), Maj(a, b, c));
h = g;
g = f;
f = e;
e = safe_add(d, T1);
d = c;
c = b;
b = a;
a = safe_add(T1, T2);
}
HASH[0] = safe_add(a, HASH[0]);
HASH[1] = safe_add(b, HASH[1]);
HASH[2] = safe_add(c, HASH[2]);
HASH[3] = safe_add(d, HASH[3]);
HASH[4] = safe_add(e, HASH[4]);
HASH[5] = safe_add(f, HASH[5]);
HASH[6] = safe_add(g, HASH[6]);
HASH[7] = safe_add(h, HASH[7]);
}
return HASH;
}
function str2binb (str) {
var bin = Array();
var mask = (1 << chrsz) - 1;
for(var i = 0; i < str.length * chrsz; i += chrsz) {
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32);
}
return bin;
}
function Utf8Encode(string) {
string = string.replace(/\r\n/g,"\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
}
function binb2hex (binarray) {
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
var str = "";
for(var i = 0; i < binarray.length * 4; i++) {
str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF);
}
return str;
}
s = Utf8Encode(s);
return binb2hex(core_sha256(str2binb(s), s.length * chrsz));
}