HEX
Server: Apache
System: Linux p3plzcpnl507418.prod.phx3.secureserver.net 4.18.0-553.141.2.lve.el8.x86_64 #1 SMP Wed Jul 8 16:10:02 UTC 2026 x86_64
User: retoti4c1e1s (10075650)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /home/retoti4c1e1s/public_html/thecommitment.earth/wp-content/themes/save-life/js/_admin.js
/* global jQuery:false */
/* global SAVE_LIFE_STORAGE:false */

jQuery(document).ready(function() {
	"use strict";

	// Init Media manager variables
	SAVE_LIFE_STORAGE['media_id'] = '';
	SAVE_LIFE_STORAGE['media_frame'] = [];
	SAVE_LIFE_STORAGE['media_link'] = [];
	jQuery('.save_life_media_selector').on('click', function(e) {
		save_life_show_media_manager(this);
		e.preventDefault();
		return false;
	});
	
	// Hide empty options-overrides
	jQuery('.postbox > .inside').each(function() {
		if (jQuery(this).html().length < 5) jQuery(this).parent().hide();
	});

	// Hide admin notice
	jQuery('#save_life_admin_notice .save_life_hide_notice').on('click', function(e) {
		jQuery('#save_life_admin_notice').slideUp();
		jQuery.post( SAVE_LIFE_STORAGE['ajax_url'], {'action': 'save_life_hide_admin_notice'}, function(response){});
		e.preventDefault();
		return false;
	});
	
	// TGMPA Source selector is changed
	jQuery('.tgmpa_source_file').on('change', function(e) {
		var chk = jQuery(this).parents('tr').find('>th>input[type="checkbox"]');
		if (chk.length == 1) {
			if (jQuery(this).val() != '')
				chk.attr('checked', 'checked');
			else
				chk.removeAttr('checked');
		}
	});
		
	// Add icon selector after the menu item classes field
	jQuery('.edit-menu-item-classes').each(function() {
		var icon = save_life_get_icon_class(jQuery(this).val());
		jQuery(this).after('<span class="save_life_list_icons_selector'+(icon ? ' '+icon : '')+'" title="'+SAVE_LIFE_STORAGE['icon_selector_msg']+'"></span>');
	});
	jQuery('.save_life_list_icons_selector').on('click', function(e) {
		var input_id = jQuery(this).prev().attr('id');
		var list = jQuery('.save_life_list_icons');
		if (list.length > 0) {
			list.find('span.save_life_list_active').removeClass('save_life_list_active');
			var icon = save_life_get_icon_class(jQuery(this).attr('class'));
			if (icon != '') list.find('span[class*="'+icon+'"]').addClass('save_life_list_active');
			var pos = jQuery(this).offset();
			list.data('input_id', input_id).css({'left': pos.left, 'top': pos.top}).fadeIn();
		}
		e.preventDefault();
		return false;
	});
	jQuery('.save_life_list_icons span').on('click', function(e) {
		var list = jQuery(this).parent().fadeOut();
		var icon = save_life_alltrim(jQuery(this).attr('class').replace(/save_life_list_active/, ''));
		var input = jQuery('#'+list.data('input_id'));
		input.val(save_life_chg_icon_class(input.val(), icon));
		var selector = input.next();
		selector.attr('class', save_life_chg_icon_class(selector.attr('class'), icon));
		e.preventDefault();
		return false;
	});

	// Standard WP Color Picker
	if (jQuery('.save_life_color_selector').length > 0) {
		jQuery('.save_life_color_selector').wpColorPicker({
			// you can declare a default color here,
			// or in the data-default-color attribute on the input
			//defaultColor: false,
	
			// a callback to fire whenever the color changes to a valid color
			change: function(e, ui){
				jQuery(e.target).val(ui.color).trigger('change');
			},
	
			// a callback to fire when the input is emptied or an invalid color
			clear: function(e) {
				jQuery(e.target).prev().trigger('change')
			},
	
			// hide the color picker controls on load
			//hide: true,
	
			// show a group of common colors beneath the square
			// or, supply an array of colors to customize further
			//palettes: true
		});
	}

	function save_life_chg_icon_class(classes, icon) {
		var chg = false;
		classes = save_life_alltrim(classes).split(' ');
		for (var i=0; i<classes.length; i++) {
			if (classes[i].indexOf('icon-') >= 0) {
				classes[i] = icon;
				chg = true;
				break;
			}
		}
		if (!chg) {
			if (classes.length == 1 && classes[0] == '')
				classes[0] = icon;
			else
				classes.push(icon);
		}
		return classes.join(' ');
	}

	function save_life_get_icon_class(classes) {
		var classes = save_life_alltrim(classes).split(' ');
		var icon = '';
		for (var i=0; i<classes.length; i++) {
			if (classes[i].indexOf('icon-') >= 0) {
				icon = classes[i];
				break;
			}
		}
		return icon;
	}

	function save_life_show_media_manager(el) {
		SAVE_LIFE_STORAGE['media_id'] = jQuery(el).attr('id');
		SAVE_LIFE_STORAGE['media_link'][SAVE_LIFE_STORAGE['media_id']] = jQuery(el);
		// If the media frame already exists, reopen it.
		if ( SAVE_LIFE_STORAGE['media_frame'][SAVE_LIFE_STORAGE['media_id']] ) {
			SAVE_LIFE_STORAGE['media_frame'][SAVE_LIFE_STORAGE['media_id']].open();
			return false;
		}
		// Create the media frame.
		SAVE_LIFE_STORAGE['media_frame'][SAVE_LIFE_STORAGE['media_id']] = wp.media({
			// Popup layout (if comment next row - hide filters and image sizes popups)
			frame: 'post',
			// Set the title of the modal.
			title: SAVE_LIFE_STORAGE['media_link'][SAVE_LIFE_STORAGE['media_id']].data('choose'),
			// Tell the modal to show only images.
			library: {
				type: SAVE_LIFE_STORAGE['media_link'][SAVE_LIFE_STORAGE['media_id']].data('type') ? SAVE_LIFE_STORAGE['media_link'][SAVE_LIFE_STORAGE['media_id']].data('type') : 'image'
			},
			// Multiple choise
			multiple: SAVE_LIFE_STORAGE['media_link'][SAVE_LIFE_STORAGE['media_id']].data('multiple')===true ? 'add' : false,
			// Customize the submit button.
			button: {
				// Set the text of the button.
				text: SAVE_LIFE_STORAGE['media_link'][SAVE_LIFE_STORAGE['media_id']].data('update'),
				// Tell the button not to close the modal, since we're
				// going to refresh the page when the image is selected.
				close: true
			}
		});
		// When an image is selected, run a callback.
		SAVE_LIFE_STORAGE['media_frame'][SAVE_LIFE_STORAGE['media_id']].on( 'insert select', function(selection) {
			// Grab the selected attachment.
			var field = jQuery("#"+SAVE_LIFE_STORAGE['media_link'][SAVE_LIFE_STORAGE['media_id']].data('linked-field')).eq(0);
			var attachment = null, attachment_url = '';
			if (SAVE_LIFE_STORAGE['media_link'][SAVE_LIFE_STORAGE['media_id']].data('multiple')===true) {
				SAVE_LIFE_STORAGE['media_frame'][SAVE_LIFE_STORAGE['media_id']].state().get('selection').map( function( att ) {
					attachment_url += (attachment_url ? "\n" : "") + att.toJSON().url;
				});
				var val = field.val();
				attachment_url = val + (val ? "\n" : '') + attachment_url;
			} else {
				attachment = SAVE_LIFE_STORAGE['media_frame'][SAVE_LIFE_STORAGE['media_id']].state().get('selection').first().toJSON();
				attachment_url = attachment.url;
				var sizes_selector = jQuery('.media-modal-content .attachment-display-settings select.size');
				if (sizes_selector.length > 0) {
					var size = save_life_get_listbox_selected_value(sizes_selector.get(0));
					if (size != '') attachment_url = attachment.sizes[size].url;
				}
			}
			field.val(attachment_url);
			if (attachment_url.indexOf('.jpg') > 0 || attachment_url.indexOf('.png') > 0 || attachment_url.indexOf('.gif') > 0) {
				var preview = field.siblings('.save_life_options_override_field_preview');
				if (preview.length != 0) {
					if (preview.find('img').length == 0)
						preview.append('<img src="'+attachment_url+'">');
					else 
						preview.find('img').attr('src', attachment_url);
				} else {
					preview = field.siblings('img');
					if (preview.length != 0)
						preview.attr('src', attachment_url);
				}
			}
			field.trigger('change');
		});
		// Finally, open the modal.
		SAVE_LIFE_STORAGE['media_frame'][SAVE_LIFE_STORAGE['media_id']].open();
		return false;
	}

});