PageSourceSearch

https://www.drapersonline.com/wp-content/mu-plugins/MBM-SEO/assets/js/alt_tags.js?ver=1.10.0

js drapersonline.com collected 2026-10-01 08:40:18 UTC 10,187 bytes, 310 lines download raw bytes

1jQuery(function(){
2	window.jQuery = window.$ = jQuery;
3
4	function fixAltTag(image,file_url) {
5		url_bits 	=	file_url.split("/");
6		filename 	=	url_bits[(url_bits.length)-1]
7		$(img).attr("alt", filename);
8	}
9	
10	$("img").each(function(){
11		img 		=	$(this);
12		alt_tag 	= 	$(img).attr('alt');
13		src_tag		=	$(img).attr('src');
14		lazy_tag 	=	$(img).attr('data-lazy');
15		if (typeof alt_tag == typeof undefined || alt_tag == false) {
16			if (typeof src_tag !== typeof undefined && src_tag !== false) {
17				fixAltTag(img, src_tag);
18			} else {
19				if (typeof lazy_tag !== typeof undefined && lazy_tag !== false) {
20					fixAltTag(img, lazy_tag);
21				}
22			}
23		}
24	});
25
26	$(document).on("click", "#upload_csv", function(e){
27		
28		$("#empty-alert").addClass('d-none');
29		$("#max-limit-alert").addClass('d-none');
30
31		if ($("#file_to_upload").val()) {
32			// check if the limit entered is not more than max limit
33			if ($("#limit_next").val() > $("#max-limit-alert").data('max-limit')) {
34				$("#max-limit-alert").removeClass('d-none');
35			} else {
36				e.preventDefault();
37				uploadCSV('upload_csv', $(this).data('form-name'));
38			}
39		}else{
40			$("#empty-alert").removeClass('d-none');
41		}
42
43	});
44
45	$(document).on("click", "#dry_run", function(e){
46		e.preventDefault();
47		$(".records_processed").html('Trying to match records, please wait...');
48		performAction($(this).attr('id'), $(this).data('action'), $(this).data('action-status'));
49	});
50
51	$(document).on("click", "#perform_action", function(e){
52		e.preventDefault();
53		if ( confirm("You cannot undo this once started - are you sure? - Click OK to continue") ){
54			$(".records_processed").html('Processing Record, please wait...');
55			performAction($(this).attr('id'), $(this).data('action'), $(this).data('action-status'));
56		}
57	});
58
59	$(document).on("click", "#empty_bin", function(e){
60		e.preventDefault();
61		if ( confirm("You cannot undo this once started - are you sure? - Click OK to continue") ){
62			$(".records_processed").html('Processing Record, please wait...');
63			performActionOnBin($(this).attr('id'), $(this).data('action'), $(this).data('action-status'));
64		}
65	});
66
67	// ========================= Search Replace START ============================
68
69	// to toggle offset input box depending on db replace checkbox checked/unchecked
70	$(document).on("click", "#final_db_replace", function () { 
71		if ($("#after-process").data('final-db-replace') != 'on') {
72			if ($("#final_db_replace").is(":checked")) {
73				if ($("#after-process").data('offset-db-replace')) {
74					$("#offset_next").val($("#after-process").data('offset-db-replace'));
75				}
76			} else {
77				$("#offset_next").val($("#offset_next").data("ref"));
78			}
79		}
80	});
81
82	// ========================= Search Replace END ===============================
83
84	$(document).on("click", "#all_tables_label", function(e){
85		$(".records").prop('selected', true);
86		$("#db_tables").addClass('d-none');
87	});
88
89	$(document).on("click", "#selected_tables_label", function(e){
90		$(".records").prop('selected', false);
91		$("#db_tables").removeClass('d-none');
92	});
93});
94
95// ========================= Search Replace START ============================
96function setOffsetLimit() {
97	let limit  = parseInt($("#limit_next").val());
98	let offset = parseInt($("#offset_next").val());
99	let total  = parseInt(offset + limit);
100	$("#offset_next").val(total);
101	$("#offset_next").data('ref',total); // for reference
102}
103
104function uploadCSV( action, form_name ) {
105
106	// Get form
107	var form = $('#'+form_name)[0];
108	// Create an FormData object 
109	var data = new FormData(form);
110
111    // Begin an Ajax request
112    $.ajax({
113        type: "POST",
114		cache: false,
115		enctype: 'multipart/form-data',
116		contentType: false,
117		processData: false,
118		url: ajaxURL,
119		data: data,
120        dataType: 'html',               // You should set this to JSON if you are going to use the REST api
121        beforeSend: function(){         // Let's show a message while the request is being processed
122			$("#" + action).text('searching...');
123			$("#offset_next_text").text($("#offset_next").val());
124			$("#process_next").removeClass('d-none');
125        },
126		complete: function(){
127			$("#" + action).text($("#" + action).val());
128			$("#process_next").addClass('d-none');
129			setOffsetLimit();
130		},
131        success: function ( response ) {
132            // The Ajax request is successful. This doesn't mean the
133            // sever was able to do the task, it just means that the
134            // server did send a response. So, let's check the response
135			$("#dry_run").removeClass('d-none');
136			$("#perform_action").removeClass('d-none');
137			// $("#upload_csv").addClass('d-none');
138			
139			// csv_table 
140			$("#csv_display").html(response);
141        },
142        error: function(){ // The request wasn't successful for some reason
143            $('#status').html('<span>Unknown error.</span>');
144        }
145    });
146};
147
148function performActionOnBin(elemid, action, status_msg) {
149	// Create an FormData object 
150	var data = {
151		"action": action
152	};
153
154	$("#"+elemid).text(status_msg);
155	$(".action-button").prop('disabled', true);
156	$.ajax({
157		type: "POST",
158		cache: false,
159		url: ajaxURL,
160		data: data,
161		dataType: 'json',               // You should set this to JSON if you are going to use the REST api
162		beforeSend: function(){         // Let's show a message while the request is being processed
163			$("#"+elemid).text(status_msg)
164		},
165		complete: function(){
166			
167			$("#"+elemid).text($("#"+elemid).val());
168			$(".action-button").prop('disabled', false);
169		
170		},
171		success: function ( response ) {
172			var html="",counter=0;
173			$.each( response, function( i, val ) {
174				counter++;
175			  	html+= "<tr><td>"+val.result+"</td>"
176			});
177			$("#deleted_records").html(html);
178		},
179		error: function(){ // The request wasn't successful for some reason
180			$('#status').html('<span>Unknown error.</span>');
181		}
182	});
183}
184
185function performAction( elemid, action, status_msg ) {
186
187	var record  = '';
188	var records = [];
189	
190	// Create an FormData object 
191	var data = {
192		"action": action
193	};
194
195	$("#"+elemid).text(status_msg);
196	$(".action-button").prop('disabled', true);
197
198	$('.records').each(function(i, obj) {
199		record = $(obj).find('a').attr('href');
200		records.push( record );
201		data.record = record;
202
203		// Begin an Ajax request
204		$.ajax({
205			type: "POST",
206			cache: false,
207			url: ajaxURL,
208			data: data,
209			dataType: 'json',               // You should set this to JSON if you are going to use the REST api
210			beforeSend: function(){         // Let's show a message while the request is being processed
211				$("#"+elemid).text(status_msg)
212			},
213			complete: function(){
214				if( i == $('.records').length-1 ){
215					$("#"+elemid).text($("#"+elemid).val());
216					$(".action-button").prop('disabled', false);
217				}
218			},
219			success: function ( response ) {
220				if( response.post_id && $("#record-post-"+i).length ){
221					$("#record-post-"+i).text(response.post_id);
222				}
223				$("#record-"+i).text(response.result);
224			},
225			error: function(){ // The request wasn't successful for some reason
226				$('#status').html('<span>Unknown error.</span>');
227			}
228		});
229	});
230};
231
232function searchAndReplaceCSV( action, status_msg, actual = false ) {
233
234	var affected_url_arr     = $('.records');
235	var replace_with_url_arr = $('.replace_with');
236
237	SearchReplaceAjaxOne(affected_url_arr, replace_with_url_arr, action, status_msg, actual = false);
238}
239
240function SearchReplaceAjaxOne(affected_url_arr, replace_with_url_arr, action, status_msg, actual = false) {
241
242	// Create an FormData object 
243	var data = {
244		"action": action,
245		// "searchFor": affected_url_arr,
246		// "replaceWith": replace_with_url_arr
247	};
248
249	// data.searchFor   = $(affected_url_arr[$i]).text();
250	// data.seq         = $(affected_url_arr[$i]).data('seq');
251	// data.replaceWith = $(replace_with_url_arr[$i]).text();
252
253	// if (action == 'search_replace_dry_run') {
254	// 	$("#records_processed-" + $i).html('Trying to match records, please wait...');
255
256	// } else if(action == 'search_replace') {
257	// 	$("#replace_with_processed-" + $i).html('Processing Record, please wait...');
258	// }
259
260	// Begin an Ajax request
261	$.ajax({
262		type: "POST",
263		cache: false,
264		url: ajaxURL,
265		data: data,
266		dataType: 'json',
267		beforeSend: function(){
268			$("#"+action).text(status_msg)
269			$(".action-button").prop('disabled', true);
270		},
271		complete: function(){
272			$("#"+action).text($("#"+action).val());
273			$(".action-button").prop('disabled', false);
274		},
275		success: function ( response ) {
276			if( response ){
277				if( action == 'search_replace' ){
278					$("#replace_with_processed-" + response.seq).html(response.updated);
279					$("#replace_with_processed-" + response.seq).append('<br/><br/> <mark>Query took  ' + response.query_time_taken + '</mark>');
280					if (response.regex_time_taken) {
281						$("#replace_with_processed-" + response.seq).append('<br/> <mark>Regexed in ' + response.regex_time_taken_txt + '</mark>');
282					}
283				} else {
284					$("#records_processed-"+response.seq).html('');
285					if( response.data && $.isArray(response.data) ){
286						$.each(response.data, function (key, val) {
287							$('<li />', {html: val.permalink}).appendTo($("#records_processed-"+val.seq))
288						});
289					} else {
290						if (response.permalink) {
291							$("#records_processed-" + response.seq).html(response.permalink);
292						} else {
293							$("#records_processed-" + response.seq).html('No matching URL found');
294						}
295					}
296					$("#records_processed-" + response.seq).append('<br/><br/> <mark>Query took ' + response.query_time_taken + '</mark>');
297					if (response.regex_time_taken) {
298						$("#replace_with_processed-" + response.seq).append('<br/> <mark>Regexed in ' + response.regex_time_taken_txt + '</mark>');
299					}
300					if(actual){
301						searchAndReplaceCSV('search_replace', 'Updating...', true);
302					}
303				}
304			}
305		},
306		error: function(){ // The request wasn't successful for some reason
307			$('#status').html('<span>Unknown error.</span>');
308		}
309	});
310}

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.