1 jQuery( function ( $ ) { |
1 jQuery( function ( $ ) { |
2 $( 'a.activate-option' ).click( function(){ |
2 var mshotRemovalTimer = null; |
3 var link = $( this ); |
3 var mshotSecondTryTimer = null |
4 if ( link.hasClass( 'clicked' ) ) { |
4 var mshotThirdTryTimer = null |
5 link.removeClass( 'clicked' ); |
5 |
6 } |
6 var mshotEnabledLinkSelector = 'a[id^="author_comment_url"], tr.pingback td.column-author a:first-of-type, td.comment p a'; |
7 else { |
7 |
8 link.addClass( 'clicked' ); |
|
9 } |
|
10 $( '.toggle-have-key' ).slideToggle( 'slow', function() {}); |
|
11 return false; |
|
12 }); |
|
13 $('.akismet-status').each(function () { |
8 $('.akismet-status').each(function () { |
14 var thisId = $(this).attr('commentid'); |
9 var thisId = $(this).attr('commentid'); |
15 $(this).prependTo('#comment-' + thisId + ' .column-comment'); |
10 $(this).prependTo('#comment-' + thisId + ' .column-comment'); |
16 }); |
11 }); |
17 $('.akismet-user-comment-count').each(function () { |
12 $('.akismet-user-comment-count').each(function () { |
18 var thisId = $(this).attr('commentid'); |
13 var thisId = $(this).attr('commentid'); |
19 $(this).insertAfter('#comment-' + thisId + ' .author strong:first').show(); |
14 $(this).insertAfter('#comment-' + thisId + ' .author strong:first').show(); |
20 }); |
15 }); |
21 $('#the-comment-list').find('tr.comment, tr[id ^= "comment-"]').find('.column-author a[title]').each(function () { |
16 |
22 // Comment author URLs are the only URL with a title attribute in the author column. |
17 akismet_enable_comment_author_url_removal(); |
23 var thisTitle = $(this).attr('title'); |
18 |
24 |
19 $( '#the-comment-list' ).on( 'click', '.akismet_remove_url', function () { |
25 var thisCommentId = $(this).parents('tr:first').attr('id').split("-"); |
|
26 |
|
27 $(this).attr("id", "author_comment_url_"+ thisCommentId[1]); |
|
28 |
|
29 if (thisTitle) { |
|
30 $(this).after( |
|
31 $( '<a href="#" class="remove_url">x</a>' ) |
|
32 .attr( 'commentid', thisCommentId[1] ) |
|
33 .attr( 'title', WPAkismet.strings['Remove this URL'] ) |
|
34 ); |
|
35 } |
|
36 }); |
|
37 $('.remove_url').live('click', function () { |
|
38 var thisId = $(this).attr('commentid'); |
20 var thisId = $(this).attr('commentid'); |
39 var data = { |
21 var data = { |
40 action: 'comment_author_deurl', |
22 action: 'comment_author_deurl', |
41 _wpnonce: WPAkismet.comment_author_url_nonce, |
23 _wpnonce: WPAkismet.comment_author_url_nonce, |
42 id: thisId |
24 id: thisId |
99 } |
80 } |
100 }); |
81 }); |
101 |
82 |
102 return false; |
83 return false; |
103 }); |
84 }); |
104 $('a[id^="author_comment_url"], tr.pingback td.column-author a:first-of-type').mouseover(function () { |
85 |
105 var wpcomProtocol = ( 'https:' === location.protocol ) ? 'https://' : 'http://'; |
86 // Show a preview image of the hovered URL. Applies to author URLs and URLs inside the comments. |
106 // Need to determine size of author column |
87 $( '#the-comment-list' ).on( 'mouseover', mshotEnabledLinkSelector, function () { |
107 var thisParentWidth = $(this).parent().width(); |
88 clearTimeout( mshotRemovalTimer ); |
108 // It changes based on if there is a gravatar present |
89 |
109 thisParentWidth = ($(this).parent().find('.grav-hijack').length) ? thisParentWidth - 42 + 'px' : thisParentWidth + 'px'; |
90 if ( $( '.akismet-mshot' ).length > 0 ) { |
110 if ($(this).find('.mShot').length == 0 && !$(this).hasClass('akismet_undo_link_removal')) { |
91 if ( $( '.akismet-mshot:first' ).data( 'link' ) == this ) { |
111 var self = $( this ); |
92 // The preview is already showing for this link. |
112 $('.widefat td').css('overflow', 'visible'); |
93 return; |
113 $(this).css('position', 'relative'); |
94 } |
114 var thisHref = $.URLEncode( $(this).attr('href') ); |
95 else { |
115 $(this).append('<div class="mShot mshot-container" style="left: '+thisParentWidth+'"><div class="mshot-arrow"></div><img src="//s0.wordpress.com/mshots/v1/'+thisHref+'?w=450" width="450" class="mshot-image" style="margin: 0;" /></div>'); |
96 // A new link is being hovered, so remove the old preview. |
116 setTimeout(function () { |
97 $( '.akismet-mshot' ).remove(); |
117 self.find( '.mshot-image' ).attr('src', '//s0.wordpress.com/mshots/v1/'+thisHref+'?w=450&r=2'); |
98 } |
118 }, 6000); |
|
119 setTimeout(function () { |
|
120 self.find( '.mshot-image' ).attr('src', '//s0.wordpress.com/mshots/v1/'+thisHref+'?w=450&r=3'); |
|
121 }, 12000); |
|
122 } else { |
|
123 $(this).find('.mShot').css('left', thisParentWidth).show(); |
|
124 } |
99 } |
125 }).mouseout(function () { |
100 |
126 $(this).find('.mShot').hide(); |
101 clearTimeout( mshotSecondTryTimer ); |
127 }); |
102 clearTimeout( mshotThirdTryTimer ); |
|
103 |
|
104 var thisHref = $( this ).attr( 'href' ); |
|
105 |
|
106 var mShot = $( '<div class="akismet-mshot mshot-container"><div class="mshot-arrow"></div><img src="' + akismet_mshot_url( thisHref ) + '" width="450" height="338" class="mshot-image" /></div>' ); |
|
107 mShot.data( 'link', this ); |
|
108 |
|
109 var offset = $( this ).offset(); |
|
110 |
|
111 mShot.offset( { |
|
112 left : Math.min( $( window ).width() - 475, offset.left + $( this ).width() + 10 ), // Keep it on the screen if the link is near the edge of the window. |
|
113 top: offset.top + ( $( this ).height() / 2 ) - 101 // 101 = top offset of the arrow plus the top border thickness |
|
114 } ); |
|
115 |
|
116 // These retries appear to be superfluous if .mshot-image has already loaded, but it's because mShots |
|
117 // can return a "Generating thumbnail..." image if it doesn't have a thumbnail ready, so we need |
|
118 // to retry to see if we can get the newly generated thumbnail. |
|
119 mshotSecondTryTimer = setTimeout( function () { |
|
120 mShot.find( '.mshot-image' ).attr( 'src', akismet_mshot_url( thisHref, 2 ) ); |
|
121 }, 6000 ); |
|
122 |
|
123 mshotThirdTryTimer = setTimeout( function () { |
|
124 mShot.find( '.mshot-image' ).attr( 'src', akismet_mshot_url( thisHref, 3 ) ); |
|
125 }, 12000 ); |
|
126 |
|
127 $( 'body' ).append( mShot ); |
|
128 } ).on( 'mouseout', 'a[id^="author_comment_url"], tr.pingback td.column-author a:first-of-type, td.comment p a', function () { |
|
129 mshotRemovalTimer = setTimeout( function () { |
|
130 clearTimeout( mshotSecondTryTimer ); |
|
131 clearTimeout( mshotThirdTryTimer ); |
|
132 |
|
133 $( '.akismet-mshot' ).remove(); |
|
134 }, 200 ); |
|
135 } ).on( 'mouseover', 'tr', function () { |
|
136 // When the mouse hovers over a comment row, begin preloading mshots for any links in the comment or the comment author. |
|
137 var linksToPreloadMshotsFor = $( this ).find( mshotEnabledLinkSelector ); |
|
138 |
|
139 linksToPreloadMshotsFor.each( function () { |
|
140 // Don't attempt to preload an mshot for a single link twice. Browser caching should cover this, but in case of |
|
141 // race conditions, save a flag locally when we've begun trying to preload one. |
|
142 if ( ! $( this ).data( 'akismet-mshot-preloaded' ) ) { |
|
143 akismet_preload_mshot( $( this ).attr( 'href' ) ); |
|
144 $( this ).data( 'akismet-mshot-preloaded', true ); |
|
145 } |
|
146 } ); |
|
147 } ); |
|
148 |
128 $('.checkforspam:not(.button-disabled)').click( function(e) { |
149 $('.checkforspam:not(.button-disabled)').click( function(e) { |
|
150 e.preventDefault(); |
|
151 |
129 $('.checkforspam:not(.button-disabled)').addClass('button-disabled'); |
152 $('.checkforspam:not(.button-disabled)').addClass('button-disabled'); |
130 $('.checkforspam-spinner').addClass( 'spinner' ); |
153 $('.checkforspam-spinner').addClass( 'spinner' ).addClass( 'is-active' ); |
|
154 |
|
155 // Update the label on the "Check for Spam" button to use the active "Checking for Spam" language. |
|
156 $( '.checkforspam .akismet-label' ).text( $( '.checkforspam' ).data( 'active-label' ) ); |
|
157 |
131 akismet_check_for_spam(0, 100); |
158 akismet_check_for_spam(0, 100); |
132 e.preventDefault(); |
159 }); |
133 }); |
160 |
|
161 var spam_count = 0; |
|
162 var recheck_count = 0; |
134 |
163 |
135 function akismet_check_for_spam(offset, limit) { |
164 function akismet_check_for_spam(offset, limit) { |
|
165 var check_for_spam_buttons = $( '.checkforspam' ); |
|
166 |
|
167 // We show the percentage complete down to one decimal point so even queues with 100k |
|
168 // pending comments will show some progress pretty quickly. |
|
169 var percentage_complete = Math.round( ( recheck_count / check_for_spam_buttons.data( 'pending-comment-count' ) ) * 1000 ) / 10; |
|
170 |
|
171 // Update the progress counter on the "Check for Spam" button. |
|
172 $( '.checkforspam-progress' ).text( check_for_spam_buttons.data( 'progress-label-format' ).replace( '%1$s', percentage_complete ) ); |
|
173 |
136 $.post( |
174 $.post( |
137 ajaxurl, |
175 ajaxurl, |
138 { |
176 { |
139 'action': 'akismet_recheck_queue', |
177 'action': 'akismet_recheck_queue', |
140 'offset': offset, |
178 'offset': offset, |
141 'limit': limit |
179 'limit': limit |
142 }, |
180 }, |
143 function(result) { |
181 function(result) { |
144 if (result.processed < limit) { |
182 recheck_count += result.counts.processed; |
145 window.location.reload(); |
183 spam_count += result.counts.spam; |
|
184 |
|
185 if (result.counts.processed < limit) { |
|
186 window.location.href = check_for_spam_buttons.data( 'success-url' ).replace( '__recheck_count__', recheck_count ).replace( '__spam_count__', spam_count ); |
146 } |
187 } |
147 else { |
188 else { |
148 akismet_check_for_spam(offset + limit, limit); |
189 // Account for comments that were caught as spam and moved out of the queue. |
|
190 akismet_check_for_spam(offset + limit - result.counts.spam, limit); |
149 } |
191 } |
150 } |
192 } |
151 ); |
193 ); |
152 } |
194 } |
|
195 |
|
196 if ( "start_recheck" in WPAkismet && WPAkismet.start_recheck ) { |
|
197 $( '.checkforspam' ).click(); |
|
198 } |
|
199 |
|
200 if ( typeof MutationObserver !== 'undefined' ) { |
|
201 // Dynamically add the "X" next the the author URL links when a comment is quick-edited. |
|
202 var comment_list_container = document.getElementById( 'the-comment-list' ); |
|
203 |
|
204 if ( comment_list_container ) { |
|
205 var observer = new MutationObserver( function ( mutations ) { |
|
206 for ( var i = 0, _len = mutations.length; i < _len; i++ ) { |
|
207 if ( mutations[i].addedNodes.length > 0 ) { |
|
208 akismet_enable_comment_author_url_removal(); |
|
209 |
|
210 // Once we know that we'll have to check for new author links, skip the rest of the mutations. |
|
211 break; |
|
212 } |
|
213 } |
|
214 } ); |
|
215 |
|
216 observer.observe( comment_list_container, { attributes: true, childList: true, characterData: true } ); |
|
217 } |
|
218 } |
|
219 |
|
220 function akismet_enable_comment_author_url_removal() { |
|
221 $( '#the-comment-list' ) |
|
222 .find( 'tr.comment, tr[id ^= "comment-"]' ) |
|
223 .find( '.column-author a[href^="http"]:first' ) // Ignore mailto: links, which would be the comment author's email. |
|
224 .each(function () { |
|
225 if ( $( this ).parent().find( '.akismet_remove_url' ).length > 0 ) { |
|
226 return; |
|
227 } |
|
228 |
|
229 var linkHref = $(this).attr( 'href' ); |
|
230 |
|
231 // Ignore any links to the current domain, which are diagnostic tools, like the IP address link |
|
232 // or any other links another plugin might add. |
|
233 var currentHostParts = document.location.href.split( '/' ); |
|
234 var currentHost = currentHostParts[0] + '//' + currentHostParts[2] + '/'; |
|
235 |
|
236 if ( linkHref.indexOf( currentHost ) != 0 ) { |
|
237 var thisCommentId = $(this).parents('tr:first').attr('id').split("-"); |
|
238 |
|
239 $(this) |
|
240 .attr("id", "author_comment_url_"+ thisCommentId[1]) |
|
241 .after( |
|
242 $( '<a href="#" class="akismet_remove_url">x</a>' ) |
|
243 .attr( 'commentid', thisCommentId[1] ) |
|
244 .attr( 'title', WPAkismet.strings['Remove this URL'] ) |
|
245 ); |
|
246 } |
|
247 }); |
|
248 } |
|
249 |
|
250 /** |
|
251 * Generate an mShot URL if given a link URL. |
|
252 * |
|
253 * @param string linkUrl |
|
254 * @param int retry If retrying a request, the number of the retry. |
|
255 * @return string The mShot URL; |
|
256 */ |
|
257 function akismet_mshot_url( linkUrl, retry ) { |
|
258 var mshotUrl = '//s0.wordpress.com/mshots/v1/' + encodeURIComponent( linkUrl ) + '?w=900'; |
|
259 |
|
260 if ( retry ) { |
|
261 mshotUrl += '&r=' + encodeURIComponent( retry ); |
|
262 } |
|
263 |
|
264 return mshotUrl; |
|
265 } |
|
266 |
|
267 /** |
|
268 * Begin loading an mShot preview of a link. |
|
269 * |
|
270 * @param string linkUrl |
|
271 */ |
|
272 function akismet_preload_mshot( linkUrl ) { |
|
273 var img = new Image(); |
|
274 img.src = akismet_mshot_url( linkUrl ); |
|
275 } |
|
276 |
|
277 /** |
|
278 * Sets the comment form privacy notice display to hide when one clicks Core's dismiss button on the related admin notice. |
|
279 */ |
|
280 $( '#akismet-privacy-notice-admin-notice' ).on( 'click', '.notice-dismiss', function(){ |
|
281 $.ajax({ |
|
282 url: './options-general.php?page=akismet-key-config&akismet_comment_form_privacy_notice=hide', |
|
283 }); |
|
284 }); |
153 }); |
285 }); |
154 // URL encode plugin |
|
155 jQuery.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/; |
|
156 while(x<c.length){var m=r.exec(c.substr(x)); |
|
157 if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length; |
|
158 }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16); |
|
159 o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;} |
|
160 }); |
|