| 1 |
function toggleDepartmentFields() |
| 2 |
{ |
| 3 |
if (jQuery('form.property-search-form').length > 0) |
| 4 |
{ |
| 5 |
// There may be multiple forms on the page so treat each one individually |
| 6 |
jQuery('form.property-search-form').each(function() |
| 7 |
{ |
| 8 |
var selectedDepartment = "residential-sales"; // TODO: Use default from settings |
| 9 |
|
| 10 |
var departmentEl = jQuery(this).find('[name=\'department\']') |
| 11 |
if (departmentEl.length > 0) |
| 12 |
{ |
| 13 |
switch (departmentEl.prop('tagName').toLowerCase()) |
| 14 |
{ |
| 15 |
case "select": |
| 16 |
{ |
| 17 |
var selected = departmentEl; |
| 18 |
break; |
| 19 |
} |
| 20 |
default: |
| 21 |
{ |
| 22 |
if ( departmentEl.attr('type') == 'hidden' ) |
| 23 |
{ |
| 24 |
var selected = departmentEl; |
| 25 |
} |
| 26 |
else |
| 27 |
{ |
| 28 |
var selected = departmentEl.filter(':checked'); |
| 29 |
} |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
jQuery(this).find('.sales-only').hide(); |
| 35 |
jQuery(this).find('.lettings-only').hide(); |
| 36 |
jQuery(this).find('.residential-only').hide(); |
| 37 |
jQuery(this).find('.commercial-only').hide(); |
| 38 |
|
| 39 |
if (selected.length > 0) |
| 40 |
{ |
| 41 |
selectedDepartment = selected.val(); |
| 42 |
|
| 43 |
// controls won't always be display:block so we should get the |
| 44 |
// first visible component (that isnt sales/lettings-only) and |
| 45 |
// use that display |
| 46 |
var display = 'block'; |
| 47 |
var found = false; |
| 48 |
jQuery(this).find('.control').each(function() |
| 49 |
{ |
| 50 |
if (!jQuery(this).hasClass('.sales-only') && !jQuery(this).hasClass('.lettings-only') && !jQuery(this).hasClass('.residential-only') && !jQuery(this).hasClass('.commercial-only') && jQuery(this).css('display') != 'none') |
| 51 |
{ |
| 52 |
display = jQuery(this).css('display'); |
| 53 |
found = true; |
| 54 |
} |
| 55 |
}); |
| 56 |
|
| 57 |
if (found == false) |
| 58 |
{ |
| 59 |
if (jQuery(this).css('display') == 'table') |
| 60 |
{ |
| 61 |
display = 'table-cell'; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
if (selectedDepartment == 'residential-sales') |
| 66 |
{ |
| 67 |
jQuery(this).find('.sales-only').css('display', display); |
| 68 |
jQuery(this).find('.residential-only').css('display', display); |
| 69 |
} |
| 70 |
else if (selectedDepartment == 'residential-lettings') |
| 71 |
{ |
| 72 |
jQuery(this).find('.lettings-only').css('display', display); |
| 73 |
jQuery(this).find('.residential-only').css('display', display); |
| 74 |
} |
| 75 |
else if (selectedDepartment == 'commercial') |
| 76 |
{ |
| 77 |
jQuery(this).find('.commercial-only').css('display', display); |
| 78 |
} |
| 79 |
|
| 80 |
if ( jQuery(this).find('[name=\'availability\']').length > 0 && typeof availability_departments !== "undefined" ) |
| 81 |
{ |
| 82 |
if ( Object.keys(availability_departments).length > 0 ) |
| 83 |
{ |
| 84 |
jQuery(this).find('[name=\'availability\']').empty(); |
| 85 |
|
| 86 |
for ( var i in availabilities_order ) |
| 87 |
{ |
| 88 |
var availability_id = availabilities_order[i]; |
| 89 |
var availability_text = availabilities[availabilities_order[i]]; |
| 90 |
|
| 91 |
var this_availability_departments = []; |
| 92 |
var availability_departments_exist = true; |
| 93 |
if ( typeof availability_departments[availability_id] !== 'undefined' ) |
| 94 |
{ |
| 95 |
this_availability_departments = availability_departments[availability_id]; |
| 96 |
} |
| 97 |
else |
| 98 |
{ |
| 99 |
availability_departments_exist = false; |
| 100 |
} |
| 101 |
|
| 102 |
if ( jQuery.inArray( selectedDepartment, this_availability_departments ) > -1 || !availability_departments_exist ) |
| 103 |
{ |
| 104 |
jQuery(this).find('[name=\'availability\']').append( jQuery("<option />").val(availability_id).text(availability_text) ); |
| 105 |
} |
| 106 |
jQuery(this).find('[name=\'availability\']').val(selected_availability); |
| 107 |
} |
| 108 |
if ( jQuery(this).find('[name=\'availability\']').val() == '' || jQuery(this).find('[name=\'availability\']').val() == null ) |
| 109 |
{ |
| 110 |
jQuery(this).find('[name=\'availability\']').val( jQuery(this).find('[name=\'availability\'] option:first').val() ); |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
}); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
jQuery( function(jQuery){ |
| 120 |
|
| 121 |
// Orderby |
| 122 |
jQuery( '.propertyhive-ordering' ).on( 'change', 'select.orderby', function() { |
| 123 |
jQuery( this ).closest( 'form' ).submit(); |
| 124 |
}); |
| 125 |
|
| 126 |
toggleDepartmentFields(); |
| 127 |
|
| 128 |
jQuery('form.property-search-form [name=\'department\']').change(function() |
| 129 |
{ |
| 130 |
toggleDepartmentFields(); |
| 131 |
}); |
| 132 |
|
| 133 |
if ( jQuery('form.property-search-form select.ph-form-multiselect').length > 0 ) |
| 134 |
{ |
| 135 |
jQuery('form.property-search-form select.ph-form-multiselect').each(function() |
| 136 |
{ |
| 137 |
jQuery(this).multiselect({ |
| 138 |
texts: { |
| 139 |
placeholder: jQuery(this).data('blank-option') |
| 140 |
} |
| 141 |
}); |
| 142 |
}); |
| 143 |
} |
| 144 |
}); |
| 145 |
|
| 146 |
jQuery(window).resize(function() { |
| 147 |
toggleDepartmentFields(); |
| 148 |
}); |