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