From 38d4fd1a59108ff664bb3c9fb30a88a03b85db19 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sat, 15 Mar 2014 17:50:19 -0400 Subject: [PATCH] took out forking to its own file --- public/src/forum/topic.js | 152 ++++++++------------------------- public/src/forum/topic/fork.js | 115 +++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 116 deletions(-) create mode 100644 public/src/forum/topic/fork.js diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index a86c6d9b71..6084daffaf 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -1,4 +1,9 @@ -define(['composer', 'forum/pagination'], function(composer, pagination) { +'use strict'; + + +/* globals define, app, templates, translator, socket, bootbox, config, ajaxify, RELATIVE_PATH */ + +define(['composer', 'forum/pagination', 'forum/topic/fork'], function(composer, pagination, fork) { var Topic = {}, infiniteLoaderActive = false, scrollingToPost = false, @@ -196,97 +201,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { } }); - $('.fork_thread').on('click', function() { - var pids = []; - var forkModal = $('#fork-thread-modal'), - forkCommit = forkModal.find('#fork_thread_commit'); - forkModal.removeClass('hide'); - forkModal.css('position', 'fixed') - .css('left', Math.max(0, (($(window).width() - $(forkModal).outerWidth()) / 2) + $(window).scrollLeft()) + 'px') - .css('top', '0px') - .css('z-index', '2000'); - - showNoPostsSelected(); - - forkModal.find('.close,#fork_thread_cancel').on('click', closeForkModal); - forkModal.find('#fork-title').on('change', checkForkButtonEnable); - $('#post-container').on('click', 'li', togglePostSelection); - forkCommit.on('click', createTopicFromPosts); - - function createTopicFromPosts() { - socket.emit('topics.createTopicFromPosts', { - title: forkModal.find('#fork-title').val(), - pids: pids - }, function(err) { - if(err) { - return app.alertError(err.message); - } - - translator.get('topic:fork_success', function(translated) { - app.alertSuccess(translated); - }); - - function removePost() { - $(this).remove(); - } - - for(var i=0; i 8) { break; @@ -688,12 +603,13 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { activeEl.append(anonLink); var title = ''; - if(remainingUsers && anonymousCount) + if(remainingUsers && anonymousCount) { title = remainingUsers + ' more user(s) and ' + anonymousCount + ' guest(s)'; - else if(remainingUsers) + } else if(remainingUsers) { title = remainingUsers + ' more user(s)'; - else + } else { title = anonymousCount + ' guest(s)'; + } anonLink.tooltip({ placement: 'top', @@ -884,7 +800,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { socket.on('event:post_deleted', function(data) { if (data.pid) { - toggle_post_delete_state(data.pid); + toggle_post_delete_state(data.pid); } }); @@ -913,7 +829,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { votes.html(currentVotes).attr('data-votes', currentVotes); reputationElements.html(reputation).attr('data-reputation', reputation); - }; + } function adjust_favourites(value, pid, uid) { var favourites = $('li[data-pid="' + pid + '"] .favouriteCount'), @@ -922,7 +838,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { currentFavourites += value; favourites.html(currentFavourites).attr('data-favourites', currentFavourites); - }; + } function set_follow_state(state, alert) { @@ -937,7 +853,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { type: 'success' }); } - }; + } function set_locked_state(locked, alert) { translator.translate(' [[topic:thread_tools.' + (locked ? 'un': '') + 'lock]]', function(translated) { @@ -960,7 +876,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { } thread_state.locked = locked ? '1' : '0'; - }; + } function set_delete_state(deleted) { var threadEl = $('#post-container'); @@ -977,7 +893,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { } else { $('#thread-deleted').remove(); } - }; + } function set_pinned_state(pinned, alert) { translator.translate(' [[topic:thread_tools.' + (pinned ? 'unpin' : 'pin') + ']]', function(translated) { @@ -994,7 +910,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { } thread_state.pinned = pinned ? '1' : '0'; }); - }; + } function toggle_post_delete_state(pid) { var postEl = $('#post-container li[data-pid="' + pid + '"]'); @@ -1006,7 +922,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { updatePostCount(); } - }; + } function toggle_post_tools(pid, isDeleted) { var postEl = $('#post-container li[data-pid="' + pid + '"]'); @@ -1016,7 +932,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { translator.translate(isDeleted ? ' [[topic:restore]]' : ' [[topic:delete]]', function(translated) { postEl.find('.delete').find('span').html(translated); }); - }; + } $(window).on('scroll', updateHeader); $(window).trigger('action:topic.loaded'); @@ -1231,7 +1147,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { } if(after) { - translated.insertAfter(after) + translated.insertAfter(after); } else if(before) { translated.insertBefore(before); } else { @@ -1250,16 +1166,16 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { function parseAndTranslatePosts(data, callback) { templates.preload_template('topic', function() { - templates['topic'].parse({posts: []}); - var html = templates.prepare(templates['topic'].blocks['posts']).parse(data); + templates.topic.parse({posts: []}); + var html = templates.prepare(templates.topic.blocks.posts).parse(data); translator.translate(html, callback); }); } function onNewPostsLoaded(html, posts) { - for (var x = 0, numPosts = posts.length; x < numPosts; x++) { - socket.emit('posts.getPrivileges', posts[x].pid, function(err, privileges) { + function getPostPrivileges(pid) { + socket.emit('posts.getPrivileges', pid, function(err, privileges) { if(err) { return app.alertError(err.message); } @@ -1267,6 +1183,10 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { }); } + for (var x = 0, numPosts = posts.length; x < numPosts; x++) { + getPostPrivileges(posts[x].pid); + } + infiniteLoaderActive = false; app.populateOnlineUsers(); diff --git a/public/src/forum/topic/fork.js b/public/src/forum/topic/fork.js new file mode 100644 index 0000000000..468b708a5a --- /dev/null +++ b/public/src/forum/topic/fork.js @@ -0,0 +1,115 @@ +'use strict'; + +/* globals define, app, translator, socket */ + +define(function() { + + var Fork = {}, + forkModal, + forkCommit, + pids = []; + + Fork.init = function() { + $('.fork_thread').on('click', onForkThreadClicked); + }; + + function onForkThreadClicked() { + forkModal = $('#fork-thread-modal'); + forkModal.removeClass('hide') + .css('position', 'fixed') + .css('left', Math.max(0, (($(window).width() - $(forkModal).outerWidth()) / 2) + $(window).scrollLeft()) + 'px') + .css('top', '0px') + .css('z-index', '2000'); + + forkCommit = forkModal.find('#fork_thread_commit'); + + pids.length = 0; + + showNoPostsSelected(); + + forkModal.find('.close,#fork_thread_cancel').on('click', closeForkModal); + forkModal.find('#fork-title').on('change', checkForkButtonEnable); + $('#post-container').on('click', 'li[data-pid]', function() { + togglePostSelection($(this)); + }); + + forkCommit.on('click', createTopicFromPosts); + } + + function createTopicFromPosts() { + socket.emit('topics.createTopicFromPosts', { + title: forkModal.find('#fork-title').val(), + pids: pids + }, function(err) { + function fadeOutAndRemove(pid) { + $('#post-container li[data-pid="' + pid + '"]').fadeOut(500, function() { + $(this).remove(); + }); + } + + if(err) { + return app.alertError(err.message); + } + + translator.get('topic:fork_success', function(translated) { + app.alertSuccess(translated); + }); + + for(var i=0; i