diff --git a/src/public/css/buddykit.css b/src/public/css/buddykit.css index 23da0a3..3645541 100644 --- a/src/public/css/buddykit.css +++ b/src/public/css/buddykit.css @@ -153,7 +153,7 @@ input#aw-whats-new-submit[disabled=disabled] { } /** * Video Player (Plyr) - * Needs .buddypress .buddypress-wrap, some themes overwrite bp buttons through + * Needs .buddypress .buddypress-wrap, some themes overwrite bp buttons through * this selector so we need to overwrite them. */ @@ -303,3 +303,50 @@ li.buddykit-profile-tab-list-media-item:hover a.buddykit-profile-tabs-media-dele display: block; } +/******************************** + MY UPGRADES +********************************/ + +/* + File processing - notification - styling +*/ +.buddykit-file-processing { + display: block; + text-align: center; +} +.buddykit-file-processing .loader{ + margin: 0 0 2em; + height: 100px; + width: 100%; + text-align: center; + padding: 0; + margin: 0 auto; + display: inline-block; + vertical-align: top; +} + +/* + Set the color of the loading icon +*/ +.buddykit-file-processing svg path, +.buddykit-file-processing svg rect{ + fill: #FF6700; +} + +/* + Cancel button - style disabled +*/ +.activity-update-form #whats-new-submit input#aw-whats-new-reset[disabled="disabled"], +.activity-update-form #whats-new-submit input#aw-whats-new-reset[disabled="disabled"]:hover { + color: rgba(0, 0, 0, 0.3) !important; + background-color: transparent !important; + cursor: not-allowed; +} + +/* + Activity textarea - error - no content +*/ +.activity-update-form .textarea-empty-error { + color: white !important; + background-color: red !important; +} diff --git a/src/public/js/buddykit.js b/src/public/js/buddykit.js index 74018c8..3f31f84 100644 --- a/src/public/js/buddykit.js +++ b/src/public/js/buddykit.js @@ -165,17 +165,96 @@ jQuery(document).ready(function($){ buddyKitFilesView.render(); + + ///////////////////////////////////// + // My Upgrades + //////////////////////////////////// + // Sync the files - Backbone.sync( 'read', buddyKitFiles, { - url: __buddyKit.rest_upload_uri + 'user-temporary-media', - headers: { 'X-WP-Nonce': __buddyKit.nonce }, - success: function( response ) { - if (response) { - buddyKitFiles.add(response); + function syncTheFiles(){ //I've wrapped existing code in the function so it can be called later + Backbone.sync( 'read', buddyKitFiles, { + url: __buddyKit.rest_upload_uri + 'user-temporary-media', + headers: { 'X-WP-Nonce': __buddyKit.nonce }, + success: function( response ) { + if (response) { + buddyKitFiles.add(response); + } } + }); + } + syncTheFiles(); + // Index File End == + + //////////////////////////////////////////////////////////////////////////////////////// + // On SUBMIT button click - hide Submit and Cancel buttons and display spinning loader + /////////////////////////////////////////////////////////////////////////////////////// + $(document).on('click', '#aw-whats-new-submit', function(){ + var textarea = $('#whats-new-textarea textarea'); + var text_content = textarea.val().trim(); + + + // Activity textarea must not be empty + if (text_content === '') { + // Mark - textarea as a problem + textarea.addClass('textarea-empty-error'); + + // Load and display uploaded media files again - if deleted + var chk_attached_media_files = setInterval(function(){ + if ( $('#buddykit-filelist li').length == 0 ) { + syncTheFiles(); + clearInterval(chk_attached_media_files); + } + // console.log('Checking if there are media files attached.'); + }, 250); + + return; } + + + // Unmark textarea + textarea.removeClass('textarea-empty-error'); + + + + // DISPLAY SPINNER ONLY IF THERE IS NO ERROR DETECTED BY BUDDYPRESS + + // On submit, hide Submit and Cancel buttons and display Spinner + $(this).hide(); //Hide submit button + $('#aw-whats-new-reset').hide(); //Hide cancel button + //Display spinner + $(this).after('
'); + + + var chk_submit_status = setInterval(function(){ + // CHECK IF SUBMIT BUTTON EL - REMOVED + if ( $('#aw-whats-new-submit').length == 0 ) { + // Submit button el removed + // There is no need to Hide or remove Spinner + // Becasue parent element has been removed + // and it is going to be recreated dynamically without spinner. + clearInterval(chk_submit_status); + + + // CHECK IF ERROR MESSAGE DISPLAYED + } else if($('#whats-new-form #message').length > 0){ + + // Hide spinner and Display Submit and Cancel buttons + $('#buddykit-publish-spinner').remove();// Hide or remove Spinner + $('#aw-whats-new-submit').show(); // Display submit button + $('#aw-whats-new-reset').show(); // Display cancel button + + clearInterval(chk_submit_status); + } + + // console.log('Checking submit status.'); + }, 250); + + }); - // Index File End == + + /////////////////////////////////////////////////////////////////////// + + // PlUpload Script var uploader = new plupload.Uploader({ @@ -191,7 +270,7 @@ jQuery(document).ready(function($){ { title: "Video files", extensions: "mp4" } ] }, - + unique_names: true, headers: { 'X-WP-Nonce': __buddyKit.nonce @@ -199,7 +278,7 @@ jQuery(document).ready(function($){ init: { PostInit: function() {}, FileFiltered: function(up, file) { - + var max_img_size = parseInt(__buddyKit.config.options.buddykit_field_max_image_size) * 1000000; var max_vid_size = parseInt(__buddyKit.config.options.buddykit_field_max_video_size) * 1000000; @@ -210,29 +289,31 @@ jQuery(document).ready(function($){ }); this.setOption('max_file_size', size_collection[size_collection.length-1] ); - + return; }, FilesAdded: function(up, files) { $('#buddykit-filelist-wrap').show(); - + // Filter maximum number of downloads. if ( buddyKitFiles.length >= __buddyKit.config.options.buddykit_field_max_image_number ) { alert('You have reached the allowed number of images per post.'); } else { - plupload.each( files, + plupload.each( files, function(file) { document.getElementById(__buddyKit.file_list_container_id ).innerHTML += '