$u.Confirm = new $class(B.Page, { el:null, _tpl: '\ <div\ class="pngbox confirm {type}"\ style="top:{top}; left:{left}; right:{right};"\ >\ <div class="tpt">\ <div class="tpc"></div>\ <div class="bpt">\ <div class="cont">\ <div class="ask" id="confirm_ask">{title}</div>\ {msg}\ <div id="confirm_buttons">\ <button class="dConfirm-ok btn_st btn_smt">{bn_text}</button>\ <span class="confirm_or">{or} <a href="#" class="dConfirm-cancel">{cancel}</a></span>\ </div>\ </div>\ <div class="bpc"></div>\ </div>\ </div>\ <div class="tcn"></div>\ <div class="bcn"></div>\ </div>', x: 0, y: 0, ralign: false, type: '', text: '', onOk: null, onCancel: null, scope: null, defaults: { x: 0, y: 0, ralign: false, type: '', text: '', onOk: null, onCancel: null, scope: null }, init: function () { $e.on({ '.dConfirm-ok': this.ok, '.dConfirm-cancel': this.cancel }, this); }, show: function (config) { $config(this, config, this.defaults); this.el = $u.tpl2el(this._tpl, { type: this.type, top: this.y + 'px', left: this.ralign ? '' : (this.x + 'px'), right: this.ralign ? ($el.dimensions(document).width - this.x + 'px') : '', title: config.text[0], bn_text: config.text[1], or: config.text[2], cancel: config.text[3], msg: config.text[4] }); document.body.appendChild(this.el); var bn = $el.down(this.el, 'input, button'); bn && bn.focus(); $e.on('__all__', this._onclick, this); }, _onclick: function (element) { if (!$el.up($e.element($e.e), '.confirm')) { this.hide(); } return true; }, hide: function() { if (this.el) { $el.remove(this.el); $e.un('__all__', this._onclick, this); } }, ok: function(el) { this.hide(); if(this.onOk) this.onOk.call(this.scope); }, cancel: function(el) { this.hide(); this.onCancel && this.onCancel.call(this.scope); } }); if(!$u.CharCount) $u.CharCount=$class( { el:null, elc:null, limit:0, constructor:function(id,limit) { this.el=$(id), this.elc=$(id+'_count'), this.limit=+limit; if(!this.el || !this.elc) return; $e.add(this.el,'keyup',this.count,this); this.count(); }, destroy:function() { $e.del(this.el,'keyup',this.count,this); this.el=this.elc=null; }, count:function() { var l=this.el.value.length, c=this.limit-l; if(c<0){ this.el.value=this.el.value.substr(0,this.limit); c=0; } this.elc.innerHTML=c; return true; } }); B.Comments=new $class(B.Page, { name: 'Comments', deleteText:{ comment:"Delete only this comment", thread:"Delete whole thread" }, init:function() { if(!$('comments')) return; $e.on({ '.sub_to_com, * .sub_to_com':this.toggle_subscribe, '.reply_anchor':this.reply, '.add_comment_anchor':this.add_comment, '.delete_comment': this.delete_comment }, this); if($('add_comment_form')){ $el.del($('add_comment_form'), 'editing'); }else{ if($('reply_form')){ $('reply_form').style.display = 'block'; } } if($('f_comment')) new $u.CharCount('f_comment', 5000); if($('comment_timer')) this.comment_timer(); }, toggle_subscribe:function(el) { $el.tgl(el, 'enabled'); new $r(el.href,{ method:'get', params:{ws:1} }); }, comment_timer: function() { var ct=$('comment_timer'); var t=parseInt(ct.value)-1; if(t>0){ ct.value=t; $('post_comment').disabled=true; $('post_comment_error_wait').style.display='inline'; var el = $el.down($('post_comment_error_wait'), 'b'); el.innerHTML = t; var comments = this; window.setTimeout(function () { comments.comment_timer(); } , 1000); }else{ $('post_comment').disabled=false; $('post_comment_error_wait').style.display='none'; } }, reply:function(el) { if($el.has(el.parentNode, 'editing')){ $el.del(el.parentNode, 'editing'); $('reply_form').style.display = 'none'; }else{ if($el.has($('add_comment'), 'editing')) $el.del($('add_comment'), 'editing'); $el.del($('reply_form').parentNode, 'editing'); $el.add(el.parentNode, 'editing'); el.parentNode.appendChild($('reply_form')); $('reply_form').style.display = 'block'; if($('f_comment'))$('f_comment').focus(); } if($('thread_id')) { var t=el.rel.split('|'); $('thread_id').value=t[0]; $('photo_id').value=t[1]; } if($('current_page'))$('page_num').value=$('current_page').value; }, add_comment:function(el) { if($el.has($('add_comment'), 'editing')) { $el.del($('add_comment'), 'editing'); $('reply_form').style.display = 'none'; if($('no_comments_text')) $('no_comments_text').style.display = 'block'; }else{ if($el.has($('reply_form').parentNode, 'editing')) $el.del($('reply_form').parentNode, 'editing'); $el.add($('add_comment'), 'editing'); $('add_comment_form').appendChild($('reply_form')); if($('no_comments_text')) $('no_comments_text').style.display = 'none'; $('reply_form').style.display = 'block'; if($('f_comment')) $('f_comment').focus(); } if($('page_num')) $('page_num').value=''; if($('thread_id') && top==self){ $('thread_id').value=0; } }, delete_comment:function(el) { var texts=this.comments_str; var opt=''; if(el.rev == '1') opt='<div id="confirm_text"><label><input type="radio" id="confirm_opt1" name="confirm_opt" checked="checked" value="1"> '+ this.deleteText.comment + '</label><br><label><input type="radio" id="confirm_opt2" name="confirm_opt" value="2"> '+ this.deleteText.thread + '</label></div>'; texts[4]=opt; var tl = $el.cumulativeOffset(el); var url1= el.rel; var url2 = opt ? $u.add_href(el.rel, 'all=1') : ''; $u.Confirm.show({ x: tl.left -10, y: tl.top-90-35 *(el.rev=='1'), type:'b_tail', text:texts, onOk:function () { $u.Confirm.hide(); document.location =(url2 ?($('confirm_opt1').checked?url1:url2):url1); } }); } }); $u.Slider=$class({ el:null, fe:null, p:-1, pm:-1, z0:0, z1:1, z0e:null, z1e: null, z:null, onStart:function(p){}, onUpdate:function(p){}, onUpdateEnd:function(p){}, scope:null, dir:'x', constructor:function(config, scope) { this.z=[]; $config(this,config); this.scope=scope||this; if(!this.el || !this.fe){ return; } if(this.dir=='y'){ this.prop='top', this.propget='offsetHeight', this.propset='top', this.getpos=this.getposy; }else{ this.prop='left', this.propget='offsetWidth', this.propset='marginLeft', this.getpos=this.getposx; if($el.dir()=='rtl'){ this.v2px=this.v2px_rtl; this.px2v=this.px2v_rtl; } } this.z0e && $e.add(this.z0e,'click',this.zoom_prev,this); this.z1e && $e.add(this.z1e,'click',this.zoom_next,this); $e.add(this.el,'mousedown',this.start,this); this.init(); }, init:function() { this.ww=this.el[this.propget]-this.fe[this.propget]+1; if(this.p!=-1){ var ex=this.v2px(this.p); this.fe.style[this.propset]=ex+'px'; this.pm=this.p; } }, getposx:function(e){ return e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)) }, getposy:function(e){ return e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop)) }, v2px:function(v){ return this.ww*(v-this.z0)/(this.z1-this.z0); }, v2px_rtl:function(v){ return this.ww-this.ww*(v-this.z0)/(this.z1-this.z0); }, px2v:function(px){ return parseInt((this.z0+(this.z1-this.z0)*px/this.ww)*1000)/1000; }, px2v_rtl:function(px){ return parseInt((this.z0+(this.z1-this.z0)*(this.ww-px)/this.ww)*1000)/1000; }, start:function(el) { this.onStart.call(this.scope,this.pm); $e.add(document,'mousemove',this.drag,this); $e.add(document,'mouseup',this.stop,this); var wtl=$el.cumulativeOffset(this.el); this.wx=wtl[this.prop]; this.ww=this.el[this.propget]-this.fe[this.propget]+1; this.drag(el); }, drag:function(el) { var e=$e.e, p, ww=this.ww, ex=this.getpos(e) - this.wx; ex=ex<0?0:(ex>ww?ww:ex); p=this.px2v(ex); if(p==this.pm) return; this.fe.style[this.propset]=ex+'px'; this.onUpdate.call(this.scope,this.pm=p); }, stop:function() { $e.del(document,'mouseup',this.stop,this); $e.del(document,'mousemove',this.drag,this); this.onUpdateEnd.call(this.scope,this.pm); this.interactive=false; }, zoom_next:function() { var z=this.z, p=this.pm; for(var i=0, n=z.length; i<n; i++) if(z[i]>p){ p=z[i]; break; } this.zoom(p); }, zoom_prev:function() { var z=this.z, p=this.pm; for(var i=z.length-1; i>=0; i--) if(z[i]<p){ p=z[i]; break; } this.zoom(p); }, zoom:function(p) { if(p==this.pm) return; var ex=this.v2px(p); this.fe.style[this.propset]=ex+'px'; this.onUpdate.call(this.scope,this.pm=p); this.onUpdateEnd.call(this.scope,this.pm); } }); B.EntryView=$class(B.Page, { name:'Entry', ez:1, photo_count:0, cc_photos:null, fom:false, have_others:false, s_confirm_abuse:null, wrap:null, wrap2:null, ds:null, z_items:null, ozh:96, z0:0.5, z1:3.125, z:[0.5, 1, 2, 3.125], zoom_path:[48, 96, 192, 300, 300], init:function() { this.prev_z=this.zoom_path[this.ez<0.6?0:Math.ceil(this.ez)]; this.wrap=$('b_photos'); if(!this.wrap){ return; } this.z_items=$el.select(this.wrap, 'img'); if(this.fom && this.have_others){ this.wrap2=$('b_photos_other'); if(this.wrap2){ this.z_items=this.z_items.concat($el.select(this.wrap2, 'img')); if(!this.photo_count) $('slider_other').appendChild($('slider')); } } var def_w=this.ozh; for(var i=0, ez=this.ez, els=this.z_items, n=els.length; i<n; i++){ var el=els[i]; el._w=parseInt(el.width/ez)||def_w; el._id=el.parentNode.id; } this.ds=new $u.Slider({ el:$('scale'), fe:$('slide_me'), p:this.ez, z0:this.z0, z1:this.z1, z:this.z, z0e:$('zoom_out'), z1e:$('zoom_in'), onUpdate:this.zoom, onUpdateEnd:this.zoom_end, zoomNext:this.zoom_next, zoomPrev:this.zoom_prev }, this); if($('slideshow')){ if($u.flash.init(9) && ($u.flash.version[0]>9 || ($u.flash.version[0]==9 && $u.flash.version[2]>=115))){ $('slideshow_flash').innerHTML=$u.flash.draw(JSRoot+'flash/slideshow.swf', "144", "16", "#fff", $('slideshow_params').value, true, "fSlideshow"); $el.add($('slideshow'),'on'); }else{ $el.add($('slideshow'),'bad-flash-ver'); } } var people=$('people_tagged'); if(people){ $e.add(people, 'mouseover', this.tag_over, this); $e.add(people, 'mouseout', this.tag_out, this); } $e.on({ '#tagsmore':this.load_tags, '#confirm_abuse':this.confirm_abuse }, this); }, zoom:function(p,items) { var w,h=p*this.ozh; for(var i=0, els=items||this.z_items, n=els.length; i<n; i++){ els[i].height=Math.ceil(h); els[i].width=p*els[i]._w; } }, zoom_end:function(p,items) { this.ez=p; var d=new Date(); d.setFullYear(5+d.getFullYear()); $u.cookie('ez',parseInt(p*100)/100,d,'/','.'+/[^.]+\.[^.]+$/.exec(location.host)); var z=(p<0.6?0:Math.ceil(p)); if(this.zoom_path[z]==this.prev_z) return; this.prev_z=this.zoom_path[z]; var i,m,id,src,cc, ccs=this.cc_photos, cc_i=({'2':0,'3':1,'4':1})[''+z], re=/_(\d+)(\.\w+(\?|$))/, re_cc=/(\?|&)cc=([^&]+)(&|$)/, new_size='_'+this.zoom_path[z]+'$2'; for(var j=0, els=items||this.z_items, n=els.length; j<n; j++){ i=els[j]; src=i.src.replace(re, new_size); if(src==i.src) continue; src=src.replace(re_cc,'$1').replace(/&$/,''); if(ccs && cc_i!=undefined) src+=(ccs[id=i._id] && ccs[id][cc_i] && ('&cc='+ccs[id][cc_i]) || ''); i.src=src; } }, zoom_end_one:function(i) { var p=this.ez, z=(p<0.6?0:Math.ceil(p)), w,h=p*this.ozh, m,id,src,cc, ccs=this.cc_photos, cc_i=({'2':0,'3':1,'4':1})[''+z], re=/_(\d+)(\.\w+(\?|$))/, re_cc=/(\?|&)cc=([^&]+)(&|$)/, new_size='_'+this.zoom_path[z]+'$2'; i.height=Math.ceil(h); i.width=p*i._w; src=i.src.replace(re, new_size); if(src==i.src) return; src=src.replace(re_cc,'$1').replace(/&$/,''); if(ccs && cc_i!=undefined) src+=(ccs[id=i._id] && ccs[id][cc_i] && ('&cc='+ccs[id][cc_i]) || ''); i.src=src; }, last_hovered:[], tag_over:function(el) { if(el.nodeName!='LI') el=$el.up(el,'li'); if(!el) return; var els=this.last_hovered, ids=el.id.split('_'); ids.shift(); for(var i=0, n=els.length; i<n; i++) $el.del(els[i],'hovered'); els=[]; for(var i=0, n=ids.length; i<n; i++) (el=$('i'+ids[i])) && (els[els.length]=el) && $el.add(el,'hovered'); this.last_hovered=els; }, tag_out:function(el) { var els=this.last_hovered; for(var i=0, n=els.length; i<n; i++) $el.del(els[i],'hovered'); this.last_hovered=[]; }, load_tags:function(el) { this.load_tags_el=el.parentNode.parentNode; new $r(el.rev,{ ready:this.load_tags_done },this); }, load_tags_done:function(res) { $('people_tagged').innerHTML+=res.html; if(res.more) this.load_tags_el.parentNode.replaceChild($u.tpl2el(res.more),this.load_tags_el); else this.load_tags_el.parentNode.removeChild(this.load_tags_el); }, confirm_abuse:function(el) { if(!this.s_confirm_abuse) return true; var xy=$e.pointerXY($e.e); $u.Confirm.show({ x:(xy.x-24), y:(xy.y-115), type:'confirm_claim', text:this.s_confirm_abuse, onOk:this.abuse_redirect.bind(this,$u.add_href(el.href, 'confirm=1')), scope:this }); }, abuse_redirect:function(url) { window.location=url; } }); B.Entry=new B.EntryView();
