PageSourceSearch

https://penaviation.com/wp-content/themes/motors/assets/js/sell-a-car.js?ver=4.0

js penaviation.com collected 2026-09-26 07:51:58 UTC 10,407 bytes, 337 lines download raw bytes

1(function ($) {
2	"use strict";
3
4	var ListingForm = STMListings.ListingForm = function (form) {
5		this.$form = $(form);
6		this.formUser = $('.stm-form-checking-user');
7		this.featuredId = 0;
8		this.userFiles = [];
9		this.orderChanged = false;
10		this.init();
11	};
12
13	ListingForm.prototype.init = function () {
14		this.$loader = $('.stm-add-a-car-loader');
15		this.$message = $('.stm-add-a-car-message');
16
17		this.$form.on('submit', $.proxy(this.submit, this));
18
19		this.$form.on('change', 'input[name^="stm_car_gallery_add"]', $.proxy(this.onImagePicked, this));
20
21		$(document).on('touchend click', '.stm-media-car-gallery .stm-placeholder .inner .stm-image-preview .fas', $.proxy(this.imageRemove, this));
22
23		$('.stm-media-car-gallery .stm-placeholder').droppable({
24			drop: $.proxy(this.onDropped, this)
25		});
26	};
27
28	ListingForm.prototype.submit = function (e) {
29		e.preventDefault();
30
31        var loadType = $('input[name="btn-type"]').val();
32        this.$loader = $('.stm-add-a-car-loader.' + loadType);
33
34		$.ajax({
35			url: ajaxurl,
36			type: "POST",
37			dataType: 'json',
38			context: this,
39			data: this.submitData(),
40			beforeSend: function () {
41				this.$loader.addClass('activated');
42				this.$message.slideUp();
43			},
44			success: this.success
45		});
46
47	};
48
49	ListingForm.prototype.submitData = function () {
50		var gdpr = '';
51
52		if (typeof this.formUser.find('input[name="motors-gdpr-agree"]')[0] !== 'undefined') {
53			var gdprAgree = (this.formUser.find('input[name="motors-gdpr-agree"]')[0].checked) ? 'agree' : 'not_agree';
54			gdpr = '&motors-gdpr-agree=' + gdprAgree;
55		}
56
57		return this.$form.serialize() + gdpr + '&action=stm_ajax_add_a_car&security=' + addACar;
58	};
59
60	ListingForm.prototype.success = function (data) {
61		this.$loader.removeClass('activated');
62		$('.stm-form-checking-user button[type="submit"]').removeClass().addClass('enabled');
63
64		if (data.message) {
65			if (typeof data.html !== 'undefined') {
66				this.$message.html(data.message).slideDown();
67			} else {
68				this.$message.html(data.message).slideDown();
69			}
70		}
71
72		if (data.post_id) {
73			this.$message.html(data.message).slideDown();
74			this.$loader.addClass('activated');
75
76			if (typeof(this.userFiles) !== 'undefined') {
77				if (!this.orderChanged) {
78					this.sortImages();
79				}
80
81				this.uploadImages.call(this, data);
82			}
83		}
84	};
85
86	ListingForm.prototype.uploadImages = function (data) {
87		var fd = new FormData();
88
89		if (this.$form.closest('.stm_edit_car_form').length) {
90			fd.append('stm_edit', 'update');
91		}
92
93		fd.append('action', 'stm_ajax_add_a_car_media');
94		fd.append('post_id', data.post_id);
95		fd.append('redirect_type', data.redirect_type);
96
97		$.each(this.userFiles, function (i, file) {
98			if (typeof(file) !== undefined) {
99				if (typeof(file) !== 'number') {
100					fd.append('files[' + i + ']', file);
101				} else {
102					fd.append('media_position_' + i, file);
103				}
104			}
105		});
106
107		$.ajax({
108			type: 'POST',
109			url: ajaxurl,
110			data: fd,
111			contentType: false,
112			processData: false,
113			context: this,
114			success: function (response) {
115
116				if (typeof(response) != 'object') {
117					var responseObj = JSON.parse(response);
118				} else {
119					var responseObj = response;
120				}
121				if (responseObj.allowed_posts) {
122					$('.stm-posts-available-number span').text(responseObj.allowed_posts);
123				}
124				this.$loader.removeClass('activated');
125				if (responseObj.message) {
126					this.$message.html(responseObj.message).slideDown();
127				}
128				if (responseObj.url) {
129					window.location = responseObj.url;
130				}
131			}
132		});
133	};
134
135	ListingForm.prototype.sortImages = function () {
136        $(".stm-media-car-gallery .stm-placeholder").each(function () {
137            $(this).trigger('blur');
138            $(this).find(".inner").removeClass("active");
139            $(this).find(".stm-image-preview").trigger('blur');
140        });
141
142        var _this = this;
143
144		setTimeout(function () {
145			var tmpArr = [];
146
147			$('.stm-placeholder.stm-placeholder-generated').each(function (i, e) {
148				/*Get old id*/
149				var oldId = $(this).find('.stm-image-preview').attr('data-id');
150
151				/*Set new ids to preview and to delete icon*/
152				$(this).find('.stm-image-preview').attr('data-id', i);
153				$(this).find('.stm-image-preview .fas').attr('data-id', i);
154
155				if (typeof(_this.userFiles[oldId]) !== 'undefined') {
156					tmpArr[i] = _this.userFiles[oldId];
157				}
158			});
159
160			_this.featuredId = 0;
161			_this.userFiles = tmpArr;
162		}, 100);
163	};
164
165    ListingForm.prototype.onImagePicked = function (event) {
166        var wasEmpty = this.userFiles.length === 0, _this = this;
167
168        [].forEach.call($(event.target)[0].files, function (file) {
169
170            if (typeof(file) === 'object' && file.type.match(/^image/)) {
171				_this.userFiles.push(file);
172                var index = _this.userFiles.length - 1;
173
174                if (index === 0 && wasEmpty) {
175					_this.featuredId = index;
176                    $('.stm-media-car-main-input')
177                        .find('.stm-image-preview').remove().end()
178                        .append('<div class="stm-image-preview" data-id="' + index + '"></div>');
179                }
180
181                $('.stm-placeholder-native').remove();
182                $('.stm-media-car-gallery')
183                    .append(
184                        '<div class="stm-placeholder stm-placeholder-generated"><div class="inner">' +
185                        '<div class="stm-image-preview" data-id="' + index + '"><i class="fas fa-times" data-id="' + index + '"></i></div>' +
186                        '</div></div>'
187                    );
188
189                loadImage(
190                    file,
191                    function (img) {
192                        $('.stm-image-preview[data-id="' + index + '"]').css('background-image', 'url(' + img.toDataURL() + ')');
193						$('.stm-media-car-gallery .stm-placeholder').stop().droppable({
194							drop: $.proxy(_this.onDropped, _this),
195							delay: 200
196						});
197                    },
198                    {
199                        orientation: true,
200                        canvas: true
201                    }
202                );
203            }
204        });
205
206        if (this.userFiles.length > 0) {
207            $('.stm-media-car-main-input .stm-placeholder').addClass('hasPreviews');
208        } else {
209            $('.stm-media-car-main-input .stm-placeholder').removeClass('hasPreviews');
210        }
211
212        $('.stm_add_car_form input[type="file"]').val('');
213    };
214
215	ListingForm.prototype.onDropped = function (event, ui) {
216		var dragFrom = ui.draggable.closest('.inner');
217		var dragTo = $(event.target).find('.inner');
218		var dragToPreview = dragTo.find('.stm-image-preview');
219
220		if (ui.draggable.length > 0 && dragToPreview.length > 0 && dragTo.length > 0 && dragFrom.length > 0) {
221
222			if (dragFrom[0] !== dragTo[0]) {
223
224				ui.draggable.clone().appendTo(dragTo);
225				dragToPreview.clone().appendTo(dragFrom);
226
227
228				/*If placed in first pos*/
229				if (dragTo.closest('.stm-placeholder').index() === 0) {
230					$('.stm-media-car-main-input .stm-image-preview').remove();
231					ui.draggable.clone().appendTo('.stm-media-car-main-input');
232					this.featuredId = ui.draggable.data('id');
233				}
234
235				/*If moving from first place*/
236				if (ui.draggable.closest('.stm-placeholder').index() === 0) {
237					$('.stm-media-car-main-input .stm-image-preview').remove();
238					dragToPreview.clone().appendTo('.stm-media-car-main-input');
239					this.featuredId = dragToPreview.data('id');
240				}
241
242				ui.draggable.remove();
243				dragToPreview.remove();
244
245				this.sortImages();
246				this.orderChanged = true;
247			}
248		}
249	};
250
251	ListingForm.prototype.imageRemove = function (event) {
252		var stm_id = $(event.target).attr('data-id');
253		var stm_length = 0;
254		delete this.userFiles[stm_id];
255		$('.stm-placeholder .inner').removeClass('deleting');
256
257		$(event.target).closest('.stm-placeholder').remove();
258
259		$(this.userFiles).each(function (i, e) {
260			if (typeof(e) !== 'undefined') {
261				stm_length++;
262			}
263		});
264
265		if (stm_length === 0) {
266			$('.stm-media-car-main-input .stm-image-preview').remove();
267			$('.stm-media-car-main-input .stm-placeholder').removeClass('hasPreviews');
268			var defaultPlaceholders = '';
269			for (var i = 0; i < 5; i++) {
270				defaultPlaceholders += '<div class="stm-placeholder stm-placeholder-native"><div class="inner"><i class="stm-service-icon-photos"></i></div></div>';
271			}
272
273			$('.stm-media-car-gallery').append(defaultPlaceholders);
274		}
275
276		if (this.featuredId === parseInt(stm_id)) {
277			var changeFeatured = $('.stm-media-car-gallery .stm-placeholder:nth-child(1)');
278			this.featuredId = changeFeatured.find('.stm-image-preview').attr('data-id');
279
280			$('.stm-media-car-main-input .stm-image-preview').remove();
281			$(changeFeatured).find('.stm-image-preview').clone().appendTo('.stm-media-car-main-input');
282		}
283
284		this.sortImages();
285	};
286
287	$(document).ready(function () {
288
289		var $form = $('#stm_sell_a_car_form'), listingForm = new ListingForm($form);
290
291		//window.hasOwnProperty = window.hasOwnProperty || Object.prototype.hasOwnProperty;
292
293		/*Sell a car*/
294		if (typeof stmUserFilesLoaded !== 'undefined') {
295			listingForm.userFiles = stmUserFilesLoaded;
296		}
297
298		$(document).on('mouseenter touchstart', '.stm-media-car-gallery .stm-placeholder .inner .stm-image-preview .fas', function () {
299			$(this).closest('.inner').addClass('deleting');
300		});
301
302		$(document).on('mouseleave touchend', '.stm-media-car-gallery .stm-placeholder .inner .stm-image-preview .fas', function () {
303			$(this).closest('.inner').removeClass('deleting');
304		});
305
306		/*Droppable*/
307		$(document).on("mouseenter touchstart", '.stm-media-car-gallery .stm-placeholder .inner .stm-image-preview', function (e) {
308			$(this).draggable({
309				revert: 'invalid',
310				helper: "clone"
311			})
312		});
313
314		$(document).on("mouseenter touchstart click", ".stm-media-car-gallery .stm-placeholder .inner", function () {
315			$(".stm-media-car-gallery .stm-placeholder").each(function () {
316				$(this).trigger('blur');
317				$(this).find(".inner").removeClass("active");
318				$(this).find(".stm-image-preview").trigger('blur');
319            });
320
321			$(this).addClass("active");
322        });
323
324		$('.stm-form-checking-user button[type="submit"]').on('click', function (e) {
325			e.preventDefault();
326			if (!$(this).hasClass('disabled')) {
327                var loadType = $(this).attr('data-load');
328                $('input[name="btn-type"]').val(loadType);
329
330				$(this).removeClass().addClass('disabled');
331				$form.trigger('submit');
332			}
333		});
334
335	});
336
337})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.