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-07-16 20:30:46 -04:00
|
|
|
return false;
|
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');
|
2013-07-16 20:30:46 -04:00
|
|
|
return false;
|
2013-06-25 21:15:24 -04:00
|
|
|
}, false);
|
|
|
|
|
googleEl.addEventListener('click', function() {
|
|
|
|
|
window.open(google_url, '_blank', 'width=500,height=570,scrollbars=no,status=no');
|
2013-07-16 20:30:46 -04:00
|
|
|
return false;
|
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');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.emit('api:categories.getRecentReplies', cid);
|
2013-07-02 19:46:58 -04:00
|
|
|
socket.on('api:categories.getRecentReplies', function(posts) {
|
|
|
|
|
if (!posts || posts.length === 0) {
|
2013-05-29 12:17:44 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2013-07-15 16:19:27 -04:00
|
|
|
|
2013-07-02 19:46:58 -04:00
|
|
|
var recent_replies = document.getElementById('category_recent_replies');
|
2013-05-29 12:17:44 -04:00
|
|
|
|
|
|
|
|
recent_replies.innerHTML = '';
|
2013-07-02 19:46:58 -04:00
|
|
|
|
2013-07-15 16:19:27 -04:00
|
|
|
var frag = document.createDocumentFragment(),
|
|
|
|
|
li = document.createElement('li');
|
|
|
|
|
for (var i=0,numPosts=posts.length; i<numPosts; i++) {
|
|
|
|
|
var dateString = utils.relativeTime(posts[i].timestamp);
|
|
|
|
|
li.setAttribute('data-pid', posts[i].pid);
|
2013-07-19 10:36:42 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
li.innerHTML = '<a href="/users/' + posts[i].userslug + '"><img title="' + posts[i].username + '" style="width: 48px; height: 48px; /*temporary*/" class="img-polaroid" src="' + posts[i].picture + '" class="" /></a>' +
|
2013-08-01 17:27:37 -04:00
|
|
|
'<a href="/topic/'+ posts[i].topicSlug + '#' + posts[i].pid + '">' +
|
2013-07-19 10:36:42 -04:00
|
|
|
'<p>' +
|
|
|
|
|
'<strong>' + posts[i].username + '</strong>: ' + posts[i].content +
|
|
|
|
|
'</p>' +
|
|
|
|
|
'<span>posted ' + utils.relativeTime(posts[i].timestamp) + ' ago</span>' +
|
|
|
|
|
'</a>';
|
2013-05-29 12:17:44 -04:00
|
|
|
|
2013-07-15 16:19:27 -04:00
|
|
|
frag.appendChild(li.cloneNode(true));
|
|
|
|
|
recent_replies.appendChild(frag);
|
2013-05-29 12:17:44 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})();
|