Ticket #8230: 8230.patch
| File 8230.patch, 17.3 KB (added by , 6 years ago) |
|---|
-
src/bp-core/js/avatar.js
4 4 5 5 ( function( exports, $ ) { 6 6 7 // Bail if not set 7 // Bail if not set. 8 8 if ( typeof BP_Uploader === 'undefined' ) { 9 9 return; 10 10 } … … 25 25 */ 26 26 this.removeLegacyUI(); 27 27 28 // Init some vars 28 // Init some vars. 29 29 this.views = new Backbone.Collection(); 30 30 this.jcropapi = {}; 31 31 this.warning = null; 32 32 33 // Set up nav 33 // Set up nav. 34 34 this.setupNav(); 35 35 36 // Avatars are uploaded files 36 // Avatars are uploaded files. 37 37 this.avatars = bp.Uploader.filesUploaded; 38 38 39 39 // The Avatar Attachment object. 40 40 this.Attachment = new Backbone.Model(); 41 41 42 // Wait till the queue is reset 42 // Wait till the queue is reset. 43 43 bp.Uploader.filesQueue.on( 'reset', this.cropView, this ); 44 44 45 45 /** … … 56 56 }, 57 57 58 58 removeLegacyUI: function() { 59 // User 59 // User. 60 60 if ( $( '#avatar-upload-form' ).length ) { 61 61 $( '#avatar-upload' ).remove(); 62 62 $( '#avatar-upload-form p' ).remove(); 63 63 64 // Group Manage 64 // Group Manage. 65 65 } else if ( $( '#group-settings-form' ).length ) { 66 66 $( '#group-settings-form p' ).each( function( i ) { 67 67 if ( 0 !== i ) { … … 73 73 $( '#delete-group-avatar-button' ).remove(); 74 74 } 75 75 76 // Group Create 76 // Group Create. 77 77 } else if ( $( '#group-create-body' ).length ) { 78 78 $( '.main-column p #file' ).remove(); 79 79 $( '.main-column p #upload' ).remove(); 80 80 81 // Admin Extended Profile 81 // Admin Extended Profile. 82 82 } else if ( $( '#bp_xprofile_user_admin_avatar a.bp-xprofile-avatar-user-admin' ).length ) { 83 83 $( '#bp_xprofile_user_admin_avatar a.bp-xprofile-avatar-user-admin' ).remove(); 84 84 } … … 85 85 }, 86 86 87 87 setView: function( view ) { 88 // Clear views 88 // Clear views. 89 89 if ( ! _.isUndefined( this.views.models ) ) { 90 90 _.each( this.views.models, function( model ) { 91 91 model.get( 'view' ).remove(); … … 92 92 }, this ); 93 93 } 94 94 95 // Reset Views 95 // Reset Views. 96 96 this.views.reset(); 97 97 98 // Reset Avatars (file uploaded) 98 // Reset Avatars (file uploaded). 99 99 if ( ! _.isUndefined( this.avatars ) ) { 100 100 this.avatars.reset(); 101 101 } 102 102 103 // Reset the Jcrop API 103 // Reset the Jcrop API. 104 104 if ( ! _.isEmpty( this.jcropapi ) ) { 105 105 this.jcropapi.destroy(); 106 106 this.jcropapi = {}; 107 107 } 108 108 109 // Load the required view 109 // Load the required view. 110 110 switch ( view ) { 111 111 case 'upload': 112 112 this.uploaderView(); … … 119 119 }, 120 120 121 121 resetViews: function() { 122 // Reset to the uploader view 122 // Reset to the uploader view. 123 123 this.nav.trigger( 'bp-avatar-view:changed', 'upload' ); 124 124 125 // Reset to the uploader nav 125 // Reset to the uploader nav. 126 126 _.each( this.navItems.models, function( model ) { 127 127 if ( model.id === 'upload' ) { 128 128 model.set( { active: 1 } ); … … 143 143 return; 144 144 } 145 145 146 // Reset active View 146 // Reset active View. 147 147 activeView = 0; 148 148 149 149 if ( 0 === index ) { … … 163 163 this.nav = new bp.Views.Nav( { collection: this.navItems } ); 164 164 this.nav.inject( '.bp-avatar-nav' ); 165 165 166 // Activate the initial view (uploader) 166 // Activate the initial view (uploader). 167 167 this.setView( initView ); 168 168 169 // Listen to nav changes (it's like a do_action!) 169 // Listen to nav changes (it's like a do_action!). 170 170 this.nav.on( 'bp-avatar-view:changed', _.bind( this.setView, this ) ); 171 171 }, 172 172 173 173 uploaderView: function() { 174 // Listen to the Queued uploads 174 // Listen to the Queued uploads. 175 175 bp.Uploader.filesQueue.on( 'add', this.uploadProgress, this ); 176 176 177 // Create the BuddyPress Uploader 177 // Create the BuddyPress Uploader. 178 178 var uploader = new bp.Views.Uploader(); 179 179 180 // Add it to views 180 // Add it to views. 181 181 this.views.add( { id: 'upload', view: uploader } ); 182 182 183 // Display it 183 // Display it. 184 184 uploader.inject( '.bp-avatar' ); 185 185 }, 186 186 187 187 uploadProgress: function() { 188 // Create the Uploader status view 188 // Create the Uploader status view. 189 189 var avatarStatus = new bp.Views.uploaderStatus( { collection: bp.Uploader.filesQueue } ); 190 190 191 191 if ( ! _.isUndefined( this.views.get( 'status' ) ) ) { … … 194 194 this.views.add( { id: 'status', view: avatarStatus } ); 195 195 } 196 196 197 // Display it 197 // Display it. 198 198 avatarStatus.inject( '.bp-avatar-status' ); 199 199 }, 200 200 … … 201 201 cropView: function() { 202 202 var status; 203 203 204 // Bail there was an error during the Upload 204 // Bail there was an error during the Upload. 205 205 if ( _.isEmpty( this.avatars.models ) ) { 206 206 return; 207 207 } 208 208 209 // Make sure to remove the uploads status 209 // Make sure to remove the uploads status. 210 210 if ( ! _.isUndefined( this.views.get( 'status' ) ) ) { 211 211 status = this.views.get( 'status' ); 212 212 status.get( 'view' ).remove(); … … 213 213 this.views.remove( { id: 'status', view: status } ); 214 214 } 215 215 216 // Create the Avatars view 216 // Create the Avatars view. 217 217 var avatar = new bp.Views.Avatars( { collection: this.avatars } ); 218 218 this.views.add( { id: 'crop', view: avatar } ); 219 219 … … 224 224 var self = this, 225 225 crop; 226 226 227 // Remove the crop view 227 // Remove the crop view. 228 228 if ( ! _.isUndefined( this.views.get( 'crop' ) ) ) { 229 // Remove the JCrop API 229 // Remove the JCrop API. 230 230 if ( ! _.isEmpty( this.jcropapi ) ) { 231 231 this.jcropapi.destroy(); 232 232 this.jcropapi = {}; … … 261 261 262 262 avatarStatus.inject( '.bp-avatar-status' ); 263 263 264 // Update each avatars of the page 264 // Update each avatars of the page. 265 265 $( '.' + avatar.get( 'object' ) + '-' + response.item_id + '-avatar' ).each( function() { 266 266 $(this).prop( 'src', response.avatar ); 267 267 } ); 268 268 269 // Inject the Delete nav 269 // Inject the Delete nav. 270 270 bp.Avatar.navItems.get( 'delete' ).set( { hide: 0 } ); 271 271 272 272 /** … … 304 304 }, 305 305 306 306 deleteView:function() { 307 // Create the delete model 307 // Create the delete model. 308 308 var delete_model = new Backbone.Model( _.pick( BP_Uploader.settings.defaults.multipart_params.bp_params, 309 309 'object', 310 310 'item_id', … … 311 311 'nonces' 312 312 ) ); 313 313 314 // Create the delete view 314 // Create the delete view. 315 315 var deleteView = new bp.Views.DeleteAvatar( { model: delete_model } ); 316 316 317 // Add it to views 317 // Add it to views. 318 318 this.views.add( { id: 'delete', view: deleteView } ); 319 319 320 // Display it 320 // Display it. 321 321 deleteView.inject( '.bp-avatar' ); 322 322 }, 323 323 … … 325 325 var self = this, 326 326 deleteView; 327 327 328 // Remove the delete view 328 // Remove the delete view. 329 329 if ( ! _.isUndefined( this.views.get( 'delete' ) ) ) { 330 330 deleteView = this.views.get( 'delete' ); 331 331 deleteView.get( 'view' ).remove(); … … 351 351 352 352 avatarStatus.inject( '.bp-avatar-status' ); 353 353 354 // Update each avatars of the page 354 // Update each avatars of the page. 355 355 $( '.' + model.get( 'object' ) + '-' + response.item_id + '-avatar').each( function() { 356 356 $( this ).prop( 'src', response.avatar ); 357 357 } ); 358 358 359 // Remove the Delete nav 359 // Remove the Delete nav. 360 360 bp.Avatar.navItems.get( 'delete' ).set( { active: 0, hide: 1 } ); 361 361 362 362 /** 363 * Reset the Attachment object 363 * Reset the Attachment object. 364 364 * 365 365 * You can run extra actions once the avatar is set using: 366 366 * bp.Avatar.Attachment.on( 'change:url', function( data ) { your code } ); … … 410 410 } 411 411 }; 412 412 413 // Main Nav view 413 // Main Nav view. 414 414 bp.Views.Nav = bp.View.extend( { 415 415 tagName: 'ul', 416 416 className: 'avatar-nav-items', … … 422 422 initialize: function() { 423 423 var hasAvatar = _.findWhere( this.collection.models, { id: 'delete' } ); 424 424 425 // Display a message to inform about the delete tab 425 // Display a message to inform about the delete tab. 426 426 if ( 1 !== hasAvatar.get( 'hide' ) ) { 427 427 bp.Avatar.displayWarning( BP_Uploader.strings.has_avatar_warning ); 428 428 } … … 434 434 addNavItem: function( item ) { 435 435 /** 436 436 * The delete nav is not added if no avatar 437 * is set for the object 437 * is set for the object. 438 438 */ 439 439 if ( 1 === item.get( 'hide' ) ) { 440 440 return; … … 455 455 view.remove(); 456 456 } 457 457 458 // Check to see if the nav is not already rendered 458 // Check to see if the nav is not already rendered. 459 459 if ( item.get( 'id' ) === view.model.get( 'id' ) ) { 460 460 isRendered = true; 461 461 } 462 462 } ); 463 463 464 // Add the Delete nav if not rendered 464 // Add the Delete nav if not rendered. 465 465 if ( ! _.isBoolean( isRendered ) ) { 466 466 this.addNavItem( item ); 467 467 } … … 470 470 toggleView: function( event ) { 471 471 event.preventDefault(); 472 472 473 // First make sure to remove all warnings 473 // First make sure to remove all warnings. 474 474 bp.Avatar.removeWarning(); 475 475 476 476 var active = $( event.target ).data( 'nav' ); … … 486 486 } 487 487 } ); 488 488 489 // Nav item view 489 // Nav item view. 490 490 bp.Views.NavItem = bp.View.extend( { 491 491 tagName: 'li', 492 492 className: 'avatar-nav-item', … … 510 510 } 511 511 } ); 512 512 513 // Avatars view 513 // Avatars view. 514 514 bp.Views.Avatars = bp.View.extend( { 515 515 className: 'items', 516 516 … … 519 519 }, 520 520 521 521 addItemView: function( item ) { 522 // Defaults to 150 522 // Defaults to 150. 523 523 var full_d = { full_h: 150, full_w: 150 }; 524 524 525 // Make sure to take in account bp_core_avatar_full_height or bp_core_avatar_full_width php filters 525 // Make sure to take in account bp_core_avatar_full_height or bp_core_avatar_full_width php filters. 526 526 if ( ! _.isUndefined( BP_Uploader.settings.crop.full_h ) && ! _.isUndefined( BP_Uploader.settings.crop.full_w ) ) { 527 527 full_d.full_h = BP_Uploader.settings.crop.full_h; 528 528 full_d.full_w = BP_Uploader.settings.crop.full_w; 529 529 } 530 530 531 // Set the avatar model 531 // Set the avatar model. 532 532 item.set( _.extend( _.pick( BP_Uploader.settings.defaults.multipart_params.bp_params, 533 533 'object', 534 534 'item_id', … … 535 535 'nonces' 536 536 ), full_d ) ); 537 537 538 // Add the view 538 // Add the view. 539 539 this.views.add( new bp.Views.Avatar( { model: item } ) ); 540 540 } 541 541 } ); 542 542 543 // Avatar view 543 // Avatar view. 544 544 bp.Views.Avatar = bp.View.extend( { 545 545 className: 'item', 546 546 template: bp.template( 'bp-avatar-item' ), … … 556 556 aspectRatio : 1 557 557 } ); 558 558 559 // Display a warning if the image is smaller than minimum advised 559 // Display a warning if the image is smaller than minimum advised. 560 560 if ( false !== this.model.get( 'feedback' ) ) { 561 561 bp.Avatar.displayWarning( this.model.get( 'feedback' ) ); 562 562 } … … 600 600 crop_bottom = nh + crop_top; 601 601 } 602 602 603 // Add the cropping interface 603 // Add the cropping interface. 604 604 tocrop.Jcrop( { 605 605 onChange: _.bind( self.showPreview, self ), 606 606 onSelect: _.bind( self.showPreview, self ), … … 607 607 aspectRatio: self.options.aspectRatio, 608 608 setSelect: [ crop_left, crop_top, crop_right, crop_bottom ] 609 609 }, function() { 610 // Get the Jcrop API 610 // Get the Jcrop API. 611 611 bp.Avatar.jcropapi = this; 612 612 } ); 613 613 }, … … 629 629 var rx = fw / coords.w; 630 630 var ry = fh / coords.h; 631 631 632 // Update the model 632 // Update the model. 633 633 this.model.set( { x: coords.x, y: coords.y, w: coords.w, h: coords.h } ); 634 634 635 635 $( '#avatar-crop-preview' ).css( { … … 643 643 } 644 644 } ); 645 645 646 // BuddyPress Avatar Feedback view 646 // BuddyPress Avatar Feedback view. 647 647 bp.Views.AvatarStatus = bp.View.extend( { 648 648 tagName: 'p', 649 649 className: 'updated', -
src/bp-core/js/bp-api-request.js
8 8 window.bp = window.bp || {}; 9 9 10 10 ( function( wp, bp, $ ) { 11 // Bail if not set 11 // Bail if not set. 12 12 if ( typeof bpApiSettings === 'undefined' ) { 13 13 return; 14 14 } … … 15 15 16 16 bp.isRestEnabled = true; 17 17 18 // Polyfill wp.apiRequest if WordPress < 4.9 18 // Polyfill wp.apiRequest if WordPress < 4.9. 19 19 bp.apiRequest = function( options ) { 20 20 var bpRequest; 21 21 -
src/bp-core/js/bp-plupload.js
5 5 6 6 ( function( exports, $ ) { 7 7 8 // Bail if not set 8 // Bail if not set. 9 9 if ( typeof BP_Uploader === 'undefined' ) { 10 10 return; 11 11 } … … 17 17 */ 18 18 _.extend( bp, _.pick( wp, 'Backbone', 'ajax', 'template' ) ); 19 19 20 // Init Models, Collections, Views and the BuddyPress Uploader 20 // Init Models, Collections, Views and the BuddyPress Uploader. 21 21 bp.Models = bp.Models || {}; 22 22 bp.Collections = bp.Collections || {}; 23 23 bp.Views = bp.Views || {}; … … 26 26 /** 27 27 * BuddyPress Uploader. 28 28 * 29 * This is an adapted version of wp.Uploader 29 * This is an adapted version of wp.Uploader. 30 30 */ 31 31 bp.Uploader.uploader = function() { 32 32 var self = this, … … 47 47 return; 48 48 } 49 49 50 // Make sure flash sends cookies (seems in IE it does without switching to urlstream mode) 50 // Make sure flash sends cookies (seems in IE it does without switching to urlstream mode). 51 51 if ( ! isIE && 'flash' === plupload.predictRuntime( this.params.defaults ) && 52 52 ( ! this.params.defaults.required_features || ! this.params.defaults.required_features.hasOwnProperty( 'send_binary_string' ) ) ) { 53 53 … … 97 97 98 98 } ); 99 99 100 // See https://core.trac.wordpress.org/ticket/37039 100 // See https://core.trac.wordpress.org/ticket/37039. 101 101 this.uploader.bind( 'postinit', function( up ) { 102 102 up.refresh(); 103 103 }); 104 104 105 // Init BuddyPress Uploader 105 // Init BuddyPress Uploader. 106 106 this.uploader.init(); 107 107 108 108 /** … … 109 109 * Feedback callback. 110 110 * 111 111 * Add a new message to the errors collection, so it's possible 112 * to give some feedback to the user 112 * to give some feedback to the user. 113 113 * 114 114 * @param {string} message 115 115 * @param {object} data … … 140 140 141 141 /** 142 142 * In case the multiple selection is false (eg: avatar) stop the process and send 143 * and event containing a warning 143 * and event containing a warning. 144 144 */ 145 145 if ( ! uploader.settings.multi_selection && files.length > 1 ) { 146 146 for ( var i in files ) { … … 181 181 } ); 182 182 183 183 /** 184 * Update each file item on progress 184 * Update each file item on progress. 185 185 * 186 186 * @event UploadProgress 187 187 * @param {plupload.Uploader} uploader Uploader instance. … … 225 225 226 226 file.item.set( _.extend( response.data, { uploading: false } ) ); 227 227 228 // Add the file to the Uploaded ones 228 // Add the file to the Uploaded ones. 229 229 bp.Uploader.filesUploaded.add( file.item ); 230 230 231 231 } ); 232 232 233 233 /** 234 * Trigger an event to inform a new upload is being processed 234 * Trigger an event to inform a new upload is being processed. 235 235 * 236 * Mainly used to remove an eventual warning 236 * Mainly used to remove an eventual warning. 237 237 * 238 238 * @event BeforeUpload 239 239 * @param {plupload.Uploader} uploader Uploader instance. … … 244 244 } ); 245 245 246 246 /** 247 * Reset the filesQueue once the upload is complete 247 * Reset the filesQueue once the upload is complete. 248 248 * 249 249 * @event BeforeUpload 250 250 * @param {plupload.Uploader} uploader Uploader instance. … … 256 256 } ); 257 257 258 258 /** 259 * Map Plupload errors & Create a warning when plupload failed 259 * Map Plupload errors & Create a warning when plupload failed. 260 260 * 261 261 * @event Error 262 262 * @param {plupload.Uploader} uploader Uploader instance. … … 291 291 } ); 292 292 }; 293 293 294 // Create a very generic Model for files 294 // Create a very generic Model for files. 295 295 bp.Models.File = Backbone.Model.extend( { 296 296 file: {} 297 297 } ); 298 298 299 // Add Collections to store queue, uploaded files and errors 299 // Add Collections to store queue, uploaded files and errors. 300 300 $.extend( bp.Uploader, { 301 301 filesQueue : new Backbone.Collection(), 302 302 filesUploaded : new Backbone.Collection(), … … 303 303 filesError : new Backbone.Collection() 304 304 } ); 305 305 306 // Extend wp.Backbone.View with .prepare() and .inject() 306 // Extend wp.Backbone.View with .prepare() and .inject(). 307 307 bp.View = bp.Backbone.View.extend( { 308 308 inject: function( selector ) { 309 309 this.render(); … … 320 320 } 321 321 } ); 322 322 323 // BuddyPress Uploader main view 323 // BuddyPress Uploader main view. 324 324 bp.Views.Uploader = bp.View.extend( { 325 325 className: 'bp-uploader-window', 326 326 template: bp.template( 'upload-window' ), … … 358 358 return; 359 359 } 360 360 361 // Remove all warning views 361 // Remove all warning views. 362 362 _.each( this.warnings, function( view ) { 363 363 view.remove(); 364 364 } ); 365 365 366 // Reset Warnings 366 // Reset Warnings. 367 367 this.warnings = []; 368 368 } 369 369 } ); 370 370 371 // BuddyPress Uploader warning view 371 // BuddyPress Uploader warning view. 372 372 bp.Views.uploaderWarning = bp.View.extend( { 373 373 tagName: 'p', 374 374 className: 'warning', … … 383 383 } 384 384 } ); 385 385 386 // BuddyPress Uploader Files view 386 // BuddyPress Uploader Files view. 387 387 bp.Views.uploaderStatus = bp.View.extend( { 388 388 className: 'files', 389 389 … … 410 410 } 411 411 } ); 412 412 413 // BuddyPress Uploader File progress view 413 // BuddyPress Uploader File progress view. 414 414 bp.Views.uploaderProgress = bp.View.extend( { 415 415 className: 'bp-uploader-progress', 416 416 template: bp.template( 'progress-window' )