From a4916103efb2d97896c456ff0e83064b21e85d25 Mon Sep 17 00:00:00 2001 From: Pepper Date: Wed, 20 May 2015 11:16:13 -0400 Subject: first commit in a while --- frontend/static/js/src/api.js | 132 ++ frontend/static/js/src/audio.js | 142 ++ frontend/static/js/src/auth.js | 165 ++ frontend/static/js/src/chat.js | 288 +++ frontend/static/js/src/debug.js | 130 ++ frontend/static/js/src/jquery-1.5.2.min.js | 16 + frontend/static/js/src/jquery.md5.js | 269 +++ frontend/static/js/src/like.js | 97 + frontend/static/js/src/main.js | 694 +++++++ frontend/static/js/src/player.js | 551 ++++++ frontend/static/js/src/room.js | 460 +++++ frontend/static/js/src/search.js | 190 ++ frontend/static/js/src/soundcloud.js | 156 ++ frontend/static/js/src/soundmanager.js | 2838 ++++++++++++++++++++++++++++ frontend/static/js/src/swfobject.js | 4 + frontend/static/js/src/toggler.js | 27 + frontend/static/js/src/vimeo.js | 99 + frontend/static/js/src/youtube.js | 176 ++ 18 files changed, 6434 insertions(+) create mode 100644 frontend/static/js/src/api.js create mode 100644 frontend/static/js/src/audio.js create mode 100644 frontend/static/js/src/auth.js create mode 100644 frontend/static/js/src/chat.js create mode 100644 frontend/static/js/src/debug.js create mode 100755 frontend/static/js/src/jquery-1.5.2.min.js create mode 100755 frontend/static/js/src/jquery.md5.js create mode 100644 frontend/static/js/src/like.js create mode 100644 frontend/static/js/src/main.js create mode 100644 frontend/static/js/src/player.js create mode 100644 frontend/static/js/src/room.js create mode 100644 frontend/static/js/src/search.js create mode 100644 frontend/static/js/src/soundcloud.js create mode 100755 frontend/static/js/src/soundmanager.js create mode 100755 frontend/static/js/src/swfobject.js create mode 100644 frontend/static/js/src/toggler.js create mode 100644 frontend/static/js/src/vimeo.js create mode 100644 frontend/static/js/src/youtube.js (limited to 'frontend/static/js/src') diff --git a/frontend/static/js/src/api.js b/frontend/static/js/src/api.js new file mode 100644 index 0000000..797823e --- /dev/null +++ b/frontend/static/js/src/api.js @@ -0,0 +1,132 @@ +var API = + { + HEADER: "#@scanjam 0.3b", + BASE_URL: "http://"+serverHost+":"+serverPort, + URL: + { + auth: + { + login: "/api/auth/login", + logout: "/api/auth/logout", + checkin: "/api/auth/checkin", + sneakin: "/api/auth/sneakin", + }, + room: + { + join: "/api/room/join", + list: "/api/room/list", + view: "/api/room/view", + poll: "/api/room/poll", + watch: "/api/room/watch", + say: "/api/room/say", + settings: "/api/room/settings", + stats: "/stats", + }, + video: + { + date: "/api/video/date", + like: "/api/video/like", + unlike: "/api/video/unlike", + remove: "/api/video/remove", + search: "/api/video/search", + }, + user: + { + settings: "/api/user/settings", + videos: "/api/user/videos", + likes: "/api/user/likes", + }, + }, + error: function (s) + { + d.error("API: "+s) + return false + }, + parse: function (api, raw) + { + if (! raw) + return API.error("no result") + var lines = raw.split("\n") + if (lines.shift() !== API.HEADER) + return API.error("bad header") + if (! lines.length) + return API.error("no content") + return lines + }, + init: function () + { + d.warn("INIT API") + for (type in API.URL) + { + for (name in API.URL[type]) + { + API.URL[type][name] = API.BASE_URL + API.URL[type][name] + "/" + } + } + // $.ajaxSetup({ timeout: 1000 }) + } + } +var Local = + { + support: false, + hash: null, + get: null, + set: null, + _html5_get: function (key) + { + var val = localStorage["scanjam."+key] + if (val === "true") return true + if (val === "false") return false + if (val === "undefined") return undefined + return val + }, + _html5_set: function (key, val) + { + if (val === undefined) + localStorage["scanjam."+key] = "" + else + localStorage["scanjam."+key] = val + }, + _hash_get: function (key) + { + if (key in Local.hash) + return Local.hash[key] + }, + _hash_set: function (key, val) + { + Local.hash[key] = val + }, + _supports_html5_storage: function () + { + try + { return 'localStorage' in window && window['localStorage'] !== null; } + catch (e) + { return false } + }, + like: function (videoid) + { Local.set("like."+videoid, true) }, + unlike: function (videoid) + { Local.set("like."+videoid, false) }, + isLiked: function (videoid) + { return Local.get("like."+videoid) }, + init: function () + { + Local.support = Local._supports_html5_storage() + if (Local.support) + { + d.warn("SUPPORTS LOCAL STORAGE") + Local.get = Local._html5_get + Local.set = Local._html5_set + } + else + { + d.error("NO LOCAL STORAGE") + Local.hash = {} + Local.get = Local._hash_get + Local.set = Local._hash_set + } + } + } +API.init() +Local.init() + diff --git a/frontend/static/js/src/audio.js b/frontend/static/js/src/audio.js new file mode 100644 index 0000000..dfba914 --- /dev/null +++ b/frontend/static/js/src/audio.js @@ -0,0 +1,142 @@ +var Audio = + { + type: "audio", + loaded: false, + pending: false, + playing: false, + paused: false, + player: null, + playerId: null, + timeout: null, + video: null, + width: "100%", + height: "100%", + volume: 100, + play: function (video) + { + d.warn("AUDIO PLAY "+video.key) + if (video.error) + return Audio.error() + if (Audio.playing) + Audio.stop() + $("#screen").html("
") + $("#ytscreen").css("z-index", -2) + Audio.video = video + Audio.playing = false + + var partz = video.src.split(" ") + var img = partz[0] + var url = partz[1] + var title = partz.slice(2).join(" ") + + if (Audio.player) + { + Audio.player.stop() + Audio.player.destruct() + } + Audio.player = soundManager.createSound + ({ + id: "player-"+video.id, + url: url, + volume: Audio.volume, + onfinish: Audio.finish, + onerror: Audio.error, + onload: Audio.onload, + }) + if (! Audio.player) + return Audio.error("no player") + Audio.player.play() + + $("#video-title").html(title) + $("#video-link").attr("href", url) + $("#audio-dl").html('download') + $("#audio-img").html("") + $("#audio-art").bind("error", function(){$("#audio-art").hide()}) + }, + onload: function (success) + { + if (! success) + return Audio.error("failed to load") + }, + toggle: function () + { + d.warn("TOGGLE PLAYBACK") + if (Audio.paused) + return Audio.resume() + else + return Audio.pause() + }, + error: function (s) + { + if (! s) + s = "unspecified error" + Player.error("AUDIO "+s) + Audio.finish() + }, + setVolume: function (vol) + { + Audio.volume = vol + if (Audio.player) + Audio.player.setVolume(vol) + }, + pause: function () + { + d.warn("PAUSED PLAYBACK") + Audio.paused = true + Audio.playing = false + if (Audio.player) + Audio.player.pause() + return true + }, + resume: function () + { + d.warn("RESUME PLAYBACK") + Audio.paused = false + Audio.playing = true + if (Audio.player) + Audio.player.resume() + return false + }, + stop: function () + { + d.warn("AUDIO STOP") + if (Audio.player) + Audio.player.stop() + Audio.playing = false + }, + finish: function () + { + d.warn("AUDIO FINISH") + Audio.playing = false + if (Audio.player) + { + Audio.player.stop() + Audio.player.destruct() + } + Player.finish() + }, + load: function () + { + d.warn("LOADING AUDIO") + Audio.loaded = true + }, + unload: function () + { + d.warn("AUDIO UNLOADED") + if (Audio.player) + { + Audio.player.stop() + Audio.player.destruct() + } + Audio.loaded = false + Audio.playing = false + }, + init: function () + { + d.warn("AUDIO INIT") + } + } +Player.register(Audio) +soundManager.url = '/static/swf/' +soundManager.useFlashBlock = false +soundManager.debugMode = false diff --git a/frontend/static/js/src/auth.js b/frontend/static/js/src/auth.js new file mode 100644 index 0000000..26da79d --- /dev/null +++ b/frontend/static/js/src/auth.js @@ -0,0 +1,165 @@ +var Auth = + { + userid: false, + username: false, + session: false, + loaded: false, + access: 0, + login: function () + { + d.warn("LOG IN") + var username = d.trim( $("#login-username").val() ) + var password = d.trim( $("#login-password").val() ) + var pwhash = $.md5("scanjam"+password) + if (! username || ! password) return + Main.enter = false + d.warn("LOGGING IN") + $.post(API.URL.auth.login, {'username':username, 'password': pwhash}, Auth.loginCallback) + $("#chat").hide() + }, + loginCallback: function (raw) + { + var lines = API.parse("/auth/login", raw) + if (! lines.length) return + if (lines[0] !== "OK") + { + alert(lines[0].split("\t")[1]) + return Auth.error() + } + u = lines[1].split("\t") + + Auth.userid = u[0] + Auth.username = u[1] + Auth.session = u[2] + Auth.access = u[3] + + document.cookie = "session="+Auth.session+";path=/;domain=.scannerjammer.com;max-age=1086400" + Auth.success() + }, + checkin: function () + { + d.warn("CHECK IN") + $.post(API.URL.auth.checkin, {'session':Auth.session}, Auth.checkinCallback) + }, + checkinCallback: function (raw) + { + var lines = API.parse("/auth/checkin", raw) + if (! lines.length) return + if (lines[0] !== "OK") + { + alert(lines[0].split("\t")[1]) + return Auth.error() + } + u = lines[1].split("\t") + Auth.userid = u[0] + Auth.username = u[1] + Auth.success() + }, + sneakin: function (userid,username) + { + d.warn("SNEAK IN") + $.post(API.URL.auth.sneakin, {'userid':userid,'username':username}).success(Auth.sneakinCallback) + }, + sneakinCallback: function (raw) + { + var lines = API.parse("/auth/sneakin", raw) + if (! lines.length) return + if (lines[0] !== "OK") + { + alert(lines[0].split("\t")[1]) + return Auth.error() + } + d.joy("snuck in!") + u = lines[1].split("\t") + + Auth.userid = u[0] + Auth.username = u[1] + Auth.session = u[2] + Auth.access = u[3] + + d.warn(lines[1]) + if (! Auth.session) + return + document.cookie = "session="+Auth.session+";path=/;domain=.scannerjammer.com;max-age=1086400" + Auth.success() + }, + logout: function () + { + d.warn("LOG OUT") + clearTimeout(Room.timer) + Room.unload() + Auth.userid = false + Auth.username = false + Local.set('userid', false) + Local.set('username', false) + document.cookie = "session=false;path=/;domain=.scannerjammer.com;max-age=0" + Auth.session = "" + Auth.load() + }, + error: function () + { + Auth.load() + }, + success: function () + { + d.joy("logged in as "+Auth.username) + Auth.unload() + Room.load() + }, + unload: function () + { + d.warn("AUTH UNLOAD") + $("#login").hide() + $("#loading").show() + Keyboard.enter = false + Auth.loaded = false + }, + load: function () + { + d.warn("AUTH LOAD") + $("#loading").hide() + $("#login").show() + $("#login-username").focus() + $("#login-username").keydown(Keyboard.textareaMap) + $("#login-password").keydown(Keyboard.textareaMap) + $("#login-password").val("") + $("#login-go").click(Auth.login) + Keyboard.enter = Auth.login + $("#bg").show() + Auth.loaded = true + }, + init: function () + { + d.warn("INIT AUTH") + if (document.cookie) + { + d.warn("got a cookie") + d.warn(document.cookie) + var cookies = document.cookie.split(";") + for (i in cookies) + { + var cookie = cookies[i].split("=") + if (cookie[0].indexOf("session") !== -1) + { + if (cookie[1] !== 'false' && cookie[1] !== 'undefined') + { + Auth.session = cookie[1] + break + } + } + } + d.warn("got sessionid "+Auth.session) + if (Auth.session) + return true + } + var userid = Local.get('userid') + var username = Local.get('username') + if (userid && username) + { + d.warn("attempting to sneak in "+username) + Auth.sneakin(userid,username) + return true + } + return false + } + } diff --git a/frontend/static/js/src/chat.js b/frontend/static/js/src/chat.js new file mode 100644 index 0000000..689dad6 --- /dev/null +++ b/frontend/static/js/src/chat.js @@ -0,0 +1,288 @@ +var VIMEOregexp = /^(\bhttps?:\/\/)(www.)?vimeo.com\/([0-9]+).*$/i +var Chat = + { + timer: null, + oldChat: {}, + oldVideo: {}, + lastPoll: 0, + delay: 1000, + delayShort: 1000, + delayLong: 5000, + messages: {}, + callback: false, + parse: function (row) + { + var domain = window.location.hostname.split('.').slice(-2).join('.') + var s = '' + row[2] + " " + s += Chat.parseWords(row[3],row[0]) + s += "
" + return s + }, + parseWords: function (raw,id) + { + if (! raw) + return "" + var words = raw.split(" ") + var s = "" + for (i in words) + { + var word = words[i] + if (word.indexOf("http") !== -1) + { + if (word.indexOf("youtube.com/watch?") !== -1) + { + var ytid = "youtube_"+Youtube.getYtid(word) + var txt + if (ytid in Player.videos) + txt = Player.videos[ytid].title + else + txt = word + s += ''+txt+' ' + } + else if (word.indexOf("youtube.com/v/") !== -1) + { + var index = word.indexOf("/v/") + var ytid = "youtube_"+word.substr(index+3,11) + var txt + if (ytid in Player.videos) + txt = Player.videos[ytid].title + else + txt = word + s += ''+txt+' ' + } + else if (word.indexOf("youtu.be") !== -1) + { + var ytid = "youtube_"+word.substr(16,11) + var txt + if (ytid in Player.videos) + txt = Player.videos[ytid].title + else + txt = word + s += ''+txt+' ' + } + // http://www.youtube.com/user/ahchachachacha#p/f/28/1GSBekxLR1E + else if (word.indexOf("youtube.com/user") !== -1) + { + var ytid = "youtube_"+word.substr(-11) + var txt + if (ytid in Player.videos) + txt = Player.videos[ytid].title + else + txt = word + s += ''+txt+' ' + } + else if (word.indexOf("vimeo.com") !== -1) + { + var vimeoid = word.replace(VIMEOregexp, "vimeo_$3") + if (vimeoid in Player.videos) + txt = Player.videos[vimeoid].title + else + txt = word + s += ''+txt+' ' + } + else if (word.indexOf("soundcloud.com") !== -1) + { + var scid = "soundcloud_" + $.md5(word) + if (scid in Player.videos) + txt = Player.videos[scid].title + else + txt = word + s += ''+txt+' ' + } + else if (word.indexOf(".jpeg") !== -1 || + word.indexOf(".JPG") !== -1 || + word.indexOf(".GIF") !== -1 || + word.indexOf(".PNG") !== -1 || + word.indexOf(".JPEG") !== -1 || + word.indexOf(".jpg") !== -1 || + word.indexOf(".gif") !== -1 || + word.indexOf(".png") !== -1) + { + s += + ''+ + ''+ + '
'; + if(id){ + s+='like'; + } + } + else if (word.indexOf("scannerjammer.com/profile") !== -1) + { + var username = word.substr( word.indexOf("profile")+8 ).replace("/","") + s += '@'+username+'' + } + // else if (word.indexOf("@") === 0 && word.length > 2) + // { + // } + else + { + var poffset = word.indexOf('//') + var linktext = word.substr(poffset+2, word.indexOf('/', poffset+2) - 2).replace("www.","").replace(/\/+$/,"") + s += ''+linktext+' ' + } + } + else if (word.indexOf(".com") !== -1 || + word.indexOf(".net") !== -1 || + word.indexOf(".org") !== -1 || + word.indexOf(".us") !== -1 || + word.indexOf(".nu") !== -1 || + word.indexOf(".uk") !== -1 || + word.indexOf(".fr") !== -1 || + word.indexOf(".de") !== -1 || + word.indexOf(".fm") !== -1) + { + var txt = word.replace("www.","") + s += ''+txt+' ' + } + else + s += word + " " + } + return s + }, + store: function (lines) + { + var newVideos = [] + var newChat = [] + var postponeScroll = false + for (i in lines) + { + if (! lines[i]) + continue + row = lines[i].split("\t") + if (row[0] === 'VIDEO') + { + row.shift() + if (row[0] in Chat.oldVideo) + continue + Chat.oldVideo[row[0]] = row + Playlist.enqueueOldVideoFormat([row]) + } + else if (row[0] === 'ROOM') + { + Room.updateSetting(row[1],row[2]) + } + else if (row[0] === 'LIKE') + { + username = row[1] + Like.enqueue(username) + } + else if (row[0] === 'CAM') + { + VideoChat.updateCount(row[1]) + } + else + { + // 0 id 1 date 2 user 3 msg + if (row[0] in Chat.oldChat) + continue + Chat.oldChat[row[0]] = row + var c = Chat.parse(row) + if (c.indexOf("> POSTPONING") + } + if (row[2] === Auth.username && $.md5(row[3]) in Chat.messages) + continue + newChat.push(c) + } + } + if (newChat.length) + { + $("#chat").append(newChat.join("")) + if (postponeScroll) + setTimeout('d.scrollToBottom("#chat")', 2000) + else + d.scrollToBottom("#chat") + } + }, + say: function () + { + d.act("+ sent message") + var msg = d.sanitize( $("#chat-message").val() ) + $("#chat-message").val("") + if (! msg) return + if (msg === "debug=1") { $("#msg").show(); d.scrollToBottom("#msg"); return } + if (msg === "debug=0") { $("#msg").hide(); return } + if (msg === "poll=0") { d.error("+ DISABLED POLLING"); clearTimeout(Chat.timer); return} + var hash = $.md5(msg) + Chat.messages[hash] = true + var newrow = [0, 0, Auth.username, msg] + var newdiv = Chat.parse(newrow) + $("#chat").append(newdiv) + // if (Chat.callback) + // Chat.callback(1) + if (newdiv.indexOf(""+names[i]+"" + } + $("#lastlog").html(s) + $("#lastlogbg").css("height", $("#lastlogbox").height()) + } + } diff --git a/frontend/static/js/src/debug.js b/frontend/static/js/src/debug.js new file mode 100644 index 0000000..1a3339f --- /dev/null +++ b/frontend/static/js/src/debug.js @@ -0,0 +1,130 @@ +var d = + { + DEBUG: false, + act: function (s) + { + // $('#msg').append(''+s+'
') + // d.scrollToBottom("#msg") + // if (d.DEBUG) + // console.log(s) + return false + }, + joy: function (s) + { + // $('#msg').append(''+s+'
') + // d.scrollToBottom("#msg") + // if (d.DEBUG) + // console.log(s) + return false + }, + warn: function (s) + { + // $('#msg').append(s+'
') + // d.scrollToBottom("#msg") + // if (d.DEBUG) + // console.log(s) + return false + }, + error: function (s) + { + // $('#msg').append('ERROR: '+s+'
') + // d.scrollToBottom("#msg") + // console.log(s) + return false + }, + noop: function () {}, + scrollToTop: function (elem) + { + $(elem).scrollTop( 0 ) + }, + scrollToBottom: function (elem) + { + try + { + $(elem).scrollTop( $(elem)[0].scrollHeight ) + } + catch (err) + { + } + }, + pageUp: function (div) + { + var st = $(div).scrollTop() + var h = $(window).height() + d.warn("PAGEUP: "+st+" "+h) + $(div).scrollTop( st - (2/3) * h ) + var st = $(div).scrollTop() + d.warn("ST NOW: "+st+" "+h) + }, + pageDown: function (div) + { + var st = $(div).scrollTop() + var h = $(window).height() + $(div).scrollTop( st + (2/3) * h ) + }, + choice: function (list) + { + return list[Math.floor (Math.random () * list.length)] + }, + trim: function (s) + { + if (s) + return s.replace(/^\s+|\s+$/g,"") + else + return "" + }, + sanitizeWithNewlines: function (s) + { + if (s) + return d.trim( s ).replace(//g,">").replace(/\"/g,""").replace(/\0/g,"") + return "" + }, + sanitize: function (s) + { + if (s) + return d.trim( s ).replace(//g,">").replace(/\"/g,""").replace(/\n/g,"").replace(/\r/g,"").replace(/\0/g,"") + return "" + }, + linkify: function (s) + { + var words = s.split(" ") + var checked = [] + for (i in words) + { + var word = words[i] + if (words[i].indexOf("http") === 0) + { + var poffset = word.indexOf('//') + var linktext = word.substr(poffset+2, word.indexOf('/', poffset+2)) + checked.push(''+linktext+'') + } + else + checked.push(word) + } + return checked.join(" ") + }, + enableStylesheet: function (style) + { + $("link[@rel*=style][title]").each(function (i) + { + if (this.getAttribute('title') == style) + this.disabled = false + }) + }, + disableStylesheet: function (style) + { + $("link[@rel*=style][title]").each(function (i) + { + if (this.getAttribute('title') == style) + this.disabled = true + }) + }, + buildLookup: function (list) + { + var lookup = {} + for (var i = 0; i < list.length; i++) + lookup[list[i]] = true + return lookup + } + } + diff --git a/frontend/static/js/src/jquery-1.5.2.min.js b/frontend/static/js/src/jquery-1.5.2.min.js new file mode 100755 index 0000000..f78f96a --- /dev/null +++ b/frontend/static/js/src/jquery-1.5.2.min.js @@ -0,0 +1,16 @@ +/*! + * jQuery JavaScript Library v1.5.2 + * http://jquery.com/ + * + * Copyright 2011, John Resig + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * Includes Sizzle.js + * http://sizzlejs.com/ + * Copyright 2011, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * + * Date: Thu Mar 31 15:28:23 2011 -0400 + */ +(function(a,b){function ci(a){return d.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cf(a){if(!b_[a]){var b=d("<"+a+">").appendTo("body"),c=b.css("display");b.remove();if(c==="none"||c==="")c="block";b_[a]=c}return b_[a]}function ce(a,b){var c={};d.each(cd.concat.apply([],cd.slice(0,b)),function(){c[this]=a});return c}function b$(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function bZ(){try{return new a.XMLHttpRequest}catch(b){}}function bY(){d(a).unload(function(){for(var a in bW)bW[a](0,1)})}function bS(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var e=a.dataTypes,f={},g,h,i=e.length,j,k=e[0],l,m,n,o,p;for(g=1;g=0===c})}function P(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function H(a,b){return(a&&a!=="*"?a+".":"")+b.replace(t,"`").replace(u,"&")}function G(a){var b,c,e,f,g,h,i,j,k,l,m,n,o,p=[],q=[],s=d._data(this,"events");if(a.liveFired!==this&&s&&s.live&&!a.target.disabled&&(!a.button||a.type!=="click")){a.namespace&&(n=new RegExp("(^|\\.)"+a.namespace.split(".").join("\\.(?:.*\\.)?")+"(\\.|$)")),a.liveFired=this;var t=s.live.slice(0);for(i=0;ic)break;a.currentTarget=f.elem,a.data=f.handleObj.data,a.handleObj=f.handleObj,o=f.handleObj.origHandler.apply(f.elem,arguments);if(o===!1||a.isPropagationStopped()){c=f.level,o===!1&&(b=!1);if(a.isImmediatePropagationStopped())break}}return b}}function E(a,c,e){var f=d.extend({},e[0]);f.type=a,f.originalEvent={},f.liveFired=b,d.event.handle.call(c,f),f.isDefaultPrevented()&&e[0].preventDefault()}function y(){return!0}function x(){return!1}function i(a){for(var b in a)if(b!=="toJSON")return!1;return!0}function h(a,c,e){if(e===b&&a.nodeType===1){e=a.getAttribute("data-"+c);if(typeof e==="string"){try{e=e==="true"?!0:e==="false"?!1:e==="null"?null:d.isNaN(e)?g.test(e)?d.parseJSON(e):e:parseFloat(e)}catch(f){}d.data(a,c,e)}else e=b}return e}var c=a.document,d=function(){function G(){if(!d.isReady){try{c.documentElement.doScroll("left")}catch(a){setTimeout(G,1);return}d.ready()}}var d=function(a,b){return new d.fn.init(a,b,g)},e=a.jQuery,f=a.$,g,h=/^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/,i=/\S/,j=/^\s+/,k=/\s+$/,l=/\d/,m=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,n=/^[\],:{}\s]*$/,o=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,p=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,q=/(?:^|:|,)(?:\s*\[)+/g,r=/(webkit)[ \/]([\w.]+)/,s=/(opera)(?:.*version)?[ \/]([\w.]+)/,t=/(msie) ([\w.]+)/,u=/(mozilla)(?:.*? rv:([\w.]+))?/,v=navigator.userAgent,w,x,y,z=Object.prototype.toString,A=Object.prototype.hasOwnProperty,B=Array.prototype.push,C=Array.prototype.slice,D=String.prototype.trim,E=Array.prototype.indexOf,F={};d.fn=d.prototype={constructor:d,init:function(a,e,f){var g,i,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!e&&c.body){this.context=c,this[0]=c.body,this.selector="body",this.length=1;return this}if(typeof a==="string"){g=h.exec(a);if(!g||!g[1]&&e)return!e||e.jquery?(e||f).find(a):this.constructor(e).find(a);if(g[1]){e=e instanceof d?e[0]:e,k=e?e.ownerDocument||e:c,j=m.exec(a),j?d.isPlainObject(e)?(a=[c.createElement(j[1])],d.fn.attr.call(a,e,!0)):a=[k.createElement(j[1])]:(j=d.buildFragment([g[1]],[k]),a=(j.cacheable?d.clone(j.fragment):j.fragment).childNodes);return d.merge(this,a)}i=c.getElementById(g[2]);if(i&&i.parentNode){if(i.id!==g[2])return f.find(a);this.length=1,this[0]=i}this.context=c,this.selector=a;return this}if(d.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return d.makeArray(a,this)},selector:"",jquery:"1.5.2",length:0,size:function(){return this.length},toArray:function(){return C.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var e=this.constructor();d.isArray(a)?B.apply(e,a):d.merge(e,a),e.prevObject=this,e.context=this.context,b==="find"?e.selector=this.selector+(this.selector?" ":"")+c:b&&(e.selector=this.selector+"."+b+"("+c+")");return e},each:function(a,b){return d.each(this,a,b)},ready:function(a){d.bindReady(),x.done(a);return this},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(C.apply(this,arguments),"slice",C.call(arguments).join(","))},map:function(a){return this.pushStack(d.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:B,sort:[].sort,splice:[].splice},d.fn.init.prototype=d.fn,d.extend=d.fn.extend=function(){var a,c,e,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i==="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!=="object"&&!d.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j0)return;x.resolveWith(c,[d]),d.fn.trigger&&d(c).trigger("ready").unbind("ready")}},bindReady:function(){if(!x){x=d._Deferred();if(c.readyState==="complete")return setTimeout(d.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",y,!1),a.addEventListener("load",d.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",y),a.attachEvent("onload",d.ready);var b=!1;try{b=a.frameElement==null}catch(e){}c.documentElement.doScroll&&b&&G()}}},isFunction:function(a){return d.type(a)==="function"},isArray:Array.isArray||function(a){return d.type(a)==="array"},isWindow:function(a){return a&&typeof a==="object"&&"setInterval"in a},isNaN:function(a){return a==null||!l.test(a)||isNaN(a)},type:function(a){return a==null?String(a):F[z.call(a)]||"object"},isPlainObject:function(a){if(!a||d.type(a)!=="object"||a.nodeType||d.isWindow(a))return!1;if(a.constructor&&!A.call(a,"constructor")&&!A.call(a.constructor.prototype,"isPrototypeOf"))return!1;var c;for(c in a){}return c===b||A.call(a,c)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw a},parseJSON:function(b){if(typeof b!=="string"||!b)return null;b=d.trim(b);if(n.test(b.replace(o,"@").replace(p,"]").replace(q,"")))return a.JSON&&a.JSON.parse?a.JSON.parse(b):(new Function("return "+b))();d.error("Invalid JSON: "+b)},parseXML:function(b,c,e){a.DOMParser?(e=new DOMParser,c=e.parseFromString(b,"text/xml")):(c=new ActiveXObject("Microsoft.XMLDOM"),c.async="false",c.loadXML(b)),e=c.documentElement,(!e||!e.nodeName||e.nodeName==="parsererror")&&d.error("Invalid XML: "+b);return c},noop:function(){},globalEval:function(a){if(a&&i.test(a)){var b=c.head||c.getElementsByTagName("head")[0]||c.documentElement,e=c.createElement("script");d.support.scriptEval()?e.appendChild(c.createTextNode(a)):e.text=a,b.insertBefore(e,b.firstChild),b.removeChild(e)}},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,e){var f,g=0,h=a.length,i=h===b||d.isFunction(a);if(e){if(i){for(f in a)if(c.apply(a[f],e)===!1)break}else for(;g1?f.call(arguments,0):c,--g||h.resolveWith(h,f.call(b,0))}}var b=arguments,c=0,e=b.length,g=e,h=e<=1&&a&&d.isFunction(a.promise)?a:d.Deferred();if(e>1){for(;c
a";var e=b.getElementsByTagName("*"),f=b.getElementsByTagName("a")[0],g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=b.getElementsByTagName("input")[0];if(e&&e.length&&f){d.support={leadingWhitespace:b.firstChild.nodeType===3,tbody:!b.getElementsByTagName("tbody").length,htmlSerialize:!!b.getElementsByTagName("link").length,style:/red/.test(f.getAttribute("style")),hrefNormalized:f.getAttribute("href")==="/a",opacity:/^0.55$/.test(f.style.opacity),cssFloat:!!f.style.cssFloat,checkOn:i.value==="on",optSelected:h.selected,deleteExpando:!0,optDisabled:!1,checkClone:!1,noCloneEvent:!0,noCloneChecked:!0,boxModel:null,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableHiddenOffsets:!0,reliableMarginRight:!0},i.checked=!0,d.support.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,d.support.optDisabled=!h.disabled;var j=null;d.support.scriptEval=function(){if(j===null){var b=c.documentElement,e=c.createElement("script"),f="script"+d.now();try{e.appendChild(c.createTextNode("window."+f+"=1;"))}catch(g){}b.insertBefore(e,b.firstChild),a[f]?(j=!0,delete a[f]):j=!1,b.removeChild(e)}return j};try{delete b.test}catch(k){d.support.deleteExpando=!1}!b.addEventListener&&b.attachEvent&&b.fireEvent&&(b.attachEvent("onclick",function l(){d.support.noCloneEvent=!1,b.detachEvent("onclick",l)}),b.cloneNode(!0).fireEvent("onclick")),b=c.createElement("div"),b.innerHTML="";var m=c.createDocumentFragment();m.appendChild(b.firstChild),d.support.checkClone=m.cloneNode(!0).cloneNode(!0).lastChild.checked,d(function(){var a=c.createElement("div"),b=c.getElementsByTagName("body")[0];if(b){a.style.width=a.style.paddingLeft="1px",b.appendChild(a),d.boxModel=d.support.boxModel=a.offsetWidth===2,"zoom"in a.style&&(a.style.display="inline",a.style.zoom=1,d.support.inlineBlockNeedsLayout=a.offsetWidth===2,a.style.display="",a.innerHTML="
",d.support.shrinkWrapBlocks=a.offsetWidth!==2),a.innerHTML="
t
";var e=a.getElementsByTagName("td");d.support.reliableHiddenOffsets=e[0].offsetHeight===0,e[0].style.display="",e[1].style.display="none",d.support.reliableHiddenOffsets=d.support.reliableHiddenOffsets&&e[0].offsetHeight===0,a.innerHTML="",c.defaultView&&c.defaultView.getComputedStyle&&(a.style.width="1px",a.style.marginRight="0",d.support.reliableMarginRight=(parseInt(c.defaultView.getComputedStyle(a,null).marginRight,10)||0)===0),b.removeChild(a).style.display="none",a=e=null}});var n=function(a){var b=c.createElement("div");a="on"+a;if(!b.attachEvent)return!0;var d=a in b;d||(b.setAttribute(a,"return;"),d=typeof b[a]==="function");return d};d.support.submitBubbles=n("submit"),d.support.changeBubbles=n("change"),b=e=f=null}}();var g=/^(?:\{.*\}|\[.*\])$/;d.extend({cache:{},uuid:0,expando:"jQuery"+(d.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?d.cache[a[d.expando]]:a[d.expando];return!!a&&!i(a)},data:function(a,c,e,f){if(d.acceptData(a)){var g=d.expando,h=typeof c==="string",i,j=a.nodeType,k=j?d.cache:a,l=j?a[d.expando]:a[d.expando]&&d.expando;if((!l||f&&l&&!k[l][g])&&h&&e===b)return;l||(j?a[d.expando]=l=++d.uuid:l=d.expando),k[l]||(k[l]={},j||(k[l].toJSON=d.noop));if(typeof c==="object"||typeof c==="function")f?k[l][g]=d.extend(k[l][g],c):k[l]=d.extend(k[l],c);i=k[l],f&&(i[g]||(i[g]={}),i=i[g]),e!==b&&(i[c]=e);if(c==="events"&&!i[c])return i[g]&&i[g].events;return h?i[c]:i}},removeData:function(b,c,e){if(d.acceptData(b)){var f=d.expando,g=b.nodeType,h=g?d.cache:b,j=g?b[d.expando]:d.expando;if(!h[j])return;if(c){var k=e?h[j][f]:h[j];if(k){delete k[c];if(!i(k))return}}if(e){delete h[j][f];if(!i(h[j]))return}var l=h[j][f];d.support.deleteExpando||h!=a?delete h[j]:h[j]=null,l?(h[j]={},g||(h[j].toJSON=d.noop),h[j][f]=l):g&&(d.support.deleteExpando?delete b[d.expando]:b.removeAttribute?b.removeAttribute(d.expando):b[d.expando]=null)}},_data:function(a,b,c){return d.data(a,b,c,!0)},acceptData:function(a){if(a.nodeName){var b=d.noData[a.nodeName.toLowerCase()];if(b)return b!==!0&&a.getAttribute("classid")===b}return!0}}),d.fn.extend({data:function(a,c){var e=null;if(typeof a==="undefined"){if(this.length){e=d.data(this[0]);if(this[0].nodeType===1){var f=this[0].attributes,g;for(var i=0,j=f.length;i-1)return!0;return!1},val:function(a){if(!arguments.length){var c=this[0];if(c){if(d.nodeName(c,"option")){var e=c.attributes.value;return!e||e.specified?c.value:c.text}if(d.nodeName(c,"select")){var f=c.selectedIndex,g=[],h=c.options,i=c.type==="select-one";if(f<0)return null;for(var j=i?f:0,k=i?f+1:h.length;j=0;else if(d.nodeName(this,"select")){var f=d.makeArray(e);d("option",this).each(function(){this.selected=d.inArray(d(this).val(),f)>=0}),f.length||(this.selectedIndex=-1)}else this.value=e}})}}),d.extend({attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,e,f){if(!a||a.nodeType===3||a.nodeType===8||a.nodeType===2)return b;if(f&&c in d.attrFn)return d(a)[c](e);var g=a.nodeType!==1||!d.isXMLDoc(a),h=e!==b;c=g&&d.props[c]||c;if(a.nodeType===1){var i=m.test(c);if(c==="selected"&&!d.support.optSelected){var j=a.parentNode;j&&(j.selectedIndex,j.parentNode&&j.parentNode.selectedIndex)}if((c in a||a[c]!==b)&&g&&!i){h&&(c==="type"&&n.test(a.nodeName)&&a.parentNode&&d.error("type property can't be changed"),e===null?a.nodeType===1&&a.removeAttribute(c):a[c]=e);if(d.nodeName(a,"form")&&a.getAttributeNode(c))return a.getAttributeNode(c).nodeValue;if(c==="tabIndex"){var k=a.getAttributeNode("tabIndex");return k&&k.specified?k.value:o.test(a.nodeName)||p.test(a.nodeName)&&a.href?0:b}return a[c]}if(!d.support.style&&g&&c==="style"){h&&(a.style.cssText=""+e);return a.style.cssText}h&&a.setAttribute(c,""+e);if(!a.attributes[c]&&(a.hasAttribute&&!a.hasAttribute(c)))return b;var l=!d.support.hrefNormalized&&g&&i?a.getAttribute(c,2):a.getAttribute(c);return l===null?b:l}h&&(a[c]=e);return a[c]}});var r=/\.(.*)$/,s=/^(?:textarea|input|select)$/i,t=/\./g,u=/ /g,v=/[^\w\s.|`]/g,w=function(a){return a.replace(v,"\\$&")};d.event={add:function(c,e,f,g){if(c.nodeType!==3&&c.nodeType!==8){try{d.isWindow(c)&&(c!==a&&!c.frameElement)&&(c=a)}catch(h){}if(f===!1)f=x;else if(!f)return;var i,j;f.handler&&(i=f,f=i.handler),f.guid||(f.guid=d.guid++);var k=d._data(c);if(!k)return;var l=k.events,m=k.handle;l||(k.events=l={}),m||(k.handle=m=function(a){return typeof d!=="undefined"&&d.event.triggered!==a.type?d.event.handle.apply(m.elem,arguments):b}),m.elem=c,e=e.split(" ");var n,o=0,p;while(n=e[o++]){j=i?d.extend({},i):{handler:f,data:g},n.indexOf(".")>-1?(p=n.split("."),n=p.shift(),j.namespace=p.slice(0).sort().join(".")):(p=[],j.namespace=""),j.type=n,j.guid||(j.guid=f.guid);var q=l[n],r=d.event.special[n]||{};if(!q){q=l[n]=[];if(!r.setup||r.setup.call(c,g,p,m)===!1)c.addEventListener?c.addEventListener(n,m,!1):c.attachEvent&&c.attachEvent("on"+n,m)}r.add&&(r.add.call(c,j),j.handler.guid||(j.handler.guid=f.guid)),q.push(j),d.event.global[n]=!0}c=null}},global:{},remove:function(a,c,e,f){if(a.nodeType!==3&&a.nodeType!==8){e===!1&&(e=x);var g,h,i,j,k=0,l,m,n,o,p,q,r,s=d.hasData(a)&&d._data(a),t=s&&s.events;if(!s||!t)return;c&&c.type&&(e=c.handler,c=c.type);if(!c||typeof c==="string"&&c.charAt(0)==="."){c=c||"";for(h in t)d.event.remove(a,h+c);return}c=c.split(" ");while(h=c[k++]){r=h,q=null,l=h.indexOf(".")<0,m=[],l||(m=h.split("."),h=m.shift(),n=new RegExp("(^|\\.)"+d.map(m.slice(0).sort(),w).join("\\.(?:.*\\.)?")+"(\\.|$)")),p=t[h];if(!p)continue;if(!e){for(j=0;j=0&&(a.type=f=f.slice(0,-1),a.exclusive=!0),e||(a.stopPropagation(),d.event.global[f]&&d.each(d.cache,function(){var b=d.expando,e=this[b];e&&e.events&&e.events[f]&&d.event.trigger(a,c,e.handle.elem)}));if(!e||e.nodeType===3||e.nodeType===8)return b;a.result=b,a.target=e,c=d.makeArray(c),c.unshift(a)}a.currentTarget=e;var h=d._data(e,"handle");h&&h.apply(e,c);var i=e.parentNode||e.ownerDocument;try{e&&e.nodeName&&d.noData[e.nodeName.toLowerCase()]||e["on"+f]&&e["on"+f].apply(e,c)===!1&&(a.result=!1,a.preventDefault())}catch(j){}if(!a.isPropagationStopped()&&i)d.event.trigger(a,c,i,!0);else if(!a.isDefaultPrevented()){var k,l=a.target,m=f.replace(r,""),n=d.nodeName(l,"a")&&m==="click",o=d.event.special[m]||{};if((!o._default||o._default.call(e,a)===!1)&&!n&&!(l&&l.nodeName&&d.noData[l.nodeName.toLowerCase()])){try{l[m]&&(k=l["on"+m],k&&(l["on"+m]=null),d.event.triggered=a.type,l[m]())}catch(p){}k&&(l["on"+m]=k),d.event.triggered=b}}},handle:function(c){var e,f,g,h,i,j=[],k=d.makeArray(arguments);c=k[0]=d.event.fix(c||a.event),c.currentTarget=this,e=c.type.indexOf(".")<0&&!c.exclusive,e||(g=c.type.split("."),c.type=g.shift(),j=g.slice(0).sort(),h=new RegExp("(^|\\.)"+j.join("\\.(?:.*\\.)?")+"(\\.|$)")),c.namespace=c.namespace||j.join("."),i=d._data(this,"events"),f=(i||{})[c.type];if(i&&f){f=f.slice(0);for(var l=0,m=f.length;l-1?d.map(a.options,function(a){return a.selected}).join("-"):"":a.nodeName.toLowerCase()==="select"&&(c=a.selectedIndex);return c},D=function D(a){var c=a.target,e,f;if(s.test(c.nodeName)&&!c.readOnly){e=d._data(c,"_change_data"),f=C(c),(a.type!=="focusout"||c.type!=="radio")&&d._data(c,"_change_data",f);if(e===b||f===e)return;if(e!=null||f)a.type="change",a.liveFired=b,d.event.trigger(a,arguments[1],c)}};d.event.special.change={filters:{focusout:D,beforedeactivate:D,click:function(a){var b=a.target,c=b.type;(c==="radio"||c==="checkbox"||b.nodeName.toLowerCase()==="select")&&D.call(this,a)},keydown:function(a){var b=a.target,c=b.type;(a.keyCode===13&&b.nodeName.toLowerCase()!=="textarea"||a.keyCode===32&&(c==="checkbox"||c==="radio")||c==="select-multiple")&&D.call(this,a)},beforeactivate:function(a){var b=a.target;d._data(b,"_change_data",C(b))}},setup:function(a,b){if(this.type==="file")return!1;for(var c in B)d.event.add(this,c+".specialChange",B[c]);return s.test(this.nodeName)},teardown:function(a){d.event.remove(this,".specialChange");return s.test(this.nodeName)}},B=d.event.special.change.filters,B.focus=B.beforeactivate}c.addEventListener&&d.each({focus:"focusin",blur:"focusout"},function(a,b){function f(a){var c=d.event.fix(a);c.type=b,c.originalEvent={},d.event.trigger(c,null,c.target),c.isDefaultPrevented()&&a.preventDefault()}var e=0;d.event.special[b]={setup:function(){e++===0&&c.addEventListener(a,f,!0)},teardown:function(){--e===0&&c.removeEventListener(a,f,!0)}}}),d.each(["bind","one"],function(a,c){d.fn[c]=function(a,e,f){if(typeof a==="object"){for(var g in a)this[c](g,e,a[g],f);return this}if(d.isFunction(e)||e===!1)f=e,e=b;var h=c==="one"?d.proxy(f,function(a){d(this).unbind(a,h);return f.apply(this,arguments)}):f;if(a==="unload"&&c!=="one")this.one(a,e,f);else for(var i=0,j=this.length;i0?this.bind(b,a,c):this.trigger(b)},d.attrFn&&(d.attrFn[b]=!0)}),function(){function u(a,b,c,d,e,f){for(var g=0,h=d.length;g0){j=i;break}}i=i[a]}d[g]=j}}}function t(a,b,c,d,e,f){for(var g=0,h=d.length;g+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,e=0,f=Object.prototype.toString,g=!1,h=!0,i=/\\/g,j=/\W/;[0,0].sort(function(){h=!1;return 0});var k=function(b,d,e,g){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!=="string")return e;var i,j,n,o,q,r,s,t,u=!0,w=k.isXML(d),x=[],y=b;do{a.exec(""),i=a.exec(y);if(i){y=i[3],x.push(i[1]);if(i[2]){o=i[3];break}}}while(i);if(x.length>1&&m.exec(b))if(x.length===2&&l.relative[x[0]])j=v(x[0]+x[1],d);else{j=l.relative[x[0]]?[d]:k(x.shift(),d);while(x.length)b=x.shift(),l.relative[b]&&(b+=x.shift()),j=v(b,j)}else{!g&&x.length>1&&d.nodeType===9&&!w&&l.match.ID.test(x[0])&&!l.match.ID.test(x[x.length-1])&&(q=k.find(x.shift(),d,w),d=q.expr?k.filter(q.expr,q.set)[0]:q.set[0]);if(d){q=g?{expr:x.pop(),set:p(g)}:k.find(x.pop(),x.length===1&&(x[0]==="~"||x[0]==="+")&&d.parentNode?d.parentNode:d,w),j=q.expr?k.filter(q.expr,q.set):q.set,x.length>0?n=p(j):u=!1;while(x.length)r=x.pop(),s=r,l.relative[r]?s=x.pop():r="",s==null&&(s=d),l.relative[r](n,s,w)}else n=x=[]}n||(n=j),n||k.error(r||b);if(f.call(n)==="[object Array]")if(u)if(d&&d.nodeType===1)for(t=0;n[t]!=null;t++)n[t]&&(n[t]===!0||n[t].nodeType===1&&k.contains(d,n[t]))&&e.push(j[t]);else for(t=0;n[t]!=null;t++)n[t]&&n[t].nodeType===1&&e.push(j[t]);else e.push.apply(e,n);else p(n,e);o&&(k(o,h,e,g),k.uniqueSort(e));return e};k.uniqueSort=function(a){if(r){g=h,a.sort(r);if(g)for(var b=1;b0},k.find=function(a,b,c){var d;if(!a)return[];for(var e=0,f=l.order.length;e":function(a,b){var c,d=typeof b==="string",e=0,f=a.length;if(d&&!j.test(b)){b=b.toLowerCase();for(;e=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(i,"")},TAG:function(a,b){return a[1].replace(i,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||k.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&k.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(i,"");!f&&l.attrMap[g]&&(a[1]=l.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(i,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=k(b[3],null,null,c);else{var g=k.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(l.match.POS.test(b[0])||l.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!k(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return"text"===c&&(b===c||b===null)},radio:function(a){return"radio"===a.type},checkbox:function(a){return"checkbox"===a.type},file:function(a){return"file"===a.type},password:function(a){return"password"===a.type},submit:function(a){return"submit"===a.type},image:function(a){return"image"===a.type},reset:function(a){return"reset"===a.type},button:function(a){return"button"===a.type||a.nodeName.toLowerCase()==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return bc[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=l.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||k.getText([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=l.attrHandle[c]?l.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=l.setFilters[e];if(f)return f(a,c,b,d)}}},m=l.match.POS,n=function(a,b){return"\\"+(b-0+1)};for(var o in l.match)l.match[o]=new RegExp(l.match[o].source+/(?![^\[]*\])(?![^\(]*\))/.source),l.leftMatch[o]=new RegExp(/(^(?:.|\r|\n)*?)/.source+l.match[o].source.replace(/\\(\d+)/g,n));var p=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(q){p=function(a,b){var c=0,d=b||[];if(f.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length==="number")for(var e=a.length;c",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(l.find.ID=function(a,c,d){if(typeof c.getElementById!=="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!=="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},l.filter.ID=function(a,b){var c=typeof a.getAttributeNode!=="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(l.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="",a.firstChild&&typeof a.firstChild.getAttribute!=="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(l.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=k,b=c.createElement("div"),d="__sizzle__";b.innerHTML="

";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){k=function(b,e,f,g){e=e||c;if(!g&&!k.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return p(e.getElementsByTagName(b),f);if(h[2]&&l.find.CLASS&&e.getElementsByClassName)return p(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return p([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return p([],f);if(i.id===h[3])return p([i],f)}try{return p(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var m=e,n=e.getAttribute("id"),o=n||d,q=e.parentNode,r=/^\s*[+~]/.test(b);n?o=o.replace(/'/g,"\\$&"):e.setAttribute("id",o),r&&q&&(e=e.parentNode);try{if(!r||q)return p(e.querySelectorAll("[id='"+o+"'] "+b),f)}catch(s){}finally{n||m.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)k[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}k.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!k.isXML(a))try{if(e||!l.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return k(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="
";if(a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;l.order.splice(1,0,"CLASS"),l.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!=="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?k.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?k.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:k.contains=function(){return!1},k.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var v=function(a,b){var c,d=[],e="",f=b.nodeType?[b]:b;while(c=l.match.PSEUDO.exec(a))e+=c[0],a=a.replace(l.match.PSEUDO,"");a=l.relative[a]?a+"*":a;for(var g=0,h=f.length;g0)for(var g=c;g0},closest:function(a,b){var c=[],e,f,g=this[0];if(d.isArray(a)){var h,i,j={},k=1;if(g&&a.length){for(e=0,f=a.length;e-1:d(g).is(h))&&c.push({selector:i,elem:g,level:k});g=g.parentNode,k++}}return c}var l=N.test(a)?d(a,b||this.context):null;for(e=0,f=this.length;e-1:d.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b)break}}c=c.length>1?d.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a||typeof a==="string")return d.inArray(this[0],a?d(a):this.parent().children());return d.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a==="string"?d(a,b):d.makeArray(a),e=d.merge(this.get(),c);return this.pushStack(P(c[0])||P(e[0])?e:d.unique(e))},andSelf:function(){return this.add(this.prevObject)}}),d.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return d.dir(a,"parentNode")},parentsUntil:function(a,b,c){return d.dir(a,"parentNode",c)},next:function(a){return d.nth(a,2,"nextSibling")},prev:function(a){return d.nth(a,2,"previousSibling")},nextAll:function(a){return d.dir(a,"nextSibling")},prevAll:function(a){return d.dir(a,"previousSibling")},nextUntil:function(a,b,c){return d.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return d.dir(a,"previousSibling",c)},siblings:function(a){return d.sibling(a.parentNode.firstChild,a)},children:function(a){return d.sibling(a.firstChild)},contents:function(a){return d.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:d.makeArray(a.childNodes)}},function(a,b){d.fn[a]=function(c,e){var f=d.map(this,b,c),g=M.call(arguments);I.test(a)||(e=c),e&&typeof e==="string"&&(f=d.filter(e,f)),f=this.length>1&&!O[a]?d.unique(f):f,(this.length>1||K.test(e))&&J.test(a)&&(f=f.reverse());return this.pushStack(f,a,g.join(","))}}),d.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?d.find.matchesSelector(b[0],a)?[b[0]]:[]:d.find.matches(a,b)},dir:function(a,c,e){var f=[],g=a[c];while(g&&g.nodeType!==9&&(e===b||g.nodeType!==1||!d(g).is(e)))g.nodeType===1&&f.push(g),g=g[c];return f},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var R=/ jQuery\d+="(?:\d+|null)"/g,S=/^\s+/,T=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,U=/<([\w:]+)/,V=/",""],legend:[1,"
","
"],thead:[1,"","
"],tr:[2,"","
"],td:[3,"","
"],col:[2,"","
"],area:[1,"",""],_default:[0,"",""]};Z.optgroup=Z.option,Z.tbody=Z.tfoot=Z.colgroup=Z.caption=Z.thead,Z.th=Z.td,d.support.htmlSerialize||(Z._default=[1,"div
","
"]),d.fn.extend({text:function(a){if(d.isFunction(a))return this.each(function(b){var c=d(this);c.text(a.call(this,b,c.text()))});if(typeof a!=="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return d.text(this)},wrapAll:function(a){if(d.isFunction(a))return this.each(function(b){d(this).wrapAll(a.call(this,b))});if(this[0]){var b=d(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(d.isFunction(a))return this.each(function(b){d(this).wrapInner(a.call(this,b))});return this.each(function(){var b=d(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){d(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){d.nodeName(this,"body")||d(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=d(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,d(arguments[0]).toArray());return a}},remove:function(a,b){for(var c=0,e;(e=this[c])!=null;c++)if(!a||d.filter(a,[e]).length)!b&&e.nodeType===1&&(d.cleanData(e.getElementsByTagName("*")),d.cleanData([e])),e.parentNode&&e.parentNode.removeChild(e);return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&d.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return d.clone(this,a,b)})},html:function(a){if(a===b)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(R,""):null;if(typeof a!=="string"||X.test(a)||!d.support.leadingWhitespace&&S.test(a)||Z[(U.exec(a)||["",""])[1].toLowerCase()])d.isFunction(a)?this.each(function(b){var c=d(this);c.html(a.call(this,b,c.html()))}):this.empty().append(a);else{a=a.replace(T,"<$1>");try{for(var c=0,e=this.length;c1&&l0?this.clone(!0):this).get();d(f[h])[b](j),e=e.concat(j)}return this.pushStack(e,a,f.selector)}}),d.extend({clone:function(a,b,c){var e=a.cloneNode(!0),f,g,h;if((!d.support.noCloneEvent||!d.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!d.isXMLDoc(a)){ba(a,e),f=bb(a),g=bb(e);for(h=0;f[h];++h)ba(f[h],g[h])}if(b){_(a,e);if(c){f=bb(a),g=bb(e);for(h=0;f[h];++h)_(f[h],g[h])}}return e},clean:function(a,b,e,f){b=b||c,typeof b.createElement==="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);var g=[];for(var h=0,i;(i=a[h])!=null;h++){typeof i==="number"&&(i+="");if(!i)continue;if(typeof i!=="string"||W.test(i)){if(typeof i==="string"){i=i.replace(T,"<$1>");var j=(U.exec(i)||["",""])[1].toLowerCase(),k=Z[j]||Z._default,l=k[0],m=b.createElement("div");m.innerHTML=k[1]+i+k[2];while(l--)m=m.lastChild;if(!d.support.tbody){var n=V.test(i),o=j==="table"&&!n?m.firstChild&&m.firstChild.childNodes:k[1]===""&&!n?m.childNodes:[];for(var p=o.length-1;p>=0;--p)d.nodeName(o[p],"tbody")&&!o[p].childNodes.length&&o[p].parentNode.removeChild(o[p])}!d.support.leadingWhitespace&&S.test(i)&&m.insertBefore(b.createTextNode(S.exec(i)[0]),m.firstChild),i=m.childNodes}}else i=b.createTextNode(i);i.nodeType?g.push(i):g=d.merge(g,i)}if(e)for(h=0;g[h];h++)!f||!d.nodeName(g[h],"script")||g[h].type&&g[h].type.toLowerCase()!=="text/javascript"?(g[h].nodeType===1&&g.splice.apply(g,[h+1,0].concat(d.makeArray(g[h].getElementsByTagName("script")))),e.appendChild(g[h])):f.push(g[h].parentNode?g[h].parentNode.removeChild(g[h]):g[h]);return g},cleanData:function(a){var b,c,e=d.cache,f=d.expando,g=d.event.special,h=d.support.deleteExpando;for(var i=0,j;(j=a[i])!=null;i++){if(j.nodeName&&d.noData[j.nodeName.toLowerCase()])continue;c=j[d.expando];if(c){b=e[c]&&e[c][f];if(b&&b.events){for(var k in b.events)g[k]?d.event.remove(j,k):d.removeEvent(j,k,b.handle);b.handle&&(b.handle.elem=null)}h?delete j[d.expando]:j.removeAttribute&&j.removeAttribute(d.expando),delete e[c]}}}});var bd=/alpha\([^)]*\)/i,be=/opacity=([^)]*)/,bf=/-([a-z])/ig,bg=/([A-Z]|^ms)/g,bh=/^-?\d+(?:px)?$/i,bi=/^-?\d/,bj={position:"absolute",visibility:"hidden",display:"block"},bk=["Left","Right"],bl=["Top","Bottom"],bm,bn,bo,bp=function(a,b){return b.toUpperCase()};d.fn.css=function(a,c){if(arguments.length===2&&c===b)return this;return d.access(this,a,c,!0,function(a,c,e){return e!==b?d.style(a,c,e):d.css(a,c)})},d.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=bm(a,"opacity","opacity");return c===""?"1":c}return a.style.opacity}}},cssNumber:{zIndex:!0,fontWeight:!0,opacity:!0,zoom:!0,lineHeight:!0},cssProps:{"float":d.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,c,e,f){if(a&&a.nodeType!==3&&a.nodeType!==8&&a.style){var g,h=d.camelCase(c),i=a.style,j=d.cssHooks[h];c=d.cssProps[h]||h;if(e===b){if(j&&"get"in j&&(g=j.get(a,!1,f))!==b)return g;return i[c]}if(typeof e==="number"&&isNaN(e)||e==null)return;typeof e==="number"&&!d.cssNumber[h]&&(e+="px");if(!j||!("set"in j)||(e=j.set(a,e))!==b)try{i[c]=e}catch(k){}}},css:function(a,c,e){var f,g=d.camelCase(c),h=d.cssHooks[g];c=d.cssProps[g]||g;if(h&&"get"in h&&(f=h.get(a,!0,e))!==b)return f;if(bm)return bm(a,c,g)},swap:function(a,b,c){var d={};for(var e in b)d[e]=a.style[e],a.style[e]=b[e];c.call(a);for(e in b)a.style[e]=d[e]},camelCase:function(a){return a.replace(bf,bp)}}),d.curCSS=d.css,d.each(["height","width"],function(a,b){d.cssHooks[b]={get:function(a,c,e){var f;if(c){a.offsetWidth!==0?f=bq(a,b,e):d.swap(a,bj,function(){f=bq(a,b,e)});if(f<=0){f=bm(a,b,b),f==="0px"&&bo&&(f=bo(a,b,b));if(f!=null)return f===""||f==="auto"?"0px":f}if(f<0||f==null){f=a.style[b];return f===""||f==="auto"?"0px":f}return typeof f==="string"?f:f+"px"}},set:function(a,b){if(!bh.test(b))return b;b=parseFloat(b);if(b>=0)return b+"px"}}}),d.support.opacity||(d.cssHooks.opacity={get:function(a,b){return be.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style;c.zoom=1;var e=d.isNaN(b)?"":"alpha(opacity="+b*100+")",f=c.filter||"";c.filter=bd.test(f)?f.replace(bd,e):c.filter+" "+e}}),d(function(){d.support.reliableMarginRight||(d.cssHooks.marginRight={get:function(a,b){var c;d.swap(a,{display:"inline-block"},function(){b?c=bm(a,"margin-right","marginRight"):c=a.style.marginRight});return c}})}),c.defaultView&&c.defaultView.getComputedStyle&&(bn=function(a,c,e){var f,g,h;e=e.replace(bg,"-$1").toLowerCase();if(!(g=a.ownerDocument.defaultView))return b;if(h=g.getComputedStyle(a,null))f=h.getPropertyValue(e),f===""&&!d.contains(a.ownerDocument.documentElement,a)&&(f=d.style(a,e));return f}),c.documentElement.currentStyle&&(bo=function(a,b){var c,d=a.currentStyle&&a.currentStyle[b],e=a.runtimeStyle&&a.runtimeStyle[b],f=a.style;!bh.test(d)&&bi.test(d)&&(c=f.left,e&&(a.runtimeStyle.left=a.currentStyle.left),f.left=b==="fontSize"?"1em":d||0,d=f.pixelLeft+"px",f.left=c,e&&(a.runtimeStyle.left=e));return d===""?"auto":d}),bm=bn||bo,d.expr&&d.expr.filters&&(d.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!d.support.reliableHiddenOffsets&&(a.style.display||d.css(a,"display"))==="none"},d.expr.filters.visible=function(a){return!d.expr.filters.hidden(a)});var br=/%20/g,bs=/\[\]$/,bt=/\r?\n/g,bu=/#.*$/,bv=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bw=/^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bx=/^(?:about|app|app\-storage|.+\-extension|file|widget):$/,by=/^(?:GET|HEAD)$/,bz=/^\/\//,bA=/\?/,bB=/)<[^<]*)*<\/script>/gi,bC=/^(?:select|textarea)/i,bD=/\s+/,bE=/([?&])_=[^&]*/,bF=/(^|\-)([a-z])/g,bG=function(a,b,c){return b+c.toUpperCase()},bH=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bI=d.fn.load,bJ={},bK={},bL,bM;try{bL=c.location.href}catch(bN){bL=c.createElement("a"),bL.href="",bL=bL.href}bM=bH.exec(bL.toLowerCase())||[],d.fn.extend({load:function(a,c,e){if(typeof a!=="string"&&bI)return bI.apply(this,arguments);if(!this.length)return this;var f=a.indexOf(" ");if(f>=0){var g=a.slice(f,a.length);a=a.slice(0,f)}var h="GET";c&&(d.isFunction(c)?(e=c,c=b):typeof c==="object"&&(c=d.param(c,d.ajaxSettings.traditional),h="POST"));var i=this;d.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?d("
").append(c.replace(bB,"")).find(g):c)),e&&i.each(e,[c,b,a])}});return this},serialize:function(){return d.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?d.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bC.test(this.nodeName)||bw.test(this.type))}).map(function(a,b){var c=d(this).val();return c==null?null:d.isArray(c)?d.map(c,function(a,c){return{name:b.name,value:a.replace(bt,"\r\n")}}):{name:b.name,value:c.replace(bt,"\r\n")}}).get()}}),d.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){d.fn[b]=function(a){return this.bind(b,a)}}),d.each(["get","post"],function(a,c){d[c]=function(a,e,f,g){d.isFunction(e)&&(g=g||f,f=e,e=b);return d.ajax({type:c,url:a,data:e,success:f,dataType:g})}}),d.extend({getScript:function(a,c){return d.get(a,b,c,"script")},getJSON:function(a,b,c){return d.get(a,b,c,"json")},ajaxSetup:function(a,b){b?d.extend(!0,a,d.ajaxSettings,b):(b=a,a=d.extend(!0,d.ajaxSettings,b));for(var c in {context:1,url:1})c in b?a[c]=b[c]:c in d.ajaxSettings&&(a[c]=d.ajaxSettings[c]);return a},ajaxSettings:{url:bL,isLocal:bx.test(bM[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":"*/*"},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":d.parseJSON,"text xml":d.parseXML}},ajaxPrefilter:bO(bJ),ajaxTransport:bO(bK),ajax:function(a,c){function v(a,c,l,n){if(r!==2){r=2,p&&clearTimeout(p),o=b,m=n||"",u.readyState=a?4:0;var q,t,v,w=l?bR(e,u,l):b,x,y;if(a>=200&&a<300||a===304){if(e.ifModified){if(x=u.getResponseHeader("Last-Modified"))d.lastModified[k]=x;if(y=u.getResponseHeader("Etag"))d.etag[k]=y}if(a===304)c="notmodified",q=!0;else try{t=bS(e,w),c="success",q=!0}catch(z){c="parsererror",v=z}}else{v=c;if(!c||a)c="error",a<0&&(a=0)}u.status=a,u.statusText=c,q?h.resolveWith(f,[t,c,u]):h.rejectWith(f,[u,c,v]),u.statusCode(j),j=b,s&&g.trigger("ajax"+(q?"Success":"Error"),[u,e,q?t:v]),i.resolveWith(f,[u,c]),s&&(g.trigger("ajaxComplete",[u,e]),--d.active||d.event.trigger("ajaxStop"))}}typeof a==="object"&&(c=a,a=b),c=c||{};var e=d.ajaxSetup({},c),f=e.context||e,g=f!==e&&(f.nodeType||f instanceof d)?d(f):d.event,h=d.Deferred(),i=d._Deferred(),j=e.statusCode||{},k,l={},m,n,o,p,q,r=0,s,t,u={readyState:0,setRequestHeader:function(a,b){r||(l[a.toLowerCase().replace(bF,bG)]=b);return this},getAllResponseHeaders:function(){return r===2?m:null},getResponseHeader:function(a){var c;if(r===2){if(!n){n={};while(c=bv.exec(m))n[c[1].toLowerCase()]=c[2]}c=n[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){r||(e.mimeType=a);return this},abort:function(a){a=a||"abort",o&&o.abort(a),v(0,a);return this}};h.promise(u),u.success=u.done,u.error=u.fail,u.complete=i.done,u.statusCode=function(a){if(a){var b;if(r<2)for(b in a)j[b]=[j[b],a[b]];else b=a[u.status],u.then(b,b)}return this},e.url=((a||e.url)+"").replace(bu,"").replace(bz,bM[1]+"//"),e.dataTypes=d.trim(e.dataType||"*").toLowerCase().split(bD),e.crossDomain==null&&(q=bH.exec(e.url.toLowerCase()),e.crossDomain=q&&(q[1]!=bM[1]||q[2]!=bM[2]||(q[3]||(q[1]==="http:"?80:443))!=(bM[3]||(bM[1]==="http:"?80:443)))),e.data&&e.processData&&typeof e.data!=="string"&&(e.data=d.param(e.data,e.traditional)),bP(bJ,e,c,u);if(r===2)return!1;s=e.global,e.type=e.type.toUpperCase(),e.hasContent=!by.test(e.type),s&&d.active++===0&&d.event.trigger("ajaxStart");if(!e.hasContent){e.data&&(e.url+=(bA.test(e.url)?"&":"?")+e.data),k=e.url;if(e.cache===!1){var w=d.now(),x=e.url.replace(bE,"$1_="+w);e.url=x+(x===e.url?(bA.test(e.url)?"&":"?")+"_="+w:"")}}if(e.data&&e.hasContent&&e.contentType!==!1||c.contentType)l["Content-Type"]=e.contentType;e.ifModified&&(k=k||e.url,d.lastModified[k]&&(l["If-Modified-Since"]=d.lastModified[k]),d.etag[k]&&(l["If-None-Match"]=d.etag[k])),l.Accept=e.dataTypes[0]&&e.accepts[e.dataTypes[0]]?e.accepts[e.dataTypes[0]]+(e.dataTypes[0]!=="*"?", */*; q=0.01":""):e.accepts["*"];for(t in e.headers)u.setRequestHeader(t,e.headers[t]);if(e.beforeSend&&(e.beforeSend.call(f,u,e)===!1||r===2)){u.abort();return!1}for(t in {success:1,error:1,complete:1})u[t](e[t]);o=bP(bK,e,c,u);if(o){u.readyState=1,s&&g.trigger("ajaxSend",[u,e]),e.async&&e.timeout>0&&(p=setTimeout(function(){u.abort("timeout")},e.timeout));try{r=1,o.send(l,v)}catch(y){status<2?v(-1,y):d.error(y)}}else v(-1,"No Transport");return u},param:function(a,c){var e=[],f=function(a,b){b=d.isFunction(b)?b():b,e[e.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=d.ajaxSettings.traditional);if(d.isArray(a)||a.jquery&&!d.isPlainObject(a))d.each(a,function(){f(this.name,this.value)});else for(var g in a)bQ(g,a[g],c,f);return e.join("&").replace(br,"+")}}),d.extend({active:0,lastModified:{},etag:{}});var bT=d.now(),bU=/(\=)\?(&|$)|\?\?/i;d.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return d.expando+"_"+bT++}}),d.ajaxPrefilter("json jsonp",function(b,c,e){var f=typeof b.data==="string";if(b.dataTypes[0]==="jsonp"||c.jsonpCallback||c.jsonp!=null||b.jsonp!==!1&&(bU.test(b.url)||f&&bU.test(b.data))){var g,h=b.jsonpCallback=d.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2",m=function(){a[h]=i,g&&d.isFunction(i)&&a[h](g[0])};b.jsonp!==!1&&(j=j.replace(bU,l),b.url===j&&(f&&(k=k.replace(bU,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},e.then(m,m),b.converters["script json"]=function(){g||d.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),d.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){d.globalEval(a);return a}}}),d.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),d.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var bV=d.now(),bW,bX;d.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&bZ()||b$()}:bZ,bX=d.ajaxSettings.xhr(),d.support.ajax=!!bX,d.support.cors=bX&&"withCredentials"in bX,bX=b,d.support.ajax&&d.ajaxTransport(function(a){if(!a.crossDomain||d.support.cors){var c;return{send:function(e,f){var g=a.xhr(),h,i;a.username?g.open(a.type,a.url,a.async,a.username,a.password):g.open(a.type,a.url,a.async);if(a.xhrFields)for(i in a.xhrFields)g[i]=a.xhrFields[i];a.mimeType&&g.overrideMimeType&&g.overrideMimeType(a.mimeType),!a.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(i in e)g.setRequestHeader(i,e[i])}catch(j){}g.send(a.hasContent&&a.data||null),c=function(e,i){var j,k,l,m,n;try{if(c&&(i||g.readyState===4)){c=b,h&&(g.onreadystatechange=d.noop,delete bW[h]);if(i)g.readyState!==4&&g.abort();else{j=g.status,l=g.getAllResponseHeaders(),m={},n=g.responseXML,n&&n.documentElement&&(m.xml=n),m.text=g.responseText;try{k=g.statusText}catch(o){k=""}j||!a.isLocal||a.crossDomain?j===1223&&(j=204):j=m.text?200:404}}}catch(p){i||f(-1,p)}m&&f(j,k,m,l)},a.async&&g.readyState!==4?(bW||(bW={},bY()),h=bV++,g.onreadystatechange=bW[h]=c):c()},abort:function(){c&&c(0,1)}}}});var b_={},ca=/^(?:toggle|show|hide)$/,cb=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,cc,cd=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]];d.fn.extend({show:function(a,b,c){var e,f;if(a||a===0)return this.animate(ce("show",3),a,b,c);for(var g=0,h=this.length;g=0;a--)c[a].elem===this&&(b&&c[a](!0),c.splice(a,1))}),b||this.dequeue();return this}}),d.each({slideDown:ce("show",1),slideUp:ce("hide",1),slideToggle:ce("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){d.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),d.extend({speed:function(a,b,c){var e=a&&typeof a==="object"?d.extend({},a):{complete:c||!c&&b||d.isFunction(a)&&a,duration:a,easing:c&&b||b&&!d.isFunction(b)&&b};e.duration=d.fx.off?0:typeof e.duration==="number"?e.duration:e.duration in d.fx.speeds?d.fx.speeds[e.duration]:d.fx.speeds._default,e.old=e.complete,e.complete=function(){e.queue!==!1&&d(this).dequeue(),d.isFunction(e.old)&&e.old.call(this)};return e},easing:{linear:function(a,b,c,d){return c+d*a},swing:function(a,b,c,d){return(-Math.cos(a*Math.PI)/2+.5)*d+c}},timers:[],fx:function(a,b,c){this.options=b,this.elem=a,this.prop=c,b.orig||(b.orig={})}}),d.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this),(d.fx.step[this.prop]||d.fx.step._default)(this)},cur:function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];var a,b=d.css(this.elem,this.prop);return isNaN(a=parseFloat(b))?!b||b==="auto"?0:b:a},custom:function(a,b,c){function g(a){return e.step(a)}var e=this,f=d.fx;this.startTime=d.now(),this.start=a,this.end=b,this.unit=c||this.unit||(d.cssNumber[this.prop]?"":"px"),this.now=this.start,this.pos=this.state=0,g.elem=this.elem,g()&&d.timers.push(g)&&!cc&&(cc=setInterval(f.tick,f.interval))},show:function(){this.options.orig[this.prop]=d.style(this.elem,this.prop),this.options.show=!0,this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur()),d(this.elem).show()},hide:function(){this.options.orig[this.prop]=d.style(this.elem,this.prop),this.options.hide=!0,this.custom(this.cur(),0)},step:function(a){var b=d.now(),c=!0;if(a||b>=this.options.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),this.options.curAnim[this.prop]=!0;for(var e in this.options.curAnim)this.options.curAnim[e]!==!0&&(c=!1);if(c){if(this.options.overflow!=null&&!d.support.shrinkWrapBlocks){var f=this.elem,g=this.options;d.each(["","X","Y"],function(a,b){f.style["overflow"+b]=g.overflow[a]})}this.options.hide&&d(this.elem).hide();if(this.options.hide||this.options.show)for(var h in this.options.curAnim)d.style(this.elem,h,this.options.orig[h]);this.options.complete.call(this.elem)}return!1}var i=b-this.startTime;this.state=i/this.options.duration;var j=this.options.specialEasing&&this.options.specialEasing[this.prop],k=this.options.easing||(d.easing.swing?"swing":"linear");this.pos=d.easing[j||k](this.state,i,0,1,this.options.duration),this.now=this.start+(this.end-this.start)*this.pos,this.update();return!0}},d.extend(d.fx,{tick:function(){var a=d.timers;for(var b=0;b
";d.extend(b.style,{position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",height:"1px",visibility:"hidden"}),b.innerHTML=j,a.insertBefore(b,a.firstChild),e=b.firstChild,f=e.firstChild,h=e.nextSibling.firstChild.firstChild,this.doesNotAddBorder=f.offsetTop!==5,this.doesAddBorderForTableAndCells=h.offsetTop===5,f.style.position="fixed",f.style.top="20px",this.supportsFixedPosition=f.offsetTop===20||f.offsetTop===15,f.style.position=f.style.top="",e.style.overflow="hidden",e.style.position="relative",this.subtractsBorderForOverflowNotVisible=f.offsetTop===-5,this.doesNotIncludeMarginInBodyOffset=a.offsetTop!==i,a.removeChild(b),d.offset.initialize=d.noop},bodyOffset:function(a){var b=a.offsetTop,c=a.offsetLeft;d.offset.initialize(),d.offset.doesNotIncludeMarginInBodyOffset&&(b+=parseFloat(d.css(a,"marginTop"))||0,c+=parseFloat(d.css(a,"marginLeft"))||0);return{top:b,left:c}},setOffset:function(a,b,c){var e=d.css(a,"position");e==="static"&&(a.style.position="relative");var f=d(a),g=f.offset(),h=d.css(a,"top"),i=d.css(a,"left"),j=(e==="absolute"||e==="fixed")&&d.inArray("auto",[h,i])>-1,k={},l={},m,n;j&&(l=f.position()),m=j?l.top:parseInt(h,10)||0,n=j?l.left:parseInt(i,10)||0,d.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):f.css(k)}},d.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),e=ch.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(d.css(a,"marginTop"))||0,c.left-=parseFloat(d.css(a,"marginLeft"))||0,e.top+=parseFloat(d.css(b[0],"borderTopWidth"))||0,e.left+=parseFloat(d.css(b[0],"borderLeftWidth"))||0;return{top:c.top-e.top,left:c.left-e.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&(!ch.test(a.nodeName)&&d.css(a,"position")==="static"))a=a.offsetParent;return a})}}),d.each(["Left","Top"],function(a,c){var e="scroll"+c;d.fn[e]=function(c){var f=this[0],g;if(!f)return null;if(c!==b)return this.each(function(){g=ci(this),g?g.scrollTo(a?d(g).scrollLeft():c,a?c:d(g).scrollTop()):this[e]=c});g=ci(f);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:d.support.boxModel&&g.document.documentElement[e]||g.document.body[e]:f[e]}}),d.each(["Height","Width"],function(a,c){var e=c.toLowerCase();d.fn["inner"+c]=function(){return this[0]?parseFloat(d.css(this[0],e,"padding")):null},d.fn["outer"+c]=function(a){return this[0]?parseFloat(d.css(this[0],e,a?"margin":"border")):null},d.fn[e]=function(a){var f=this[0];if(!f)return a==null?null:this;if(d.isFunction(a))return this.each(function(b){var c=d(this);c[e](a.call(this,b,c[e]()))});if(d.isWindow(f)){var g=f.document.documentElement["client"+c];return f.document.compatMode==="CSS1Compat"&&g||f.document.body["client"+c]||g}if(f.nodeType===9)return Math.max(f.documentElement["client"+c],f.body["scroll"+c],f.documentElement["scroll"+c],f.body["offset"+c],f.documentElement["offset"+c]);if(a===b){var h=d.css(f,e),i=parseFloat(h);return d.isNaN(i)?h:i}return this.css(e,typeof a==="string"?a:a+"px")}}),a.jQuery=a.$=d})(window); \ No newline at end of file diff --git a/frontend/static/js/src/jquery.md5.js b/frontend/static/js/src/jquery.md5.js new file mode 100755 index 0000000..bf9bbe9 --- /dev/null +++ b/frontend/static/js/src/jquery.md5.js @@ -0,0 +1,269 @@ +/* + * jQuery MD5 Plugin 1.2.1 + * https://github.com/blueimp/jQuery-MD5 + * + * Copyright 2010, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://creativecommons.org/licenses/MIT/ + * + * Based on + * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message + * Digest Algorithm, as defined in RFC 1321. + * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009 + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * Distributed under the BSD License + * See http://pajhome.org.uk/crypt/md5 for more info. + */ + +/*jslint bitwise: true */ +/*global unescape, jQuery */ + +(function ($) { + 'use strict'; + + /* + * Add integers, wrapping at 2^32. This uses 16-bit operations internally + * to work around bugs in some JS interpreters. + */ + function safe_add(x, y) { + var lsw = (x & 0xFFFF) + (y & 0xFFFF), + msw = (x >> 16) + (y >> 16) + (lsw >> 16); + return (msw << 16) | (lsw & 0xFFFF); + } + + /* + * Bitwise rotate a 32-bit number to the left. + */ + function bit_rol(num, cnt) { + return (num << cnt) | (num >>> (32 - cnt)); + } + + /* + * These functions implement the four basic operations the algorithm uses. + */ + function md5_cmn(q, a, b, x, s, t) { + return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b); + } + function md5_ff(a, b, c, d, x, s, t) { + return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); + } + function md5_gg(a, b, c, d, x, s, t) { + return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); + } + function md5_hh(a, b, c, d, x, s, t) { + return md5_cmn(b ^ c ^ d, a, b, x, s, t); + } + function md5_ii(a, b, c, d, x, s, t) { + return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); + } + + /* + * Calculate the MD5 of an array of little-endian words, and a bit length. + */ + function binl_md5(x, len) { + /* append padding */ + x[len >> 5] |= 0x80 << ((len) % 32); + x[(((len + 64) >>> 9) << 4) + 14] = len; + + var i, olda, oldb, oldc, oldd, + a = 1732584193, + b = -271733879, + c = -1732584194, + d = 271733878; + + for (i = 0; i < x.length; i += 16) { + olda = a; + oldb = b; + oldc = c; + oldd = d; + + a = md5_ff(a, b, c, d, x[i], 7, -680876936); + d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586); + c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819); + b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330); + a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897); + d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426); + c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341); + b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983); + a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416); + d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417); + c = md5_ff(c, d, a, b, x[i + 10], 17, -42063); + b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162); + a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682); + d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101); + c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290); + b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329); + + a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510); + d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632); + c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713); + b = md5_gg(b, c, d, a, x[i], 20, -373897302); + a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691); + d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083); + c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335); + b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848); + a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438); + d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690); + c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961); + b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501); + a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467); + d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784); + c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473); + b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734); + + a = md5_hh(a, b, c, d, x[i + 5], 4, -378558); + d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463); + c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562); + b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556); + a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060); + d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353); + c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632); + b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640); + a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174); + d = md5_hh(d, a, b, c, x[i], 11, -358537222); + c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979); + b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189); + a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487); + d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835); + c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520); + b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651); + + a = md5_ii(a, b, c, d, x[i], 6, -198630844); + d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415); + c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905); + b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055); + a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571); + d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606); + c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523); + b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799); + a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359); + d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744); + c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380); + b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649); + a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070); + d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379); + c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259); + b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551); + + a = safe_add(a, olda); + b = safe_add(b, oldb); + c = safe_add(c, oldc); + d = safe_add(d, oldd); + } + return [a, b, c, d]; + } + + /* + * Convert an array of little-endian words to a string + */ + function binl2rstr(input) { + var i, + output = ''; + for (i = 0; i < input.length * 32; i += 8) { + output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xFF); + } + return output; + } + + /* + * Convert a raw string to an array of little-endian words + * Characters >255 have their high-byte silently ignored. + */ + function rstr2binl(input) { + var i, + output = []; + output[(input.length >> 2) - 1] = undefined; + for (i = 0; i < output.length; i += 1) { + output[i] = 0; + } + for (i = 0; i < input.length * 8; i += 8) { + output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (i % 32); + } + return output; + } + + /* + * Calculate the MD5 of a raw string + */ + function rstr_md5(s) { + return binl2rstr(binl_md5(rstr2binl(s), s.length * 8)); + } + + /* + * Calculate the HMAC-MD5, of a key and some data (raw strings) + */ + function rstr_hmac_md5(key, data) { + var i, + bkey = rstr2binl(key), + ipad = [], + opad = [], + hash; + ipad[15] = opad[15] = undefined; + if (bkey.length > 16) { + bkey = binl_md5(bkey, key.length * 8); + } + for (i = 0; i < 16; i += 1) { + ipad[i] = bkey[i] ^ 0x36363636; + opad[i] = bkey[i] ^ 0x5C5C5C5C; + } + hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8); + return binl2rstr(binl_md5(opad.concat(hash), 512 + 128)); + } + + /* + * Convert a raw string to a hex string + */ + function rstr2hex(input) { + var hex_tab = '0123456789abcdef', + output = '', + x, + i; + for (i = 0; i < input.length; i += 1) { + x = input.charCodeAt(i); + output += hex_tab.charAt((x >>> 4) & 0x0F) + + hex_tab.charAt(x & 0x0F); + } + return output; + } + + /* + * Encode a string as utf-8 + */ + function str2rstr_utf8(input) { + return unescape(encodeURIComponent(input)); + } + + /* + * Take string arguments and return either raw or hex encoded strings + */ + function raw_md5(s) { + return rstr_md5(str2rstr_utf8(s)); + } + function hex_md5(s) { + return rstr2hex(raw_md5(s)); + } + function raw_hmac_md5(k, d) { + return rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)); + } + function hex_hmac_md5(k, d) { + return rstr2hex(raw_hmac_md5(k, d)); + } + + $.md5 = function (string, key, raw) { + if (!key) { + if (!raw) { + return hex_md5(string); + } else { + return raw_md5(string); + } + } + if (!raw) { + return hex_hmac_md5(key, string); + } else { + return raw_hmac_md5(key, string); + } + }; + +}(typeof jQuery === 'function' ? jQuery : this)); \ No newline at end of file diff --git a/frontend/static/js/src/like.js b/frontend/static/js/src/like.js new file mode 100644 index 0000000..8ae975f --- /dev/null +++ b/frontend/static/js/src/like.js @@ -0,0 +1,97 @@ +var Like = + { + timeout: false, + likeContentDelay: 1000, + likeMessageDelay: 10000, + favewords: + [ + 'dazzled', 'dangled', 'amazed', 'shocked', 'wowed', + 'spangled', 'glittered', 'blinged', 'jazzed', 'smoked', + 'rocked', 'jammed', 'stoked', 'blazed', 'pringled', 'engulfed', + ], + colors: + [ + "#ffa1b8","#ffb9a1","#ffe8a1","#ffa1e7","#a1a4ff","#cda1ff","#fca1ff","#a1d3ff","#e8a1ff","#a1f6ff","#a1ffaa","#c7ffa1" + ], + enqueue: function (username) + { + var domain = window.location.hostname.split('.').slice(-2).join('.') + d.joy("liked by "+username) + $("#likereport").append( + $("").attr("href","http://"+username+"."+domain+"/").html(username+" was "+d.choice(Like.favewords)+"!").attr("style","color:"+d.choice(Like.colors))) + if (Viewport.focused) + Like.fire() + else + Like.pending = true + }, + fire: function () + { + d.joy("LIKE ANIMATION GO") + Like.pending = false + $("#likereport").stop(false,false).show() + d.scrollToBottom("#likereport") + $("#plant").stop(true, true).show() + $("#flower").stop(true, true).show() + if (Like.timeout) + clearTimeout(Like.timeout) + Like.timeout = setTimeout(Like.queueFade, 1000) + }, + queueFade: function timeout() + { + d.joy("LIKE ANIMATION FADE") + Like.timeout = false + $("#plant").fadeOut(Like.likeContentDelay) + $("#flower").fadeOut(Like.likeContentDelay) + $("#likereport").fadeOut(Like.likeMessageDelay, function(){$("#likereport").html("")}) + }, + likeContent: function (video) + { + if (! Auth.session) + return d.error("like: not logged in") + if (video.username === Auth.username) + return d.error("like: that's you") + var data = { video: video.id, session: Auth.session, } + if (Local.isLiked(video.id)) + { + d.joy("unliking "+video.key) + if (Player.currentKey === video.key) + $("#like").removeClass("liked") + $("#like_"+video.id).removeClass("liked").html("  like") + video.liked = false + Local.unlike(video.id) + if (video.score) + { + video.score -= 1 + if (video.score < 0) + { + video.score = 0 + $("#score_"+video.id).html(' ') + } + else + { + $("#score_"+video.id).html(video.score) + } + } + $.post(API.URL.video.unlike, data) + } + else + { + d.joy("liking "+video.key) + if (Player.currentKey === video.key) + $("#like").addClass("liked") + $("#like_"+video.id).addClass("liked").html("liked") + $("#flower").show().fadeOut(Like.likeContentDelay) + video.liked = true + Local.like(video.id) + if (video.score) + { + video.score += 1 + $("#score_"+video.id).html(video.score) + } + $.post(API.URL.video.like, data) + } + }, + init: function () + { + } + } diff --git a/frontend/static/js/src/main.js b/frontend/static/js/src/main.js new file mode 100644 index 0000000..993c494 --- /dev/null +++ b/frontend/static/js/src/main.js @@ -0,0 +1,694 @@ +var Keyboard = + { + enter: false, + enteredText: false, + altMode: false, + focusTextarea: function () + { + // $("#chat").append("TEXTAREA FOCUS") + $(window).unbind("keydown") + $("#chat-message").unbind("keydown").bind("keydown", Keyboard.textareaMap) + $("#chat-message").unbind("focus").focus().bind("focus", Keyboard.focusTextarea) + Search.close () + if ($("#chat-message").val().length === 0) + Keyboard.enteredText = false + }, + blurTextarea: function () + { + // $("#chat").append("TEXTAREA BLUR") + $(window).unbind("keydown") + if (Viewport.fullscreenMode && Viewport.fullscreenInterface) + $(window).bind("keydown", Keyboard.fullscreenInterfaceMap) + else if (Viewport.fullscreenMode) + $(window).bind("keydown", Keyboard.fullscreenMap) + else + $(window).bind("keydown", Keyboard.standardMap) + $("#chat-message").unbind("keydown") + }, + textareaMap: function (event) + { + var kc = event.keyCode + if (kc === 8) + { + var v = $("#chat-message").val() + if (v.length < 2) + Keyboard.enteredText = false + return true + } + if (kc === 13) + { + Keyboard.enteredText = false + if (Keyboard.enter) + Keyboard.enter() + if (Chat.callback) + { + Chat.callback(1) + } + return false + } + if (kc === 27) + { + Menu.close() + if (Viewport.fullscreenMode && Viewport.fullscreenInterface) + Viewport.fullscreenHideInterface() + else if (Viewport.fullscreenMode) + Viewport.fullscreenOff() + else + Viewport.fullscreenOn() + return false + } + if (! Keyboard.enteredText) + { + if (kc === 37) + { + Player.playPrev() + return + } + else if (kc === 39) + { + Player.playNext() + return + } + } + if (kc === 33) + return d.pageUp("#chat") + if (kc === 34) + return d.pageDown("#chat") + Keyboard.enteredText = true + return true + }, + standardMap: function (event) + { + kc = event.keyCode + if (kc === 91) + { + Keyboard.altMode = true + return true + } + else if (kc === 27) // && Room.loaded) + { + Menu.close() + Viewport.fullscreenOn() + return false + } + else if (! Menu.isOpen) + { + if (kc === 37 || kc === 177) + Player.playPrev() + else if (kc === 39 || kc === 176) + Player.playNext() + else if (kc === 32 || kc === 179) + Player.pause() + else if (! Keyboard.altMode && kc === 76) + Player.likeClick() + } + Keyboard.altMode = false + return true + }, + fullscreenInterfaceMap: function (event) + { + kc = event.keyCode + if (kc === 27) + Viewport.fullscreenHideInterface() + if (kc === 33) + d.pageUp("#chat") + if (kc === 34) + d.pageDown("#chat") + if (kc === 32 || kc === 179) + Player.pause() + if (kc === 37 || kc === 177) + Player.playPrev() + else if (kc === 39 || kc === 176) + Player.playNext() + if (! Keyboardndow).bind("resize", Viewport.standardResize) + $("#chat").bind("mouseover", Viewport.chatMouseOver) + $("#chat").bind("mouseout", Viewport.chatMouseLaave) + $("#bg,#logo,#logobg,#form,#formbg,#chat,#chatbg,#playlist,#playlistbg,#lastlogbox,#lastlogbg,#sitez,#controls").show() + $("#controls").css("position", "absolute") + $("#controls").css("min-width", "auto").css('top','auto').css('bottom', 'auto').css('left','auto').css('right','auto') + $("#fullscreen").unbind("click") + $("#fullscreen").bind("click", Main.fullscreenOn) + $("#video-title").removeClass("fullscreen") + $("#chat,#playlist").removeClass("fullscreen") + $("#controls").css("padding", 0) + Viewport.standardResize() + setTimeout('d.scrollToBottom("#chat")', 500) + Keyboard.focusTextarea() + Viewport.fullscreenMode = false + clearInterval(Viewport.fule") + $(window).bind("resize", Viewport.standardResize) + $("#chat").bind("mouseover", Viewport.chatMouseOver) + $("#chat").bind("mouseout", Viewport.chatMouseLaave) + $("#bg,#logo,#logobg,#form,#formbg,#chat,#chatbg,#playlist,#playlistbg,#lastlogbox,#lastlogbg,#sitez,#controls").show() + $("#controls").css("position", "absolute") + $("#controls").css("min-width", "auto").css('top','auto').css('bottom', 'auto').css('left','auto').css('right','auto') + $("#fullscreen").unbind("click") + $("#fullscreen").bind("click", Main.fullscreenOn) + $("#video-title").removeClass("fullscreen") + $("#chat,#playlist").removeClass("fullscreen") + $("#controls").css("padding", 0) + Viewport.standardResize() + setTimeout('d.scrollToBottom("#chat")', 500) + Keyboard.focusTextarea() + Viewport.fullscreenMode = false + clearInterval(Viewport.ful.altMode && kc === 76) + Player.likeClick() + return false + }, + fullscreenMap: function (event) + { + kc = event.keyCode + if (kc === 27) + Viewport.fullscreenOff() + if (kc === 37 || kc === 177) + Player.playPrev() + if (kc === 39 || kc === 176) + Player.playNext() + if (kc === 32 || kc === 179) + Player.pause() + if (kc === 76) + Player.likeClick() + return false + } + } +var Viewport = + { + focused: true, + fullscreenMode: false, + fullscreenInterface: false, + fullscreenFocusTimer: false, + fullscreenOn: function () + { + var msg = $("#chat-message").val() + $(window).unbind("resize") + $(window).bind("resize", Viewport.fullscreenResize) + $("#chat").unbind("mouseover").unbind("mouseout") + $("#chat-message").focus() + Keyboard.focusTextarea() + $("#chat,#playlist").addClass("fullscreen") + $("#bg,#chatbg,#playlistbg,#playlist").hide() + $("#faqlink").hide() + $("#logobg").css("width",$("#logo").width()+60) + $("#like").show() + $("#controls").css("position", "fixed") + Menu.close () + Search.close () + $("#fullscreen").unbind("click") + $("#fullscreen").bind("click", Viewport.fullscreenOff) + $("#video-title").addClass("fullscreen") + Viewport.fullscreenInterface = true + Viewport.fullscreenMode = true + Viewport.fullscreenResize() + Viewport.chatMouseOut() + $("#chat-message").val(msg) + d.scrollToBottom("#chat") + }, + fullscreenOff: function () + { + $("#logobg").css("width","100%") + $(window).unbind("keydown") + // $(window).bind("keydown", Keyboard.standardMap) + $(window).unbind("resize") + $(window).bind("resize", Viewport.standardResize) + $("#chat").bind("mouseover", Viewport.chatMouseOver) + $("#chat").bind("mouseout", Viewport.chatMouseLaave) + $("#bg,#logo,#logobg,#form,#formbg,#chat,#chatbg,#playlist,#playlistbg,#lastlogbox,#lastlogbg,#sitez,#controls").show() + $("#controls").css("position", "absolute") + $("#controls").css("min-width", "auto").css('top','auto').css('bottom', 'auto').css('left','auto').css('right','auto') + $("#fullscreen").unbind("click") + $("#fullscreen").bind("click", Main.fullscreenOn) + $("#video-title").removeClass("fullscreen") + $("#chat,#playlist").removeClass("fullscreen") + $("#controls").css("padding", 0) + Viewport.standardResize() + setTimeout('d.scrollToBottom("#chat")', 500) + Keyboard.focusTextarea() + Viewport.fullscreenMode = false + clearInterval(Viewport.fullscreenFocusTimer) + Viewport.fullscreenFocusTimer = false + }, + fullscreenHideInterface: function () + { + Viewport.fullscreenInterface = false + Keyboard.blurTextarea() + $("#form,#formbg,#chat,#playlist,#lastlogbox,#lastlogbg,#sitez,#controls,#logo,#logobg").hide() + }, + fullscreenResize: function () + { + var w = $(window).width() + var h = $(window).height() + var fw = 4 * w / 7 - 40 + var ph = h / 3 - 30 + var ch = 2 * h / 3 + var fh = 50 + var clh = ch - fh - 50 + + var pw = w * 2 / 3 - 20 + + var chatwidth = (4*w)/5 - 20 + + var chatheight = h-fh-5 + var fbot = 20 + var chatbot = Viewport.chatBottom + + if (VideoChat.isOpen) + { + var vch = 150 + $("#tokbox-embed").css("width", fw-20) + chatheight -= vch + chatbot += vch + fbot += vch + } + + $("#player").css("top", -10).css("left", -10) + $("#screen,#ytscreen").css("width",w).css("height",h) + + $("#chat").css("left", 0).css("bottom", chatbot).css("width", chatwidth).css("height", chatheight) + d.scrollToBottom("#chat") + + var sendw = $("#chat-send").width() + var camw = $("#videochat-toggle").width() + $("#chat-message").css("width", fw-sendw-camw-50) + $("#form,#formbg").css("left", 0) + $("#form").css("bottom", fbot) + $("#form,#formbg").css("width", fw) + + var controlsw = $("#controls").width() + var controlsoffset = ( w - fw - controlsw ) / 2 + $("#controls").css({ "top": "auto", "bottom": fbot+2, "right": controlsoffset, "background": "black", "padding": 10, }) + + $("#lastlogbox,#lastlogbg").css("top", h/3).css("left", w*(7/8)-10) + $("#lastlogbg").css("height", $("#lastlogbox").height()) + }, + playerTop: 94, + chatWidth: 500, + chatBottom: 75, + formHeight: 50, + standardResize: function () + { + var w = $(window).width() + var h = $(window).height() + var ytw = 1 * w / 2 - 90 + if (ytw > 500) + ytw = 500 + var yth = ytw * 9/ 16 + + var fh = Viewport.formHeight + + var cw = w - ytw - 80 + var ch = 2 * h / 3 + var chatheight = h-fh-5 + Viewport.chatWidth = cw + + var pw = cw - 20 + var ph = h / 3 - 30 + + var fbot = 20 + var chatbot = Viewport.chatBottom + + var clw = cw*3/4 + var clh = ch - fh - 50 + + var llw = cw / 4 - 30 + var llh = ch - fh - 30 + + var sendw = $("#chat-send").width() + var camw = $("#videochat-toggle").width() + $("#chat-message").css("width", pw-sendw-camw-30) + + if (VideoChat.isOpen) + { + var vch = chatheight * 1 / 2 + if (vch < 280) + vch = 280 + $("#tokbox-embed").css({"width": cw+20, "height": vch}) + $("#tokbox-embedded").css({"height": vch}) + chatheight -= vch + chatbot += vch + fbot += vch + } + + var msgw = 0 + var buttonheight = $("#fullscreen").height() + + $("#bg img").css("width", w) + $("#bg img").css("height", h) + + $("#logo").css("left", 20) + + if (retrograde) + { + // PLAYER ON LEFT + $("#player").css("left", 20) + $("#player").css("top", Viewport.playerTop) + $("#player").css("height", yth+buttonheight+20) + $("#player,#projector,#screen,#ytscreen").width(ytw) + $("#projector,#screen,#ytscreen").height(yth) + Player.width = ytw + Player.height = yth + + $("#controls").css("top", yth+10+10) + var playerHeight = yth+buttonheight+Viewport.playerTop + 10 + + $("#playlist,#playlistbg").css("left", 20) + $("#playlist,#playlistbg").css("top", playerHeight+30) + $("#playlist,#playlistbg").css("width", ytw+19) + $("#playlist,#playlistbg,#queue").css("height", h-playerHeight-50) + + $("#chat,#chatbg").css("left", 60+ytw) + $("#chat,#chatbg").css("bottom", chatbot) + $("#chat,#chatbg").css("width", cw) + $("#chat,#chatbg").css("height", chatheight) + // $("#chat").css("overflow-y", "scroll") + // $("#chat").css("overflow-x", "hidden") + + $("#form,#formbg").css("left", 60+ytw) + $("#form,#formbg").css("bottom", fbot) + $("#form,#formbg").css("width", cw) + $("#form,#formbg").css("height", fh-15) + $("#formbg").css("opacity", 0.7) + + $("#lastlogbox,#lastlogbg").css("top", 90) + $("#lastlogbox,#lastlogbg").css("left", ytw+60+clw) + $("#lastlogbox,#lastlogbg").css("width", llw) + $("#lastlogbox").css("max-height", (h-fh-70-40)*3/4) + $("#lastlogbox").css("overflow-y", "auto") + $("#lastlogbox").css("overflow-x", "hidden") + + $("#likereport").css("bottom", 90) + $("#likereport").css("left", ytw+60+clw) + $("#likereport").css("width", llw-20) + $("#likereport").css("height", (h-fh-70-40)*1/4) + + $("#msg").css("max-height", h-130) + } + + else + { + // PLAYER ON RIGHT + $("#player").css("left", 40+pw+20) + $("#player").css("top", Viewport.playerTop) + $("#player").css("height", yth+buttonheight+20) + $("#player,#projector,#screen,#ytscreen").width(ytw) + $("#projector,#screen,#ytscreen").height(yth) + + $("#controls").css("top", yth+10+10) + var playerHeight = yth+buttonheight+Viewport.playerTop+10 + + $("#playlist,#playlistbg").css("left", 40+pw+20) + $("#playlist,#playlistbg").css("top", playerHeight+30) + $("#playlist,#playlistbg").css("width", ytw+19) + $("#playlist,#playlistbg,#queue").css("height", h-playerHeight-50) + + $("#chat,#chatbg").css("left", 0) + $("#chat,#chatbg").css("bottom", chatbot) + $("#chat,#chatbg").css("width", cw) + $("#chat,#chatbg").css("height", chatheight) + // $("#chat").css("overflow-y", "scroll") + // $("#chat").css("overflow-x", "hidden") + + $("#plant").css("left", cw-300) + + $("#form,#formbg").css("left", 0) + $("#form").css("bottom", fbot) + $("#form,#formbg").css("width", cw) + $("#form,#formbg").css("height", fh-15) + $("#formbg").css("opacity", 0.7) + + $("#lastlogbox,#lastlogbg").css("top", 90) + $("#lastlogbox,#lastlogbg").css("left", 10+clw) + $("#lastlogbox,#lastlogbg").css("width", llw) + $("#lastlogbox").css("max-height", (h-fh-70-40)*3/4) + $("#lastlogbox").css("overflow-y", "auto") + $("#lastlogbox").css("overflow-x", "hidden") + + var lrwidth = llw-20 + if (lrwidth < 150) lrwidth = 150 + $("#likereport").css("bottom", 90) + $("#likereport").css("left", cw-lrwidth-90) + $("#likereport").css("width", lrwidth) + $("#likereport").css("max-height", (h-fh-70-40)*1/4) + + $("#msg").css("max-height", h-130) + } + $("#lastlogbg").css("height", $("#lastlogbox").height()) + d.scrollToBottom("#chat") + }, + scrollbarWidth: 16, + getScrollbarWidth: function () + { + var initial = document.body.style.overflow + document.body.style.overflow = 'hidden'; + var width = document.body.clientWidth; + document.body.style.overflow = 'scroll' + width -= document.body.clientWidth + if (! width) + width = document.body.offsetWidth - document.body.clientWidth + document.body.style.overflow = initial + return width + }, + focus: function () + { + d.warn("VIEWPORT FOCUS") + if (! Viewport.fullscreenMode || Viewport.fullscreenInterface) + Keyboard.focusTextarea() + document.body.tabIndex = 0 + document.body.focus() + Viewport.focused = true + // Chat.delay = 1000 + if (Like.pending) + Like.fire() + // Chat.delay = Chat.delayShort + }, + blur: function () + { + d.warn("VIEWPORT BLUR") + Viewport.focused = false + // Chat.delay = Chat.delayLong + }, + chatMouseOver: function () + { + $("#chat").css({"overflow-y": "scroll", "width": Viewport.chatWidth + Viewport.scrollbarWidth }) + $("#chat").scrollTop( $("#chat").scrollTop() ) + }, + chatMouseOut: function () + { + $("#chat").css({"overflow-y": "hidden", "width": Viewport.chatWidth}) + }, + init: function () + { + Viewport.scrollbarWidth = Viewport.getScrollbarWidth () + $("#chat").bind("mouseover", Viewport.chatMouseOver) + $("#chat").bind("mouseout", Viewport.chatMouseOut) + } + } +var Background = + { + src: "http://scannerjammer.com/static/bgz/jupiteraurora.jpg", + srcReset: "http://scannerjammer.com/static/bgz/1302474305250-dumpfm-GucciSoFlosy-pattern4.gif", + load: function () + { + $("#bg").show() + //setTimeout(function(){$("#bg img").attr("src", Background.src)}, 2000) + }, + init: function () + { + } + } +var Include = + { + glitter: function () + { + Room.ops = {} + $("body").append("") + $("body").append("") + d.enableStylesheet("glitter") + }, + avatar: function () + { + Room.ops = {} + $("body").append("") + $("body").append("") + d.enableStylesheet("avatar") + }, + jonomilo: function () + { + Room.ops = d.buildLookup(["daytimetelevision"]) + d.enableStylesheet("white") + $("#heading").remove() + $("#topic").remove() + $("#likebutton").before("

") + Include.middleColumn () + }, + middleColumn: function () + { + Chat.previousName = false + Chat.containsImage = function (s) + { + if (s.indexOf("http") === -1) + return false + var suffixes = ["jpg","jpeg","gif","png"] + for (var i = 0; i < suffixes.length; i++) + { + if (s.indexOf(suffixes[i]) !== -1) + { + // console.log(suffixes[i] + " " + s) + return true + } + } + return false + } + Chat.parse = function (row) + { + if (Chat.containsImage(row[3])) + { + var s = "
" + s += "" + s += Chat.parseWords(row[3]) + s += "" + s += "
" + return s + } + else + { + Chat.previousName = row[2] + var s = "
" + return s + } + } + }, + diornights: function () + { + $("#logo").append("

OPEN RADIO

") + }, + disaro: function () + { + $("#logo").append("

OPEN RADIO

") + }, + sewergreats: function () + { + $("#logo").append("

OPEN RADIO

") + }, + dump: function () + { + Room.ops = d.buildLookup([""]) + $("body").append("") + }, + yhvh: function () + { + Room.ops = d.buildLookup(["greta"]) + }, +/* + icons: function () + { + $("#bg").html(''); + }, +*/ + feederbleeder: function () + { + Room.ops = {} + $("#preamblewords").remove() + $("#topic").remove() + $("#heading").after("

") + d.enableStylesheet("feederbleeder") + var oldsay = Chat.say + Chat.say = function () + { + var msg = $("#chat-message").val() + if (msg.indexOf("http") !== -1) + { + $("#chat").append("
Sorry, only the Feederbleeder robot can post videos and images in this room. Please visit another room to post videos.
") + $("#chat-message").val("") + d.scrollToBottom("#chat") + } + else + { + oldsay () + } + } + }, + fred: function () + { + Room.ops = d.buildLookup(["scannerjammer"]) + }, + frederick: function () + { + Room.ops = d.buildLookup(["scannerjammer"]) + d.enableStylesheet("frederick") + }, + glasspopcorn: function () + { + Room.ops = d.buildLookup(["glasspopcorn"]) + setTimeout(VideoChat.toggle, 2000) + $("#plant img").attr("src", "/static/img/1309267681552dumpfmfrakbuddyglasscross_1310066105.gif") + $("#flower img").attr("src", "/static/img/1278131405573-dumpfm-glasspopcorn-sitmanpiano.gif") + $("#heading").remove() + $("#logo").append("

OPEN RADIO

") + $("body").append("") + $("#preamblewords").html("Post GIFs and Soundclouds into the chat!
Use arrow keys to switch videos
Hit L key to LIKE
Hit ESC to change modes") + Player.unregister("youtube") + Player.unregister("vimeo") + Player.unregister("audio") + }, + sfvacid: function () + { + // $("#logo").append("

OPEN RADIO

") + }, + main: function () + { + Room.ops = false + $("#heading").remove() + $("#preamblewords").after("

 

") + $("#topic").remove() + // Room.loadCallback = function () + // { + // setTimeout(Viewport.fullscreenOn, 3000) + // } + // $("#likebutton").before("

Post urls into the chat!
Use arrow keys to switch videos

") + } + } + +var Main = + { + init: function () + { + d.warn("INIT MAIN") + + if (roomName in Include) + { + Include[roomName]() + } + + $(window).bind("focus", Viewport.focus) + $(window).bind("blur", Viewport.blur) + $(window).bind("resize", Viewport.standardResize) + $(window).bind("keydown", Keyboard.standardMap) + Viewport.standardResize() + Viewport.init() + Background.init() + $("#chat").append("
") + Room.init() + if ( Auth.init() ) + Room.connect() + else + Auth.load() + //document.write('') + if (window.location.pathname.split("/")[2] == "read") + { + API.URL.room.join = API.BASE_URL + "/api/room/view" + // API.URL.room.poll = API.BASE_URL + "/api/room/read" + d.enableStylesheet("tiny") + Viewport.playerTop = 20 + Viewport.chatBottom = 20 + Viewport.formHeight = 5 + Player.mute() + } + } + } +Main.init () diff --git a/frontend/static/js/src/player.js b/frontend/static/js/src/player.js new file mode 100644 index 0000000..28c62e6 --- /dev/null +++ b/frontend/static/js/src/player.js @@ -0,0 +1,551 @@ +var VIMEOregexp = /^(\bhttps?:\/\/)(www.)?vimeo.com\/([0-9]+).*$/i +var PLAY_BUTTONS = + { + prev: "
", + next: "
", + pause: "
", + play: "
", + } +var Player = + { + videos: {}, + queue: [], + projectors: {}, + projector: null, + newVideos: false, + currentIdx: 0, + video: false, + errors: 0, + width: '100%', + height: '100%', + playlistOffset: 30, + queueOffset: 60, + paused: false, + muted: false, + enqueue: function (video) + { + if (! (video.type in Player.projectors)) + return d.error("unknown video type "+video.type) + var key = video.type+"_"+video.name + if (key in Player.videos) + { + Player.videos[key].idx = Player.queue.length + Player.videos[key].seen = false + if (video.offset) + Player.videos[key].offset = video.offset + d.warn("bumped "+key) + } + else + { + video.key = key + video.idx = Player.queue.length + Player.videos[key] = video + Player.newVideos = true + d.warn("enqueued "+key) + } + $("#"+video.key).html(video.title) + Player.queue.push(key) + return true + }, + clearQueue: function () + { + Player.queue = [] + Player.currentIdx = 0 + Playlist.count = 0 + }, + register: function (projector) + { + d.warn("registered "+projector.type) + Player.projectors[projector.type] = projector + }, + unregister: function (projectortype) + { + d.warn("unregistered "+projectortype) + delete Player.projectors[projectortype] + }, + start: function () + { + d.warn("PLAYER START") + Player.currentIdx = Player.queue.length - 1 + if (! Player.queue.length) + return d.error("empty queue") + Player.playLatest() + }, + finish: function () + { + d.warn("PLAYER FINISH") + d.warn("____________") + Player.playLatest() + }, + error: function (s) + { + if (s) + d.error(Player.errors+" "+s) + else + d.error("PLAYER ERROR "+Player.errors) + $("li#queue_"+Player.video.idx+" span.title").html("This video cannot be embedded") + Player.video.error = true + }, + playLatest: function () + { + d.warn("PLAY LATEST") + var idx = Player.currentIdx + var len = Player.queue.length + if (Player.newVideos) + { + for (i = idx; i < len; i++) + { + var video = Player.videos[Player.queue[i]] + d.warn("check "+Player.queue[i]) + if (video.seen) + continue + Player.currentIdx = i + d.joy("new video! "+video.key+" at "+i) + Player.queueJumpToCurrentVideo(Player.currentIdx) + Player.playVideo(video) + return + } + for (i = idx - 1; i >= 0; i--) + { + var video = Player.videos[Player.queue[i]] + d.warn("check "+Player.queue[i]) + if (video.seen) + continue + Player.currentIdx = i + d.joy("new video! "+video.key+" at "+i) + Player.queueJumpToCurrentVideo(Player.currentIdx) + Player.playVideo(video) + return + } + Player.newVideos = false + d.warn("no new videos") + } + Player.playNext() + }, + playNext: function () + { + d.warn("____________") + d.warn("PLAY NEXT") + var idx = Player.currentIdx + do + { + idx -= 1 + if (Player.queue[idx] === Player.video.key) + idx -= 1 + if (idx < 0) + idx = Player.queue.length - 1 + } + while (Player.videos[ Player.queue[idx] ].error === true) + Player.queueJumpToCurrentVideo(idx) + Player.playIdx(idx) + }, + playPrev: function () + { + d.warn("____________") + d.warn("PLAY PREV") + var idx = Player.currentIdx + do + { + idx = (idx + 1) % Player.queue.length + if (Player.queue[idx] === Player.video.key) + continue + } + while (Player.videos[ Player.queue[idx] ].error === true) + Player.queueJumpToCurrentVideo(idx) + Player.playIdx(idx) + }, + playKey: function (key) + { + Player.playVideo( Player.videos[key] ) + }, + playIdx: function (idx) + { + d.warn("play idx: "+idx) + Player.currentIdx = idx + Player.playVideo( Player.videos[Player.queue[idx]] ) + }, + throttle: function () + { + d.error("THROTTLED") + Player.stop() + Player.errors = 0 + }, + stop: function () + { + Player.projector.stop() + }, + playVideo: function (video) + { + if (! video) + { + d.error("GOT EMPTY VIDEO") + d.warn(Player.currentIdx) + d.warn(Player.queue[ Player.currentIdx ]) + d.warn(Player.videos[ Player.queue[ Player.currentIdx ] ]) + return + } + if (video.error === true) + { + Player.errors += 1 + d.error(video.key) + if (Player.errors > Player.queue.length) + return Player.throttle() + return Player.finish() + } + d.warn("PLAY VIDEO: "+video.key) + if (video.type !== Player.projector.type) + { + d.warn("SWITCHING PROJECTORS") + d.warn([Player.projector.type, video.type].join(" → ")) + Player.projector.unload() + Player.projector = Player.projectors[video.type] + Player.projector.load() + if (Player.muted) + Player.projector.setVolume(0) + } + video.seen = true + if (! Player.fullscreenMode) + { + $("#video-title").hide().html(video.title).fadeIn(100, function () { + setTimeout("$('#video-title').fadeOut(2000)", 4000) + }) + } + + Player.errors = 0 + Player.video = video + Player.projector.play(video) + Player.linkUpdate(video) + Player.currentIdx = video.idx + $("#queue li.playing").removeClass("playing") + $("#chat a.ytlink.playing").removeClass("playing") + $("#queue li").removeClass("playing") + $("li#queue_"+video.idx).addClass("playing") + $("#"+video.key).addClass("playing") + $("#"+video.key).html(video.title) + $("#like").removeClass("liked").html("LIKE") + $("#pause").html(PLAY_BUTTONS.pause) + if (Local.isLiked(video.id)) + { + $("#like").addClass("liked").html("LIKED") + } + }, + queueJumpToCurrentVideo: function (idx) + { + $("#playlist").scrollTop( $("li#queue_"+idx)[0].offsetTop - Player.playlistOffset ) + $("#queue").scrollTop( $("li#queue_"+idx)[0].offsetTop - Player.queueOffset ) + }, + toggle: function () + { + Player.projector.toggle() + }, + pause: function () + { + Player.projector.pause() + $("#pause").html(PLAY_BUTTONS.play) + }, + mute: function () + { + if (Player.projector) + { + if (Player.muted) + Player.projector.setVolume(100) + else + Player.projector.setVolume(0) + } + Player.muted = ! Player.muted + }, + muteClick: function () + { + if (Player.muted) + $("#mute").removeClass("muted") + else + $("#mute").addClass("muted") + Player.mute() + }, + prevClick: function () + { + d.act("+ clicked prev") + Player.playPrev() + }, + pauseClick: function () + { + d.act("+ clicked pause") + Player.errors = 0 + if (Player.projector.toggle()) + { + $("#pause").html(PLAY_BUTTONS.play) + d.warn("set to play") + } + else + { + $("#pause").html(PLAY_BUTTONS.pause) + d.warn("set to pause") + } + }, + nextClick: function () + { + d.act("+ clicked next") + Player.playNext() + }, + scanClick: function () + { + d.act("+ clicked scan") + Scanner.scan() + }, + likeClick: function () + { + d.act("+ clicked player like") + Like.likeContent(Player.video) + }, + linkClick: function () + { + d.act("+ clicked permalink") + Player.pause() + }, + linkUpdate: function (video) + { + d.warn("UPDATING LINK") + $("#video-link").attr("href", video.src) + var vidurl = "http://scannerjammer.com/" + if (Room.name !== "main") + vidurl += Room.name+"/" + vidurl += "#v="+video.id + $("#sharebutton").attr("st_url", vidurl).attr("st_title", video.title) +/* + stWidget.addEntry({ + service: "sharethis", + element: document.getElementById("sharebutton"), + url: vidurl, + title: video.title, + summary: "ScannerJammer: Youtube video chat", + }) +*/ + }, + + fullscreenClick: function () + { + d.act("+ clicked fullscreen") + }, + setVolume: function (vol) + { + if (Player.projector && Player.projector.type !== 'null') + { + // alert(Player.projector.type) + Player.projector.setVolume(vol) + } + }, + init: function () + { + d.warn("PLAYER INIT") + $("#prev").html(PLAY_BUTTONS.prev) + $("#pause").html(PLAY_BUTTONS.play) + $("#next").html(PLAY_BUTTONS.next) + $("#prev").bind("click", Player.prevClick) + $("#pause").bind("click", Player.pauseClick) + $("#next").bind("click", Player.nextClick) + $("#scan").bind("click", Player.scanClick) + $("#like").bind("click", Player.likeClick) + $("#video-link").bind("click", Player.linkClick) + $("#fullscreen").bind("click", Viewport.fullscreenOn) + Player.projector = {type:"null",load:d.noop,unload:Youtube.unload,} + for (i in Player.projectors) + Player.projectors[i].init() + if (Player.queue.length > 0) + Player.currentIdx = Player.queue.length + Playlist.init() + } + } + +var Playlist = + { + count: 0, + showScores: false, + enqueue: function (videos) + { + if (! (videos instanceof Array)) + videos = [videos] + // d.warn("PLAYLIST ENQUEUE "+videos.length) + var rows = [] + var clickables = [] + for (i in videos) + { + var video = videos[i] + $("#"+video.key).html(video.title) + if (Player.enqueue(video)) + { + rows.push(Playlist.display(video)) + Playlist.count += 1 + } + } + $("#queue").prepend(rows.reverse().join("")) + }, + enqueueOldVideoFormat: function (videos) + { + // d.warn("ENQUEUING "+videos.length+" OLD FORMAT") + for (i in videos) + { + // 0 id 1 date 2 userid 3 user 4 url 5 title + var row = videos[i] + var video = + { + id: row[0], + date: row[1], + userid: row[2], + username: row[3], + src: row[4], + title: row[5] || '___', + seen: false, + error: false, + } + if (row.length > 6) + { + video.score = parseInt(row[6]) || 0 + // block video if it's a duplicate + } + var url = row[4] + if (url.indexOf("youtube.com") !== -1) + { + var ytid = Youtube.getYtid(url) + video.type = "youtube" + video.name = ytid + } + else if (url.indexOf("vimeo.com") !== -1) + { + var vimeoid = url.replace(VIMEOregexp, "$3") + video.type = "vimeo" + video.name = vimeoid + } + else if (url.indexOf("soundcloud.com") !== -1) + { + video.type = "soundcloud" + video.name = $.md5(video.src) + } + else if (url.indexOf("mp3") !== -1) + { + video.type = "audio" + video.name = $.md5(video.src) + } + else + { + d.error("bad video id in "+url) + continue + } + video.key = video.type + "_" + video.name + Playlist.enqueue(video) + // d.joy("GOT VIDEO: "+key) + } + }, + clickTitle: function (e) + { + var id = $(this).parent().attr("id") + var idx = id.substr(id.indexOf("_")+1) + d.act("+ clicked playlist "+idx) + Player.playIdx(parseInt(idx)) + }, + clickLike: function (e) + { + var id = $(this).parent().attr("id") + var idx = id.substr(id.indexOf("_")+1) + var videokey = Player.queue[idx] + var video = Player.videos[videokey] + d.act("+ clicked playlist like "+video.key) + Like.likeContent(video) + }, + clickChatlink: function (e) + { + e.preventDefault() + var key = $(this).attr("id") + var video = Player.videos[key] + d.act("+ clicked link "+video.key) + Player.playVideo(video) + }, + display: function (video) + { + var likeClass = '' + var likeWord = "  like" + if (video.username === Auth.username) + { + likeClass = "you" + } + else if (Local.isLiked(video.id)) + { + likeClass = 'liked' + likeWord = 'liked' + } + var s = "
  • " + if (Playlist.showScores) + { + score = video.score + if (score < 1) + score = ' ' + s += ""+score+"" + } + s += "" + var domain = window.location.hostname.split('.').slice(-2).join('.') + s += ""+video.username+"" + s += ""+video.title+"" //I'm having trouble figuring out how the "video" gets passed in here tried traceback in firebug? I don't know how to do that. +//do you know the equivalent in chrome? they both should have it, just need to set a breakpoint on js code line and f5 page +//ok can you walk me through it? sure ok the page is loaded, where should I set the breakpoint? this line ok where exactly? I have the source +//open in the inspector, do I set the breakpointpoint before or after the line? on the line trying to open the site, it gives 404 on static files are you sure? +//yeah scannerjammer.com ? works fine for me hm + s += "
  • " + return s + }, + init: function () + { + d.warn("PLAYLIST INIT") + $("#queue li span.title").live("click", Playlist.clickTitle) + $("#queue li span.like").live("click", Playlist.clickLike) + $("#chat a.ytlink").live("click", Playlist.clickChatlink) + } + } + +var Scanner = + { + scanMode: false, + scanTimeout: false, + scanBlinkTimeout: false, + scanBlinkState: false, + scanBlinkRate: 200, + scanRate: 9000, + scanBlink: function () + { + if (Scanner.scanBlinkState) + { + $("#scan").addClass("blinkOff") + $("#scan").removeClass("blinkOn") + Scanner.scanBlinkState = false + } + else + { + $("#scan").addClass("blinkOn") + $("#scan").removeClass("blinkOff") + Scanner.scanBlinkState = true + } + Scanner.scanBlinkTimeout = setTimeout(Scanner.scanBlink, Scanner.scanBlinkRate) + }, + scanGo: function () + { + Player.playNext() + Scanner.scanTimeout = setTimeout(Scanner.scanGo, Scanner.scanRate) + }, + scan: function () + { + if (Scanner.scanMode) + { + d.warn("SCANNER ON") + Scanner.scanMode = false + clearTimeout(Scanner.scanTimeout) + clearTimeout(Scanner.scanBlinkTimeout) + $("#scan").removeClass("blinkOn") + $("#scan").removeClass("blinkOff") + } + else + { + d.warn("SCANNER OFF") + Scanner.scanMode = true + Scanner.scanBlink() + Scanner.scanGo() + } + } + } diff --git a/frontend/static/js/src/room.js b/frontend/static/js/src/room.js new file mode 100644 index 0000000..2d77f6f --- /dev/null +++ b/frontend/static/js/src/room.js @@ -0,0 +1,460 @@ +var Menu = {} +var Room = + { + loaded: false, + ops: {}, + settings: {}, + settingsButtonBound: false, + updateSettingMethods: + { + bg: function (url) + { + if (url === Room.settings.bg) + return + d.warn("clearing bg") + $("#bg").fadeOut(500, function () + { + if (url) + { + d.warn("updating bg to "+url) + $("#bg img").attr('src', url).bind("load", function(){$("#bg").fadeIn(2000);d.warn("bg updated")}) + } + }) + }, + title: function (s) + { + if (s.length === 0) + s = " " + $("#heading").html( s.replace(">",">").replace("<","<") ) + }, + topic: function (s) + { + if (s.length === 0) + s = " " + $("#topic").html( d.linkify(s.replace(">",">").replace("<","<")) ) + }, + phase: function (s) + { + if (s === 'light') + { + // turn on lookit stylesheet + } + else + { + // turn off lookit stylesheet + } + }, + bgcolor: function (s) + { + if (s) + $('body').css("background-color", s) + } + }, + updateSetting: function (k, v) + { + d.warn( "update setting: "+k ) + $("room-"+k).val(v) + if (k in Room.updateSettingMethods) + var f = Room.updateSettingMethods[k](v) + Room.settings[k] = v + }, + settingsOpen: function () + { + d.warn("ROOM SETTINGS LOAD") + $("#room-id").html(Room.id) + $("#room-name").html(Room.name) + $("#room-path").html(Room.path) + $("#room-title").val(Room.settings['title']) + $("#room-topic").val(Room.settings['topic']) + $("#room-phase").val(Room.settings['phase']) + $("#room-bg").val(Room.settings['bg']) + $("#room-bgcolor").val(Room.settings['bgcolor']) + $("#room-plant").val(Room.settings['plant']) + $("#room-flower").val(Room.settings['flower']) + $("#room-updater").html(Room.settings['updater']) + if (! Room.settingsButtonBound) + { + Room.settingsButtonBound = true + $("#room-settings-save").bind("click", Room.settingsSaveClick) + } + $("#room-settings-unload").bind("click", Room.settingsClose) + if (Auth.access > 0) + $("#room-mod-tag").html("Moderate room") + else + $("#room-mod-tag").html("") + d.warn("LOADED") + }, + settingsClose: function () + { + d.warn("ROOM SETTINGS UNLOAD") + Room.settingsButtonBound = false + $("#room-settings-save").unbind("click") + }, + settingsKeys: ["title","topic","bg"], + last_bg: "", + settingsSaveClick: function () + { + $("#room-settings-save").unbind("click") + var set = [] + if (Room.ops !== false) + { + if (Auth.access < 1 && !(Auth.username in Room.ops)) + { + Menu.settings.close() + return + } + } + Room.last_bg = Room.settingsKeys['bg'] + for (i in Room.settingsKeys) + { + var k = Room.settingsKeys[i] + var v = d.sanitize( $("#room-"+k).val() ) + Room.updateSetting(k, v) + set.push(k+"\t"+v) + } + set.push("updater\t"+Auth.username) + var s = set.join("\n") + $.post(API.URL.room.settings, {room: Room.name, session: Auth.session, settings: s}, Room.settingsCallback) + Menu.settings.close() + }, + settingsCallback: function (raw) + { + var lines = API.parse("/room/say", raw) + if (! lines) + return + if (lines[0].indexOf("OK") !== -1) + { + d.warn("settings updated: "+lines.shift()) + $("#room-updater").hide().html("you!").fadeIn(500) + } + else if (lines[0].indexOf("BG_SIZE") !== -1) + { + var partz = lines[0].split("\t") + setTimeout('Room.updateSettingMethods.bg(Room.last_bg)', 2000) + alert("Background too large!\n\nYour image: "+ partz[2]+" bytes\nMax size: " + partz[3] + " bytes") + } + else if (lines[0].indexOf("BG_DATA") !== -1) + { + setTimeout('Room.updateSettingMethods.bg(Room.last_bg)', 2000) + alert("Unable to retrieve background image") + } + $("#room-settings-save").bind("click", Room.settingsSaveClick) + }, + connect: function () + { + var videoKey = '' + var hash = document.location.hash + if (hash.indexOf("#") !== -1) + hash = hash.substr(1) + var partz = hash.split("&") + for (i in partz) + { + var pair = partz[i].split("=") + if (pair[0] === "v") + videoKey = pair[1] + } + d.warn("JOINING ROOM "+Room.name) + $.ajax({ + type: 'POST', + url: API.URL.room.join, + data: {'room':Room.name,'session':Auth.session,'enqueue':videoKey}, + timeout: 60000, + }).success(Room.joinCallback).error(Room.joinErrorCallback) + }, + joinErrorCallback: function (jqXHR, textStatus, errorThrown) + { + d.warn("JOIN ERROR") + if (Room.loaded) + return + if (textStatus === "timeout") + Room.connect() + else + Auth.load() + }, + joinCallback: function (raw) + { + var lines = API.parse("/room/join", raw) + if (!lines){ + d.error("UNABLE TO LOAD ROOM"); + setTimeout(Room.load, 500); + return; + } + var u = lines.shift().split("\t") + + if (u[0] === '0') + return Auth.load() + d.warn("JOINED ROOM") + Auth.unload() + Auth.userid = u[0] + Auth.username = u[1] + Auth.access = u[2] + d.joy("logged in as "+Auth.username) + + Lastlog.update(lines.shift()) + Chat.store(lines) + + d.warn("__________") + d.warn("__________") + d.warn("__________") + Room.load() + d.warn("__________") + d.warn("__________") + d.warn("__________") + }, + load: function () + { + d.warn("LOAD ROOM") + $("#loading").fadeOut(500, function() + { + Background.load() + Player.init() + VideoChat.init() + Chat.poll() + }) + $("#loading").fadeOut(1500, Room.loadFinish) + }, + loadFinish: function () + { + setTimeout("d.scrollToBottom('#chat')", 500) + $("#logo").show() + $("#logobg,#logobar").show() + $("#likebutton").css("display", "inline-block") + + $("#player").show() + $("#playlist").show() + $("#playlistbg").show() + + $("#form").show() + $("#formbg").show() + $("#chat").fadeIn(200) + d.scrollToBottom("#chat") + $("#chatbg").show() + $("#lastlogbox").show() + $("#lastlogbg").show() + + Keyboard.enter = Chat.say + $("#chat-message").bind("focus", Keyboard.focusTextarea) + $("#chat-message").bind("blur", Keyboard.blurTextarea) + $("#chat-message").focus() + Keyboard.focusTextarea() + $("#chat-send").bind("click", Chat.say) + $("#fullscreen").bind("click", Viewport.fullscreenOn) + $("#sitez").show() + $("#logout").click(Auth.logout) + if (Room.name === "feederbleeder") + { + $("#heading").css({ "color": "#ff3333" }) + // Viewport.fullscreenOn() + } + //else + Viewport.standardResize() + // $(".ytlink").live("click", Player.ytLinkClick, false) + + if (Auth.access > 0) + { + // var div = $("
    ").addClass("modhello").html("Congratulations new moderator! Click on the cube icon in the upper right corner and you will see the MODERATE ROOM link.").click(function(){$(this).fadeOut(1000)}) + // $("#chat").append(div) + } + // var div = $("
    ").addClass("modhello").html("Hey! You can now use the LEFT AND RIGHT ARROW KEYS to browse the playlist, and the L key to like a video!").click(function(){$(this).fadeOut(1000)}) + // $("#chat").append(div) + setTimeout(Player.start, 2000) + Room.loaded = true + document.cookie = "room="+Room.name+";path=/;domain=.scannerjammer.com;max-age=86400" + if (Room.loadCallback) + Room.loadCallback() + }, + loadCallback: false, + unload: function () + { + $("#logo,#logobg,#player,#playlist,#playlistbg,#form,#formbg,#chat,#chatbg,#lastlogbox,#lastlogbg,#sitez").hide() + Menu.close() + }, + init: function () + { + d.warn("INIT ROOM") + if (roomName !== undefined) + Room.name = roomName + else + Room.name = "main" + d.warn("room: "+Room.name) + // $("#chat").show() + } + } + +var Rooms = + { + loaded: false, + queue: [ + [0, "rooms", "/", "http://scannerjammer.com/static/bgz/gridzy9.jpg", "→ SEE ALL OPEN ROOMS"], + [1, "main", "/main", "http://scannerjammer.com/static/bgz/1302474305250-dumpfm-GucciSoFlosy-pattern4.gif", "MAIN ROOM"], + [12, "FEEDERBLEEDER", "/feederbleeder", "http://scannerjammer.com/static/img/Tropic_Of_Cancer__The_Sorrow_Of_Two_Blooms_1308602037.jpg", "FEEDERBLEEDER"], + [2, "avatar", "/avatar", "http://scannerjammer.com/static/img/avatar2.png", "avatar"], + [3, "glitter", "/glitter", "http://scannerjammer.com/static/bgz/argus.gif", "glitter"], + [10, 'jono', '/jonomilo', 'http://scannerjammer.com/static/bgz/whitesquare.gif', 'jònò mì lò'], + //[11, 'SJD', 'http://lolz.biz/sjd', 'http://scannerjammer.com/static/img/idgiguy2.png', 'SJD'], + [4, "waterfall", "/waterfall", "http://i.imgur.com/QEZRF.gif", "waterfall"], + ], + list: function () + { + if (Rooms.loaded) + return + Rooms.listDisplay(Rooms.queue) + // $.post(API.URL.room.list, {session:Auth.session}).success(Rooms.listCallback).error(Rooms.listError) + }, + listCallback: function (raw) + { + // parse API + Rooms.listDisplay(lines) + }, + listError: function () + { + Rooms.listDisplay(Rooms.queue) + }, + listDisplay: function (rooms) + { + $("#rooms-loading").hide() + var divz = [] + for (i in rooms) + { + var r = rooms[i] + var s = "
  • "+r[4] + if (r[1] === Room.name) + s += " < YOU ARE HERE" + s += "
  • " + divz.push(s) + } + $("#rooms-list").html(divz.join('')) + Rooms.loaded = true + } + } +var About = + { + loaded: false, + init: function () + { + var domain = window.location.hostname.split('.').slice(-2).join('.') + $("#your-profile").attr('href', 'http://'+Auth.username+"."+domain+"/") + About.loaded = true + } + } +function menu (key, loadCallback) + { + d.warn("MENU INIT "+key) + this.appear = function () + { + if (! Menu.isOpen) + { + $("#"+key+"-container").show() + Menu.current = key + loadCallback() + $("#chat-message").blur() + Keyboard.blurTextarea() + } + } + this.disappear = function () + { + if (! Menu.isOpen) + $("#"+key+"-container").hide() + } + this.close = function () + { + $("#"+key+"-container").hide() + $(".opened").removeClass("opened") + Menu.isOpen = false + } + this.click = function () + { + for (i in Menu.keys) + { + $("#"+Menu.keys[i]+"-container").hide() + } + $("#"+key+"-container").show() + if (Menu.current !== key) + loadCallback() + Menu.current = key + $(".opened").removeClass("opened") + $("#"+key+"-hook").addClass("opened") + Menu.isOpen = true + } + $("#"+key+"-hook").hover(this.appear, this.disappear).click(this.click) + $("#"+key+"-close").click(this.close) + $("#"+key+"-container").hover(this.click, this.close) + } +var VideoChat = + { + isOpen: false, + badgePositioned: false, + suppressBadge: 0, + updateCount: function (count) + { + /* + if (VideoChat.suppressBadge > 0) + { + VideoChat.suppressBadge -= 1 + return + } + */ + if (parseInt(count) > 0) + { + if (! VideoChat.badgePositioned) + { + VideoChat.badgePositioned = true + $("#videochat-badge").css({ + right: 5, + top: 5, + }).show() + } + $("#videochat-badge").html(count).show() + } + else + { + $("#videochat-badge").hide() + } + }, + open: function () + { + // $("#tokbox-embed").html('') + // $("#tokbox-embed").show() + // $(window).trigger('resize') + VideoChat.isOpen = true + // Webcam.load() + Tokbox.load() + }, + close: function () + { + // $("#tokbox-embed").hide().html("") + // $("#tokbox-close").hide() + // $(window).trigger('resize') + VideoChat.isOpen = false + VideoChat.suppressBadge = 20 + // Webcam.unload() + Tokbox.unload() + }, + toggle: function () + { + if (VideoChat.isOpen) + VideoChat.close() + else + VideoChat.open() + }, + init: function () + { + // Webcam.init() + $("#tokbox").show() + $("#videochat-toggle").click(VideoChat.toggle) + } + } +var Menu = + { + isOpen: false, + current: false, + keys: ["settings","about","rooms"], + close: function () + { + if (Menu.current) + Menu[Menu.current].close() + }, + settings: new menu("settings", Room.settingsOpen), + rooms: new menu("rooms", Rooms.list), + about: new menu("about", About.init), + } diff --git a/frontend/static/js/src/search.js b/frontend/static/js/src/search.js new file mode 100644 index 0000000..85014af --- /dev/null +++ b/frontend/static/js/src/search.js @@ -0,0 +1,190 @@ +YOUTUBE_SEARCH_URL = "https://gdata.youtube.com/feeds/api/videos" +YOUTUBE_URL_PREFIX = "http://youtube.com/watch?v=" +function courtesy_s (quantity, noun) + { + if (quantity > 1) + return quantity + " " + noun + "s" + return quantity + " " + noun + } +var Search = + { + start: 0, + limit: 20, + sj: function () + { + Search.start = 0 + Search.terms = $("#search-terms").val() + Search.sjSearch (Search.terms, Search.start) + }, + sjSearch: function (terms, start) + { + var params = + { + "q": terms, + "start": Search.start, + "limit": Search.limit, + "session": Auth.session, + } + $.post(API.URL.video.search, params, Search.sjCallback) + $("#search-instructions").hide() + $("#search-results").html("").hide() + $("#search-loading").show() + $("#search-results-container").show() + }, + sjCallback: function (raw) + { + var lines = API.parse ("/video/search", raw) + var items = [] + for (var i = 0; i < lines.length; i++) + { + // 0 id 1 score 2 user 3 usercount 4 title 5 url 6 thumbnail + var line = lines[i].split("\t") + if (line.length < 7) + continue + var video = + { + url: line[5], + thumbnail: line[6], + title: line[4], + user: line[2], + quantify: "", + } + if (parseInt(line[3]) > 1) + video['user'] += " + " + courtesy_s (parseInt(line[3])-1, "other") + if (parseInt(line[1]) > 0) + video['quantify'] = courtesy_s (parseInt(line[1]), "like") + var tag = Search.resultTag (video) + items.push(tag) + } + if (items.length === Search.limit) + { + Search.start += Search.limit + $("#search-next-page").show() + } + else + { + $("#search-next-page").hide() + } + $("#search-loading").hide() + $("#search-results").html(items.join("")).show() + $("#search-instructions").show() + $("#curtain").bind("click", Search.close).css({"background-color": "transparent", "z-index": 99}).show() + }, + youtube: function () + { + var terms = $("#search-terms").val() + var params = + { + "q": terms, + "v": 2, + "alt": "jsonc", + } + $.get(YOUTUBE_SEARCH_URL, params, Search.youtubeCallback, "jsonp") + $("#search-results-container").show() + $("#search-results").html("").hide() + $("#search-loading").show() + }, + durationToString: function (duration) + { + return Math.floor(duration / 60) + ":" + (duration % 60) + }, + viewCountToString: function (viewCount) + { + if (! viewCount) + return '0' + var vc = viewCount.toString () + var commas = /(\d+)(\d{3})/; + while (commas.test(vc)) + { + vc = vc.replace(commas, '$1' + ',' + '$2'); + } + return vc + }, + resultTag: function (video) + { + var tag = "
  • " + tag += "
    " + tag += "

    " + video['title'] + "

    " + tag += "" + tag += "Preview" + tag += "
  • " + return tag + }, + youtubeCallback: function (data) + { + var items = [] + for (var i = 0; i < data['data']['items'].length; i++) + { + var item = data['data']['items'][i] + var video = + { + url: YOUTUBE_URL_PREFIX+item['id'], + thumbnail: item['thumbnail']['sqDefault'], + title: item['title'], + user: item['uploader'], + quantify: Search.viewCountToString(item['viewCount']) + "views", + } + var tag = Search.resultTag (video) + items.push(tag) + } + $("#search-loading").hide() + $("#search-results").html(items.join("")).show() + }, + keydown: function (e) + { + if (e.keyCode === 13) + { + Search.sj () + } + if (e.keyCode === 27) + { + Search.close () + Keyboard.focusTextarea () + } + }, + nextPage: function () + { + Search.sjSearch (Search.terms, Search.start) + }, + loadResult: function () + { + var url = $(this).parent().data("url") + $.post(API.URL.room.say, {room: Room.name, session: Auth.session, msg: url}) + Search.close () + }, + close: function () + { + $("#curtain").unbind("click", Search.close).hide() + $("#search-results-container").hide() + $("#search-terms").val("") + }, + blurSearchTextarea: function () + { + $(window).unbind("keydown") + $("#chat-message").unbind("keydown").bind("keydown", Keyboard.textareaMap) + $("#chat-message").unbind("focus").focus().bind("focus", Keyboard.focusTextarea) + if ($("#chat-message").val().length === 0) + Keyboard.enteredText = false + }, + focusSearchTextarea: function () + { + $(window).unbind("keydown") + $("#chat-message").unbind("keydown") + }, + init: function () + { + $("#search-results li div").live("click", Search.loadResult) + $("#search-results li h4").live("click", Search.loadResult) + $("#search-results li span").live("click", Search.loadResult) + $("#search-terms").bind("keydown", Search.keydown) + $("#search-terms").bind("focus", Search.focusSearchTextarea) + $("#search-terms").bind("blur", Search.blurSearchTextarea) + // $("#search-terms").val("glock n my hand") + // Search.sj () + } + } +Search.init () diff --git a/frontend/static/js/src/soundcloud.js b/frontend/static/js/src/soundcloud.js new file mode 100644 index 0000000..22d7aa3 --- /dev/null +++ b/frontend/static/js/src/soundcloud.js @@ -0,0 +1,156 @@ +var Soundcloud = + { + type: "soundcloud", + loaded: false, + pending: false, + playing: false, + player: null, + playerId: null, + timeout: null, + video: null, + width: "100%", + height: "100%", + volume: 100, + play: function (video) + { + d.warn("SOUNDCLOUD PLAY "+video.key) + if (video.error) + return Soundcloud.error() + if (Soundcloud.playing) + Soundcloud.stop() + $("#screen").html("
    ") + Soundcloud.video = video + Soundcloud.playing = false + + if (Soundcloud.player) + { + Soundcloud.player = null + swfobject.removeSWF("soundcloud") + } + + var flashvars = { enable_api: true, object_id: "soundcloud", url: video.src, theme_color: "#657b83", } + var attributes = { id: "soundcloud", name: "soundcloud" } + var params = { allowscriptaccess: "always", wmode: "opaque", } + + swfobject.embedSWF("http://player.soundcloud.com/player.swf", "soundcloud", "81", "81", "9.0.0", + "expressInstall.swf", flashvars, params, attributes, Soundcloud.playerDidLoad); + }, + playerDidLoad: function (e) + { + if (e.success === false) + return Soundcloud.error("failed to load") + d.warn("LOADED") + Soundcloud.player = swfobject.getObjectById('soundcloud') + $("#ytscreen").css("z-index", -2) + // instead of raising events, the soundcloud swf calls it's js api directly + window.soundcloud = { onPlayerReady: Soundcloud.ready, onMediaEnd: Soundcloud.finish } + }, + ready: function () + { + d.warn("READY") + Soundcloud.playing = true + Soundcloud.player = swfobject.getObjectById('soundcloud') + if (Soundcloud.player) + { + Soundcloud.player.api_play() + Soundcloud.player.api_setVolume(Soundcloud.volume) + } + Soundcloud.report() + }, + report: function () + { + if (! Soundcloud.player) + return Soundcloud.error() + var track = Soundcloud.player.api_getCurrentTrack() + $("#video-title").html(track.title) + if (track.downloadable && track.download_url !== "undefined" && track.download_url !== undefined) + $("#soundcloud-dl").html('download') + else + $("#soundcloud-dl").html("") + var art = '' + if (track.artwork) + art = track.artwork.split("?")[0].replace('large','original') + else if (track.user && track.user.avatarUrl) + art = track.user.avatarUrl.split("?")[0].replace('large','crop') + if (art.length) + { + $("#soundcloud-img").html("") + $("#sc-art").bind("error", function(){$("#sc-art").hide()}) + } + return + d.warn("____________") + for (i in track) + d.warn(""+i+": "+track[i]) + d.warn("____________") + var user = track.user + for (i in user) + d.warn(""+i+": "+user[i]) + d.warn("____________") + }, + toggle: function () + { + d.warn("TOGGLE PLAYBACK") + if (Soundcloud.player) + return Soundcloud.player.api_toggle() + return false + }, + error: function (s) + { + Player.error("SOUNDCLOUD "+s) + Soundcloud.finish() + }, + setVolume: function (vol) + { + Soundcloud.volume = vol + if (Soundcloud.player) + Soundcloud.player.api_setVolume(vol) + }, + pause: function () + { + d.warn("PAUSED PLAYBACK") + Soundcloud.playing = false + if (Soundcloud.player) + Soundcloud.player.api_pause() + return true + }, + resume: function () + { + d.warn("RESUME PLAYBACK") + Soundcloud.playing = true + if (Soundcloud.player) + Soundcloud.player.api_play() + return false + }, + stop: function () + { + d.warn("SOUNDCLOUD STOP") + if (Soundcloud.player) + Soundcloud.player.api_stop() + Soundcloud.playing = false + }, + finish: function () + { + d.warn("SOUNDCLOUD FINISH") + Soundcloud.playing = false + swfobject.removeSWF("soundcloud") + Player.finish() + }, + load: function () + { + d.warn("LOADING SOUNDCLOUD") + Soundcloud.loaded = true + }, + unload: function () + { + d.warn("SOUNDCLOUD UNLOADED") + swfobject.removeSWF("soundcloud") + Soundcloud.loaded = false + Soundcloud.playing = false + }, + init: function () + { + d.warn("SOUNDCLOUD INIT") + window.soundcloud = Soundcloud + } + } +Player.register(Soundcloud) diff --git a/frontend/static/js/src/soundmanager.js b/frontend/static/js/src/soundmanager.js new file mode 100755 index 0000000..46528c9 --- /dev/null +++ b/frontend/static/js/src/soundmanager.js @@ -0,0 +1,2838 @@ +/** @license + * SoundManager 2: Javascript Sound for the Web + * -------------------------------------------- + * http://schillmania.com/projects/soundmanager2/ + * + * Copyright (c) 2007, Scott Schiller. All rights reserved. + * Code provided under the BSD License: + * http://schillmania.com/projects/soundmanager2/license.txt + * + * V2.97a.20101010 + */ + +/*jslint white: false, onevar: true, undef: true, nomen: false, eqeqeq: true, plusplus: false, bitwise: true, regexp: true, newcap: true, immed: true, regexp: false */ +/*global window, SM2_DEFER, sm2Debugger, alert, console, document, navigator, setTimeout, setInterval, clearInterval, Audio */ + +(function(window) { + +var soundManager = null; + +function SoundManager(smURL, smID) { + + this.flashVersion = 8; // version of flash to require, either 8 or 9. Some API features require Flash 9. + this.debugMode = true; // enable debugging output (div#soundmanager-debug, OR console if available+configured) + this.debugFlash = false; // enable debugging output inside SWF, troubleshoot Flash/browser issues + this.useConsole = true; // use firebug/safari console.log()-type debug console if available + this.consoleOnly = false; // if console is being used, do not create/write to #soundmanager-debug + this.waitForWindowLoad = false; // force SM2 to wait for window.onload() before trying to call soundManager.onload() + this.nullURL = 'about:blank'; // path to "null" (empty) MP3 file, used to unload sounds (Flash 8 only) + this.allowPolling = true; // allow flash to poll for status update (required for whileplaying() events, peak, sound spectrum functions to work.) + this.useFastPolling = false; // uses lower flash timer interval for higher callback frequency, best combined with useHighPerformance + this.useMovieStar = true; // enable support for Flash 9.0r115+ (codename "MovieStar") MPEG4 audio formats (AAC, M4V, FLV, MOV etc.) + this.bgColor = '#ffffff'; // movie (.swf) background color, eg. '#000000' + this.useHighPerformance = false; // position:fixed flash movie can help increase js/flash speed, minimize lag + this.flashLoadTimeout = 1000; // msec to wait for flash movie to load before failing (0 = infinity) + this.wmode = null; // string: flash rendering mode - null, transparent, opaque (last two allow layering of HTML on top) + this.allowScriptAccess = 'always'; // for scripting the SWF (object/embed property), either 'always' or 'sameDomain' + this.useFlashBlock = false; // *requires flashblock.css, see demos* - allow recovery from flash blockers. Wait indefinitely and apply timeout CSS to SWF, if applicable. + this.useHTML5Audio = false; // Beta feature: Use HTML 5 Audio() where API is supported (most Safari, Chrome versions), Firefox (no MP3/MP4.) Ideally, transparent vs. Flash API where possible. + this.html5Test = /^probably$/i; // HTML5 Audio().canPlayType() test. /^(probably|maybe)$/i if you want to be more liberal/risky. + this.ondebuglog = false; // callback made with each log message, regardless of debugMode + + this.audioFormats = { + // determines HTML5 support, flash requirements + // eg. if MP3 or MP4 required, Flash fallback is used if HTML5 can't play it + // shotgun approach to MIME testing due to browser variance + 'mp3': { + 'type': ['audio/mpeg; codecs="mp3"','audio/mpeg','audio/mp3','audio/MPA','audio/mpa-robust'], + 'required': true + }, + 'mp4': { + 'related': ['aac','m4a'], // additional formats under the MP4 container + 'type': ['audio/mp4; codecs="mp4a.40.2"','audio/aac','audio/x-m4a','audio/MP4A-LATM','audio/mpeg4-generic'], + 'required': true + }, + 'ogg': { + 'type': ['audio/ogg; codecs=vorbis'], + 'required': false + }, + 'wav': { + 'type': ['audio/wav; codecs="1"','audio/wav','audio/wave','audio/x-wav'], + 'required': false + } + }; + + this.defaultOptions = { + 'autoLoad': false, // enable automatic loading (otherwise .load() will be called on demand with .play(), the latter being nicer on bandwidth - if you want to .load yourself, you also can) + 'stream': true, // allows playing before entire file has loaded (recommended) + 'autoPlay': false, // enable playing of file as soon as possible (much faster if "stream" is true) + 'loops': 1, // how many times to repeat the sound (position will wrap around to 0, setPosition() will break out of loop when >0) + 'onid3': null, // callback function for "ID3 data is added/available" + 'onload': null, // callback function for "load finished" + 'whileloading': null, // callback function for "download progress update" (X of Y bytes received) + 'onplay': null, // callback for "play" start + 'onpause': null, // callback for "pause" + 'onresume': null, // callback for "resume" (pause toggle) + 'whileplaying': null, // callback during play (position update) + 'onstop': null, // callback for "user stop" + 'onfailure': null, // callback function for when playing fails + 'onfinish': null, // callback function for "sound finished playing" + 'onbeforefinish': null, // callback for "before sound finished playing (at [time])" + 'onbeforefinishtime': 5000, // offset (milliseconds) before end of sound to trigger beforefinish (eg. 1000 msec = 1 second) + 'onbeforefinishcomplete': null,// function to call when said sound finishes playing + 'onjustbeforefinish': null, // callback for [n] msec before end of current sound + 'onjustbeforefinishtime': 200, // [n] - if not using, set to 0 (or null handler) and event will not fire. + 'multiShot': true, // let sounds "restart" or layer on top of each other when played multiple times, rather than one-shot/one at a time + 'multiShotEvents': false, // fire multiple sound events (currently onfinish() only) when multiShot is enabled + 'position': null, // offset (milliseconds) to seek to within loaded sound data. + 'pan': 0, // "pan" settings, left-to-right, -100 to 100 + 'type': null, // MIME-like hint for file pattern / canPlay() tests, eg. audio/mp3 + 'usePolicyFile': false, // enable crossdomain.xml request for audio on remote domains (for ID3/waveform access) + 'volume': 100 // self-explanatory. 0-100, the latter being the max. + }; + + this.flash9Options = { // flash 9-only options, merged into defaultOptions if flash 9 is being used + 'isMovieStar': null, // "MovieStar" MPEG4 audio mode. Null (default) = auto detect MP4, AAC etc. based on URL. true = force on, ignore URL + 'usePeakData': false, // enable left/right channel peak (level) data + 'useWaveformData': false, // enable sound spectrum (raw waveform data) - WARNING: CPU-INTENSIVE: may set CPUs on fire. + 'useEQData': false, // enable sound EQ (frequency spectrum data) - WARNING: Also CPU-intensive. + 'onbufferchange': null, // callback for "isBuffering" property change + 'ondataerror': null, // callback for waveform/eq data access error (flash playing audio in other tabs/domains) + 'onstats': null // callback for when connection & play times have been measured + }; + + this.movieStarOptions = { // flash 9.0r115+ MPEG4 audio options, merged into defaultOptions if flash 9+movieStar mode is enabled + 'bufferTime': 3, // seconds of data to buffer before playback begins (null = flash default of 0.1 seconds - if AAC playback is gappy, try increasing.) + 'serverURL': null, // rtmp: FMS or FMIS server to connect to, required when requesting media via RTMP or one of its variants + 'onconnect': null, // rtmp: callback for connection to flash media server + 'bufferTimes': null, // array of buffer sizes to use. Size increases as buffer fills up. + 'duration': null // rtmp: song duration (msec) + }; + + this.version = null; + this.versionNumber = 'V2.97a.20101010'; + this.movieURL = null; + this.url = (smURL || null); + this.altURL = null; + this.swfLoaded = false; + this.enabled = false; + this.o = null; + this.movieID = 'sm2-container'; + this.id = (smID || 'sm2movie'); + this.swfCSS = { + 'swfBox': 'sm2-object-box', + 'swfDefault': 'movieContainer', + 'swfError': 'swf_error', // SWF loaded, but SM2 couldn't start (other error) + 'swfTimedout': 'swf_timedout', + 'swfUnblocked': 'swf_unblocked', // or loaded OK + 'sm2Debug': 'sm2_debug', + 'highPerf': 'high_performance', + 'flashDebug': 'flash_debug' + }; + this.oMC = null; + this.sounds = {}; + this.soundIDs = []; + this.muted = false; + this.debugID = 'soundmanager-debug'; + this.debugURLParam = /([#?&])debug=1/i; + this.specialWmodeCase = false; + this.didFlashBlock = false; + + this.filePattern = null; + this.filePatterns = { + 'flash8': /\.mp3(\?.*)?$/i, + 'flash9': /\.mp3(\?.*)?$/i + }; + + this.baseMimeTypes = /^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i; // mp3 + this.netStreamMimeTypes = /^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i; // mp3, mp4, aac etc. + this.netStreamTypes = ['aac', 'flv', 'mov', 'mp4', 'm4v', 'f4v', 'm4a', 'mp4v', '3gp', '3g2']; // Flash v9.0r115+ "moviestar" formats + this.netStreamPattern = new RegExp('\\.(' + this.netStreamTypes.join('|') + ')(\\?.*)?$', 'i'); + this.mimePattern = this.baseMimeTypes; + + this.features = { + 'buffering': false, + 'peakData': false, + 'waveformData': false, + 'eqData': false, + 'movieStar': false + }; + + this.sandbox = { + // + 'type': null, + 'types': { + 'remote': 'remote (domain-based) rules', + 'localWithFile': 'local with file access (no internet access)', + 'localWithNetwork': 'local with network (internet access only, no local access)', + 'localTrusted': 'local, trusted (local+internet access)' + }, + 'description': null, + 'noRemote': null, + 'noLocal': null + // + }; + + this.hasHTML5 = null; // switch for handling logic + this.html5 = { // stores canPlayType() results, etc. treat as read-only. + // mp3: boolean + // mp4: boolean + 'usingFlash': null // set if/when flash fallback is needed + }; + this.ignoreFlash = false; // used for special cases (eg. iPad/iPhone/palm OS?) + + // --- private SM2 internals --- + + var SMSound, + _s = this, _sm = 'soundManager', _id, _ua = navigator.userAgent, _wl = window.location.href.toString(), _fV = this.flashVersion, _doc = document, _win = window, _doNothing, _init, _onready = [], _debugOpen = true, _debugTS, _didAppend = false, _appendSuccess = false, _didInit = false, _disabled = false, _windowLoaded = false, _wDS, _wdCount = 0, _initComplete, _mixin, _addOnReady, _processOnReady, _initUserOnload, _go, _delayWaitForEI, _waitForEI, _setVersionInfo, _handleFocus, _beginInit, _strings, _initMovie, _dcLoaded, _didDCLoaded, _getDocument, _createMovie, _die, _mobileFlash, _setPolling, _debugLevels = ['log', 'info', 'warn', 'error'], _defaultFlashVersion = 8, _disableObject, _failSafely, _normalizeMovieURL, _oRemoved = null, _oRemovedHTML = null, _str, _flashBlockHandler, _getSWFCSS, _toggleDebug, _loopFix, _policyFix, _complain, _idCheck, _waitingForEI = false, _initPending = false, _smTimer, _onTimer, _startTimer, _stopTimer, _needsFlash = null, _featureCheck, _html5OK, _html5Only = false, _html5CanPlay, _html5Ext, _dcIE, _testHTML5, _addEvt, _removeEvt, _slice = Array.prototype.slice, + _is_pre = _ua.match(/pre\//i), + _iPadOrPhone = _ua.match(/(ipad|iphone)/i), + _isMobile = (_ua.match(/mobile/i) || _is_pre || _iPadOrPhone), + _isIE = (_ua.match(/MSIE/i)), + _isSafari = (_ua.match(/safari/i) && !_ua.match(/chrome/i)), + _hasConsole = (typeof console !== 'undefined' && typeof console.log !== 'undefined'), + _isFocused = (typeof _doc.hasFocus !== 'undefined'?_doc.hasFocus():null), + _tryInitOnFocus = (typeof _doc.hasFocus === 'undefined' && _isSafari), + _okToDisable = !_tryInitOnFocus; + + this._use_maybe = (_wl.match(/sm2\-useHTML5Maybe\=1/i)); // temporary feature: #sm2-useHTML5Maybe=1 forces loose canPlay() check + this._overHTTP = (_doc.location?_doc.location.protocol.match(/http/i):null); + this.useAltURL = !this._overHTTP; // use altURL if not "online" + + if (_iPadOrPhone || _is_pre) { + // might as well force it on Apple + Palm, flash support unlikely + _s.useHTML5Audio = true; + _s.ignoreFlash = true; + } + + if (_is_pre || this._use_maybe) { + // less-strict canPlayType() checking option + _s.html5Test = /^(probably|maybe)$/i; + } + + // Temporary feature: allow force of HTML5 via URL: #sm2-usehtml5audio=0 or 1 + // + (function(){ + var a = '#sm2-usehtml5audio=', l = _wl, b = null; + if (l.indexOf(a) !== -1) { + b = (l.substr(l.indexOf(a)+a.length) === '1'); + if (typeof console !== 'undefined' && typeof console.log !== 'undefined') { + console.log((b?'Enabling ':'Disabling ')+'useHTML5Audio via URL parameter'); + } + _s.useHTML5Audio = b; + } + }()); + // + + // --- public API methods --- + + this.supported = function() { + return (_needsFlash?(_didInit && !_disabled):(_s.useHTML5Audio && _s.hasHTML5)); + }; + + this.getMovie = function(smID) { + return _isIE?_win[smID]:(_isSafari?_id(smID) || _doc[smID]:_id(smID)); + }; + + this.loadFromXML = function(sXmlUrl) { + try { + _s.o._loadFromXML(sXmlUrl); + } catch(e) { + _failSafely(); + } + return true; + }; + + this.createSound = function(oOptions) { + var _cs = 'soundManager.createSound(): ', + thisOptions = null, oSound = null, _tO = null; + if (!_didInit || !_s.supported()) { + _complain(_cs + _str(!_didInit?'notReady':'notOK')); + return false; + } + if (arguments.length === 2) { + // function overloading in JS! :) ..assume simple createSound(id,url) use case + oOptions = { + 'id': arguments[0], + 'url': arguments[1] + }; + } + thisOptions = _mixin(oOptions); // inherit from defaultOptions + _tO = thisOptions; // alias + // + if (_tO.id.toString().charAt(0).match(/^[0-9]$/)) { + _s._wD(_cs + _str('badID', _tO.id), 2); + } + _s._wD(_cs + _tO.id + ' (' + _tO.url + ')', 1); + // + if (_idCheck(_tO.id, true)) { + _s._wD(_cs + _tO.id + ' exists', 1); + return _s.sounds[_tO.id]; + } + + function make() { + thisOptions = _loopFix(thisOptions); + _s.sounds[_tO.id] = new SMSound(_tO); + _s.soundIDs.push(_tO.id); + return _s.sounds[_tO.id]; + } + + if (_html5OK(_tO)) { + oSound = make(); + _s._wD('Loading sound '+_tO.id+' from HTML5'); + oSound._setup_html5(_tO); + } else { + if (_fV > 8 && _s.useMovieStar) { + if (_tO.isMovieStar === null) { + _tO.isMovieStar = ((_tO.serverURL || (_tO.type?_tO.type.match(_s.netStreamPattern):false)||_tO.url.match(_s.netStreamPattern))?true:false); + } + if (_tO.isMovieStar) { + _s._wD(_cs + 'using MovieStar handling'); + } + if (_tO.isMovieStar) { + if (_tO.usePeakData) { + _wDS('noPeak'); + _tO.usePeakData = false; + } + if (_tO.loops > 1) { + _wDS('noNSLoop'); + } + } + } + _tO = _policyFix(_tO, _cs); + oSound = make(); + if (_fV === 8) { + _s.o._createSound(_tO.id, _tO.onjustbeforefinishtime, _tO.loops||1, _tO.usePolicyFile); + } else { + _s.o._createSound(_tO.id, _tO.url, _tO.onjustbeforefinishtime, _tO.usePeakData, _tO.useWaveformData, _tO.useEQData, _tO.isMovieStar, (_tO.isMovieStar?_tO.bufferTime:false), _tO.loops||1, _tO.serverURL, _tO.duration||null, _tO.autoPlay, true, _tO.bufferTimes, _tO.onstats ? true : false, _tO.autoLoad, _tO.usePolicyFile); + if (!_tO.serverURL) { + // We are connected immediately + oSound.connected = true; + if (_tO.onconnect) { + _tO.onconnect.apply(oSound); + } + } + } + } + if (_tO.autoLoad || _tO.autoPlay) { + if (oSound) { + if (_s.isHTML5) { + oSound.autobuffer = 'auto'; // early HTML5 implementation (non-standard) + oSound.preload = 'auto'; // standard + } else { + oSound.load(_tO); + } + } + } + if (_tO.autoPlay) { + oSound.play(); + } + return oSound; + }; + + this.destroySound = function(sID, _bFromSound) { + // explicitly destroy a sound before normal page unload, etc. + if (!_idCheck(sID)) { + return false; + } + var oS = _s.sounds[sID], i; + oS._iO = {}; // Disable all callbacks while the sound is being destroyed + oS.stop(); + oS.unload(); + for (i = 0; i < _s.soundIDs.length; i++) { + if (_s.soundIDs[i] === sID) { + _s.soundIDs.splice(i, 1); + break; + } + } + if (!_bFromSound) { + // ignore if being called from SMSound instance + oS.destruct(true); + } + oS = null; + delete _s.sounds[sID]; + return true; + }; + + this.load = function(sID, oOptions) { + if (!_idCheck(sID)) { + return false; + } + return _s.sounds[sID].load(oOptions); + }; + + this.unload = function(sID) { + if (!_idCheck(sID)) { + return false; + } + return _s.sounds[sID].unload(); + }; + + this.play = function(sID, oOptions) { + var fN = 'soundManager.play(): '; + if (!_didInit || !_s.supported()) { + _complain(fN + _str(!_didInit?'notReady':'notOK')); + return false; + } + if (!_idCheck(sID)) { + if (!(oOptions instanceof Object)) { + oOptions = { + url: oOptions + }; // overloading use case: play('mySound','/path/to/some.mp3'); + } + if (oOptions && oOptions.url) { + // overloading use case, create+play: .play('someID',{url:'/path/to.mp3'}); + _s._wD(fN + 'attempting to create "' + sID + '"', 1); + oOptions.id = sID; + return _s.createSound(oOptions).play(); + } else { + return false; + } + } + return _s.sounds[sID].play(oOptions); + }; + + this.start = this.play; // just for convenience + + this.setPosition = function(sID, nMsecOffset) { + if (!_idCheck(sID)) { + return false; + } + return _s.sounds[sID].setPosition(nMsecOffset); + }; + + this.stop = function(sID) { + if (!_idCheck(sID)) { + return false; + } + _s._wD('soundManager.stop(' + sID + ')', 1); + return _s.sounds[sID].stop(); + }; + + this.stopAll = function() { + _s._wD('soundManager.stopAll()', 1); + for (var oSound in _s.sounds) { + if (_s.sounds[oSound] instanceof SMSound) { + _s.sounds[oSound].stop(); // apply only to sound objects + } + } + }; + + this.pause = function(sID) { + if (!_idCheck(sID)) { + return false; + } + return _s.sounds[sID].pause(); + }; + + this.pauseAll = function() { + for (var i = _s.soundIDs.length; i--;) { + _s.sounds[_s.soundIDs[i]].pause(); + } + }; + + this.resume = function(sID) { + if (!_idCheck(sID)) { + return false; + } + return _s.sounds[sID].resume(); + }; + + this.resumeAll = function() { + for (var i = _s.soundIDs.length; i--;) { + _s.sounds[_s.soundIDs[i]].resume(); + } + }; + + this.togglePause = function(sID) { + if (!_idCheck(sID)) { + return false; + } + return _s.sounds[sID].togglePause(); + }; + + this.setPan = function(sID, nPan) { + if (!_idCheck(sID)) { + return false; + } + return _s.sounds[sID].setPan(nPan); + }; + + this.setVolume = function(sID, nVol) { + if (!_idCheck(sID)) { + return false; + } + return _s.sounds[sID].setVolume(nVol); + }; + + this.mute = function(sID) { + var fN = 'soundManager.mute(): ', + i = 0; + if (typeof sID !== 'string') { + sID = null; + } + if (!sID) { + _s._wD(fN + 'Muting all sounds'); + for (i = _s.soundIDs.length; i--;) { + _s.sounds[_s.soundIDs[i]].mute(); + } + _s.muted = true; + } else { + if (!_idCheck(sID)) { + return false; + } + _s._wD(fN + 'Muting "' + sID + '"'); + return _s.sounds[sID].mute(); + } + return true; + }; + + this.muteAll = function() { + _s.mute(); + }; + + this.unmute = function(sID) { + var fN = 'soundManager.unmute(): ', i; + if (typeof sID !== 'string') { + sID = null; + } + if (!sID) { + _s._wD(fN + 'Unmuting all sounds'); + for (i = _s.soundIDs.length; i--;) { + _s.sounds[_s.soundIDs[i]].unmute(); + } + _s.muted = false; + } else { + if (!_idCheck(sID)) { + return false; + } + _s._wD(fN + 'Unmuting "' + sID + '"'); + return _s.sounds[sID].unmute(); + } + return true; + }; + + this.unmuteAll = function() { + _s.unmute(); + }; + + this.toggleMute = function(sID) { + if (!_idCheck(sID)) { + return false; + } + return _s.sounds[sID].toggleMute(); + }; + + this.getMemoryUse = function() { + if (_fV === 8) { + return 0; + } + if (_s.o) { + return parseInt(_s.o._getMemoryUse(), 10); + } + }; + + this.disable = function(bNoDisable) { + // destroy all functions + if (typeof bNoDisable === 'undefined') { + bNoDisable = false; + } + if (_disabled) { + return false; + } + _disabled = true; + _wDS('shutdown', 1); + for (var i = _s.soundIDs.length; i--;) { + _disableObject(_s.sounds[_s.soundIDs[i]]); + } + _initComplete(bNoDisable); // fire "complete", despite fail + _removeEvt(_win, 'load', _initUserOnload); + return true; + }; + + this.canPlayMIME = function(sMIME) { + var result; + if (_s.hasHTML5) { + result = _html5CanPlay({type:sMIME}); + } + if (!_needsFlash || result) { + // no flash, or OK + return result; + } else { + return (sMIME?(sMIME.match(_s.mimePattern)?true:false):null); + } + }; + + this.canPlayURL = function(sURL) { + var result; + if (_s.hasHTML5) { + result = _html5CanPlay(sURL); + } + if (!_needsFlash || result) { + // no flash, or OK + return result; + } else { + return (sURL?(sURL.match(_s.filePattern)?true:false):null); + } + }; + + this.canPlayLink = function(oLink) { + if (typeof oLink.type !== 'undefined' && oLink.type) { + if (_s.canPlayMIME(oLink.type)) { + return true; + } + } + return _s.canPlayURL(oLink.href); + }; + + this.getSoundById = function(sID, suppressDebug) { + if (!sID) { + throw new Error('SoundManager.getSoundById(): sID is null/undefined'); + } + var result = _s.sounds[sID]; + if (!result && !suppressDebug) { + _s._wD('"' + sID + '" is an invalid sound ID.', 2); + } + return result; + }; + + this.onready = function(oMethod, oScope) { + if (oMethod && oMethod instanceof Function) { + if (_didInit) { + _wDS('queue'); + } + if (!oScope) { + oScope = _win; + } + _addOnReady(oMethod, oScope); + _processOnReady(); + return true; + } else { + throw _str('needFunction'); + } + }; + + this.getMoviePercent = function() { + return (_s.o && typeof _s.o.PercentLoaded !== 'undefined'?_s.o.PercentLoaded():null); + }; + + this._writeDebug = function(sText, sType, bTimestamp) { + // If the debug log callback is set, always call it, regardless of debugMode + if (_s.ondebuglog) { + _s.ondebuglog(sText, sType, bTimestamp); + } + // pseudo-private console.log()-style output + // + var sDID = 'soundmanager-debug', o, oItem, sMethod; + if (!_s.debugMode) { + return false; + } + if (typeof bTimestamp !== 'undefined' && bTimestamp) { + sText = sText + ' | ' + new Date().getTime(); + } + if (_hasConsole && _s.useConsole) { + sMethod = _debugLevels[sType]; + if (typeof console[sMethod] !== 'undefined') { + console[sMethod](sText); + } else { + console.log(sText); + } + if (_s.useConsoleOnly) { + return true; + } + } + try { + o = _id(sDID); + if (!o) { + return false; + } + oItem = _doc.createElement('div'); + if (++_wdCount % 2 === 0) { + oItem.className = 'sm2-alt'; + } + if (typeof sType === 'undefined') { + sType = 0; + } else { + sType = parseInt(sType, 10); + } + oItem.appendChild(_doc.createTextNode(sText)); + if (sType) { + if (sType >= 2) { + oItem.style.fontWeight = 'bold'; + } + if (sType === 3) { + oItem.style.color = '#ff3333'; + } + } + // o.appendChild(oItem); // top-to-bottom + o.insertBefore(oItem, o.firstChild); // bottom-to-top + } catch(e) { + // oh well + } + o = null; + // + return true; + }; + this._wD = this._writeDebug; // alias + + this._debug = function() { + // + _wDS('currentObj', 1); + for (var i = 0, j = _s.soundIDs.length; i < j; i++) { + _s.sounds[_s.soundIDs[i]]._debug(); + } + // + }; + + this.reboot = function() { + // attempt to reset and init SM2 + _s._wD('soundManager.reboot()'); + if (_s.soundIDs.length) { + _s._wD('Destroying ' + _s.soundIDs.length + ' SMSound objects...'); + } + for (var i = _s.soundIDs.length; i--;) { + _s.sounds[_s.soundIDs[i]].destruct(); + } + // trash ze flash + try { + if (_isIE) { + _oRemovedHTML = _s.o.innerHTML; + } + _oRemoved = _s.o.parentNode.removeChild(_s.o); + _s._wD('Flash movie removed.'); + } catch(e) { + // uh-oh. + _wDS('badRemove', 2); + } + // actually, force recreate of movie. + _oRemovedHTML = _oRemoved = null; + _s.enabled = _didInit = _waitingForEI = _initPending = _didAppend = _appendSuccess = _disabled = _s.swfLoaded = false; + _s.soundIDs = _s.sounds = []; + _s.o = null; + for (i = _onready.length; i--;) { + _onready[i].fired = false; + } + _s._wD(_sm + ': Rebooting...'); + _win.setTimeout(function() { + _s.beginDelayedInit(); + }, 20); + }; + + this.destruct = function() { + _s._wD('soundManager.destruct()'); + _s.disable(true); + }; + + this.beginDelayedInit = function() { + // _s._wD('soundManager.beginDelayedInit()'); + _windowLoaded = true; + _dcLoaded(); + setTimeout(_beginInit, 20); + _delayWaitForEI(); + }; + + // --- SMSound (sound object) instance --- + + SMSound = function(oOptions) { + var _t = this, _resetProperties, _add_html5_events, _stop_html5_timer, _start_html5_timer, _get_html5_duration, _a; + this.sID = oOptions.id; + this.url = oOptions.url; + this.options = _mixin(oOptions); + this.instanceOptions = this.options; // per-play-instance-specific options + this._iO = this.instanceOptions; // short alias + // assign property defaults + this.pan = this.options.pan; + this.volume = this.options.volume; + this._lastURL = null; + this.isHTML5 = false; + + // --- public methods --- + + this.id3 = {}; + + this._debug = function() { + // + // pseudo-private console.log()-style output + if (_s.debugMode) { + var stuff = null, msg = [], sF, sfBracket, maxLength = 64; + for (stuff in _t.options) { + if (_t.options[stuff] !== null) { + if (_t.options[stuff] instanceof Function) { + // handle functions specially + sF = _t.options[stuff].toString(); + sF = sF.replace(/\s\s+/g, ' '); // normalize spaces + sfBracket = sF.indexOf('{'); + msg.push(' ' + stuff + ': {' + sF.substr(sfBracket + 1, (Math.min(Math.max(sF.indexOf('\n') - 1, maxLength), maxLength))).replace(/\n/g, '') + '... }'); + } else { + msg.push(' ' + stuff + ': ' + _t.options[stuff]); + } + } + } + _s._wD('SMSound() merged options: {\n' + msg.join(', \n') + '\n}'); + } + // + }; + + this._debug(); + + this.load = function(oOptions) { + var oS = null; + if (typeof oOptions !== 'undefined') { + _t._iO = _mixin(oOptions); + _t.instanceOptions = _t._iO; + } else { + oOptions = _t.options; + _t._iO = oOptions; + _t.instanceOptions = _t._iO; + if (_t._lastURL && _t._lastURL !== _t.url) { + _wDS('manURL'); + _t._iO.url = _t.url; + _t.url = null; + } + } + _s._wD('soundManager.load(): ' + _t._iO.url, 1); + if (_t._iO.url === _t.url && _t.readyState !== 0 && _t.readyState !== 2) { + _wDS('onURL', 1); + return _t; + } + _t._lastURL = _t.url; + _t.loaded = false; + _t.readyState = 1; + _t.playState = 0; + if (_html5OK(_t._iO)) { + _s._wD('HTML 5 load: '+_t._iO.url); + oS = _t._setup_html5(_t._iO); + oS.load(); + if (_t._iO.autoPlay) { + _t.play(); + } + } else { + try { + _t.isHTML5 = false; + _t._iO = _policyFix(_loopFix(_t._iO)); + if (_fV === 8) { + _s.o._load(_t.sID, _t._iO.url, _t._iO.stream, _t._iO.autoPlay, (_t._iO.whileloading?1:0), _t._iO.loops||1, _t._iO.usePolicyFile); + } else { + _s.o._load(_t.sID, _t._iO.url, _t._iO.stream?true:false, _t._iO.autoPlay?true:false, _t._iO.loops||1, _t._iO.autoLoad?true:false, _t._iO.usePolicyFile); + } + } catch(e) { + _wDS('smError', 2); + _debugTS('onload', false); + _die(); + } + } + return _t; + }; + + this.unload = function() { + // Flash 8/AS2 can't "close" a stream - fake it by loading an empty MP3 + // Flash 9/AS3: Close stream, preventing further load + if (_t.readyState !== 0) { + _s._wD('SMSound.unload(): "' + _t.sID + '"'); + if (!_t.isHTML5) { + if (_fV === 8) { + _s.o._unload(_t.sID, _s.nullURL); + } else { + _s.o._unload(_t.sID); + } + } else { + _stop_html5_timer(); + if (_a) { + // abort()-style method here, stop loading? (doesn't exist?) + _a.pause(); + _a.src = _s.nullURL; // needed? does nulling object work? any better way to cancel/unload/abort? + _a.load(); + _t._audio = null; + _a = null; + // delete _t._audio; + } + } + // reset load/status flags + _resetProperties(); + } + return _t; + }; + + this.destruct = function(_bFromSM) { + _s._wD('SMSound.destruct(): "' + _t.sID + '"'); + if (!_t.isHTML5) { + // kill sound within Flash + // Disable the onfailure handler + _t._iO.onfailure = null; + _s.o._destroySound(_t.sID); + } else { + _stop_html5_timer(); + if (_a) { + _a.pause(); + _a.src = 'about:blank'; + _a.load(); + _t._audio = null; + _a = null; + // delete _t._audio; + } + } + if (!_bFromSM) { + _s.destroySound(_t.sID, true); // ensure deletion from controller + } + }; + + this.play = function(oOptions, _updatePlayState) { + var fN = 'SMSound.play(): ', allowMulti; + _updatePlayState = (typeof _updatePlayState === 'undefined' ? true : _updatePlayState); + if (!oOptions) { + oOptions = {}; + } + _t._iO = _mixin(oOptions, _t._iO); + _t._iO = _mixin(_t._iO, _t.options); + _t.instanceOptions = _t._iO; + if (_t._iO.serverURL) { + if (!_t.connected) { + if (!_t.getAutoPlay()) { + _s._wD(fN+' Netstream not connected yet - setting autoPlay'); + _t.setAutoPlay(true); + } + return _t; + } + } + if (_html5OK(_t._iO)) { + _t._setup_html5(_t._iO); + _start_html5_timer(); + } + // KJV paused sounds have playState 1. We want these sounds to play. + if (_t.playState === 1 && !_t.paused) { + allowMulti = _t._iO.multiShot; + if (!allowMulti) { + _s._wD(fN + '"' + _t.sID + '" already playing (one-shot)', 1); + return _t; + } else { + _s._wD(fN + '"' + _t.sID + '" already playing (multi-shot)', 1); + if (_t.isHTML5) { + // TODO: BUG? + _t.setPosition(_t._iO.position); + } + } + } + if (!_t.loaded) { + if (_t.readyState === 0) { + _s._wD(fN + 'Attempting to load "' + _t.sID + '"', 1); + // try to get this sound playing ASAP + if (!_t.isHTML5) { + if (!_t._iO.serverURL) { + _t._iO.autoPlay = true; + _t.load(_t._iO); + } + } else { + _t.load(_t._iO); + _t.readyState = 1; + } + } else if (_t.readyState === 2) { + _s._wD(fN + 'Could not load "' + _t.sID + '" - exiting', 2); + return _t; + } else { + _s._wD(fN + '"' + _t.sID + '" is loading - attempting to play..', 1); + } + } else { + _s._wD(fN + '"' + _t.sID + '"'); + } + // Streams will pause when their buffer is full if they are not auto-playing. + // In this case paused is true, but the song hasn't started playing yet. If + // we just call resume() the onplay() callback will never be called. + + // Also, if we just call resume() in this case and the sound has been muted + // (volume is 0), it will never have its volume set so sound will be heard + // when it shouldn't. + if (_t.paused && _t.position && _t.position > 0) { // https://gist.github.com/37b17df75cc4d7a90bf6 + _s._wD(fN + '"' + _t.sID + '" is resuming from paused state',1); + _t.resume(); + } else { + _s._wD(fN+'"'+ _t.sID+'" is starting to play'); + _t.playState = 1; + _t.paused = false; + if (!_t.instanceCount || _t._iO.multiShotEvents || (_fV > 8 && !_t.isHTML5 && !_t.getAutoPlay())) { + _t.instanceCount++; + } + _t.position = (typeof _t._iO.position !== 'undefined' && !isNaN(_t._iO.position)?_t._iO.position:0); + _t._iO = _policyFix(_loopFix(_t._iO)); + if (_t._iO.onplay && _updatePlayState) { + _t._iO.onplay.apply(_t); + } + _t.setVolume(_t._iO.volume, true); + _t.setPan(_t._iO.pan, true); + if (!_t.isHTML5) { + _s.o._start(_t.sID, _t._iO.loops || 1, (_fV === 9?_t.position:_t.position / 1000)); + } else { + _start_html5_timer(); + _t._setup_html5().play(); + } + } + return _t; + }; + + this.start = this.play; // just for convenience + + this.stop = function(bAll) { + if (_t.playState === 1) { + _t._onbufferchange(0); + _t.resetOnPosition(0); + if (!_t.isHTML5) { + _t.playState = 0; + } + _t.paused = false; + if (_t._iO.onstop) { + _t._iO.onstop.apply(_t); + } + if (!_t.isHTML5) { + _s.o._stop(_t.sID, bAll); + // hack for netStream: just unload + if (_t._iO.serverURL) { + _t.unload(); + } + } else { + if (_a) { + _t.setPosition(0); // act like Flash, though + _a.pause(); // html5 has no stop() + _t.playState = 0; + _t._onTimer(); // and update UI + _stop_html5_timer(); + _t.unload(); + } + } + _t.instanceCount = 0; + _t._iO = {}; + } + return _t; + }; + + this.setAutoPlay = function(autoPlay) { + _s._wD('sound '+_t.sID+' turned autoplay ' + (autoPlay ? 'on' : 'off')); + _t._iO.autoPlay = autoPlay; + _s.o._setAutoPlay(_t.sID, autoPlay); + if (autoPlay) { + // KJV Only increment the instanceCount if the sound isn't loaded (TODO: verify RTMP) + if (!_t.instanceCount && _t.readyState === 1) { + _t.instanceCount++; + _s._wD('sound '+_t.sID+' incremented instance count to '+_t.instanceCount); + } + } + }; + + this.getAutoPlay = function() { + return _t._iO.autoPlay; + }; + + this.setPosition = function(nMsecOffset, bNoDebug) { + if (nMsecOffset === undefined) { + nMsecOffset = 0; + } + // KJV Use the duration from the instance options, if we don't have a track duration yet. + // Auto-loading streams with a starting position in their options will start playing + // as soon as they connect. In the start() call we set the position on the stream, + // but because the stream hasn't played _t.duration won't have been set (that is + // done in whileloading()). So if we don't have a duration yet, use the duration + // from the instance options, if available. + var position, offset = (_t.isHTML5 ? Math.max(nMsecOffset,0) : Math.min(_t.duration || _t._iO.duration, Math.max(nMsecOffset, 0))); // position >= 0 and <= current available (loaded) duration + _t.position = offset; + _t.resetOnPosition(_t.position); + if (!_t.isHTML5) { + position = _fV === 9 ? _t.position : _t.position / 1000; + // KJV We want our sounds to play on seek. A progressive download that + // is loaded has paused = false so resume() does nothing and the sound + // doesn't play. Handle that case here. + if (_t.playState === 0) { + _t.play({ position: position }); + } else { + _s.o._setPosition(_t.sID, position, (_t.paused || !_t.playState)); // if paused or not playing, will not resume (by playing) + // if (_t.paused) { + // _t.resume(); + // } + } + } else if (_a) { + _s._wD('setPosition(): setting position to '+(_t.position / 1000)); + if (_t.playState) { + // DOM/JS errors/exceptions to watch out for: + // if seek is beyond (loaded?) position, "DOM exception 11" + // "INDEX_SIZE_ERR": DOM exception 1 + try { + _a.currentTime = _t.position / 1000; + } catch(e) { + _s._wD('setPosition('+_t.position+'): WARN: Caught exception: '+e.message, 2); + } + } else { + _s._wD('HTML 5 warning: cannot set position while playState == 0 (not playing)',2); + } + if (_t.paused) { // if paused, refresh UI right away + _t._onTimer(true); // force update + if (_t._iO.useMovieStar) { + _t.resume(); + } + } + } + return _t; + }; + + this.pause = function(bCallFlash) { + if (_t.paused || (_t.playState === 0 && _t.readyState !== 1)) { + return _t; + } + _s._wD('SMSound.pause()'); + _t.paused = true; + if (!_t.isHTML5) { + if (bCallFlash || bCallFlash === undefined) { + _s.o._pause(_t.sID); + } + } else { + _t._setup_html5().pause(); + _stop_html5_timer(); + } + if (_t._iO.onpause) { + _t._iO.onpause.apply(_t); + } + return _t; + }; + + this.resume = function() { + // When auto-loaded streams pause on buffer full they have a playState of 0. + // We need to make sure that the playState is set to 1 when these streams "resume". + if (!_t.paused) { + return _t; + } + _s._wD('SMSound.resume()'); + _t.paused = false; + _t.playState = 1; // TODO: verify that this is needed. + if (!_t.isHTML5) { + _s.o._pause(_t.sID); // flash method is toggle-based (pause/resume) + } else { + _t._setup_html5().play(); + _start_html5_timer(); + } + if (_t._iO.onresume) { + _t._iO.onresume.apply(_t); + } + return _t; + }; + + this.togglePause = function() { + _s._wD('SMSound.togglePause()'); + if (_t.playState === 0) { + _t.play({ + position: (_fV === 9 && !_t.isHTML5 ? _t.position:_t.position / 1000) + }); + return _t; + } + if (_t.paused) { + _t.resume(); + } else { + _t.pause(); + } + return _t; + }; + + this.setPan = function(nPan, bInstanceOnly) { + if (typeof nPan === 'undefined') { + nPan = 0; + } + if (typeof bInstanceOnly === 'undefined') { + bInstanceOnly = false; + } + if (!_t.isHTML5) { + _s.o._setPan(_t.sID, nPan); + } // else { no HTML5 pan? } + _t._iO.pan = nPan; + if (!bInstanceOnly) { + _t.pan = nPan; + } + return _t; + }; + + this.setVolume = function(nVol, bInstanceOnly) { + if (typeof nVol === 'undefined') { + nVol = 100; + } + if (typeof bInstanceOnly === 'undefined') { + bInstanceOnly = false; + } + if (!_t.isHTML5) { + _s.o._setVolume(_t.sID, (_s.muted && !_t.muted) || _t.muted?0:nVol); + } else if (_a) { + _a.volume = nVol/100; + } + _t._iO.volume = nVol; + if (!bInstanceOnly) { + _t.volume = nVol; + } + return _t; + }; + + this.mute = function() { + _t.muted = true; + if (!_t.isHTML5) { + _s.o._setVolume(_t.sID, 0); + } else if (_a) { + _a.muted = true; + } + return _t; + }; + + this.unmute = function() { + _t.muted = false; + var hasIO = typeof _t._iO.volume !== 'undefined'; + if (!_t.isHTML5) { + _s.o._setVolume(_t.sID, hasIO?_t._iO.volume:_t.options.volume); + } else if (_a) { + _a.muted = false; + } + return _t; + }; + + this.toggleMute = function() { + return (_t.muted?_t.unmute():_t.mute()); + }; + + this.onposition = function(nPosition, oMethod, oScope) { + // TODO: allow for ranges, too? eg. (nPosition instanceof Array) + _t._onPositionItems.push({ + position: nPosition, + method: oMethod, + scope: (typeof oScope !== 'undefined'?oScope:_t), + fired: false + }); + return _t; + }; + + this.processOnPosition = function() { + var i, item, j = _t._onPositionItems.length; + if (!j || !_t.playState || _t._onPositionFired >= j) { + return false; + } + for (i=j; i--;) { + item = _t._onPositionItems[i]; + if (!item.fired && _t.position >= item.position) { + item.method.apply(item.scope,[item.position]); + item.fired = true; + _s._onPositionFired++; + } + } + return true; + }; + + this.resetOnPosition = function(nPosition) { + // reset "fired" for items interested in this position + var i, item, j = _t._onPositionItems.length; + if (!j) { + return false; + } + for (i=j; i--;) { + item = _t._onPositionItems[i]; + if (item.fired && nPosition <= item.position) { + item.fired = false; + _s._onPositionFired--; + } + } + return true; + }; + + // pseudo-private soundManager reference + + this._onTimer = function(bForce) { + // HTML 5-only _whileplaying() etc. + var time, x = {}; + if (_t._hasTimer || bForce) { + if (_a && (bForce || ((_t.playState > 0 || _t.readyState === 1) && !_t.paused))) { // TODO: May not need to track readyState (1 = loading) + _t.duration = _get_html5_duration(); + _t.durationEstimate = _t.duration; + time = _a.currentTime?_a.currentTime*1000:0; + _t._whileplaying(time,x,x,x,x); + return true; + } else { + _s._wD('_onTimer: Warn for "'+_t.sID+'": '+(!_a?'Could not find element. ':'')+(_t.playState === 0?'playState bad, 0?':'playState = '+_t.playState+', OK')); + return false; + } + } + }; + + // --- private internals --- + + _get_html5_duration = function() { + var d = (_a?_a.duration*1000:undefined); + return (d && !isNaN(d)?d:null); + }; + + _start_html5_timer = function() { + if (_t.isHTML5) { + _startTimer(_t); + } + }; + + _stop_html5_timer = function() { + if (_t.isHTML5) { + _stopTimer(_t); + } + }; + + _resetProperties = function(bLoaded) { + _t._onPositionItems = []; + _t._onPositionFired = 0; + _t._hasTimer = null; + _t._added_events = null; + _t._audio = null; + _a = null; + _t.bytesLoaded = null; + _t.bytesTotal = null; + _t.position = null; + _t.duration = (_t._iO && _t._iO.duration?_t._iO.duration:null); + _t.durationEstimate = null; + _t.failures = 0; + _t.loaded = false; + _t.playState = 0; + _t.paused = false; + _t.readyState = 0; // 0 = uninitialised, 1 = loading, 2 = failed/error, 3 = loaded/success + _t.muted = false; + _t.didBeforeFinish = false; + _t.didJustBeforeFinish = false; + _t.isBuffering = false; + _t.instanceOptions = {}; + _t.instanceCount = 0; + _t.peakData = { + left: 0, + right: 0 + }; + _t.waveformData = { + left: [], + right: [] + }; + _t.eqData = []; // legacy: 1D array + _t.eqData.left = []; + _t.eqData.right = []; + }; + + _resetProperties(); + + // pseudo-private methods used by soundManager + + this._setup_html5 = function(oOptions) { + var _iO = _mixin(_t._iO, oOptions); + if (_a) { + if (_t.url !== _iO.url) { + _s._wD('setting new URL on existing object: '+_iO.url); + _a.src = _iO.url; + } + } else { + _s._wD('creating HTML 5 audio element with URL: '+_iO.url); + _t._audio = new Audio(_iO.url); + _a = _t._audio; + _t.isHTML5 = true; + _add_html5_events(); + } + _a.loop = (_iO.loops>1?'loop':''); + return _t._audio; + }; + + // related private methods + + _add_html5_events = function() { + if (_t._added_events) { + return false; + } + _t._added_events = true; + + function _add(oEvt, oFn, bCapture) { + return (_a ? _a.addEventListener(oEvt, oFn, bCapture||false) : null); + } + + _add('load', function(e) { + _s._wD('HTML5::load: '+_t.sID); + if (_a) { + _t._onbufferchange(0); + _t._whileloading(_t.bytesTotal, _t.bytesTotal, _get_html5_duration()); + _t._onload(true); + } + }, false); + + _add('canplay', function(e) { + _s._wD('HTML5::canplay: '+_t.sID); + // enough has loaded to play + _t._onbufferchange(0); + },false); + + _add('waiting', function(e) { + _s._wD('HTML5::waiting: '+_t.sID); + // playback faster than download rate, etc. + _t._onbufferchange(1); + },false); + + _add('progress', function(e) { // not supported everywhere yet.. + _s._wD('HTML5::progress: '+_t.sID+': loaded/total: '+(e.loaded||0)+'/'+(e.total||1)); + if (!_t.loaded && _a) { + _t._onbufferchange(0); // if progress, likely not buffering + _t._whileloading(e.loaded||0, e.total||1, _get_html5_duration()); + } + }, false); + + _add('error', function(e) { + if (_a) { + _s._wD('HTML5::error: '+_a.error.code); + // call load with error state? + _t._onload(false); + } + }, false); + + _add('loadstart', function(e) { + _s._wD('HTML5::loadstart: '+_t.sID); + // assume buffering at first + _t._onbufferchange(1); + }, false); + + _add('play', function(e) { + _s._wD('HTML5::play: '+_t.sID); + // once play starts, no buffering + _t._onbufferchange(0); + }, false); + + // TODO: verify if this is actually implemented anywhere yet. + _add('playing', function(e) { + _s._wD('HTML5::playing: '+_t.sID); + // once play starts, no buffering + _t._onbufferchange(0); + }, false); + + _add('timeupdate', function(e) { + _t._onTimer(); + }, false); + + // avoid stupid premature event-firing bug in Safari(?) + setTimeout(function(){ + if (_t && _a) { + _add('ended',function(e) { + _s._wD('HTML5::ended: '+_t.sID); + _t._onfinish(); + }, false); + } + }, 250); + return true; + }; + + // --- "private" methods called by Flash --- + + this._whileloading = function(nBytesLoaded, nBytesTotal, nDuration, nBufferLength) { + _t.bytesLoaded = nBytesLoaded; + _t.bytesTotal = nBytesTotal; + _t.duration = Math.floor(nDuration); + _t.bufferLength = nBufferLength; + if (!_t._iO.isMovieStar) { + if (_t._iO.duration) { + // use options, if specified and larger + _t.durationEstimate = (_t.duration > _t._iO.duration) ? _t.duration : _t._iO.duration; + } else { + _t.durationEstimate = parseInt((_t.bytesTotal / _t.bytesLoaded) * _t.duration, 10); + } + if (_t.durationEstimate === undefined) { + _t.durationEstimate = _t.duration; + } + _t.bufferLength = nBufferLength; + if (_t.readyState !== 3 && _t._iO.whileloading) { + _t._iO.whileloading.apply(_t); + } + } else { + _t.durationEstimate = _t.duration; + if (_t.readyState !== 3 && _t._iO.whileloading) { + _t._iO.whileloading.apply(_t); + } + } + }; + + this._onid3 = function(oID3PropNames, oID3Data) { + // oID3PropNames: string array (names) + // ID3Data: string array (data) + _s._wD('SMSound._onid3(): "' + this.sID + '" ID3 data received.'); + var oData = [], i, j; + for (i = 0, j = oID3PropNames.length; i < j; i++) { + oData[oID3PropNames[i]] = oID3Data[i]; + } + _t.id3 = _mixin(_t.id3, oData); + if (_t._iO.onid3) { + _t._iO.onid3.apply(_t); + } + }; + + this._whileplaying = function(nPosition, oPeakData, oWaveformDataLeft, oWaveformDataRight, oEQData) { + if (isNaN(nPosition) || nPosition === null) { + return false; // Flash may return NaN at times + } + if (_t.playState === 0 && nPosition > 0) { + // invalid position edge case for end/stop + nPosition = 0; + } + _t.position = nPosition; + _t.processOnPosition(); + if (_fV > 8 && !_t.isHTML5) { + if (_t._iO.usePeakData && typeof oPeakData !== 'undefined' && oPeakData) { + _t.peakData = { + left: oPeakData.leftPeak, + right: oPeakData.rightPeak + }; + } + if (_t._iO.useWaveformData && typeof oWaveformDataLeft !== 'undefined' && oWaveformDataLeft) { + _t.waveformData = { + left: oWaveformDataLeft.split(','), + right: oWaveformDataRight.split(',') + }; + } + if (_t._iO.useEQData) { + if (typeof oEQData !== 'undefined' && oEQData && oEQData.leftEQ) { + var eqLeft = oEQData.leftEQ.split(','); + _t.eqData = eqLeft; + _t.eqData.left = eqLeft; + if (typeof oEQData.rightEQ !== 'undefined' && oEQData.rightEQ) { + _t.eqData.right = oEQData.rightEQ.split(','); + } + } + } + } + if (_t.playState === 1) { + // special case/hack: ensure buffering is false if loading from cache (and not yet started) + if (!_t.isHTML5 && _s.flashVersion === 8 && !_t.position && _t.isBuffering) { + _t._onbufferchange(0); + } + if (_t._iO.whileplaying) { + _t._iO.whileplaying.apply(_t); // flash may call after actual finish + } + if ((_t.loaded || (!_t.loaded && _t._iO.isMovieStar)) && _t._iO.onbeforefinish && _t._iO.onbeforefinishtime && !_t.didBeforeFinish && _t.duration - _t.position <= _t._iO.onbeforefinishtime) { + _t._onbeforefinish(); + } + } + return true; + }; + + this._onconnect = function(bSuccess) { + var fN = 'SMSound._onconnect(): '; + bSuccess = (bSuccess === 1); + _s._wD(fN+'"'+_t.sID+'"'+(bSuccess?' connected.':' failed to connect? - '+_t.url), (bSuccess?1:2)); + _t.connected = bSuccess; + if (bSuccess) { + _t.failures = 0; + if (_t._iO.onconnect) { + _t._iO.onconnect.apply(_t,[bSuccess]); + } + // don't play if the sound is being destroyed + if (_idCheck(_t.sID) && (_t.options.autoLoad || _t.getAutoPlay())) { + _t.play(undefined, _t.getAutoPlay()); // only update the play state if auto playing + } + } + }; + + this._onload = function(nSuccess) { + var fN = 'SMSound._onload(): ', loadOK = (nSuccess?true:false); + _s._wD(fN + '"' + _t.sID + '"' + (loadOK?' loaded.':' failed to load? - ' + _t.url), (loadOK?1:2)); + // + if (!loadOK && !_t.isHTML5) { + if (_s.sandbox.noRemote === true) { + _s._wD(fN + _str('noNet'), 1); + } + if (_s.sandbox.noLocal === true) { + _s._wD(fN + _str('noLocal'), 1); + } + } + // + _t.loaded = loadOK; + _t.readyState = loadOK?3:2; + _t._onbufferchange(0); + if (_t._iO.onload) { + _t._iO.onload.apply(_t, [loadOK]); + } + return true; + }; + + // fire onfailure() only once at most + // at this point we just recreate failed sounds rather than trying to reconnect. + this._onfailure = function(msg, level, code) { + _t.failures++; + _s._wD('SMSound._onfailure(): "'+_t.sID+'" count '+_t.failures); + if (_t._iO.onfailure && _t.failures === 1) { + _t._iO.onfailure(_t, msg, level, code); + } else { + _s._wD('SMSound._onfailure(): ignoring'); + } + }; + + this._onbeforefinish = function() { + if (!_t.didBeforeFinish) { + _t.didBeforeFinish = true; + if (_t._iO.onbeforefinish) { + _s._wD('SMSound._onbeforefinish(): "' + _t.sID + '"'); + _t._iO.onbeforefinish.apply(_t); + } + } + }; + + this._onjustbeforefinish = function(msOffset) { + if (!_t.didJustBeforeFinish) { + _t.didJustBeforeFinish = true; + if (_t._iO.onjustbeforefinish) { + _s._wD('SMSound._onjustbeforefinish(): "' + _t.sID + '"'); + _t._iO.onjustbeforefinish.apply(_t); + } + } + }; + + // KJV - connect & play time callback from Flash + this._onstats = function(stats) { + if (_t._iO.onstats) { + _t._iO.onstats(_t, stats); + } + }; + + this._onfinish = function() { + // _s._wD('SMSound._onfinish(): "' + _t.sID + '" got instanceCount '+_t.instanceCount); + _t._onbufferchange(0); + _t.resetOnPosition(0); + if (_t._iO.onbeforefinishcomplete) { + _t._iO.onbeforefinishcomplete.apply(_t); + } + // reset some state items + _t.didBeforeFinish = false; + _t.didJustBeforeFinish = false; + if (_t.instanceCount) { + _t.instanceCount--; + if (!_t.instanceCount) { + // reset instance options + _t.playState = 0; + _t.paused = false; + _t.instanceCount = 0; + _t.instanceOptions = {}; + _stop_html5_timer(); + } + if (!_t.instanceCount || _t._iO.multiShotEvents) { + // fire onfinish for last, or every instance + if (_t._iO.onfinish) { + _s._wD('SMSound._onfinish(): "' + _t.sID + '"'); + _t._iO.onfinish.apply(_t); + } + } + } + }; + + this._onbufferchange = function(nIsBuffering) { + var fN = 'SMSound._onbufferchange()'; + if (_t.playState === 0) { + // ignore if not playing + return false; + } + if ((nIsBuffering && _t.isBuffering) || (!nIsBuffering && !_t.isBuffering)) { + return false; + } + _t.isBuffering = (nIsBuffering === 1); + if (_t._iO.onbufferchange) { + _s._wD(fN + ': ' + nIsBuffering); + _t._iO.onbufferchange.apply(_t); + } + return true; + }; + + this._ondataerror = function(sError) { + // flash 9 wave/eq data handler + if (_t.playState > 0) { // hack: called at start, and end from flash at/after onfinish() + _s._wD('SMSound._ondataerror(): ' + sError); + if (_t._iO.ondataerror) { + _t._iO.ondataerror.apply(_t); + } + } + }; + + }; // SMSound() + + // --- private SM2 internals --- + + _getDocument = function() { + return (_doc.body?_doc.body:(_doc._docElement?_doc.documentElement:_doc.getElementsByTagName('div')[0])); + }; + + _id = function(sID) { + return _doc.getElementById(sID); + }; + + _mixin = function(oMain, oAdd) { + // non-destructive merge + var o1 = {}, i, o2, o; + for (i in oMain) { // clone c1 + if (oMain.hasOwnProperty(i)) { + o1[i] = oMain[i]; + } + } + o2 = (typeof oAdd === 'undefined'?_s.defaultOptions:oAdd); + for (o in o2) { + if (o2.hasOwnProperty(o) && typeof o1[o] === 'undefined') { + o1[o] = o2[o]; + } + } + return o1; + }; + + (function() { + var old = (_win.attachEvent), + evt = { + add: (old?'attachEvent':'addEventListener'), + remove: (old?'detachEvent':'removeEventListener') + }; + + function getArgs(oArgs) { + var args = _slice.call(oArgs), len = args.length; + if (old) { + args[1] = 'on' + args[1]; // prefix + if (len > 3) { + args.pop(); // no capture + } + } else if (len === 3) { + args.push(false); + } + return args; + } + + function apply(args, sType) { + var oFunc = args.shift()[evt[sType]]; + if (old) { + oFunc(args[0], args[1]); + } else { + oFunc.apply(this, args); + } + } + + _addEvt = function() { + apply(getArgs(arguments), 'add'); + }; + + _removeEvt = function() { + apply(getArgs(arguments), 'remove'); + }; + }()); + + _html5OK = function(iO) { + return ((iO.type?_html5CanPlay({type:iO.type}):false)||_html5CanPlay(iO.url)); + }; + + _html5CanPlay = function(sURL) { + // try to find MIME, test and return truthiness + if (!_s.useHTML5Audio || !_s.hasHTML5) { + return false; + } + var result, mime, fileExt, item, aF = _s.audioFormats; + if (!_html5Ext) { + _html5Ext = []; + for (item in aF) { + if (aF.hasOwnProperty(item)) { + _html5Ext.push(item); + if (aF[item].related) { + _html5Ext = _html5Ext.concat(aF[item].related); + } + } + } + _html5Ext = new RegExp('\\.('+_html5Ext.join('|')+')','i'); + } + mime = (typeof sURL.type !== 'undefined'?sURL.type:null); + fileExt = (typeof sURL === 'string'?sURL.toLowerCase().match(_html5Ext):null); // TODO: Strip URL queries, etc. + if (!fileExt || !fileExt.length) { + if (!mime) { + return false; + } + } else { + fileExt = fileExt[0].substr(1); // "mp3", for example + } + if (fileExt && typeof _s.html5[fileExt] !== 'undefined') { + // result known + return _s.html5[fileExt]; + } else { + if (!mime) { + if (fileExt && _s.html5[fileExt]) { + return _s.html5[fileExt]; + } else { + // best-case guess, audio/whatever-dot-filename-format-you're-playing + mime = 'audio/'+fileExt; + } + } + result = _s.html5.canPlayType(mime); + _s.html5[fileExt] = result; + // _s._wD('canPlayType, found result: '+result); + return result; + } + }; + + _testHTML5 = function() { + if (!_s.useHTML5Audio || typeof Audio === 'undefined') { + return false; + } + var a = (typeof Audio !== 'undefined' ? new Audio():null), item, support = {}, aF, i; + function _cp(m) { + var canPlay, i, j, isOK = false; + if (!a || typeof a.canPlayType !== 'function') { + return false; + } + if (m instanceof Array) { + // iterate through all mime types, return any successes + for (i=0, j=m.length; i + notReady: 'Not loaded yet - wait for soundManager.onload()/onready()', + notOK: 'Audio support is not available.', + appXHTML: _sm + '::createMovie(): appendChild/innerHTML set failed. May be app/xhtml+xml DOM-related.', + spcWmode: _sm + '::createMovie(): Removing wmode, preventing win32 below-the-fold SWF loading issue', + swf404: _sm + ': Verify that %s is a valid path.', + tryDebug: 'Try ' + _sm + '.debugFlash = true for more security details (output goes to SWF.)', + checkSWF: 'See SWF output for more debug info.', + localFail: _sm + ': Non-HTTP page (' + _doc.location.protocol + ' URL?) Review Flash player security settings for this special case:\nhttp://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html\nMay need to add/allow path, eg. c:/sm2/ or /users/me/sm2/', + waitFocus: _sm + ': Special case: Waiting for focus-related event..', + waitImpatient: _sm + ': Getting impatient, still waiting for Flash%s...', + waitForever: _sm + ': Waiting indefinitely for Flash (will recover if unblocked)...', + needFunction: _sm + '.onready(): Function object expected', + badID: 'Warning: Sound ID "%s" should be a string, starting with a non-numeric character', + noMS: 'MovieStar mode not enabled. Exiting.', + currentObj: '--- ' + _sm + '._debug(): Current sound objects ---', + waitEI: _sm + '::initMovie(): Waiting for ExternalInterface call from Flash..', + waitOnload: _sm + ': Waiting for window.onload()', + docLoaded: _sm + ': Document already loaded', + onload: _sm + '::initComplete(): calling soundManager.onload()', + onloadOK: _sm + '.onload() complete', + init: '-- ' + _sm + '::init() --', + didInit: _sm + '::init(): Already called?', + flashJS: _sm + ': Attempting to call Flash from JS..', + noPolling: _sm + ': Polling (whileloading()/whileplaying() support) is disabled.', + secNote: 'Flash security note: Network/internet URLs will not load due to security restrictions. Access can be configured via Flash Player Global Security Settings Page: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html', + badRemove: 'Warning: Failed to remove flash movie.', + noPeak: 'Warning: peakData features unsupported for movieStar formats', + shutdown: _sm + '.disable(): Shutting down', + queue: _sm + '.onready(): Queueing handler', + smFail: _sm + ': Failed to initialise.', + smError: 'SMSound.load(): Exception: JS-Flash communication failed, or JS error.', + fbTimeout: 'No flash response, applying .'+_s.swfCSS.swfTimedout+' CSS..', + fbLoaded: 'Flash loaded', + fbHandler: 'soundManager::flashBlockHandler()', + manURL: 'SMSound.load(): Using manually-assigned URL', + onURL: _sm + '.load(): current URL already assigned.', + badFV: 'soundManager.flashVersion must be 8 or 9. "%s" is invalid. Reverting to %s.', + as2loop: 'Note: Setting stream:false so looping can work (flash 8 limitation)', + noNSLoop: 'Note: Looping not implemented for MovieStar formats', + needfl9: 'Note: Switching to flash 9, required for MP4 formats.', + mfTimeout: 'Setting flashLoadTimeout = 0 (infinite) for off-screen, mobile flash case', + mfOn: 'mobileFlash::enabling on-screen flash repositioning', + policy: 'Enabling usePolicyFile for data access' + // + }; + + _id = function(sID) { + return _doc.getElementById(sID); + }; + + _str = function() { // o [,items to replace] + // + var args = _slice.call(arguments), // real array, please + o = args.shift(), // first arg + str = (_strings && _strings[o]?_strings[o]:''), i, j; + if (str && args && args.length) { + for (i = 0, j = args.length; i < j; i++) { + str = str.replace('%s', args[i]); + } + } + return str; + // + }; + + _loopFix = function(sOpt) { + // flash 8 requires stream = false for looping to work + if (_fV === 8 && sOpt.loops > 1 && sOpt.stream) { + _wDS('as2loop'); + sOpt.stream = false; + } + return sOpt; + }; + + _policyFix = function(sOpt, sPre) { + if (sOpt && !sOpt.usePolicyFile && (sOpt.onid3 || sOpt.usePeakData || sOpt.useWaveformData || sOpt.useEQData)) { + _s._wD((sPre?sPre+':':'') + _str('policy')); + sOpt.usePolicyFile = true; + } + return sOpt; + }; + + _complain = function(sMsg) { + if (typeof console !== 'undefined' && typeof console.warn !== 'undefined') { + console.warn(sMsg); + } else { + _s._wD(sMsg); + } + }; + + _doNothing = function() { + return false; + }; + + _disableObject = function(o) { + for (var oProp in o) { + if (o.hasOwnProperty(oProp) && typeof o[oProp] === 'function') { + o[oProp] = _doNothing; + } + } + oProp = null; + }; + + _failSafely = function(bNoDisable) { + // general failure exception handler + if (typeof bNoDisable === 'undefined') { + bNoDisable = false; + } + if (_disabled || bNoDisable) { + _wDS('smFail', 2); + _s.disable(bNoDisable); + } + }; + + _normalizeMovieURL = function(smURL) { + var urlParams = null; + if (smURL) { + if (smURL.match(/\.swf(\?\.*)?$/i)) { + urlParams = smURL.substr(smURL.toLowerCase().lastIndexOf('.swf?') + 4); + if (urlParams) { + return smURL; // assume user knows what they're doing + } + } else if (smURL.lastIndexOf('/') !== smURL.length - 1) { + smURL = smURL + '/'; + } + } + return (smURL && smURL.lastIndexOf('/') !== - 1?smURL.substr(0, smURL.lastIndexOf('/') + 1):'./') + _s.movieURL; + }; + + _setVersionInfo = function() { + if (_fV !== 8 && _fV !== 9) { + _s._wD(_str('badFV', _fV, _defaultFlashVersion)); + _s.flashVersion = _defaultFlashVersion; + } + var isDebug = (_s.debugMode || _s.debugFlash?'_debug.swf':'.swf'); // debug flash movie, if applicable + if (_s.flashVersion < 9 && _s.useHTML5Audio && _s.audioFormats.mp4.required) { + _s._wD(_str('needfl9')); + _s.flashVersion = 9; + } + _fV = _s.flashVersion; // short-hand for internal use + _s.version = _s.versionNumber + (_html5Only?' (HTML5-only mode)':(_fV === 9?' (AS3/Flash 9)':' (AS2/Flash 8)')); + // set up default options + if (_fV > 8) { + _s.defaultOptions = _mixin(_s.defaultOptions, _s.flash9Options); + _s.features.buffering = true; + } + if (_fV > 8 && _s.useMovieStar) { + // flash 9+ support for movieStar formats as well as MP3 + _s.defaultOptions = _mixin(_s.defaultOptions, _s.movieStarOptions); + _s.filePatterns.flash9 = new RegExp('\\.(mp3|' + _s.netStreamTypes.join('|') + ')(\\?.*)?$', 'i'); + _s.mimePattern = _s.netStreamMimeTypes; + _s.features.movieStar = true; + } else { + _s.features.movieStar = false; + } + _s.filePattern = _s.filePatterns[(_fV !== 8?'flash9':'flash8')]; + _s.movieURL = (_fV === 8?'soundmanager2.swf':'soundmanager2_flash9.swf').replace('.swf',isDebug); + _s.features.peakData = _s.features.waveformData = _s.features.eqData = (_fV > 8); + }; + + _setPolling = function(bPolling, bHighPerformance) { + if (!_s.o || !_s.allowPolling) { + return false; + } + _s.o._setPolling(bPolling, bHighPerformance); + }; + + (function() { + var old = (_win.attachEvent), + evt = { + add: (old?'attachEvent':'addEventListener'), + remove: (old?'detachEvent':'removeEventListener') + }; + + function getArgs(oArgs) { + var args = _slice.call(oArgs), len = args.length; + if (old) { + args[1] = 'on' + args[1]; // prefix + if (len > 3) { + args.pop(); // no capture + } + } else if (len === 3) { + args.push(false); + } + return args; + } + + function apply(args, sType) { + var oFunc = args.shift()[evt[sType]]; + if (old) { + oFunc(args[0], args[1]); + } else { + oFunc.apply(this, args); + } + } + + _addEvt = function() { + apply(getArgs(arguments), 'add'); + }; + + _removeEvt = function() { + apply(getArgs(arguments), 'remove'); + }; + }()); + + function _initDebug() { + if (_s.debugURLParam.test(_wl)) { + _s.debugMode = true; // allow force of debug mode via URL + } + // + if (_id(_s.debugID)) { + return false; + } + var oD, oDebug, oTarget, oToggle, tmp; + if (_s.debugMode && !_id(_s.debugID) && ((!_hasConsole || !_s.useConsole) || (_s.useConsole && _hasConsole && !_s.consoleOnly))) { + oD = _doc.createElement('div'); + oD.id = _s.debugID + '-toggle'; + oToggle = { + 'position': 'fixed', + 'bottom': '0px', + 'right': '0px', + 'width': '1.2em', + 'height': '1.2em', + 'lineHeight': '1.2em', + 'margin': '2px', + 'textAlign': 'center', + 'border': '1px solid #999', + 'cursor': 'pointer', + 'background': '#fff', + 'color': '#333', + 'zIndex': 10001 + }; + oD.appendChild(_doc.createTextNode('-')); + oD.onclick = _toggleDebug; + oD.title = 'Toggle SM2 debug console'; + if (_ua.match(/msie 6/i)) { + oD.style.position = 'absolute'; + oD.style.cursor = 'hand'; + } + for (tmp in oToggle) { + if (oToggle.hasOwnProperty(tmp)) { + oD.style[tmp] = oToggle[tmp]; + } + } + oDebug = _doc.createElement('div'); + oDebug.id = _s.debugID; + oDebug.style.display = (_s.debugMode?'block':'none'); + if (_s.debugMode && !_id(oD.id)) { + try { + oTarget = _getDocument(); + oTarget.appendChild(oD); + } catch(e2) { + throw new Error(_str('appXHTML')); + } + oTarget.appendChild(oDebug); + } + } + oTarget = null; + // + } + + _mobileFlash = (function(){ + + var oM = null; + + function resetPosition() { + if (oM) { + oM.left = oM.top = '-9999px'; + } + } + + function reposition() { + oM.left = _win.scrollX+'px'; + oM.top = _win.scrollY+'px'; + } + + function setReposition(bOn) { + _s._wD('mobileFlash::flash on-screen hack: '+(bOn?'ON':'OFF')); + var f = _win[(bOn?'add':'remove')+'EventListener']; + f('resize', reposition, false); + f('scroll', reposition, false); + } + + function check(inDoc) { + // mobile flash (Android for starters) check + oM = _s.oMC.style; + if (_ua.match(/android/i)) { + if (inDoc) { + if (_s.flashLoadTimeout) { + _s._wDS('mfTimeout'); + _s.flashLoadTimeout = 0; + } + return false; + } + _s._wD('mfOn'); + oM.position = 'absolute'; + oM.left = oM.top = '0px'; + setReposition(true); + _s.onready(function(){ + setReposition(false); // detach + resetPosition(); // restore when OK/timed out + }); + reposition(); + } + return true; + } + + return { + 'check': check + }; + + }()); + + _createMovie = function(smID, smURL) { + + var specialCase = null, + remoteURL = (smURL?smURL:_s.url), + localURL = (_s.altURL?_s.altURL:remoteURL), + oEmbed, oMovie, oTarget = _getDocument(), tmp, movieHTML, oEl, extraClass = _getSWFCSS(), s, x, sClass, side = '100%', isRTL = null, html = _doc.getElementsByTagName('html')[0]; + isRTL = (html && html.dir && html.dir.match(/rtl/i)); + smID = (typeof smID === 'undefined'?_s.id:smID); + + if (_didAppend && _appendSuccess) { + return false; // ignore if already succeeded + } + + function _initMsg() { + _s._wD('-- SoundManager 2 ' + _s.version + (!_html5Only && _s.useHTML5Audio?(_s.hasHTML5?' + HTML5 audio':', no HTML5 audio support'):'') + (_s.useMovieStar?', MovieStar mode':'') + (_s.useHighPerformance?', high performance mode, ':', ') + ((_s.useFastPolling?'fast':'normal') + ' polling') + (_s.wmode?', wmode: ' + _s.wmode:'') + (_s.debugFlash?', flash debug mode':'') + (_s.useFlashBlock?', flashBlock mode':'') + ' --', 1); + } + + if (_html5Only) { + _setVersionInfo(); + _initMsg(); + _s.oMC = _id(_s.movieID); + _init(); + // prevent multiple init attempts + _didAppend = true; + _appendSuccess = true; + return false; + } + + _didAppend = true; + + // safety check for legacy (change to Flash 9 URL) + _setVersionInfo(); + _s.url = _normalizeMovieURL(this._overHTTP?remoteURL:localURL); + smURL = _s.url; + + _s.wmode = (!_s.wmode && _s.useHighPerformance && !_s.useMovieStar?'transparent':_s.wmode); + + if (_s.wmode !== null && !_isIE && !_s.useHighPerformance && navigator.platform.match(/win32/i)) { + _s.specialWmodeCase = true; + // extra-special case: movie doesn't load until scrolled into view when using wmode = anything but 'window' here + // does not apply when using high performance (position:fixed means on-screen), OR infinite flash load timeout + _wDS('spcWmode'); + _s.wmode = null; + } + + oEmbed = { + 'name': smID, + 'id': smID, + 'src': smURL, + 'width': side, + 'height': side, + 'quality': 'high', + 'allowScriptAccess': _s.allowScriptAccess, + 'bgcolor': _s.bgColor, + 'pluginspage': 'http://www.macromedia.com/go/getflashplayer', + 'type': 'application/x-shockwave-flash', + 'wmode': _s.wmode + }; + + if (_s.debugFlash) { + oEmbed.FlashVars = 'debug=1'; + } + + if (!_s.wmode) { + delete oEmbed.wmode; // don't write empty attribute + } + + if (_isIE) { + // IE is "special". + oMovie = _doc.createElement('div'); + movieHTML = '' + (_s.wmode?' ':'') + '' + (_s.debugFlash?'':'') + ''; + } else { + oMovie = _doc.createElement('embed'); + for (tmp in oEmbed) { + if (oEmbed.hasOwnProperty(tmp)) { + oMovie.setAttribute(tmp, oEmbed[tmp]); + } + } + } + + _initDebug(); + extraClass = _getSWFCSS(); + oTarget = _getDocument(); + + if (oTarget) { + _s.oMC = _id(_s.movieID)?_id(_s.movieID):_doc.createElement('div'); + if (!_s.oMC.id) { + _s.oMC.id = _s.movieID; + _s.oMC.className = _s.swfCSS.swfDefault + ' ' + extraClass; + // "hide" flash movie + s = null; + oEl = null; + if (!_s.useFlashBlock) { + if (_s.useHighPerformance) { + s = { + 'position': 'fixed', + 'width': '8px', + 'height': '8px', + // >= 6px for flash to run fast, >= 8px to start up under Firefox/win32 in some cases. odd? yes. + 'bottom': '0px', + 'left': '0px', + 'overflow': 'hidden' + }; + } else { + s = { + 'position': 'absolute', + 'width': '6px', + 'height': '6px', + 'top': '-9999px', + 'left': '-9999px' + }; + if (isRTL) { + s.left = Math.abs(parseInt(s.left,10))+'px'; + } + } + } + if (_ua.match(/webkit/i)) { + _s.oMC.style.zIndex = 10000; // soundcloud-reported render/crash fix, safari 5 + } + if (!_s.debugFlash) { + for (x in s) { + if (s.hasOwnProperty(x)) { + _s.oMC.style[x] = s[x]; + } + } + } + try { + if (!_isIE) { + _s.oMC.appendChild(oMovie); + } + oTarget.appendChild(_s.oMC); + if (_isIE) { + oEl = _s.oMC.appendChild(_doc.createElement('div')); + oEl.className = _s.swfCSS.swfBox; + oEl.innerHTML = movieHTML; + } + _appendSuccess = true; + } catch(e) { + throw new Error(_str('appXHTML')); + } + _mobileFlash.check(); + } else { + // it's already in the document. + sClass = _s.oMC.className; + _s.oMC.className = (sClass?sClass+' ':_s.swfCSS.swfDefault) + (extraClass?' '+extraClass:''); + _s.oMC.appendChild(oMovie); + if (_isIE) { + oEl = _s.oMC.appendChild(_doc.createElement('div')); + oEl.className = _s.swfCSS.swfBox; + oEl.innerHTML = movieHTML; + } + _appendSuccess = true; + _mobileFlash.check(true); + } + } + + if (specialCase) { + _s._wD(specialCase); + } + + _initMsg(); + _s._wD('soundManager::createMovie(): Trying to load ' + smURL + (!this._overHTTP && _s.altURL?' (alternate URL)':''), 1); + + return true; + }; + + _idCheck = this.getSoundById; + + _initMovie = function() { + if (_html5Only) { + _createMovie(); + return false; + } + // attempt to get, or create, movie + if (_s.o) { + return false; // may already exist + } + _s.o = _s.getMovie(_s.id); // inline markup + if (!_s.o) { + if (!_oRemoved) { + // try to create + _createMovie(_s.id, _s.url); + } else { + // try to re-append removed movie after reboot() + if (!_isIE) { + _s.oMC.appendChild(_oRemoved); + } else { + _s.oMC.innerHTML = _oRemovedHTML; + } + _oRemoved = null; + _didAppend = true; + } + _s.o = _s.getMovie(_s.id); + } + if (_s.o) { + _s._wD('soundManager::initMovie(): Got '+_s.o.nodeName+' element ('+(_didAppend?'created via JS':'static HTML')+')'); + _wDS('waitEI'); + } + if (_s.oninitmovie instanceof Function) { + setTimeout(_s.oninitmovie, 1); + } + return true; + }; + + _go = function(sURL) { + // where it all begins. + if (sURL) { + _s.url = sURL; + } + _initMovie(); + }; + + _delayWaitForEI = function() { + setTimeout(_waitForEI, 500); + }; + + _waitForEI = function() { + if (_waitingForEI) { + return false; + } + _waitingForEI = true; + _removeEvt(_win, 'load', _delayWaitForEI); + if (_tryInitOnFocus && !_isFocused) { + _wDS('waitFocus'); + return false; + } + var p; + if (!_didInit) { + p = _s.getMoviePercent(); + _s._wD(_str('waitImpatient', (p === 100?' (SWF loaded)':(p > 0?' (SWF ' + p + '% loaded)':'')))); + } + setTimeout(function() { + p = _s.getMoviePercent(); + if (!_didInit) { + _s._wD(_sm + ': No Flash response within expected time.\nLikely causes: ' + (p === 0?'Loading ' + _s.movieURL + ' may have failed (and/or Flash ' + _fV + '+ not present?), ':'') + 'Flash blocked or JS-Flash security error.' + (_s.debugFlash?' ' + _str('checkSWF'):''), 2); + if (!this._overHTTP && p) { + _wDS('localFail', 2); + if (!_s.debugFlash) { + _wDS('tryDebug', 2); + } + } + if (p === 0) { + // if 0 (not null), probably a 404. + _s._wD(_str('swf404', _s.url)); + } + _debugTS('flashtojs', false, ': Timed out' + this._overHTTP?' (Check flash security or flash blockers)':' (No plugin/missing SWF?)'); + } + // give up / time-out, depending + if (!_didInit && _okToDisable) { + if (p === null) { + // SWF failed. Maybe blocked. + if (_s.useFlashBlock || _s.flashLoadTimeout === 0) { + if (_s.useFlashBlock) { + _flashBlockHandler(); + } + _wDS('waitForever'); + } else { + // old SM2 behaviour, simply fail + _failSafely(true); + } + } else { + // flash loaded? Shouldn't be a blocking issue, then. + if (_s.flashLoadTimeout === 0) { + _wDS('waitForever'); + } else { + _failSafely(true); + } + } + } + }, _s.flashLoadTimeout); + }; + + _go = function(sURL) { + // where it all begins. + if (sURL) { + _s.url = sURL; + } + _initMovie(); + }; + + // + _wDS = function(o, errorLevel) { + if (!o) { + return ''; + } else { + return _s._wD(_str(o), errorLevel); + } + }; + + if (_wl.indexOf('debug=alert') + 1 && _s.debugMode) { + _s._wD = function(sText) {alert(sText);}; + } + + _toggleDebug = function() { + var o = _id(_s.debugID), + oT = _id(_s.debugID + '-toggle'); + if (!o) { + return false; + } + if (_debugOpen) { + // minimize + oT.innerHTML = '+'; + o.style.display = 'none'; + } else { + oT.innerHTML = '-'; + o.style.display = 'block'; + } + _debugOpen = !_debugOpen; + }; + + _debugTS = function(sEventType, bSuccess, sMessage) { + // troubleshooter debug hooks + if (typeof sm2Debugger !== 'undefined') { + try { + sm2Debugger.handleEvent(sEventType, bSuccess, sMessage); + } catch(e) { + // oh well + } + } + return true; + }; + // + + _getSWFCSS = function() { + var css = []; + if (_s.debugMode) { + css.push(_s.swfCSS.sm2Debug); + } + if (_s.debugFlash) { + css.push(_s.swfCSS.flashDebug); + } + if (_s.useHighPerformance) { + css.push(_s.swfCSS.highPerf); + } + return css.join(' '); + }; + + _flashBlockHandler = function() { + // *possible* flash block situation. + var name = _str('fbHandler'), p = _s.getMoviePercent(); + if (!_s.supported()) { + if (_needsFlash) { + // make the movie more visible, so user can fix + _s.oMC.className = _getSWFCSS() + ' ' + _s.swfCSS.swfDefault + ' ' + (p === null?_s.swfCSS.swfTimedout:_s.swfCSS.swfError); + _s._wD(name+': '+_str('fbTimeout')+(p?' ('+_str('fbLoaded')+')':'')); + } + _s.didFlashBlock = true; + _processOnReady(true); // fire onready(), complain lightly + if (_s.onerror instanceof Function) { + _s.onerror.apply(_win); + } + } else { + // SM2 loaded OK (or recovered) + if (_s.didFlashBlock) { + _s._wD(name+': Unblocked'); + } + if (_s.oMC) { + _s.oMC.className = _getSWFCSS() + ' ' + _s.swfCSS.swfDefault + (' '+_s.swfCSS.swfUnblocked); + } + } + }; + + _handleFocus = function() { + function cleanup() { + _removeEvt(_win, 'focus', _handleFocus); + _removeEvt(_win, 'load', _handleFocus); + } + if (_isFocused || !_tryInitOnFocus) { + cleanup(); + return true; + } + _okToDisable = true; + _isFocused = true; + _s._wD('soundManager::handleFocus()'); + if (_isSafari && _tryInitOnFocus) { + // giant Safari 3.1 hack - assume mousemove = focus given lack of focus event + _removeEvt(_win, 'mousemove', _handleFocus); + } + // allow init to restart + _waitingForEI = false; + cleanup(); + return true; + }; + + _initComplete = function(bNoDisable) { + if (_didInit) { + return false; + } + if (_html5Only) { + // all good. + _s._wD('-- SoundManager 2: loaded --'); + _didInit = true; + _processOnReady(); + _initUserOnload(); + return true; + } + var sClass = _s.oMC.className, + wasTimeout = (_s.useFlashBlock && _s.flashLoadTimeout && !_s.getMoviePercent()); + if (!wasTimeout) { + _didInit = true; + } + _s._wD('-- SoundManager 2 ' + (_disabled?'failed to load':'loaded') + ' (' + (_disabled?'security/load error':'OK') + ') --', 1); + if (_disabled || bNoDisable) { + if (_s.useFlashBlock) { + _s.oMC.className = _getSWFCSS() + ' ' + (_s.getMoviePercent() === null?_s.swfCSS.swfTimedout:_s.swfCSS.swfError); + } + _processOnReady(); + _debugTS('onload', false); + if (_s.onerror instanceof Function) { + _s.onerror.apply(_win); + } + return false; + } else { + _debugTS('onload', true); + } + if (_s.waitForWindowLoad && !_windowLoaded) { + _wDS('waitOnload'); + _addEvt(_win, 'load', _initUserOnload); + return false; + } else { + if (_s.waitForWindowLoad && _windowLoaded) { + _wDS('docLoaded'); + } + _initUserOnload(); + } + return true; + }; + + _addOnReady = function(oMethod, oScope) { + _onready.push({ + 'method': oMethod, + 'scope': (oScope || null), + 'fired': false + }); + }; + + _processOnReady = function(ignoreInit) { + if (!_didInit && !ignoreInit) { + // not ready yet. + return false; + } + var status = { + success: (ignoreInit?_s.supported():!_disabled) + }, + queue = [], i, j, + canRetry = (!_s.useFlashBlock || (_s.useFlashBlock && !_s.supported())); + for (i = 0, j = _onready.length; i < j; i++) { + if (_onready[i].fired !== true) { + queue.push(_onready[i]); + } + } + if (queue.length) { + _s._wD(_sm + ': Firing ' + queue.length + ' onready() item' + (queue.length > 1?'s':'')); + for (i = 0, j = queue.length; i < j; i++) { + if (queue[i].scope) { + queue[i].method.apply(queue[i].scope, [status]); + } else { + queue[i].method(status); + } + if (!canRetry) { // flashblock case doesn't count here + queue[i].fired = true; + } + } + } + return true; + }; + + _initUserOnload = function() { + _win.setTimeout(function() { + if (_s.useFlashBlock) { + _flashBlockHandler(); + } + _processOnReady(); + _wDS('onload', 1); + // call user-defined "onload", scoped to window + if (_s.onload instanceof Function) { + _s.onload.apply(_win); + } + _wDS('onloadOK', 1); + if (_s.waitForWindowLoad) { + _addEvt(_win, 'load', _initUserOnload); + } + },1); + }; + + _featureCheck = function() { + var needsFlash, item, + isBadSafari = (!_wl.match(/usehtml5audio/i) && !_wl.match(/sm2\-ignorebadua/i) && _isSafari && _ua.match(/OS X 10_6_(3|4)/i)), // Safari 4 and 5 occasionally fail to load/play HTML5 audio on Snow Leopard due to bug(s) in QuickTime X and/or other underlying frameworks. :/ Known Apple "radar" bug. https://bugs.webkit.org/show_bug.cgi?id=32159 + isSpecial = (_ua.match(/iphone os (1|2|3_0|3_1)/i)?true:false); // iPhone <= 3.1 has broken HTML5 audio(), but firmware 3.2 (iPad) + iOS4 works. + if (isSpecial) { + _s.hasHTML5 = false; // has Audio(), but is broken; let it load links directly. + _html5Only = true; // ignore flash case, however + if (_s.oMC) { + _s.oMC.style.display = 'none'; + } + return false; + } + if (_s.useHTML5Audio) { + if (!_s.html5 || !_s.html5.canPlayType) { + _s._wD('SoundManager: No HTML5 Audio() support detected.'); + _s.hasHTML5 = false; + return true; + } else { + _s.hasHTML5 = true; + } + if (isBadSafari) { + _s._wD('SoundManager::Note: Buggy HTML5 Audio in Safari on OS X 10.6.[3|4], see https://bugs.webkit.org/show_bug.cgi?id=32159 - disabling HTML5 audio',1); + _s.useHTML5Audio = false; + _s.hasHTML5 = false; + return true; + } + } else { + // flash required. + return true; + } + for (item in _s.audioFormats) { + if (_s.audioFormats.hasOwnProperty(item) && _s.audioFormats[item].required && !_s.html5.canPlayType(_s.audioFormats[item].type)) { + // may need flash for this format? + needsFlash = true; + } + } + // sanity check.. + if (_s.ignoreFlash) { + needsFlash = false; + } + _html5Only = (_s.useHTML5Audio && _s.hasHTML5 && !needsFlash); + return needsFlash; + }; + + _init = function() { + var item, tests = []; + _wDS('init'); + + // called after onload() + if (_didInit) { + _wDS('didInit'); + return false; + } + + function _cleanup() { + _removeEvt(_win, 'load', _s.beginDelayedInit); + } + + if (_s.hasHTML5) { + for (item in _s.audioFormats) { + if (_s.audioFormats.hasOwnProperty(item)) { + tests.push(item+': '+_s.html5[item]); + } + } + _s._wD('-- SoundManager 2: HTML5 support tests ('+_s.html5Test+'): '+tests.join(', ')+' --',1); + } + + if (_html5Only) { + if (!_didInit) { + // we don't need no steenking flash! + _cleanup(); + _s.enabled = true; + _initComplete(); + } + return true; + } + + // flash path + _initMovie(); + try { + _wDS('flashJS'); + _s.o._externalInterfaceTest(false); // attempt to talk to Flash + if (!_s.allowPolling) { + _wDS('noPolling', 1); + } else { + _setPolling(true, _s.useFastPolling?true:false); + } + if (!_s.debugMode) { + _s.o._disableDebug(); + } + _s.enabled = true; + _debugTS('jstoflash', true); + } catch(e) { + _s._wD('js/flash exception: ' + e.toString()); + _debugTS('jstoflash', false); + _failSafely(true); // don't disable, for reboot() + _initComplete(); + return false; + } + _initComplete(); + // event cleanup + _cleanup(); + return true; + }; + + _beginInit = function() { + if (_initPending) { + return false; + } + _createMovie(); + _initMovie(); + _initPending = true; + return true; + }; + + _dcLoaded = function() { + if (_didDCLoaded) { + return false; + } + _didDCLoaded = true; + _initDebug(); + _testHTML5(); + _s.html5.usingFlash = _featureCheck(); + _needsFlash = _s.html5.usingFlash; + _didDCLoaded = true; + if (_doc.removeEventListener) { + _doc.removeEventListener('DOMContentLoaded', _dcLoaded, false); + } + _go(); + return true; + }; + + _startTimer = function(oSound) { + if (!oSound._hasTimer) { + oSound._hasTimer = true; + } + }; + + _stopTimer = function(oSound) { + if (oSound._hasTimer) { + oSound._hasTimer = false; + } + }; + + _die = function() { + if (_s.onerror instanceof Function) { + _s.onerror(); + } + _s.disable(); + }; + + // pseudo-private methods called by Flash + + this._setSandboxType = function(sandboxType) { + // + var sb = _s.sandbox; + sb.type = sandboxType; + sb.description = sb.types[(typeof sb.types[sandboxType] !== 'undefined'?sandboxType:'unknown')]; + _s._wD('Flash security sandbox type: ' + sb.type); + if (sb.type === 'localWithFile') { + sb.noRemote = true; + sb.noLocal = false; + _wDS('secNote', 2); + } else if (sb.type === 'localWithNetwork') { + sb.noRemote = false; + sb.noLocal = true; + } else if (sb.type === 'localTrusted') { + sb.noRemote = false; + sb.noLocal = false; + } + // + }; + + this._externalInterfaceOK = function(flashDate) { + // flash callback confirming flash loaded, EI working etc. + // flashDate = approx. timing/delay info for JS/flash bridge + if (_s.swfLoaded) { + return false; + } + var eiTime = new Date().getTime(); + _s._wD('soundManager::externalInterfaceOK()' + (flashDate?' (~' + (eiTime - flashDate) + ' ms)':'')); + _debugTS('swf', true); + _debugTS('flashtojs', true); + _s.swfLoaded = true; + _tryInitOnFocus = false; + if (_isIE) { + // IE needs a timeout OR delay until window.onload - may need TODO: investigating + setTimeout(_init, 100); + } else { + _init(); + } + }; + + _dcIE = function() { + if (_doc.readyState === 'complete') { + _dcLoaded(); + _doc.detachEvent('onreadystatechange', _dcIE); + } + return true; + }; + + // focus and window load, init + if (!_s.hasHTML5 || _needsFlash) { + // only applies to Flash mode + _addEvt(_win, 'focus', _handleFocus); + _addEvt(_win, 'load', _handleFocus); + _addEvt(_win, 'load', _delayWaitForEI); + if (_isSafari && _tryInitOnFocus) { + _addEvt(_win, 'mousemove', _handleFocus); // massive Safari focus hack + } + } + + if (_doc.addEventListener) { + _doc.addEventListener('DOMContentLoaded', _dcLoaded, false); + } else if (_doc.attachEvent) { + _doc.attachEvent('onreadystatechange', _dcIE); + } else { + // no add/attachevent support - safe to assume no JS -> Flash either + _debugTS('onload', false); + _die(); + } + + if (_doc.readyState === 'complete') { + setTimeout(_dcLoaded,100); + } + +} // SoundManager() + +// var SM2_DEFER = true; +// details: http://www.schillmania.com/projects/soundmanager2/doc/getstarted/#lazy-loading + +if (typeof SM2_DEFER === 'undefined' || !SM2_DEFER) { + soundManager = new SoundManager(); +} + +// public interfaces +window.SoundManager = SoundManager; // constructor +window.soundManager = soundManager; // public instance: API, Flash callbacks etc. + +}(window)); diff --git a/frontend/static/js/src/swfobject.js b/frontend/static/js/src/swfobject.js new file mode 100755 index 0000000..8eafe9d --- /dev/null +++ b/frontend/static/js/src/swfobject.js @@ -0,0 +1,4 @@ +/* SWFObject v2.2 + is released under the MIT License +*/ +var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y0){for(var af=0;af0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad'}}aa.outerHTML='"+af+"";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab
    ") + Vimeo.video = video + Vimeo.playing = true + var params = { allowScriptAccess: "always", wmode: "opaque", } + var atts = { id: "vimeo" } + var flashvars = { api: 1 } + swfobject.embedSWF("http://vimeo.com/moogaloop.swf?clip_id="+video.name+"&server=vimeo.com&color=00adef&api=1", + "vimeo", "100%","100%", "8", null, flashvars, params, atts) + // $("#vimeo").html('') + }, + toggle: function () + { + if (Vimeo.player.api_paused()) + return Vimeo.resume() + else + return Vimeo.pause() + }, + error: function (s) + { + Player.error("VIMEO "+s) + Vimeo.finish() + }, + setVolume: function (vol) + { + Vimeo.volume = vol + Vimeo.player.api_setVolume(vol) + }, + pause: function () + { + d.warn("PAUSED PLAYBACK") + Vimeo.playing = false + Vimeo.player.api_pause() + return true + }, + resume: function () + { + d.warn("RESUME PLAYBACK") + Vimeo.playing = true + Vimeo.player.api_play() + return false + }, + stop: function () + { + d.warn("VIMEO STOP") + Vimeo.playing = false + }, + finish: function () + { + d.warn("VIMEO FINISH") + Vimeo.playing = false + swfobject.removeSWF("vimeo") + Player.finish() + }, + load: function () + { + d.warn("LOADING VIMEO") + Vimeo.loaded = true + }, + unload: function () + { + d.warn("VIMEO UNLOADED") + swfobject.removeSWF("vimeo") + Vimeo.loaded = false + }, + init: function () + { + d.warn("VIMEO INIT") + } + } +function vimeo_player_loaded() + { + d.warn("VIMEO LOADED") + Vimeo.player = document.getElementById('vimeo') + Vimeo.player.api_play() + // Vimeo.player.addEventListener("finish", "Vimeo.finish") + Vimeo.player.api_addEventListener("finish", "Vimeo.finish") + Vimeo.player.api_setVolume(Vimeo.volume) + } +Player.register(Vimeo) diff --git a/frontend/static/js/src/youtube.js b/frontend/static/js/src/youtube.js new file mode 100644 index 0000000..23d0089 --- /dev/null +++ b/frontend/static/js/src/youtube.js @@ -0,0 +1,176 @@ +var Youtube = + { + type: "youtube", + loaded: false, + pending: false, + playing: false, + player: null, + playerId: null, + timeout: null, + video: null, + width: "100%", + height: "100%", + getYtid: function (url) + { + if (! url) return + var ytid = url.substr(url.indexOf("v=")+2,11) + if (ytid.indexOf("&") !== -1) + ytid = ytid.substr(0, ytid.indexOf("&")) + if (ytid.indexOf("#") !== -1) + ytid = ytid.substr(0, ytid.indexOf("#")) + return ytid + }, + play: function (video) + { + d.warn("YOUTUBE PLAY "+video.key) + if (video.error) + return Youtube.error() + if (Youtube.playing) + Youtube.stop() + Youtube.video = video + Youtube.playing = true + if (Youtube.ready) + { + d.warn("ORDERING VIDEO LOAD "+video.name) + Youtube.player.loadVideoById(video.name) + Youtube.pending = false + } + else + { + d.error("YOUTUBE PLAYER NOT READY") + Youtube.pending = true + } + }, + toggle: function () + { + if (Youtube.playing) + return Youtube.pause() + else + return Youtube.resume() + }, + error: function (s) + { + Player.error("YOUTUBE "+s) + $("li#queue_"+Youtube.video.idx+" span.title").html("This video cannot be embedded") + setTimeout(Youtube.finish, 1000) + }, + onStateChange: function (state) + { + Youtube.state = state + if (state === -1) + { + d.warn("YOUTUBE: UNSTARTED") + Youtube.playing = false + } + else if (state === 0) + { + d.warn("YOUTUBE: ENDED") + Youtube.playing = false + return Youtube.finish() + } + else if (state === 1) + { + d.warn("YOUTUBE: PLAYING") + Youtube.playing = true + if (! Youtube.loaded) + return Youtube.unload() + } + else if (state === 2) + { + d.warn("YOUTUBE: PAUSED") + Youtube.playing = false + } + else if (state === 3) + { + d.warn("YOUTUBE: BUFFERING") + } + else if (state === 5) + { + d.warn("YOUTUBE: CUED") + } + else + { + d.error("YOUTUBE: UNKNOWN") + } + }, + onError: function (error) + { + var errorStr = 'UNKNOWN' + if (error === 2) + errorStr = "INVALID PARAMETER" + if (error === 100) + errorStr = "NOT FOUND" + if (error === 101 || error === 150) + errorStr = "EMBED FORBIDDEN" + Youtube.error(errorStr) + }, + setVolume: function (vol) + { + Youtube.player.setVolume(vol) + }, + pause: function () + { + d.warn("PAUSED PLAYBACK") + Youtube.playing = false + Youtube.player.pauseVideo() + return true + }, + resume: function () + { + d.warn("RESUME PLAYBACK") + Youtube.playing = true + Youtube.player.playVideo() + return false + }, + stop: function () + { + d.warn("YOUTUBE STOP") + Youtube.player.stopVideo() + Youtube.playing = false + }, + finish: function () + { + d.warn("YOUTUBE FINISH") + Youtube.playing = false + Player.finish() + }, + load: function () + { + d.warn("LOADING YOUTUBE") + $("#ytscreen").css("z-index", 19) + Youtube.loaded = true + }, + unload: function () + { + d.warn("YOUTUBE UNLOADED") + $("#ytscreen").css("z-index", -3) + if (Youtube.player) + Youtube.player.stopVideo() + Youtube.playing = false + Youtube.loaded = false + Youtube.pending = false + }, + init: function () + { + d.warn("YOUTUBE INIT") + var params = { allowScriptAccess: "always", wmode: "opaque" } + var atts = { id: "ytscreen" } + swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid=ytscreen", + "ytscreen", Player.width, Player.height, "8", null, null, params, atts) + } + } +function onYouTubePlayerReady (playerId) + { + d.warn("YOUTUBE READY") + Youtube.player = document.getElementById(playerId) + Youtube.playerId = playerId + Youtube.player.addEventListener("onStateChange", "Youtube.onStateChange") + Youtube.player.addEventListener("onError", "Youtube.onError") + Youtube.ready = true + if (! Youtube.loaded) + return Youtube.unload() + if (Youtube.pending) + Youtube.player.loadVideoById(Youtube.video.name) + Youtube.pending = false + } +Player.register(Youtube) -- cgit v1.2.3-70-g09d2