PHP 8.2.31
Preview: customize-models.js Size: 6.66 KB
//proc/self/root/var/softaculous/sitepad/editor/site-inc/js/customize-models.js

/**
 * @output wp-includes/js/customize-models.js
 */

/* global _wpCustomizeHeader */
(function( $, wp ) {
	var api = wp.customize;
	/** @namespace wp.customize.HeaderTool */
	api.HeaderTool = {};


	/**
	 * wp.customize.HeaderTool.ImageModel
	 *
	 * A header image. This is where saves via the Customizer API are
	 * abstracted away, plus our own AJAX calls to add images to and remove
	 * images from the user's recently uploaded images setting on the server.
	 * These calls are made regardless of whether the user actually saves new
	 * Customizer settings.
	 *
	 * @memberOf wp.customize.HeaderTool
	 * @alias wp.customize.HeaderTool.ImageModel
	 *
	 * @constructor
	 * @augments Backbone.Model
	 */
	api.HeaderTool.ImageModel = Backbone.Model.extend(/** @lends wp.customize.HeaderTool.ImageModel.prototype */{
		defaults: function() {
			return {
				header: {
					attachment_id: 0,
					url: '',
					timestamp: _.now(),
					thumbnail_url: ''
				},
				choice: '',
				selected: false,
				random: false
			};
		},

		initialize: function() {
			this.on('hide', this.hide, this);
		},

		hide: function() {
			this.set('choice', '');
			api('header_image').set('remove-header');
			api('header_image_data').set('remove-header');
		},

		destroy: function() {
			var data = this.get('header'),
				curr = api.HeaderTool.currentHeader.get('header').attachment_id;

			// If the image we're removing is also the current header, unset
			// the latter
			if (curr && data.attachment_id === curr) {
				api.HeaderTool.currentHeader.trigger('hide');
			}

			wp.ajax.post( 'custom-header-remove', {
				nonce: _wpCustomizeHeader.nonces.remove,
				wp_customize: 'on',
				theme: api.settings.theme.stylesheet,
				attachment_id: data.attachment_id
			});

			this.trigger('destroy', this, this.collection);
		},

		save: function() {
			if (this.get('random')) {
				api('header_image').set(this.get('header').random);
				api('header_image_data').set(this.get('header').random);
			} else {
				if (this.get('header').defaultName) {
					api('header_image').set(this.get('header').url);
					api('header_image_data').set(this.get('header').defaultName);
				} else {
					api('header_image').set(this.get('header').url);
					api('header_image_data').set(this.get('header'));
				}
			}

			api.HeaderTool.combinedList.trigger('control:setImage', this);
		},

		importImage: function() {
			var data = this.get('header');
			if (data.attachment_id === undefined) {
				return;
			}

			wp.ajax.post( 'custom-header-add', {
				nonce: _wpCustomizeHeader.nonces.add,
				wp_customize: 'on',
				theme: api.settings.theme.stylesheet,
				attachment_id: data.attachment_id
			} );
		},

		shouldBeCropped: function() {
			if (this.get('themeFlexWidth') === true &&
						this.get('themeFlexHeight') === true) {
				return false;
			}

			if (this.get('themeFlexWidth') === true &&
				this.get('themeHeight') === this.get('imageHeight')) {
				return false;
			}

			if (this.get('themeFlexHeight') === true &&
				this.get('themeWidth') === this.get('imageWidth')) {
				return false;
			}

			if (this.get('themeWidth') === this.get('imageWidth') &&
				this.get('themeHeight') === this.get('imageHeight')) {
				return false;
			}

			if (this.get('imageWidth') <= this.get('themeWidth')) {
				return false;
			}

			return true;
		}
	});


	/**
	 * wp.customize.HeaderTool.ChoiceList
	 *
	 * @memberOf wp.customize.HeaderTool
	 * @alias wp.customize.HeaderTool.ChoiceList
	 *
	 * @constructor
	 * @augments Backbone.Collection
	 */
	api.HeaderTool.ChoiceList = Backbone.Collection.extend({
		model: api.HeaderTool.ImageModel,

		// Ordered from most recently used to least
		comparator: function(model) {
			return -model.get('header').timestamp;
		},

		initialize: function() {
			var current = api.HeaderTool.currentHeader.get('choice').replace(/^https?:\/\//, ''),
				isRandom = this.isRandomChoice(api.get().header_image);

			// Overridable by an extending class
			if (!this.type) {
				this.type = 'uploaded';
			}

			// Overridable by an extending class
			if (typeof this.data === 'undefined') {
				this.data = _wpCustomizeHeader.uploads;
			}

			if (isRandom) {
				// So that when adding data we don't hide regular images
				current = api.get().header_image;
			}

			this.on('control:setImage', this.setImage, this);
			this.on('control:removeImage', this.removeImage, this);
			this.on('add', this.maybeRemoveOldCrop, this);
			this.on('add', this.maybeAddRandomChoice, this);

			_.each(this.data, function(elt, index) {
				if (!elt.attachment_id) {
					elt.defaultName = index;
				}

				if (typeof elt.timestamp === 'undefined') {
					elt.timestamp = 0;
				}

				this.add({
					header: elt,
					choice: elt.url.split('/').pop(),
					selected: current === elt.url.replace(/^https?:\/\//, '')
				}, { silent: true });
			}, this);

			if (this.size() > 0) {
				this.addRandomChoice(current);
			}
		},

		maybeRemoveOldCrop: function( model ) {
			var newID = model.get( 'header' ).attachment_id || false,
			 	oldCrop;

			// Bail early if we don't have a new attachment ID.
			if ( ! newID ) {
				return;
			}

			oldCrop = this.find( function( item ) {
				return ( item.cid !== model.cid && item.get( 'header' ).attachment_id === newID );
			} );

			// If we found an old crop, remove it from the collection.
			if ( oldCrop ) {
				this.remove( oldCrop );
			}
		},

		maybeAddRandomChoice: function() {
			if (this.size() === 1) {
				this.addRandomChoice();
			}
		},

		addRandomChoice: function(initialChoice) {
			var isRandomSameType = RegExp(this.type).test(initialChoice),
				randomChoice = 'random-' + this.type + '-image';

			this.add({
				header: {
					timestamp: 0,
					random: randomChoice,
					width: 245,
					height: 41
				},
				choice: randomChoice,
				random: true,
				selected: isRandomSameType
			});
		},

		isRandomChoice: function(choice) {
			return (/^random-(uploaded|default)-image$/).test(choice);
		},

		shouldHideTitle: function() {
			return this.size() < 2;
		},

		setImage: function(model) {
			this.each(function(m) {
				m.set('selected', false);
			});

			if (model) {
				model.set('selected', true);
			}
		},

		removeImage: function() {
			this.each(function(m) {
				m.set('selected', false);
			});
		}
	});


	/**
	 * wp.customize.HeaderTool.DefaultsList
	 *
	 * @memberOf wp.customize.HeaderTool
	 * @alias wp.customize.HeaderTool.DefaultsList
	 *
	 * @constructor
	 * @augments wp.customize.HeaderTool.ChoiceList
	 * @augments Backbone.Collection
	 */
	api.HeaderTool.DefaultsList = api.HeaderTool.ChoiceList.extend({
		initialize: function() {
			this.type = 'default';
			this.data = _wpCustomizeHeader.defaults;
			api.HeaderTool.ChoiceList.prototype.initialize.apply(this);
		}
	});

})( jQuery, window.wp );

Directory Contents

Dirs: 10 × Files: 97

Name Size Perms Modified Actions
- drwxr-xr-x 2026-04-25 02:31:39
Edit Download
crop DIR
- drwxr-xr-x 2026-04-25 02:31:39
Edit Download
dist DIR
- drwxr-xr-x 2026-04-25 02:31:39
Edit Download
- drwxr-xr-x 2026-04-25 02:31:39
Edit Download
jquery DIR
- drwxr-xr-x 2026-04-25 02:31:39
Edit Download
- drwxr-xr-x 2026-04-25 02:31:39
Edit Download
plupload DIR
- drwxr-xr-x 2026-04-25 02:31:39
Edit Download
swfupload DIR
- drwxr-xr-x 2026-04-25 02:31:39
Edit Download
thickbox DIR
- drwxr-xr-x 2026-04-25 02:31:39
Edit Download
tinymce DIR
- drwxr-xr-x 2026-04-25 02:31:39
Edit Download
2.59 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
771 B lrw-r--r-- 2026-04-22 07:17:42
Edit Download
20.83 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
5.51 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
70.54 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
21.94 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
28.40 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
16.28 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
9.84 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
2.18 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
25.08 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
7.77 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
7.71 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
3.44 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
6.66 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
3.60 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
14.67 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
4.93 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
22.61 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
7.71 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
27.31 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
10.65 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
32.54 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
10.56 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
4.95 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
2.37 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
22.62 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
5.88 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
4.83 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
1.09 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
7.92 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
17.99 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
3.06 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
28.27 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
25.16 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
9.52 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
26.83 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
12.56 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
28.25 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
10.65 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
28.40 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
13.82 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
44.35 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
13.72 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
242.30 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
98.90 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
22.05 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
11.02 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
10.31 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
2.55 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
9.99 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
4.85 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
3.21 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
25.21 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
8.91 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
51.68 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
15.80 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
4.54 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
1.82 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
2.56 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
653 B lrw-r--r-- 2026-04-22 07:17:42
Edit Download
3.12 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
2.02 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
45.65 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
14.34 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
4.27 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
1.74 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
14.88 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
2.95 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
10.20 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
4.36 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
6.10 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
3.04 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
3.14 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
1.37 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
5.75 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
1.74 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
11.75 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
8.70 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
2.76 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
967 B lrw-r--r-- 2026-04-22 07:17:42
Edit Download
569 B lrw-r--r-- 2026-04-22 07:17:42
Edit Download
24.69 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
7.24 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
10.06 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
3.55 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
1.02 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
397 B lrw-r--r-- 2026-04-22 07:17:42
Edit Download
3.87 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
1.02 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
557 B lrw-r--r-- 2026-04-22 07:17:42
Edit Download
237 B lrw-r--r-- 2026-04-22 07:17:42
Edit Download
20.47 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
11.00 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download
818 B lrw-r--r-- 2026-04-22 07:17:42
Edit Download
324 B lrw-r--r-- 2026-04-22 07:17:42
Edit Download
802.93 KB lrw-r--r-- 2026-04-22 07:17:42
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).