2008-02-28 01:50:25 -05:00
var theList ; var theExtraList ;
2008-08-29 01:07:40 -04:00
( function ( $ ) {
setCommentsList = function ( ) {
2008-12-14 07:13:30 -05:00
var totalInput = $ ( '#comments-form .tablenav :input[name="_total"]' ) ;
var perPageInput = $ ( '#comments-form .tablenav :input[name="_per_page"]' ) ;
var pageInput = $ ( '#comments-form .tablenav :input[name="_page"]' ) ;
var lastConfidentTime = 0 ;
2008-08-29 01:07:40 -04:00
var dimAfter = function ( r , settings ) {
2008-11-14 16:54:39 -05:00
var c = $ ( '#' + settings . element ) ;
2008-12-09 13:03:31 -05:00
2008-11-14 16:54:39 -05:00
if ( c . is ( '.unapproved' ) )
c . find ( 'div.comment_status' ) . html ( '0' )
else
c . find ( 'div.comment_status' ) . html ( '1' )
2008-11-15 13:57:53 -05:00
$ ( 'span.pending-count' ) . each ( function ( ) {
2008-08-29 01:07:40 -04:00
var a = $ ( this ) ;
2008-11-15 14:40:38 -05:00
var n = a . html ( ) . replace ( /[ ,.]+/g , '' ) ;
n = parseInt ( n , 10 ) ;
2008-11-15 13:57:53 -05:00
if ( isNaN ( n ) ) return ;
2008-08-29 01:07:40 -04:00
n = n + ( $ ( '#' + settings . element ) . is ( '.' + settings . dimClass ) ? 1 : - 1 ) ;
if ( n < 0 ) { n = 0 ; }
$ ( '#awaiting-mod' ) [ 0 == n ? 'addClass' : 'removeClass' ] ( 'count-0' ) ;
2008-11-15 16:58:51 -05:00
n = n . toString ( ) ;
if ( n . length > 3 )
n = n . substr ( 0 , n . length - 3 ) + ' ' + n . substr ( - 3 ) ;
a . html ( n ) ;
2008-08-29 01:07:40 -04:00
} ) ;
} ;
2008-10-07 21:18:16 -04:00
2008-12-14 07:13:30 -05:00
// Send current total, page, per_page and url
var delBefore = function ( settings ) {
settings . data . _total = totalInput . val ( ) ;
settings . data . _per _page = perPageInput . val ( ) ;
settings . data . _page = pageInput . val ( ) ;
settings . data . _url = document . location . href ;
return settings ;
} ;
/ * U p d a t e s t h e c u r r e n t t o t a l ( a s d i s p l a y e d v i s i b l y )
* /
var updateTotalCount = function ( total , time , setConfidentTime ) {
if ( time < lastConfidentTime ) {
return ;
}
totalInput . val ( total . toString ( ) ) ;
if ( setConfidentTime ) {
lastConfidentTime = time ;
}
$ ( 'span.total-type-count' ) . each ( function ( ) {
var a = $ ( this ) ;
var n = totalInput . val ( ) . toString ( ) ;
if ( n . length > 3 )
n = n . substr ( 0 , n . length - 3 ) + ' ' + n . substr ( - 3 ) ;
a . html ( n ) ;
} ) ;
} ;
// In admin-ajax.php, we send back the unix time stamp instead of 1 on success
2008-08-29 01:07:40 -04:00
var delAfter = function ( r , settings ) {
2008-11-15 13:57:53 -05:00
$ ( 'span.pending-count' ) . each ( function ( ) {
2008-08-29 01:07:40 -04:00
var a = $ ( this ) ;
2008-11-15 14:40:38 -05:00
var n = a . html ( ) . replace ( /[ ,.]+/g , '' ) ;
n = parseInt ( n , 10 ) ;
2008-11-15 13:57:53 -05:00
if ( isNaN ( n ) ) return ;
2008-08-29 01:07:40 -04:00
if ( $ ( '#' + settings . element ) . is ( '.unapproved' ) ) { // we deleted a formerly unapproved comment
n = n - 1 ;
} else if ( $ ( settings . target ) . parents ( 'span.unapprove' ) . size ( ) ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
n = n + 1 ;
}
if ( n < 0 ) { n = 0 ; }
$ ( '#awaiting-mod' ) [ 0 == n ? 'addClass' : 'removeClass' ] ( 'count-0' ) ;
2008-11-15 16:58:51 -05:00
n = n . toString ( ) ;
if ( n . length > 3 )
n = n . substr ( 0 , n . length - 3 ) + ' ' + n . substr ( - 3 ) ;
a . html ( n ) ;
2008-08-29 01:07:40 -04:00
} ) ;
2008-11-15 13:57:53 -05:00
2008-12-14 07:13:30 -05:00
$ ( 'span.spam-count' ) . each ( function ( ) {
2008-08-29 01:07:40 -04:00
var a = $ ( this ) ;
2008-11-15 14:40:38 -05:00
var n = a . html ( ) . replace ( /[ ,.]+/g , '' ) ;
n = parseInt ( n , 10 ) ;
2008-11-15 13:57:53 -05:00
if ( isNaN ( n ) ) return ;
2008-08-29 01:07:40 -04:00
if ( $ ( settings . target ) . parents ( 'span.spam' ) . size ( ) ) { // we marked a comment as spam
n = n + 1 ;
} else if ( $ ( '#' + settings . element ) . is ( '.spam' ) ) { // we approved or deleted a comment marked as spam
n = n - 1 ;
}
if ( n < 0 ) { n = 0 ; }
2008-11-15 16:58:51 -05:00
n = n . toString ( ) ;
if ( n . length > 3 )
n = n . substr ( 0 , n . length - 3 ) + ' ' + n . substr ( - 3 ) ;
a . html ( n ) ;
2008-08-29 01:07:40 -04:00
} ) ;
2008-10-07 21:18:16 -04:00
2008-12-14 07:13:30 -05:00
// XML response
if ( ( 'object' == typeof r ) && lastConfidentTime < settings . parsed . responses [ 0 ] . supplemental . time ) {
// Set the total to the known good value (even if this value is a little old, newer values should only be a few less, and so shouldn't mess up the page links)
updateTotalCount ( settings . parsed . responses [ 0 ] . supplemental . total , settings . parsed . responses [ 0 ] . supplemental . time , true ) ;
if ( $ . trim ( settings . parsed . responses [ 0 ] . supplemental . pageLinks ) ) {
$ ( '.tablenav-pages' ) . find ( '.page-numbers' ) . remove ( ) . end ( ) . append ( $ ( settings . parsed . responses [ 0 ] . supplemental . pageLinks ) ) ;
} else if ( 'undefined' != typeof settings . parsed . responses [ 0 ] . supplemental . pageLinks ) {
$ ( '.tablenav-pages' ) . find ( '.page-numbers' ) . remove ( ) ;
}
} else {
// Decrement the total
var total = parseInt ( totalInput . val ( ) , 10 ) ;
if ( total -- < 0 )
total = 0 ;
updateTotalCount ( total , r , false ) ;
}
2008-08-29 01:07:40 -04:00
if ( theExtraList . size ( ) == 0 || theExtraList . children ( ) . size ( ) == 0 ) {
2008-03-04 12:07:47 -05:00
return ;
}
2008-10-07 21:18:16 -04:00
2008-08-29 01:07:40 -04:00
theList . get ( 0 ) . wpList . add ( theExtraList . children ( ':eq(0)' ) . remove ( ) . clone ( ) ) ;
$ ( '#get-extra-comments' ) . submit ( ) ;
} ;
2007-03-27 17:20:16 -04:00
2008-08-29 01:07:40 -04:00
theExtraList = $ ( '#the-extra-comment-list' ) . wpList ( { alt : '' , delColor : 'none' , addColor : 'none' } ) ;
2008-12-14 07:13:30 -05:00
theList = $ ( '#the-comment-list' ) . wpList ( { alt : '' , delBefore : delBefore , dimAfter : dimAfter , delAfter : delAfter , addColor : 'none' } ) ;
2008-10-07 21:18:16 -04:00
2008-08-29 01:07:40 -04:00
} ;
2006-06-06 00:14:04 -04:00
2008-08-29 01:07:40 -04:00
$ ( document ) . ready ( function ( ) {
setCommentsList ( ) ;
2008-08-24 02:56:22 -04:00
} ) ;
commentReply = {
2008-10-07 21:18:16 -04:00
init : function ( ) {
var row = $ ( '#replyrow' ) ;
2008-08-24 02:56:22 -04:00
2008-10-07 21:18:16 -04:00
$ ( 'a.cancel' , row ) . click ( function ( ) { return commentReply . revert ( ) ; } ) ;
$ ( 'a.save' , row ) . click ( function ( ) { return commentReply . send ( this ) ; } ) ;
2008-08-24 02:56:22 -04:00
2008-10-07 21:18:16 -04:00
// add events
2008-10-31 14:09:42 -04:00
$ ( '#the-comment-list .column-comment > p' ) . dblclick ( function ( ) {
commentReply . toggle ( $ ( this ) . parent ( ) ) ;
} ) ;
2008-10-07 21:18:16 -04:00
$ ( '#doaction, #doaction2, #post-query-submit' ) . click ( function ( e ) {
if ( $ ( '#the-comment-list #replyrow' ) . length > 0 )
t . close ( ) ;
2008-08-24 02:56:22 -04:00
} ) ;
2008-10-07 21:18:16 -04:00
} ,
addEvents : function ( r ) {
r . each ( function ( ) {
2008-10-31 14:09:42 -04:00
$ ( this ) . find ( '.column-comment > p' ) . dblclick ( function ( ) {
commentReply . toggle ( $ ( this ) . parent ( ) ) ;
2008-10-07 21:18:16 -04:00
} ) ;
2008-08-24 02:56:22 -04:00
} ) ;
2008-10-07 21:18:16 -04:00
} ,
2008-08-24 02:56:22 -04:00
2008-10-23 12:34:21 -04:00
toggle : function ( el ) {
if ( $ ( el ) . css ( 'display' ) != 'none' )
$ ( el ) . find ( 'a.vim-q' ) . click ( ) ;
2008-10-07 21:18:16 -04:00
} ,
revert : function ( ) {
2008-10-23 12:34:21 -04:00
if ( $ ( '#the-comment-list #replyrow' ) . length < 1 )
return false ;
$ ( '#replyrow' ) . fadeOut ( 'fast' , function ( ) {
commentReply . close ( ) ;
} ) ;
2008-08-24 02:56:22 -04:00
2008-10-07 21:18:16 -04:00
return false ;
2008-08-24 02:56:22 -04:00
} ,
close : function ( ) {
2008-10-07 21:18:16 -04:00
$ ( this . o ) . fadeIn ( 'fast' ) . css ( 'backgroundColor' , '' ) ;
$ ( '#com-reply' ) . append ( $ ( '#replyrow' ) ) ;
2008-08-24 02:56:22 -04:00
$ ( '#replycontent' ) . val ( '' ) ;
2008-10-07 21:18:16 -04:00
$ ( '#edithead input' ) . val ( '' ) ;
$ ( '#replysubmit .error' ) . html ( '' ) . hide ( ) ;
$ ( '#replysubmit .waiting' ) . hide ( ) ;
if ( $ . browser . msie )
$ ( '#replycontainer, #replycontent' ) . css ( 'height' , '120px' ) ;
else
$ ( '#replycontainer' ) . resizable ( 'destroy' ) . css ( 'height' , '120px' ) ;
} ,
open : function ( id , p , a ) {
var t = this ;
2008-10-23 12:34:21 -04:00
t . close ( ) ;
2008-10-07 21:18:16 -04:00
t . o = '#comment-' + id ;
2008-10-30 11:50:21 -04:00
$ ( '#replyrow td' ) . attr ( 'colspan' , $ ( '.widefat thead th:visible' ) . length ) ;
2008-10-07 21:18:16 -04:00
var editRow = $ ( '#replyrow' ) , rowData = $ ( '#inline-' + id ) ;
var act = t . act = ( a == 'edit' ) ? 'edit-comment' : 'replyto-comment' ;
$ ( '#action' , editRow ) . val ( act ) ;
$ ( '#comment_post_ID' , editRow ) . val ( p ) ;
$ ( '#comment_ID' , editRow ) . val ( id ) ;
if ( a == 'edit' ) {
$ ( '#author' , editRow ) . val ( $ ( 'div.author' , rowData ) . text ( ) ) ;
$ ( '#author-email' , editRow ) . val ( $ ( 'div.author-email' , rowData ) . text ( ) ) ;
$ ( '#author-url' , editRow ) . val ( $ ( 'div.author-url' , rowData ) . text ( ) ) ;
$ ( '#status' , editRow ) . val ( $ ( 'div.comment_status' , rowData ) . text ( ) ) ;
$ ( '#replycontent' , editRow ) . val ( $ ( 'textarea.comment' , rowData ) . val ( ) ) ;
$ ( '#edithead, #savebtn' , editRow ) . show ( ) ;
$ ( '#replyhead, #replybtn' , editRow ) . hide ( ) ;
var h = $ ( t . o ) . height ( ) ;
if ( h > 220 )
if ( $ . browser . msie )
$ ( '#replycontainer, #replycontent' , editRow ) . height ( h - 105 ) ;
else
$ ( '#replycontainer' , editRow ) . height ( h - 105 ) ;
$ ( t . o ) . after ( editRow . hide ( ) ) . fadeOut ( 'fast' , function ( ) {
$ ( '#replyrow' ) . fadeIn ( 'fast' ) ;
} ) ;
} else {
$ ( '#edithead, #savebtn' , editRow ) . hide ( ) ;
$ ( '#replyhead, #replybtn' , editRow ) . show ( ) ;
2008-11-01 23:40:21 -04:00
$ ( t . o ) . after ( editRow ) ;
2008-10-07 21:18:16 -04:00
$ ( '#replyrow' ) . hide ( ) . fadeIn ( 'fast' ) ;
}
if ( ! $ . browser . msie )
$ ( '#replycontainer' ) . resizable ( {
handles : 's' ,
axis : 'y' ,
minHeight : 80 ,
stop : function ( ) {
$ ( '#replycontainer' ) . width ( 'auto' ) ;
}
} ) ;
setTimeout ( function ( ) {
var rtop = $ ( '#replyrow' ) . offset ( ) . top ;
var rbottom = rtop + $ ( '#replyrow' ) . height ( ) ;
var scrollTop = window . pageYOffset || document . documentElement . scrollTop ;
var vp = document . documentElement . clientHeight || self . innerHeight || 0 ;
var scrollBottom = scrollTop + vp ;
if ( scrollBottom - 20 < rbottom )
window . scroll ( 0 , rbottom - vp + 35 ) ;
else if ( rtop - 20 < scrollTop )
window . scroll ( 0 , rtop - 35 ) ;
$ ( '#replycontent' ) . focus ( ) . keyup ( function ( e ) {
if ( e . which == 27 ) commentReply . revert ( ) ; // close on Escape
} ) ;
} , 600 ) ;
2008-08-24 02:56:22 -04:00
return false ;
} ,
send : function ( ) {
var post = { } ;
2008-10-07 21:18:16 -04:00
$ ( '#replysubmit .waiting' ) . show ( ) ;
$ ( '#replyrow input' ) . each ( function ( ) {
2008-08-24 02:56:22 -04:00
post [ $ ( this ) . attr ( 'name' ) ] = $ ( this ) . val ( ) ;
} ) ;
2008-10-07 21:18:16 -04:00
post . content = $ ( '#replycontent' ) . val ( ) ;
2008-08-24 02:56:22 -04:00
post . id = post . comment _post _ID ;
$ . ajax ( {
type : 'POST' ,
url : wpListL10n . url ,
data : post ,
success : function ( x ) { commentReply . show ( x ) ; } ,
error : function ( r ) { commentReply . error ( r ) ; }
} ) ;
2008-10-07 21:18:16 -04:00
return false ;
2008-08-24 02:56:22 -04:00
} ,
show : function ( xml ) {
if ( typeof ( xml ) == 'string' ) {
this . error ( { 'responseText' : xml } ) ;
2008-10-07 21:18:16 -04:00
return false ;
2008-08-24 02:56:22 -04:00
}
var r = wpAjax . parseAjaxResponse ( xml ) ;
2008-10-07 21:18:16 -04:00
if ( r . errors ) {
2008-08-24 02:56:22 -04:00
this . error ( { 'responseText' : wpAjax . broken } ) ;
2008-10-07 21:18:16 -04:00
return false ;
}
2008-08-24 02:56:22 -04:00
2008-10-07 21:18:16 -04:00
if ( 'edit-comment' == this . act )
$ ( this . o ) . remove ( ) ;
2008-08-24 02:56:22 -04:00
2008-10-07 21:18:16 -04:00
r = r . responses [ 0 ] ;
var c = r . data ;
2008-08-24 02:56:22 -04:00
2008-10-07 21:18:16 -04:00
$ ( c ) . hide ( )
$ ( '#replyrow' ) . after ( c ) ;
this . o = id = '#comment-' + r . id ;
this . revert ( ) ;
this . addEvents ( $ ( id ) ) ;
2008-11-14 16:54:39 -05:00
var bg = $ ( id ) . hasClass ( 'unapproved' ) ? '#ffffe0' : '#fff' ;
2008-09-05 15:11:41 -04:00
2008-10-07 21:18:16 -04:00
$ ( id )
2008-11-14 16:54:39 -05:00
. animate ( { 'backgroundColor' : '#CCEEBB' } , 600 )
. animate ( { 'backgroundColor' : bg } , 600 ) ;
2008-10-07 21:18:16 -04:00
2008-12-07 07:18:04 -05:00
$ . fn . wpList . process ( $ ( id ) )
2008-08-24 02:56:22 -04:00
} ,
error : function ( r ) {
var er = r . statusText ;
2008-10-07 21:18:16 -04:00
$ ( '#replysubmit .waiting' ) . hide ( ) ;
2008-08-24 02:56:22 -04:00
if ( r . responseText )
er = r . responseText . replace ( /<.[^<>]*?>/g , '' ) ;
2008-10-07 21:18:16 -04:00
if ( er )
$ ( '#replysubmit .error' ) . html ( er ) . show ( ) ;
2008-08-24 02:56:22 -04:00
}
2008-08-29 01:07:40 -04:00
} ;
2008-12-05 02:15:31 -05:00
toggleWithKeyboard = false ;
2008-08-24 02:56:22 -04:00
$ ( document ) . ready ( function ( ) {
2008-11-17 14:16:26 -05:00
columns . init ( 'edit-comments' ) ;
2008-10-07 21:18:16 -04:00
commentReply . init ( ) ;
2008-09-25 21:05:52 -04:00
2008-08-24 02:56:22 -04:00
if ( typeof QTags != 'undefined' )
ed _reply = new QTags ( 'ed_reply' , 'replycontent' , 'replycontainer' , 'more' ) ;
2008-09-05 15:11:41 -04:00
2008-09-01 01:28:41 -04:00
if ( typeof $ . table _hotkeys != 'undefined' ) {
var make _hotkeys _redirect = function ( which ) {
return function ( ) {
2008-10-07 21:18:16 -04:00
var first _last = 'next' == which ? 'first' : 'last' ;
2008-09-01 01:28:41 -04:00
var l = $ ( '.' + which + '.page-numbers' ) ;
if ( l . length )
window . location = l [ 0 ] . href . replace ( /\&hotkeys_highlight_(first|last)=1/g , '' ) + '&hotkeys_highlight_' + first _last + '=1' ;
}
2008-09-04 13:53:14 -04:00
} ;
var edit _comment = function ( event , current _row ) {
window . location = $ ( 'span.edit a' , current _row ) . attr ( 'href' ) ;
} ;
var toggle _all = function ( ) {
2008-12-05 02:15:31 -05:00
toggleWithKeyboard = true ;
2008-09-04 13:53:14 -04:00
var master _checkbox = $ ( 'form#comments-form .check-column :checkbox:first' ) ;
2008-12-05 02:15:31 -05:00
master _checkbox . click ( ) . attr ( 'checked' , '' ) ;
toggleWithKeyboard = false ;
2008-09-01 01:28:41 -04:00
}
2008-09-04 13:53:14 -04:00
var make _bulk = function ( value ) {
return function ( event , _ ) {
$ ( 'option[value=' + value + ']' ) . attr ( 'selected' , 'selected' ) ;
$ ( 'form#comments-form' ) [ 0 ] . submit ( ) ;
2008-09-01 01:28:41 -04:00
}
2008-09-04 13:53:14 -04:00
} ;
2008-10-23 12:34:21 -04:00
$ . table _hotkeys ( $ ( 'table.widefat' ) , [ 'a' , 'u' , 's' , 'd' , 'r' , 'q' , [ 'e' , edit _comment ] ,
2008-09-04 13:53:14 -04:00
[ 'shift+a' , make _bulk ( 'approve' ) ] , [ 'shift+s' , make _bulk ( 'markspam' ) ] ,
2008-10-16 18:23:32 -04:00
[ 'shift+d' , make _bulk ( 'delete' ) ] , [ 'shift+x' , toggle _all ] ,
[ 'shift+u' , make _bulk ( 'unapprove' ) ] ] ,
2008-09-04 13:53:14 -04:00
{ highlight _first : adminCommentsL10n . hotkeys _highlight _first , highlight _last : adminCommentsL10n . hotkeys _highlight _last ,
prev _page _link _cb : make _hotkeys _redirect ( 'prev' ) , next _page _link _cb : make _hotkeys _redirect ( 'next' ) }
2008-09-01 01:28:41 -04:00
) ;
}
2008-08-24 02:56:22 -04:00
} ) ;
2008-09-05 15:11:41 -04:00
} ) ( jQuery ) ;