Advertisement
Guest User

Untitled

a guest
May 5th, 2015
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.25 KB | None | 0 0
  1. }});$("button.checkbox[rel]").each(function(ind,elem){if($('input[name="'+$(elem).attr("rel")+'"]').val()=="1"){$(elem).addClass("active")}else{$(elem).removeClass("active")}});var temp=$('<div id="loginWindowContainer"></div>');$("body").append(temp).on("click",".loginWindow .head a",function(e){var block=$(this).closest(".loginWindow");e.preventDefault();$(this).closest("ul").find("a").removeClass("active");$(this).addClass("active");if($(this).attr("rel")=="login-inner"){$("#loginTabs").removeClass("tab2").addClass("tab1")}else{$("#loginTabs").removeClass("tab1").addClass("tab2")}});$("#loginMenuContainer").add(temp).on("click",".icon-vk",function(){VK.Auth.login(function(udata){if(udata.status=="connected"){$.post("/oauth/auth",{site:"vk",data:udata.session.user,token:udata.session.sig},function(data){if(data.result=="auth"){reload()}else if(data.result=="notfound"){oauth_step2(udata.session.user.domain||udata.session.user.first_name+" "+udata.session.user.last_name)}},"json")}})}).on("click",".icon-facebook",function(){FB.login(function(data){if(data.status=="connected"){FB.api("/me",function(response){$.post("/oauth/auth",{site:"fb",data:response},function(data){if(data.result=="auth"){reload()}else if(data.result=="notfound"){oauth_step2(response.username||response.name)}},"json")})}},{scope:"email"})}).on("click",".icon-twitter",function(){var win=window.open("/oauth/twitter","_blank","menubar=no,toolbar=no,location=no,directories=no,width=500,height=400")}).on("click",".icon-bnet-icon",function(){var win=window.open("/oauth/bnet","_blank","menubar=no,toolbar=no,location=no,directories=no,width=500,height=400")}).on("click","a[rel=bind]",function(){$.post(AJAX_PATH+"/login/",$("#form-bind").serialize(),function(data){if(!data.result){alert(data.response)}if(data.login_page){redirect(data.login_page)}else if(data.result){$.post("/oauth/bind",function(data){if(data.result){reload()}else{alert("Произошла ошибка")}},"json")}},"json");return false}).on("submit","#form-login",function(e){e.preventDefault();var form=$(this);$.post(AJAX_PATH+"/login/",$(this).serialize(),function(data){if(!data){throw new Error("Login error: No data");return}if(!data.result&&data.login_page){redirect(data.login_page);return}if(!data.result){var dialog=$("#dialog-confirm");if(data.code==3){dialog.find("p").html(data.response);dialog.dialog({resizable:false,modal:true,buttons:{"Да":function(){$.post(AJAX_PATH+"/reactivate/",form.serialize(),function(data){dialog.find("p").html(data.result?"Письмо выслано":"Произошла ошибка");dialog.dialog({resizable:false,modal:true,buttons:{OK:function(){$(this).dialog("close")}}})},"json")},"Нет":function(){$(this).dialog("close")}}});return}else{dialog.find("p").html(data.response);dialog.dialog({resizable:false,modal:true,buttons:{OK:function(){$(this).dialog("close")}}});return}}if(data.return&&$(form).data("callback")){var callback=$(form).data("callback");callback(data.return);$("#loginOverlay").click()}else if(data.login_page){redirect(data.login_page)}else if(data.result){if(window.location.pathname.toLowerCase().indexOf("activate")!==-1){redirect("/")}else{reload()}}},"json");return}).on("submit","#form-reg",function(e){e.preventDefault();if($(this).find("input[name=email]").val()!=""&&$(this).find("input[name=password]").val()!=""){$.post("/ajax/register/",$(this).serializeArray(),function(data){if(data.errors){if(data.errors.email){alert(data.errors.email)}else if(data.errors.password){alert(data.errors.password)}else if(data.errors.captcha){alert(data.errors.captcha)}}else{$("#reg_step1").hide();$("#reg_step2").show()}},"json")}})});function oauth_step2(username,data){if($("#reg-popup").is(":visible")||$("#loginTabs").hasClass("tab2")){redirect("register/")}else{var login=$("#login-inner");var step1=login.is(":visible")?login.find("#step1"):$("#step1");var step2=login.is(":visible")?login.find("#step2"):$("#step2");step2.find("#ext-username").html(username);step1.hide();step2.show()}}function oauthCallback(data){if(data.result=="error"){if(data.txt)alert(data.txt);else alert("Произошла ошибка")}else if(data.result=="auth"){if(User!=0&&typeof window.cupScope!="undefined"){window.cupScope.bnetCallback()}else{reload()}}else{oauth_step2(data.name)}}function checkClickOutside(target,container){return!container.is(target)&&container.has(target).length===0}function uglyflashhack(){var flashIframe=$("#streams-content");if(flashIframe.length==0){flashIframe=$(".player-tab:visible")}try{if(navigator.platform=="MacIntel"||flashIframe.find("iframe").contents().find("embed").attr("wmode")!="direct")return false;if($("#login-popup").is(":visible")||$("#reg-popup").is(":visible")||$(".make-ban").is(":visible")){flashIframe.find("iframe").hide()}else{flashIframe.find("iframe").show()}}catch(e){}return true}function comments_callback(user){$(".leave-comment-warning").remove();$(".leave-comment").find("input[type=submit]").show();$(".leave-comment").find(".avatar-block").css({"background-image":"url("+user.avatar+")"})}(function(global,$){if(!$){throw new Error("jQuery not init.")}$.fn.extend({notify:function(event_name,callback){if(typeof $.notifyEvents=="undefined"){$.notifyEvents=[]}if(typeof $.notifyEvents[event_name]=="undefined"){$.notifyEvents[event_name]=[]}$.notifyEvents[event_name].push({callback:callback,obj:this})},notifySubscribe:function(callback){if(!$(this).attr("gg-obj"))return;var data=JSON.parse($(this).attr("gg-obj"));var pwd=$(this).attr("gg-pwd");if(window.notify){window.notify.addObject(data.obj_type+":"+data.obj_id+(pwd?":"+pwd:""),{callback:callback,obj:this})}else{console.log("There is no Notify")}}});global.Notify=Notify;function Notify(doc,userid,token){this.document=doc;this.user=userid;this.token=token;this.subscribeObjects=[];this.canSubscribe=false;this.waitingPong=false;this._timerCallback=false;this.obj=$("*[gg-obj]").length?$("*[gg-obj]").attr("gg-obj"):false;NotifySettings=$.extend({},{all:0,sound:0,pm:1,sm:1,bn:1,st:1},NotifySettings);global.window.addEventListener("storage",this._storageEvent,false);var that=this;this.setPingTimeout(6e4);that.connect()}Notify.prototype.setPingTimeout=function(value){var that=this;console.log("set timer on",value);if(this._pingTimeout)clearInterval(this._pingTimeout);this._pingTimeout=setInterval(function(){that._ping()},value)};Notify.prototype._ping=function(){this.waitingPong=true;this._send("ping",{});var self=this;setTimeout(function(){if(!!self.waitingPong){console.warn("No pong in 5 seconds. Closing.");if(self.socket){self.socket.onclose=function(){};self.socket.close()}self._onClose()}},5e3)};Notify.prototype._onClose=function(){console.warn("Websocket closed, reconnecting...");this.canSubscribe=false;setTimeout(this.connect.bind(this),5e3)};Notify.prototype.connect=function(){console.log("Websocket connecting...");this.waitingPong=false;try{this.socket=new WebSocket("ws://chat.goodgame.ru:8080/chat/websocket")||null}catch(e){}if(!this.socket){console.log("Can't create sockjs-client.");return false}this.socket.onmessage=this._onMessage.bind(this);this.socket.onclose=this._onClose.bind(this)};Notify.prototype._onMessage=function(event){try{var msg=JSON.parse(event.data)}catch(err){console.log(err);return}if(this.user==666)console.log(msg);switch(msg.type){case"timer":this._timerCallback&&this._timerCallback(msg.data);break;case"pong":this.waitingPong=false;break;case"welcome":this.subscribe(this.user,this.token,this.obj);break;case"canSubscribe":this.canSubscribe=true;this._subscribeObjects();break;case"objectEvent":if(typeof this.subscribeObjects[msg.objid]!="undefined"){var data=this.subscribeObjects[msg.objid];data.callback.apply(data.obj,[msg.data])}break;case"notifyEvent":if(NotifySettings["all"])return false;if(typeof $.notifyEvents=="undefined"||typeof $.notifyEvents[msg.data.event]=="undefined"){console.log("no listeners for "+msg.data.event);return false}$.notifyEvents[msg.data.event].forEach(function(data){data.callback.apply(data.obj,[msg.data.eid,msg.data.data,msg.data.common])});break}return true};Notify.prototype.addObject=function(objid,callback){if(this.subscribeObjects.indexOf(objid)!=-1)return false;this.subscribeObjects[objid]=callback;if(this.canSubscribe)this.subscribeObj(objid);return true};Notify.prototype._subscribeObjects=function(){for(var key in this.subscribeObjects){if(!this.subscribeObjects.hasOwnProperty(key))continue;this.subscribeObj(key)}if(this._timerCallback)this._sendGetTimer()};Notify.prototype.closeMsg=function(msgId){localDB.set("eventSystemAction",JSON.stringify({rnd:Math.random(),action:"close",id:msgId}))};Notify.prototype.settingsMsg=function(settings){localDB.set("eventSystemAction",JSON.stringify({rnd:Math.random(),action:"settings",settings:settings}))};Notify.prototype._storageEvent=function(event){var data=JSON.parse(localDB.get("eventSystemAction"))||{};if(typeof eventSystemActionLast!="undefined"&&data.rnd==eventSystemActionLast)return;eventSystemActionLast=data.rnd;switch(data.action){case"close":var li=data.id=="all"?$(this.document).find("ul#notifySystem").find("li"):$(this.document).find("ul#notifySystem").find("li#"+data.id);li.fadeOut(300,function(){$(li).remove()});break;case"settings":NotifySettings=data.settings;break}};Notify.prototype.subscribe=function(userId,userToken,object){this._send("notifySubscribe",{user_id:userId,token:userToken,obj:object})};Notify.prototype.subscribeObj=function(objid){this._send("subscribeObject",{id:objid})};Notify.prototype._sendGetTimer=function(){this._send("getTimer",{})};Notify.prototype.getTimer=function(callback){this._timerCallback=callback;if(this.canSubscribe)this._sendGetTimer()};Notify.prototype._send=function(type,data){if(!this.socket||this.socket.readyState!=1){return}if(this.user==666)console.log({type:type,data:data});try{this.socket.send(JSON.stringify({type:type,data:data}))}catch(e){}}})(this,this.jQuery);$(function(){if(User&&Token&&typeof window.notify=="undefined")window.notify=new Notify(document,User,Token)});function renderNotifyBlock(options){var settings={id:"",title:"",body:"",icon:"/images/notify1.png",sound:1,link:false,onClick:function(){console.log("onClick")},onClose:function(){console.log("onClose")},_close:function(){var li=$(this);window.notify.closeMsg(li.attr("id"));li.fadeOut(300,function(){$(this).remove()})}};$.extend(settings,options);var block;var system=$("#notifySystem");if(system.find("#"+settings.id).length){block=$("#notifySystem").find("#"+settings.id);block.find(".title").html(settings.title);block.find(".text").html(settings.body);block.find(".more").html(block.find(".more").text()?"+"+(parseInt(block.find(".more").text())+1):"+1")}else{block=$('<li><div class="onlineNotify"><div class="close"></div><div class="icon"></div><div class="title"></div><div class="text"></div><div class="more"></div></div></li>');block.find(".title").html(settings.title);block.find(".text").html(settings.body);block.find(".icon").css({"background-image":"url("+settings.icon+")"});block.attr("id",settings.id);system.append(block.hide());block.show()}if(NotifySettings["sound"]){var soundMsg=new Audio("/files/msg"+settings.sound+".mp3");soundMsg.play()}block.bind("contextmenu",function(e){e.preventDefault();return false});block.mousedown(function(e){if(!$(e.target).hasClass("close")&&e.button!=2){if(settings.link){if(e.button==0){redirect(settings.link)}else{_blank(settings.link)}}else{settings.onClick.call(block)}}else{settings._close.call(block);settings.onClose.call(block)}});return block}$(function(){$("header").notify("newPM",function(id,value1,value2){if(typeof notifyCurrentDialog!="undefined"&&value1.dialog==notifyCurrentDialog){return}$("#pms").find(".count").html(value1.total);if(!NotifySettings["pm"])return;var title="Новое сообщение от "+value1.from;var block=renderNotifyBlock({id:"pm"+value1.dialog,title:title,body:value1.text,icon:value1.avatar,sound:3,link:"pm/"+value1.dialog+"/",onClose:function(){$.post(AJAX_PATH+"/pm/setread/",{ids:[value1.dialog]},function(data){$("#pms").find(".count").html(data.count)},"json")}})});$("header").notify("customNotify",function(id,value1,value2){$("#sms").find(".count").html(value1.count);if(!NotifySettings["st"]&&value2.icon==3)return;if(!NotifySettings["bn"]&&value2.icon==2)return;if(!NotifySettings["sm"]&&value2.icon==1)return;var icon="/images/notify"+value2.icon+".png";if(value2.icon==4&&value2.data){icon="/images/donat"+(value2.data>=1e4?"6":value2.data>=3e3?"5":value2.data>=500?"4":value2.data>=300?"3":value2.data>=100?"2":"1");icon+=".png"}if(value2.icon==5){icon="/images/prem.png"}var block=renderNotifyBlock({id:id,title:value2.title,body:value2.text,icon:icon,link:value2.link||"pm/sms/",onClose:function(){$.post(AJAX_PATH+"/pm/setread/",{ids:[value2.smid],type:1},function(data){$("#sms").find(".count").html(data.count)},"json")}})});$("#favcount").notify("updateFavouriteStreams",function(id,value,channel){$(this).html(value);var text='На канале <a href="'+channel.link+'">'+channel.streamName+"</a> началась трансляция по игре "+channel.game;var block=renderNotifyBlock({id:id,title:"Трансляция",body:text,icon:"/images/notify3.png",link:channel.link,onClose:function(){$.post(AJAX_PATH+"/pm/setread/",{ids:[channel.smid],type:1},function(data){$("#favcount").html(data.count)},"json")}})})});(function($,doc){$.fn.pms=function(arg1){return new PMS(this,arg1)}})(jQuery,window.document);function PMS(elem,pm_id){this.pm_id=pm_id;this.elem=$(elem);this.form=this.elem.find("#send");this.dialog=this.elem.find(".dialog-list");this.editor=this.elem.find(".comments_editor");this.scrollWrapper=this.elem.find(".tse-scrollable");this.init();this.bindButtons()}PMS.prototype.bindButtons=function(){this.form.submit($.proxy(this.send,this));this.elem.on("click","#loadMore",$.proxy(this.loadMore,this))};PMS.prototype.init=function(){var that=this;this.scrollWrapper.TrackpadScrollEmulator();this.scrollContent=this.elem.find(".tse-scroll-content");this.scrollContent.on("DOMMouseScroll mousewheel",function(e){var scrollTo=null;if(e.type=="mousewheel"){scrollTo=e.originalEvent.wheelDelta*-1}else if(e.type=="DOMMouseScroll"){scrollTo=40*e.originalEvent.detail}if(scrollTo){e.preventDefault();$(this).scrollTop(scrollTo+$(this).scrollTop())}});this.scrollWrapper.resizable({maxHeight:1e3,maxWidth:1093,minHeight:73,minWidth:620,resize:function(){that.scrollWrapper.TrackpadScrollEmulator("recalculate")}});initBBEditor4_forum("comment-editor",this.form);if(this.pm_id){this.loadDialog();notifyCurrentDialog=this.pm_id}else{this.dialog.removeClass("loading");new UsersAutoComplete(that.elem.find("#pm_to_input"),function(arg,input,data){that.elem.find("#pm_to").html(data.sign).show();that.elem.find("#pm_to_search").hide();that.getDialogAndLoad(data.id)})}};PMS.prototype.loadMore=function(e){var block=$(e.currentTarget).addClass("loading").html("");var that=this;$.post(AJAX_PATH+"/pm/get/",{id:this.pm_id,from:block.data("from")},function(data){var oldH=that.scrollContent[0].scrollHeight;block.replaceWith(data);that.scrollWrapper.TrackpadScrollEmulator("recalculate");that.scrollContent.scrollTop(that.scrollContent[0].scrollHeight-oldH)})};PMS.prototype.loadNew=function(callback){this.callback=callback;var last=this.dialog.find(".dialog-block").last().data("id");$.post(AJAX_PATH+"/pm/send/",{id:this.pm_id,text:"",last:last},$.proxy(this.afterSend,this))};PMS.prototype.getDialogAndLoad=function(to){var that=this;$.post(AJAX_PATH+"/pm/new/",{to:to},function(data){if(data.pm){that.dialog.addClass("loading").html("");that.pm_id=notifyCurrentDialog=data.pm;that.loadDialog()}},"json")};PMS.prototype.loadDialog=function(e){$.post(AJAX_PATH+"/pm/get/",{id:this.pm_id},$.proxy(this.onloadDialog,this))};PMS.prototype.onloadDialog=function(data){var that=this;this.dialog.removeClass("loading").html(data);this.scrollWrapper.add(".tse-scroll-content").animate({height:"375px",scrollTop:that.dialog.innerHeight()},function(){that.scrollWrapper.TrackpadScrollEmulator("recalculate")})};PMS.prototype.send=function(e){if(!this.pm_id)return false;var text=tinyMCE.activeEditor.getContent();var last=this.dialog.find(".dialog-block").last().data("id");this.editor.addClass("disabled");tinyMCE.activeEditor.setContent("");$.post(AJAX_PATH+"/pm/send/",{id:this.pm_id,text:text,last:last},$.proxy(this.afterSend,this));e.preventDefault();return true};PMS.prototype.afterSend=function(data){this.dialog.find(".blank-block").remove();var first=$(data).first().data("id");$.each(this.dialog.find(".dialog-block"),function(o,elem){if($(elem).data("id")>=first)$(elem).remove()});this.dialog.append(data);this.scrollWrapper.TrackpadScrollEmulator("recalculate");this.scrollWrapper.find(".tse-scroll-content").animate({scrollTop:$(".dialog-list")[0].scrollHeight},function(){});this.editor.removeClass("disabled");if(typeof this.callback=="function"){this.callback();this.callback=null}};function showStatusPanel(){var selected=$(".dialog").find(".checkbox.active").length;var total=$(".dialog").find(".checkbox").length;var s=$("#status");if(selected>0){s.css({visibility:"visible"});$(".status").html("Выбрано "+selected+" из "+total);if($(".message-table").find(".selected.unread").length){s.find(".read").show()}else{s.find(".read").hide()}}else{s.css({visibility:"hidden"})}}function saveNotifySettings(opts){window.notify.settingsMsg(opts);$.post(AJAX_PATH+"/notify/settings/",opts,function(data){})}function closeAllNotifies(){var li=$("ul#notifySystem").find("li");li.fadeOut(300,function(){$(li).remove()});if(window.notify)window.notify.closeMsg("all")}function bindControls(){$("#content").unbind().on("click",".pms-table .dialog td:not(:first-child)",function(){document.location.href="/pm/"+$(this).closest(".dialog").attr("rel")+"/"}).on("click",".dialog a.checkbox",function(e){e.preventDefault();e.stopImmediatePropagation();$(this).toggleClass("active");$(this).closest(".dialog").toggleClass("selected");var selected=$(".dialog").find(".checkbox.active").length;var total=$(".dialog").find(".checkbox").length;if(total==selected){$(".message-table").find("th").find("a.checkbox").addClass("active")}else{$(".message-table").find("th").find("a.checkbox").removeClass("active")}showStatusPanel()}).on("click","th a.checkbox",function(e){e.preventDefault();$(this).toggleClass("active");if($(this).hasClass("active")){$(".dialog").addClass("selected").find(".checkbox").addClass("active")}else{$(".dialog").removeClass("selected").find(".checkbox").removeClass("active")}showStatusPanel()}).on("click","#status .read",function(e){var type=$(this).parents(".pms-table").length?0:1;e.preventDefault();var all=$(".dialog.unread").has(".checkbox.active").removeClass("unread");all.find(".more").remove();$(".message-table").find("tr.selected, th").removeClass("selected").find(".checkbox").removeClass("active");var ids=[];all.each(function(){ids.push($(this).attr("rel"))});if(ids.length)$.post(AJAX_PATH+"/pm/setread/",{ids:ids,type:type},function(data){$(".switch.active").find(".count").html(data.count);if(type){$("#top").find(".inbox-sms").find(".count").html(data.count)}else{$("#top").find(".inbox-message").find(".count").html(data.count)}},"json");showStatusPanel()}).on("click","#status .delete",function(e){var type=$(this).parents(".pms-table").length?0:1;if(confirm("Вы действительно хотите полностью удалить отмеченные диалоги? Отменить это действие будет невозможно.")){e.preventDefault();var all=$(".dialog").has(".checkbox.active");$(".message-table").find("tr.selected, th").removeClass("selected").find(".checkbox").removeClass("active");var ids=[];all.each(function(){ids.push($(this).attr("rel"))});all.remove();if(ids.length)$.post(AJAX_PATH+"/pm/delete/",{ids:ids,type:type},function(data){});showStatusPanel()}}).on("click",".icon-cog",function(e){$(".preference-menu").toggle();e.preventDefault();e.stopImmediatePropagation()}).on("click",".preference-menu a",function(e){var span=$(this).find(".checkbox");span.toggleClass("active");NotifySettings[$(this).attr("href").substring(1)]=span.hasClass("active")?1:0;saveNotifySettings(NotifySettings);e.preventDefault()});$(".message-switcher").tabsAjaxSwitcher("#content-left",[])}$(function(){var restreamBlock=$("#restream");restreamBlock.on("click",".channel",function(e){e.preventDefault();$("#restream").find(".channel").removeClass("active");$(this).addClass("active");$(".restreamtab").removeClass("active");$(".restreamtab[rel="+$(this).data("channel")+"]").addClass("active")});restreamBlock.on("click","#stopstart",function(e){e.preventDefault();var player=restreamBlock.find(".preference-block").data("key");$.post(AJAX_PATH+"/player/resetrestream/",{player:player,s:$(this).data("value")},function(data){restreamBlock.html(data)})});restreamBlock.on("click",".preference-btn",function(e){e.preventDefault();$(".preference-block").toggle();$("#channel").add(".content").css({overflow:"visible"})});restreamBlock.on("click","#btnSave",function(e){e.preventDefault();var current=restreamBlock.find(".channel.active").data("channel");var links=[];restreamBlock.find(".restreamtab").each(function(ind,elem){links.push({s:$(elem).attr("rel"),k:$(elem).find("input[placeholder]").val()})});var player=restreamBlock.find(".preference-block").data("key");$.post(AJAX_PATH+"/player/restream/",{player:player,key:links,srv:current},function(data){restreamBlock.html(data)})});$("#showAdvert").click(function(e){var self=this;$.cachedScript("//goodgame.ru/js/libraries/sockjs-0.3.min.js").done(function(){e.preventDefault();var key=$(self).data("key");var pwd=$(self).data("pwd");var socket=new SockJS("http://chat.goodgame.ru:8081/chat");socket.onopen=function(){socket.send(JSON.stringify({type:"commercial",data:{action:"show",key:key,pwd:pwd}}));socket.close()}});var timeout=$(this).data("timeout");if(timeout)window.clearInterval(timeout);$(self).siblings(".status-txt").data("start",new Date).text("Таймер: 0:00");timeout=window.setInterval(function(){var b=$(self).siblings(".status-txt");var d=b.data("start");var diff=Math.round((new Date-d)/1e3);var mins=Math.floor(diff/60);var secs=diff-mins*60;if(secs<10)secs="0"+secs;b.text("Таймер: "+mins+":"+secs)},1e3)});restreamBlock.restreamStatus(restreamBlock.data("key"))});(function(global,$){if(!$){throw new Error("jQuery not init.")}$.fn.extend({restreamStatus:function(key){if($(this).length)return new RestreamStatusChecker(this,key)},MainpageSlider:function(){if($(this).length)return new MainpageSlider(this)}})})(this,this.jQuery);function MainpageSlider(block){this.block=$(block);this.wtimer=false;this.iswheeling=false;this.currentSlide=0;this.touchStart=0;this.touchStartMargin=0;this.player=false;this.bind();this._notify()}MainpageSlider.prototype.bind=function(reset){if(reset){this.currentSlide=0}this.scroll=this.block.find(".streams-list");this.totalSlides=this.block.find(".slide").length-1;this.dots=this.block.find(".streams-navigation").find("a");this.init()};MainpageSlider.prototype._notify=function(){var self=this;self.block.on("change",function(){self.bind(true)});self.scroll.notifySubscribe(function(data){var elem=$("<div>"+data+"</div>");if(!elem.find("div.li").length)return;elem.find(".streams-list").css("margin-left",self.scroll.css("margin-left"));self.block.html(elem.html());self.bind(false);self._goToSlide(self.currentSlide);var id;if(id=$("#streams-content").data("streamid")){$("#"+id).addClass("selected")}else{self.block.find("div.li").eq(0).addClass("selected")}})};MainpageSlider.prototype.init=function(){var self=this;self.block.on("click",".streams-navigation a",function(e){e.preventDefault();self._goToSlide($(this).attr("rel"))});self.block.on("mousewheel DOMMouseScroll MozMousePixelScroll",".streams-list",function(e){e.preventDefault();var delta=0;if(e.type=="mousewheel"){delta=e.originalEvent.wheelDelta}else if(e.type=="DOMMouseScroll"){delta=e.originalEvent.detail*-1}if(!delta||isNaN(delta))return;if(self.wtimer)clearTimeout(self.wtimer);if(!self.iswheeling){self._goToSlide(parseInt(self.currentSlide)+(delta<0?1:-1))}self.iswheeling=true;self.wtimer=setTimeout(function(){self.iswheeling=false},70)});self.block.on("touchstart",".streams-list",function(event){var touch=event.originalEvent.touches[0];self.touchStart=touch.pageX;self.touchStartMargin=-parseInt(self.scroll.css("margin-left"))});self.block.on("touchmove",".streams-list",function(event){var touch=event.originalEvent.touches[0];var moveTo=self.touchStartMargin+(self.touchStart-touch.pageX);self.scroll.css({"margin-left":"-"+moveTo+"px"})});self.block.on("touchend",".streams-list",function(event){var finish=-parseInt(self.scroll.css("margin-left"));var slide=finish>self.touchStartMargin?Math.ceil(finish/305):Math.floor(finish/305);self._goToSlide(slide)});$.cachedScript("/js/libraries/clappr/clappr.js").done(function(){self.block.on("mouseleave","div.li",function(e){VideoPreview.remove()});self.block.on("mouseenter","div.li",function(e){VideoPreview.create($(this).find(".stream-img"),$(this).attr("id").substr(1),$(this).find(".preview").attr("src"),1e3)})})};MainpageSlider.prototype._goToSlide=function(n){if(n>this.totalSlides)n=0;if(n<0)n=this.totalSlides;this.currentSlide=n;this.scroll.css({"margin-left":n*-304+"px"});this.dots.removeClass("selected");this.dots.eq(n).addClass("selected")};function RestreamStatusChecker(elem,key){this.elem=$(elem);this.currentWorker=0;this._cycle=0;this.key=key;this.xml=false;this._ports=["http://stream3.goodgame.ru:8080/stat","http://stream6.goodgame.ru:8080/stat"];this.status=false;this.onTimer()}RestreamStatusChecker.prototype.init=function(){this.timeout=setTimeout($.proxy(this.onTimer,this),1e4)};RestreamStatusChecker.prototype.onTimer=function(){if(this.elem.find("#stopstart").data("value")==0){this.init()}else{this.statusLbl=this.elem.find(".status-txt");this._cycle=0;this._getStatus(this.currentWorker)}};RestreamStatusChecker.prototype._onFound=function(data){this._cycle=0;this.statusLbl.addClass("ok").html("Ретрансляция запущена");this.init()};RestreamStatusChecker.prototype._notFound=function(){this._cycle=0;this.statusLbl.html("Ретрансляция не запущена");this.init()};RestreamStatusChecker.prototype._onError=function(){this.currentWorker++;if(this.currentWorker>this._ports.length-1)this.currentWorker=0;this._cycle++;if(this._cycle<this._ports.length){this._getStatus(this.currentWorker)}else{this._notFound()}};RestreamStatusChecker.prototype._onLoad=function(data){var ret=0;var self=this;var xmlDoc=this.xml.responseXML;var streams=$(xmlDoc).find("server").find("application:has(name:contains(retwitch))").find("live").find("stream");streams.each(function(i,elem){if($(elem).find("name").text()==self.key||$(elem).find("name").text()==self.key+"_720"){ret=$(elem).find("bw_out").text();return false}});if(ret!=0){this._onFound(ret)}else{this._onError()}};RestreamStatusChecker.prototype._getStatus=function(workerId){if(this._cycle)this.statusLbl.removeClass("ok").html("Проверка статуса... "+(this._ports.length-this._cycle));this.xml=new window.XMLHttpRequest;this.xml.open("GET",this._ports[workerId],true);this.xml.send();this.xml.onload=$.proxy(this._onLoad,this);this.xml.onerror=$.proxy(this._onError,this)};$(function(){});function streams_callback(user){redirect("channel/new/")}function initVideoModule(){$("#streams-right").on("click",".streams-list div.li",function(event){if(event.metaKey){_blank($(this).data("link"));return false}if($(event.target).hasClass("channel-link")){return true}var li=$(this);if(li.hasClass("selected")||li.hasClass("direct-link")){redirect(li.data("link"));return false}var block=$("#streams-left");$.post(AJAX_PATH+"/player/get/",{key:li.attr("id")},function(data){block.find("#streams-content").data("streamid",li.attr("id")).html(data.content);$("#streams-inner-list").find("div.li").removeClass("selected");li.addClass("selected")},"json");return false}).on("click",".icons a.icon-refresh-new",function(){var link=$(this).addClass("loading");var $block=$("#streams-inner-list").addClass("loading");$.post(AJAX_PATH+"/streams/index_list/",{},function(html){if(html){$block.html(html).removeClass("loading");$block.find("li.selected").removeClass("selected");var id;if(id=$("#streams-content").data("streamid")){$(".streams-list").find("li.selected").removeClass("selected");$("#"+id).addClass("selected")}link.removeClass("loading");$block.trigger("change")}});return false})}$(function(){$(document).keyup(function(e){if(e.altKey&&e.keyCode==84)goTheaterMode()})});function exitTheaterMode(){if($("#channel").hasClass("popup"))return false;if(window._gaq){window._gaq.push(["_trackEvent","theaterMode","switch","off"])}$("#resizer").add($("#overlay")).fadeOut(300,function(){$(this).remove();$("body").removeClass("theater").css({overflow:"auto"})});$(".full-screen").show();$(".theater-screen-exit").hide();$(".theater-screen").removeClass("disabled");if($("#chatIframe").length==0)openChat();animateBack($("#streams-left"));animateBack($("#streams-right"));animateBack($("#player--tabs"));if(window.chat)window.chat._toggleClose(true)}function animateBack(block){var startPos=block.data("startpos");block.css({bottom:"auto",width:block.width(),height:block.height()});block.animate({top:startPos.top,left:startPos.left,width:startPos.width,height:startPos.height},200,function(){block.removeAttr("style")})}function goTheaterMode(){if($("#channel").hasClass("popup"))return false;if($("body").hasClass("theater")){exitTheaterMode();return true}if($("#chatIframe").length==0){openChat();setTimeout(goTheaterMode,200);return false}if(window.chat)window.chat._toggleClose(false);if(window._gaq){window._gaq.push(["_trackEvent","theaterMode","switch","on"])}$("body").addClass("theater").css({overflow:"hidden"});var overlay=$('<div id="overlay"></div>');var resizer=$('<div id="resizer"></div>');$("body").append(resizer).append(overlay);overlay.animate({opacity:1},300);resizer.animate({opacity:1},300);animateBlock({block:$("#streams-left"),top:45,pos:"left",size:78});animateBlock({block:$("#streams-right").css({"padding-left":"1px"}),pos:"right",size:22});animateBlock({block:$("#player--tabs").css({"padding-top":"15px"}),pos:"left",size:78,height:"30px"});$(".full-screen").hide();$(".theater-screen-exit").show();$(".theater-screen").addClass("disabled");$("#resizer").on("mousedown",function(e){$(this).addClass("draggable");$("body").on("mousemove",function(e){var percent=e.pageX/$(window).width();if(percent>.9||percent<.4){return}$("#streams-left").css({right:(1-percent)*100+"%"});$("#streams-right").css({left:percent*100+"%"});$(".draggable").offset({left:e.pageX-$(".draggable").outerWidth()/2})});e.preventDefault()});$("body").on("mouseup blur mouseexit",function(){$("body").off("mousemove");$(".draggable").removeClass("draggable")});return true}function animateBlock(options){var defaults={block:null,top:0,bottom:0,pos:"left",size:0,height:"auto"};var opts=$.extend({},defaults,options);var block=opts.block;var currPos=block.offset();block.css({top:currPos.top-$(window).scrollTop(),left:currPos.left,width:block.width(),height:block.height()});block.css({position:"fixed","z-index":100002});block.data("startpos",{top:currPos.top-$(window).scrollTop(),left:currPos.left,width:block.width(),height:block.height()});var targetWidth=$(window).width()*(opts.size/100);var l=100-opts.size;block.animate({top:opts.top,left:opts.pos=="left"?0:l+"%",right:opts.pos=="right"?0:l+"%",bottom:opts.bottom,width:targetWidth,height:opts.height=="auto"?$(window).height():opts.height},300,function(){block.css({width:"auto",height:opts.height})})}function VideoPreview(){this.block=false;this.player=false;this.timeout=false}VideoPreview.create=function(block,key,poster,delay){var self=this;if(delay===undefined)delay=500;VideoPreview.debounce(function(){$("#VideoPreviewPl").remove();self.block=$(block);var width=self.block.width();var height=self.block.height();var pl=$("<div id=VideoPreviewPl></div>");pl.insertAfter(block);self.player=new Clappr.Player({source:"http://goodgame.ru/channel/getpreview.m3u8?key="+key,autoPlay:true,chromeless:true,mute:true,parentId:"#VideoPreviewPl",width:width,height:height});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement