| @@ -27,8 +27,18 @@ | ||
| 27 | 27 | $( this ).remove(); |
| 28 | 28 | return false; |
| 29 | 29 | } ); |
| 30 | 30 | |
| 31 | + $( document ).on( 'keyup', 'input#display_name', function ( e ) { | |
| 32 | + const login = $( '#user_login' ); | |
| 33 | + if ( this.value && login.data( 'original' ) === login.val() ) { | |
| 34 | + const generated_login = this.value.toLowerCase().replace( /[^a-z0-9.]+/g, '-' ).replace( /-$/, '' ).replace( /^-/, '' ); | |
| 35 | + login.val( generated_login ); | |
| 36 | + login.data( 'original', generated_login ); | |
| 37 | + } | |
| 38 | + } ); | |
| 39 | + | |
| 40 | + | |
| 31 | 41 | $( document ).on( 'click', 'a#show-details', function () { |
| 32 | 42 | $( '.details' ).toggleClass( 'hidden' ).focus(); |
| 33 | 43 | return false; |
| 34 | 44 | } ); |
| @@ -108,9 +118,9 @@ | ||
| 108 | 118 | url, |
| 109 | 119 | $( 'form#edit-rules [name^=rules]' ) |
| 110 | 120 | .add( 'form#edit-rules [name=catch_all]' ) |
| 111 | 121 | .serialize() + |
| 112 | - '&_ajax_nonce=' + | |
| 122 | + '&_wpnonce=' + | |
| 113 | 123 | $this.data( 'nonce' ) + |
| 114 | 124 | '&action=friends_preview_rules', |
| 115 | 125 | function ( response ) { |
| 116 | 126 | $( '#preview-rules' ).html( response ); |
| @@ -199,9 +209,9 @@ | ||
| 199 | 209 | |
| 200 | 210 | $( document ).on( 'click', '.delete-feed', function () { |
| 201 | 211 | // eslint-disable-next-line no-alert |
| 202 | 212 | if ( window.confirm( friends.delete_feed_question ) ) { |
| 203 | - $( this ).closest( 'tr' ).remove(); | |
| 213 | + $( this ).closest( 'li' ).remove(); | |
| 204 | 214 | } |
| 205 | 215 | return false; |
| 206 | 216 | } ); |
| 207 | 217 | |
| @@ -239,69 +249,12 @@ | ||
| 239 | 249 | .find( 'select option[value=publish]' ) |
| 240 | 250 | .prop( 'selected', true ); |
| 241 | 251 | } ); |
| 242 | 252 | |
| 243 | - $( document ).on( | |
| 244 | - 'click', | |
| 245 | - 'a.friends-auth-link, button.comments.friends-auth-link', | |
| 246 | - function () { | |
| 247 | - const $this = jQuery( this ); | |
| 248 | - const token = $this.data( 'token' ); | |
| 249 | - | |
| 250 | - if ( ! token ) { | |
| 251 | - return; | |
| 252 | - } | |
| 253 | - let href = $this.attr( 'href' ); | |
| 254 | - | |
| 255 | - const parts = token.split( /-/ ); | |
| 256 | - const now = new Date(); | |
| 257 | - if ( now / 1000 > parts[ 1 ] ) { | |
| 258 | - wp.ajax | |
| 259 | - .post( 'friends_refresh_link_token', { | |
| 260 | - _ajax_nonce: $this.data( 'nonce' ), | |
| 261 | - friend: $this.data( 'friend' ), | |
| 262 | - url: href, | |
| 263 | - } ) | |
| 264 | - .done( function ( response ) { | |
| 265 | - if ( response.data ) { | |
| 266 | - $this.data( 'token', response.data.token ); | |
| 267 | - } | |
| 268 | - } ); | |
| 269 | - | |
| 270 | - // eslint-disable-next-line no-alert | |
| 271 | - window.alert( friends.text_link_expired ); | |
| 272 | - return false; | |
| 273 | - } | |
| 274 | - | |
| 275 | - if ( href && href.indexOf( 'friend_auth=' ) < 0 ) { | |
| 276 | - let hash = href.indexOf( '#' ); | |
| 277 | - if ( hash >= 0 ) { | |
| 278 | - hash = href.substr( hash ); | |
| 279 | - href = href.substr( 0, href.length - hash.length ); | |
| 280 | - } else { | |
| 281 | - hash = ''; | |
| 282 | - } | |
| 283 | - | |
| 284 | - if ( href.indexOf( '?' ) >= 0 ) { | |
| 285 | - href += '&'; | |
| 286 | - } else { | |
| 287 | - href += '?'; | |
| 288 | - } | |
| 289 | - href += 'friend_auth=' + token + hash; | |
| 290 | - $this.attr( 'href', href ); | |
| 291 | - } | |
| 292 | - | |
| 293 | - if ( $this.is( 'button' ) ) { | |
| 294 | - window.location.href = href; | |
| 295 | - return false; | |
| 296 | - } | |
| 297 | - } | |
| 298 | - ); | |
| 299 | - | |
| 300 | 253 | $( document ).on( 'click', 'a.set-avatar', function () { |
| 301 | 254 | setAvatarUrl( |
| 302 | 255 | $( this ).find( 'img' ).prop( 'src' ), |
| 303 | - $( this ).data( 'id' ), | |
| 256 | + $( this ).data( 'user' ), | |
| 304 | 257 | $( this ).data( 'nonce' ) |
| 305 | 258 | ); |
| 306 | 259 | return false; |
| 307 | 260 | } ); |
| @@ -331,9 +284,9 @@ | ||
| 331 | 284 | }; |
| 332 | 285 | |
| 333 | 286 | $( document ).on( 'click', 'button#set-avatar-url', function () { |
| 334 | 287 | const url = $( '#new-avatar-url' ); |
| 335 | - setAvatarUrl( url.val(), url.data( 'id' ), url.data( 'nonce' ) ); | |
| 288 | + setAvatarUrl( url.val(), url.data( 'user' ), url.data( 'nonce' ) ); | |
| 336 | 289 | return false; |
| 337 | 290 | } ); |
| 338 | 291 | |
| 339 | 292 | $( document ).on( 'keyup', 'input#new-avatar-url', function ( e ) { |
| @@ -338,11 +291,70 @@ | ||
| 338 | 291 | |
| 339 | 292 | $( document ).on( 'keyup', 'input#new-avatar-url', function ( e ) { |
| 340 | 293 | const url = $( '#new-avatar-url' ); |
| 341 | 294 | if ( e.keyCode === 13 ) { |
| 342 | - setAvatarUrl( url.val(), url.data( 'id' ), url.data( 'nonce' ) ); | |
| 295 | + setAvatarUrl( url.val(), url.data( 'user' ), url.data( 'nonce' ) ); | |
| 343 | 296 | return false; |
| 344 | 297 | } |
| 298 | + } ); | |
| 299 | + | |
| 300 | + var updateDashboardWidgets = function() { | |
| 301 | + $( '.friends-dashboard-widget' ).each( function() { | |
| 302 | + const $this = $( this ); | |
| 303 | + if ( $this.find( 'li.friends-post' ).length ) { | |
| 304 | + $( '#friends-dashboard-widget' ).append( ' <i class="friends-loading"></i>' ); | |
| 305 | + } | |
| 306 | + const data = { | |
| 307 | + _ajax_nonce: $this.data( 'nonce' ), | |
| 308 | + action: 'friends_dashboard', | |
| 309 | + }; | |
| 310 | + if ( $this.data( 'friend' ) ) { | |
| 311 | + data.friend = $this.data( 'friend' ); | |
| 312 | + } | |
| 313 | + if ( $this.data( 'format' ) ) { | |
| 314 | + data.format = $this.data( 'format' ); | |
| 315 | + } | |
| 316 | + | |
| 317 | + $.post( | |
| 318 | + friends.ajax_url, | |
| 319 | + data, | |
| 320 | + function ( response ) { | |
| 321 | + if ( response.success ) { | |
| 322 | + if ( ! $this.find( 'li.friends-post' ).length ) { | |
| 323 | + $this.html( response.data ); | |
| 324 | + } else { | |
| 325 | + $( $( response.data ).find( 'li.friends-post' ).get().reverse() ).each( function () { | |
| 326 | + if ( ! document.getElementById( $( this ).attr('id') ) ) { | |
| 327 | + $this.find( 'ul' ).prepend( this ); | |
| 328 | + } | |
| 329 | + } ); | |
| 330 | + $( '.friends-dashboard-widget li.friends-post:gt(49)' ).remove(); | |
| 331 | + } | |
| 332 | + } else { | |
| 333 | + $this.find( 'i' ) | |
| 334 | + .removeClass( 'friends-loading' ) | |
| 335 | + .addClass( 'dashicons dashicons-warning' ) | |
| 336 | + .prop( 'title', response.data ); | |
| 337 | + } | |
| 338 | + } | |
| 339 | + ); | |
| 340 | + } ); | |
| 341 | + }; | |
| 342 | + if ( $( '.friends-dashboard-widget' ).length ) { | |
| 343 | + updateDashboardWidgets(); | |
| 344 | + setInterval( updateDashboardWidgets, 60000 ); | |
| 345 | + } | |
| 346 | + | |
| 347 | + $( document ).on( 'click', '#copy-api-key', function ( e ) { | |
| 348 | + e.preventDefault(); | |
| 349 | + const $this = $( this ); | |
| 350 | + const $input = $( '#api-key' ); | |
| 351 | + navigator.clipboard.writeText( $input.val() ); | |
| 352 | + $this.text( friends.copied_text ); | |
| 353 | + setTimeout( function () { | |
| 354 | + $this.text( friends.copy_text ); | |
| 355 | + }, 2000 ); | |
| 356 | + return false; | |
| 345 | 357 | } ); |
| 346 | 358 | |
| 347 | 359 | setTimeout( function () { |
| 348 | 360 | if ( $( '#fetch-feeds' ).length ) { |