Skip to content

Commit

Permalink
Update so deleting works within lightbox. Bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillip Gray committed Mar 18, 2019
1 parent df4c3b2 commit fefaf40
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
2 changes: 1 addition & 1 deletion assets/media_library.backend.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.media-library {
form.media-library {
padding: 1rem 1.8rem 0;
}

Expand Down
56 changes: 43 additions & 13 deletions assets/media_library.backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ jQuery(window).load(function () {

// Function for loading in ML content into the lightbox
function loadMediaPage(href) {
var jqxhr = $.get(href, function () {
$('.ml-lightbox-content').addClass('show-loader');
$('.ml-lightbox-content').find('#contents').remove();
});
$('.ml-lightbox-content').addClass('show-loader');
$('.ml-lightbox-content').find('#contents').remove();

var jqxhr = $.get(href);

jqxhr.done(function(data) {
var parser = new DOMParser(),
Expand All @@ -82,15 +82,35 @@ jQuery(window).load(function () {
$('.ml-lightbox-content').find('.media_library-upload, #context').remove();
$('.ml-lightbox-content').prepend(header);

if (href.indexOf('?folder=') > -1) ml_folder_path = href.split('?folder=')[1];
if (localStorage.getItem('add-to-editor') === 'yes') {
$('.ml-lightbox .ml-file .copy').text('Add to editor').addClass('add-to-editor');
}

if (getUrlParameter('folder') !== '' || getUrlParameter('folder') !== undefined) ml_folder_path = getUrlParameter('folder');

Symphony.Extensions.MediaLibrary.fileUpload.init();
Symphony.Extensions.MediaLibrary.events();
});

jqxhr.fail(function() {
jqxhr.fail(function(data) {
alert('Something went wrong. Try again.');
console.log(data);
});

function getUrlParameter(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(href);

if(results === null) {
return false;
}
else {
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
}
}

Symphony.Extensions.MediaLibrary = {
Expand Down Expand Up @@ -127,7 +147,7 @@ jQuery(window).load(function () {
});

// Backwards
$('.ml-directory-back').on('click', function () {
$('.ml-directory-back').on('click', function (e) {
var self = $(this),
// The handle to append, which is the full folder path minus the last folder
handle = ml_folder_path.replace(ml_folder_path.substring(ml_folder_path.lastIndexOf('/')), '');
Expand All @@ -138,6 +158,8 @@ jQuery(window).load(function () {
else {
window.location.href = base_url + handle;
}

return false;
});

// Forwards
Expand All @@ -155,29 +177,37 @@ jQuery(window).load(function () {
else {
window.location.href = base_url + handle;
}

return false;
});

/*
* Delete a file
*/
$('.ml-file a.delete').on('click', function () {
$('.ml-file a.delete').on('click', function (e) {
e.preventDefault();

var self = $(this),
src = self.prev('a').data('src');
check = confirm(Symphony.Language.get('Are you sure you want to delete this file? This action cannot be undone.'));
check = confirm(Symphony.Language.get('Are you sure you want to delete this file? This action cannot be undone.')),
unlink = '&unlink=' + src.replace(Symphony.Context.get('root') + '/', ''),
href = (ml_folder_path !== '' && ml_folder_path !== undefined) ? base_url + ml_folder_path + unlink : base_url + unlink;

// Only remove the files if the user is bloody well sure
if (check === true) {
if (ml_folder_path !== '' && ml_folder_path !== undefined) {
window.location.href = base_url + ml_folder_path + '&unlink=' + src.replace(Symphony.Context.get('root') + '/', '')
if ($('.ml-lightbox').length) {
loadMediaPage(href);
}
else {
window.location.href = base_url + '&unlink=' + src.replace(Symphony.Context.get('root') + '/', '')
window.location.href = href;
}
}
// Do nothing
else {

}

return false;
});

/*
Expand Down Expand Up @@ -246,7 +276,7 @@ jQuery(window).load(function () {
});

// clicking on the lightbox area should also close the lightbox
$('.ml-lightbox').on('click', function (e) {
$('.ml-lightbox').on('click', function (e) {
var container = $(this).find('> *');

// if the target of the click isn't the container, or a descendant of the container
Expand Down
4 changes: 4 additions & 0 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
</author>
</authors>
<releases>
<release version="1.0.1" date="2019-03-19" min="2.7.x">
- Update so deleting works within lightbox
- Bug fixes
</release>
<release version="1.0.0" date="2019-03-18" min="2.7.x">
- Remove unused plugins and add clipboard into extension js file for fewer requests
- Add AJAX call for page fetching
Expand Down

0 comments on commit fefaf40

Please sign in to comment.