summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-10-20 15:25:24 +0200
committerJules Laplace <julescarbon@gmail.com>2017-10-20 15:25:24 +0200
commit9b0a8b9e41e255b1e7cafbc31d5c12f19e32a2c0 (patch)
treea61681fa6e3dbc7a2d7036a43ae8d17816afd212
parenteb73811e6ead48d4ef32b5ee7e3ce0f7868b7e29 (diff)
parent094c8e01572b953398c543360f29622cdcfcd541 (diff)
Merge branch 'master' of ghghgh.us:scannerjammer
-rw-r--r--frontend/static/js/room.js460
-rwxr-xr-xfrontend/static/js/sj_compiled.js13
2 files changed, 471 insertions, 2 deletions
diff --git a/frontend/static/js/room.js b/frontend/static/js/room.js
new file mode 100644
index 0000000..2d77f6f
--- /dev/null
+++ b/frontend/static/js/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 = "&nbsp;"
+ $("#heading").html( s.replace(">","&gt;").replace("<","&lt;") )
+ },
+ topic: function (s)
+ {
+ if (s.length === 0)
+ s = "&nbsp;"
+ $("#topic").html( d.linkify(s.replace(">","&gt;").replace("<","&lt;")) )
+ },
+ 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("<a href='/"+Room.name+"/admin'>Moderate room</a>")
+ 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 = $("<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 = $("<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", "<span style='color: #fff;'>&rarr; SEE ALL <span style='text-decoration: underline;'>OPEN ROOMS</span></span>"],
+ [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&ograve;n&ograve; m&igrave; l&ograve;'],
+ //[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 = "<a href='"+r[2]+"'><li style='background-image: url("+r[3]+")'>"+r[4]
+ if (r[1] === Room.name)
+ s += " &lt; YOU ARE HERE"
+ s += "</li></a>"
+ 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('<iframe id="tokbox-embedded" src="http://scannerjammer.com/tokbox/" style="border:none"></iframe>')
+ // $("#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/sj_compiled.js b/frontend/static/js/sj_compiled.js
index 7ba2ad7..32ded05 100755
--- a/frontend/static/js/sj_compiled.js
+++ b/frontend/static/js/sj_compiled.js
@@ -1513,7 +1513,7 @@ var Playlist =
// block video if it's a duplicate
}
var url = row[4]
- if (url.indexOf("youtube.com") !== -1)
+ if (url.indexOf("youtube.com") !== -1 || url.indexOf("youtu.be") !== -1)
{
var ytid = Youtube.getYtid(url)
video.type = "youtube"
@@ -1979,6 +1979,15 @@ var Youtube =
height: "100%",
getYtid: function (url)
{
+ if (url.indexOf("youtu.be")){
+ var reg = /youtu\.be\/([A-Za-z0-9]+)/
+ var matches = reg.exec(url)
+ if (matches){
+ console.log(matches[1])
+ return matches[1]
+ }
+
+ }
if (! url) return
var ytid = url.substr(url.indexOf("v=")+2,11)
if (ytid.indexOf("&") !== -1)
@@ -2531,7 +2540,7 @@ var Chat =
var word = words[i]
if (word.indexOf("http") !== -1)
{
- if (word.indexOf("youtube.com/watch?") !== -1)
+ if (word.indexOf("youtube.com/watch?") !== -1 || word.indexOf("youtu.be") !== -1 )
{
var ytid = "youtube_"+Youtube.getYtid(word)
var txt