1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: CG Comment Reply |
---|
4 | Version: 0.1 <strong>α</strong> |
---|
5 | Plugin URI: http://www.caesarsgrunt.com/ |
---|
6 | Description: Enhances the appearance and functionality of the new reply-to-comments feature in 2.7-hemorrhage. |
---|
7 | Author: Caesar Schinas |
---|
8 | Author URI: http://www.caesarsgrunt.com/ |
---|
9 | */ |
---|
10 | function cg_comment_reply() { |
---|
11 | ob_start(); |
---|
12 | ?> |
---|
13 | <div id="replydiv" style="display:none;"> |
---|
14 | <p id="replyhandle" style="cursor:default;"> |
---|
15 | <!--<a id='show-settings-link' class='button-secondary' style='float:right; cursor:pointer; font-size:0.8em; line-height:inherit; padding-right:5px;'>More Details</a>--> |
---|
16 | <?php _e('Reply'); ?> |
---|
17 | </p> |
---|
18 | <form action="" method="post" id="replyform"> |
---|
19 | <input type="hidden" name="user_ID" id="user_ID" value="<?php echo $current_user->ID; ?>" /> |
---|
20 | <input type="hidden" name="action" value="replyto-comment" /> |
---|
21 | <input type="hidden" name="comment_ID" id="comment_ID" value="" /> |
---|
22 | <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" /> |
---|
23 | <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" /> |
---|
24 | <input type="hidden" name="checkbox" id="checkbox" value="1" /> |
---|
25 | <input type="hidden" name="mode" id="mode" value="<?php echo $mode; ?>" /> |
---|
26 | <?php wp_nonce_field( 'replyto-comment', '_ajax_nonce', false ); ?> |
---|
27 | <?php wp_comment_form_unfiltered_html_nonce(); ?> |
---|
28 | |
---|
29 | <div id="replycontainer"><textarea rows="5" cols="50" name="replycontent" tabindex="10" id="replycontent"></textarea></div> |
---|
30 | <p id="replyerrtext" class="error" style="display:none; padding:10px; margin:2px 0; border:none;"></p> |
---|
31 | |
---|
32 | <p id="replysubmit"> |
---|
33 | <input id="close-button" type="button" onclick="commentReply.close();" class="button" value="<?php _e('Cancel'); ?>" /> |
---|
34 | <input id="reply-button" type="button" onclick="commentReply.send();" class="button button-highlighted" value="<?php _e('Submit Reply'); ?>" /> |
---|
35 | <input id="retry-button" type="button" onclick="commentReply.open();" class="button button-highlighted" style="display:none;" value="<?php _e('Go Back'); ?>" /> |
---|
36 | </p> |
---|
37 | </form> |
---|
38 | </div> |
---|
39 | <script type='text/javascript'> |
---|
40 | jQuery(function($){ |
---|
41 | commentReply.open = function(c, p) { |
---|
42 | $('#replyerrtext, #retry-button').hide(); |
---|
43 | $('#replycontainer, #ed_reply_qtags, #reply-button').show(); |
---|
44 | |
---|
45 | $('#replydiv #comment_post_ID').val(p); |
---|
46 | $('#replydiv #comment_ID').val(c); |
---|
47 | |
---|
48 | if ($('td#replyerror').is(':visible')) { |
---|
49 | $('td#replyerror').hide(); |
---|
50 | $('#comment-'+c).after($('td#replydiv').show()); |
---|
51 | } |
---|
52 | else if (!$('td#replydiv').is(':visible')) { |
---|
53 | var tr = document.createElement('tr'); |
---|
54 | var td = tr.appendChild(document.createElement('td')) |
---|
55 | $(td).attr('colspan',5).hide(); |
---|
56 | $('#comment-'+c).after(tr); |
---|
57 | $(td).append($('#replydiv').contents()); |
---|
58 | $('#replydiv').remove(); |
---|
59 | $('#replyform, #replyhandle').hide(); |
---|
60 | $(td).attr('id','replydiv').fadeIn('fast').css('border','1px solid #CCC'); |
---|
61 | $('#replyform, #replyhandle').slideDown('fast'); |
---|
62 | } |
---|
63 | else { |
---|
64 | $('#comment-'+c).after($('td#replydiv')); |
---|
65 | } |
---|
66 | |
---|
67 | $('#replycontent').focus().keyup(function(e){ |
---|
68 | if (e.which == 27) commentReply.close(); // close on Escape |
---|
69 | }); |
---|
70 | |
---|
71 | $('#replycontainer').resizable({ |
---|
72 | handles : 's', |
---|
73 | minHeight : 100, |
---|
74 | maxHeight : 350, |
---|
75 | containment : '#wpwrap', |
---|
76 | resize : function(e,o) { |
---|
77 | h = o.size.height; |
---|
78 | $('#replycontainer').height(h); |
---|
79 | $('#replycontainer').width('auto'); |
---|
80 | }, |
---|
81 | }); |
---|
82 | |
---|
83 | $('.ui-resizable-s').css({ |
---|
84 | border: '0 none', |
---|
85 | width: '11px', |
---|
86 | height: '12px', |
---|
87 | background: 'transparent url(images/se.png) no-repeat scroll 0 0', |
---|
88 | right: '2px', |
---|
89 | left: 'auto', |
---|
90 | bottom: '2px', |
---|
91 | position: 'absolute' |
---|
92 | }); |
---|
93 | |
---|
94 | setTimeout(function(){ |
---|
95 | var replyBottom = $('#replydiv').offset().top + $('#replydiv').height(); |
---|
96 | var scrollTop = (window.pageYOffset||document.body.scrollTop||document.documentElement.scrollTop); |
---|
97 | var viewportHeight = (document.documentElement.clientHeight || self.innerHeight || document.body.clientHeight || 0) + 0; |
---|
98 | var scrollBottom = scrollTop + viewportHeight; |
---|
99 | |
---|
100 | if ( scrollBottom - 20 < replyBottom ) |
---|
101 | window.scroll(0, replyBottom - viewportHeight + 25); |
---|
102 | }, 500); |
---|
103 | } |
---|
104 | commentReply.close = function() { |
---|
105 | $('#replyform, #replyhandle').slideUp('fast'); |
---|
106 | $('#replydiv').fadeOut('fast'); |
---|
107 | |
---|
108 | $('#replycontent').val(''); |
---|
109 | |
---|
110 | return false; |
---|
111 | } |
---|
112 | commentReply.error = function(r) { |
---|
113 | var er = r.statusText; |
---|
114 | |
---|
115 | if ( r.responseText ) |
---|
116 | er = r.responseText.replace( /<.[^<>]*?>/g, '' ); |
---|
117 | |
---|
118 | if ( er ) { |
---|
119 | var height = $('#replycontainer').height() + $('#ed_reply_qtags').height() - 13; |
---|
120 | $('#replycontainer, #ed_reply_qtags, #reply-button').hide(); |
---|
121 | $('#replyerrtext').show().css('height', height); |
---|
122 | $('#retry-button').show().focus(); |
---|
123 | |
---|
124 | $('#replyerrtext').html(er) |
---|
125 | $('#close-button').css('outline','none').focus().keyup(function(e) { |
---|
126 | if (e.which == 27) commentReply.close(); // close on Escape |
---|
127 | }); |
---|
128 | } |
---|
129 | } |
---|
130 | }); |
---|
131 | </script> |
---|
132 | <?php |
---|
133 | $form = ob_get_contents(); |
---|
134 | ob_end_clean(); |
---|
135 | return $form; |
---|
136 | } |
---|
137 | add_filter('wp_comment_reply','cg_comment_reply'); |
---|
138 | ?> |
---|