/* * ClassiPress theme jQuery functions * Written by AppThemes * http://www.appthemes.com * * Left .js uncompressed so it's easier to customize */ jQuery(document).ready(function($) { /* style the select dropdown menus */ if ( jQuery.isFunction( jQuery.fn.selectBox ) ) { jQuery('select').selectBox({ menuTransition: 'fade', // default, slide, fade menuSpeed: 'fast' }); /* do not apply in step1 of add new listing form */ jQuery('.form_step #ad-categories select').selectBox('destroy'); /* do not apply in report listing form */ jQuery('.reports_form select').selectBox('destroy'); } /* convert header menu into select list on mobile devices */ if ( jQuery.isFunction( jQuery.fn.tinyNav ) ) { jQuery('.header_menu_res .menu').tinyNav({ active: 'current-menu-item', header: classipress_params.text_mobile_navigation, header_href: classipress_params.home_url, indent: '-', excluded: ['#adv_categories'] }); } /* mouse over main image fade */ jQuery('.img-main, .post-gallery img').mouseover(function() { jQuery(this).stop().animate( { opacity:0.6 }, 200 ); }).mouseout(function() { jQuery(this).stop().animate( { opacity:1 }, 200 ); }); /* initialize the category selection on add-new page */ if ( jQuery('#step1 .form_step').length > 0 ) cp_handle_form_category_select(); /* initialize the image previewer */ imagePreview(); /* initialize tabs control of sidebar and home page */ cp_tab_control(); /* move welcome widget out of sidebar to the top of home page */ jQuery(window).bind( "resize", cp_reposition_widgets ); cp_reposition_widgets(); /* auto complete the search field with tags */ jQuery('#s').autocomplete({ source: function( request, response ) { jQuery.ajax({ url: classipress_params.ajax_url + '?action=ajax-tag-search-front&tax=' + classipress_params.appTaxTag, dataType: 'json', data: { term: request.term }, error: function(XMLHttpRequest, textStatus, errorThrown) { //alert('Error: ' + errorThrown + ' - ' + textStatus + ' - ' + XMLHttpRequest); }, success: function( data ) { response( jQuery.map( data, function( item ) { return { term: item, value: unescapeHtml(item.name) }; })); } }); }, minLength: 2 }); /* add data-rel=colorbox attribute to blog post image links */ jQuery(".entry-content a, .post a").each(function(i, el) { var href_value = el.href; if ( /\.(jpg|jpeg|png|gif)$/.test( href_value ) ) { jQuery(this).has('img').attr('data-rel', 'colorbox'); } }); /* assign the ColorBox event to elements */ if ( jQuery.isFunction(jQuery.colorbox) ) { jQuery("a[data-rel='colorbox']").colorbox({ transition: 'fade', rel: 'colorbox', current: '', scrolling: false, slideshow: false, maxWidth: '100%', maxHeight: '100%', slideshowAuto: false, title: function() { return jQuery(this).find('img').attr('title'); } }); jQuery("#mainImageLink").click(function() { jQuery("#thumb1").click(); }); } /* hide flash elements on ColorBox load */ jQuery(document).bind("cbox_open", function() { jQuery('object, embed, iframe').css({'visibility':'hidden'}); }); jQuery(document).bind("cbox_closed", function() { jQuery('object, embed, iframe').css({'visibility':'inherit'}); }); /* initialize the form validation */ if ( jQuery.isFunction(jQuery.fn.validate) ) { // validate profile fields jQuery("#your-profile").validate({errorClass: 'invalid'}); // sidebar contact form validation jQuery('.form_contact').validate({errorClass: 'invalid'}); // 'add new' form validation jQuery('.form_step').validate({ ignore: '.ignore', errorClass: 'invalid', errorPlacement: function(error, element) { if (element.attr('type') == 'checkbox' || element.attr('type') == 'radio') { element.closest('ol').after(error); } else if ( jQuery.isFunction( jQuery.fn.selectBox ) && element.is('select') ) { if ( jQuery(window).width() > 600 ) { var nextelement = jQuery(element).next(); error.insertAfter(nextelement); error.css('display', 'inline-block'); } else { error.insertBefore(element); } } else { if ( jQuery(window).width() > 600 ) { error.insertAfter(element); error.css('display', 'inline-block'); } else { error.insertBefore(element); } } }, highlight: function(element, errorClass, validClass) { jQuery(element).addClass(errorClass).removeClass(validClass); jQuery(element).parent().find('a.selectBox').addClass(errorClass).removeClass(validClass).focus(); }, unhighlight: function(element, errorClass, validClass) { jQuery(element).removeClass(errorClass).addClass(validClass); jQuery(element).parent().find('a.selectBox').removeClass(errorClass).addClass(validClass); }, submitHandler: function(form) { setTimeout(function () { jQuery('input[type=submit]').attr('disabled', true).attr('value', classipress_params.text_processing ).addClass('clicked'); }, 1); form.submit(); } }); // 'edit ad' form validation jQuery(".form_edit").validate({ ignore: '.ignore', errorClass: 'invalid', errorPlacement: function(error, element) { if (element.attr('type') == 'checkbox' || element.attr('type') == 'radio') { element.closest('ol').before(error); } else { error.insertBefore(element); } error.css('display', 'block'); }, highlight: function(element, errorClass, validClass) { jQuery(element).addClass(errorClass).removeClass(validClass); jQuery(element).parent().find('a.selectBox').addClass(errorClass).removeClass(validClass).focus(); }, unhighlight: function(element, errorClass, validClass) { jQuery(element).removeClass(errorClass).addClass(validClass); jQuery(element).parent().find('a.selectBox').removeClass(errorClass).addClass(validClass); }, submitHandler: function(form) { setTimeout(function () { jQuery('input[type=submit]').attr('disabled', true).attr('value', classipress_params.text_processing ).addClass('clicked'); }, 1); form.submit(); } }); // comment form validation jQuery("#commentform").validate({ errorClass: "invalid", errorElement: "div", errorPlacement: function(error, element) { error.insertAfter(element); } }); jQuery("#commentform").fadeIn(); } // displays error if images are required and user did not selected any image if ( classipress_params.require_images && typeof window.appFileCount != 'undefined' ) { jQuery('input[type=submit]').on('click', function() { window.appFileCountBrowser = 0; jQuery('input[type="file"]').each(function() { if ( jQuery(this).val() != '' ) { window.appFileCountBrowser += 1; } }); if ( window.appFileCountBrowser == 0 && window.appFileCount == 0 ) { jQuery( '#app-attachment-upload-container .app-attachment-info .required-image' ).remove(); jQuery( '#app-attachment-upload-container .app-attachment-info' ).append( '
' + classipress_params.text_require_images + '
' ); jQuery( '#app-attachment-upload-container .app-attachment-info .required-image' ).delay(5000).fadeOut('slow'); return false; } }); } /* initialize the tooltip */ if ( jQuery.isFunction(jQuery.fn.easyTooltip) ) { // tooltip on 'membership' and 'add new' pages jQuery("#mainform a").easyTooltip(); } /* makes the tables responsive */ if ( jQuery.isFunction( jQuery.fn.footable ) ) { jQuery('.footable').footable(); } /* toggle reports form */ jQuery(".edit a.reports_form_link").on( "click", function() { jQuery(this).parent().parent().find(".reports_form").slideToggle( 400 ); return false; }); }); /* Tab Control sidebar and home page */ function cp_tab_control() { var tabs = []; var tabContainers = []; jQuery('ul.tabnavig a').each(function() { if ( window.location.pathname.match(this.pathname) ) { tabs.push(this); tabContainers.push( jQuery(this.hash).get(0) ); } }); //hide all contrainers except execpt for the one from the URL hash or the first container if ( window.location.hash !== "" && window.location.hash.search('block') >= 0 ) { jQuery(tabContainers).hide().filter(window.location.hash).show(); //detecting tab using its "href" which should always equal the hash jQuery(tabs).filter( function(index) { return ( jQuery(this).attr('href') === window.location.hash ); }).addClass('selected'); jQuery('html').scrollTop( jQuery(window.location.hash).parent().position().top ); } else { jQuery(tabContainers).hide().filter(':first').show(); jQuery(tabs).filter(':first').addClass('selected'); } jQuery(tabs).click(function() { // hide all tabs jQuery(tabContainers).hide().filter(this.hash).fadeIn(100); jQuery(tabs).removeClass('selected'); jQuery(this).addClass('selected'); return false; }); } // creates previews of images function imagePreview() { var xOffset = 10; var yOffset = 30; jQuery('a.preview').hover(function(e) { var adTitle = jQuery(this).find('img').attr('alt'); jQuery('body').append("" + adTitle + "