@ -2,13 +2,13 @@
/* globals define, app, ajaxify, bootbox, socket, templates, utils, config */
define ( 'forum/topic/postTools' , [ 'share' , 'navigator' , 'components' , 'translator' ] , function ( share , navigator , components , translator ) {
define ( 'forum/topic/postTools' , [ 'share' , 'navigator' , 'components' , 'translator' ] , function ( share , navigator , components , translator ) {
var PostTools = { } ;
var staleReplyAnyway = false ;
PostTools . init = function ( tid ) {
PostTools . init = function ( tid ) {
staleReplyAnyway = false ;
renderMenu ( ) ;
@ -23,7 +23,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
} ;
function renderMenu ( ) {
$ ( '[component="topic"]' ) . on ( 'show.bs.dropdown' , '.moderator-tools' , function ( ) {
$ ( '[component="topic"]' ) . on ( 'show.bs.dropdown' , '.moderator-tools' , function ( ) {
var $this = $ ( this ) ;
var dropdownMenu = $this . find ( '.dropdown-menu' ) ;
if ( dropdownMenu . html ( ) ) {
@ -33,14 +33,14 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
var pid = postEl . attr ( 'data-pid' ) ;
var index = parseInt ( postEl . attr ( 'data-index' ) , 10 ) ;
socket . emit ( 'posts.loadPostTools' , { pid : pid , cid : ajaxify . data . cid } , function ( err , data ) {
socket . emit ( 'posts.loadPostTools' , { pid : pid , cid : ajaxify . data . cid } , function ( err , data ) {
if ( err ) {
return app . alertError ( err . message ) ;
}
data . posts . display _move _tools = data . posts . display _move _tools && index !== 0 ;
templates . parse ( 'partials/topic/post-menu-list' , data , function ( html ) {
translator . translate ( html , function ( html ) {
templates . parse ( 'partials/topic/post-menu-list' , data , function ( html ) {
translator . translate ( html , function ( html ) {
dropdownMenu . html ( html ) ;
$ ( window ) . trigger ( 'action:post.tools.load' ) ;
} ) ;
@ -49,7 +49,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
} ) ;
}
PostTools . toggle = function ( pid , isDeleted ) {
PostTools . toggle = function ( pid , isDeleted ) {
var postEl = components . get ( 'post' , 'pid' , pid ) ;
postEl . find ( '[component="post/quote"], [component="post/bookmark"], [component="post/reply"], [component="post/flag"], [component="user/chat"]' )
@ -62,7 +62,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
postEl . find ( '[component="post/tools"] .dropdown-menu' ) . html ( '' ) ;
} ;
PostTools . updatePostCount = function ( postCount ) {
PostTools . updatePostCount = function ( postCount ) {
var postCountEl = components . get ( 'topic/post-count' ) ;
postCountEl . html ( postCount ) . attr ( 'title' , postCount ) ;
utils . makeNumbersHumanReadable ( postCountEl ) ;
@ -71,9 +71,9 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
function addVoteHandler ( ) {
components . get ( 'topic' ) . on ( 'mouseenter' , '[data-pid] [component="post/vote-count"]' , loadDataAndCreateTooltip ) ;
components . get ( 'topic' ) . on ( 'mouseout' , '[data-pid] [component="post/vote-count"]' , function ( ) {
components . get ( 'topic' ) . on ( 'mouseout' , '[data-pid] [component="post/vote-count"]' , function ( ) {
var el = $ ( this ) . parent ( ) ;
el . on ( 'shown.bs.tooltip' , function ( ) {
el . on ( 'shown.bs.tooltip' , function ( ) {
$ ( '.tooltip' ) . tooltip ( 'destroy' ) ;
el . off ( 'shown.bs.tooltip' ) ;
} ) ;
@ -92,7 +92,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
$ ( '.tooltip' ) . tooltip ( 'destroy' ) ;
$this . off ( 'mouseenter' , loadDataAndCreateTooltip ) ;
socket . emit ( 'posts.getUpvoters' , [ pid ] , function ( err , data ) {
socket . emit ( 'posts.getUpvoters' , [ pid ] , function ( err , data ) {
if ( err ) {
return app . alertError ( err . message ) ;
}
@ -115,7 +115,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
}
if ( usernames . length + data . otherCount > 6 ) {
usernames = usernames . join ( ', ' ) . replace ( /,/g , '|' ) ;
translator . translate ( '[[topic:users_and_others, ' + usernames + ', ' + data . otherCount + ']]' , function ( translated ) {
translator . translate ( '[[topic:users_and_others, ' + usernames + ', ' + data . otherCount + ']]' , function ( translated ) {
translated = translated . replace ( /\|/g , ',' ) ;
doCreateTooltip ( translated ) ;
} ) ;
@ -128,20 +128,20 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
function addPostHandlers ( tid ) {
var postContainer = components . get ( 'topic' ) ;
postContainer . on ( 'click' , '[component="post/quote"]' , function ( ) {
postContainer . on ( 'click' , '[component="post/quote"]' , function ( ) {
onQuoteClicked ( $ ( this ) , tid ) ;
} ) ;
postContainer . on ( 'click' , '[component="post/reply"]' , function ( ) {
postContainer . on ( 'click' , '[component="post/reply"]' , function ( ) {
onReplyClicked ( $ ( this ) , tid ) ;
} ) ;
$ ( '.topic' ) . on ( 'click' , '[component="topic/reply"]' , function ( ) {
$ ( '.topic' ) . on ( 'click' , '[component="topic/reply"]' , function ( ) {
onReplyClicked ( $ ( this ) , tid ) ;
} ) ;
$ ( '.topic' ) . on ( 'click' , '[component="topic/reply-as-topic"]' , function ( ) {
translator . translate ( '[[topic:link_back, ' + ajaxify . data . titleRaw + ', ' + config . relative _path + '/topic/' + ajaxify . data . slug + ']]' , function ( body ) {
$ ( '.topic' ) . on ( 'click' , '[component="topic/reply-as-topic"]' , function ( ) {
translator . translate ( '[[topic:link_back, ' + ajaxify . data . titleRaw + ', ' + config . relative _path + '/topic/' + ajaxify . data . slug + ']]' , function ( body ) {
$ ( window ) . trigger ( 'action:composer.topic.new' , {
cid : ajaxify . data . cid ,
body : body
@ -149,30 +149,30 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
} ) ;
} ) ;
postContainer . on ( 'click' , '[component="post/bookmark"]' , function ( ) {
postContainer . on ( 'click' , '[component="post/bookmark"]' , function ( ) {
bookmarkPost ( $ ( this ) , getData ( $ ( this ) , 'data-pid' ) ) ;
} ) ;
postContainer . on ( 'click' , '[component="post/upvote"]' , function ( ) {
postContainer . on ( 'click' , '[component="post/upvote"]' , function ( ) {
return toggleVote ( $ ( this ) , '.upvoted' , 'posts.upvote' ) ;
} ) ;
postContainer . on ( 'click' , '[component="post/downvote"]' , function ( ) {
postContainer . on ( 'click' , '[component="post/downvote"]' , function ( ) {
return toggleVote ( $ ( this ) , '.downvoted' , 'posts.downvote' ) ;
} ) ;
postContainer . on ( 'click' , '[component="post/vote-count"]' , function ( ) {
postContainer . on ( 'click' , '[component="post/vote-count"]' , function ( ) {
showVotes ( getData ( $ ( this ) , 'data-pid' ) ) ;
} ) ;
postContainer . on ( 'click' , '[component="post/flag"]' , function ( ) {
postContainer . on ( 'click' , '[component="post/flag"]' , function ( ) {
var pid = getData ( $ ( this ) , 'data-pid' ) ;
require ( [ 'forum/topic/flag' ] , function ( flag ) {
require ( [ 'forum/topic/flag' ] , function ( flag ) {
flag . showFlagModal ( pid ) ;
} ) ;
} ) ;
postContainer . on ( 'click' , '[component="post/edit"]' , function ( ) {
postContainer . on ( 'click' , '[component="post/edit"]' , function ( ) {
var btn = $ ( this ) ;
var timestamp = parseInt ( getData ( btn , 'data-timestamp' ) , 10 ) ;
@ -185,7 +185,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
}
} ) ;
postContainer . on ( 'click' , '[component="post/delete"]' , function ( ) {
postContainer . on ( 'click' , '[component="post/delete"]' , function ( ) {
var btn = $ ( this ) ;
var timestamp = parseInt ( getData ( btn , 'data-timestamp' ) , 10 ) ;
var postDeleteDuration = parseInt ( ajaxify . data . postDeleteDuration , 10 ) ;
@ -226,19 +226,19 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
return true ;
}
postContainer . on ( 'click' , '[component="post/restore"]' , function ( ) {
postContainer . on ( 'click' , '[component="post/restore"]' , function ( ) {
togglePostDelete ( $ ( this ) , tid ) ;
} ) ;
postContainer . on ( 'click' , '[component="post/purge"]' , function ( ) {
postContainer . on ( 'click' , '[component="post/purge"]' , function ( ) {
purgePost ( $ ( this ) , tid ) ;
} ) ;
postContainer . on ( 'click' , '[component="post/move"]' , function ( ) {
postContainer . on ( 'click' , '[component="post/move"]' , function ( ) {
openMovePostModal ( $ ( this ) ) ;
} ) ;
postContainer . on ( 'click' , '[component="post/chat"]' , function ( ) {
postContainer . on ( 'click' , '[component="post/chat"]' , function ( ) {
openChat ( $ ( this ) ) ;
} ) ;
}
@ -246,7 +246,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
function onReplyClicked ( button , tid ) {
var selectedText = getSelectedText ( button ) ;
showStaleWarning ( function ( ) {
showStaleWarning ( function ( ) {
var username = getUserName ( button ) ;
if ( getData ( button , 'data-uid' ) === '0' || ! getData ( button , 'data-userslug' ) ) {
username = '' ;
@ -278,7 +278,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
function onQuoteClicked ( button , tid ) {
var selectedText = getSelectedText ( button ) ;
showStaleWarning ( function ( ) {
showStaleWarning ( function ( ) {
function quote ( text ) {
$ ( window ) . trigger ( 'action:composer.addQuote' , {
@ -298,7 +298,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
if ( selectedText ) {
return quote ( selectedText ) ;
}
socket . emit ( 'posts.getRawPost' , pid , function ( err , post ) {
socket . emit ( 'posts.getRawPost' , pid , function ( err , post ) {
if ( err ) {
return app . alertError ( err . message ) ;
}
@ -336,7 +336,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
socket . emit ( method , {
pid : pid ,
room _id : app . currentRoom
} , function ( err ) {
} , function ( err ) {
if ( err ) {
app . alertError ( err . message ) ;
}
@ -352,7 +352,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
socket . emit ( currentState ? 'posts.unvote' : method , {
pid : post . attr ( 'data-pid' ) ,
room _id : app . currentRoom
} , function ( err ) {
} , function ( err ) {
if ( err ) {
if ( err . message === 'self-vote' ) {
showVotes ( post . attr ( 'data-pid' ) ) ;
@ -366,7 +366,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
}
function showVotes ( pid ) {
socket . emit ( 'posts.getVoters' , { pid : pid , cid : ajaxify . data . cid } , function ( err , data ) {
socket . emit ( 'posts.getVoters' , { pid : pid , cid : ajaxify . data . cid } , function ( err , data ) {
if ( err ) {
if ( err . message === '[[error:no-privileges]]' ) {
return ;
@ -376,8 +376,8 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
return app . alertError ( err . message ) ;
}
templates . parse ( 'partials/modals/votes_modal' , data , function ( html ) {
translator . translate ( html , function ( translated ) {
templates . parse ( 'partials/modals/votes_modal' , data , function ( html ) {
translator . translate ( html , function ( translated ) {
var dialog = bootbox . dialog ( {
title : 'Voters' ,
message : translated ,
@ -385,7 +385,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
show : true
} ) ;
dialog . on ( 'click' , function ( ) {
dialog . on ( 'click' , function ( ) {
dialog . modal ( 'hide' ) ;
} ) ;
@ -429,8 +429,8 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
}
function postAction ( action , pid , tid ) {
translator . translate ( '[[topic:post_' + action + '_confirm]]' , function ( msg ) {
bootbox . confirm ( msg , function ( confirm ) {
translator . translate ( '[[topic:post_' + action + '_confirm]]' , function ( msg ) {
bootbox . confirm ( msg , function ( confirm ) {
if ( ! confirm ) {
return ;
}
@ -438,7 +438,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
socket . emit ( 'posts.' + action , {
pid : pid ,
tid : tid
} , function ( err ) {
} , function ( err ) {
if ( err ) {
app . alertError ( err . message ) ;
}
@ -448,28 +448,28 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
}
function openMovePostModal ( button ) {
parseMoveModal ( function ( html ) {
parseMoveModal ( function ( html ) {
var moveModal = $ ( html ) ;
var moveBtn = moveModal . find ( '#move_post_commit' ) ,
topicId = moveModal . find ( '#topicId' ) ;
moveModal . on ( 'hidden.bs.modal' , function ( ) {
moveModal . on ( 'hidden.bs.modal' , function ( ) {
moveModal . remove ( ) ;
} ) ;
showMoveModal ( moveModal ) ;
moveModal . find ( '.close, #move_post_cancel' ) . on ( 'click' , function ( ) {
moveModal . find ( '.close, #move_post_cancel' ) . on ( 'click' , function ( ) {
moveModal . addClass ( 'hide' ) ;
} ) ;
topicId . on ( 'keyup change' , function ( ) {
topicId . on ( 'keyup change' , function ( ) {
moveBtn . attr ( 'disabled' , ! topicId . val ( ) ) ;
} ) ;
moveBtn . on ( 'click' , function ( ) {
movePost ( button . parents ( '[data-pid]' ) , getData ( button , 'data-pid' ) , topicId . val ( ) , function ( ) {
moveBtn . on ( 'click' , function ( ) {
movePost ( button . parents ( '[data-pid]' ) , getData ( button , 'data-pid' ) , topicId . val ( ) , function ( ) {
moveModal . modal ( 'hide' ) ;
topicId . val ( '' ) ;
} ) ;
@ -479,7 +479,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
}
function parseMoveModal ( callback ) {
templates . parse ( 'partials/move_post_modal' , { } , function ( html ) {
templates . parse ( 'partials/move_post_modal' , { } , function ( html ) {
translator . translate ( html , callback ) ;
} ) ;
}
@ -493,13 +493,13 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
}
function movePost ( post , pid , tid , callback ) {
socket . emit ( 'posts.movePost' , { pid : pid , tid : tid } , function ( err ) {
socket . emit ( 'posts.movePost' , { pid : pid , tid : tid } , function ( err ) {
if ( err ) {
app . alertError ( err . message ) ;
return callback ( ) ;
}
post . fadeOut ( 500 , function ( ) {
post . fadeOut ( 500 , function ( ) {
post . remove ( ) ;
} ) ;
@ -521,7 +521,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
return callback ( ) ;
}
translator . translate ( '[[topic:stale.warning]]' , function ( translated ) {
translator . translate ( '[[topic:stale.warning]]' , function ( translated ) {
var warning = bootbox . dialog ( {
title : '[[topic:stale.title]]' ,
message : translated ,
@ -529,7 +529,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
reply : {
label : '[[topic:stale.reply_anyway]]' ,
className : 'btn-link' ,
callback : function ( ) {
callback : function ( ) {
staleReplyAnyway = true ;
callback ( ) ;
}
@ -537,8 +537,8 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
create : {
label : '[[topic:stale.create]]' ,
className : 'btn-primary' ,
callback : function ( ) {
translator . translate ( '[[topic:link_back, ' + ajaxify . data . title + ', ' + config . relative _path + '/topic/' + ajaxify . data . slug + ']]' , function ( body ) {
callback : function ( ) {
translator . translate ( '[[topic:link_back, ' + ajaxify . data . title + ', ' + config . relative _path + '/topic/' + ajaxify . data . slug + ']]' , function ( body ) {
$ ( window ) . trigger ( 'action:composer.topic.new' , {
cid : ajaxify . data . cid ,
body : body