2013-05-29 12:17:44 -04:00
|
|
|
(function() {
|
|
|
|
|
var cid = templates.get('category_id'),
|
2013-06-24 17:05:23 -04:00
|
|
|
room = 'category_' + cid,
|
|
|
|
|
twitterEl = document.getElementById('twitter-intent'),
|
2013-06-25 21:15:24 -04:00
|
|
|
facebookEl = document.getElementById('facebook-share'),
|
|
|
|
|
googleEl = document.getElementById('google-share'),
|
|
|
|
|
twitter_url = templates.get('twitter-intent-url'),
|
|
|
|
|
facebook_url = templates.get('facebook-share-url'),
|
|
|
|
|
google_url = templates.get('google-share-url');
|
2013-05-29 12:17:44 -04:00
|
|
|
|
|
|
|
|
app.enter_room(room);
|
|
|
|
|
|
2013-06-24 17:05:23 -04:00
|
|
|
twitterEl.addEventListener('click', function() {
|
|
|
|
|
window.open(twitter_url, '_blank', 'width=550,height=420,scrollbars=no,status=no');
|
2013-06-25 21:15:24 -04:00
|
|
|
}, false);
|
|
|
|
|
facebookEl.addEventListener('click', function() {
|
|
|
|
|
window.open(facebook_url, '_blank', 'width=626,height=436,scrollbars=no,status=no');
|
|
|
|
|
}, false);
|
|
|
|
|
googleEl.addEventListener('click', function() {
|
|
|
|
|
window.open(google_url, '_blank', 'width=500,height=570,scrollbars=no,status=no');
|
2013-06-24 17:05:23 -04:00
|
|
|
}, false);
|
|
|
|
|
|
2013-05-29 12:17:44 -04:00
|
|
|
var new_post = document.getElementById('new_post');
|
|
|
|
|
new_post.onclick = function() {
|
2013-06-04 16:20:27 -04:00
|
|
|
require(['composer'], function(cmp) {
|
|
|
|
|
cmp.push(0, cid);
|
|
|
|
|
});
|
2013-05-29 12:17:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ajaxify.register_events([
|
|
|
|
|
'event:new_topic'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
socket.on('event:new_topic', function(data) {
|
|
|
|
|
var html = templates.prepare(templates['category'].blocks['topics']).parse({ topics: [data] }),
|
|
|
|
|
topic = document.createElement('div'),
|
|
|
|
|
container = document.getElementById('topics-container'),
|
|
|
|
|
topics = document.querySelectorAll('#topics-container a'),
|
|
|
|
|
numTopics = topics.length,
|
|
|
|
|
x;
|
|
|
|
|
|
2013-06-11 16:36:33 -04:00
|
|
|
jQuery('#topics-container, .category-sidebar').removeClass('hidden');
|
|
|
|
|
jQuery('#category-no-topics').remove();
|
2013-05-29 12:17:44 -04:00
|
|
|
|
|
|
|
|
topic.innerHTML = html;
|
2013-06-24 12:54:14 -04:00
|
|
|
topic = topic.querySelector('a');
|
|
|
|
|
|
2013-05-29 12:17:44 -04:00
|
|
|
if (numTopics > 0) {
|
|
|
|
|
for(x=0;x<numTopics;x++) {
|
|
|
|
|
if (topics[x].querySelector('.icon-pushpin')) continue;
|
2013-06-24 12:54:14 -04:00
|
|
|
container.insertBefore(topic, topics[x]);
|
2013-05-29 12:17:44 -04:00
|
|
|
$(topic).hide().fadeIn('slow');
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2013-06-24 12:54:14 -04:00
|
|
|
container.insertBefore(topic, null);
|
2013-05-29 12:17:44 -04:00
|
|
|
$(topic).hide().fadeIn('slow');
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 12:54:14 -04:00
|
|
|
ajaxify.enable();
|
2013-05-29 12:17:44 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.emit('api:categories.getRecentReplies', cid);
|
|
|
|
|
socket.on('api:categories.getRecentReplies', function(replies) {
|
|
|
|
|
if (replies === false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var users = replies.users,
|
|
|
|
|
posts = replies.posts,
|
|
|
|
|
recent_replies = document.getElementById('category_recent_replies');
|
|
|
|
|
|
|
|
|
|
recent_replies.innerHTML = '';
|
|
|
|
|
for (var i=0, ii=posts.pids.length; i<ii; i++) {
|
|
|
|
|
var a = document.createElement('a'),
|
|
|
|
|
ul = document.createElement('ul'),
|
|
|
|
|
username = users[posts.uid[i]].username,
|
|
|
|
|
picture = users[posts.uid[i]].picture;
|
|
|
|
|
|
|
|
|
|
//temp until design finalized
|
|
|
|
|
ul.innerHTML = '<li><img title="' + username + '" style="width: 48px; height: 48px; /*temporary*/" src="' + picture + '" class="" />'
|
|
|
|
|
+ '<p><strong>' + username + '</strong>: ' + posts.content[i] + '</p><span>posted ' + utils.relativeTime(posts.timestamp[i]) + ' ago</span></li>';
|
|
|
|
|
|
|
|
|
|
a.appendChild(ul);
|
|
|
|
|
recent_replies.appendChild(a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})();
|