PageSourceSearch

http://informatii-agrorurale.ro/anunturi-agricole/wp-content/theme…/includes/js/theme-scripts.js?ver=3.3.3

js informatii-agrorurale.ro collected 2026-10-02 19:35:55 UTC 16,303 bytes, 497 lines download raw bytes

1/*
2 * ClassiPress theme jQuery functions
3 * Written by AppThemes
4 * http://www.appthemes.com
5 *
6 * Left .js uncompressed so it's easier to customize
7 */
8
9
10
11jQuery(document).ready(function($) {
12
13	/* style the select dropdown menus */
14	if ( jQuery.isFunction( jQuery.fn.selectBox ) ) {
15		jQuery('select').selectBox({
16			menuTransition: 'fade', // default, slide, fade
17			menuSpeed: 'fast'
18		});
19
20		/* do not apply in step1 of add new listing form */
21		jQuery('.form_step #ad-categories select').selectBox('destroy');
22	}
23
24	/* convert header menu into select list on mobile devices */
25	if ( jQuery.isFunction( jQuery.fn.tinyNav ) ) {
26		jQuery('.header_menu_res .menu').tinyNav({
27			active: 'current-menu-item',
28			header: classipress_params.text_mobile_navigation,
29			header_href: classipress_params.home_url,
30			indent: '-',
31			excluded: ['#adv_categories']
32		});
33	}
34
35	/* mouse over main image fade */
36	jQuery('.img-main, .post-gallery img').mouseover(function() {
37		jQuery(this).stop().animate( { opacity:0.6 }, 200 );
38	}).mouseout(function() {
39		jQuery(this).stop().animate( { opacity:1 }, 200 );
40	});
41
42	/* initialize the category selection on add-new page */
43	if ( jQuery('#step1 .form_step').length > 0 )
44		cp_handle_form_category_select();
45
46	/* initialize the image previewer */
47	imagePreview();
48
49	/* initialize tabs control of sidebar and home page */
50	cp_tab_control();
51
52	/* move welcome widget out of sidebar to the top of home page */
53	jQuery(window).bind( "resize", cp_reposition_widgets );
54	cp_reposition_widgets();
55
56	/* auto complete the search field with tags */
57	jQuery('#s').autocomplete({
58		source: function( request, response ) {
59			jQuery.ajax({
60				url: classipress_params.ajax_url + '?action=ajax-tag-search-front&tax=' + classipress_params.appTaxTag,
61				dataType: 'json',
62				data: {
63					term: request.term
64				},
65				error: function(XMLHttpRequest, textStatus, errorThrown) {
66					//alert('Error: ' + errorThrown + ' - ' + textStatus + ' - ' + XMLHttpRequest);
67				},
68				success: function( data ) {
69					response( jQuery.map( data, function( item ) {
70						return {
71							term: item,
72							value: unescapeHtml(item.name)
73						};
74					}));
75				}
76			});
77		},
78		minLength: 2
79	});
80
81
82	/* add data-rel=colorbox attribute to blog post image links */
83	jQuery(".entry-content a, .post a").each(function(i, el) {
84		var href_value = el.href;
85		if ( /\.(jpg|jpeg|png|gif)$/.test( href_value ) ) {
86			jQuery(this).has('img').attr('data-rel', 'colorbox');
87		}
88	});
89
90	/* assign the ColorBox event to elements */
91	if ( jQuery.isFunction(jQuery.colorbox) ) {
92		jQuery("a[data-rel='colorbox']").colorbox({
93			transition: 'fade',
94			rel: 'colorbox',
95			current: '',
96			scrolling: false,
97			slideshow: false,
98			maxWidth: '100%',
99			maxHeight: '100%',
100			slideshowAuto: false,
101			title: function() { return jQuery(this).find('img').attr('title'); }
102		});
103		jQuery("#mainImageLink").click(function() {
104			jQuery("#thumb1").click();
105		});
106	}
107
108
109	/* hide flash elements on ColorBox load */
110	jQuery(document).bind("cbox_open", function() {
111		jQuery('object, embed, iframe').css({'visibility':'hidden'});
112	});
113	jQuery(document).bind("cbox_closed", function() {
114		jQuery('object, embed, iframe').css({'visibility':'inherit'});
115	});
116
117
118	/* initialize the form validation */
119	if ( jQuery.isFunction(jQuery.fn.validate) ) {
120		// validate profile fields
121		jQuery("#your-profile").validate({errorClass: 'invalid'});
122
123		// sidebar contact form validation
124		jQuery('.form_contact').validate({errorClass: 'invalid'});
125
126		// 'add new' form validation
127		jQuery('.form_step').validate({
128			ignore: '.ignore',
129			errorClass: 'invalid',
130			errorPlacement: function(error, element) {
131				if (element.attr('type') == 'checkbox' || element.attr('type') == 'radio') {
132					element.closest('ol').after(error);
133				} else if ( jQuery.isFunction( jQuery.fn.selectBox ) && element.is('select') ) {
134					if ( jQuery(window).width() > 600 ) {
135						var nextelement = jQuery(element).next();
136						error.insertAfter(nextelement);
137						error.css('display', 'inline-block');
138					} else {
139						error.insertBefore(element);
140					}
141				} else {
142					if ( jQuery(window).width() > 600 ) {
143						error.insertAfter(element);
144						error.css('display', 'inline-block');
145					} else {
146						error.insertBefore(element);
147					}
148				}
149			},
150			highlight: function(element, errorClass, validClass) {
151				jQuery(element).addClass(errorClass).removeClass(validClass);
152				jQuery(element).parent().find('a.selectBox').addClass(errorClass).removeClass(validClass).focus();
153			},
154			unhighlight: function(element, errorClass, validClass) {
155				jQuery(element).removeClass(errorClass).addClass(validClass);
156				jQuery(element).parent().find('a.selectBox').removeClass(errorClass).addClass(validClass);
157			},
158			submitHandler: function() {
159				jQuery('input[type=submit]').attr('disabled', true).attr('value', classipress_params.text_processing ).addClass('clicked');
160				form.submit();
161			}
162
163		});
164
165		// 'edit ad' form validation
166		jQuery(".form_edit").validate({
167			ignore: '.ignore',
168			errorClass: 'invalid',
169			errorPlacement: function(error, element) {
170				if (element.attr('type') == 'checkbox' || element.attr('type') == 'radio') {
171					element.closest('ol').before(error);
172				} else {
173					error.insertBefore(element);
174				}
175				error.css('display', 'block');
176			},
177			highlight: function(element, errorClass, validClass) {
178				jQuery(element).addClass(errorClass).removeClass(validClass);
179				jQuery(element).parent().find('a.selectBox').addClass(errorClass).removeClass(validClass).focus();
180			},
181			unhighlight: function(element, errorClass, validClass) {
182				jQuery(element).removeClass(errorClass).addClass(validClass);
183				jQuery(element).parent().find('a.selectBox').removeClass(errorClass).addClass(validClass);
184			},
185			submitHandler: function() {
186				jQuery('input[type=submit]').attr('disabled', true).attr('value', classipress_params.text_processing ).addClass('clicked');
187				form.submit();
188			}
189			
190		});
191
192		// comment form validation
193		jQuery("#commentform").validate({
194			errorClass: "invalid",
195			errorElement: "div",
196			errorPlacement: function(error, element) {
197				error.insertAfter(element);
198			}
199		});
200		jQuery("#commentform").fadeIn();
201
202	}
203
204	// displays error if images are required and user did not selected any image
205	if ( classipress_params.require_images && typeof window.appFileCount != 'undefined' ) {
206		jQuery('input[type=submit]').on('click', function() {
207			window.appFileCountBrowser = 0;
208			jQuery('input[type="file"]').each(function() {
209				if ( jQuery(this).val() != '' ) {
210					window.appFileCountBrowser += 1;
211				}
212			});
213
214			if ( window.appFileCountBrowser == 0 && window.appFileCount == 0 ) {
215				jQuery( '#app-attachment-upload-container .app-attachment-info .required-image' ).remove();
216				jQuery( '#app-attachment-upload-container .app-attachment-info' ).append( '<p class="error required-image">' + classipress_params.text_require_images + '</p>' );
217				jQuery( '#app-attachment-upload-container .app-attachment-info .required-image' ).delay(5000).fadeOut('slow');
218				return false;
219			}
220		});
221	}
222
223	/* initialize the tooltip */
224	if ( jQuery.isFunction(jQuery.fn.easyTooltip) ) {
225		// tooltip on 'membership' and 'add new' pages
226		jQuery("#mainform a").easyTooltip();
227	}
228
229	/* makes the tables responsive */
230	if ( jQuery.isFunction( jQuery.fn.footable ) ) {
231		jQuery('.footable').footable();
232	}
233});
234
235
236/* Tab Control sidebar and home page */
237function cp_tab_control() {
238	var tabs = [];
239	var tabContainers = [];
240	jQuery('ul.tabnavig a').each(function() {
241		if ( window.location.pathname.match(this.pathname) ) {
242			tabs.push(this);
243			tabContainers.push( jQuery(this.hash).get(0) );
244		}
245	});
246
247	//hide all contrainers except execpt for the one from the URL hash or the first container
248	if ( window.location.hash !== "" && window.location.hash.search('block') >= 0 ) {
249		jQuery(tabContainers).hide().filter(window.location.hash).show();
250		//detecting <a> tab using its "href" which should always equal the hash
251		jQuery(tabs).filter( function(index) {
252			return ( jQuery(this).attr('href') === window.location.hash );
253		}).addClass('selected');
254		jQuery('html').scrollTop( jQuery(window.location.hash).parent().position().top );
255	} else {
256		jQuery(tabContainers).hide().filter(':first').show();
257		jQuery(tabs).filter(':first').addClass('selected');
258	}
259
260	jQuery(tabs).click(function() {
261		// hide all tabs
262		jQuery(tabContainers).hide().filter(this.hash).fadeIn(100);
263		jQuery(tabs).removeClass('selected');
264		jQuery(this).addClass('selected');
265		return false;
266	});
267}
268
269
270// creates previews of images
271function imagePreview() {
272	var xOffset = 10;
273	var yOffset = 30;
274
275	jQuery('a.preview').hover(function(e) {
276		var adTitle = jQuery(this).find('img').attr('alt');
277		jQuery('body').append("<div id='preview'><img src='" + jQuery(this).data('rel') + "' alt='' /><p>" + adTitle + "</p></div>");
278		jQuery('#preview').css('top', (e.pageY - xOffset) + 'px').css('left', (e.pageX + yOffset) + 'px').fadeIn('fast');
279	}, function() {
280		jQuery('#preview').remove();
281	});
282
283	jQuery('a.preview').mousemove(function(e) {
284		jQuery('#preview').css('top', (e.pageY - xOffset) + 'px').css('left', (e.pageX + yOffset) + 'px');
285	});
286}
287
288
289// used to unescape any encoded html passed from ajax json_encode (i.e. &amp;)
290function unescapeHtml(html) {
291	var temp = document.createElement("div");
292	temp.innerHTML = html;
293	var result = temp.childNodes[0].nodeValue;
294	temp.removeChild(temp.firstChild);
295	return result;
296}
297
298
299// highlight search results
300jQuery.fn.extend({
301	highlight: function(search, insensitive, hclass) {
302		var regex = new RegExp("(<[^>]*>)|(\\b"+ search.replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1") +")", insensitive ? "ig" : "g");
303		return this.html(this.html().replace(regex, function(a, b, c) {
304			return ( ( a.charAt(0) === "<" ) ? a : "<span class=\""+ hclass +"\">" + c + "</span>" );
305		}));
306	}
307});
308
309
310/* Form Checkboxes Values Function */
311function addRemoveCheckboxValues(cbval, cbGroupVals) {
312	var a;
313	if ( cbval.checked === true ) {
314		a = document.getElementById(cbGroupVals);
315		a.value += ',' + cbval.value;
316		a.value = a.value.replace(/^\,/, '');
317	} else {
318		a = document.getElementById(cbGroupVals);
319		a.value = a.value.replace(cbval.value + ',', '');
320		a.value = a.value.replace(cbval.value, '');
321		a.value = a.value.replace(/\,$/, '');
322	}
323}
324
325
326/* General Trim Function  */
327function trim(str) {
328	var	str = str.replace(/^\s\s*/, '');
329	var	ws = /\s/;
330	var	i = str.length;
331
332	while (ws.test(str.charAt(--i)));
333	return str.slice(0, i + 1);
334}
335
336
337/* Used for enabling the image for uploads */
338function enableNextImage(a, i) {
339	jQuery('#upload' + i).removeAttr('disabled');
340}
341
342
343/* Position price currency */
344function cp_currency_position( price ) {
345	var position = classipress_params.currency_position;
346	var currency = classipress_params.ad_currency;
347
348	switch ( position ) {
349		case 'left':
350			return currency + price;
351		case 'left_space':
352			return currency + ' ' + price;
353		case 'right':
354			return price + currency;
355		default: // right_space
356			return price + ' ' + currency;
357	}
358
359}
360
361
362/* Handle price slider in refine results widget */
363function cp_show_price_slider( min_price, max_price, min_value, max_value, precise_price ) {
364	max_value = ( ( ! precise_price && max_value <= 1000 ) ? max_price : ( ( precise_price && max_value >= 1000 ) ? 1000 : max_value ) );
365
366	jQuery('#slider-range').slider( {
367		range: true,
368		min: min_price,
369		max: ( ( ! precise_price ) ? max_price : 1000 ),
370		step: 1,
371		values: [ min_value, max_value ],
372		slide: function(event, ui) {
373			jQuery('#amount').val( cp_currency_position( ui.values[0] ) + ' - ' + cp_currency_position( ui.values[1] ) );
374		}
375	});
376
377	jQuery('#amount').val( cp_currency_position( jQuery('#slider-range').slider('values', 0) ) + ' - ' + cp_currency_position( jQuery('#slider-range').slider('values', 1) ) );
378
379}
380
381
382/* Moves welcome widget out of sidebar */
383function cp_reposition_widgets() {
384	if ( jQuery(window).width() > 800 ) {
385		jQuery('.content_left #welcome_widget').prependTo('.content_right');
386		jQuery('.content_left #refine_widget').prependTo('.content_right');
387	} else {
388		jQuery('.content_right #welcome_widget').prependTo('.content_left');
389		jQuery('.content_right #refine_widget').prependTo('.content_left');
390	}
391}
392
393
394/* Used for deleting ad on customer dashboard */
395function confirmBeforeDeleteAd() {
396	return confirm(classipress_params.text_before_delete_ad);
397}
398
399
400/* Used for selecting category on add-new form */
401function cp_handle_form_category_select() {
402	//if on page load the parent category is already selected, load up the child categories
403	jQuery('#catlvl0').attr('level', 0);
404	if ( jQuery('#catlvl0 #ad_cat_id').val() > 0 ) {
405		cp_get_subcategories(jQuery('#catlvl0 #ad_cat_id'), 'catlvl-', 1, classipress_params.ad_parent_posting);
406	}
407
408	//bind the ajax lookup event to #ad_cat_id object
409	jQuery(document).on('change', '#ad_cat_id', function() {
410		currentLevel = parseInt(jQuery(this).parent().attr('level'), 10);
411		cp_get_subcategories(jQuery(this), 'catlvl', currentLevel + 1, classipress_params.ad_parent_posting);
412
413		//rebuild the entire set of dropdowns based on which dropdown was changed
414		jQuery.each(jQuery(this).parent().parent().children(), function(childLevel, childElement) {
415			if ( currentLevel + 1 < childLevel )
416				jQuery(childElement).remove();
417
418			if ( currentLevel + 1 === childLevel )
419				jQuery(childElement).removeClass('hasChild');
420		});
421
422		//find the deepest selected category and assign the value to the "chosenCateory" field
423		if ( jQuery(this).val() > 0 ) {
424			jQuery('#chosenCategory input:first').val(jQuery(this).val());
425		} else if ( jQuery('#catlvl' + ( currentLevel - 1 ) + ' select').val() > 0) {
426			jQuery('#chosenCategory input:first').val(jQuery('#catlvl' + ( currentLevel - 1 ) + ' select').val());
427		} else {
428			jQuery('#chosenCategory input:first').val('-1');
429		}
430	});
431}
432
433
434function cp_get_subcategories(dropdown, results_div_id, level, allow_parent_posting) {
435	parent_dropdown = jQuery(dropdown).parent();
436	category_ID = jQuery(dropdown).val();
437	results_div = results_div_id + level;
438	if ( ! jQuery(parent_dropdown).hasClass('hasChild') ) {
439		jQuery(parent_dropdown).addClass('hasChild').parent().append('<div id="' + results_div + '" level="' + level + '" class="childCategory"></div>');
440	}
441
442	jQuery.ajax({
443		type: 'POST',
444		url: classipress_params.ajax_url + "?action=dropdown-child-categories",
445		dataType: "json",
446		data: {
447			cat_id : category_ID
448		},
449		//show loading just when dropdown changed
450		beforeSend: function() {
451			jQuery('#getcat').hide();
452			jQuery('#ad-categories-footer').addClass('ui-autocomplete-loading').slideDown("fast");
453		},
454		//stop showing loading when the process is complete
455		complete: function() {
456			jQuery('#ad-categories-footer').removeClass('ui-autocomplete-loading');
457		},
458		error: function(XMLHttpRequest, textStatus, errorThrown){
459			//alert( 'Error: ' + errorThrown + ' - ' + textStatus + ' - ' + XMLHttpRequest );
460		},
461		// if data is retrieved, store it in html
462		success: function( data ) {
463			// child categories found so build and display them
464			if ( data.success === true ) {
465				jQuery('#' + results_div).html( data.html ).slideDown("fast");
465 //build html from ajax post
466				if ( level === 1 ) {
467					whenEmpty = false;
468				} else {
469					whenEmpty = true;
470				}
471			// if no categories are found
472			} else {
473				jQuery('#' + results_div).slideUp("fast");
474				if ( jQuery(dropdown).val() === -1 && level === 2 ) {
475					whenEmpty = false;
476				} else {
477					whenEmpty = true;
478				}
479			}
480
481			// always check if go button should be on or off, jQuery parent is used for traveling backup the category heirarchy
482			if ( ( allow_parent_posting === 'yes' && jQuery('#chosenCategory input:first').val() > 0) ) {
483				jQuery('#getcat').fadeIn();
484			//check for empty category option
485			} else if ( whenEmpty && allow_parent_posting === 'whenEmpty' && jQuery('#chosenCategory input:first').val() > 0 ) {
486				jQuery('#getcat').fadeIn();
487			//if child category exists, is set, and allow_parent_posting not set to "when empty"
488			} else if ( jQuery('#' + results_div_id + (level-1)).hasClass('childCategory') && jQuery(dropdown).val() > -1 && allow_parent_posting === 'no' ) {
489				jQuery('#getcat').fadeIn();
490			} else {
491				jQuery('#getcat').fadeOut();
492			}
493
494		}
495	});
496}
497

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.