$(document).ready(function() { $('.inviteToGroupBtn').on('click', function() { lightboxAJAX('/lightbox/invite_to_group?lightbox=1&group_id='+$(this).data('group-id')); }); $('.usergroupCTA').on('click', function() { var $this = $(this); $.ajax({ url: '/restapi/usergroup_access.json', type: 'post', data: { user_id: $this.data('user'), group_id: $this.data('group'), action: $this.data('role') } }).done(function(response) { if (response.success) { $this.closest('.userItem').fadeOut(); } }); }); //Change Value of GroupDropdown $('#groupDropdown a').live('click', function(){ $('#groupDropdown input').val($(this).attr('value')); }); $('.groupCTA').on('click', function() { var $this = $(this); $.ajax({ url: '/restapi/toggle_user_group.json', type: 'post', data: { groupId: $this.data('group-id'), replaceHandler: $this.data('replace-handler') }, cache: false }).done(function(response) { $this.html(response.buttonText); if (!response.replaceHandler) { $this.removeClass('groupCTA').off(); } }); }); $('#locationDropdown').on('focus', function(e) { var $this = $(this); setTimeout(function() { if ($this.find('.clicked').length === 0) { $this.find('.arrow').trigger('click'); $this.find('input[name="location"]').focus(); } }, 200); }); // HIDE NAV BAR FOR MOBILE if(mobile) { $(window).scrollTop(0); } // EDITABLE TOUT STUFF $('.editable-tout').editable('/restapi/post_edit_tout_comment', { type: 'textarea', indicator: 'Saving...', tooltip: 'Click to edit...', onblur: 'submit' }); // WELCOME SCREEN SLIDER STUFF $('.imageSide ul').roundabout({ minOpacity: 1, maxOpacity: 1, duration: 800, autoplay: true, autoplayDuration: 6000, autoplayPauseOnHover: true, reflect: true }); /* slideCount = $('#welcome table.slides td.top .slide').length; if(slideCount > 0) { currentSlide = parseInt($('#welcome table.slides td.top .slide.active').attr('slide')); activateSlider(); $('a.arrow').live('click', function() { arrow = $(this); if(arrow.hasClass('left')) { changeSlideWithFades(currentSlide-1); } else { changeSlideWithFades(); } }); } */ // ONLY LOADS ON <= IE9 if (window.PIE) { $('.dashboard, .item .mainbox ul.ctaButtons a, #locationDropdown span, #search input, #nav .menu, #feedFilters').each(function() { PIE.attach(this); }); } // QUERY ONLOAD() onloadEvents = getParameterByName('onload'); if(onloadEvents) { lightboxAJAX(decodeURIComponent(onloadEvents)); } // SEARCH STUFF activateSearchbar(); // ACTIVATE BACK TO TOP BUTTON back_to_top(); // activate FEEDS HOVER BUTTONS activateFeedsHoverButtons(); // SET DROP DOWN SORT SELECTION //set_dd_selection();RVS - comment this out now, but keeping just in case // USER THUMBNAIL STUFF $('a.userThumb, a.metaName, a.questionDetail, a.userThumbSmall').live('mouseenter', function(e) { var name = $(this).attr('networklink'); if (typeof name !== 'undefined' && name !== false) { $(''+name+'').prependTo('body').css({ 'top': e.pageY+10, 'left': e.pageX+10 }).show(); } }).live('mouseleave', function(e) { $('#userNameHover').remove(); }).live('mousemove', function(e) { $('#userNameHover').css({ 'top': e.pageY+10, 'left': e.pageX+10 }); }); // RESPONSES HOVER STUFF $('.mainbox', '.responses').live('mouseenter', function(e) { var name = $(this).attr('hovertext'); if (typeof name !== 'undefined' && name !== false) { $(''+name+'').prependTo('body').css({ 'top': e.pageY+10, 'left': e.pageX+10 }).show(); } }).live('mouseleave', function(e) { $('#userNameHover2').remove(); }).live('mousemove', function(e) { $('#userNameHover2').css({ 'top': e.pageY+10, 'left': e.pageX+10 }); }); // FOLLOW BUTTON STUFF $('a.followButton').live('mouseenter', function(e) { var name = $(this).attr('hovertext'); if (typeof name !== 'undefined' && name !== false) { $(''+name+'').prependTo('body').css({ 'top': e.pageY+10, 'left': e.pageX+10 }).show(); } }).live('mouseleave', function(e) { $('#userNameHover').remove(); }).live('mousemove', function(e) { $('#userNameHover').css({ 'top': e.pageY+10, 'left': e.pageX+10 }); }); $('a.followButton').live('click', function(e) { followUnfollow($(this), 'follow'); }); $('a.unfollowButton').live('click', function(e) { followUnfollow($(this), 'unfollow'); }); function followUnfollow(obj, action) { $.ajax({ url: '/restapi/'+action+'_question.json', type: 'post', data: { 'question_id' : obj.attr('id').split('_')[1] }, dataType: 'json', cache: false, success: function(response) { if (response.success) { if (action === 'follow') { obj.addClass('unfollowButton').html('Unfollow'); } else if (action === 'unfollow') { obj.removeClass('unfollowButton').html('Follow'); } } else if (!response.success && !td_globals.lgd_in) { lightboxAJAX('/lightbox/signup_login?lightbox=1'); } } }); } // TIMEAGO STUFF // $('.timeago').each(function() { // $(this).timeago(); // }); render_time_ago(); // CALL TO ACTION BUTTONS ON ITEMS STUFF $('.item .mainbox ul.ctaButtons a, .item .mainbox ul.ctaButtons span').live('mouseenter', function() { $(this).stop(true, false).animate({ 'left': '0' }, 300); }).live('mouseleave', function() { $(this).stop(true, false).animate({ 'left': '-155px' }, 300); }); $(document).on('keyup', 'form', function(e) { if (e.keyCode === 13 && $(this).attr('id') != 'ask' && $(this).attr('id') != 'thing') { $(this).find('a.submitButton').trigger('click'); } }); // DROPDOWN STUFF bindDropdown('.dropdown'); bindSelect('select[class!="chzn-select"], input[type="checkbox"]'); // ACTIVATE AUTOSUGGEST // activateAutoSuggest(); // INPUT STUFF $('input[type=text], input[type=password]').live('focusin',function() { $(this).addClass('focused'); if($(this).hasClass('default')) { $(this).attr('placeholder', ''); } }).live('focusout',function() { $(this).removeClass('focused'); if($(this).val() == '') { var dtext = $(this).attr('dtext'); if(dtext){ $(this).attr('placeholder', dtext).addClass('default'); } } else { $(this).removeClass('default').removeClass('error').closest('.error').removeClass('error').find('p.error').remove(); $('.errorMsg').stop(true, true).fadeOut(400); } }); if ($('input[name="location"]').val() != "") { $('#locationDropdown').find('span').html($('input[name="location"]').val()); } else { $('#locationDropdown').find('span').html('Add a location'); } $('input[name="location"]').live('keyup', function(e) { locationInput = $(this); locationHidden = $(this).parent().find('input[name="location_id"]'); if($(this).val().length >= 3) { var locations = []; dropdown = false; appendResults = locationInput.parent(); if(locationInput.closest('ul#locations').length > 0) { dropdown = true; var locationDropdown = $(this).closest('.dropdown'); var locationSpan = locationDropdown.find('span'); appendResults = $('#locationResults'); } geocoder.geocode({ address : locationInput.val() }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { if(typeof results !== 'undefined' && results.length > 0) { $.each(results, function (index, value) { locations.push({ label: value.formatted_address, value: value }); }); } locationInput.autocomplete({ source: function( request, response ) { response(locations); }, appendTo: appendResults, my: "left top", at: "left bottom", collision: "none", delay: 400, open: function() { // menu = locationInput.parent().first('.ui-autocomplete'); // menu.width(menu.width()-4).css('left', (menu.offset().left+2)); }, select: function( event, ui ) { $.ajax({ url: '/restapi/add_and_return_loc.json', type: 'post', data: { location_obj : JSON.stringify(ui.item.value) }, dataType: 'json', cache: false, success: function(results) { if(dropdown) { locationSpan.html( results.loc_bucket.name ); locationHidden.val( results.location.id ); closeDropdown('#'+locationDropdown.attr('id')); $('form#search input[name="q"]').focus(); if($('form#search input[name="q"]').val().length >= 3) { if(searchQ) { searchQ.abort(); } searchQ = $.ajax({ url: '/search/results', type: 'post', data: $('form#search').serialize(), dataType: 'html', cache: false, success: function(response){ openSearchResults(response); } }); } } else if(locationInput.closest('form').is('#person, #place')) { locationInput.val( ui.item.label ); locationHidden.val( results.location.id ); if(locationInput.closest('form').find('input[name="vendor"]').val() !== '') { populateVendorResults(); } } else { locationInput.val( ui.item.label ); locationHidden.val( results.location.id ); } } }); return false; }, focus: function( event, ui ) { locationInput.val( ui.item.label ); return false; }, change: function(event, ui) { if ($(this).val() == '') { if (!ui.item) { locationInput.val(""); locationHidden.val(""); } } else { if (!$(this).parent().hasClass('inputHolder') && $('.ui-autocomplete').length > 0) { if (locations.length > 0) { $.ajax({ url: '/restapi/add_and_return_loc.json', type: 'post', data: { location_obj : JSON.stringify(locations[0].value) }, dataType: 'json', cache: true, success: function(results) { if (locationInput && locationHidden) { locationInput.val( locations[0].label ); locationHidden.val( results.location.id ); } if(locationInput.closest('form').is('#person, #place')) { if(locationInput.closest('form').find('input[name="vendor"]').val() !== '') { populateVendorResults(); } } } }); } } } } }); } }); } else { if ($('input[name="location"]').val() == "") { $('#locationDropdown').find('span').html('Add a location'); $('input[name="location_id"]').val(''); } } }); activateTextarea(); //Acitvate Placeholders activatePlaceholders(); //thanks button stuff - sameerified $('.ctaButtons').on('click', '.thanks-button', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } var thankButton = $(this); $.ajax({ type: 'post', url: '/restapi/thank.json', data: { tout_id : thankButton.data('answer-id') }, dataType: 'json', cache: false }).done(function(response) { if (response.results.success) { thankButton.parent().empty().append('
* '+error+'
'); }); } else { $('input[name="'+variable+'"], select[name="'+variable+'"], textarea[name="'+variable+'"]').addClass('error').closest('.labelField').addClass('error').append('* '+msg+'
'); } }); } } }); } function showLoading(title) { if(title) $('#lightbox #loading span').text(title); $('#lightbox #loading').css({ 'top': (($(window).height()-$('#lightbox #loading').outerHeight())/4), 'left': (($(window).width()-$('#lightbox #loading').outerWidth())/2) }).fadeIn(400); $(window).resize(function() { $('#lightbox #loading').css({ 'top': (($(window).height()-$('#lightbox #loading').outerHeight())/4), 'left': (($(window).width()-$('#lightbox #loading').outerWidth())/2) }); }); return false; } function removeLoading(title) { title = title ? title : 'Loading...'; $('#lightbox #loading').fadeOut(200); $('#lightbox #loading span').text(title); } function lightboxAJAX(path,params) { if(!params) { $.ajax({ url: path, type: 'get', dataType: 'html', cache: false, success: function(response) { openLightbox(response); } }); } else { $.ajax({ url: path, type: 'post', dataType: 'html', data: params, cache: false, success: function(response) { openLightbox(response); } }); } } function openLightbox(data) { if($('#lightbox').length > 0) { changeLightbox(data); } else { if(mobile) { $(window).scrollTop(0); $(data).insertAfter('#footer'); $('#lightbox').css('min-height', $(document).height()); $('#lightbox .container').slideDown(800, function() { $('#lightbox a.close').click(function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } closeLightbox(); }); }); bindDropdown('.dropdown'); bindSelect('select:not(".chzn-select"), input[type="checkbox"]'); activateTextarea(); } else { $(data).insertAfter('#footer').fadeIn(400, function() { $('#lightbox .container').slideDown(400, function() { resizeLightbox(); $('#lightbox a.close').click(function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } closeLightbox(); }); $(window).resize(function() { resizeLightbox(); }); $(document).keydown(function(key) { if(key.keyCode == '27') { closeLightbox(); } }); $('html').click(function(e) { if(($(e.target).closest('#lightbox .container').length === 0) && ($(e.target).closest('.ui-autocomplete').length === 0)) { if($(e.target).attr('class') != 'search-choice-close') { closeLightbox(); } } }); //need to set vendor logic for this event if ($('.typeSelector').length > 0 && $('input[name="vendor_data"]').length > 0) { set_vendor_data(); } }); bindDropdown('.dropdown'); bindSelect('select:not(".chzn-select"), input[type="checkbox"]'); activatePlaceholders(); // ASK A QUESTION LIGHTBOX if($(this).attr('class') == 'ask') { activateShowLocationButtons(); } // ASK A QUESTION LIGHTBOX if($(this).attr('class') == 'tout') { // Prevent Submiting, Trigger Search Results $('form#thing').submit(function() { $('form.active input[name="thing"]').trigger('blur'); return false; }); } // INVITE MORE FIRENDS LIGHTBOX if($(this).attr('class') == 'friend' ) { activateScrollbar('#scrollbar1'); // Friends Contacts Scrollbar // Only Render from the beggining on Invite if($(this).find('#friend').attr('action') == 'invite') activateScrollbar('#scrollbar3'); // Gmail Scrollbar activateLiveFilter('#toutd-forward .livefilter','#toutd-forward .userItem','#scrollbar1'); activateLiveFilter('.email-tab .livefilter','.email-tab .userItem','#scrollbar3'); activateLiveFilter('#facebook-friend .livefilter','#facebook-friend .userItem','#scrollbar2'); selectAllFriends('.select-all-friends','.toutd-tab .userContainer'); selectAllFriends('.select-all-gmail','.email-tab .userContainer'); selectAllFriends('.select-all-facebook','#facebook-friend .userContainer'); } }); } } } function selectAllFriends(selector,target) { $(selector).live('click',function(e){ if(!$(this).hasClass('selected')) { $(this).addClass('selected'); $(selector + '-title').html('Unselect'); $(target).trigger('click',['select']); } else { $(this).removeClass('selected'); $(selector + '-title').html('Select'); $(target).trigger('click',['unselect']); } }); } function changeLightbox(data) { $(document).unbind('keydown'); $('html').unbind('click'); $('#lightbox .container').slideUp(400, function() { $('#lightbox').empty(); if(data) { $('#lightbox').html($(data).html()).removeClass().addClass($(data).attr('class')); $('#lightbox .container').slideDown(400, function() { $('#lightbox a.close').click(function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } closeLightbox(); }); if(!mobile) { resizeLightbox(); $(window).resize(function() { resizeLightbox(); }); $(document).keydown(function(key) { if(key.keyCode == '27') { closeLightbox(); } }); $('html').click(function(e) { if(($(e.target).closest('#lightbox .container').length === 0) && ($(e.target).closest('.ui-autocomplete').length === 0)) { closeLightbox(); } }); //Activate Facebook Friends Scrollbar if($(data).attr('class') == 'friend') { activateScrollbar('#scrollbar2'); if ($(this).find('#email-invite').length > 0) { activateScrollbar('#scrollbar3'); } } } bindDropdown('.dropdown'); bindSelect('select[class!="chzn-select"], input[type="checkbox"]'); activatePlaceholders(); activateTextarea(); // Activate Scrollbars activateScrollbar('#scrollbar1'); // Friends Contacts Scrollbar activateScrollbar('#scrollbar2'); // Facebook Scrollbar activateScrollbar('#scrollbar3'); // Gmail Scrollbar // Prevent Submiting, Trigger Search Results $('form#thing').submit(function() { $('form.active input[name="thing"]').trigger('blur'); return false; }); // Only When Vendor Search Lightbox is Opened if($(this).parent().hasClass('vendor_search') || $(this).parent().hasClass('thing_search')) { activateLightboxSuggestion(); activateScrollbar('#scrollbar4',false,{ sizethumb: 30, size: 345 }); // Results activateScrollbar('#scrollbar4',true,false,345); } // Activate Live Filters activateLiveFilter('#toutd-forward .livefilter','#toutd-forward .userItem','#scrollbar1'); activateLiveFilter('.email-tab .livefilter','.email-tab .userItem','#scrollbar3'); activateLiveFilter('#facebook-friend .livefilter','#facebook-friend .userItem','#scrollbar2'); selectAllFriends('.select-all-friends','.toutd-tab .userContainer'); selectAllFriends('.select-all-gmail','.email-tab .userContainer'); selectAllFriends('.select-all-facebook','#facebook-friend .userContainer'); }); } }); } function resizeLightbox() { contentHeight = ($(window).height()-$('#lightbox .container').position().top-$('#lightbox .boxHeading').outerHeight()-50); $('#lightbox .content').css({ maxHeight: contentHeight }); } function closeLightbox(data) { // When Closing Vendor Search Lightbox it means that it open as a second lightbox // therefore we must reopen the first lightbox from were it was called if($('#lightbox').hasClass('vendor_search') || $('#lightbox').hasClass('thing_search') ) { reopenToutLightbox(); return true; } if(mobile) { $(window).scrollTop(0); $(data).insertAfter('#footer'); $('#lightbox .container').slideUp(400, function() { $('#lightbox').remove(); }); } else { $('#lightbox .container').slideUp(400, function() { $('#lightbox').fadeOut(400, function() { $('#lightbox').remove(); if(data) { openLightbox(data); } }); }); $(document).unbind('keydown'); $('html').unbind('click'); } } function closeDashboard() { if(mobile) { $('#mobileDashboard').stop(true, false).slideUp(400); } else { $('#userTab').parent().find('.content').stop(true, false).animate({ opacity: 0 }, 100, function() { $(this).stop(true, false).slideUp(200, 'linear'); $(this).parent().find('#userTab').stop(true, false).animate({ 'padding': '0 10px', 'height': '45px' }, 200, 'linear').find('.info').stop(true, false).animate({ 'width': '220px' }, 200, 'linear').find('.name').stop(true, false).animate({ 'font-size': '14px', 'margin-top': '10px' }, 200, 'linear').parent().find('.location, .profileLink').stop(true, false).hide(); $('#userTab .userThumb img, #userTab .userThumb .innerShadow, #userTab .userThumb').animate({ height: '30px', width: '30px' }, 200, 'linear'); $(this).parent().stop(true, false).animate({ width: '310px' }, 200, 'linear'); }); $('#userTab').toggleClass('open'); } } function openDashboard() { if(mobile) { $('#mobileDashboard').stop(true, false).css('min-height', $(document).height()).slideDown(800, function() { $(window).scrollTop(0); $(this).live('click', function() { closeDashboard(); }); }); } else { $('#userTab').stop(true, false).toggleClass('open').stop(true, false).animate({ 'padding': '5px 15px 0', 'height': '80px' }, 200, 'linear').find('.info').stop(true, false).animate({ 'width': '300px' }, 200, 'linear').find('.name').stop(true, false).animate({ 'font-size': '18px', 'margin-top': '7px' }, 200, 'linear').parent().find('.location, .profileLink').stop(true, false).fadeIn(200); $('#userTab .userThumb img, #userTab .userThumb .innerShadow, #userTab .userThumb').animate({ height: '60px', width: '60px' }, 200, 'linear'); $('#userTab').parent().stop(true, false).animate({ width: '400px' }, 200, 'linear').find('.content').stop(true, false).slideDown(200, 'linear', function() { $(this).stop(true, false).animate({ opacity: 1 }, 100 ); }); } } /** * Activate Multiple Select * @param string selector - Id/Class of desired scrollbar * */ function activateMultipleSelect(selector) { // Predefined Selector if(selector) selector = $(selector); else selector = $('.chzn-select'); //Render Multiple Select selector.chosen(); } /** * Activate Auto Suggest * @param string selector - Id/Class of desired scrollbar * */ // function activateAutoSuggest(selector) { // // Predefined Selector // selector = (selector) ? $(selector) : $('.auto_suggest'); // $.ajax({ // url: '/restapi/gmail_contacts.json', // type: 'get', // dataType: 'json', // success: function(data) { // if(data.success) { // selector.autoSuggest(data.gmail_contacts, {selectedItemProp: "name", searchObjProps: "name"}); // } else { // selector.autoSuggest({items: [{name: "No Results"}]}, {selectedItemProp: "name", searchObjProps: "name"}); // } // } // }); // } // Resize Viewport base on item quantities function viewportSizes(size) { switch(size) { case 0: return '40px'; case 1: case 2: return '60px'; case 3: case 4: return '120px'; case 5: case 6: return '180px'; default: return '245px'; } } /** * Live Filter working with Tinyscroll * * @param searchBar - Search bar class/id Ex '.filter' '#filter' * @param content - Conter class/id name Ex '.class' or '#id' * @param tinyscroll - Tinyscroll selector ( Must be anticipate declared! ) */ function activateLiveFilter(searchBar,content,tinyscroll){ // Live Filter $(searchBar).fastLiveFilter(content,{ timeout: 200, // Update Scrollbar and Autosize Viewport after filtering callback: function(e,total) { activateScrollbar(tinyscroll,true); e.parent().find('.viewport').attr('style','height: ' + viewportSizes(total)); } }); } /** * Activate Scrollbar * * @param string selector - Id/Class of desired scrollbar * @param params - Define your own Tiny Scrollbar params * **/ function activateScrollbar(selector,update,params,viewportHeight) { // Predefined Variables var viewportHeight = (viewportHeight) ? viewportHeight : 245; var thumbSize = 30; var selector = (selector) ? $(selector) : $('.tinyscroll'); var params = (params) ? params : { sizethumb: thumbSize, size: viewportHeight }; var viewport = selector.children('.viewport'); var total = viewport.children().children().children('ol').children('li').size(); // Update Scroll if(update) { // Update only activated scrolls if(selector.hasClass('scroll-activated')) { viewport.height(viewportHeight); selector.tinyscrollbar_update(params); } // Throw update error else { return 'Tinyscroll cant be updated, the selected scroll has not been activated'; } } // Render New Scroll else if(!selector.hasClass('scroll-activated')) { selector.addClass('scroll-activated'); viewport.height( viewportSizes(total)); selector.tinyscrollbar(params); } } function activateTextarea() { $('textarea').autosize().live('focusin',function() { $(this).addClass('focused'); if($(this).hasClass('default')) { $(this).attr('placeholder', ''); } }).live('focusout',function() { $(this).removeClass('focused'); if($(this).val() == '') { var dtext = $(this).attr('dtext'); if(dtext){ $(this).attr('placeholder', dtext).addClass('default'); } } else { $(this).removeClass('default').removeClass('error').closest('.error').removeClass('error').find('p.error').remove(); $('.errorMsg').stop(true, true).fadeOut(400); } }); } function bindDropdown(e){ // $('#tout-type').live('click',function(){ openDropdown('#'+$(this).attr('id')); }); $(e+' span').live('click',function(){ openDropdown('#'+$(this).parent().attr('id')); }); $(e+' .arrow').live('click', function(){ openDropdown('#'+$(this).parent().attr('id')); }); } function bindSelect(e) { if(!mobile) { $(e).uniform(); } } function openDropdown(e){ $('.dropdown span.clicked').each(function() { if('#'+$(this).parent().attr('id') != e) { closeDropdown('#'+$(this).parent().attr('id')); } }); if(!$(e+' span').hasClass('clicked')) { $(e).css('z-index', (parseInt($(e).css('z-index'))+100)); $(e+' ul.options, '+e+' ul#locations').slideDown(200, function() { $(e).addClass('clicked'); $(e+' span').addClass('clicked'); $(e+' .arrow').addClass('clicked'); $('html').click(function(event) { if(($(event.target).closest('.options').length === 0) && ($(event.target).closest('#locations').length === 0)) { if(e === "#locationDropdown" && $(e + ' input[name="location"]').val() === '' || e === "#locationDropdown" && $(e + ' input[name="location"]').val() === 'i.e. New York, NY or 10007') { $('.resultContainer .addLocation input[name="location"]').val(''); $('.addLocation').slideUp(400); $('#askQuestion .category').width(''); $('.showLocation').show(); } closeDropdown(e); } }); $(document).keydown(function(key) { if(key.keyCode == '27') { closeDropdown(e); } }); $(e+' span').click(function(f) { closeDropdown(e); }); }); } $(e+' ul.options li, '+e+' ul#locations ul.locations li').live('click', function(f) { if($(this).closest('#tout-type').length > 0) { linkClass = $(this).attr('class'); $(this).closest('#tout-type').removeClass('default'); $('input[name="type"]').val($(this).attr('val')); $(e+' span').html($(this).html()).removeClass().addClass(linkClass); closeDropdown(e); $('.toutForm form.active').removeClass('active').slideUp(200, function() { $('.toutForm form#'+linkClass).slideDown(400).addClass('active'); }); } else if($(this).closest('.friendDropdown').length > 0) { var link = $(this).find('a'); if(link.hasClass('active')) { closeDropdown(e); } else { submitForm(link, '', 'friend_id='+link.attr('friend_id')+'&frequency='+link.attr('frequency')); $(e).find('span').html(link.html()); closeDropdown(e); } } else { $(e+' span').html($(this).html()); closeDropdown(e); } }); } function closeDropdown(e) { $(e).css('z-index', 15700); $(e+' ul.options, '+e+' ul#locations').slideUp(100, function() { $(e).removeClass('clicked'); $(e+' .arrow').removeClass('clicked'); $(e+' span').removeClass('clicked'); $(document).unbind('keydown'); $('html').unbind('click'); activateSearchbar(); }); } // // Populate Vendor Results // var thing = ''; var thing_id = ''; var vendor_q = ''; var vendor_id = ''; var loc_q = ''; var loc_id = ''; var recommend_comments = ''; var recommend_category = ''; var prev_category = ''; var tab_id = false; var q_id = false; var vendor_search_flag = false; function populateVendorResults() { // Assign Values to Variables q_id = $('form.active input[name="question_id"]').val(); vendor_q = $('form.active input[name="vendor"]').val(); vendor_id = ''; loc_q = $('form.active input[name="location"]').val(); loc_id = $('form.active input[name="location_id"]').val(); recommend_comments = $('form.active textarea').val(); recommend_category = $('input[name="category"]').val(); vendor_search_flag = true; if(loc_q == 'i.e. New York, NY') return true; if(vendorSearch) { vendorSearch.abort(); } // Assign Tab Id switch($('form.active').attr('id')) { case 'person': tab_id = 1; break; case 'place' : tab_id = 2; break; } showLoading('Searching...'); vendorSearch = $.ajax({ url: '/lightbox/vendor_search?lightbox=1', type: 'post', data: { location_id : loc_id , location : loc_q , vendor : vendor_q , type: $('#tout #tout-type input[name="type"]').val() }, dataType: 'html', cache: false, success: function(results) { // Turn Off Flag vendor_search_flag = false; //Remove Searching removeLoading('Searching...'); // Open Suggestion Lightbox openLightbox(results); } }); } // ----------------- Populate Things Results ---------------- function populateThingResults(){ tab_id = 3; q_id = $('form.active input[name="question_id"]').val(); thing = $('form.active input[name="thing"]').val(); thing_id = ''; recommend_comments = $('form.active textarea').val(); recommend_category = $('input[name="category"]').val(); vendor_search_flag = true; showLoading('Searching...'); $.ajax({ url: '/lightbox/thing_search?lightbox=1', type: 'get', data: { thing : thing }, dataType: 'html', cache: false, success: function(results) { // Turn Off Flag vendor_search_flag = false; //Remove Searching removeLoading('Searching...'); // Open Suggestion Lightbox openLightbox(results); } }); } // Suggestion Has been selected Logic function activateLightboxSuggestion() { // LIGTBOX TABS $('.vendorSearch a.changeTab').on('click', function(e) { var e = $(this); $('.vendorSearch .tabsContainer').stop(true, false).slideUp(200, function() { $('.vendorSearch a.changeTab').removeClass('active'); $(e).addClass('active'); $('.vendorSearch .tabsContainer .tabs').hide(); $(this).show().attr('style',''); $('#' + e.attr('tab')).slideDown(400); }); }); // REDIRECT TO ADD A NEW PLACE/PERSON/THING $('.vendorSearch a.redirectToAddNewVendorBt').on('click', function(e) { resizeLightbox(); $('.vendorSearch .tabsContainer').stop(true, false).slideUp(200, function() { $('.vendorSearch a.changeTab').removeClass('active'); $('.vendorSearch a.changeTab[tab="addNewVendor"]').addClass('active'); $('.vendorSearch .tabsContainer .tabs').hide(); $(this).show().attr('style',''); $('.vendorSearch #addNewVendor').slideDown(400); }); return false; }); // Add This Vendor Button $('.vendorSearch a.submitVendor, .vendorSearch a.submitProduct').on('click', function(e) { $.ajax({ url: $(this).attr('submit'), type: 'post', data: $(this).closest('form').serialize(), dataType: 'json', cache: false, success: function(result) { if(result.thing_id !== '') { thing = result.thing; thing_id = result.thing_id; } if(result.vendor_id !== '') { vendor_q = result.vendor; vendor_id = result.vendor_id; } reopenToutLightbox(); } }); return false; }); $('.vendorSearch a.result').on('click', function(e) { vendor = $(this); // SAVE A THING if(tab_id == 3) { if (thingAdded) { thingAdded.abort(); } var thingAdded = $.ajax({ url: '/restapi/save_thing.json', type: 'post', data: { image_path : vendor.attr('image_path'), name : vendor.attr('name'), asin : vendor.attr('asin'), category : vendor.attr('category'), large_image_path : vendor.attr('large_image_path'), thing_url : vendor.attr('url') }, dataType: 'json', cache: false, success: function(result) { thing = vendor.attr('name'); thing_id = result.thing_id; var separator = ', '; // First Category Selected if(prev_category === '' || recommend_category.match(prev_category) === null) { // there are some categories already so add a comman if(recommend_category !== '' && recommend_category !== 'e.g. Digital Camera, Mexican Restaurant, Babysitter' ) { recommend_category += separator + vendor.attr('category'); } else { recommend_category = vendor.attr('category'); } } // Second or More Time Catefgory Selected... else { recommend_category = recommend_category.replace( separator + prev_category , separator + vendor.attr('category') ); recommend_category = recommend_category.replace( prev_category,vendor.attr('category') ); } // Previous Category Selected prev_category = vendor.attr('category'); reopenToutLightbox(); } }); } // SAVE A VENDOR (PLACE OR PERSON) else { geocoder.geocode({ address : vendor.attr('address') }, function(results, status) { // if (status == google.maps.GeocoderStatus.OK) { if(typeof results !== 'undefined' && results.length > 0) { $.ajax({ url: '/restapi/add_and_return_loc.json', type: 'post', data: { location_obj : JSON.stringify(results[0]) }, dataType: 'json', cache: false, success: function(result) { $.ajax({ url: '/restapi/save_vendor.json', type: 'post', data: { vendor_name : vendor.attr('name'), vendor_id : vendor.attr('vendor_id'), vendor_reference : vendor.attr('vendor_reference'), location_id : result.location.id }, dataType: 'json', cache: false, success: function(vendor_object) { vendor_q = vendor.attr('name'); vendor_id = vendor_object.vendor_id; loc_q = result.location.name; loc_id = result.location.id; reopenToutLightbox(); } }); } }); } /*} else { $.ajax({ url: '/restapi/save_vendor.json', type: 'post', data: { vendor_name : vendor.attr('name'), vendor_id : vendor.attr('vendor_id'), vendor_reference : vendor.attr('vendor_reference'), location_id : null }, dataType: 'json', cache: false, success: function(vendor_object) { reopenToutLightbox(); } }); }*/ }); } return false; }); } /* * Once The User Make a selection form the suggestion list, or either * if he decided to don't go with anyone we have to reopen previous lightbox * and repopuplate with the input information */ function reopenToutLightbox(type) { // Thing Suggestions if(tab_id == 3) var params = { thing : thing, thing_id : thing_id, comments : recommend_comments , category : recommend_category }; // Place & Person Suggestions else var params = { vendor_name : vendor_q , vendor_id : vendor_id , location_name : loc_q , location_id : loc_id , comments : recommend_comments , category : recommend_category }; lightboxAJAX('/lightbox/tout?lightbox=1&qid=' + q_id + '&tab=' + tab_id, params ); } function activateSlider() { sliderQueue = setTimeout(changeSlideWithFades, slideDelay); } function changeSlide(slide) { clearTimeout(sliderQueue); // var showNext = false; if(typeof slide == 'undefined') { slide = currentSlide+1; // showNext = true; } if(slide > (slideCount-1)) { slide = 0; } else if(slide < 0) { slide = slideCount-1; } currentSlide = slide; $('#welcome table.slides td.top .slide').stop(true, false).fadeOut(200, function() { $(this).removeClass('active'); }); $('#welcome table.slides td.top .slide[slide="'+slide+'"]').delay(400).fadeIn(400, function() { $(this).addClass('active'); }); $('#welcome table.slides td.imageSide .slide img').stop(true, false).animate({ top: '100%' }, 400, function() { $(this).parent().removeClass('active'); }); $('#welcome table.slides td.imageSide .slide[slide="'+slide+'"] img').animate({ top: '0%' }, 800, function() { $(this).parent().addClass('active'); }); // if(showNext) { sliderQueue = setTimeout(changeSlide, slideDelay); // } } function changeSlideWithFades(slide) { clearTimeout(sliderQueue); // var showNext = false; if(typeof slide == 'undefined') { slide = currentSlide+1; // showNext = true; } if(slide > (slideCount-1)) { slide = 0; } else if(slide < 0) { slide = slideCount-1; } currentSlide = slide; $('#welcome table.slides td.top .slide').stop(true, false).fadeOut(600, function() { $(this).removeClass('active'); }); $('#welcome table.slides td.top .slide[slide="'+slide+'"]').delay(600).fadeIn(600, function() { $(this).addClass('active'); }); $('#welcome table.slides td.imageSide .slide.active').fadeOut(600,function() { $(this).removeClass('active'); }); $('#welcome table.slides td.imageSide .slide[slide="'+slide+'"]').delay(600).fadeIn(600, function() { $(this).addClass('active'); }); // if(showNext) { sliderQueue = setTimeout(changeSlideWithFades, slideDelay); // } } function getParameterByName(name) { name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^]*)"; var regex = new RegExp(regexS); var results = regex.exec(window.location.search); if(results == null) return ""; else return decodeURIComponent(results[1].replace(/\+/g, " ")); } if (window.location.hash == '#_=_') { window.location.hash = ''; } var newwindow; function callback_complete(error) { newwindow.close(); if(error == 0) { if($('#lightbox').hasClass('settings')) { $('#lightbox #loading span').text('Updating...'); lightboxAJAX('/lightbox/account_settings?tab='+$('#accountSettings .tabContent.active').attr('tab')+'&lightbox=1'); } else if ($('#lightbox').hasClass('signup_login')) { $('#lightbox #loading span').text('Logging In...'); window.location.reload(); } else if ($('#lightbox').hasClass('friend')) { $('#lightbox #loading span').text('Updating...'); lightboxAJAX('/lightbox/friend?tab='+$('#friend .changeTab.active').attr('tab')+'&lightbox=1&action='+$('#friend').attr('action')+'&qid='+$('#friend input[name="qid"]').val()); } else { window.location.reload(); } } } function fb_window(url) { l=(screen.width-600)/2; t=(screen.height-350)/2; newwindow = window.open(url, 'newproductreview', 'height=350,width=600,resizable=no,scrollbars=0,toolbar=no,menubar=no,titlebar=no,status=no,left='+l+',top='+t); if (window.focus) { newwindow.focus(); } } /* Sample methods to run when testing the tooltip update */ // Still requires code to go into openLightBox() where you do the first ajax call for the first tooltip var toolTipper = function(tooltip, update) { return $.ajax({ type: 'get', url: '/restapi/tool_tip.json', data: { name: tooltip, update: update }, dataType: 'json', cache: false }); }; bindToolTipParams = [ 'first_ask' ]; $.each(bindToolTipParams, function(key, val) { $('#'+val+'-close-btn').on('click', '#'+val, function() { onClickEvent($(this).attr('id')); }); //locking pagination down to specific ids if ($('#endlessScrollContent').length > 0) { var processing; var offset = 1; var data_params = ''; var end_of_activity = false; $(document).scroll(function(e){ if (processing) { return false; } if ($(window).scrollTop() >= $(document).height() - $(window).height() - 700) { processing = true; ntwrk = getParameterByName('ntwrk'); offset = offset+1; urlParams.offset = offset; if (ntwrk != '') { urlParams.ntwrk = ntwrk; } data_params = $('#endlessScrollContent').data('params'); if (data_params != '' && (data_params == 'pag=0' || data_params == 'pag=1')) { value = data_params.split('='); urlParams.pag = value[1]; } else if (data_params != '') { urlParams = data_params+'&offset='+offset; if (ntwrk) { urlParams = data_params+'&ntwrk='+ntwrk; } } // Display Loading Icon if(!end_of_activity) { $('.loadingMore').css('display', 'block'); } $.ajax({ type: 'POST', url: '/restapi/activity_feed_pagination', data: urlParams, dataType: 'html', cache: false }).done(function(data) { processing = false; if (data.length > 0 && data != '') { $(data).appendTo('#endlessScrollContent').slideDown('slow'); render_time_ago(); renderGoogleMap(); }else { end_of_activity = true; } // Hide Loading Icon $('.loadingMore').hide(); }); } }); // Enable Back To Top Buttom back_to_top(); } }); var urlParams = {}; (function () { var match, pl = /\+/g, // Regex for replacing addition symbol with a space search = /([^&=]+)=?([^&]*)/g, decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }, query = window.location.search.substring(1); while (match = search.exec(query)) { urlParams[decode(match[1])] = decode(match[2]); } })(); //------------------------ FB AJAX Activity Log ----------------------------- function log_activity(fb_activity) { if (fb_activity != '') { $.ajax({ type: 'POST', url: '/restapi/log_activity.json', data: { activity: fb_activity }, dataType: 'json', cache: false }).done(function(data) { //do nothing }); } } //----------------------- Back to Top Button -------------------------------- function back_to_top() { // Back to Top Buttom Object var b = $('#backToTop'); b.css({opacity:0}); $(window).scroll(function() { if ($(this).scrollTop() > 100) { b.stop().css({ display: 'block' }).animate({ opacity: 1 }, 200); } else { b.stop().animate({ opacity: 0 }, 200, function() { $(this).css({ display: 'none' }); }); } }); b.click(function() { $('body,html').animate({ scrollTop: 0 }, 800); return false; }); } //----------------------- URL sorting selection -------------------------------- function set_filter_param(dom_object) { var sort_by = $(dom_object).data('sortby'); var count = 0; var qs = ''; if (urlParams.offset || urlParams.ntwrk || urlParams.sort_by) { delete urlParams.offset; delete urlParams.pag; delete urlParams.ntwrk; delete urlParams.sort_by; } if (!urlParams.user_id && sort_by == 'sort_non_network') { urlParams.ntwrk = 0; } else if (sort_by == 'sort_network_only') { urlParams.ntwrk = 1; } else { urlParams.sort_by = sort_by; } for(var key in urlParams) { qs += key+'='+urlParams[key]+'&'; } var strLen = qs.length; qs = qs.slice(0, strLen-1); window.location = td_globals.base_url+'activity?'+qs; } function set_dd_selection() { if (urlParams && (urlParams.ntwrk || urlParams.sort_by)) { if (urlParams.ntwrk) { key = 'sort_network_only'; } else if (urlParams.sort_by) { key = urlParams.sort_by; } dd_selection = $('#filters li[data-sortby="'+key+'"]').html(); $('#feedFilters').find('span').html(dd_selection); } } function render_time_ago() { // TIMEAGO STUFF $('.timeago').each(function() { $(this).timeago(); }); } /** * Activate Hover Buttons on Q/A feeds * */ function activateFeedsHoverButtons() { $('.mainbox').live('mouseenter', function() { // This element var e = $(this); // Hover Button to Show buttonQueue = setTimeout(function() { if (typeof e !== 'undefined' && e !== false) { e.find('ul.ctaFeedButtons').fadeIn(500).addClass('activated'); } }, 250); }).live('mouseleave', function() { // if(!$(this).attr('class').hasClass('question')) // { clearTimeout(buttonQueue); $('ul.ctaFeedButtons').fadeOut(250); // } }); } function getTooltip(area, n) { var tooltip; // THIS IS WHERE YOU DEFINE THE TOOLTIPS BASED ON AREA AND ORDER if(area == 'first_activity') { if( n == 0) { tooltip = { area : area, n : n, title: "Welcome to Villij!", message : "This is your Activity Feed, where you see all of the questions & recommendations of the people in your Villij. You can also see what everyone else on Villij has to say.