$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--; } }); B.UCounter = new $class(B.Page, { name: "UCounter", value: null, speed: null, url_sync: null, spf: 3000, step_to_sync: 10, els: {}, timer: null, step_num: 0, digits_value: null, init: function() { this.digits_value = this.value.toString().split("").reverse(); for (var i=0; i < this.digits_value.length; i++) { this.els[i] = $("mp_cnt_pos_"+i); if (!this.els[i]) return; } this.timer = new $t(this.step, this); this.run(); }, run: function() { this.ups = this.spf/1000*this.speed; this.delta = this.ups * 0.3; this.ups = this.ups * 0.7; this.timer.set(this.spf); }, step: function() { this.step_num++; this.value += this.ups + this.delta * Math.sin(this.step_num / this.step_to_sync * Math.PI * 2); var value = Math.floor(this.value); this.refreshDigits(value); this.step_num == this.step_to_sync ? this.sync() : this.timer.set(this.spf); }, refreshDigits: function(newvalue) { newvalue = newvalue.toString().split("").reverse(); var need_change = {}; for (var i=0; i <= newvalue.length; i++) if (newvalue[i] != this.digits_value[i]) need_change[i] = {from: this.digits_value[i], to: newvalue[i]}; this.digits_value = newvalue; this.timer_animate = new $t(this.animate, this); this.animate(need_change, 0); }, animate: function(data, state, isdata) { state = state == 2 ? 0 : state+1; for (var r in data) { isdata = 1; if (state == 0) data[r].from = data[r].from == 9 ? 0: +data[r].from +1; this.els[r].className = "mp_cnt_d mp_cnt_d_" + data[r].from +(state ? ("_" + state): ""); if (data[r].from == data[r].to) delete(data[r]); } if (isdata) this.timer_animate.set(40, data, state); }, sync: function() { new $r(this.url_sync, { ready: this.sync_ready },this); }, sync_ready: function(res) { this.step_num = 0; this.value = res.value; this.speed = res.speed; this.run(); } }); B.Captcha=new $class(B.Page, { init:function() { $e.on('.reset_check,* .reset_check', this.reload_capcha, this); }, reload_capcha:function(el) { var img=$('check_code_img'), inp=$('checkcode'), src; if(!img) return true; src=img.src, img.src=JSRoot+'i/blank.png', img.src=src.split('?')[0]+'?reload=1&rand='+Math.random(); inp.value=''; inp.focus(); } }); $u.Suggest=$class({ w:null, el:null, id:null, n:0, constructor:function(w,url) { if(!w || !url) return; this.w=w; this.el=$el.down(w,'.ds_input'); this.id=$el.down(w,'.ds_id'); this.res=$el.down(w,'.ds_res'); this.ovl=$el.down(w,'.ds_ovl'); this.geo=$el.down(w,'.ds_geo_simple'); this._cache={ '':{ q:'', locations:this.res.innerHTML, n:this.n=($el.select(this.res,'li')).length } }; this._v=this.el.value; this.t=new $r(url,{ auto:false, method:'get', ready:this.ready, error:this.error },this); this.timer=new $t(this.suggest,this,250); $e.add(this.el,'keydown',this.keydown,this); $e.add(this.el,'focus',this.focus,this); $e.add(this.res,'mouseover',this.hover,this); $e.add(this.res,'click',this.click,this); this.ovl && $e.add(this.ovl,'click',this.ovl_open,this); this.geo && $e.add(this.geo,'click',this.geo_click,this); }, destroy:function() { this.timer.clear(); this.t.abort(); $e.del(this.el,'keydown',this.keydown,this); $e.del(this.el,'focus',this.focus,this); $e.del(this.res,'mouseover',this.hover,this); $e.del(this.res,'click',this.click,this); $e.del(this.ovl,'click',this.ovl_open,this); this.geo && $e.del(this.geo,'click',this.geo_click,this); this.w=this.el=this.id=this.res=this.ovl=this.geo=this.t=null; }, focus:function(el) { if(!el || $e.e.type!='focus') this.el.focus(); if(!this._active){ this._active=true; this.el.select(); this.draw(); } return true; }, suggest:function() { var v=this.el.value; v=v.replace(/(^[\s,]+|[\s,]+$)/g,''); if(this._v==v) return; this.id.value=''; if(v.length<2){ this._v=''; this.ready(this._cache['']); return; } this._v=v; var res=this._cache[v]; if(res) this.ready(res); else this.t.request({q:v}); }, ready:function(res) { this._cache[res.q]=res; this.res.innerHTML=res.locations; this.n=res.n; this.draw(); }, error:function(er) { this.res.innerHTML=''; this.n=0; this.draw(); }, select:function(el) { var i=el||$el.down(this.res,'.selected'); if(!i) return; this.set(i.id.replace('dsi_',''), i.textContent || i.innerText); return true; }, keydown:function() { var e=$e.e, code=e.charCode||e.keyCode||e.which||0; switch(code){ case 40: this.highlight(+1); break; case 38: this.highlight(-1); break; case 13: if(!this.select()) return; this._active=false; this.draw(); this.el.blur(); break; default: this.timer.set(); return true; } }, highlight:function(d) { var els=$el.select(this.res,'li'), n=els.length, idx=-1; if(!n) return; for(var i=0; i<n; i++){ if(els[i].className=='selected'){ els[i].className=''; idx=i; break; } } i=(idx+d)%n; if(i<0) i=n-1; els[i].className='selected'; this.select(els[i]); }, hover:function(el) { if(!this.n||!el) return; while(el && el.nodeName!='LI'){ if(el==this.res) return; el=el.parentNode; } if(el){ var o=$el.down(this.res,'.selected'); if(o==el) return; $el.del(o,'selected'); el.className='selected'; } }, click:function(el) { if(!this.n||!el) return true; while(el && el.nodeName!='LI'){ if(el==this.res) return true; el=el.parentNode; } if(el){ if(!this.select(el)) return; this._active=false; this.draw(); } }, draw:function() { this.w.className='dSuggest '+(this._active && 'ds_focus ' || '')+(!this.n && this._v && 'ds_nothing ' || ''); }, geo_click:function(el) { this.set(el.rel,el.rev); }, ovl_open:function(el) { dOvl.open_ex({ type:'loc-ovl', url:el.rev, set_location:this.set_close.bind(this) }); }, set:function(id,text) { this.id.value=id; this.el.value=this._v=text; $el.add($el.down(this.w,'.input_error'),'hidden'); }, set_close:function(id,text) { this.set(id,text); this._active=false; this.draw(); } }); B.MsgClose=new $class(B.Page, { shown:false, init:function() { $e.on('.msg-close', this.msg_close, this); setTimeout(this.show.bind(this), 500); }, show:function() { if(this.shown) return; this.shown=true; var el=$el.down(document.body,'.valert'); if(!el) return; new $fx.effect({ wait:false, duration:500, items:[ new $fx.style({ el:el, prop:'height', from:0, start:function() { this.el.style.height='0'; this.el.style.display='block'; this.to=this.el.scrollHeight; }, end:function() { this.el.style.height=''; } }) ] }); }, msg_close:function(a) { var el=$el.up(a,'.cfm'); if(!el) return; new $fx.effect({ wait:false, duration:300, items:[ new $fx.style({ el:el, prop:'height', start:function() { this.from=this.el.offsetHeight; this.el.style.overflow='hidden'; }, end:function() { this.el.parentNode.removeChild(this.el); } }) ] }); if(a.rev) new $r(a.rev); } }); $u.autofocus=function(w){ var el=$el.down(w,'.autofocus'); try{ el && el.focus(); }catch(er){} }; $e.onload($u.autofocus); B.EmailMisprint=new $class(B.Page, { name:'EmailMisprint', el:null, url:'', error_tpl:'', er:null, email:'', corrected_email:'', _cache:{}, init:function() { this.el=$el.down(document.body,'.email_misprint'); if(!this.el || !this.url) return; this._cache[this.email]=true; this._cache[this.corrected_email]=true; if(this.corrected_email) this.er=$el.down(this.el.parentNode,'.input_error_blue'); $e.on('.email_misprint_revert',this.revert,this); $e.add(this.el,'blur',this.correct,this); }, correct:function(el) { var q=this.el.value; if(q in this._cache) return; if(!q || q==this.email || q==this.corrected_email) return; this._cache[q]=true; if(this._loading) this._transport.abort(); this._loading=true; this.email=q; this._transport=new $r(this.url,{ params:{q:q}, ready:this.loaded, error:this.load_error },this); }, revert:function(el) { if(this._loading){ this._transport.abort(); this._loading=false; } this.el.value=this.email; this.hide_error(); new $r(this.url,{ params:{change_back:this.email} }); }, loaded:function(res) { this._loading=false; if(!res.errno) this.hide_error(); else this.show_error(res.q,res.email); }, load_error:function() { this._loading=false; }, show_error:function(email,corrected_email) { if(this.el.value!=email) return; this._cache[corrected_email]=true; this.corrected_email=corrected_email; this.el.value=corrected_email; if(!this.er){ this.er=$u.tpl2el(this.error_tpl); this.el.parentNode.insertBefore(this.er,this.el); } this.er.style.display='block'; }, hide_error:function() { if(this.er) this.er.style.display='none'; } }); B.Signup=new $class(B.Page, { name:'Signup', passwd_min:5, focused:false, init:function() { this.form=$('signup_form'); if(!this.form) return; $e.on({ '.show_interest':this.show_interest },this); var el=$el.down(this.form,'.dSuggest'); if(el) this.suggest=new $u.Suggest(el,$vars['Suggest']['url']); $e.add(this.form,'submit',this.submit,this); $('email') && $e.add($('email'),'focus',this.focus,this); $('first_name') && $e.add($('first_name'),'focus',this.focus,this); el=$('js_pw_input'); if(el) new $u.PasswordStrength({ target:el, msg_target:$('js_pw_tooltip'), min_chars:this.passwd_min }); }, submit:function() { if(!this.focused) this.focus(); if(this.form.elements['location_id'].value){ $el.add(this.form,'el-loading'); return true; } var er=$el.down(this.form,'.dSuggest .input_error'); $el.del(er,'hidden'); this.suggest.focus(); }, focus:function() { $('email') && $e.del($('email'),'focus',this.focus,this); $('first_name') && $e.del($('first_name'),'focus',this.focus,this); $el.add(this.form, 'view_all_fields'); this.focused=true; }, setupNumPhotos:function(v) { if($('photo_quant_field')) $('photo_quant_field').value=v; }, show_interest:function() { $e.un('.show_interest', this.show_interest, this); var el=$el.down(null,'.w_interest'); if(!el) return true; new $fx.effect({ wait:false, duration:200, items:[ new $fx.style({ el:el, prop:'height', start:function() { this.from=0; var s=this.el.style; s.overflow='hidden'; s.height=this.from+'px'; this.to=this.el.scrollHeight; } }) ] }); return true; } }); $u.PasswordStrength=$class({ target :null, msg_target :null, min_chars :5, messages : ['js_pw_info','js_pw_toshort', 'js_pw_weak', 'js_pw_medium', 'js_pw_strong'], character_classes : [ /[a-z]/, /[A-Z]/, /\d/, /\s/, /[-!"#$%&'()*+,.\/:;<=>?@[\\\]_`{|}~]/, /[^a-zA-Z\d\s-!"#$%&'()*+,.\/:;<=>?@[\\\]_`{|}~]/ ], constructor:function(config) { $config(this, config); this.init(); }, init:function() { if(!this.target||!this.msg_target) return; if(this.target.value) this.test(); $e.add(this.target,'keyup',this.test,this); }, test:function(el) { var re=this.character_classes; var v=this.target.value; var idx=1; if(v.length<this.min_chars){ idx=v?1:0; }else{ for(var i=0, n=re.length; i<n; i++){ if(re[i].test(v)) idx++; } idx=(idx>4?4:idx); } this.msg_target.className=this.messages[idx]; } }); B.ProfileViewUnauth=new $class(B.Page, { init:function() { $e.on('.phovl, * .phovl', this.open_photo, this); }, open_photo:function(el) { window.location.href=el.rev; } });
