PageSourceSearch

https://www.sabc.co.za/sabc/wp-content/plugins/som-free-downloads-…/assets/js/somdn_pro_script.js?ver=1.0.0

js sabc.co.za collected 2026-09-24 09:12:07 UTC 19,762 bytes, 606 lines download raw bytes

1(function($) {
2
3	var clicked_button = '';
4
5	/**
6	 * Scripts relating to adding/removing the "loading" class which some themes use
7	 */
8
9	$( 'body' ).on( 'click', '.somdn-download-button:not(.somdn-checkbox-submit), .somdn-download-archive', function (e) {
10	//LEGACY// $( '.somdn-download-button:not(.somdn-checkbox-submit), .somdn-download-archive' ).click( function(e) {
11		// Assign the clicked link/button to the clicked_button variable for later
12		clicked_button = $( this );
13		var form = $( this ).closest( 'form' );
14		if ( ! capture_email_active_page( form ) ) {
15			//console.log('addClass');
16			$( this ).addClass( 'loading' );
17		}
18	});
19
20	$( 'body' ).on( 'click', '.somdn-download-button, .somdn-download-archive', function (e) {
21		var element = $( this );
22		setTimeout(
23			function() {
24				if ( element.hasClass( 'loading' ) ) {
25					element.removeClass( 'loading' );
26					//console.log('element.removeClass');
27				}
28			},
29		2000);
30	});
31
32/*
33	$( '.somdn-download-button, .somdn-download-archive' ).each( function() {
34		$( this ).click(
35		function(e) {
36			var element = $( this );
37			setTimeout(
38				function() {
39					if ( element.hasClass( 'loading' ) ) {
40						element.removeClass( 'loading' );
41						console.log('element.removeClass');
42					}
43				},
44				2000);
45		});
46	});
47*/
48
49	$( 'body' ).on( 'somdn_email_capture_submit_clicked_success', function( event, click_event, button, form ) {
50
51		// If a button or archive page link was clicked add the "loading" class and remove it after 2 seconds.
52		if ( clicked_button.length ) {
53			clicked_button.addClass('loading');
54			//console.log('clicked_button addClass');
55			setTimeout(
56				function() {
57					if ( clicked_button.hasClass( 'loading' ) ) {
58						//console.log('clicked_button removeClass');
59						clicked_button.removeClass( 'loading' );
60					}
61				},
62				2000);
63		}
64
65	});
66
67	/**********************************************************************/
68
69	/**
70	 * Scripts relating to download buttons that are actually anchor elements
71	 */
72
73	$( 'body' ).on( 'click', 'a.somdn-download-archive', function (e) {
74	//LEGACY// $( 'a.somdn-download-archive' ).click( function(e) {
75		//console.log('a.somdn-download-archive Click');
76		e.stopImmediatePropagation();
77		var form = $( this ).closest( 'form.somdn-archive-download-form' );
78		if ( capture_email_active_page( form ) ) {
79			//console.log( 'Capture email active' );
80			somdn_open_email_capture( form, e );
81		} else {
82			//console.log( 'No capture email' );
83			form.submit();
84		}
85		return false;
86	});
87
88	$( 'body' ).on( 'click', '.somdn-download-link', function (e) {
89	//LEGACY// $( '.somdn-download-link' ).click( function(e) {
90		//console.log('.somdn-download-link Click');
91		e.stopImmediatePropagation();
92		var form = $( this ).closest( 'form' );
93		if ( capture_email_active_page( form ) ) {
94			//console.log( 'Capture email active' );
95			somdn_open_email_capture( form, e );
96		} else {
97			//console.log( 'No capture email' );
98			form.submit();
99		}
100		return false;
101	});
102
103	/**********************************************************************/
104
105	/**
106	 * Scripts relating to the multiple file checkbox form
107	 */
108
109	$( 'body' ).on( 'click', '.somdn-checkbox-form .somdn-checkbox-submit', function (e) {
110	//LEGACY// $( '.somdn-checkbox-form .somdn-checkbox-submit' ).click( function(e) {
111		var form = $( this ).closest( 'form' );
112		if ( $( form ).find( 'input[type="checkbox"]:checked' ).length == 0 ) {
113			e.preventDefault();
114			$( '.somdn-form-validate' ).css( 'display', 'block' );
115		} else {
116			$( '.somdn-form-validate' ).css( 'display', 'none' );
117			$( this ).addClass( 'loading' );
118			var form = $( this ).closest( 'form' );
119			if ( capture_email_active_page( form ) ) {
120				e.preventDefault();
121				capture_email_checkbox_form(e, this);
122			}
123		}
124	});
125
126	$( 'body' ).on( 'click', '.somdn-select-all-wrap input[type="checkbox"]', function (e) {
127	//LEGACY// $( '.somdn-select-all-wrap input[type="checkbox"]' ).click( function(e) {
128		var c = this.checked;
129		var form = $( this ).closest( 'form' );
130		$( form ).find( '.somdn-checkboxes-wrap input[type="checkbox"]' ).prop( 'checked', c );
131	});
132
133	$( 'body' ).on( 'click', '.somdn-checkbox-form .somdn-checkbox-form-checkbox', function (e) {
134	//LEGACY// $( '.somdn-checkbox-form .somdn-checkbox-form-checkbox' ).click( function(e) {
135		var form = $( this ).closest( 'form' );
136		var checkboxes = $( form ).find( '.somdn-checkbox-form-checkbox' );
137		var checked_count = $( form ).find( '.somdn-checkbox-form-checkbox:checked' ).length;// How many checkboxes currently checked
138		var count = checkboxes.length;// How many checkboxes in total
139		if ( checked_count < count ) {
140			$( form ).find( '.somdn-checkbox-all' ).prop( 'checked', false );
141		} else {
142			$( form ).find( '.somdn-checkbox-all' ).prop( 'checked', true );
143		}
144	});
145
146	/**********************************************************************/
147
148	/**
149	 * Quick View scripts
150	 */
151
152	$( 'body' ).on( 'click', '.somdn-qview-link', function (e) {
153	//LEGACY// $( '.somdn-qview-link' ).click( function(e) {
154		//console.log('Quick View');
155		var prod_wrap = $( this ).closest( 'li.product' );
156		if ( qview_active() ) {
157			e.preventDefault();
158			somdn_open_qview( prod_wrap, event );
159		} else {
160			// Do nothing
161		}
162	});
163
164	/**
165	 * Check if Quick View is active globally
166	 *
167	 * @return bool
168	 */
169	function qview_active() {
170		var qview_enabled = somdn_script_params.somdn_qview_active;
171		if ( qview_enabled ) {
172			return true;
173		} else {
174			return false;
175		}	
176	}
177
178	/**
179	 * Check if Quick View is active on the current page
180	 *
181	 * @return bool
182	 */
183	function qview_active_page( form ) {
184		var qview_enabled = somdn_script_params.somdn_qview_active;
185		if ( qview_enabled ) {
186			return true;
187		} else {
188			return false;
189		}	
190	}
191
192	/**
193	 * Open the Quick View modal
194	 */
195	function somdn_open_qview( prod_wrap, event ) {
196
197		//$( prod_wrap ).addClass( 'somdn-form-email-capture' );
198
199		var the_qview_wrap = $( prod_wrap ).find( '.somdn-qview-wrap' );
200
201		$( 'body' ).addClass( 'somdn-qview-open' );
202		$( the_qview_wrap ).addClass( 'open' );
203
204		$( 'body' ).trigger( 'somdn_open_qview', [ prod_wrap, event ] );
205
206	}
207
208	/**
209	 * Close the Quick View modal
210	 */
211	function somdn_close_qview( prod_wrap, event ) {
212
213		//$( prod_wrap ).removeClass( 'somdn-form-email-capture' );
214		$( prod_wrap ).find( '.somdn-checkbox-form-checkbox, .somdn-checkbox-all' ).prop( 'checked', false );
215		$( prod_wrap ).find( '.somdn-qview-wrap' ).removeClass( 'open' );
216		$( 'body' ).removeClass( 'somdn-qview-open' );
217
218		$( 'body' ).trigger( 'somdn_close_qview', [ prod_wrap, event ] );
219
220	}
221
222	/**
223	 * Two events that close the Quick View modal
224	 * 1. Clicking the X in the top right corner of the modal
225	 * 2. Clicking anywhere outside the modal when it is open
226	 */
227	$( 'body' ).on( 'click', '.somdn-qview-wrap .somdn-qview-close', function (event) {
228	//LEGACY// $( '.somdn-qview-wrap .somdn-qview-close' ).click( function( event ) {
229		var prod_wrap =  $( this ).closest( 'li.product' );
230		somdn_close_qview( prod_wrap, event );
231	});
232
233	$( document ).on( 'click', '.somdn-qview-wrap', function( event ) {
234		var prod_wrap = $( this ).closest( 'li.product' );
235		somdn_close_qview( prod_wrap, event );
236	}).on( 'click' , '.somdn-qview-window', function(e) {
237			e.stopPropagation();
238	});
239
240	/**********************************************************************/
241
242	/**
243	 * Scripts relating to the download forms where email capture is being used
244	 */
245
246	function capture_email_checkbox_form(e, this_var) {
247		//console.log('capture email checkbox form');
248		e.stopImmediatePropagation();
249		var form = $( this_var ).closest( 'form' );
250		if ( capture_email_active_page( form ) ) {
251			//console.log( 'Capture email active' );
252			somdn_open_email_capture( form, e );
253		} else {
254			//console.log( 'No capture email' );
255			form.submit();
256		}
257		return false;
258	}
259
260	$( 'body' ).on( 'click', '.somdn-download-button:not(.somdn-checkbox-submit)', function (e) {
261	//LEGACY// $( '.somdn-download-button:not(.somdn-checkbox-submit)' ).click( function(e) {
262		e.stopImmediatePropagation();
263		var form = $( this ).closest( 'form' );
264		if ( capture_email_active_page( form ) ) {
265			//console.log( 'Capture email active' );
266			somdn_open_email_capture( form, e );
267		} else {
268			//console.log( 'No capture email' );
269			form.submit();
270		}
271		return false;
272	});
273
274	/**
275	 * Email Capture scripts
276	 */
277
278	/**
279	 * Check if capture email is active globally
280	 *
281	 * @return bool
282	 */
283	function capture_email_active() {
284		var capture_enabled = somdn_script_params.somdn_capture_emails_active;
285		if ( capture_enabled ) {
286			return true;
287		} else {
288			return false;
289		}	
290	}
291
292	/**
293	 * Check if capture email is active on the current page
294	 *
295	 * @return bool
296	 */
297	function capture_email_active_page( form ) {
298		var the_email_wrap = $( form ).find( '.somdn-capture-email-wrap' );
299		var the_email = $( the_email_wrap ).find( '.somdn-download-user-email' );
300		var capture_enabled = somdn_script_params.somdn_capture_emails_active;
301		if ( the_email.length && capture_enabled ) {
302			return true;
303		} else {
304			return false;
305		}	
306	}
307/*
308	$( '.somdn-download-form:not(.somdn-checkbox-form)' ).on( 'submit', function( event ) {
309		somdn_capture_email( $( this ), event );
310	});
311*/
312
313	/**
314	 * Open the email capture modal
315	 */
316	function somdn_open_email_capture( the_form, event ) {
317
318		$( the_form ).addClass( 'somdn-form-email-capture' );
319
320		var the_email_wrap = $( the_form ).find( '.somdn-capture-email-wrap' );
321		var the_email = $( the_email_wrap ).find( '.somdn-download-user-email' );
322		//var the_email_name = $( the_email_wrap ).find( '.somdn-download-user-name' );
323
324		$( the_form ).find( '.somdn-capture-required' ).prop( 'required', true );
325		$( the_form ).find( '.somdn-capture-checkbox-wrap input[type="checkbox"].somdn-checkbox-auto-blank' ).prop( 'checked', false );
326
327		$( 'body' ).addClass( 'somdn-capture-email-open' );
328		$( the_email_wrap ).addClass( 'open' );
329
330		//$( the_form ).find( '.somdn-download-user-name' ).val( '' );
331
332		$( 'body' ).trigger( 'somdn_open_email_capture', [ the_form, event ] );
333
334	}
335
336	/**
337	 * Close the email capture modal
338	 */
339	function somdn_close_email_capture( the_form, event ) {
340
341		$( the_form ).removeClass( 'somdn-form-email-capture' );
342		$( the_form ).find( '.somdn-capture-email-wrap' ).removeClass( 'open' );
343		$( 'body' ).removeClass( 'somdn-capture-email-open' );
344		$( the_form ).find( '.somdn-capture-required' ).prop( 'required', false );
345
346		$( 'body' ).trigger( 'somdn_close_email_capture', [ the_form, event ] );
347
348	}
349
350	/**
351	 * Two events that close the email capture modal
352	 * 1. Clicking the X in the top right corner of the modal
353	 * 2. Clicking anywhere outside the modal when it is open
354	 */
355	$( 'body' ).on( 'click', '.somdn-capture-email-header .dashicons-no', function (event) {
356	//LEGACY// $( '.somdn-capture-email-header .dashicons-no' ).click( function( event ) {
357		var form = $( this ).closest( 'form' );
358		somdn_close_email_capture( form, event );
359	});
360
361	$( document ).on( 'click', '.somdn-capture-email-wrap', function( event ) {
362		var form = $( this ).closest( 'form' );
363		somdn_close_email_capture( form, event );
364	}).on( 'click' , '.somdn-capture-email-wrap-form', function(e) {
365			e.stopPropagation();
366	});
367
368	/**
369	 * Click event when the user clicks the email capture submit button
370	 */
371	$( 'body' ).on( 'click', '.somdn-capture-email-button', function (e) {
372	//LEGACY// $( '.somdn-capture-email-button' ).click( function(e) {
373
374		var button = this;
375		var form = $( this ).closest( 'form' );
376
377		$( 'body' ).trigger( 'somdn_email_capture_submit_clicked', [ e, button, form ] );
378
379		var email_name = $( form ).find( 'input[name="somdn_download_user_name"]' );
380		if ( email_name.length ) {
381			if ( ! email_name.val() && $( email_name ).hasClass( 'somdn-capture-required' ) ) {
382				alert( somdn_script_params.somdn_capture_fname_empty );
383				e.preventDefault();
384				return;
385			}
386			$( 'body input[name="somdn_download_user_name"]' ).each(function() {
387				$( this ).val( email_name.val() );
388			});
389		}
390
391		var email_lname = $( form ).find( 'input[name="somdn_download_user_lname"]' );
392		if ( email_lname.length ) {
393			if ( ! email_lname.val() && $( email_lname ).hasClass( 'somdn-capture-required' ) ) {
394				alert( somdn_script_params.somdn_capture_lname_empty );
395				e.preventDefault();
396				return;
397			}
398			$( 'body input[name="somdn_download_user_lname"]' ).each(function() {
399				$( this ).val( email_lname.val() );
400			});
401		}
402
403		var email_tel = $( form ).find( 'input[name="somdn_download_user_tel"]' );
404		if ( email_tel.length ) {
405			if ( ! email_tel.val() && $( email_tel ).hasClass( 'somdn-capture-required' ) ) {
406				alert( somdn_script_params.somdn_capture_tel_empty );
407				e.preventDefault();
408				return;
409			}
410			$( 'body input[name="somdn_download_user_tel"]' ).each(function() {
411				$( this ).val( email_tel.val() );
412			});
413		}
414
415		var email_company = $( form ).find( 'input[name="somdn_download_user_company"]' );
416		if ( email_company.length ) {
417			if ( ! email_company.val() && $( email_company ).hasClass( 'somdn-capture-required' ) ) {
418				alert( somdn_script_params.somdn_capture_company_empty );
419				e.preventDefault();
420				return;
421			}
422			$( 'body input[name="somdn_download_user_company"]' ).each(function() {
423				$( this ).val( email_company.val() );
424			});
425		}
426
427		var email_website = $( form ).find( 'input[name="somdn_download_user_website"]' );
428		if ( email_website.length ) {
429			if ( ! email_website.val() && $( email_website ).hasClass( 'somdn-capture-required' ) ) {
430				alert( somdn_script_params.somdn_capture_website_empty );
431				e.preventDefault();
432				return;
433			}
434			$( 'body input[name="somdn_download_user_website"]' ).each(function() {
435				$( this ).val( email_website.val() );
436			});
437		}
438
439		var user_email = $( form ).find( 'input[name="somdn_download_user_email"]' );
440		if ( user_email.length ) {
441
442			if ( ! user_email.val() ) {
443				alert( somdn_script_params.somdn_capture_email_empty );
444				e.preventDefault();
445				return;
446			}
447
448			if ( ! isValidEmailAddress( user_email.val() ) ) {
449				alert( somdn_script_params.somdn_capture_email_invalid );
450				e.preventDefault();
451				return;
452			}
453
454			$( 'body .somdn-download-user-email' ).each(function() {
455				$( this ).val( user_email.val() );
456			});
457
458		}
459
460		var sub_checkbox = $( form ).find( 'input[name="somdn_capture_email_subscribe"]' );
461		if ( sub_checkbox.length ) {
462			if ( ! $( sub_checkbox ).is( ':checked' ) && $( sub_checkbox ).hasClass( 'somdn-capture-required' ) ) {
463				alert( somdn_script_params.somdn_capture_checkbox_error );
464				e.preventDefault();
465				return;
466			}
467		}
468
469		somdn_close_email_capture( form, e );
470
471		$( 'body' ).trigger( 'somdn_email_capture_submit_clicked_success', [ e, button, form ] );
472
473	});
474
475	$( 'body' ).on( 'somdn_email_capture_submit_clicked_success', function( event, click_event, button, form ) {
476		//console.log('somdn_email_capture_submit_clicked_success')
477		//click_event.preventDefault();
478	});
479
480function isValidEmailAddress(emailAddress) {
481	var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i);
482	return pattern.test(emailAddress);
483};
484
485	/**
486	 * Scripts for processing AJAX data prior to download form submission
487	 */
488/*
489	$( '.somdn-download-form' ).on( 'submit', function(e) {
490
491		console.log( 'Submit' );
492
493		return true;
494
495		e.preventDefault();
496
497		var form = this;
498		var product_id = $( form ).find( 'input[name="somdn_product"]' ).val();
499		var the_ajax_url = somdn_script_params.somdn_ajax_url;
500
501		console.log( 'AJAX - let\'s do this!' );
502		console.log( 'product = ' + product_id );
503		console.log( 'url = ' + the_ajax_url );
504		//return;
505
506		$.ajax({
507			url: the_ajax_url,
508			data: {
509				product_id: product_id,
510				action: 'somdn_ajax_validate_download',
511				security: somdn_script_params.somdn_ajax_nonce
512			},
513			success : function( response ) {
514				console.log(response);
515				if ( response == 'download_valid' ) {
516					console.log( 'Valid download' );
517					form.submit();
518				} else {
519					return false;
520				}
521			},
522			error : function(error){console.log(error) }
523		});
524
525	});
526*/
527
528	/**********************************************************************/
529
530	/**
531	 * Scripts for manipulating variation product page
532	 */
533	$( document ).on( 'hide_variation', function( event, variation ) {
534
535		$( '.somdn-download-wrap-variable' ).each(function() {
536			$( this ).css( 'display', 'none' );
537			var this_wrap_variation = $( this ).attr( 'data-somdn-var-id' );
538			$( this ).insertAfter( '.somdn-variable-anchor[data-somdn-anchor-var-id="'+this_wrap_variation+'"]' );
539		});
540
541		var variation_wrap = $( '.variations_form' ).find( '.woocommerce-variation-add-to-cart' );
542		$( variation_wrap ).css( 'display', '' );
543		//console.log( 'hide_variation' );
544
545	});
546
547	$( document ).on( 'show_variation', function( event, variation ) {
548
549		$( '.somdn-download-wrap-variable' ).each(function() {
550			$( this ).css( 'display', 'none' );
551			var this_wrap_variation = $( this ).attr( 'data-somdn-var-id' );
552			$( this ).insertAfter( '.somdn-variable-anchor[data-somdn-anchor-var-id="'+this_wrap_variation+'"]' );
553		});
554
555		//console.log( 'show_variation' );
556		var variation_wrap = $( '.variations_form' ).find( '.woocommerce-variation-add-to-cart' );
557		var variation_id = variation['variation_id'];
558		//console.log( variation_id_current );
559		var variation_download = $( '*[data-somdn-var-id="'+variation_id+'"]' );
560		if ( variation_download.length ) {
561			$( variation_download ).find( '.single_add_to_cart_button' ).removeClass( 'disabled wc-variation-selection-needed wc-variation-is-unavailable' );
562			$( variation_wrap ).css( 'display', 'none' );
563			$( variation_download ).css( 'display', 'block' );
564			$( variation_download ).insertAfter( variation_wrap );
565		} else {
566			$( variation_wrap ).css( 'display', '' );
567		}
568
569	});
570
571	/**********************************************************************/
572
573	/**
574	 * Scripts for the download redirecting
575	 */
576
577	$( 'body' ).on( 'click', 'a.somdn-redirect-form-link', function (e) {
578		e.preventDefault();
579		e.stopImmediatePropagation();
580		//console.log( 'CLICK somdn-redirect-form-link' );
581		var somdn_redirect_form = $( 'body' ).find( 'form#somdn_download_redirect_form' );
582		if ( somdn_redirect_form.length ) {
583			$( somdn_redirect_form ).addClass( 'somdn-redirect-download-submitted' );
584			somdn_redirect_form.submit();
585		}
586	});
587
588	$( document ).ready( function() {
589		var somdn_redirect_form = $( 'body' ).find( 'form#somdn_download_redirect_form' ); 
590		if ( somdn_redirect_form.length ) {
591			var redirect_time = somdn_script_params.somdn_redirect_time;
592			if (! redirect_time ) {
593				redirect_time = 5000;
594			}
595			//console.log('redirect_time = ' + redirect_time);
596			setTimeout(function() {
597				if ( ! $( somdn_redirect_form ).hasClass( 'somdn-redirect-download-submitted' ) ) {
598					somdn_redirect_form.submit();
599					//console.log( 'somdn_redirect_form = ' + somdn_redirect_form );
600					//console.log('Download initiated');
601				}
602			}, redirect_time);
603		}
604	});
605
606})( 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.