B.Photo={}; 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.Photo.Comments=$class( { url:'/ws/popup.photo-comments.phtml', user_id:0, constructor:function(user_id, likes, ph, entry, readonly) { this.user_id=user_id; this.ph=ph; this.entry=entry; this.readonly=readonly; $e.on({ '.pvc-reply':this.reply, '.pvc':this.more, '.pvc-cancel':this.focus_cancel },this); this.w=$('pvc_w'); this.el=$('pvc_comments'); this.form=$('pvc_form'); this.cnew=$('pvc_new'); this.err=$('pvc_err'); if(!this.readonly){ this.comment=$('comment'); this.count=new $u.CharCount('comment',5000); $e.add(this.form,'submit',this.send,this); $e.add(this.comment,'focus',this.focus,this); } this.timer=new $t(this.load,this,1000); this.timeout=new $t(this.timeout_tick,this,1000); this.t=new $r(this.url,{ auto:false, params:{}, ready:this.ready, error:this.error }, this); this._cache={}; this._cache[ph.entry_id+'_'+ph.id]={ html:this.el.innerHTML, likes: likes }; }, destroy:function() { $e.un({ '.pvc-reply':this.reply, '.pvc':this.more, '.pvc-cancel':this.focus_cancel },this); this.timer.clear(); this.timeout.clear(); this.t.abort(); this.t=this.timer=this.timeout=null; if(!this.readonly){ this.count.destroy(); this.count=null; $e.del(this.form,'submit',this.send,this); $e.del(this.comment,'focus',this.focus,this); } this.w=this.el=this.form=this.cnew=this.err=this.like_frames=this.timeout_el=this.comment=null; this._cache=null; }, clean:function() { this.el.innerHTML=''; this.t.abort(); this.timer.clear(); $el.add(this.w,'hidden'); }, show:function(ph, entry) { this.ph=ph; this.entry=entry; if(!this.readonly){ this.form.thread.value='0'; this.form.photo.value=ph.id; } this.t.abort(); this.t.params={ user_id:this.user_id, owner_id:ph.user_id||this.user_id, photo_id:ph.id, entry_id:ph.entry_id }; var res=this._cache[ph.entry_id+'_'+ph.id]; if(res){ this._cache_req=0; this.timer.clear(); this.ready(res); }else{ this._cache_req=1; this.el.innerHTML=''; $el.add(this.w,'loading'); this.timer.set(); } $el.del(this.w,'hidden'); }, load:function() { this.t.request(); }, ready:function(res) { if(this._cache_req){ this._cache[this.ph.entry_id+'_'+this.ph.id]=res; this._cache_req=0; } if(!this.readonly) this.reply(this.cnew, true); if(res['more']){ $el.remove($('pvc_more')); this.el.innerHTML+=res['html']; }else{ this.el.innerHTML=res['html']; } $el.del(this.w,'loading'); this.draw_likes(res.likes); }, error:function(er) { $el.del(this.w,'loading'); }, more:function(el) { this.timer.clear(); this.t.abort(); this.t.params=$r.fromQueryString(el.rev); this._cache_req=0; this.t.request(); }, draw_likes:function(likes_code) { $('pv_likes').innerHTML = likes_code; }, send:function(form) { if(!form.comment.value || $el.has(form,'el-loading')) return; $el.add(this.err,'hidden'); $el.add(form,'el-loading');form.post.disabled=true; var ph=this.ph, params=$config($r.serialize(form),{ user_id:this.user_id, owner_id:ph.user_id||this.user_id, photo_id:ph.id, entry_id:ph.entry_id }); new $r(this.url,{ method:'post', params:params, ready:this.send_ready, error:this.send_error },this); delete this._cache[this.ph.entry_id+'_'+this.ph.id]; }, send_ready:function(res) { var form=this.form, cs=this.el; $el.del(form,'el-loading'); form.post.disabled=false; if(!res['errno']){ var li=$el.up(form,'li'), c=$u.tpl2el(res['html']); cs.insertBefore(c, li ? li.nextSibling : cs.firstChild); form.comment.value=''; this.count.count(); $el.del(form.parentNode,'editing'); }else{ this.err.innerHTML=res['error']; if(res['timeout']){ this.timeout_value=+res['timeout']; this.timeout_el=$el.down(this.err,'.timeout'); this.timeout.set(); form.post.disabled=true; } $el.del(this.err,'hidden'); } }, send_error:function(er) { $el.del(form,'el-loading'); form.post.disabled=false; }, timeout_value:0, timeout_el:null, timeout_tick:function() { this.timeout_value--; if(this.timeout_value>0){ this.timeout_el.innerHTML=this.timeout_value; this.timeout.set(); }else{ this.form.post.disabled=false; $el.add(this.err,'hidden'); this.timeout_el=null; } }, focus:function(el) { $el.add(this.comment.parentNode,'pv_tf_wrap_focus'); return true; }, focus_cancel:function() { this.comment.value=''; $el.del(this.comment.parentNode,'pv_tf_wrap_focus'); }, reply:function(el, noshow) { var p=el.parentNode, form=this.form; if(p==form.parentNode){ if(!$el.has(p,'editing') && !noshow) $el.add(p,'editing'); if(!noshow) form.comment.focus(); return; } $el.del(form.parentNode,'editing'); if(!noshow) $el.add(p,'editing'); p.appendChild(form); if(!noshow) form.comment.focus(); var t=el.rel.split('|'); form.thread.value=t[0]||'0'; form.photo.value=t[1]||this.ph.id; } }); $u.error_tpl='<div class="input_error"><div><b></b>{text}</div><span><i></i></span></div>'; $u.handle_errors=function(form, errors, er_cls, er_tpl) { er_cls=er_cls||'input_error'; er_tpl=er_tpl||$u.error_tpl; var ers=$el.select(form, '.input_error'); if(errors){ var el, els=form.elements, er; for(var i=0, n=els.length; i<n; i++){ el=els[i], er=null; if(el.type=='hidden' || !el.name || el.disabled) continue; for(var j=0, m=ers.length; j<m; j++){ if(ers[j].parentNode==el.parentNode){ er=ers[j]; break; } } if(el.name in errors){ if(er){ $el.down(er,'div').innerHTML='<b></b>'+errors[el.name]; }else{ er=$u.tpl2el(this.error_tpl,{text:errors[el.name]}); el.parentNode.insertBefore(er,el); } er.className=er_cls; }else{ if(er) $el.add(er,'hidden'); } } }else{ for(var i=0, n=ers.length; i<n; i++) $el.add(ers[i], 'hidden'); } }; B.Photo.Tag=function(config, mixin){ var c=B.Photo.Tag[config.tag_type]; return c && new c(config, mixin) || null; }; B.Photo.Tag.tag=$class( { cfg:null, c_type:'noted', el:null, wr:null, _tpl:'<div id="pn{tag_id}" class="dtag dtag-th {c_type}" style="left:{left}px;top:{top}px;width:{width}px;height:{height}px;">\ <a href="{url}" class="dtag-i" rel="{tag_id}"></a>\ <div class="dtag-title">{tooltip}</div>\ </div>', _prevz:1, constructor:function(config, mixin) { this.cfg=config; $config(this,mixin); this.init(); }, init:function() { this.draw(); }, destroy:function() { this.wr.removeChild(this.el); this.el=null; }, draw:function() { this.cfg.c_type=this.c_type; this.el=$u.tpl2el(this._tpl,this.cfg); this.wr.appendChild(this.el); }, resize:function(z) { var cfg=this.cfg; this._prevz=z; this.el.style.cssText=$u.tpl('left:{left}px;top:{top}px;width:{width}px;height:{height}px;',{ top:cfg.top*z, left:cfg.left*z, width:cfg.width*z, height:cfg.height*z }); }, li:function() { var li=$('t'+this.cfg.tag_id); this.li=function(){ return li; }; return li; } }); B.Photo.Tag.edit=$class(B.Photo.Tag.tag,{ _tpl:'<div id="pn{tag_id}" class="dtag dtag-th {c_type}" style="left:{left}px;top:{top}px;width:{width}px;height:{height}px;">\ <a href="{url}" class="dtag-i" rel="{tag_id}"></a>\ <a class="dtag-close" href="#" rel="{tag_id}">\ <span class="pn_rme"></span>\ {delete_str}\ </a>\ <div class="dtag-title">{tooltip}</div>\ </div>' }); B.Photo.Tag.auto=$class(B.Photo.Tag.edit,{ c_type:'who', _tpl:'<div id="pn{tag_id}" class="dtag dtag-th {c_type}" style="left:{left}px;top:{top}px;width:{width}px;height:{height}px;">\ <a href="{url}" class="dtag-i" rel="{tag_id}"></a>\ <a class="dtag-close" href="#" rel="{tag_id}">\ <span class="pn_rme"></span>\ {delete_str}\ </a>\ <div class="who_icon"></div>\ <div class="dtag-title">{tooltip}</div>\ </div>' }); B.Photo.Tag.confirm=$class(B.Photo.Tag.tag,{ c_type:'noted', _tpl:'<div id="pn{tag_id}" class="dtag {c_type} hover2" style="left:{left}px;top:{top}px;width:{width}px;height:{height}px;">\ <a class="dtag-i" rel="{tag_id}" href=""></a>\ </div>', draw:function() { $super(this,arguments); this.dlg=new B.Photo.TagDlgConfirm({ getData:this.dlg_data.bind(this) }); this.dlg.create(this.wr, this.cfg); this.dlg.show(); }, dlg_data:function() { var wh=this.getWH(), z=this._prevz, cfg=this.cfg; return { x:cfg.left*z, y:cfg.top*z, tw:cfg.width*z, w:wh.width, h:wh.height }; }, destroy:function() { this.dlg.destroy(); $super(this,arguments); }, resize:function(z) { $super(this,arguments); this.dlg.draw(); } }); B.Photo.Tag['new']=$class(B.Photo.Tag.tag,{ c_type:'find', _tpl:'<div id="pn{tag_id}" class="dtag {c_type}" style="left:{left}px;top:{top}px;width:{width}px;height:{height}px;">\ <div><i class="dtag-tl"></i><i class="dtag-tr"></i><i class="dtag-bl"></i><i class="dtag-br"></i></div>\ </div>', minw:48, minh:48, init:function() { $super(this,arguments); $e.add(this.el,'mousedown',this.start,this); }, destroy:function() { this.p=null; $e.del(this.el,'mousedown',this.start,this); $super(this,arguments); }, start:function(el) { $e.add(document,'mousemove',this.drag,this); $e.add(document,'mouseup',this.stop,this); this.interactive=true; var e=$e.e, ex=e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)), ey=e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop)), wh=this.getWH(); this.p={ ww:wh.width, wh:wh.height, ox:this.el.offsetLeft, oy:this.el.offsetTop, ow:this.el.offsetWidth-2, oh:this.el.offsetHeight-2, minw:this.minw, minh:this.minh, ix:ex, iy:ey, dt:el.className, x:this.el.offsetLeft, y:this.el.offsetTop, d:this.el.offsetWidth-2 }; $el.add(this.wr,'dtag-drag'); }, drag:function() { var e=$e.e, ex=e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)), ey=e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop)); with(this.p){ var dx=ex-ix, dy=ey-iy; switch(dt){ case '': x=Math.max(Math.min(ox+dx,ww-ow),0), y=Math.max(Math.min(oy+dy,wh-oh),0); d=ow; break; case 'dtag-tl': d=Math.max(Math.min(ow-dx,oh-dy,ox+ow,oy+oh),minw); x=ox+ow-d, y=oy+oh-d; break; case 'dtag-tr': d=Math.max(Math.min(ow+dx,oh-dy,ww-ox,oy+oh),minw); x=ox, y=oy+oh-d; break; case 'dtag-bl': d=Math.max(Math.min(ow-dx,oh+dy,wh-oy,ox+ow),minw); x=ox+ow-d, y=oy; break; case 'dtag-br': d=Math.max(Math.min(ow+dx,oh+dy,ww-ox,wh-oy),minw); x=ox, y=oy; break; } var s=this.el.style; s.left=x+'px'; s.top=y+'px'; s.width=d+'px'; s.height=d+'px'; } }, stop:function() { $config(this.cfg,{ left:this.p.x, top:this.p.y, width:this.p.d, height:this.p.d }); $e.del(document,'mouseup',this.stop,this); $e.del(document,'mousemove',this.drag,this); this.interactive=false; this.onDragEnd.call(this.scope); $el.del(this.wr,'dtag-drag'); }, resize:function(z) { var cfg=this.cfg, _prevz=this._prevz, op=function(v){ return Math.round(v/_prevz*z); }; $config(cfg,{ left:op(cfg.left), top:op(cfg.top), width:op(cfg.width), height:op(cfg.height) }); this._prevz=z; this.el.style.cssText=$u.tpl('left:{left}px;top:{top}px;width:{width}px;height:{height}px;',{ top:cfg.top, left:cfg.left, width:cfg.width, height:cfg.height }); this.onDragEnd.call(this.scope); }, onDragEnd:function(){}, scope:null }); B.iSearch=$class({ el:null, url:'', params:{}, onInit:function(){}, onComplete:function(res){}, onCancel:function(){}, onChangeState:function(state){}, scope:null, timeout:500, _value:'', _timer:0, _transport:null, min_chars:2, constructor:function(config) { $config(this,config); this.init(); }, init:function() { this._value=this.el.value; this.search_fn=this.search.bind(this); $e.on('.is-cancel',this.cancel,this); $e.add(this.el,'keyup',this.search_delayed,this); $e.add(this.el,'change',this.search_delayed,this); this.onInit.call(this.scope||this); this._transport=new $r(this.url,{ auto:false, params:this.params, ready:this.ready, error:this.error },this); }, destroy:function() { clearTimeout(this._timer); if(this._transport){ this._transport.abort(); this._transport=null; } $e.del(this.el,'keyup',this.search_delayed,this); $e.del(this.el,'change',this.search_delayed,this); $e.un('.is-cancel',this.onCancel,this); this.el=null; }, cancel:function() { clearTimeout(this._timer); this.el.value=this._value=''; this.onCancel(); this.el.focus(); this.onChangeState.call(this.scope||this); }, search_delayed:function(e) { var val=this.el.value; if(this._value==val) return; clearTimeout(this._timer); if(val.length>=this.min_chars){ this._timer=setTimeout(this.search_fn,this.timeout); }else{ this._value=''; this.onCancel.call(this.scope||this); this.onChangeState.call(this.scope||this); } }, search:function() { this.params[this.el.name]=this.el.value; this.onChangeState.call(this.scope||this,'is-loading'); this._transport.request(); }, ready:function(res) { this._value=res.q; this.onChangeState.call(this.scope||this,'is-found'); this.onComplete.call(this.scope||this,res); }, error:function() { this.onChangeState.call(this.scope||this); } }); B.Photo.TagDlg=$class( { uid_el:null, user_el:null, dh:325, labels:null, getData:null, show_data:null, dlg_tpl:'<form id="pn_wrap" class="autoloader tab_people" action="">\ <div class="pn_dialog">\ <a href="#" class="pn_tab t_people" rel="tab_people">{s_friends}</a>\ <span class="hr"></span>\ <div class="people">\ <div class="pn_input_name">\ <label for="pn_qs" class="dLabel">{s_quick_search}</label>\ <div><input id="pn_qs" name="q"></div>\ </div>\ <div class="pn_pick">\ <input id="pn_uid" type="hidden" name="uid">\ <div class="pn_limiter" id="pn_l">\ {people_list}\ </div>\ </div>\ </div>\ <div class="pn_dialog_buttons">\ <div class="tooltip_wrap">\ <button id="pn_bs" class="btn_st btn_smt pn_save" type="button">{s_save}</button><ins class="loading_to_button"><span class="waiting"></span></ins>\ <div class="fading_form"><div class="formfade"></div></div>\ <div class="bln_info pngbox">\ <div class="tpt">\ <div class="bpt">\ <div class="cont">\ {content}\ </div>\ <div class="bpc"></div>\ </div>\ </div>\ <div class="tcn"></div>\ <div class="bcn"></div>\ </div>\ </div>\ <button id="pn_bc" class="btn_st btn_gen pn_cancel" type="reset">{s_cancel}</button>\ </div>\ </div>\ <div class="pn_f"></div>\ </form>', constructor:function(config) { $config(this,config); this.init(); }, init:function() { $e.on({ '.pnu, * .pnu':this.pn_select_user, '#more_contacts, * #more_contacts':this.show_more },this); }, destroy:function() { $e.un({ '.pnu, * .pnu':this.pn_select_user, '#more_contacts, * #more_contacts':this.show_more },this); if(this.dlg) this.w.removeChild(this.dlg); $u.dLabel.destroy(this.labels); this.labels=null; this.dlg=this.w=this.dlg_list=this.uid_el=null; }, create:function(wrap) { this.w=wrap; this.dlg=$u.tpl2el(this.dlg_tpl,this.str); wrap.appendChild(this.dlg); this.labels=$u.dLabel.init(this.dlg); this.dlg_list=$('pn_l'); this.uid_el=$('pn_uid'); this.is=new B.iSearch({ el:$('pn_qs'), url:this.namesearch_url, min_chars:3, onComplete:this.dlg_list_ready_is, onCancel:this.dlg_list_cancel, onChangeState:this.is_state, scope:this }); }, is_state:function(state) { if(state=='is-loading') $el.add(this.is.el,'loading'); else $el.del(this.is.el,'loading'); }, show:function() { this._show(); this.draw(); }, _show:function(el) { if(this.show_data){ this.dlg_list_ready_is(this.show_data); }else{ var url=el&&el.rel||this.namesearch_url; new $r(url,{ ready:this.show_ready_1st },this); } }, show_ready_1st:function(res) { this.show_data=res; this.dlg_list.innerHTML=res.html; }, show_more:function(el) { var url=el&&el.rel||this.namesearch_url; new $r(url,{ params:{q:this.is.el.value}, ready:this.show_more_ready },this); }, show_more_ready:function(res) { $el.remove($('more_contacts')); var w=$u.tpl2el(res.html); this.dlg_list.appendChild(w); }, dlg_list_ready_is:function(res) { this.dlg_list.innerHTML=res.html; }, dlg_list_cancel:function() { this._show(); }, hide:function() { this.dlg.style.display='none'; $el.del(this.dlg,'el-loading'); this.dlg.reset(); this.user_el=null; this.uid_el.value=''; this.dlg_list.innerHTML=''; this.show_data=null; for(var i=0, n=this.labels.length; i<n; i++) this.labels[i].show(); }, draw:function() { with(this.getData()){ var dw=270, dh=this.dh; if(x+tw+dw>w && x-dw>0) x=x-dw; else x+=tw; if(y+dh>h && h-dh>0) y=h-dh; this.dlg.style.cssText=$u.tpl('left:{left}px;top:{top}px;display:block;',{ left:x, top:y }); } }, pn_select_user:function(el) { $el.del(this.user_el,'selected'); this.user_el=el; var m=/ul_(.*)/.exec(el.id); this.uid_el.value=m && m[1] || ''; $el.add(el,'selected'); } }); B.Photo.TagDlgConfirm=$class(B.Photo.TagDlg, { dh:110, dlg_tpl:'<form id="pn_wrap" class="autoloader tab_people" action="">\ <div class="pn_dialog">\ {text}\ <div class="pn_dialog_buttons">\ <a class="btn_st btn_smt pn_confirm" href="#" rel="{tag_id}">{yes}</a><ins class="loading_to_button"><span class="waiting"></span></ins>\ <a class="btn_st btn_gen pn_reject" href="#" rel="{tag_id}">{no}</a>\ </div>\ </div>\ <div class="pn_f"><div></div></div>\ </form>', init:function() { }, create:function(wrap, cfg) { var o={}; $config(o, cfg); $config(o, cfg.confirm); $config(o, this.str); this.dlg_tpl=$u.tpl(this.dlg_tpl, o); this.dlg=$u.tpl2el(this.dlg_tpl,this.str); wrap.appendChild(this.dlg); }, show:function() { this.draw(); }, destroy:function() { this.dlg.parentNode.removeChild(this.dlg); } }); B.Photo.Tags=$class( { tags:null, tags_cfg:null, ph_vars:null, tw:96, urls:{ namesearch:'', create:'', edit:'', confirm:'', reject:'', 'delete':'' }, str:null, constructor:function(getWH,cfg) { $config(this,cfg); this.tags={}; this.pw2=$('pv_blur'); this.getWH=getWH; $e.on({ '.dtag-close, * .dtag-close':this.del_tag, '.pn_confirm':this.confirm_tag, '.pn_reject':this.reject_tag, '#add_tag':this.add_tag, '.pn_save':this.save_tag, '.pn_cancel':this.cancel_tag, '.dtag-i':this.tag_click },this); B.Photo.Tag.tag.prototype.wr=this.pw2; B.Photo.Tag['new'].prototype.getWH=getWH; B.Photo.Tag['confirm'].prototype.getWH=getWH; var del_str=cfg.str.delete_str; B.Photo.Tag.edit.prototype._tpl=B.Photo.Tag.edit.prototype._tpl.replace('{delete_str}',del_str); B.Photo.Tag.auto.prototype._tpl=B.Photo.Tag.auto.prototype._tpl.replace('{delete_str}',del_str); }, destroy:function() { $e.un({ '.dtag-close, * .dtag-close':this.del_tag, '.pn_confirm':this.confirm_tag, '.pn_reject':this.reject_tag, '#add_tag':this.add_tag, '.pn_save':this.save_tag, '.pn_cancel':this.cancel_tag, '.dtag-i':this.tag_click },this); this.clean(); this.tags=this.tags_cfg=null; this.str={}; }, create:function(tags_cfg,ph_vars) { this.ph_vars=ph_vars; B.Photo.Tag.tag.prototype.wr=this.pw2=$('pv_blur'); this.tags_cfg=tags_cfg; var tags=this.tags; for(var i in tags_cfg) tags[i]=new B.Photo.Tag(tags_cfg[i]); }, clean:function() { if(this.edit) this.cancel_tag(); if(this.dlg){ this.dlg.destroy(); this.dlg=null; } for(var i in this.tags) this.tags[i].destroy(); this.tags={}; }, resize:function(z) { this.pz=z; var tags=this.tags; for(var i in tags) tags[i].resize(z); if(this.new_tag){ this.new_tag.resize(z); } }, url:function(name,cfg) { var o=$config({tag_id:0},this.ph_vars); if(cfg) $config(o,cfg.confirm,cfg); return $u.tpl(this.urls[name],o); }, add_tag:function(el) { $el.del(this.pw2,'dtag-hover-pw'); var wh=this.getWH(); var x=Math.ceil(Math.random()*(wh.width/3)+1), y=Math.ceil(Math.random()*(wh.height/3)+1); this.new_tag_mode=true; this._add_tag(x,y); }, _add_tag:function(x, y, cfg) { if(this.edit || this.new_tag) return; this.edit=true; this.new_tag_cfg=$config({ tag_id:0, width:this.tw, height:this.tw, left:x, top:y },{ tag_type:'new' },cfg); if(!this.dlg){ this.dlg=new B.Photo.TagDlg({ str:this.str, namesearch_url:this.url('namesearch'), getData:this.dlg_data.bind(this) }); this.dlg.create(this.pw2); } this.dlg.show(); $el.add(this.pw2,'dtag-edit'); this.new_tag=new B.Photo.Tag(this.new_tag_cfg,{ _prevz:cfg?1:this.pz, onDragEnd:this.dlg.draw, scope:this.dlg }); }, dlg_data:function() { var cfg=this.new_tag_cfg, wh=this.getWH(); return { x:cfg.left, y:cfg.top, tw:cfg.width, w:wh.width, h:wh.height }; }, cancel_tag:function() { this.edit=false; this.new_tag_mode=false; this.dlg.hide(); this.new_tag.destroy(); this.new_tag=this.new_tag_cfg=null; this.restore_tag && this.restore_tag(); this.restore_tag=null; $el.del(this.pw2,'dtag-edit'); }, save_tag:function(el) { var form=this.dlg.dlg, uid='', email='', errors={}; if($el.has(form,'tab_people')){ uid=form.elements.uid.value; if(!uid){ errors.q=this.str.s_er_select; $u.handle_errors(form, errors); return; } }else if($el.has(form,'tab_email')){ uid=form.elements.name.value; if(!uid) errors.name=this.str.s_er_name; email=form.elements.email.value; if(!email) errors.email=this.str.s_er_email; if(!uid || !email){ $u.handle_errors(form, errors); return; } } $u.handle_errors(form); var cfg=this.new_tag_cfg, z=this.pz; if(!uid) return; $config(cfg,{ left:Math.round(cfg.left/z), top:Math.round(cfg.top/z), width:Math.round(cfg.width/z), height:Math.round(cfg.height/z) }); $el.add(form,'el-loading'); new $r(this.url(this.new_tag_mode?'create':'edit',cfg),{ method:'post', params:{ count:1, tag_id:cfg.tag_id, text:uid, email:email, left:cfg.left, top:cfg.top, width:cfg.width, height:cfg.height }, ready:this.save_done },this); }, save_done:function(res) { if(res.errno==0){ res=res.data; $config(this.new_tag_cfg,res); this.tags_cfg[res.tag_id]=this.new_tag_cfg; this.tags[res.tag_id]=new B.Photo.Tag(this.new_tag_cfg); this.tags[res.tag_id].resize(this.pz); this.restore_tag=null; } this.cancel_tag(); }, confirm_tag:function(el) { var tag_id=el.rel, cfg=this.tags_cfg[tag_id]; new $r(this.url('confirm',cfg),{ method:'post', params:{}, ready:this.confirm_done },this); }, confirm_done:function(res) { var tag_id=res.data.tag_id; $config(this.tags_cfg[tag_id],res.data); this.tags[tag_id].destroy(); this.tags[tag_id]=new B.Photo.Tag(this.tags_cfg[tag_id]); this.tags[tag_id].resize(this.pz); }, reject_tag:function(el) { var tag_id=el.rel, cfg=this.tags_cfg[tag_id]; new $r(this.url('reject',cfg),{ method:'post', params:{}, ready:this.del_done },this); }, del_tag:function(el) { var xy=$e.pointerXY($e.e), cfg=this.tags_cfg[el.rel]; this.edit=true; if($e.e.shiftKey) this._del_tag(cfg); else $u.Confirm.show({ x:(xy.x-130), y:(xy.y - 90), type:'br_tail', text:this.str.tag_dialog, onOk:this._del_tag.bind(this,cfg), onCancel:this.del_cancel.bind(this,cfg), scope:this }); }, del_cancel:function(cfg) { this.edit=false; }, _del_tag:function(cfg) { new $r(this.url('delete',cfg),{ method:'post', params:{}, ready:this.del_done },this); this.del_cancel(cfg); }, del_done:function(res) { var tag_id=res.data.tag_id; this.tags[tag_id].destroy(); delete this.tags[tag_id]; delete this.tags_cfg[tag_id]; }, tag_click:function(el) { if(this.new_tag) return; var id=el.rel, tag=this.tags[id], tcfg=this.tags_cfg[id]; if(tag.c_type!='who') return; $el.del(this.pw2,'dtag-hover'); this.restore_tag=function(){ tag.init(); tag.resize(this.pz); }; tag.destroy(); this._add_tag(tcfg.left, tcfg.top, tcfg); this.new_tag.resize(this.pz); } }); if (!B.Likes) B.Likes = new $class(B.Page, { name: 'Likes', init: function(){}, google: function(btn, cfg) { btn.onmouseover = null; cfg.btn = btn; this.google_cfg = cfg; if(window.gapi){ this.google_render(); return; } window.___gcfg={ lang: cfg.lang_code, parsetags:'explicit' }; $r.loader.add(document.location.protocol+'\/\/apis.google.com/js/plusone.js', this.google_render, this ); }, google_render:function() { if(!window.gapi) return; var cfg = this.google_cfg; var pl = cfg.btn.nextSibling; pl.id+=Math.floor(Math.random()*1000000); gapi.plusone.render(pl.id, { href: cfg.liked_url, callback: this.google_log.bind(this, cfg), size:'medium', annotation:'bubble', expandto:'top', count:true }); new $t(function() { var ifr = pl.firstChild; ifr && !$u.ua_ie ? ifr.onload = this.google_clear.bind(this, cfg) : this.google_clear(cfg); }, this).set(5); }, google_log: function(response, cfg) { new $r(cfg.log_url,{ params:{href:response.href} }); }, google_clear: function(cfg) { $el.add(cfg.btn, "invisible"); }, facebook: function(btn, cfg) { btn.onmouseover = null; cfg.btn = btn; this.facebook_cfg = cfg; var fblike_tpl='<iframe src="{url}" onload="B.Likes.facebook_render()" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowTransparency="true"></iframe>'; var fblike_url='http:\/\/www.facebook.com/plugins/like.php?href={liked_url}&amp;send=false&amp;layout=button_count&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;height=21&amp;locale={locale}'; var fbl = btn.nextSibling; fbl.innerHTML = $u.tpl(fblike_tpl, {url: $u.tpl(fblike_url, {liked_url: cfg.liked_url, locale: cfg.locale})}); }, facebook_render: function() { $el.add(this.facebook_cfg.btn, "invisible"); }, tweeter: function(btn) { btn.onmouseover = null; $r.loader.add('http:\/\/platform.twitter.com/widgets.js', function(){ $el.add(btn, "invisible"); }, this ); }, vkontakte: function(btn, cfg) { btn.onmouseover = null; this.vkontakte_cfg = cfg; $r.loader.add("http:\/\/userapi.com/js/api/openapi.js?32", this.vkontakte_render, this ); }, vkontakte_render: function() { var cfg = this.vkontakte_cfg; VK.init({ apiId: cfg.api_id, onlyWidgets: true }); VK.Widgets.Like('vk_like', { type: cfg.type, pageTitle: cfg.title, pageDescription: cfg.description, pageUrl: cfg.url, pageImage: cfg.image }, cfg.page_id); }, nasaklassa: function(btn, cfg) { btn.onmouseover = null; $r.loader.add(JSRoot+'js/facebook/nk.js', function () { nk_cfg = { url: cfg.url, type: cfg.type, color: cfg.color, title:cfg.title, image:cfg.image, description:cfg.description, wid:cfg.wid }; new nk_fajne(nk_cfg); }); }, hyves: function(btn, cfg) { btn.onmouseover = null; cfg.btn = btn; this.hyves_cfg = cfg; var tpl = "<iframe onload='B.Likes.hyves_clear()' src='http:\/\/www.hyves.nl/respect/button?url={url}' style='border: medium none; overflow:hidden; width:150px; height:21px; background: transparent;' allowTransparency='true' transparent='transparent' scrolling='no' frameborder='0'></iframe>"; var el=$('hyves_like'); el.innerHTML = $u.tpl(tpl,{ url:$u.tpl(cfg.url,{}) }); }, hyves_clear: function() { var btn = this.hyves_cfg.btn; $el.add(btn, "invisible"); $el.add(btn.nextSibling, "invisible"); } }); B.Photo.Ovl=new $class(B.Page, { name:'Photo', photos:null, map:null, total:0, user_id:0, tb_url:'', tpl_loading:'<div class="dOvl-loading-icon"><div class="loading-icon"></div></div>', tpl_tb:'<img class="pv-tb" src="{tb}" alt="">', tpl_img:'<img class="pv-next pv-big" src="{url}" alt="">', tpl_rate:'<div class="pv_rate_wrap"><div class="pv_rate {zero}">\ <i class="cr tl"></i><i class="cr tr"></i><i class="cr br"></i><i class="cr bl"></i>\ <a href="{vote_url}" id="pv_rate" class="cnt" title="{rate} from 10 stars">{rate}</a>\ </div></div>', tpl_tags:'<div id="pv_blur" class="dtag-hover-pv pv-next"></div>', vote_url:'', img_active:false, preload_timer:null, _opened:0, abused:0, blocked:0, video_img:0, rate_re:/^[0-9.]+/, css_url:JSRoot+'css/photo-{dir}.css', init:function() { this.photos=[], this.map={}, this._rs={}; $e.on('.phovl, * .phovl',this.open,this); }, reopen:function() { var el=this.open_el; el.rel=this.photo_id; this.close(); this.open(el, 1); }, open:function(el, reopen) { if(this._opened) this.close(); $r.loader.add(this.css_url, this.resize, this); this._opened=1; var b=document.body; if(!this._bg){ this._bg=document.createElement('DIV'); this._bg.className='pv-bg'; b.appendChild(this._bg); } b.appendChild(this._cont||(this._cont=$u.tpl2el(this.tpl_loading))); $el.add(b,'pv-loading'); this.t=new $r(el.rev,{ params:{photo_id:el.rel, reopen:reopen}, ready:this.load, error:this.load_er },this); this.open_el={rev:el.rev,rel:el.rel}; }, load:function(res) { if(res.errno) return this.load_er(res); var vars=res['vars']; this.user_id=vars['user_id']; this.photo_id=vars['photo_id']; this.total=vars['total']; this.collect(vars['photos']); this.block_ovl=vars['block_ovl']; this.abuse_str=vars['abuse_str']; this.entries=vars['entries']; this.vote_url=vars['vote_url']; if(this.block_ovl) $r.loader.add(dOvl.css_url); $e.on({ '.phovl-close':this.close, '.pv-show':this.show, '.pv-prev':this.prev, '.pv-next':this.next, '.pv-current':this.reopen, '.pv-scroll-left':this.scroll_left, '.pv-scroll-right':this.scroll_right, '#abuse':this.abuse_confirm, '.pv-sub_to_com':this.subscribe, '#pv_rate':this.go_rate, '.pv-nomoderated':this.nomoderated },this); var b=document.body; this.el=$u.tpl2el(res['html']); b.removeChild(this._cont); b.appendChild(this.el); $el.del(b,'pv-loading'); $el.add(b.parentNode,'pv-opened'); this.img=$('pv_img'); this.tbw=$('pv_tbw'); this.tb=$el.down(this.el_pv_tbw, '.pv_tb_sel'); this.title=$('pv_title'); this.phnum=$('photo_pos'); this.descr=$('pv_descr'); this.img_preload=$('pv_preload'); var ph=this.map[this.photo_id]; this.entry_id=ph['entry_id']; if(!ph['url']) this.block(ph); this.draw_tb(ph.idx); this.comments=new B.Photo.Comments(this.user_id, res['vars']['likes'], ph, this.entries[this.entry_id], res['vars']['readonly']); if(this.blocked) this.comments.clean(); this.tags=new B.Photo.Tags(this.getWH.bind(this), vars['tags']); if(ph['video']) this.draw_video(ph); this.tags.create(ph.tags||(ph.tags={}),this.get_vars()); this.resize(); $e.add(document,'keydown',this.keypress,this); $e.add(window,'resize',this.resize_delayed,this); this.resize_timer=new $t(this.resize,this,100); ph.ready=1; $('pv_scroll_anchor').focus(); this.preload_timer=new $t(this.preload, this); this.preload_timer.set(500); }, load_er:function(er) { var b=document.body; b.removeChild(this._cont); $el.del(b,'pv-loading'); this._opened=0; if(er && ('html' in er)) dOvl.open_err({html:er.html}); }, close:function() { if(!this._opened) return; this._opened=0; dOvl.close(); $e.un({ '.phovl-close':this.close, '.pv-show':this.show, '.pv-prev':this.prev, '.pv-next':this.next, '.pv-current':this.reopen, '.pv-scroll-left':this.scroll_left, '.pv-scroll-right':this.scroll_right, '#abuse':this.abuse_confirm, '.pv-sub_to_com':this.subscribe, '#pv_rate':this.go_rate, '.pv-nomoderated':this.nomoderated },this); var b=document.body; $el.del(b.parentNode,'pv-opened'); b.removeChild(this.el); this.photos=[], this.map={}, this._rs={}; this.el=this.img=this.tbw=this.tb=this.title=this.phnum=this.descr=this.video=this.open_el=this.img_preload=null; this.comments.destroy(); this.comments=null; this.tags.destroy(); this.tags=null; this.abused=this.blocked=this.video_img=0; if(this.vars_set){ if(B.Upload) B.Upload.onComplete_fn=null; $vars['Upload'].onComplete_fn=null; this.vars_set=0; } $e.del(document,'keydown',this.keypress,this); $e.del(window,'resize',this.resize_delayed,this); this.resize_timer.clear(); this.resize_timer=null; this.preload_timer.clear(); this.preload_timer=null; }, get_vars:function() { var ph=this.map[this.photo_id]; return { user_id:ph.user_id||this.user_id, entry_id:this.entry_id, photo_id:this.photo_id }; }, collect:function(ar) { var ps=this.photos; for(var i=0, n=ar.length; i<n; i++){ this.map[ar[i]['id']]=ar[i]; ar[i].idx=ps.length; ps[ps.length]=ar[i]; } }, show:function(el) { if(!el.rel) el=el.parentNode; if(!el.rel) return; this.draw(this.map[el.rel]); }, prev:function() { if(this.tags.edit) return; var i=this.map[this.photo_id].idx; if(i==0) i=this.photos.length; this.draw(this.photos[i-1]); }, next:function() { if(this.tags.edit) return; var i=this.map[this.photo_id].idx, ps=this.photos; if(i==ps.length-1){ if(ps.length<this.total){ i=i-1; this.next_get(); }else{ i=-1; } } this.draw(ps[i+1]); }, draw:function(ph) { if(ph['id']==this.photo_id) return; if(this.blocked){ this.blocked=0; dOvl.close(); } if(this.abused){ this.abused=0; $el.del($('abuse').parentNode,'abused'); } if(this.video_img){ if(this.video) this.video.innerHTML=''; $el.del(this.el,'video-mode'); this.video_img=0; } this.tags.clean(); this.photo_id=ph['id']; if(ph['video']){ this.draw_video(ph); }else{ this.img.innerHTML=''; this.center(ph); if(ph['url']){ var html=''; html+=$u.tpl(this.tpl_tb,{tb:ph['tb']}); html+=$u.tpl(this.tpl_img,{url:ph['url']}); if(ph['rate']) html+=$u.tpl(this.tpl_rate,{ rate:ph['rate'], zero:(ph['rate']=='0.0'?'zero':''), vote_url:$u.tpl(this.vote_url,{user_id:ph.user_id||this.user_id}) }); if(!this.blocked) html+=this.tpl_tags; this.img.innerHTML=html; }else{ this.block(ph); } } this.draw_tb(ph.idx); var entry_id=ph['entry_id'], entry=this.entries[entry_id]; this.phnum.innerHTML='('+(ph.i||0)+'/'+entry.n+')'; if(ph.idx>=this.photos.length-2 && this.photos.length<this.total) this.next_get(); if(entry_id!=this.entry_id){ this.title.innerHTML=entry.title; $el.tgl(this.el,'yourself-mode',+entry.personal); $el.tgl(this.el,'private-mode',+entry.private); $el.tgl($('pvc_sub'),'enabled',+entry.subscribed); this.entry_id=entry_id; } this.descr.innerHTML=ph['descr']||''; if(this.blocked){ this.comments.clean(); }else{ $el.tgl(this.el,'notags-mode',+ph.no_tags); if(!ph['video']){ this.tags.create(ph.tags||(ph.tags={}),this.get_vars()); this.tags.resize(this.z); } this.comments.show(ph, entry); } this.preload_timer.set(250); }, draw_video:function(ph) { this.video_img=1; $el.add(this.el,'video-mode'); this.video=this.video||$('pv_video'); if(!$u.flash.init(9)){ $el.add(this.el,'no-flash'); return; } this.video.style.width=this.vw+'px', this.video.style.height=this.vh+'px'; this.video.innerHTML=$u.flash.draw(JSRoot+'flash/vp.swf', '100%', '100%', '', ph['url'], 1, 'video_frame'); }, draw_tb:function(idx) { var tb=this.tb, w=this.tbw; $el.del(tb,'pv_tb_sel'); this.tb=tb=$el.select(w,'a.pv_tb')[idx]; $el.add(tb,'pv_tb_sel'); var l1=tb.offsetLeft+tb.parentNode.offsetLeft, w1=tb.offsetWidth, l2=w.scrollLeft, w2=w.offsetWidth; if(l1<l2) w.scrollLeft=l1; else if(l1+w1>l2+w2) w.scrollLeft=l1+w1-w2; }, preload:function() { var ph=this.map[this.photo_id], i=ph.idx+1, ps=this.photos; if(i==ps.length) i=0; ph=ps[i]; if(ph.ready || !ph['url'] || ph['video']) return; var img=document.createElement('IMG'); img.src=ph['url']; this.img_preload.innerHTML=''; this.img_preload.appendChild(img); ph.ready=1; }, resize_delayed:function() { this.resize_timer.set(); }, resize:function() { if(!this.img) return; var el=this.img.parentNode; this.vw=el.offsetWidth, this.vh=el.offsetHeight; this.center(this.map[this.photo_id]); this.tags.resize(this.z); }, getWH:function() { var ph=this.map[this.photo_id]; return {width:this.z*ph['w'], height:this.z*ph['h']}; }, center:function(ph) { if(!this.video_img){ this.z=Math.min(Math.min(1,this.vh/ph['h']), Math.min(1,this.vw/ph['w'])); this.img.style.height=Math.floor(this.z*ph['h'])+'px', this.img.style.width=Math.floor(this.z*ph['w'])+'px'; }else{ this.video.style.width=this.vw+'px', this.video.style.height=this.vh+'px'; } }, block:function(ph) { if(ph['url']) return; if(ph.block=='nophoto'){ if(B.Upload) B.Upload.onComplete_fn=this.reopen.bind(this); else $vars['Upload']=$config($vars['Upload']||{},{onComplete_fn:this.reopen.bind(this)}); this.vars_set=1; } var b=this.block_ovl[ph.block]; dOvl.open_ex({type:b.type,html:b.html}); this.blocked=1; }, next_get:function() { var r=this._rs[this.photos.length]; if(r) return; this._rs[this.photos.length]=new $r(this.tb_url,{ params:{from:this.photos.length}, ready:this.next_ready, error:this.next_error },this); }, next_ready:function(res) { if(res['errno']) return this.next_error(); this._rs[this.photos.length]=true; this.tbw.innerHTML+=res['html']; this.collect(res['vars']['photos']); }, next_error:function() { delete this._rs[this.photos.length]; }, scroll:function(from,to) { if(to!=from) new $fx.effect({ wait:false, duration:500, items:[ new $fx.style({ el:this.tbw, prop:'height', from:from, to:to, step:function(ct,d) { this.el.scrollLeft=this.fx(ct,this.from,this.to,d); } }) ] }); }, scroll_left:function() { var w=this.tbw, from=w.scrollLeft, to=Math.max(0,w.scrollLeft-w.offsetWidth); if(from==to) to=w.scrollWidth; this.scroll(from,to); }, scroll_right:function() { var w=this.tbw, from=w.scrollLeft, to=Math.min(w.scrollLeft+w.offsetWidth,w.scrollWidth); if(from==to) to=0; this.scroll(from,to); }, abuse_confirm:function(el) { var xy=$e.pointerXY($e.e); $u.Confirm.show({ x:(xy.x-24), y:(xy.y-115), type:'confirm_claim', text:this.abuse_str, onOk:this.abuse.bind(this,$u.add_href(el.rev, 'confirm=1&photo_id='+this.photo_id)), scope:this }); }, abuse:function(url) { this.abused=1; $el.add($('abuse').parentNode,'abused'); new $r(url); }, subscribe:function(el) { var entry_id=this.entry_id, entries=this.entries, entry=entries[entry_id]; entry.subscribed=!entry.subscribed; if(entry_id=='tagged') entries['personal'].subscribed=entry.subscribed; if(entry_id=='personal' && ('tagged' in entries)) entries['tagged'].subscribed=entry.subscribed; $el.tgl(el.parentNode,'enabled'); new $r(el.rev,{ params:{entry_id:entry_id} }); }, go_rate:function(el) { window.location.href=$u.add_href(el.href, '&photo_id='+this.photo_id); }, keypress:function(el) { var code=$e.key($e.e); if(code==27){ this.close(); return false; } if(el.nodeName=='INPUT'||el.nodeName=='TEXTAREA') return true; switch(code){ case 27: this.close(); return false; case 39: case 74: this.next(); return false; case 37: case 75: this.prev(); return false; } return true; }, nomoderated:function(el) { var form=$el.up(el,'form'); $el.add(form,'el-loading'); new $r(form.action,{ method:form.method, params:$r.serialize(form), ready:this.reopen, error:this.reopen },this); } }); $u.dTooltip=$class({ el:null, type:'', target:'', cel:null, x:0, y:0, html:'', scope:null, _re:null, _wrap:null, _cont:null, _tpl:'<div class="js_tooltip pngbox">\ <div class="tpt">\ <div class="bpt">\ <div class="cont">\ {html}\ </div>\ <div class="bpc"></div>\ </div>\ </div>\ <div class="tcn"></div>\ <div class="bcn"></div>\ </div>', constructor:function(config) { $config(this,config); this.init(); }, init:function() { if(!this.el) throw new Error('No element for dTooltip'); this._re=new RegExp('(^|\\s)'+this.target+'(\\s|$)'); this._wrap=$el.create('div',{ id:'dTooltipWrap', className:'hidden', innerHTML:this._tpl }); this._cont = $el.down(this._wrap, '.cont'); document.body.appendChild(this._wrap); this.attachEventHandlers(); }, attachEventHandlers:function() { $e.add(this.el,'mouseover',this.test,this); $e.add(this.el,'mouseout',this.test,this); $e.add(this._wrap,'mouseout',this.test,this); }, detachEventHandlers:function() { $e.del(this.el,'mouseover',this.test,this); $e.del(this.el,'mouseout',this.test,this); $e.del(this._wrap,'mouseout',this.test,this); }, destroy:function() { this.detachEventHandlers(); $el.remove(this._wrap); this._wrap=null; this._cont=null; this.el=null; }, test:function(el) { var e=$e.e; if(e.type=='mouseout') el=e.relatedTarget||e.toElement; var p=el, cel=this.cel, w=this._wrap, b=document.body, re=this._re; if(el==cel) return; while(p && p!=cel && p!=w && !re.test(p.className) && p!=b) p=p.parentNode; if(!p || p==b) this.hide(); else if(p!=w && p!=cel) this.show(p); }, show:function(el) { this.cel=el; var config=this.format.call(this.scope || this,$(el)); if(el) el.title=''; this._cont.innerHTML=config.html; this._wrap.style.left=config.left+'px'; this._wrap.style.top=config.top+'px'; this._wrap.className=this.type; }, hide:function() { this._wrap.className='hidden'; this.cel=null; }, format:function(el) { var e=$e.e; var html=el.title; var xy=$e.pointerXY(e); return { left:xy.x, top:xy.y, html:html }; } }); B.GiftsViewClass = $class(B.Page, { name:'Gifts', gifts:{}, tpl:'<div class="giftbox"><div class="tr"></div>\ <div class="giftbox-line"></div>\ <span class="bullet"></span>\ <div class="br">\ <div class="gift_cont cont">\ {html}\ </div>\ </div>\ <div class="bl"></div></div>', init:function() { $e.on('.load_all_gifts', this.load_more, this); if($('gift_add_nosms')) new $u.Tooltip($('gift_add_nosms')); var gifts=$('gifts'); if(!gifts) return; this.gifts_tooltip=new $u.dTooltip({ _tpl:this.tpl, el:gifts, type:'giftboxs', target:'gift_tooltip_target', format:this.format_tooltip, scope:this }); if(this.gifts_tooltip && this.gifts_tooltip._wrap) this.gifts_tooltip._cont=$el.down(this.gifts_tooltip._wrap, '.gift_cont'); }, format_tooltip:function(el) { var img; if(el.nodeName!='IMG') img=el.parentNode.getElementsByTagName('IMG')[0]; else img=el; var m=/^gift([\d_]+)$/.exec(img.id); var gift_id = m&&m[1]||''; var gift=this.gifts[gift_id]; var anchor = $('gift_a_' + gift_id); if(!gift || !anchor ) return ''; var hidden = $el.has (anchor, 'hide_from_other'); this.gifts_tooltip.type = hidden ? 'w_giftbox hiddengiftbox' : 'w_giftbox'; var tl=$el.cumulativeOffset(el); var topOfs = 48; return { html:gift.tooltip, left:parseInt(tl.left+el.offsetWidth/2-17), top:tl.top+topOfs }; }, no_more:false, load_more:function(el) { if(!el || this.no_more) return; this._show_more_el=el; $el.add(el.parentNode, 'el-loading'); new $r(el.rev,{ ready:this.loaded, error:this.error },this); }, error:function() { $el.del(this._show_more_el.parentNode,'el-loading'); }, loaded:function(res) { this.no_more=true; var el=this._show_more_el; $el.del(this._show_more_el.parentNode,'el-loading'); if(res.errno) return; $el.add($el.up(el,'.profile_section'),'gifts-list-expanded'); var gifts=$('gifts'); for(var i in res.gifts){ var gift=res.gifts[i]; this.gifts[i]=gift; } gifts.innerHTML+=res.html; $e.un('.load_all_gifts', this.load_more, this); } }); B.ProfileNavigation=new $class(B.Page, { name:'ProfileNavigation', ofs:0, num:0, url_prev:'', url_next:'', iw:59, per_page:10, per_view:3, run:0, init:function() { $e.on({ '#nav_prev':this.prev, '#nav_next':this.next },this); this.w=$('nav_w'), this.line=$('nav_line'); }, prev:function() { if(this.run) return; this.scroll(this.ofs-this.per_view); }, next:function() { if(this.run) return; this.scroll(this.ofs+this.per_view); }, scroll:function(to) { if(this.num<=this.per_view) return; this.w.className=''; if(to<=0){ if(this.url_prev){ to+=this.per_page; this.c=$el.create('div',{className:'nav_c'}); this.line.insertBefore(this.c,this.line.firstChild); this.line.style.left=-(this.ofs+=this.per_page)*this.iw+'px'; this.request(-1); }else{ to=0; this.w.className='first'; } }else if(to>=this.num-this.per_view){ if(this.url_next){ this.c=$el.create('div',{className:'nav_c'}); this.line.appendChild(this.c); this.request(+1); }else{ to=this.num-this.per_view; this.w.className='last'; } } if(to==this.ofs) return; new $fx.effect({ wait:false, duration:250, items:[ new $fx.style({ el:this.line, from:-this.ofs*this.iw, to:-to*this.iw, prop:'left', dimm:'px' }) ], onEnd:function(){ this.run--; }, scope:this }); this.ofs=to; this.run++; }, request:function(dir) { var url=(this.dir=dir)>0 ? this.url_next : this.url_prev; this.r=this.r||new $r(url,{ auto:false, ready:this.ready },this); this.r.url=url; this.r.request(); $el.add(this.w,'el-loading'); this.run++; }, ready:function(res) { this.num+=res.num; this.c.innerHTML=res.html; if(this.dir>0) this.url_next=res.url_next; else this.url_prev=res.url_prev; $el.del(this.w,'el-loading'); this.run--; } }); $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); } }); B.UserAction=new $class(B.Page, { last_action:null, init:function() { $e.on('#mnpltn_more', this.show_actions, this); }, show_actions:function(el) { this.last_action=el=$el.up(el, '.mnpltn_w'); $el.add(el, 'or_pres'); $e.on('__all__',this.hide_actions,this); }, hide_actions:function() { if(this.last_action){ $el.del(this.last_action, 'or_pres'); this.last_action=null; } $e.un('__all__',this.hide_actions,this); } }); B.UploadFbc={ fb_ready:function(url) { setTimeout(function(){ dOvl.open_ex({type:'upload-import-fbc', url:url+'&ws=1'}); }, 100); }, fb_import_ready:function() { var form=$el.up($('fb_import_iframe'), 'form'); if(B.Import) B.Import._import_forms[1].submit() ; else if(B.UploadImport) B.UploadImport._import_forms[1].submit() ; } }; B.ScoialMeter=new $class(B.Page, { init:function() { $e.on({ '.sm_more':this.more, '.sm_cancel':this.cancel },this); this.form=$('sm_form'); if(this.form) $e.add(this.form,'submit',this.save,this); }, more:function(el) { $el.add(el,'el-loading'); new $r(el.href,{ ready:this.save_ready },this); }, save:function() { $el.add(this.form,'el-loading'); new $r(this.form.action,{ params:$r.serialize(this.form), ready:this.save_ready },this); return false; }, save_ready:function(res) { $e.del(this.form,'submit',this.save,this); $('sm_friends').innerHTML=res.html; this.form=$('sm_form'); $e.add(this.form,'submit',this.save,this); $el.del(this.form,'el-loading'); $el.del($el.up(this.form,'.scmt_frds_edit'),'scmt_frds_edit'); }, cancel:function(el) { this.form.reset(); B.Toggle.toggle(el); } }); B.GeoLocation=new $class(B.Page, { name:'GeoLocation', enabled:0, url:'/ws/geo.phtml', lat:0, lon:0, last:0, freq:60, cache:30, wait:30, init:function() { if(!navigator.geolocation || !(this.name in $vars)) return; $el.add(document.body,'geolocation'); $e.on('.pbda_geo_l', this.ask, this); this.ready_=this.ready.bind(this), this.error_=this.error.bind(this); this.t=new $t(this.request, this); if(this.last) this.t.set(Math.max(1000,this.freq*1000-this.last)); else if(this.enabled) this.t.set(1000); }, ask:function(el) { new $r(this.url,{params:{lon:0,lat:0}}); this.request(); dOvl.close(); }, request:function() { navigator.geolocation.getCurrentPosition(this.ready_,this.error_,{ enableHighAccuracy:true, timeout:this.wait*1000, maximumAge:this.cache*1000 }); }, ready:function(pos) { this.send(pos.coords.latitude, pos.coords.longitude, 0); }, error:function(er) { this.send(0,0,er.code); }, send:function(lat,lon,er) { this.lat=lat,this.lon=lon; new $r(this.url,{ params:{lat:lat,lon:lon,error:+er||0} }); this.t.set(this.freq*1000); } }); $u.chkToggle=new $class(B.Page, { init:function() { $e.on({ '.chk':this.chk, '.chk-all':this.chk_all, '.chk-gr':this.chk_gr },this); this.t=new $t(this.update, this); }, chk:function(el) { $el.tgl(el.parentNode,'checked'); this.t.set(0,el.form,$el.up(el,'.chk-w')); return true; }, chk_all:function(el) { this.set(el.form.elements, el.checked); this.t.set(0,el.form); return true; }, chk_gr:function(el) { this.set($el.select($el.up(el,'.chk-w'),'input'), el.checked); this.t.set(0,el.form); return true; }, set:function(els, st) { var c=0, tgl=st?$el.add:$el.del; for(var i=0, el, n=els && els.length; i<n; i++){ el=els[i]; if((el.type=='checkbox' || el.type=='radio') && ($el.has(el,'chk') || $el.has(el,'chk-gr'))){ if(st!==undefined && !el.disabled){ el.checked=st; tgl(el.parentNode,'checked'); } if(el.checked && !$el.has(el,'chk-gr')) c++; } } return c; }, update:function(form, gr_w) { var el=$el.down(form,'.chk-num'), need=el && $el.down(form,'.chk-needed'), bn=$el.down(form,'.chk-bn'), c=this.set(form.elements); if(el){ el.innerHTML=c; if(need) (c>=+need.innerHTML?$el.del:$el.add)(el.parentNode,'accent_orange'); } if(bn) (c?$el.del:$el.add)(bn,'tooltip'); if(gr_w){ var els=$el.select(gr_w,'.chk'), c=0, a=0; if(!els.length) return; for(var i=0, n=els && els.length; i<n; i++){ el=els[i]; if(el.checked) c++; a++; } if(c==0 || c==a){ el=$el.down(gr_w,'.chk-gr'); if(el) el.checked=c==a; } } } }); B.InterestCommon = $class( { constructor: function() { $e.on({ ".pf_ints_showall": this.showallInterest, ".pf_ints_create": this.createInterest }, this); }, showallInterest: function(el) { this.t = new $r(el.href,{ method: 'post', ready: this.refreshInterests },this); }, createInterest: function(el) { dOvl.close(); if (this.sg) this.sg.clear(); this.t = new $r(el.href,{ method: 'post', ready: this.refreshInterests },this); }, refreshInterests: function(res) { var ls = this.board || $('pf_ints_ls'); if (ls) ls.innerHTML = res.interests; } }); B.InterestView = new B.InterestCommon(); B.GiftsView = new B.GiftsViewClass(); B.ProfileView=new $class(B.Page, { name:'ProfileView', remove_str:['Remove {name} from {folder}?', 'Remove', 'or', 'Cancel'], add_make_meet:false, init:function() { $e.on({ '.add_contcat':this.add_contact, '.remove_contcat':this.remove_contact },this); }, add_contact:function(el) { this.send(el.rel||el.href); }, remove_contact:function(el) { if($e.e.shiftKey) this.send(el.rel||el.href); var xy=$e.pointerXY($e.e); $u.Confirm.show({ x:(xy.x-35), y:(xy.y-115), type:'b_tail', text:this.remove_str, onOk:this.send.bind(this,el.rel||el.href), scope:this }); }, send:function(url) { new $r(url,{ method:'post', params:{ws:1}, ready:this.data_ready },this); }, data_ready:function(res) { $('in_folder').innerHTML=res.html; if(res.remove_str) this.remove_str=res.remove_str; if(this.add_make_meet) $el.add($('for_make_meet'), 'make_meet'); } });
