Commit b4f9d430 authored by PhoeniX's avatar PhoeniX

Base user info

parent 5e029c7b
img/info.png

646 Bytes

......@@ -5,16 +5,86 @@ Blocks.page = (function(){
block.style.background = '#fff';
}, format_block = function(block,user){
endload(block);
block.appendChild(document.createElement('pre')).innerHTML = JSON.stringify(user,null,'\t');
var userinfo = block.appendChild(document.createElement('div'));
userinfo.style.margin = 0;
userinfo.style.cssFloat = 'left';
userinfo.style.width = '100%';
userinfo.style.backgroundColor = '#384555';
userinfo.style.color = '#fff';
var avatar = userinfo.appendChild(document.createElement('img'));
avatar.src = user.photo_50;
avatar.style.width = avatar.style.height = '50px';
avatar.style.borderRadius = '4px';
avatar.style.cssFloat = 'left';
avatar.style.margin = '10px';
var fullname = userinfo.appendChild(document.createElement('div')), name = [];
name.push(user.first_name);
if (user.nickname) name.push(user.nickname);
name.push(user.last_name);
fullname.style.cssFloat = 'left';
fullname.style.width = '-moz-calc(100% - 112px)';
fullname.style.marginTop = '10px';
fullname.style.height = '16px';
fullname.style.lineHeight = '16px';
fullname.innerHTML = name.join(' ');
var fullinfo = userinfo.appendChild(document.createElement('div'));
fullinfo.style.cssFloat = 'right';
fullinfo.style.height = '70px';
fullinfo.style.width = '32px';
fullinfo.style.background = 'url("img/info.png") center center no-repeat';
var online = userinfo.appendChild(document.createElement('div'));
online.style.cssFloat = 'left';
online.style.width = '-moz-calc(100% - 112px)';
online.style.height = '17px';
online.style.lineHeight = '17px';
online.style.color = '#aaa';
online.style.fontSize = '14px';
online.innerHTML = user.online ? (user.online_mobile ? ("📱online") : "online") : ("заходил " + (new Date(user.last_seen.time*1000)).toVKDateString());
var agecity = userinfo.appendChild(document.createElement('div'));
agecity.style.cssFloat = 'left';
agecity.style.width = '-moz-calc(100% - 112px)';
agecity.style.height = '17px';
agecity.style.lineHeight = '17px';
agecity.style.marginBottom = '10px';
var ac = document.createDocumentFragment();
if (user.bdate) {
var bdate = user.bdate.split('.'), dt;
if (bdate.length == 3) {
while(bdate[0].length < 2) bdate[0] = '0'+bdate[0];
while(bdate[1].length < 2) bdate[1] = '0'+bdate[1];
while(bdate[2].length < 4) bdate[2] = '0'+bdate[2];
var age = new Date(((new Date()).getTime() - (new Date(bdate.reverse().join('-'))).getTime())).getFullYear() - 1970;
dt = age + ' ' + ['год','года','лет'][ (age%100>4 && age%100<20)? 2 : [2, 0, 1, 1, 1, 2][(age%10<5)?age%10:5] ];
}
if (bdate.length == 2) {
while(bdate[0].length < 2) bdate[0] = '0'+bdate[0];
while(bdate[1].length < 2) bdate[1] = '0'+bdate[1];
dt = bdate.join('.');
}
ac.appendChild(document.createTextNode(dt));
}
if (user.city) {
var cs = ac.appendChild(document.createElement('span'));
VK.api.call('database.getCitiesById',{"city_ids": user.city}, function(r){
cs.innerHTML = (user.bdate ? ', ' : '') + r.response[0].name;
});
}
agecity.appendChild(ac);
var dbg = block.appendChild(document.createElement('pre'));
dbg.style.clear = 'both';
dbg.innerHTML = JSON.stringify(user,null,'\t');
};
return function(params){
var vk_params = {
"fields": "sex,bdate,city,country,online,online_mobile,"+
"lists,has_mobile,contacts,connections,site,"+
"education,universities,schools,can_post,"+
"can_see_all_posts,can_see_audio,"+
"can_write_private_message,status,last_seen,"+
"common_count,relation,relatives,counters,screen_name"
"fields": "screen_name,nickname,sex,bdate,online,online_mobile,status,last_seen,"+
"city,country,photo_50,"+
"has_mobile,contacts,connections,site,"+
"universities,schools,"+
"relation,relatives,counters,occupation,"+
"can_post,can_see_all_posts,can_see_audio,can_write_private_message,wall_comments,"+
"personal,activities,interests,music,movies,tv,books,games,about,quotes"
};
if (params.uid) vk_params['user_ids'] = params.uid;
var block = document.createElement('div');
......@@ -29,4 +99,4 @@ Blocks.page = (function(){
});
return block;
};
})();
\ No newline at end of file
})();
......@@ -124,4 +124,24 @@ VK = {
}
},
"permissions": "wall,messages,friends"
};
\ No newline at end of file
};
Date.prototype.toVKDateString = function(){
var curDate = new Date(), months = ['января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря'];
if (this.getFullYear() == curDate.getFullYear()) {
if ((this.getMonth() == curDate.getMonth()) && (curDate.getDate() - this.getDate() < 10)) {
var dc = curDate.getDate() - this.getDate(), mins = (curDate.getHours() * 60 + curDate.getMinutes()) - (this.getHours() * 60 + this.getMinutes()) + (dc-1)*60*24;
if (mins < 0) mins += 60*24;
if (mins < 60) {
return mins + ' ' + ['минуту','минуты','минут'][ (mins%100>4 && mins%100<20)? 2 : [2, 0, 1, 1, 1, 2][(mins%10<5)?mins%10:5] ] + ' назад';
}
if (dc == 0) {
return 'сегодня в ' + this.getHours() + ':' + this.getMinutes();
} else if (dc == 1) {
return 'вчера в ' + this.getHours() + ':' + this.getMinutes();
}
return dc + ' ' + ['день','дня','дней'][ (dc%100>4 && dc%100<20)? 2 : [2, 0, 1, 1, 1, 2][(dc%10<5)?dc%10:5] ] + ' назад';
}
return this.getDate() + ' ' + months[this.getMonth()]
}
return this.getDate() + ' ' + months[this.getMonth()] + ' ' + this.getFullYear() + 'года';
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment