/* How many advices to display on one page */ var pageSize = 6; var friendsRows = 3; var friendsCols = 6; var friendsPageSize = friendsRows*friendsCols; var excerptSize = 30; var emptyMessagePrompt = "Kiss Me!"; /* Array of
  • entries for the main menu */ var topMenu = [ { name : 'Kiss a Friend', id : 'send', 'default_menu' : true } ,{ name : 'I Kissed', id : 'sent' } ,{ name : 'My Kisses', id : 'received' } /* FIXME: implement this tab */ /* ,{ name : 'Most Popular', id : 'top10' } */ ]; var imagesURL = server_root_url+'kiss-me/images/'; /* Internal vars */ var viewerData = null; var currentMessageObj = null; /* Cache the user data */ var userCache = { }; /* Init hook */ function init_hook(viewerObj) { /* Global parameters */ globalParams['noSentMsgs'] = '

    You haven\'t kissed anyone. Don\'t you have friends?

    Send them a kiss!

    '; globalParams['noReceivedMsgs'] = '

    Nobody kissed you. Don\'t you have friends?

    Send them a kiss to get a kiss back!

    '; /* Statistics */ var postdata = { }; postdata['referrer'] = "canvas"; postdata['fn'] = "stats"; if(typeof(viewerObj) == 'object') { postdata['userid'] = viewerObj.getId(); viewerData = viewerObj; } serverRequest(function() { }, postdata); } function getMenuContent() { var menuItems = topMenu; if(isAdmin()) { /* menuItems.push({ name : 'Admin', id : 'admin' }); */ menuItems.push({ name : 'Debug', id : 'debug' }); } return menuItems; } /* kind is 'send' (for Send Message page), and in the future - for 'admin' */ function formatUserList(kind) { var html = '
    ' +'
    ' +'
    ' +'
    ' +'
    '; return html; } function formatSendPage() { debug('formatSendPage()'); /* Set id names in global vars */ messages_send_id = 'trash_can'; users_send_id = 'user_list_box_content'; var html = /* Banner and statistics box */ '
    ' /* Trash can for unneeded junk from the framework */ +'' /* The big Send Kiss button */ +'
    ' +'' +'
    ' /* Status message box */ +'
    ' /* Sidebar apps */ +'' /* Friend selector */ +formatUserList('send'); return html; } /* Empty placeholder - required function */ function formatMessageSend(msg) { return ''; } function onclickSendMessage() { var msg = { }; /* We have no text or content - just use place holders */ msg.text = 'Kiss Me!'; msg.content_id = 528; sendMessage(msg); } function defaultMessage() { d = document.getElementById('msg_text'); if(currentMessageObj) { if(typeof d == 'object') d.value = currentMessageObj.content_text; } } /* Update unlocked progress bar - use content.total and content.unlocked */ function updateUnlocked(content) { debug('updateUnlocked()'); var d = document.getElementById('title_banner_txt'); var sentMsg; var recMsg; if(content.friends_sent == 0) { sentMsg = 'You have not kissed anyone yet'; } else if(content.friends_sent == 1) { sentMsg = 'You kissed 1 friend ' +((content.total_sent == 1)? ' once' : (content.total_sent+' times')); } else { sentMsg= 'You kissed '+content.friends_sent+' friends ' +content.total_sent+' times'; } if(content.friends_received == 0) { recMsg = 'Nobody kissed you yet'; } else if(content.friends_received == 1) { recMsg = 'One friend kissed you ' +((content.total_received == 1)? ' once' : (content.total_received+' times')); } else { recMsg = content.friends_received+' friends kissed you ' +content.total_received+' times'; } d.innerHTML = sentMsg+'
    '+recMsg; } function selectMessageSend(msgObj) { debug('selectMessageSend('+myToStr(msgObj)+')'); currentMessageObj = msgObj; } function formatFriendSend(friend) { var id = friend.getId(); var html = '
    ' +'' +'
    '+friend.nick+'
    ' +'' +'
    '; return html; } /* Display status message. Optional status can be 'error', 'warning' or null */ function displayStatus(msg, status) { d = document.getElementById('status_msg'); if(status == 'error') d.className = 'status_error'; else if(status == 'warning') d.className = 'status_warning'; else d.className = ''; d.innerHTML = msg; } function selectUserSend(user, params) { debug('selectUserSend('+user.nick+')'); var id=user.getId(); var box = document.getElementById('userid_'+id); var icon; if(typeof box == 'object') { box.selected = 1; box.className = "user_thumb user_thumb_selected"; /* Post comment regardless */ icon = document.getElementById('user_comment_'+id); if(typeof icon == 'object') icon.style.display = 'block'; } else { debug('selectUserSend('+id+'): not displayed'); } if(params == null) params = { }; if(typeof(params.messageCount) == 'number' && params.messageCount > 0) { var n = params.messageCount; displayStatus('Selected '+((n == 1)? 'one friend' : (n+' friends')) +'. Now press the button to kiss them!'); } else { displayStatus(''); /* Clear the box */ } } function deselectUserSend(user, params) { debug('deselectUserSend('+user.nick+')'); var id=user.getId(); var box = document.getElementById('userid_'+id); var icon; if(typeof box == 'object') { box.selected = 0; box.className = "user_thumb"; /* Disable both overlays - for good measure */ icon = document.getElementById('user_comment_'+id); if(typeof icon == 'object') icon.style.display = 'none'; } else { debug('selectUserSend('+id+'): not displayed'); } if(params == null) params = { }; if(typeof(params.messageCount) == 'number' && params.messageCount > 0) { var n = params.messageCount; displayStatus('Selected '+((n == 1)? 'one friend' : (n+' friends')) +'. Now press the button to kiss them!'); } else { displayStatus(''); /* Clear the box */ } } function formatSentPage() { debug('formatSentPage()'); /* Set id names in global vars */ messages_send_id = 'kisses_content'; var html = /* Banner and statistics box */ '
    ' /* Status message box */ +'
    ' /* Sidebar apps */ +'' /* Message list */ +'
    ' +'
    ' +'
    '; return html; } /* Given the user object, fill in the info in the displayed messages */ function fillInUserInfo(user) { debug('fillInUserInfo('+myToStr(user)+')'); /* Cache user data */ userCache[user.getId()] = user; var urls = myGetElementsByName('a', 'user_url_'+user.getId()); for(var i in urls) { urls[i].href = user.getField('profileUrl'); urls[i].title = 'Kiss '+user.nick; } var imgs = myGetElementsByName('img', 'user_thumb_'+user.getId()); for(var i in imgs) { imgs[i].src = user.getField('thumbnailUrl'); } var nicks = myGetElementsByName('span', 'user_nick_'+user.getId()); for(var i in nicks) { nicks[i].innerHTML = user.nick; } } /* Here, we need to fetch the users info and fill it in the messages */ function displaySentHook(messages) { debug('displaySentHook(messages.length='+messages.length+')'); var userids = { }; for(var i in messages) { userids[messages[i].toUser] = true; } for(var id in userids) { debug('displaySentHook: getUserData('+id+')'); getUserData(id, fillInUserInfo); } } function formatMessageCustom(msg, i, userid, text, button_text) { var button = ''; if(userid != 'unknown') { button = '
    ' +'' +'
    '; } var html = '
  • ' +'' +'
    ' +'' +'' +'
    '+text+'
    ' +'on '+msg.timestamp+'
    ' +'' +'
    '+button+'
  • '; return html; } function kissBack(userid, i) { debug('kissBack(userid='+userid+', i='+i+')'); /* Send message manually - to avoid comments etc. */ var postdata = { 'fn' : 'sendMessage', 'contentid' : 528, /* required non-0 - anything will work */ 'text' : 'Kiss me!', 'fromUser' : viewerID, 'toUsers' : [ userid ] }; displayStatus('Kissing a friend…', 'warning'); serverRequest(function (response) { if(!response.error) { displayStatus('You kissed your friend!'); var msg = { }; showArgs.friends = userCache; sendUserMessages([ userid ], msg); } else { displayStatus('Sorry, your kiss didn\'t work. Please try again.', 'error'); } debug('kissBack: looking for icon lipstick_'+i); var icon = document.getElementById('lipstick_'+i); if(typeof icon == 'object') icon.style.display = 'block'; }, postdata); } function formatMessageSentCustom(msg, i) { var userid = msg.toUser; var text = 'You kissed a stranger'; var button_text = 'Kiss Again!'; return formatMessageCustom(msg, i, userid, text, button_text); } function selectMessageSent(msg) { selectMessageSend(msg); } function formatAppInviteQuestion(userIds) { return 'You\'ve sent a kiss, but '+userIds.length+' of your friends do not have this App installed. Invite them to the App, so they can kiss you back!'; } function formatUserCommentQuestion(userid, userids) { return 'Post a comment with your kiss to your friend\'s profile, ' +showArgs.friends[userid].nick+' ('+userids.length+' friends remaining):'; } function formatAppInvite(msg) { var text = viewerName+' has just kissed you. Add this app and kiss them back!'; return text; } function formatUserComment(msg) { var img = ''; var linkText = 'Open this app'; if(typeof(appInfo.profileURL) == 'string') { img = ''+img+''; linkText = ''+linkText+''; } var html = img+' '+ viewerName+" has just kissed you.
    " +linkText+' to kiss your friends!'; return html; } function formatReceivedPage() { debug('formatReceivedPage()'); return formatSentPage(); } /* Here, we need to fetch the users info and fill it in the messages */ function displayReceivedHook(messages) { debug('displayReceivedHook(messages.length='+messages.length+')'); var userids = { }; for(var i in messages) { userids[messages[i].fromUser] = true; } for(var id in userids) { debug('displayReceivedHook: getUserData('+id+')'); getUserData(id, fillInUserInfo); } } function formatMessageReceivedCustom(msg, i) { var userid = msg.fromUser; var text = 'A stranger kissed you'; var button_text = 'Kiss Back!'; return formatMessageCustom(msg, i, userid, text, button_text); } function formatCustomPage(pageID) { return ''; }