var fullHobbieslist = true; var suggestionsAction = false; var currentObj = false; var initFilterResponce = function() { var slide = function(amount) { var content = $('#hobbiesContent'), container = $('#hobbiesContainer'), delta = container.actual('height') - content.actual('outerHeight'); if (delta < 0) { content.css('marginTop', delta*(1-amount/100)); } } $( "#hobbiesContainer #scrollSlider" ).slider({ value: 100, orientation: "vertical", min: 0, max: 100, step: 1, slide: function( event, ui ) { slide(ui.value); }, change: function( event, ui ) { slide(ui.value); } }); $('#hobbiesContainer').mousewheel(function(e, delta){ delta *= 5; var obj = $( "#scrollSlider" ); var newVal = obj.slider('option', 'value') + delta; newVal = Math.max(obj.slider('option', 'min'), Math.min(obj.slider('option', 'max'),newVal)); obj.slider('option', 'value', newVal); return false; }); var content = $('#hobbiesContent'), container = $('#hobbiesContainer'), delta = container.actual('height') - content.actual('outerHeight'); if (delta < 0) { $('#hobbiesContainer #scrollSlider').show(); } else { $('#hobbiesContainer #scrollSlider').hide(); } $('#hobbiesContainer input:checkbox').live('change', function(){countSelectedHobbies();}); }; var countSelectedHobbies = function(){ var count = $('#hobbiesContainer input:checkbox:checked').length; $('#hobbiesCountResult span').text(count); if(count > 0 && count < 6) { $('#objectSearch').button('enable').attr('title', '').tooltip({showURL: false, blocked: true}); } else { var title = (count > 5) ? Travvi.s('js.select_up_to_5_hobbies') : Travvi.s('js.hobbies_not_selected'); $('#objectSearch').button('disable').attr('title', title).tooltip({showURL: false, blocked: false}); } } jQuery(function($) { var slideIgnored = function(amount) { var content = $('#ignoredHobbiesContent'), container = $('#ignoredHobbiesContainer'), delta = container.actual('height') - content.actual('outerHeight'); if (delta < 0) { content.css('marginTop', delta*(1-amount/100)); } } $( "#igonredScrollSlider" ).slider({ value: 100, orientation: "vertical", min: 0, max: 100, step: 1, slide: function( event, ui ) { slideIgnored(ui.value); }, change: function( event, ui ) { slideIgnored(ui.value); } }); $('#ignoredHobbiesContainer').mousewheel(function(e, delta){ delta *= 5; var obj = $( "#igonredScrollSlider" ); var newVal = obj.slider('option', 'value') + delta; newVal = Math.max(obj.slider('option', 'min'), Math.min(obj.slider('option', 'max'),newVal)); obj.slider('option', 'value', newVal); return false; }); var content = $('#ignoredHobbiesContent'), container = $('#ignoredHobbiesContainer'), delta = container.actual('height') - content.actual('outerHeight'); if (delta < 0) { $('#ignoredHobbiesContainer #igonredScrollSlider').show(); } else { $('#ignoredHobbiesContainer #igonredScrollSlider').hide(); } $('#dialog-skillForm').dialog({ autoOpen: false, width: 374, position: ['center', 'center'], height: 'auto', modal: true, resizable: false, draggable: false, open: function(){ $('#hobbyName').empty(); $('#dialog-skillForm select').data('selectik').changeCS({index: 1}); $(document).keydown(function(e){ if (e.keyCode == 13) { $('#dialog-skillForm .ok').click(); return false; } }); } }); $('#dialog-skillForm a').button(); $('#dialog-skillForm select').selectik({width: 300}); $('#dialog-skillForm a.cancel').click(function(){ $('#dialog-skillForm').dialog('close'); return false; }); $('.checkboxed input').checkbox({ empty: '/skin/images/empty.png'}); $('#dialog-skillForm a.ok').click(function(){ $('#dialog-skillForm').dialog('close'); var successfullyAdded = false; $.ajax({ url: '/interests/add', type: 'post', data: { hobbyId: currentObj.data('hobby_id'), skillId: $('#skillId').val()}, success: function(data) { eval(data); if(successfullyAdded) { $.each(ids, function(key, value){ current = $('#hobbies_'+value); current.parent().find('a.add').addClass('active').tooltip({bodyHandler: function() { return Travvi.s('js.in_my_hobbies'); }, showURL: false}); current.parent().find('a.delete').addClass('notClickable').tooltip({bodyHandler: function() { return Travvi.s('js.in_my_hobbies'); }, showURL: false}); }); } } }); return false; }); $('#accordion h3').click(function() { $(this).toggleClass('expanded').next().toggle('slow'); return false; }).next().hide(); $('#resultsButton').button().click(function(){ var isHidden = $('#accordion ul:hidden'); $('#accordion ul').show(); $('html, body').animate({ scrollTop: $("#hobbiesContainer").offset().top }, 2000); var serialized = $('#filterForm').serialize(); isHidden.hide(); var checked = []; $('#filterResponce .hobby').each(function(){ if($('input:checkbox', $(this)).is(':checked')) checked.push($(this)); }); checked.reverse(); $.ajax({ url: $('#filterForm').attr('action'), type: 'post', data: serialized, success: function(data) { $('#filterResponce').html(data); $.each(checked, function(){ $('#' + this.find('input:checkbox').attr('id'), $('#hobbiesContent')).parent().remove(); this.prependTo($('#hobbiesContent')); this.find('input:checkbox').checkbox({ empty: '/skin/images/empty.png'}); }); countSelectedHobbies(); } }); return false; }); var processCheckboxes = function(){ var sectionEmpty = false; if(!$('#includeMyHobbies').is(':checked')) { $('#accordion ul').each(function(){ if($('input:checkbox:checked', $(this)).length == 0) sectionEmpty = true; }); } if(sectionEmpty) { $('#resultsButton').button( "disable" ).attr('title', Travvi.s('js.for_displaying_on_selected_params_select_at_least_one_value_from_evere_section')).tooltip({showURL: false, blocked: false}); } else { $('#resultsButton').button( "enable" ).attr('title', '').tooltip({blocked: true}); } sectionEmpty = false; } $('#accordion input:checkbox').change(processCheckboxes).checkbox({ empty: '/skin/images/empty.png'}); $('#includeMyHobbies').change(processCheckboxes); $('.mass_check').change(function(){ var list = $('ul.'+$(this).attr('id').split('_')[0]); if($(this).is(':checked')) { $('input:checkbox', list).attr('checked', true); } else { $('input:checkbox', list).attr('checked', false); } processCheckboxes(); }); $('#searchHobby').keyup(function(){ var inputString = $(this).val(); if(inputString.length < 3) { $('#suggestionsContainer').fadeOut(); } else { $.post("/interests/find", {queryString: ""+inputString+"", fullSearch: fullHobbieslist ? 1 : 0}, function(data) { $('#suggestionsContainer').fadeIn(); $('#suggestions').html(data); }); } }).blur(function(){ if(!suggestionsAction) $('#suggestionsContainer').fadeOut(); }).focus(function(){ if($(this).val().length > 2) { $('#suggestionsContainer').fadeIn(); $(window).resize(); } }); var slideSuggestions = function(amount) { var content = $('#suggestions'), container = $('#suggestionsContainer'), delta = container.actual('height') - content.actual('outerHeight'); if (delta < 0) { content.css('marginTop', delta*(1-amount/100)); console.log(amount); } } $('#suggestionsSlider').slider({ value: 100, orientation: "vertical", min: 0, max: 100, step: 1, slide: function( event, ui ) { slideSuggestions(ui.value); }, change: function( event, ui ) { slideSuggestions(ui.value); } }); $('#suggestionsContainer').mousewheel(function(e, delta){ delta *= 5; var obj = $( "#suggestionsSlider" ); var newVal = obj.slider('option', 'value') + delta; newVal = Math.max(obj.slider('option', 'min'), Math.min(obj.slider('option', 'max'),newVal)); obj.slider('option', 'value', newVal); return false; }).hover(function(){ suggestionsAction = true; }, function(){ suggestionsAction = false; }); $(window).resize(function(){ var content = $('#suggestions'), container = $('#suggestionsContainer'); if(!$('#suggestions').length || !$('#suggestionsContainer')) return false; var screenHeight = $(window).height() - container.offset().top -30; container.css('height', Math.min(screenHeight, content.actual('outerHeight') + parseInt(container.css('padding-top')) + parseInt(container.css('padding-bottom')) )); var delta = container.actual('height') - content.actual('outerHeight'); if (delta < 0) { $('#suggestionsSlider').show(); $('#suggestionsSlider').height(container.actual('outerHeight') - 30); } else { $('#suggestionsSlider').hide(); } if($('#hobbiesContent').actual('height') - $('#hobbiesContainer').actual('outerHeight') > 0) { $( "#scrollSlider" ).show(); } else { $( "#scrollSlider" ).hide(); } }); initFilterResponce(); $('.hobby a.name').live('click', function(){ return false; }); $('#interestsMainContainer .hobby a.add').live('click', function(){ var obj = $(this); if(obj.hasClass('notClickable') || obj.hasClass('active')) { return false; } currentObj = obj; $('#dialog-skillForm').dialog('open'); $('#hobbyName').text(obj.parent().find('a.name').text()); return false; }); $('#interestsMainContainer .hobby a.delete').live('click', function(){ var obj = $(this); if(obj.hasClass('notClickable')) { return false; } var successfullyBlocked = false; var successfullyUnblocked = false; $.ajax({ url: '/interests/block', type: 'post', data: { hobbyId: obj.data('hobby_id')}, success: function(data) { eval(data); if(successfullyBlocked) { $.each(ids, function(key, value){ current = $('#hobbies_'+value); current.parent().find('a.delete').addClass('active').tooltip({bodyHandler: function() { return Travvi.s('js.invitations_on_this_hobby_is_blocked'); }, showURL: false}); }); } if(successfullyUnblocked) { $.each(ids, function(key, value){ current = $('#hobbies_'+value); current.parent().find('a.delete').removeClass('active').tooltip({bodyHandler: function() { return Travvi.s('js.block_invitations_on_this_hobby'); }, showURL: false}); }); } } }); return false; }); Spinner.hide(); $(window).resize(function() { $('#dialog-skillForm').dialog('option', {position: ['center', 'center']}); }); $('#suggestions li').live('click', function() { var html; if(!$('#hobbies_' + $(this).data('id')).length) { $('#hobbiesContent span.message').remove(); html = '
'; html += ''; if($(this).data('in_list') == 'blocked') { html += ' '; html += ' '; } else if($(this).data('in_list') == 'unblocked') { html += ' '; html += ' '; } else if($('#logoutCaller').length) { html += ' '; html += ' '; } else { html += ' '; html += ' '; } html += ' ' + $(this).data('name') + ''; html += '
'; $('#hobbiesContent').prepend(html); $('#hobbies_' + $(this).data('id')).checkbox({ empty: '/skin/images/empty.png'}); $(window).resize(); $('#hobbiesContainer input:checkbox').first().change(); $('.hobby.justAdded .jquery-checkbox').attr('title', Travvi.s('js.select')).tooltip({showURL: false}); $('.hobby .justAdded').tooltip({showURL: false}).removeClass('justAdded'); $('.hobby.justAdded').removeClass('justAdded'); } else { $('#hobbies_' + $(this).data('id')).attr('checked', true).change(); } $('#suggestionsContainer').hide(); flushSpinnerMessage(Travvi.s('js.hobby_named_%s_selected_for_further_processing', $(this).data('name'))); }); if($('#accordion h3').length) $('#accordion h3').first().click(); $('#objectSearch').button({disabled: true}).tooltip({showURL: false, blocked: false}).click(function(){ var ids = []; $('#hobbiesContainer input:checkbox:checked').each(function(){ $('').attr({ name: 'hobbyIds[]', value: $(this).attr('id').replace('hobbies_', '') }).appendTo('#searchForm'); }); $('#searchForm').submit(); return false; }); $('#eventSearch').button({disabled: true}).tooltip({showURL: false, blocked: false}); });