]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-content/plugins/akismet/_inc/akismet.js
WordPress 4.4.1
[autoinstalls/wordpress.git] / wp-content / plugins / akismet / _inc / akismet.js
1 jQuery( function ( $ ) {
2         var mshotRemovalTimer = null;
3         var mshotSecondTryTimer = null
4         var mshotThirdTryTimer = null
5         
6         $( 'a.activate-option' ).click( function(){
7                 var link = $( this );
8                 if ( link.hasClass( 'clicked' ) ) {
9                         link.removeClass( 'clicked' );
10                 }
11                 else {
12                         link.addClass( 'clicked' );
13                 }
14                 $( '.toggle-have-key' ).slideToggle( 'slow', function() {});
15                 return false;
16         });
17         $('.akismet-status').each(function () {
18                 var thisId = $(this).attr('commentid');
19                 $(this).prependTo('#comment-' + thisId + ' .column-comment');
20         });
21         $('.akismet-user-comment-count').each(function () {
22                 var thisId = $(this).attr('commentid');
23                 $(this).insertAfter('#comment-' + thisId + ' .author strong:first').show();
24         });
25         $('#the-comment-list')
26                 .find('tr.comment, tr[id ^= "comment-"]')
27                 .find('.column-author a[href^="http"]:first') // Ignore mailto: links, which would be the comment author's email.
28                 .each(function () {
29                 var linkHref = $(this).attr( 'href' );
30                 
31                 // Ignore any links to the current domain, which are diagnostic tools, like the IP address link
32                 // or any other links another plugin might add.
33                 var currentHostParts = document.location.href.split( '/' );
34                 var currentHost = currentHostParts[0] + '//' + currentHostParts[2] + '/';
35                 
36                 if ( linkHref.indexOf( currentHost ) != 0 ) {
37                         var thisCommentId = $(this).parents('tr:first').attr('id').split("-");
38
39                         $(this)
40                                 .attr("id", "author_comment_url_"+ thisCommentId[1])
41                                 .after(
42                                         $( '<a href="#" class="remove_url">x</a>' )
43                                                 .attr( 'commentid', thisCommentId[1] )
44                                                 .attr( 'title', WPAkismet.strings['Remove this URL'] )
45                                 );
46                 }
47         });
48         $('.remove_url').live('click', function () {
49                 var thisId = $(this).attr('commentid');
50                 var data = {
51                         action: 'comment_author_deurl',
52                         _wpnonce: WPAkismet.comment_author_url_nonce,
53                         id: thisId
54                 };
55                 $.ajax({
56                         url: ajaxurl,
57                         type: 'POST',
58                         data: data,
59                         beforeSend: function () {
60                                 // Removes "x" link
61                                 $("a[commentid='"+ thisId +"']").hide();
62                                 // Show temp status
63                                 $("#author_comment_url_"+ thisId).html( $( '<span/>' ).text( WPAkismet.strings['Removing...'] ) );
64                         },
65                         success: function (response) {
66                                 if (response) {
67                                         // Show status/undo link
68                                         $("#author_comment_url_"+ thisId)
69                                                 .attr('cid', thisId)
70                                                 .addClass('akismet_undo_link_removal')
71                                                 .html(
72                                                         $( '<span/>' ).text( WPAkismet.strings['URL removed'] )
73                                                 )
74                                                 .append( ' ' )
75                                                 .append(
76                                                         $( '<span/>' )
77                                                                 .text( WPAkismet.strings['(undo)'] )
78                                                                 .addClass( 'akismet-span-link' )
79                                                 );
80                                 }
81                         }
82                 });
83
84                 return false;
85         });
86         $('.akismet_undo_link_removal').live('click', function () {
87                 var thisId = $(this).attr('cid');
88                 var thisUrl = $(this).attr('href');
89                 var data = {
90                         action: 'comment_author_reurl',
91                         _wpnonce: WPAkismet.comment_author_url_nonce,
92                         id: thisId,
93                         url: thisUrl
94                 };
95                 $.ajax({
96                         url: ajaxurl,
97                         type: 'POST',
98                         data: data,
99                         beforeSend: function () {
100                                 // Show temp status
101                                 $("#author_comment_url_"+ thisId).html( $( '<span/>' ).text( WPAkismet.strings['Re-adding...'] ) );
102                         },
103                         success: function (response) {
104                                 if (response) {
105                                         // Add "x" link
106                                         $("a[commentid='"+ thisId +"']").show();
107                                         // Show link. Core strips leading http://, so let's do that too.
108                                         $("#author_comment_url_"+ thisId).removeClass('akismet_undo_link_removal').text( thisUrl.replace( /^http:\/\/(www\.)?/ig, '' ) );
109                                 }
110                         }
111                 });
112
113                 return false;
114         });
115
116         // Show a preview image of the hovered URL. Applies to author URLs and URLs inside the comments.
117         $( 'a[id^="author_comment_url"], tr.pingback td.column-author a:first-of-type, table.comments td.comment p a' ).mouseover( function () {
118                 clearTimeout( mshotRemovalTimer );
119
120                 if ( $( '.akismet-mshot' ).length > 0 ) {
121                         if ( $( '.akismet-mshot:first' ).data( 'link' ) == this ) {
122                                 // The preview is already showing for this link.
123                                 return;
124                         }
125                         else {
126                                 // A new link is being hovered, so remove the old preview.
127                                 $( '.akismet-mshot' ).remove();
128                         }
129                 }
130
131                 clearTimeout( mshotSecondTryTimer );
132                 clearTimeout( mshotThirdTryTimer );
133
134                 var thisHref = $.URLEncode( $( this ).attr( 'href' ) );
135
136                 var mShot = $( '<div class="akismet-mshot mshot-container"><div class="mshot-arrow"></div><img src="//s0.wordpress.com/mshots/v1/' + thisHref + '?w=450" width="450" height="338" class="mshot-image" /></div>' );
137                 mShot.data( 'link', this );
138
139                 var offset = $( this ).offset();
140
141                 mShot.offset( {
142                         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.
143                         top: offset.top + ( $( this ).height() / 2 ) - 101 // 101 = top offset of the arrow plus the top border thickness
144                 } );
145
146                 mshotSecondTryTimer = setTimeout( function () {
147                         mShot.find( '.mshot-image' ).attr( 'src', '//s0.wordpress.com/mshots/v1/'+thisHref+'?w=450&r=2' );
148                 }, 6000 );
149
150                 mshotThirdTryTimer = setTimeout( function () {
151                         mShot.find( '.mshot-image' ).attr( 'src', '//s0.wordpress.com/mshots/v1/'+thisHref+'?w=450&r=3' );
152                 }, 12000 );
153
154                 $( 'body' ).append( mShot );
155         } ).mouseout( function () {
156                 mshotRemovalTimer = setTimeout( function () {
157                         clearTimeout( mshotSecondTryTimer );
158                         clearTimeout( mshotThirdTryTimer );
159
160                         $( '.akismet-mshot' ).remove();
161                 }, 200 );
162         } );
163
164         $('.checkforspam:not(.button-disabled)').click( function(e) {
165                 $('.checkforspam:not(.button-disabled)').addClass('button-disabled');
166                 $('.checkforspam-spinner').addClass( 'spinner' );
167                 akismet_check_for_spam(0, 100);
168                 e.preventDefault();
169         });
170
171         function akismet_check_for_spam(offset, limit) {
172                 $.post(
173                         ajaxurl,
174                         {
175                                 'action': 'akismet_recheck_queue',
176                                 'offset': offset,
177                                 'limit': limit
178                         },
179                         function(result) {
180                                 if (result.processed < limit) {
181                                         window.location.reload();
182                                 }
183                                 else {
184                                         akismet_check_for_spam(offset + limit, limit);
185                                 }
186                         }
187                 );
188         }
189 });
190 // URL encode plugin
191 jQuery.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
192   while(x<c.length){var m=r.exec(c.substr(x));
193     if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
194     }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
195     o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;}
196 });