",{class:"highlighter-content"});highlighter.append(content).prependTo(this.container);this.input.css("backgroundColor","transparent");return highlighter};MentionsInput.prototype._setHighligherStyle=function(){var property,_i,_len,_results;_results=[];for(_i=0,_len=mimicProperties.length;_i<_len;_i++){property=mimicProperties[_i];_results.push(this.highlighter.css(property,this.input.css(property)))}return _results};MentionsInput.prototype._handleLeftRight=function(event){var delta,deltaEnd,deltaStart,sel,value;if(event.keyCode===Key.LEFT||event.keyCode===Key.RIGHT){value=this.input.val();sel=Selection.get(this.input);delta=event.keyCode===Key.LEFT?-1:1;deltaStart=value.charAt(sel.start)===this.marker?delta:0;deltaEnd=value.charAt(sel.end)===this.marker?delta:0;if(deltaStart||deltaEnd){return Selection.set(this.input,sel.start+deltaStart,sel.end+deltaEnd)}}};MentionsInput.prototype._mark=function(name){return name+this.marker};MentionsInput.prototype._update=function(){this._updateMentions();return this._updateValue()};MentionsInput.prototype._updateMentions=function(){var i,index,marked,mention,newval,selection,value,_i,_len,_ref;value=this.input.val();if(value){_ref=this.mentions.slice(0);for(i=_i=0,_len=_ref.length;_i<_len;i=++_i){mention=_ref[i];marked=this._mark(mention.name);index=value.indexOf(marked);if(index===-1){this.mentions.splice(i,1)}else{mention.pos=index}value=this._replaceWithSpaces(value,marked)}newval=this.input.val();while((index=value.indexOf(this.marker))>=0){value=this._cutChar(value,index);newval=this._cutChar(newval,index)}if(value!==newval){selection=Selection.get(this.input);this.input.val(newval);return Selection.set(this.input,selection.start)}}};MentionsInput.prototype._addMention=function(mention){return this.mentions.push(mention)};MentionsInput.prototype._onSelect=function(event,ui){return this._addMention({name:ui.item.value,pos:ui.item.pos,uid:ui.item.uid})};MentionsInput.prototype._updateValue=function(){var hlContent,markedName,mention,value,_i,_len,_ref;value=hlContent=this.input.val();_ref=this.mentions;for(_i=0,_len=_ref.length;_i<_len;_i++){mention=_ref[_i];markedName=this._mark(mention.name);hlContent=hlContent.replace(markedName,"
"+mention.name+"");value=value.replace(markedName,"@["+mention.name+"]("+mention.uid+")")}this.hidden.val(value);return this.highlighterContent.html(hlContent)};MentionsInput.prototype._updateVScroll=function(){var scrollTop;scrollTop=this.input.scrollTop();this.highlighterContent.css({top:"-"+scrollTop+"px"});return this.highlighter.height(this.input.height())};MentionsInput.prototype._updateHScroll=function(){var scrollLeft;scrollLeft=this.input.scrollLeft();this.highlighterContent.css({left:"-"+scrollLeft+"px"});return this.highlighterContent.width(this.input.get(0).scrollWidth)};MentionsInput.prototype._replaceWithSpaces=function(value,what){return value.replace(what,Array(what.length).join(" "))};MentionsInput.prototype._cutChar=function(value,index){return value.substring(0,index)+value.substring(index+1)};MentionsInput.prototype.append=function(){var piece,pieces,value,_i,_len;pieces=1<=arguments.length?__slice.call(arguments,0):[];value=this.input.val();for(_i=0,_len=pieces.length;_i<_len;_i++){piece=pieces[_i];if(typeof piece==="string"){value+=piece}else{this._addMention({name:piece.name,uid:piece.uid,pos:value.length});value+=this._mark(piece.name)}}this.input.val(value);return this._updateValue()};MentionsInput.prototype.getValue=function(){return this.hidden.val()};MentionsInput.prototype.clear=function(){this.input.val("");return this._update()};MentionsInput.prototype.destroy=function(){this.input.areacomplete("destroy");this.input.off("."+namespace).attr("name",this.hidden.attr("name"));return this.container.replaceWith(this.input)};return MentionsInput}(MentionsBase);MentionsContenteditable=function(_super){var insertMention,mentionTpl;__extends(MentionsContenteditable,_super);MentionsContenteditable.prototype.selector="[data-mention]";function MentionsContenteditable(input,options){this.input=input;this._onSelect=__bind(this._onSelect,this);this._addMention=__bind(this._addMention,this);MentionsContenteditable.__super__.constructor.call(this,this.input,options);this.autocomplete=this.input.editablecomplete({matcher:this._getMatcher(),suffix:this.marker,select:this._onSelect,source:this.options.source,delay:this.options.delay,showAtCaret:this.options.showAtCaret});this._initValue();this._initEvents()}mentionTpl=function(mention){return'
'+mention.value+""};insertMention=function(mention,pos,suffix){var node,range,selection;selection=window.getSelection();node=selection.focusNode;range=selection.getRangeAt(0);range.setStart(node,pos.start);range.setEnd(node,pos.end);range.deleteContents();range.insertNode(mention);if(suffix){suffix=document.createTextNode(suffix);$(suffix).insertAfter(mention);range.setStartAfter(suffix)}else{range.setStartAfter(mention)}range.collapse(true);selection.removeAllRanges();selection.addRange(range);return mention};MentionsContenteditable.prototype._initEvents=function(){return this.input.find(this.selector).each(function(_this){return function(i,el){return _this._watch(el)}}(this))};MentionsContenteditable.prototype._initValue=function(){var mentionRE,value;value=this.input.html();mentionRE=/@\[([^\]]+)\]\(([^ \)]+)\)/g;value=value.replace(mentionRE,function(_this){return function(match,value,uid){return mentionTpl({value:value,uid:uid})+_this.marker}}(this));return this.input.html(value)};MentionsContenteditable.prototype._addMention=function(data){var mention,mentionNode;mentionNode=$(mentionTpl(data))[0];mention=insertMention(mentionNode,data.pos,this.marker);return this._watch(mention)};MentionsContenteditable.prototype._onSelect=function(event,ui){this._addMention(ui.item);this.input.trigger("change."+namespace);return false};MentionsContenteditable.prototype._watch=function(mention){return mention.addEventListener("DOMCharacterDataModified",function(e){var offset,range,sel,text;if(e.newValue!==e.prevValue){text=e.target;sel=window.getSelection();offset=sel.focusOffset;$(text).insertBefore(mention);$(mention).remove();range=document.createRange();range.setStart(text,offset);range.collapse(true);sel.removeAllRanges();return sel.addRange(range)}})};MentionsContenteditable.prototype.update=function(){this._initValue();this._initEvents();return this.input.focus()};MentionsContenteditable.prototype.append=function(){var piece,pieces,value,_i,_len;pieces=1<=arguments.length?__slice.call(arguments,0):[];value=this.input.html();for(_i=0,_len=pieces.length;_i<_len;_i++){piece=pieces[_i];if(typeof piece==="string"){value+=piece}else{value+=mentionTpl({value:piece.name,uid:piece.uid})+this.marker}}this.input.html(value);this._initEvents();return this.input.focus()};MentionsContenteditable.prototype.getValue=function(){var value;value=this.input.clone();$(this.selector,value).replaceWith(function(){var name,uid;uid=$(this).data("mention");name=$(this).text();return"@["+name+"]("+uid+")"});return value.html().replace(this.marker,"")};MentionsContenteditable.prototype.clear=function(){this.input.html("");return this._update()};MentionsContenteditable.prototype.destroy=function(){this.input.editablecomplete("destroy");this.input.off("."+namespace);return this.input.html(this.getValue())};return MentionsContenteditable}(MentionsBase);$.fn[namespace]=function(){var args,options,returnValue;options=arguments[0],args=2<=arguments.length?__slice.call(arguments,1):[];returnValue=this;this.each(function(){var instance;if(typeof options==="string"&&options.charAt(0)!=="_"){instance=$(this).data("mentionsInput");if(options in instance){return returnValue=instance[options].apply(instance,args)}}else{if(/INPUT|TEXTAREA/i.test(this.tagName)){return $(this).data("mentionsInput",new MentionsInput($(this),options))}else if(this.contentEditable==="true"){return $(this).data("mentionsInput",new MentionsContenteditable($(this),options))}}});return returnValue}}).call(this);
var CryForm=Controller.create({elements:{textarea:"text",".ui-kit-textarea":"textareaKit","input[name=cry-image]":"imageUpload"},events:{"focus textarea":"onFocus","blur textarea":"onBlur","keydown textarea":"onKeyDown","keyup textarea":"onKeyUp",submit:"onSubmit"},init:function(){this.submitting=false;this.specKeyCode=false;this.thumb=null;$(window).scroll(this.proxy(this.updateThumb));this.textareaKit.textareaKit();this.text.mentionsInput();this.singleHeight=this.text.outerHeight()},getFormData:function(){return{}},onFocus:function(event){this.resize(2,true)},onBlur:function(event){this.resize(1)},onSubmit:function(event){if(this.submitting)return false;this.submitting=true;var arr=this.el.serializeArray();var data={};for(var i in arr){data[arr[i].name]=arr[i].value}$.extend(data,this.getFormData());if(this.validate()){$.extend(data,{cry_path:window.location.pathname});$.post(this.el.attr("action"),data,this.proxy(this.onSuccess))}else{this.submitting=false}return false},onKeyDown:function(event){if(event.isDefaultPrevented()){return}if(!(event.shiftKey||event.altKey)&&event.keyCode===13){this.el.submit();event.preventDefault();event.stopPropagation()}else if(event.keyCode===229){this.specKeyCode=true}},onKeyUp:function(event){var keyCode,str;if(event.isDefaultPrevented()){return}if(isMobile.any&&this.specKeyCode){str=event.currentTarget.value;keyCode=str.charCodeAt(str.length-1);if(!(event.shiftKey||event.altKey)&&(keyCode===13||keyCode===10)){this.el.submit()}this.specKeyCode=false}},validate:function(){var val=this.text.val();val=val.replace(/[\r\n\s]/g,"");if(!(val||this.imageUpload.val())){return false}return true},onSuccess:function(data){this.submitting=false;if(!data.ok){this.text.notify(data.msg,"bottom-right")}else{this.reset();this.el.trigger("cry.add",[data.cry]);if(data.redirect_url){window.location=data.redirect_url}}},focus:function(){var t=this.text;if(!this.el.onScreen()){this.el.center(this.proxy(function(){this.resize(2)}))}else{this.resize(2)}},reset:function(){this.el.resetForm();this.textareaKit.textareaKit("reset")},resize:function(lines,skipFocusEvent){if(this.text.val().length)return;var height=this.singleHeight*lines+"px";this.text.css({height:height,minHeight:height});this.textareaKit.textareaKit("refresh");if(lines>1&&!skipFocusEvent){setTimeout(this.text.focus.bind(this.text),100)}},destroy:function(){Controller.prototype.destroy.call(this);this.text.mentionsInput("destroy")}});var AnswerForm=CryForm.create({events:$.extend({},CryForm.prototype.events,{"click .closeBlack":"clearReply"}),getFormData:function(){var data={"cry-cry":this.cry};if(this.parentAnswer){data["cry-parent"]=this.parentAnswer.id}return data},onSuccess:function(data){this.submitting=false;if(!data.ok){this.text.notify(data.msg,"bottom-right")}else{this.reset();this.el.trigger("cry.add",[data.answer]);this.clearReply()}},replyTo:function(answer){this.clearReply();this.parentAnswer=answer;if(!this.el.onScreen()){this.el.center()}this.elReplyTo=$(_.template($("#answerTo").html(),answer));this.elReplyTo.hide().appendTo(this.el).fadeIn("fast");this.focus()},clearReply:function(){if(this.elReplyTo)this.elReplyTo.remove();this.parentAnswer=null}});
var CrySidebar=Controller.create({elements:{".shoutsWrap":"bar",".wrapShoutMessage":"cryFormWrapper",".shoutsList":"list",".wrapShoutsList":"listWrapper",".messageShoutBtn":"btnShout",".js-shouts-follow":"followToggler"},events:{"click .cancelBtn":"hideCryForm","click .sendBtn":"submitCryForm","click .shoutsWrap .close":"onHideBar","click .messageShoutBtn":"showCryForm","cry.add .shoutWrite form":"onCryAdd","ifChecked .js-shouts-follow":"follow","ifUnchecked .js-shouts-follow":"unfollow"},maxCount:30,scrollTimeoutID:null,init:function(){if(isLocalStorageSupported()){this.open=JSON.parse(localStorage.getItem("shouts_open"));this.followed=JSON.parse(localStorage.getItem("shouts_follow"))}else{this.open=false;this.followed=false}this.pusher=$(".js-shouts-pushed");this.toggler=$(".js-topbar .shoutsLink");this.topbar=$(".js-topbar");if(this.followed===null){this.follow()}this.followToggler.prop("checked",this.followed).iCheck().show();this.followLabel=this.el.find("label[for="+this.followToggler.attr("id")+"]");this.iscroll=new IScroll(".js-shouts-scroller-wrapper",{mouseWheel:true,scrollbars:true,fadeScrollbars:true,shrinkScrollbars:"clip",disableMouse:true});this.list.on("sse.cry",this.proxy(this.pushCry));this.list.on("sse.answer",this.proxy(this.pushAnswer));this.cryForm=new CryForm({el:$("form",this.cryFormWrapper)});if(this.open){this.showBar(false)}if(this.autoShow){if($(window).width()>=1440){this.showBar(false);if(isLocalStorageSupported())localStorage.setItem("shouts_open",true)}else{this.hideBar(false);if(isLocalStorageSupported())localStorage.setItem("shouts_open",false)}}this.toggler.on("click",this.proxy(this.onToggleBar));this.topbar.on("ensure-cries-sidebar-closed",this.proxy(this.onHideBar));$(window).resize(_.throttle(this.proxy(this.updateScroll),60))},pushCry:function(event,data){if(!Auth.user||Auth.user.id!=$(data.cry_tiny).data("author")){var cry=new Cry({el:data.cry_tiny,sidebar:this});cry.el.addClass("markNewItem");if(this.open){cry.el.css({opacity:0}).insertBefore($("li:not(.it-is-pinned):first",this.list)).animate({opacity:1},function(){setTimeout(function(){cry.el.removeClass("markNewItem")},2e3)});this.list.children().slice(this.maxCount).remove();this.updateScroll()}else{if(Auth.user&&this.followed){var hidden_css={marginLeft:"100%",opacity:0};var visible_css={marginLeft:0,opacity:1};cry.el.css(hidden_css).appendTo(this.pusher).on("click",function(){window.location.href=cry.el.find(".commentsAnchor").attr("href")}).animate(visible_css,200,function(){setTimeout(function(){cry.el.removeClass("markNewItem");cry.el.animate(hidden_css,200,function(){cry.el.remove()})},5e3)})}}}},pushAnswer:function(event,data){var $cry=this.list.children("[data-id="+data.cry_id+"]");if(!$cry.length)return;var $counter=$(".commentsAnchor",$cry),count=parseInt($counter.text(),10);$counter.text(count+1)},computeHeight:function(){var borderHeight=$(".js-topbar").height()+$(".shoutHead",this.el).height()+this.cryFormWrapper.filter(":visible").height()+$(".shouts-footer",this.el).outerHeight();return $(window).height()-borderHeight},initCries:function(cries){$("li",cries).each(this.proxy(function(ind,el){new Cry({el:el,sidebar:this})}))},updateScroll:function(){this.listWrapper.height(this.computeHeight());this.iscroll.refresh()},follow:function(event){this.followed=true;if(isLocalStorageSupported())localStorage.setItem("shouts_follow",true)},unfollow:function(event){this.followed=false;if(isLocalStorageSupported())localStorage.setItem("shouts_follow",false)},onToggleBar:function(event){event.preventDefault();if(!this.open){this.onShowBar(event)}else{this.onHideBar(event)}},onShowBar:function(event){this.topbar.trigger("ensure-miniplayer-closed");this.showBar(true);if(isLocalStorageSupported())localStorage.setItem("shouts_open",true)},onHideBar:function(event){this.hideBar(true);if(isLocalStorageSupported())localStorage.setItem("shouts_open",false)},showBar:function(animate){var duration=animate?150:0;this.bar.show();this.bar.removeClass("hideShouts",duration);this.el.attr("data-visible",true);this.open=true;this.toggler.parent().addClass("active");this.load()},hideBar:function(animate){var duration=animate?150:0;this.hideCryForm();this.el.attr("data-visible",false);this.open=false;this.toggler.parent().removeClass("active");this.bar.addClass("hideShouts",duration);if(Cry.answeringCry){Cry.answeringCry.hideAnswer()}},showCryForm:Auth.confirmed("написать вопль",function(event){this.cryFormWrapper.slideDown(150,this.proxy(function(){this.cryForm.focus();this.btnShout.addClass("active");this.updateScroll()}));this.cryFormWrapper.on("clickoutside",this.proxy(this.hideCryForm))}),hideCryForm:function(event){try{widget=$("textarea",this.cryFormWrapper).areacomplete("widget");if(event&&(event.target==this.btnShout[0]||widget.has(event.target).length))return}catch(e){}this.cryForm.reset();this.btnShout.removeClass("active");this.cryFormWrapper.slideUp(150,this.proxy(function(){this.updateScroll()}));this.cryFormWrapper.unbind("clickoutside",this.proxy(this.hideCryForm))},onCryAdd:function(event,cry){cry=new Cry({el:cry,sidebar:this});$("li:not(.it-is-pinned):first",this.list).before(cry.el);this.list.children().slice(this.maxCount).remove();this.hideCryForm();this.updateScroll()},submitCryForm:function(event){event.preventDefault();this.cryForm.el.submit()},load:function(){$.get(this.list.data("endless-source"),this.proxy(function(data){var content=this.list;content.html(data.list);this.updateScroll();if(data.more){this.list.endless({iscroll:this.iscroll,last:data.last})}this.initCries(content);this.iscroll.scrollTo(0,0)}))}});var Cry=Controller.create({elements:{".shout":"cry",".commentsAnchor span":"commentCount",".replyBtn":"btnReply",".shout-item--restore":"btnRecover"},events:{"click .replyBtn":"answer","click .deleteCry":"remove","click .shout-item--restore":"restore"},answerForm:null,init:function(){this.elFormWrapper=$("#cryAnswerForm");this.parentList=this.el.closest(".shoutsList");if(Auth.user&&(Auth.user.can_delete_cry||Auth.user.id==this.el.data("author"))){this.cry.addClass("editThisItem");this.btnRemove=$("
",{class:"deleteCry trashBask"});$(".history",this.cry).after(this.btnRemove)}},answer:Auth.confirmed("ответить",function(event){event.preventDefault();if(Cry.answeringCry){if(Cry.answeringCry==this)return;Cry.answeringCry.hideAnswer()}this.el.addClass("thisAnswerShout");this.btnReply.addClass("check");this.el.append(this.elFormWrapper);this.sidebar.updateScroll();this.elFormWrapper.fadeIn(150);this.answerForm=new AnswerForm({el:this.elFormWrapper.children(),cry:this.el.data("id")});this.answerForm.focus();this.elFormWrapper.bind("clickoutside",this.proxy(this.onClickOutside));Cry.answeringCry=this;this.answerForm.el.bind("cry.add",this.proxy(this.addAnswer))}),hideAnswer:function(){this.answerForm.el.unbind("cry.add",this.proxy(this.addAnswer));this.elFormWrapper.hide().appendTo(this.sidebar.el);this.el.removeClass("thisAnswerShout");this.btnReply.removeClass("check");this.answerForm.destroy();this.elFormWrapper.unbind("clickoutside",this.proxy(this.onClickOutside));this.sidebar.updateScroll();Cry.answeringCry=null},onClickOutside:function(event){if(event.target==this.btnReply[0])return;this.hideAnswer()},addAnswer:function(event,answer){answer=$(answer);new Answer({el:answer});this.hideAnswer();$(".allAnswerShout",this.el).remove();var ul=$("
",{class:"allAnswerShout"}).append(answer);this.el.append(ul);this.sidebar.updateScroll()},remove:function(event){event.preventDefault();$.post(this.el.data("delete-url"),{tiny:1},this.proxy(function(removed){this.replace(removed)})).fail(function(jqXhr){if(jqXhr.status===400){$(event.target).notify("Вы не можете удалить вопль","bottom")}})},restore:function(event){event.preventDefault();$.post(this.btnRecover.data("url"),{tiny:1},this.proxy(function(cry){this.replace(cry)})).fail(function(jqXhr){if(jqXhr.status===400){$(event.target).notify("Вы не можете восстановить вопль","bottom")}})}});Cry.answeringCry=null;var Answer=Controller.create({elements:{".trashBask":"btnRemove",".recoveryShout a":"btnRecover"},events:{"click .trashBask":"remove","click .recoveryShout a":"restore"},remove:function(){$.post(this.btnRemove.data("url"),{tiny:1},this.proxy(function(removed){this.replace(removed)})).fail(function(jqXhr){if(jqXhr.status===400){$(event.target).notify("Вы не можете удалить ответ","bottom")}})},restore:function(removed){$.post(this.btnRecover.data("url"),{tiny:1},this.proxy(function(cry){this.replace(cry)})).fail(function(jqXhr){if(jqXhr.status===400){$(event.target).notify("Вы не можете восстановить ответ","bottom")}})}});$(function(){var shouts_sidebar=$(".js-shouts");if(!isMobile.phone&&shouts_sidebar.length){new CrySidebar({el:shouts_sidebar,autoShow:false})}});
$(function(){$(document.body).on("click",".js-like-button",function(event){event.preventDefault();if(Auth.user&&!Auth.hasAccess()){Auth.notify("поставить лайк");return}var el=$(this),liked=el.data("liked"),count=el.data("count"),obj=el.data("object"),others=$('[data-object="'+obj+'"]');var data={action:liked?"unlike":"like",object:obj};$.post("/likes/like",data,function(data){updateLike(others,data.liked,data.count)});updateLike(others,!liked,count+(liked?-1:1))});function updateLike(elements,liked,count){elements.each(function(){var $currentEl=$(this),evt=jQuery.Event("like");$currentEl.data("liked",liked).data("count",count);$currentEl.trigger(evt,[liked,count]);if(!evt.isDefaultPrevented()){$currentEl.toggleClass("it-is-checked",liked);$currentEl.text(count)}})}});$(function(){var $container=$(".js-likes"),$btn=$(".js-likes-show-more",$container),$list=$(".js-likes-user-list",$container),$like=$(".js-like-button",$container);shown=$list.hasClass("it-is-expanded");$btn.on("click",function(){shown=!shown;$btn.text(shown?"Скрыть":"Показать еще");$list.toggleClass("it-is-expanded");$btn.toggleClass("it-is-expanded");return false});$like.on("like",function(event,liked,count){if(!Auth.user)return;var $item=$list.children().filter('[href="'+Auth.user.url+'"]');if(liked){if($item.length)return;var $img=$("
",{src:Auth.user.avatar,alt:Auth.user.name}),$anchor=$("",{href:Auth.user.url,title:Auth.user.name});$anchor.prependTo($list).append($img)}else{$item.remove()}})});var VoteItem=Controller.create({elements:{".rating-disliked":"dislikes",".rating-liked":"likes"},events:{"click .rating-disliked":"dislike","click .rating-liked":"like"},init:function(){this.el=this.sanitizeEl(this.el);this.el.addClass("inited")},sanitizeEl:function(el){if(el&&el.length>1){return el.filter(".rating-box")}return el},dislike:function(event){event.preventDefault();if(this.el.hasClass("authRequired")||this.dislikes.hasClass("disabled")){return}var payload={action:this.dislikes.hasClass("check")?"clear":"minus",object:this.el.data("object")},url=this.el.data("vote-url");$.post(url,payload,this.proxy(function(data){var prefix=data.dislikes?"-":"";this.dislikes.text(prefix+data.dislikes).toggleClass("check");this.likes.toggleClass("disabled")}))},like:function(event){event.preventDefault();if(this.el.hasClass("authRequired")||this.likes.hasClass("disabled")){return}var payload={action:this.likes.hasClass("check")?"clear":"plus",object:this.el.data("object")},url=this.el.data("vote-url");$.post(url,payload,this.proxy(function(data){var prefix=data.likes?"+":"";this.likes.text(prefix+data.likes).toggleClass("check");this.dislikes.toggleClass("disabled")}))}});$(function(){function promoteVotes($elements){if(!$elements){$elements=$(".rating-box")}$elements.not(".inited").each(function(){new VoteItem({el:$(this)})})}promoteVotes();$(".endless").on("endless:next:page",function(evt,$elements){if(!$elements||!$elements.length){return}$ratings=$elements.find(".rating-box");if($ratings.length){promoteVotes($ratings)}})});
$.fn.inputToggle=function(){function init($el){var on=$el.hasClass("_on");var $textOn=$(".__text .__on"),$textOff=$(".__text .__off");$(".__toggle",$el).click(toggle);function toggle(){if(on){$el.removeClass("_on").addClass("_off")}else{$el.removeClass("_off").addClass("_on")}on=!on;$el.trigger("change",[on])}}this.each(function(){init($(this))});return this};
$(function(){var $sc=$(".stream-center"),$scToggleLink=$(".stream-center-toggle-link",$sc),$scStreamsBody=$(".stream-center-body",$sc),collapsed=$scStreamsBody.data("collapsed")==="yes",$scStreamNew=$(".stream-center-add-stream",$sc),$scStreamNewBtn=$(".sc-add-stream-btn",$sc),$scStreamNewCloseBtn=$(".sc-add-stream-popup-close",$sc),$scroller=$("#sc-streams-scroller"),$scPlayer=$(".js-sc-player",$sc),$scPlayerTitle=$(".js-sc-player-title",$sc),$scPlayerSubtitle=$(".js-sc-player-subtitle",$sc),$scForm=$(".js-sc-stream-add",$sc),$scDoneMessage=$(".js-sc-add-stream-done",$sc),$scDoneClose=$(".js-sc-add-stream-done-close",$sc),$gameInput=$("input[name=game]",$scForm),gameAutocomplete=$(".js-sc-game-autocomplete",$scForm),$scheduled=$("[data-scheduled-start]",$sc),$scStreamChat=$(".js-sc-stream-chat",$sc),$scSwitcher=$(".js-sc-switcher",$sc),$scSwitchBtn=$(".sc-switcher-btn",$sc),$scStreamListChat=$(".sc-streams-list, .sc-streams-chat",$sc),$scHeadlineSlider=$(".sc-headline-slider",$sc),$scHeadlineItem=$(".sc-headline-item",$sc),$intro=$(".js-sc-intro",$sc),$introSkip=$(".js-sc-intro-skip"),$introNext=$(".js-sc-intro-next"),$introPrev=$(".js-sc-intro-prev"),introShown=false,hasStore=isLocalStorageSupported(),fakeStore={};if(!$("#sc-streams-scroller").length){return}function track(event){try{_gaq.push(["t3._trackEvent",event,"click"])}catch(err){console.error(err)}}function getStoreValue(key){return hasStore?localStorage.getItem(key):fakeStore[key]}function setStoreValue(key,value){if(hasStore){localStorage.setItem(key,value)}else{fakeStore[key]=value}}introShown=getStoreValue("scIntroShown")==="yes";function pad(v){if(v<10){return"0"+v}return""+v}function dayOfWeek(v){return{0:"ВС",1:"ПН",2:"ВТ",3:"СР",4:"ЧТ",5:"ПТ",6:"СБ"}[v]||""}$scheduled.each(function(){var $el=$(this),ts=$el.data("scheduled-start"),dt=new Date(ts);$el.html(dayOfWeek(dt.getDay())+" "+pad(dt.getHours())+":"+pad(dt.getMinutes()));$el.attr("title",dt.toString())});streamsScroll=new IScroll("#sc-streams-scroller",{mouseWheel:true,scrollbars:true,fadeScrollbars:true,shrinkScrollbars:"clip"});gameAutocomplete.autocomplete({source:gameAutocomplete.data("url"),create:function(event,ui){gameAutocomplete.autocomplete("widget").addClass("baseAutoComplete")},select:function(event,ui){$gameInput.val(ui.item.pk);return ui.item.label},change:function(event,ui){if(ui.item===null){$gameInput.val("")}else{$gameInput.val(ui.item.pk)}}});function strong(text){return""+text+""}function loadStream(evt){evt.preventDefault();var $item=$(evt.currentTarget),url=$item.data("href"),title=$(".sc-stream-list-item-title",$item).text(),game=$.trim($(".sc-stream-list-item-game",$item).text()),author=$.trim($item.data("author"))||"",action=$item.data("live")==="yes"?" стримит ":" стримил ",subtitle=author?strong(author)+(game?action+strong(game):""):"";width=$scPlayer.width();track("Стрим-центр: загрузить стрим");$.ajax({url:url,method:"GET",data:{width:width}}).done(function(html){var $html=$("").html(html),$embed=$html.find("iframe:first"),$chat=$html.find("#chat_embed");$(".sc-stream-list-item.current",$scroller).removeClass("current");$item.parent().addClass("current");$scPlayerTitle.text(title);$scPlayerSubtitle.html(subtitle);$embed.addClass("sc-player");$scPlayer.replaceWith($embed);$scPlayer=$embed;if($chat.length){$scStreamChat.html($chat);$scSwitcher.show()}else{$scStreamChat.html("");$scSwitcher.hide()}}).fail(function(jqXhr){console.error(jqXhr)})}function loadCurrentStream(){$(".sc-stream-list-item.current > .js-sc-load-stream",$sc).trigger("click")}function closeCurrentStream(){var $div=$('
');$scPlayer.replaceWith($div);$scPlayer=$div}function toggleStreamCenter(evt){var cb;if($scStreamsBody.is(":visible")){setStoreValue("sc-body","hidden");track("Стрим-центр: закрыть");cb=closeCurrentStream}else{setStoreValue("sc-body","visible");track("Стрим-центр: открыть");if(introShown||!$intro.length){cb=loadCurrentStream}else{cb=showIntro}}$scStreamsBody.slideToggle("slow");$scToggleLink.toggleClass("it-is-expanded");streamsScroll.refresh();setTimeout(cb,200);if(evt){evt.preventDefault()}}function showIntro(){$intro.css("display","flex");introShown=true;setStoreValue("scIntroShown","yes")}function closeIntro(evt){if(evt){evt.preventDefault()}loadCurrentStream();$intro.css("display","none").remove()}function showIntroSlide(delta){var $current=$(".sc-intro-slide.active",$intro),$next,src,$d,$ifr;if(!$current.length){return}$next=delta===1?$current.next():$current.prev();if($next.length){$current.removeClass("active");$next.addClass("active");src=$next.data("src");if(src){$d=$("
").css({position:"relative",paddingBottom:"48%"});$ifr=$('
');$ifr.css({position:"absolute",top:"0",left:"0"}).attr("src",src);$(".sc-intro-media",$next).html($d.append($ifr))}}else if(delta===1){closeIntro()}if(!$next.prev().length){$introPrev.hide()}else{$introPrev.show()}}function nextIntroSlide(evt){evt.preventDefault();showIntroSlide(1)}function prevIntroSlide(evt){evt.preventDefault();showIntroSlide(-1)}function setInitialStreamCenterState(){var v=getStoreValue("sc-body");if(collapsed){return}if(v==="visible"){toggleStreamCenter()}}function showAddNewStream(){$scStreamNew.css("display","flex");$scStreamNew.find('input[type="text"]:first').focus();return false}function hideAddNewStream(){$scStreamNew.fadeOut("fast");$scDoneMessage.hide();$scForm.show();return false}function addNewStream(evt){evt.preventDefault();$("input.error",$scForm).removeClass("error");$(".field-error",$scForm).remove();track("Стрим-центр: добавить стрим");$.ajax({url:this.action,dataType:"json",method:"POST",data:$(this).serialize()}).done(function(resp){if(resp.status&&resp.status==="error"){$.each(resp.errors,function(key,val){var $inp=$("[name="+key+"]",$scForm);if(key==="game"){$inp=$inp.prev()}$inp.addClass("error").parent().append('
'+val+"
")})}else{$(".sc-add-stream-body input",$scForm).val("");$scForm.hide();$scDoneMessage.show()}}).fail(function(jqXhr){console.error(jqXhr)})}function listChatSwitch(evt){var $this=$(this);if(!$this.hasClass("current")){$this.addClass("current").siblings().removeClass("current");$scStreamListChat.toggle()}evt.preventDefault()}function goToStream(evt){evt.preventDefault();var scid=$(this).data("scid");if(!$scStreamsBody.is(":visible")){$scToggleLink.click()}setTimeout(function(){$('.js-sc-load-stream[data-scid="'+scid+'"]',$sc).click()},100)}setInitialStreamCenterState();$sc.on("click",".js-sc-load-stream",loadStream);$scToggleLink.on("click",toggleStreamCenter);$scStreamNewBtn.on("click",Auth.confirmed("добавить стрим",function(){showAddNewStream()}));$scStreamNewCloseBtn.on("click",hideAddNewStream);$scDoneClose.on("click",hideAddNewStream);$scForm.on("submit",addNewStream);$scSwitchBtn.on("click",listChatSwitch);$scHeadlineItem.on("click",goToStream);$introSkip.on("click",closeIntro);$introNext.on("click",nextIntroSlide);$introPrev.on("click",prevIntroSlide)});
(function(){var Slider,__bind=function(fn,me){return function(){return fn.apply(me,arguments)}};Slider=function(){function Slider(selector,options){this.prevPage=__bind(this.prevPage,this);this.nextPage=__bind(this.nextPage,this);this.checkControls=__bind(this.checkControls,this);this.setSizes=__bind(this.setSizes,this);var defaults;defaults={animSpeed:"slow",container:"ul",items:"ul li",minSize:1022,maxSize:1356};this.options=$.extend({},defaults,options);this.slider=$(selector);if(this.slider.length===0){return this.slider}this.container=this.slider.find("ul").first();this.items=this.container.children();this.controls={};this.working=false;this.setup()}Slider.prototype.setup=function(){this.slider.wrap('
');this.wrapper=this.slider.parent();this.setSizes();this.controls.el=$('
');this.controls.prev=$('
');this.controls.next=$('
');this.controls.el.append(this.controls.prev).append(this.controls.next);this.controls.prev.on("click",this.prevPage);this.controls.next.on("click",this.nextPage);this.slider.after(this.controls.el);this.checkControls();return $(window).on("resize",this.setSizes)};Slider.prototype.setSizes=function(){var maxSlides,sumSize,width;this.originalWidth=1;width=this.wrapper.width();maxSlides=4;sumSize=0;this.items.removeClass("smaller");this.items.each(function(_this){return function(i,item){var $item;$item=$(item);if(width===_this.options.maxSize){sumSize+=$item.data("size");if(sumSize===maxSlides){sumSize=0;$item.addClass("smaller")}}return _this.originalWidth+=$item.outerWidth(true)}}(this));return this.container.width(this.originalWidth)};Slider.prototype.slideTo=function(pos,$item){if(!this.working){this.working=true;$item.addClass("active").siblings(".active").removeClass("active");this.slider.stop().animate({scrollLeft:pos},this.options.animSpeed,this.checkControls);return this.working=false}};Slider.prototype.checkControls=function(){var right,scroll;scroll=this.slider.scrollLeft();right=scroll+this.slider.width();if(scroll===0&&right+1>=this.originalWidth){return this.controls.el.hide()}else{this.controls.el.show().children().removeClass("disabled");if(scroll===0){return this.controls.prev.addClass("disabled")}}};Slider.prototype.nextPage=function(){var pos,scroll,slide,width;scroll=this.slider.scrollLeft();width=this.slider.width();pos=0;slide=void 0;this.items.each(function(i,item){var $item,left;$item=$(item);left=$item.position().left;if(0
0&&scroll+width+1<=this.originalWidth){this.slideTo(scroll+pos,slide)}else{this.slideTo(0,this.items.first())}return false};Slider.prototype.prevPage=function(){var pos,scroll,slide,width;scroll=this.slider.scrollLeft();width=this.slider.width();pos=0;slide=void 0;this.items.each(function(i,item){var $item;$item=$(item);if($item.position().left<1-width){pos=$item.next().position().left;return slide=$item}});if(pos===0){this.slideTo(0,this.items.first())}else{this.slideTo(scroll+pos,slide)}return false};return Slider}();this.Slider=Slider}).call(this);
$(function(){$(".page-feature-main--item").hover(function(){var $info=$(".page-feature-main-item--info",this),pk=$info.data("lazy"),ugc=$info.data("ugc")||"n";if(!pk)return;$info.data("lazy",null).data("ugc",null);$.get("/featurer/",{pk:pk,ugc:ugc},function(html){$info.html(html)})});$(".page-feature-without-slider .page-feature-main--item:gt(3)").clone().appendTo(".page-feature-main-additional");if(!isMobile.any){new Slider("[data-feature-slider=ugc]")}else{$('[data-feature-slider="ugc"]').wrap('')}});
(function(){var root=this,timerIntervalId,$timerEl,timerValue;$(function initInformer(){$timerEl=$(".informer-timer[data-timer]");if(!$timerEl){return}timerValue=parseInt($timerEl.data("timer"),10);updateTimer();timerIntervalId=root.setInterval(updateTimer,1e3)});function pad(v){return v<10?"0"+v:v}function span(t,cl){return''+t+""}function updateTimer(){var secs=timerValue%60,mins=timerValue/60,hrs=Math.floor(mins/60),minsLeft=Math.floor(mins%60),sep=span(":","informer-timer-sep"),valClass=timerValue<=3600?"informer-timer-val highlight":"informer-timer-val",days=0,text="";if(hrs>=24){days=Math.floor(hrs/24);hrs=Math.floor(hrs%24);days=pad(days);text+=span(days,"informer-timer-val")+sep}hrs=pad(hrs);minsLeft=pad(minsLeft);secs=pad(secs);text+=span(hrs,valClass)+sep+span(minsLeft,valClass)+sep+span(secs,valClass);if(timerValue<0){$timerEl.remove();root.clearInterval(timerIntervalId);return}$timerEl.html(text);timerValue-=1}}).call(this);