Commit 3a25d43b authored by PhoeniX's avatar PhoeniX

Working profile & cross-profile navigation

parent ac19a496
......@@ -50,9 +50,13 @@ Blocks.page = (function(){
"<img src=\"/img/online/mobile.png\" style=\"vertical-align:middle\">"
) : ""
) + "online"
) : (
"заходил " + (new Date(user.last_seen.time*1000)).toVKDateString()
);
) : user.last_seen ? (
"заходил"+(
user.sex ?
(user.sex == 1 ? "а" : "")
: ""
) + " " + (new Date(user.last_seen.time*1000)).toVKDateString()
) : "offline";
var agecity = userinfo.appendChild(document.createElement('div'));
agecity.style.cssFloat = 'left';
agecity.style.width = '-moz-calc(100% - 112px)';
......@@ -68,18 +72,13 @@ Blocks.page = (function(){
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] ];
ac.appendChild(document.createTextNode(dt));
}
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 = (agecity.childNodes.length ? ', ' : '') + r.response[0].name;
cs.innerHTML = (agecity.childNodes.length > 1 ? ', ' : '') + r.response[0].name;
});
}
agecity.appendChild(ac);
......@@ -131,6 +130,14 @@ Blocks.page = (function(){
mobile.style.backgroundImage = 'url("/img/contacts/mobile_phone.png")';
mobile.addEventListener('touchstart',ts);
mobile.addEventListener('touchend',te);
mobile.addEventListener('click',function(){
new MozActivity({
name: "dial",
data: {
number: user.mobile_phone
}
});
});
contacts.appendChild(sep.cloneNode());
}
if (user.home_phone) {
......@@ -139,14 +146,20 @@ Blocks.page = (function(){
home.style.backgroundImage = 'url("/img/contacts/home_phone.png")';
home.addEventListener('touchstart',ts);
home.addEventListener('touchend',te);
home.addEventListener('click',function(){
new MozActivity({
name: "dial",
data: {
number: user.home_phone
}
});
});
contacts.appendChild(sep.cloneNode());
}
if (user.skype) {
var skype = contacts.appendChild(item.cloneNode());
skype.innerHTML = user.skype;
skype.style.backgroundImage = 'url("/img/contacts/skype.png")';
skype.addEventListener('touchstart',ts);
skype.addEventListener('touchend',te);
contacts.appendChild(sep.cloneNode());
}
if (user.facebook) {
......@@ -155,6 +168,9 @@ Blocks.page = (function(){
facebook.style.backgroundImage = 'url("/img/contacts/facebook.png")';
facebook.addEventListener('touchstart',ts);
facebook.addEventListener('touchend',te);
facebook.addEventListener('click',function(){
Interface.openLink("https://facebook.com/"+user.facebook);
});
contacts.appendChild(sep.cloneNode());
}
if (user.twitter) {
......@@ -163,6 +179,9 @@ Blocks.page = (function(){
twitter.style.backgroundImage = 'url("/img/contacts/twitter.png")';
twitter.addEventListener('touchstart',ts);
twitter.addEventListener('touchend',te);
twitter.addEventListener('click',function(){
Interface.openLink("https://twitter.com/"+user.twitter);
});
contacts.appendChild(sep.cloneNode());
}
if (user.site) {
......@@ -171,13 +190,24 @@ Blocks.page = (function(){
site.style.backgroundImage = 'url("/img/contacts/site.png")';
site.addEventListener('touchstart',ts);
site.addEventListener('touchend',te);
contacts.appendChild(sep.cloneNode());
site.addEventListener('click',function(){
Interface.openLink(user.site);
});
contacts.appendChild(sep.cloneNode());
}
var vk = contacts.appendChild(item.cloneNode());
vk.innerHTML = 'https://vk.com/'+user.screen_name;
vk.style.backgroundImage = 'url("/img/contacts/vk.png")';
vk.addEventListener('touchstart',ts);
vk.addEventListener('touchend',te);
vk.addEventListener('click',function(){
new MozActivity({
name: "copy",
data: {
text: "https://vk.com/"+user.screen_name
}
});
});
var links = fullinfo.appendChild(document.createElement('div')), ttitle = document.createElement('div'), timg = document.createElement('img'), ls;
links.style.margin = '10px 0';
......@@ -200,20 +230,26 @@ Blocks.page = (function(){
if (user.occupation) {
var occupation = links.appendChild(item.cloneNode()), img = timg.cloneNode(), title = ttitle.cloneNode();
occupation.appendChild(img);
if (user.occupation.id) {
occupation.appendChild(img);
(function(img){
VK.api.call('groups.getById',{gid:user.occupation.id},function(r){
img.src = r.response[0].photo;
});
})(img);
occupation.addEventListener('touchstart',ts);
occupation.addEventListener('touchend',te);
} else {
occupation.style.padding = '0 5px 10px 5px';
occupation.style.minHeight = null;
occupation.style.background = null;
}
title.innerHTML =
user.occupation.type == 'work' ? 'Место работы' :
user.occupation.type == 'university' ? 'Место учёбы' :
user.occupation.type == 'school' ? 'Школа' : '';
occupation.appendChild(title);
occupation.appendChild(document.createTextNode(user.occupation.name));
(function(img){
VK.api.call('groups.getById',{gid:user.occupation.id},function(r){
img.src = r.response[0].photo;
});
})(img);
occupation.addEventListener('touchstart',ts);
occupation.addEventListener('touchend',te);
ls = links.appendChild(sep.cloneNode());
}
if (user.relatives) {
......@@ -236,6 +272,13 @@ Blocks.page = (function(){
});
person.addEventListener('touchstart',ts);
person.addEventListener('touchend',te);
person.addEventListener('click',function(){
var newblock = Blocks.page({uid: rel.uid}, block.setTitle,block.module);
newblock.restoreTitle = function(){
block.setTitle(user.first_name + ' ' + user.last_name);
};
Interface.push(null, newblock);
});
})(rel,person,img,title);
ls = links.appendChild(sep.cloneNode());
}
......@@ -436,7 +479,7 @@ Blocks.page = (function(){
if (ls) ls.remove();
if (personal.childNodes.length == 0) personal.remove();
for (var i in {
/*for (var i in {
"uid": 1,
"first_name": 1,
"last_name": 1,
......@@ -476,9 +519,9 @@ Blocks.page = (function(){
var dbg = block.appendChild(document.createElement('pre'));
dbg.style.overflow = 'hidden';
dbg.style.clear = 'both';
dbg.innerHTML = JSON.stringify(user,null,'\t');
dbg.innerHTML = JSON.stringify(user,null,'\t');*/
};
return function(params){
return function(params,setTitle){
var vk_params = {
"fields": "screen_name,nickname,bdate,online,online_mobile,status,last_seen,"+
"sex,city,country,photo_50,"+
......@@ -488,15 +531,25 @@ Blocks.page = (function(){
"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 (!setTitle) setTitle = function(){};
if (params.uid) vk_params['user_ids'] = params.uid;
var block = document.createElement('div');
block.setTitle = setTitle;
startload(block);
if (!params.uid && cache[0]) format_block(block,cache[0]);
else if (params.uid && cache[params.uid]) format_block(block,cache[params.uid]);
if (!params.uid && cache[0]) {
var user = cache[0];
setTitle(user.first_name + ' ' + user.last_name);
format_block(block,user);
} else if (params.uid && cache[params.uid]) {
var user = cache[params.uid];
setTitle(user.first_name + ' ' + user.last_name);
format_block(block,user);
}
else VK.api.call('users.get',vk_params,function(r){
var user = r.response[0];
cache[user.uid] = user;
if (!params.uid) cache[0] = user;
setTitle(user.first_name + ' ' + user.last_name);
format_block(block,user);
});
return block;
......
......@@ -72,6 +72,25 @@ Interface = {
var title = Interface.title = document.createElement('div');
title.className = 'title';
title.addEventListener('click',function(){
var pushed = Interface.center.getElementsByClassName('content'), element = pushed[pushed.length-1];
var start = element.scrollTop,
currentTime = 0,
increment = 20;
var animateScroll = function(){
currentTime += increment;
var val = (function (t, b, c, d) {
t /= d/2; if (t < 1) return c/2*t*t + b;
t--; return -c/2 * (t*(t-2) - 1) + b;
})(currentTime, start, -start, 200);
element.scrollTop = val;
if(currentTime < 200) {
setTimeout(animateScroll, increment);
}
};
animateScroll();
});
head.appendChild(Interface.title);
center.appendChild(head);
......@@ -167,8 +186,10 @@ Interface = {
}
},
"push": function(module, block){
if(!module.children) module.children = [];
module.children.push(block);
if (module) {
if(!module.children) module.children = [];
module.children.push(block);
}
block.className = 'content';
block.style.left = Interface.center.offsetWidth + 'px';
block.style.transition = 'left .3s';
......@@ -204,7 +225,6 @@ Interface = {
};
document.body.addEventListener('touchmove',move);
document.body.addEventListener('touchend',end);
});
setTimeout(function(){
Interface.head.classList.add('pushed');
......@@ -252,6 +272,7 @@ Interface = {
var pushed = Interface.center.getElementsByClassName('content'), last = pushed[pushed.length-1];
last.style.transition = 'left .3s';
last.style.left = Interface.center.offsetWidth + 'px';
if (last.restoreTitle) last.restoreTitle();
setTimeout(function(){
last.remove();
},300);
......@@ -311,5 +332,16 @@ Interface = {
setTimeout(function(){locker.remove();},300);
};
return locker;
},
"openLink": function(link){
// todo: check link for vk / http(s)
new MozActivity({
name: "view",
data: {
type: "url",
url: link
}
});
}
};
\ No newline at end of file
......@@ -15,10 +15,7 @@ Interface.modules.push((function(){
avatar.style.backgroundSize = 'cover';
name.innerHTML = u.first_name + ' ' + u.last_name;
if (titlenode) titlenode.innerHTML = name.innerHTML;
else titlenode = document.createTextNode(name.innerHTML);
page.title = function(){
return document.createTextNode(u.first_name + ' ' + u.last_name);
};
else titlenode = document.createElement('span',name.innerHTML);
});
Interface.addObserver('photoChanged',function(){
VK.api.call('users.get',{"fields":"photo_50"},function(r){
......@@ -30,10 +27,12 @@ Interface.modules.push((function(){
button.appendChild(name);
},
"content": function(){
return Blocks.page({});
return Blocks.page({},function(title){
titlenode.innerHTML = title;
});
},
"title": function(){
return titlenode ? titlenode : titlenode = document.createTextNode('Моя страница');
return titlenode ? titlenode : titlenode = document.createElement('span','Моя страница');
}
};
return page;
......
......@@ -66,7 +66,6 @@ Interface.modules.push((function(){
type: "image/*"
}
}), t = 'upload'+Math.random();
console.log(location.origin);
activity.onsuccess = function() {
var picture = this.result;
new Notification('Загрузка фотографии началась', {icon: location.origin+"/img/icon-16.png", tag: t, sound: 'none'});
......
......@@ -16,7 +16,7 @@ Date.prototype.toVKDateString = function(){
}
return this.getDate() + ' ' + months[this.getMonth()]
}
return this.getDate() + ' ' + months[this.getMonth()] + ' ' + this.getFullYear() + 'года';
return this.getDate() + ' ' + months[this.getMonth()] + ' ' + this.getFullYear() + ' года';
};
String.prototype.documentFragment = function(){
var df = document.createDocumentFragment(),lines=this.split('\n');
......
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