HEX
Server: Apache/2.4.59 (Debian)
System: Linux emory.shared.1984.is 6.1.0-27-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.115-1 (2024-11-01) x86_64
User: u11574 (1020)
PHP: 7.4.33
Disabled: exec,system,passthru,shell_exec,popen,show_source,shell,symlink,proc_open,pcntl_exec,pcntl_fork,pcntl_wait,pcntl_alarm,pcntl_signal,pcntl_signal_dispatch,pcntl_getpriority,proc_get_status,expect_popen,dl,putenv,mail
Upload Files
File: /var/www/virtual/mariaellingsen.com/htdocs/wp-content/plugins/soliloquy/assets/js/media-insert.js
/**
 * Creates and handles a wp.media instance for soliloquy Galleries, allowing
 * the user to insert images from the Media Library into their Gallery
 */
jQuery(document).ready(function ($) {
	// Add Images
	$('a.soliloquy-media-library').on('click', function (e) {
		// Prevent default action
		e.preventDefault();

		// If the wp.media.frames.soliloquy instance already exists, reopen it
		if (wp.media.frames.soliloquy) {
			wp.media.frames.soliloquy.open();

			return;
		} else {
			// Create the wp.media.frames.soliloquy instance (one time)
			wp.media.frames.soliloquy = wp.media({
				frame: 'post',
				title: wp.media.view.l10n.insertIntoPost,
				library: {
					type: ['image'],
				},
				button: {
					text: wp.media.view.l10n.insertIntoPost,
				},
				multiple: true,
			});
		}

		// Mark existing Gallery images as selected when the modal is opened
		wp.media.frames.soliloquy.on('open', function () {
			// Get any previously selected images
			var selection = wp.media.frames.soliloquy
				.state()
				.get('selection');

			if (typeof selection !== 'undefined') {
				// Get images that already exist in the gallery, and select each one in the modal
				$('ul#soliloquy-output li').each(function () {
					var attachment = wp.media.attachment(
						$(this).attr('id'),
					);

					selection.add(attachment ? [attachment] : []);
				});
			}
		});

		//Trigger Event when the frame is ready.
		wp.media.frames.soliloquy.on('ready', function (e) {});
		// Insert into Gallery Button Clicked
		wp.media.frames.soliloquy.on('insert', function (selection) {
			// Get state
			var state = wp.media.frames.soliloquy.state(),
				images = [];

			// Iterate through selected images, building an images array
			selection.each(function (attachment) {
				// Get the chosen options for this image (size, alignment, link type, link URL)
				var display = state.display(attachment).toJSON(),
					type = attachment.get('type');

				// Change the image link parameter based on the "Link To" setting the user chose in the media view
				switch (display.link) {
					case 'none':
						attachment.set('link', '');
						break;
					case 'file':
						attachment.set('link', attachment.get('url'));
						break;
					case 'post':
						// Already linked to post by default
						break;
					case 'custom':
						attachment.set('link', display.linkUrl);
						break;
				}

				//Only allow images selections to be inserted
				if (type === 'image') {
					// Add the image to the images array
					images.push(attachment.toJSON());
				}
			}, this);
			// Send the ajax request with our data to be processed.
			$.post(
				soliloquy_metabox.ajax,
				{
					action: 'soliloquy_insert_slides',
					nonce: soliloquy_metabox.insert_nonce,
					post_id: soliloquy_metabox.id,
					images: JSON.stringify(images),
				},
				function (response) {
					// Response should be a JSON success with the HTML for the image grid
					if (response) {
						// Set the image grid to the HTML we received
						$('#soliloquy-output').html(response.data);

						// Repopulate the Soliloquy Slide Collection
						SoliloquySlidesUpdate();

						$(document).trigger('insertSlides');
					}
				},
				'json',
			);
		});

		// Open the media frame
		wp.media.frames.soliloquy.open();
		// Remove the 'Create Gallery' left hand menu item in the modal, as we don't
		// want users inserting galleries!
		// Remove the 'Create Gallery' left hand menu item in the modal, as we don't
		// want users inserting galleries!
		$('div.media-menu #menu-item-gallery').css('display', 'none');
		$('div.media-menu #menu-item-embed').css('display', 'none');
		$('div.media-menu #menu-item-playlist').css('display', 'none');
		$('div.media-menu #menu-item-video-playlist').css('display', 'none');
		$('div.media-menu #menu-item-featured-image').css('display', 'none');

		return;
	});
});