7da76cd52e0bef9bd6afabf627cdd3b12e1d694b
[autoinstalls/wordpress.git] / wp-content / plugins / akismet / _inc / akismet.js
1 jQuery( function ( $ ) {
2         $( 'a.activate-option' ).click( function(){
3                 var link = $( this );
4                 if ( link.hasClass( 'clicked' ) ) {
5                         link.removeClass( 'clicked' );
6                 }
7                 else {
8                         link.addClass( 'clicked' );
9                 }
10                 $( '.toggle-have-key' ).slideToggle( 'slow', function() {});
11                 return false;
12         });
13         $('.akismet-status').each(function () {
14                 var thisId = $(this).attr('commentid');
15                 $(this).prependTo('#comment-' + thisId + ' .column-comment');
16         });
17         $('.akismet-user-comment-count').each(function () {
18                 var thisId = $(this).attr('commentid');
19                 $(this).insertAfter('#comment-' + thisId + ' .author strong:first').show();
20         });
21         $('#the-comment-list').find('tr.comment, tr[id ^= "comment-"]').find('.column-author a[title ^= "http://"], .column-author a[title ^= "https://"]').each(function () {
22                 var thisTitle = $(this).attr('title');
23                         thisCommentId = $(this).parents('tr:first').attr('id').split("-");
24
25                 $(this).attr("id", "author_comment_url_"+ thisCommentId[1]);
26
27                 if (thisTitle) {
28                         $(this).after(
29                                 $( '<a href="#" class="remove_url">x</a>' )
30                                         .attr( 'commentid', thisCommentId[1] )
31                                         .attr( 'title', WPAkismet.strings['Remove this URL'] )
32                         );
33                 }
34         });
35         $('.remove_url').live('click', function () {
36                 var thisId = $(this).attr('commentid');
37                 var data = {
38                         action: 'comment_author_deurl',
39                         _wpnonce: WPAkismet.comment_author_url_nonce,
40                         id: thisId
41                 };
42                 $.ajax({
43                         url: ajaxurl,
44                         type: 'POST',
45                         data: data,
46                         beforeSend: function () {
47                                 // Removes "x" link
48                                 $("a[commentid='"+ thisId +"']").hide();
49                                 // Show temp status
50                                 $("#author_comment_url_"+ thisId).html( $( '<span/>' ).text( WPAkismet.strings['Removing...'] ) );
51                         },
52                         success: function (response) {
53                                 if (response) {
54                                         // Show status/undo link
55                                         $("#author_comment_url_"+ thisId)
56                                                 .attr('cid', thisId)
57                                                 .addClass('akismet_undo_link_removal')
58                                                 .html(
59                                                         $( '<span/>' ).text( WPAkismet.strings['URL removed'] )
60                                                 )
61                                                 .append( ' ' )
62                                                 .append(
63                                                         $( '<span/>' )
64                                                                 .text( WPAkismet.strings['(undo)'] )
65                                                                 .addClass( 'akismet-span-link' )
66                                                 );
67                                 }
68                         }
69                 });
70
71                 return false;
72         });
73         $('.akismet_undo_link_removal').live('click', function () {
74                 var thisId = $(this).attr('cid');
75                 var thisUrl = $(this).attr('href');
76                 var data = {
77                         action: 'comment_author_reurl',
78                         _wpnonce: WPAkismet.comment_author_url_nonce,
79                         id: thisId,
80                         url: thisUrl
81                 };
82                 $.ajax({
83                         url: ajaxurl,
84                         type: 'POST',
85                         data: data,
86                         beforeSend: function () {
87                                 // Show temp status
88                                 $("#author_comment_url_"+ thisId).html( $( '<span/>' ).text( WPAkismet.strings['Re-adding...'] ) );
89                         },
90                         success: function (response) {
91                                 if (response) {
92                                         // Add "x" link
93                                         $("a[commentid='"+ thisId +"']").show();
94                                         // Show link. Core strips leading http://, so let's do that too.
95                                         $("#author_comment_url_"+ thisId).removeClass('akismet_undo_link_removal').text( thisUrl.replace( /^http:\/\/(www\.)?/ig, '' ) );
96                                 }
97                         }
98                 });
99
100                 return false;
101         });
102         $('a[id^="author_comment_url"], tr.pingback td.column-author a:first-of-type').mouseover(function () {
103                 var wpcomProtocol = ( 'https:' === location.protocol ) ? 'https://' : 'http://';
104                 // Need to determine size of author column
105                 var thisParentWidth = $(this).parent().width();
106                 // It changes based on if there is a gravatar present
107                 thisParentWidth = ($(this).parent().find('.grav-hijack').length) ? thisParentWidth - 42 + 'px' : thisParentWidth + 'px';
108                 if ($(this).find('.mShot').length == 0 && !$(this).hasClass('akismet_undo_link_removal')) {
109                         var self = $( this );
110                         $('.widefat td').css('overflow', 'visible');
111                         $(this).css('position', 'relative');
112                         var thisHref = $.URLEncode( $(this).attr('href') );
113                         $(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>');
114                         setTimeout(function () {
115                                 self.find( '.mshot-image' ).attr('src', '//s0.wordpress.com/mshots/v1/'+thisHref+'?w=450&r=2');
116                         }, 6000);
117                         setTimeout(function () {
118                                 self.find( '.mshot-image' ).attr('src', '//s0.wordpress.com/mshots/v1/'+thisHref+'?w=450&r=3');
119                         }, 12000);
120                 } else {
121                         $(this).find('.mShot').css('left', thisParentWidth).show();
122                 }
123         }).mouseout(function () {
124                 $(this).find('.mShot').hide();
125         });
126         $('.checkforspam:not(.button-disabled)').click( function(e) {
127                 $('.checkforspam:not(.button-disabled)').addClass('button-disabled');
128                 $('.checkforspam-spinner').addClass( 'spinner' );
129                 akismet_check_for_spam(0, 100);
130                 e.preventDefault();
131         });
132
133         function akismet_check_for_spam(offset, limit) {
134                 $.post(
135                         ajaxurl,
136                         {
137                                 'action': 'akismet_recheck_queue',
138                                 'offset': offset,
139                                 'limit': limit
140                         },
141                         function(result) {
142                                 if (result.processed < limit) {
143                                         window.location.reload();
144                                 }
145                                 else {
146                                         akismet_check_for_spam(offset + limit, limit);
147                                 }
148                         }
149                 );
150         }
151 });
152 // URL encode plugin
153 jQuery.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
154   while(x<c.length){var m=r.exec(c.substr(x));
155     if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
156     }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
157     o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;}
158 });