diff options
Diffstat (limited to 'www/static/js/profile.js')
| -rwxr-xr-x | www/static/js/profile.js | 540 |
1 files changed, 540 insertions, 0 deletions
diff --git a/www/static/js/profile.js b/www/static/js/profile.js new file mode 100755 index 0000000..6005e79 --- /dev/null +++ b/www/static/js/profile.js @@ -0,0 +1,540 @@ +var Keyboard = + { + altMode: false, + fullscreenKeys: 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.toggle() + if (kc === 76) + Player.likeClick() + return false + }, + standardKeys: function (event) + { + kc = event.keyCode + if (kc === 91) + { + Keyboard.altMode = true + return true + } + if (kc === 27) + { + Viewport.fullscreenOn() + return false + } + if (kc === 37 || kc === 177) + { + Player.playPrev() + return false + } + else if (kc === 39 || kc === 176) + { + Player.playNext() + return false + } + if (! Menu.isOpen && ! Keyboard.altMode && kc === 76) + { + Player.likeClick() + return false + } + if (kc === 32 || kc === 179) + { + Player.toggle() + return false + } + Keyboard.altMode = false + return true + } + } +var Viewport = + { + fullscreenMode: false, + fullscreenOn: function () + { + $("#logo,#logobg,#sitez,#playlist,#playlistbg,#contact,#bg,#gif-container,#controls").hide() + $("#settings-container").hide() + $(window).unbind("resize") + $(window).bind("resize", Viewport.fullscreenResize) + $(window).unbind("keydown") + $(window).bind("keydown", Keyboard.fullscreenKeys) + // 1) HIDDEN + // $("body").css("overflow-y", "hidden") + d.scrollToTop("body") + Viewport.fullscreenResize() + Viewport.fullscreenMode = true + // $("#fullscreen").unbind("click") + // $("#fullscreen").bind("click", Viewport.fullscreenOff) + $("#fullscreen-warning").show().fadeOut(3000) + $("#video-title").addClass("fullscreen") + }, + fullscreenResize: function () + { + // 2) FIXED + // $("#projector").css({ position: 'fixed', top: 0, left: 0, width: $(window).width(), height: $(window).height() }) + $("#player").css({ top: 0, left: 0, width: $(window).width(), height: $(window).height() }) + $("#screen,#ytscreen").css({ width: $(window).width(), height: $(window).height() }) + }, + fullscreenOff: function () + { + $("#logo,#logobg,#sitez,#playlist,#playlistbg,#contact,#bg,#gif-container,#controls").show() + // $("body").css("overflow-y", "scroll") + $(window).unbind("resize") + $(window).bind("resize", Viewport.standardResize) + Viewport.standardResize() + Viewport.fullscreenMode = false + $(window).unbind("keydown") + $(window).bind("keydown", Keyboard.standardKeys) + $("#fullscreen").unbind("click") + $("#fullscreen").bind("click", Viewport.fullscreenOn) + $("#video-title").removeClass("fullscreen") + }, + standardResize: function () + { + var w = $(window).width() + var h = $(window).height() + var contact = w * 200 / 1425 + var ytw = (w-contact-40)*4/7 + var yth = ytw * 9/16 + var plw = (w-contact-40)*3/7 + + $("#contact img").css("max-width", contact) + var conheight = $("#controls").height() + var contactheight = $("#contact").height() + var qheight = Math.max(yth+conheight+40, h - 94 - 60) // Math.max(yth+conheight+40, contactheight) + + $("#playlist").css("top", 94).css("left", contact+40) + $("#playlist,#playlistbg").css("width", plw-20) + $("#playlist,#playlistbg").css("height", qheight) + $("#queue").css("height", qheight) + var queuetop = $("#queue").offset().top + $("#playlistbg").css("top", queuetop).css("left", contact+40) + + $("#contact").css("width", contact).css("top", 94).css("left", 20) + + $("#projector").css({ position: 'absolute', }) + $("#player").css("height", yth+conheight+10) + $("#player").css("top", queuetop).css("left", plw+contact+40) + $("#projector").css("left", 0) + $("#player,#projector,#screen,#ytscreen").width(ytw-40) + $("#projector,#screen,#ytscreen").height(yth) + + $("#controls").css({ position: 'absolute', top: yth+20, bottom: 'auto', right: 'auto', }) + + $("#gif-container").css("top", qheight+30+134) + }, + 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 + } + } +var Room = + { + load: function () + { + Settings.open() + } + } +var Settings = + { + bio: "", + data: {}, + eventSet: false, + defaults: + { + avatar: "http://scannerjammer.com/img/runner.gif", + bg: "http://scannerjammer.com/bgz/scannerjammer_cyberspace.jpg", + }, + open: function () + { + if (parseInt(Auth.userid) !== userProfile[0]) + return + $("#settings-hook").show() + $("#profile-avatar").val(Settings.data.avatar) + $("#profile-bg").val(Settings.data.bg) + $("#profile-bio").html(Settings.bio) + if (! Profile.eventSet) + { + $("#profile-settings-save").bind("click", Settings.save) + Profile.eventSet = true + } + }, + save: function () + { + d.warn("saving profile") + var avatar = d.sanitize( $("#profile-avatar").val() ) + Settings.data.avatar = avatar + var bg = d.sanitize( $("#profile-bg").val() ) + Settings.data.bg = bg + var bio = d.sanitizeWithNewlines( $("#profile-bio").val() ) + Settings.bio = bio + Settings.load() + var s = "avatar\t"+avatar+"\n" + s += "bg\t"+bg+"\n" + var data = { + userid: userProfile[0], + settings: s, + bio: bio, + session: Auth.session, + } + $.post(API.URL.user.settings, data).success(Settings.saveCallback).error(Settings.errorCallback) + }, + errorCallback: function (raw) + { + }, + saveCallback: function (raw) + { + Menu.settings.close() + }, + load: function () + { + if (Settings.data.avatar.indexOf("http://") === 0) + $(".avatar").attr("src", Settings.data.avatar).show() + else + $(".avatar").hide() + if (Settings.data.bg.indexOf("http://") === 0) + { + $("#bg img").attr("src", Settings.data.bg) + $("#bg").show() + } + else + $("#bg").hide() + var bio = '' + if (! Settings.bio.length) + { + bio = "<img src='/img/playlist.gif' />" + } + var lines = d.trim( Settings.bio ).split("\n") + for (i in lines) + { + if (lines[i].length === 0) + continue + var s = Chat.parseWords(lines[i]) + if (s.indexOf("<img") !== -1) + bio += s + else + bio += "<p>"+s+"</p>" + } + $("#bio").html(bio) + Settings.open() + Viewport.standardResize() + }, + init: function () + { + if (userProfile[6]) + { + Settings.bio = userProfile[6] + } + if (userProfile[7]) + { + var lines = userProfile[7].split("\n") + for (i in lines) + { + var pair = lines[i].split("\t") + Settings.data[pair[0]] = pair[1] + } + } + for (i in Settings.defaults) + { + if (! (i in Settings.data)) + Settings.data[i] = Settings.defaults[i] + } + Settings.load() + } + } +function menu (key, loadCallback) + { + d.warn("MENU INIT "+key) + this.show = function () + { + if (! Menu.isOpen) + { + $("#"+key+"-container").show() + Menu.current = key + loadCallback() + } + } + this.hide = 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.show, this.hide).click(this.click) + $("#"+key+"-close").click(this.close) + $("#"+key+"-container").hover(this.click, function(){}) + } +var Menu = + { + isOpen: false, + current: false, + keys: ["settings"], + close: function () + { + if (Menu.current) + Menu[Menu.current].close() + }, + settings: new menu("settings", Settings.open) + } +var Profile = + { + mode: false, + page: 0, + pages: [], + loadMore: function () + { + var api = "" + // console.log(Profile.mode) + if (Profile.mode === "user") + api = API.URL.user.videos + else if (Profile.mode === "like") + api = API.URL.user.likes + else + return + var data = + { + user: userProfile[1], + start: Player.videos[Player.queue[0]].date, + } + d.scrollToTop(window) + $("#queueMore").unbind("click") + $("#queue").html("<li id='queueLoading'>LOADING<br/><img src='/img/loading2.gif'/></li>") + $.post(api, data).success(Profile.loadMoreCallback) + }, + loadMoreCallback: function (raw) + { + var lines = API.parse("/user/load", raw) + if (! lines) return + if (lines[0].indexOf("0\t") === 0) + return // console.log(lines.split("\t")[1]) + queue = [] + for (i in lines) + { + if (lines[i].length < 2) + continue + line = lines[i].split("\t") + queue.push(line) + } + Profile.page += 1 + Profile.pages[Profile.page] = queue + Profile.loadQueue(queue) + $("#queue").prepend("<li id='queueLess'>Go Back</li>") + $("#queueLess").unbind("click") + $("#queueLess").bind("click", Profile.loadLess) + if (queue.length < 50) + $("#queue").append("<li id='queueDone'>That's all the videos!</li>") + }, + loadLess: function () + { + Profile.page -= 1 + Profile.loadQueue(Profile.pages[Profile.page]) + if (Profile.page !== 0) + { + $("#queue").prepend("<li id='queueLess'>Go Back</li>") + $("#queueLess").unbind("click") + $("#queueLess").bind("click", Profile.loadLess) + return + } + }, + loadQueue: function (queue) + { + if (! queue || ! queue.length) + return + Player.clearQueue() + $("#queueMore").unbind("click") + $("#queue").html("") + Playlist.enqueueOldVideoFormat(queue) + d.scrollToTop("#queue") + if (Profile.mode !== "top") + { + if (queue.length > 49) + { + $("#queue").append("<li id='queueMore'>Load More Videos</li>") + $("#queueMore").bind("click", Profile.loadMore) + } + } + }, + loadLikeQueue: function () + { + if (Profile.mode === "like") + return + Profile.page = 0 + Profile.pages = [likeVideoQueue] + Profile.mode = "like" + $(".mode").removeClass("mode") + $("#likeQueue").addClass("mode") + Profile.loadQueue(likeVideoQueue) + }, + loadTopQueue: function () + { + if (Profile.mode === "top") + return + Profile.mode = "top" + $(".mode").removeClass("mode") + $("#topQueue").addClass("mode") + Profile.loadQueue(topVideoQueue) + }, + loadUserQueue: function () + { + if (Profile.mode === "user") + return + Profile.page = 0 + Profile.pages = [userVideoQueue] + Profile.mode = "user" + $(".mode").removeClass("mode") + $("#userQueue").addClass("mode") + Profile.loadQueue(userVideoQueue) + }, + loadImages: function () + { + var lastDate = imageQueue[0][0] + var bars = [] + var s = "" + + for (i in imageQueue) + { + img = imageQueue[i] + if (img[0] !== lastDate) + { + bars.push('<div>'+s+'</div>') + s = "" + lastDate = img[0] + } + s += '<img src="'+img[1]+'"/>' + } + bars.push('<div>'+s+'</div>') + $("#gifs").html(bars.join("")) + }, + init: function () + { + if (userVideoQueue && userVideoQueue.length && userVideoQueueTitle) + { + $("#queueLinks").append('<li id="userQueue">'+userVideoQueueTitle+'</li>') + $("#userQueue").bind("click", Profile.loadUserQueue) + } + if (likeVideoQueue && likeVideoQueue.length && likeVideoQueueTitle) + { + $("#queueLinks").append('<li id="likeQueue">'+likeVideoQueueTitle+'</li>') + $("#likeQueue").bind("click", Profile.loadLikeQueue) + likeVideoQueue.reverse() + } + if (topVideoQueue && topVideoQueue.length && topVideoQueueTitle) + { + $("#queueLinks").append('<li id="topQueue">'+topVideoQueueTitle+'</li>') + $("#topQueue").bind("click", Profile.loadTopQueue) + topVideoQueue.reverse() + } + if (userVideoQueue && userVideoQueue.length) + Profile.loadUserQueue() + else if (likeVideoQueue && likeVideoQueue.length) + Profile.loadLikeQueue() + // if (imageQueue && imageQueue.length) + // Profile.loadImages() + } + } +var Poll = + { + room: "main", + delay: 5000, + init: function () + { + if (document.cookie) + { + var cookies = document.cookie.split(";") + for (i in cookies) + { + var cookie = cookies[i].split("=") + if (cookie[0].indexOf("room") !== -1) + { + if (cookie[1] !== 'false' && cookie[1] !== 'undefined') + { + Poll.room = cookie[1] + break + } + } + } + } + Poll.poll() + Settings.open() + }, + poll: function () + { + $.post(API.URL.room.poll, + { + room: Poll.room, + session: Auth.session, + last: 1, + }).success(Poll.pollCallback).error(Poll.pollErrorCallback) + }, + pollErrorCallback: function () + { + Poll.timer = setTimeout(Poll.poll, Poll.delay) + }, + pollCallback: function (raw) + { + Poll.timer = setTimeout(Poll.poll, Poll.delay) + } + } + +var Main = + { + init: function () + { + $(window).bind("focus", Viewport.focus) + $(window).bind("blur", Viewport.blur) + $(window).bind("resize", Viewport.standardResize) + $(window).bind("keydown", Keyboard.standardKeys) + Playlist.showScores = true + Auth.success = Poll.init + if (Auth.init()) + Auth.checkin() + Profile.init() + Player.init() + Settings.init() + $("#controls").fadeIn(2000) + $("#contact").fadeIn(2000) + setTimeout('Viewport.standardResize()', 1000) + } + } +Main.init() + |
