;!function(name,context,definition){if(typeof module!=="undefined")module.exports=definition(name,context);else if(typeof define==="function"&&typeof define.amd==="object")define(definition);else context[name]=definition(name,context)}("humane",this,function(name,context){var win=window;var doc=document;var ENV={on:function(el,type,cb){"addEventListener"in win?el.addEventListener(type,cb,false):el.attachEvent("on"+type,cb)},off:function(el,type,cb){"removeEventListener"in win?el.removeEventListener(type,cb,false):el.detachEvent("on"+type,cb)},bind:function(fn,ctx){return function(){fn.apply(ctx,arguments)}},isArray:Array.isArray||function(obj){return Object.prototype.toString.call(obj)==="[object Array]"},config:function(preferred,fallback){return preferred!=null?preferred:fallback},transSupport:false,useFilter:/msie [678]/i.test(navigator.userAgent),_checkTransition:function(){var el=doc.createElement("div");var vendors={webkit:"webkit",Moz:"",O:"o",ms:"MS"};for(var vendor in vendors)if(vendor+"Transition"in el.style){this.vendorPrefix=vendors[vendor];this.transSupport=true}}};ENV._checkTransition();var Humane=function(o){o||(o={});this.queue=[];this.baseCls=o.baseCls||"humane";this.addnCls=o.addnCls||"";this.timeout="timeout"in o?o.timeout:2500;this.waitForMove=o.waitForMove||false;this.clickToClose=o.clickToClose||false;this.timeoutAfterMove=o.timeoutAfterMove||false;this.container=o.container;try{this._setupEl()}catch(e){ENV.on(win,"load",ENV.bind(this._setupEl,this))}};Humane.prototype={constructor:Humane,_setupEl:function(){var el=doc.createElement("div");el.style.display="none";if(!this.container){if(doc.body)this.container=doc.body;else throw"document.body is null"}this.container.appendChild(el);this.el=el;this.removeEvent=ENV.bind(function(){var timeoutAfterMove=ENV.config(this.currentMsg.timeoutAfterMove,this.timeoutAfterMove);if(!timeoutAfterMove){this.remove()}else{setTimeout(ENV.bind(this.remove,this),timeoutAfterMove)}},this);this.transEvent=ENV.bind(this._afterAnimation,this);this._run()},_afterTimeout:function(){if(!ENV.config(this.currentMsg.waitForMove,this.waitForMove))this.remove();else if(!this.removeEventsSet){ENV.on(doc.body,"mousemove",this.removeEvent);ENV.on(doc.body,"click",this.removeEvent);ENV.on(doc.body,"keypress",this.removeEvent);ENV.on(doc.body,"touchstart",this.removeEvent);this.removeEventsSet=true}},_run:function(){if(this._animating||!this.queue.length||!this.el)return;this._animating=true;if(this.currentTimer){clearTimeout(this.currentTimer);this.currentTimer=null}var msg=this.queue.shift();var clickToClose=ENV.config(msg.clickToClose,this.clickToClose);if(clickToClose){ENV.on(this.el,"click",this.removeEvent);ENV.on(this.el,"touchstart",this.removeEvent)}var timeout=ENV.config(msg.timeout,this.timeout);if(timeout>0)this.currentTimer=setTimeout(ENV.bind(this._afterTimeout,this),timeout);if(ENV.isArray(msg.html))msg.html="";this.el.innerHTML=msg.html;this.currentMsg=msg;this.el.className=this.baseCls;if(ENV.transSupport){this.el.style.display="block";setTimeout(ENV.bind(this._showMsg,this),50)}else{this._showMsg()}},_setOpacity:function(opacity){if(ENV.useFilter){try{this.el.filters.item("DXImageTransform.Microsoft.Alpha").Opacity=opacity*100}catch(err){}}else{this.el.style.opacity=String(opacity)}},_showMsg:function(){var addnCls=ENV.config(this.currentMsg.addnCls,this.addnCls);if(ENV.transSupport){this.el.className=this.baseCls+" "+addnCls+" "+this.baseCls+"-animate"}else{var opacity=0;this.el.className=this.baseCls+" "+addnCls+" "+this.baseCls+"-js-animate";this._setOpacity(0);this.el.style.display="block";var self=this;var interval=setInterval(function(){if(opacity<1){opacity+=.1;if(opacity>1)opacity=1;self._setOpacity(opacity)}else clearInterval(interval)},30)}},_hideMsg:function(){var addnCls=ENV.config(this.currentMsg.addnCls,this.addnCls);if(ENV.transSupport){this.el.className=this.baseCls+" "+addnCls;ENV.on(this.el,ENV.vendorPrefix?ENV.vendorPrefix+"TransitionEnd":"transitionend",this.transEvent)}else{var opacity=1;var self=this;var interval=setInterval(function(){if(opacity>0){opacity-=.1;if(opacity<0)opacity=0;self._setOpacity(opacity)}else{self.el.className=self.baseCls+" "+addnCls;clearInterval(interval);self._afterAnimation()}},30)}},_afterAnimation:function(){if(ENV.transSupport)ENV.off(this.el,ENV.vendorPrefix?ENV.vendorPrefix+"TransitionEnd":"transitionend",this.transEvent);if(this.currentMsg.cb)this.currentMsg.cb();this.el.style.display="none";this._animating=false;this._run()},remove:function(e){var cb=typeof e=="function"?e:null;ENV.off(doc.body,"mousemove",this.removeEvent);ENV.off(doc.body,"click",this.removeEvent);ENV.off(doc.body,"keypress",this.removeEvent);ENV.off(doc.body,"touchstart",this.removeEvent);ENV.off(this.el,"click",this.removeEvent);ENV.off(this.el,"touchstart",this.removeEvent);this.removeEventsSet=false;if(cb&&this.currentMsg)this.currentMsg.cb=cb;if(this._animating)this._hideMsg();else if(cb)cb()},log:function(html,o,cb,defaults){var msg={};if(defaults)for(var opt in defaults)msg[opt]=defaults[opt];if(typeof o=="function")cb=o;else if(o)for(var opt in o)msg[opt]=o[opt];msg.html=html;if(cb)msg.cb=cb;this.queue.push(msg);this._run();return this},spawn:function(defaults){var self=this;return function(html,o,cb){self.log.call(self,html,o,cb,defaults);return self}},create:function(o){return new Humane(o)}};return new Humane});/*! Autosize 3.0.8 license: MIT http://www.jacklmoore.com/autosize */!function(e,t){if("function"==typeof define&&define.amd)define(["exports","module"],t);else if("undefined"!=typeof exports&&"undefined"!=typeof module)t(exports,module);else{var o={exports:{}};t(o.exports,o),e.autosize=o.exports}}(this,function(e,t){"use strict";function o(e){function t(){var t=window.getComputedStyle(e,null);"vertical"===t.resize?e.style.resize="none":"both"===t.resize&&(e.style.resize="horizontal"),u="content-box"===t.boxSizing?-(parseFloat(t.paddingTop)+parseFloat(t.paddingBottom)):parseFloat(t.borderTopWidth)+parseFloat(t.borderBottomWidth),i()}function o(t){var o=e.style.width;e.style.width="0px",e.offsetWidth,e.style.width=o,v=t,l&&(e.style.overflowY=t),n()}function n(){var t=window.pageYOffset,o=document.body.scrollTop,n=e.style.height;e.style.height="auto";var i=e.scrollHeight+u;return 0===e.scrollHeight?void(e.style.height=n):(e.style.height=i+"px",document.documentElement.scrollTop=t,void(document.body.scrollTop=o))}function i(){var t=e.style.height;n();var i=window.getComputedStyle(e,null);if(i.height!==e.style.height?"visible"!==v&&o("visible"):"hidden"!==v&&o("hidden"),t!==e.style.height){var r=document.createEvent("Event");r.initEvent("autosize:resized",!0,!1),e.dispatchEvent(r)}}var r=void 0===arguments[1]?{}:arguments[1],d=r.setOverflowX,s=void 0===d?!0:d,a=r.setOverflowY,l=void 0===a?!0:a;if(e&&e.nodeName&&"TEXTAREA"===e.nodeName&&!e.hasAttribute("data-autosize-on")){var u=null,v="hidden",f=function(t){window.removeEventListener("resize",i),e.removeEventListener("input",i),e.removeEventListener("keyup",i),e.removeAttribute("data-autosize-on"),e.removeEventListener("autosize:destroy",f),Object.keys(t).forEach(function(o){e.style[o]=t[o]})}.bind(e,{height:e.style.height,resize:e.style.resize,overflowY:e.style.overflowY,overflowX:e.style.overflowX,wordWrap:e.style.wordWrap});e.addEventListener("autosize:destroy",f),"onpropertychange"in e&&"oninput"in e&&e.addEventListener("keyup",i),window.addEventListener("resize",i),e.addEventListener("input",i),e.addEventListener("autosize:update",i),e.setAttribute("data-autosize-on",!0),l&&(e.style.overflowY="hidden"),s&&(e.style.overflowX="hidden",e.style.wordWrap="break-word"),t()}}function n(e){if(e&&e.nodeName&&"TEXTAREA"===e.nodeName){var t=document.createEvent("Event");t.initEvent("autosize:destroy",!0,!1),e.dispatchEvent(t)}}function i(e){if(e&&e.nodeName&&"TEXTAREA"===e.nodeName){var t=document.createEvent("Event");t.initEvent("autosize:update",!0,!1),e.dispatchEvent(t)}}var r=null;"undefined"==typeof window||"function"!=typeof window.getComputedStyle?(r=function(e){return e},r.destroy=function(e){return e},r.update=function(e){return e}):(r=function(e,t){return e&&Array.prototype.forEach.call(e.length?e:[e],function(e){return o(e,t)}),e},r.destroy=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],n),e},r.update=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],i),e}),t.exports=r});(function(c){c.fn.stupidtable=function(b){return this.each(function(){var a=c(this);b=b||{};b=c.extend({},c.fn.stupidtable.default_sort_fns,b);a.on("click.stupidtable","th",function(){var d=c(this),f=0,g=c.fn.stupidtable.dir;a.find("th").slice(0,d.index()).each(function(){var a=c(this).attr("colspan")||1;f+=parseInt(a,10)});var e=d.data("sort-default")||g.ASC;d.data("sort-dir")&&(e=d.data("sort-dir")===g.ASC?g.DESC:g.ASC);var l=d.data("sort")||null;null!==l&&(a.trigger("beforetablesort",{column:f,direction:e}),a.css("display"),setTimeout(function(){var h=[],m=b[l],k=a.children("tbody").children("tr");k.each(function(a,b){var d=c(b).children().eq(f),e=d.data("sort-value"),d="undefined"!==typeof e?e:d.text();h.push([d,b])});h.sort(function(a,b){return m(a[0],b[0])});e!=g.ASC&&h.reverse();k=c.map(h,function(a){return a[1]});a.children("tbody").append(k);a.find("th").data("sort-dir",null).removeClass("sorting-desc sorting-asc");d.data("sort-dir",e).addClass("sorting-"+e);a.trigger("aftertablesort",{column:f,direction:e});a.css("display")},10))})})};c.fn.stupidtable.dir={ASC:"asc",DESC:"desc"};c.fn.stupidtable.default_sort_fns={"int":function(b,a){return parseInt(b,10)-parseInt(a,10)},"float":function(b,a){return parseFloat(b)-parseFloat(a)},string:function(b,a){return ba?1:0},"string-ins":function(b,a){b=b.toLowerCase();a=a.toLowerCase();return ba?1:0}}})(jQuery);function loginRedirect(){if(confirm('Пожалуйста, авторизуйтесь!')){window.location='/accounts/login/?next='+window.location.pathname;}} var agentIE=(function(){var myNav=navigator.userAgent.toLowerCase();return(myNav.indexOf('msie')!=-1)?parseInt(myNav.split('msie')[1]):false;})();$(function(){var REQUEST_USER=window.REQUEST_USER;$('.limit-show .show-all .btn').click(function(){$(this).parentsUntil('limit-show').removeClass('limit-show');});var body=$('body'),burger=$('.nav__burger'),sidepanel=$('.sidepanel');burger.click(function(){body.toggleClass('sidepanel-active');sidepanel.scrollTop(0);});$('.sidepanel-blocker').on('touchstart click',function(){burger.click()});$(window).scroll(function(){if($(this).scrollTop()>100){$('.scroll-up').addClass('visible');}else{$('.scroll-up').removeClass('visible');}});$('.scroll-up').click(function(){window.scrollTo(0,0) return false;});$('.sidepanel__user__inner').click(function(){$(this).toggleClass('sidepanel__user__inner--active');});if($('.sidepanel__user__menu__list .sidepanel__menu__item__link--active').length){$('.sidepanel__user__inner').click();} var yaShared=function(share_id){try{var post_id=parseInt(share_id.replace('post_share_',''));return function(){$.get('/shared/'+post_id+'/')}}catch(err){};} $('.action-share').click(function(){$(this).removeClass('post__footer__offset__item--link action-share').unbind('click');var domain='http://www.ruzatur.ru',share_id=$(this).attr('id'),post_link=domain+$(this).data('url'),post_image=domain+$(this).data('image'),post_title=$(this).data('title');var tw_link=post_link.replace('www.ruzatur.ru/post/','ruzatur.ru/p/');var tw_after=' @DIYRU #diy' var tw_max=140-(tw_after.length+tw_link.length+2);var tw_title='';var tw_split=post_title.split(' ') var i=0 while(itw_max){break;} tw_title=t;i++;} if(tw_title!=post_title){tw_title+='…';} tw_title+=tw_after;var YaShareInstance=new Ya.share2(share_id,{content:{title:post_title,url:post_link,theme:'counter',image:post_image},theme:{services:'vkontakte,facebook,odnoklassniki,moimir,twitter,gplus,pocket,whatsapp',counter:true},hooks:{onshare:yaShared(share_id)},contentByService:{twitter:{title:tw_title,link:tw_link}}});}) try{if(window.location.pathname.match(/\/post\/\d+\/$/)){$('.post-page .action-share').click();}}catch(err){} $('.sortable-table').stupidtable();if($('.typo--reader').length){$('.typo > p:has(img:nth-of-type(2))').fotorama({nav:'thumbs',allowfullscreen:true,loop:false,thumbheight:48,thumbwidth:72,captions:true,trackpad:true,shadows:true,maxheight:800,maxwidth:'100%',minwidth:'100%',ratio:1.5});if(!agentIE||agentIE>9){$('.comment__content img, .typo > p > img:not([class])').each(function(){$(this).addClass('image-zoomer-source').parent().addClass('image-zoomer-source-parent');});var image_zoomer,image_zoomer_img;$('.image-zoomer-source').click(function(){if(!image_zoomer){image_zoomer=$('
');image_zoomer.appendTo(document.body).click(function(){$(this).addClass('hide');});image_zoomer_img=$('
');image_zoomer_img.appendTo(image_zoomer);} image_zoomer_img.css('background-image','url('+$(this).attr('src')+')');image_zoomer.removeClass('hide');});}} var nav_js_tab_active='modal-nav__item--active' $('.modal-nav--js').each(function(){var target_class=$(this).data('target'),target=$(target_class);$(this).children().click(function(){$(this).siblings().removeClass(nav_js_tab_active).end().addClass(nav_js_tab_active);target.addClass('hide');$(target_class+'--'+$(this).index()).removeClass('hide');})}) if(!REQUEST_USER){$('#poll_form').submit(function(e){e.preventDefault();return loginRedirect();}) $('.action-like, .action-favorite').click(function(e){e.preventDefault();return loginRedirect();})}else{$('.action-like, .action-favorite').click(function(e){e.preventDefault();$.ajax({context:this,url:$(this).data('href'),success:function(data){var c=$(this).children('.caption').first();var l=parseInt(c.text())||0;if(parseInt(data)==0){c.text(l-1||'0');$(this).removeClass('active');}else{c.text(l+1) $(this).addClass('active');}},error:function(){alert('Что-то пошло не так! Пожалуйста, попробуйте повторить позже.')}});});$('#poll_form').submit(function(e){e.preventDefault();var self=$(this) $.ajax({url:$(this).attr('action'),type:$(this).attr('method'),data:$(this).serialize(),error:function(){alert('Что-то пошло не так. Попробуйте проголосовать позже.')},success:function(data){self.parent().html(data);}})}) autosize($('#conversation_form #id_content'));$('.poll-edit__toggle').click(function(){$('.poll-edit__form').toggleClass('poll-edit__form--hide');});$('#id_poll-delete').change(function(){var items=$('[id*="id_poll-"]').not(this);if(this.checked){items.attr('disabled','disabled');}else{items.removeAttr('disabled');}})}});(function(humane,_){humane.baseCls='humane';humane.timeout=1500;humane.timeoutAfterMove=2000;humane.waitForMove=true;humane.clickToClose=true;var message_levels={info:{fa:'info-circle'},error:{fa:'times-circle'},success:{fa:'check-circle'},processing:{fa:'cog fa-spin',timeout:0},} _.each(message_levels,function(conf,level){humane[level]=function(html,options,cb){var opt=_.extend(_.clone(conf),options);var message=''+html,defaults={addnCls:'humane-'+level};return this.log(message,opt,cb,defaults)}});})(humane,_);$(function(){var current_suggestion=-1,search_form=$('.nav__search__form'),search_input=$('.nav__search__input'),search_hidden=$('.nav__search__hidden'),search_timout=null,suggests=$('.nav__search__suggests'),suggests_icons={0:'briefcase',1:'user',2:'bars',3:'tag'};function chooseSuggest(direction){var c=suggests.children(),length=c.length;if(!length)return;current_suggestion+=direction;c.removeClass('active');if(current_suggestion==-1||current_suggestion==length){resetHidden();return;} else if(current_suggestion<-1){current_suggestion=length-1;} else if(current_suggestion>length){current_suggestion=0} var current=c.eq(current_suggestion).addClass('active');search_input.val(current.text());replaceInputText(current);} function replaceInputText(that){search_input.val(that.text());} function resetChoice(){current_suggestion=-1;suggests.children().removeClass('active');} function setChoiceToHidden(){var val=search_input.val().trim();search_hidden.val(val);return val;} function resetHidden(){search_input.val(search_hidden.val());} function commitRedirect(that){replaceInputText(that);window.location.replace(that.attr('href'));} suggests.mouseleave(function(){resetChoice();});search_input.keydown(function(event){if(event.defaultPrevented){return;} switch(event.which||event.keyCode){case 40:chooseSuggest(1);break;case 38:chooseSuggest(-1);break;case 27:$(this).blur();resetHidden();break;case 13:event.preventDefault();var a=suggests.find('.active');if(a.attr('href')){return commitRedirect(a);} else{return search_form.submit();} default:resetChoice();return;} event.preventDefault();}).keyup(function(event){clearTimeout(search_timout);search_timout=null;var code=event.which||event.keyCode;if($.inArray(code,[40,38,27,13])!==-1){return;} var origin=search_input.val().trim(),hidden=search_hidden.val().trim();if(!origin){suggests.addClass('hide');return;}else if(origin===hidden){suggests.removeClass('hide');}else if(origin.length<3){return;} search_timout=setTimeout(function(){search_timout=null;var val=setChoiceToHidden();$.ajax({url:search_form.data('suggests'),data:{'q':val},success:function(data){suggests.html('');if(!data['items']||!data['items'].length){suggests.addClass('hide');return} var _i=-1,_length=data['items'].length while(++_i<_length){var klass=data['items'][_i][0],title=data['items'][_i][3][0],link=data['items'][_i][3][1],icon=suggests_icons[klass];if(icon){title=''+title;} suggests.append($(''+ title+''));} suggests.removeClass('hide');}});},400);});search_form.submit(function(e){clearTimeout(search_timout);search_timout=null;var val=setChoiceToHidden();if(!val){e.preventDefault();}}) window.suggestMouseDown=function(that){commitRedirect($(that));} window.suggestHover=function(that){current_suggestion=$(that).siblings().removeClass('active').end().addClass('active').index();};}) $(function(){'use strict';var REQUEST_USER=window.REQUEST_USER;if(!REQUEST_USER){$('.comment__replay').click(function(e){e.preventDefault();return window.loginRedirect();});return;} var oldSync=Backbone.sync;Backbone.sync=function(method,model,options){options.beforeSend=function(xhr){xhr.setRequestHeader('X-CSRFToken',comment_form.csrf_token);};return oldSync(method,model,options);};var comment_tree=$('.comment-tree'),comment_count=$('.comment__count'),comment_class={commenting:'comment--commenting',updating:'comment--updating',deleted:'comment--deleted',sub:'comment--sub',_new:'comment--new'};var Storage=function(name){this.name=name;var store=localStorage.getItem(this.name);this.data=(store&&JSON.parse(store))||{};};_.extend(Storage.prototype,{save:function(){localStorage.setItem(this.name,JSON.stringify(this.data));return this;},setItem:function(key,value){this.data[key]=value;this.save();return this;},getItem:function(key){return this.data[key];},delItem:function(key){delete this.data[key];return this.save();}});function CommentForm(el){this.el=$(el);this.form=this.el.find('form');this.form_url=this.form.attr('action');this.textarea=this.el.find('textarea');this.parent_field=this.el.find('input[name="parent_id"]');this.csrf_token=this.el.find('input[name="csrfmiddlewaretoken"]').val();this.image_field=this.el.find('input[name="image"]');this.image_field_label=this.image_field.prev().text();this.nullKey=this.el.find('input[name="obj_type"]').val()+this.el.find('input[name="obj_id"]').val();this.storage=new Storage('comments');this.image_field.val('');this.parent_field.val('');this.textarea.val(this.storage.getItem(this.nullKey));autosize(this.textarea);this.image_field.change(function(){var path=this.value||comment_form.image_field_label;$(this).prev().text(path.replace(/^.*\\/,''));});this.resetPosition=function(view){$('.'+comment_class.commenting).removeClass(comment_class.commenting);this.storage.setItem(this.parent_field.val()||this.nullKey,this.textarea.val());var id=view?view.model.id:this.nullKey,content=this.storage.getItem(id);if(!content&&view&&REQUEST_USER.display_name!==view.model.get('user')){content=view.model.get('user')+', ';} this.textarea.val(content);this.parent_field.val(id!==this.nullKey?id:'');this.image_field.val('');this.image_field.trigger('change');if(view){this.el.insertAfter(view.$el).addClass(comment_class.sub);view.$el.addClass(comment_class.commenting);}else{this.el.removeClass(comment_class.sub);comment_tree.prepend(this.el);} autosize.update(this.textarea);return this;};} var comment_form=new CommentForm('.comment--blank');comment_form.resetPosition();var Item=Backbone.Model.extend({defaults:{editable:false},url:function(){var original_url=Backbone.Model.prototype.url.call(this);var parsed_url=original_url+(original_url.charAt(original_url.length-1)=='/'?'':'/');return parsed_url;}});var ItemList=Backbone.Collection.extend({model:Item,url:comment_form.form_url});var ItemView=Backbone.View.extend({events:{'click .comment__replay':'replay','click .comment__update':'update','click .comment__cancel':'cancel','click .comment__delete':'remove','click .comment__save':'save','keypress .comment__textarea':'saveOnCmdEnter'},saveOnCmdEnter:function(e){if(cmdEnterPressed(e)){this.save();} return this;},replay:function(){comment_form.resetPosition(this).textarea.focus();},update:function(){if(!this.hasOwnProperty('content')){this.content=this.$('.comment__content');this.time=this.$('.comment__time');this.textarea=$('');this.textarea.insertAfter(this.content);autosize(this.textarea);this.model.set({content:this.content.html()});} this.$el.addClass(comment_class.updating);var content=this.model.get('content');content=content.replace(/<\/?br>/gi,'\n').replace(/\n{2,}/gi,'\n').replace(/ /gi,' ');content=_.unescape(content);content=$.trim(content);this.textarea.val(content);autosize.update(this.textarea);this.textarea.focus();},cancel:function(){if(this.$el.hasClass(comment_class.updating)){this.content.html(this.model.get('content'));this.$el.removeClass(comment_class.updating);}else if(this.$el.hasClass(comment_class.commenting)){comment_form.resetPosition();}},save:function(){var content=$.trim(this.textarea.val());if(!content){this.textarea.focus();return humane.error('Мы не можешь сохранить пустой комментарий');} this.model.set({content:content});if(this.model.hasChanged('content')){var obj=this;this.model.save({content:content},{wait:true,patch:true,dataType:'html',success:function(model,response){obj.time.text('отредактировано.');humane.success('Комментарий изменен.');obj.model.set({content:response},{silent:true});obj.cancel();obj.content.html(response);},error:function(model,response){humane.error('Что-то пошло не так, изменения не сохранены');}});} return this;},remove:function(){if(!confirm('Вы точно хотите удалить комментарий?')){return this;} var obj=this.$el;this.model.destroy({wait:true,dataType:'text',success:function(model,response){humane.success('Комментарий удален.');obj.addClass(comment_class.deleted).html('Комментарий удален');},error:function(model,response){humane.error('Не удалось удалить комментарий');}});return this;},modifyTimeout:function(){this.$('.comment__update, .comment__delete').remove();this.cancel();}});var ItemListView=Backbone.View.extend({el:comment_tree,events:{'submit .comment__form':'createItem','keypress .comment__form__textarea':'submitOnCmdEnter'},initialize:function(){this.collection=new ItemList();_.each(this.$el.children().not('.comment--blank'),function(el){this.parseItem(el);},this);this.collection.on('add remove',this.updateCounter,this);},submitOnCmdEnter:function(e){if(cmdEnterPressed(e)){this.createItem(e);} return this;},updateCounter:function(){comment_count.text(this.collection.length);},parseItem:function(el){var id=parseInt(el.id.match(/\d+$/),10),$el=$(el),user=$el.find('.comment__header__item--username').text(),datetime=$el.find('.comment__header__item--time time').attr('datetime'),time=new Date(datetime);var item=new Item({id:id,user:user,time:time});var view=new ItemView({model:item,el:el});this.collection.add(item);var diff=(time.getTime()+10*60000)-new Date();if(!REQUEST_USER.is_staff&&diff>=0){setTimeout(function(obj){if(obj.$el.hasClass(comment_class.updating)){humane.error('Время редактирования истекло');} obj.modifyTimeout();},diff,view);} return view;},createItem:function(e){e.preventDefault();var content=$.trim(comment_form.textarea.val());if(!content){return comment_form.textarea.val().focus();} var parent_id=comment_form.parent_field.val();if(parent_id){var user=this.collection.get(parent_id).get('user')+', ';if($.trim(user)===content){humane.info('Пожалуйста, напишите комментарий');return comment_form.textarea.val(user).focus();}} comment_tree.addClass('comment-tree--blocked');humane.processing('Сохраняем комментарий');var data,processData,contentType;if(window.agentIE&&window.agentIE<10){data=$(this).serialize();processData=true;contentType='application/x-www-form-urlencoded; charset=UTF-8';}else{data=new FormData(comment_form.form[0]);processData=false;contentType=false;} var self=this;$.ajax({url:comment_form.form_url,type:'POST',data:data,dataType:'html',processData:processData,contentType:contentType,success:function(data){humane.remove();var el=$(data);el.addClass(comment_class._new);self.parseItem(el[0]).$el.insertAfter(comment_form.el);comment_form.storage.delItem(parent_id||comment_form.nullKey);comment_form.textarea.val('');comment_form.resetPosition();humane.success('Комментарий добавлен');},error:function(){humane.remove();humane.error('Что-то пошло не так. Пожалуйста, попробуйте повторить позже');},complete:function(){comment_tree.removeClass('comment-tree--blocked');}});}});var listView=new ItemListView();var cmdEnterPressed=function(e){return!!(e.keyCode==10||e.keyCode==13)&&(e.ctrlKey||e.metaKey);};$(window).bind('beforeunload',function(){comment_form.resetPosition();});});