NxTIC/js/includes/min/input-facebook-contact.js

10 lines
2.9 KiB
JavaScript
Raw Normal View History

function inputFacebookContact(a,c){this.container=a;this.nav_container=c}inputFacebookContact.prototype={container:this.container,nav_container:this.nav_container,selected:0,handler:null};inputFacebookContact.prototype.check=function(a){return!isNaN(a.existing)||0<a.username.length};
inputFacebookContact.prototype.fieldsToStorage=function(){console.group("[facebook.contact] fields to storage");for(var a=$$('[data-sublink="facebook"] article.contact-panel .new-contact'),c=0;c<a.length;c++){var b=(new FormDeflater(a[c],["input","select"],["data-name"])).deflate();if(this.check(b)){var d={uid:parseInt(b.uid),username:b.username,firstname:b.firstname,lastname:b.lastname,existing:isNaN(b.existing)?".":parseInt(b.existing)};d.hash=crc32(JSON.stringify(d));lsi.set("f_contacts",parseInt(b.uid),
d)}}console.groupEnd()};
inputFacebookContact.prototype.add=function(a){if(null==a||null==a.uid||isNaN(a.uid))return!1;a.username=null!=a.username?a.username:"";a.existing=null!=a.existing?a.existing:".";var c=lsi["export"]("f_friends");a.contacts="";for(var b in c)a.contacts+="\t\t<option value='"+b+"'>"+c[b].name+"</option>\n";this.container.innerHTML+=fContactBuilder.build(a);b=$('[data-sublink="facebook"] article.contact-panel .new-contact input[data-name="uid"][value="'+a.uid+'"] ~ span select[data-name="existing"]>option[value="'+a.existing+
'"]');null!=b&&b.setAttribute("selected","selected");a=$$('[data-sublink="facebook"] article.contact-panel .new-contact');var d=this;for(b=0;b<a.length;b++)a[b].removeEventListener("click",function(a){d.nav(a.target);d.handler(a.target)},!1),a[b].addEventListener("click",function(a){d.nav(a.target);d.handler(a.target)},!1)};
inputFacebookContact.prototype.storageToFields=function(){console.group("[facebook.contact] storage to fields");var a=lsi.keys("f_contacts");this.container.innerHTML="";for(var c=this.selected+10,b=this.selected;b<c&&b<a.length;b++)this.add(lsi.get("f_contacts",a[b]));c>=a.length&&this.add({uid:a.length});this.updateNavBar();console.groupEnd()};
inputFacebookContact.prototype.nav=function(a){if(null==a||!1===a.getData("n")||isNaN(a.getData("n"))||"f_nav-contact"!=a.parentNode.id)return!1;for(var c=$$('[data-sublink="facebook"] #f_nav-contact > span.active'),b=0;b<c.length;b++)c[b].remClass("active");a.addClass("active");this.selected=parseInt(a.getData("n"))};
inputFacebookContact.prototype.updateNavBar=function(){var a=lsi.keys("f_contacts").length;if(this.nav_container.children.length!=a){this.nav_container.innerHTML="";for(var c=0;c<a;c+=10)this.nav_container.innerHTML+='<span data-n="'+c+'">'+(1+c/10)+"</span>"}this.nav($('[data-sublink="facebook"] #f_nav-contact [data-n="'+this.selected+'"]'))};
inputFacebookContact.prototype.attach=function(a){console.group("[facebook.contact] attaching events");lsi.createDataset("f_contacts");this.storageToFields();this.handler=a;var c=this;this.nav_container.addEventListener("click",function(a){c.nav(a.target);c.handler(a.target)},!1);console.groupEnd()};