$(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('
  • Already Thanked!
  • '); // .html('Already Thanked!'); } }); }); // HEADER - NAV BUTTON STUFF $('#nav .navPoint').hover(function() { $('#nav .navPoint ul.menu').stop(true, true); $(this).find('ul.menu').delay(75).show(400); }, function() { $('#nav .navPoint ul.menu').stop(true, true); $(this).find('ul.menu').hide(400); }); // FOOTER - NAV BUTTON STUFF if(mobile) { $('#navFooter .navPoint a.mainButton').click(function() { button = $(this); $('#footerMenus .menu').stop(true, false).slideUp(400); $('#footerMenus #'+button.attr('menu')).css('height', $(document).height()).delay(401).stop(true, false).slideDown(800, function() { $(window).scrollTop(0); $(this).live('click', function() { $('#footerMenus .menu').stop(true, false).slideUp(400); }); }); }); } // HEADER - USER DASHBOARD STUFF if(mobile) { $('.dashboard').live('click', function() { openDashboard(); }); } else { $('.dashboard').live('mouseenter', function() { if(!$('#header').hasClass('out')) { clearTimeout(dashboardQueue); dashboardQueue = setTimeout('openDashboard()', 200); } }).live('mouseleave', function() { if(!$('#header').hasClass('out')) { clearTimeout(dashboardQueue); closeDashboard(); } }); } // ACCOUNT SETTINGS STUFF $('a[lightbox="account_settings"]').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } lightboxAJAX('/lightbox/account_settings?tab='+$(this).attr('tab')+'&lightbox=1'); }); $('#accountSettings li.changeTab').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } if(!$(this).hasClass('active')) { tab = $(this).attr('tab'); $('#accountSettings .tabContent.active').stop(true, false).slideUp(200, function() { $(this).removeClass('active'); $('#accountSettings li.changeTab').removeClass('active'); $('#accountSettings li.changeTab[tab="'+tab+'"]').addClass('active'); $('#accountSettings .tabContent[tab="'+tab+'"]').slideDown(400, function() { $(this).addClass('active'); }); }); } }).live('mouseenter', function() { $(this).addClass('hover'); }).live('mouseleave', function() { $(this).removeClass('hover'); }); // MAP STUFF if($('#map_canvas').length > 0) { renderGoogleMap(); } // FRIENDIFIER STUFF $('a.friendifier').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } submitForm($(this), '#'+$(this).closest('form').attr('id'), 'friend_id='+$(this).attr('friend_id')); }); // FORM SUBMISSION STUFF $('a.submitButton').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } if($(this).closest('#tout').length > 0) { formType = $('#tout-type span').attr('class'), validated = true, activeForm = $('#tout form.active'); if (formType === 'place' || formType === 'person' || formType === 'thing') { if(vendor_search_flag) return true; locationIsEmpty = $.trim(activeForm.find('input[name="location"]').val()) == ''; validated = activeForm.find('input[name="vendor_id"]').val() !== ''; } if (validated) { submitForm($(this), 'form#'+formType, $('form#'+formType).serialize()+'&'+$('#tout input[name="category"]').serialize()+'&'+$('#tout input[name="type"]').serialize()); } else { if (locationIsEmpty) { alert('Please enter a location.'); } else { alert('Please add a '+formType+'.'); } } } else if($(this).closest('form#facebook-friend').length > 0) { fbUserIds = new Array; message = ''; redirect_link = td_globals.base_url+'lightbox/tout?lightbox=1&iby='+$(this).attr('uid'); if ($('#friend input[name="qid"]') && $('#friend input[name="qid"]').length > 0) { redirect_link += '&qid='+$('#friend input[name="qid"]').val(); } if ($('#friend input[name="message"]').length > 0) { message = $('#friend input[name="message"]').val(); } $('#friend input[name="friend_ids"]').each(function() { $.each($(this).val().split(','), function(key, value) { if (!isNaN(value) && value !== '') { fbUserIds.push(value); } }); }); var i, j, tempfbUserIds, chunk = 50; for (i = 0, j = fbUserIds.length; i < j; i += chunk) { tempfbUserIds = fbUserIds.slice(i, i + chunk); sendRequestToRecipients(tempfbUserIds, redirect_link, message); } } else { if (!$(this).hasClass('step')) { var formType = $(this).closest('form').attr('id'), thisForm = $(this).closest('form'), validated = true; if (formType === 'ask') { if (thisForm.find('input[name="location"]').is(':visible')) { if ($.trim(thisForm.find('input[name="location"]').val()) === '') { alert('Please specify a location.'); validated = false; } else { if (thisForm.find('input[name="location_id"]').val() === '') { validated = false; var location_text = thisForm.find('input[name="location"]').val(); alert('Unfortunately, "' + location_text + '" is not a location that we recognize. Please enter a differnt location to contine.'); } } } } if (validated) { submitForm($(this), '#'+$(this).closest('form').attr('id')); } } } }); // FRIEND / INVITE LIGHTBOX STUFF var friend_forwards = []; $('a[lightbox="friend"]').live('click', function(e) { friend_forwards = []; if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } if(typeof $(this).attr('qid') !== 'undefined') { lightboxAJAX('/lightbox/friend?lightbox=1&action='+$(this).attr('action')+'&qid='+$(this).attr('qid')); } else { lightboxAJAX('/lightbox/friend?lightbox=1&action='+$(this).attr('action')); } }); $('#friend a.changeTab').live('click', function(e) { $('.livefilter').trigger('keyup'); if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } if(friend_forwards.length > 0) { var conf = confirm('You have selected some friends, are you sure you want to continue without forwarding?'); if(!conf) { return false; } } if(!$(this).hasClass('active')) { tab = $(this).attr('tab'); $('#friend .tabsContainer .tab.active').stop(true, false).slideUp(200, function() { $(this).removeClass('active'); $('#friend a.changeTab').removeClass('active'); $('#friend a.changeTab[tab="'+tab+'"]').addClass('active'); $('#friend .tabsContainer .tab[tab="'+tab+'"]').slideDown(400, function() { // Activate Scrollbars (This are scrollbars that belong // to tabs that are hidden from the beggining) if($(this).attr('tab') == 'facebook') activateScrollbar('#scrollbar2'); // Facebook Filters else if($(this).attr('tab') == 'gmail') activateScrollbar('#scrollbar3'); // Gmail Scrollbar $(this).addClass('active'); old_vals = $(this).find('input[name="friend_ids"]').val(); if(old_vals != null && old_vals.length > 0) { friend_forwards = $.map($(this).find('input[name="friend_ids"]').val().split(','), function(value){ return value; }); } else { friend_forwards = []; } }); }); } }).live('mouseenter', function() { $(this).addClass('hover'); }).live('mouseleave', function() { $(this).removeClass('hover'); }); var filterQ; $('#toutd-friend input[name="filter"]').live('keyup', function(e) { if($(this).val().length > 2) { if(filterQ) { filterQ.abort(); } filterQ = $.ajax({ url: '/restapi/toutd_friends', type: 'get', data: { q : $(this).val() }, dataType: 'text', cache: false, success: function(results) { $('#toutd-friend .results').html(results); } }); } else { $('#toutd-friend .results').empty(); } }); //----------------------- Forward Green Big Buttons -------------------------------- $('#friend .userContainer').live('click', function(e,selectType) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } // Select Button var forward = $(this).find('.forward'); if(selectType != 'unselect' || forward.hasClass('selected') ) { if(selectType != 'select' || selectType == 'select' && !forward.hasClass('selected') ) forward.toggleClass('selected').closest('li.userItem').toggleClass('selected'); } if(forward.hasClass('selected')) { var match = forward.closest('form').find('input[name="friend_ids"]').val().indexOf(forward.attr('friend_id')); // Prevents multiple addition of the same value into the string if(match == -1) friend_forwards.push(forward.attr('friend_id')); // Activate Invite Button $(this).closest('.tab').find('.submitButton').addClass('active'); } else { // Deactivate Invite when no contacts selected if(friend_forwards.length == 1) { $(this).closest('.tab').find('.submitButton').removeClass('active'); } //forward.text('Select'); friend_forwards.splice($.inArray(forward.attr('friend_id'), friend_forwards), 1); } forward.closest('form').find('input[name="friend_ids"]').val(friend_forwards); }); $('#friend a.addAnother').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } $('ul.emailInputs li:last-child').clone().find('input[name="email[]"]').val('').addClass('default').parent().hide().appendTo('ul.emailInputs').slideDown(400); }); // QUESTION LIGHTBOX STUFF $('a[lightbox="ask"]').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } lightboxAJAX('/lightbox/ask?lightbox=1'); }); $('input[name="category"]').live('keyup', function(e) { var tagSearch; tagInput = $(this); tags = Array(); currentTags = tagInput.val().split(','); tagText = currentTags.pop().trim(); oldTags = ''; tagTextWordLenght = tagText.split(" ").length; if(tagTextWordLenght > 4) { tagInput.val(currentTags); $('textarea[name="comment"]').focus(); $('textarea[name="comment"]').val(tagText); } $.each(currentTags, function (index, value) { oldTags = oldTags + value.trim() + ', '; }); if(tagText.length >= 3) { if(tagSearch) { tagSearch.abort(); } tagSearch = $.ajax({ url: '/restapi/tags.json', type: 'get', data: { q : tagText }, dataType: 'json', cache: false, success: function(results) { tags = Array(); $.each(results.tags, function (index, value) { tags.push(value.name); }); tagInput.autocomplete({ source: function( request, response ) { response(tags); }, appendTo: tagInput.parent(), delay: 400, open: function() { // menu = tagInput.parent().first('.ui-autocomplete'); // menu.width(menu.width()-6).css('left', (menu.offset().left+4)); }, focus: function( event, ui ) { return false; }, select: function( event, ui ) { tagInput.val( oldTags + ui.item.label ); return false; } }); } }); } }); // TOUT LIGHTBOX STUFF $('a[lightbox="tout"]').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } if(typeof $(this).attr('qid') !== 'undefined') { if (!td_globals.lgd_in) { cta = true; } lightboxAJAX('/lightbox/tout?lightbox=1&qid='+$(this).attr('qid')); } else if(typeof $(this).attr('vid') !== 'undefined') { lightboxAJAX('/lightbox/tout?lightbox=1&vid='+$(this).attr('vid')); } else if(typeof $(this).attr('tid') !== 'undefined') { lightboxAJAX('/lightbox/tout?lightbox=1&tid='+$(this).attr('tid')); } else { lightboxAJAX('/lightbox/tout?lightbox=1'); } }); $('#tout .typeSelector td a').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } clicked = $(this).parent(); linkClass = $(this).parent().attr('class'); clicked.addClass('active'); $('#tout-type').removeClass('default'); $('input[name="type"]').val(clicked.attr('val')); $('#tout-type span').html(clicked.html()).removeClass().addClass(linkClass); closeDropdown('tout-type'); $('#tout #instructions').slideUp(400); $('#tout .typeSelector td').not(clicked).hide(400, function() { $('#tout .typeSelector').fadeOut(400, function() { $(this).remove(); }); $('#tout tr.bottom').slideDown(400); $('.toutForm form#'+linkClass).slideDown(400).addClass('active'); }); //set the values of a vendor if (e.vendor_location !== 'undefined' && e.vendor_location) { var selected_form = $('#tout form[id="'+e.vendor_type.toLowerCase()+'"]'); selected_form.find('input[name="vendor"]').val(e.vendor_name); selected_form.find('input[name="location"]').val(e.vendor_location); selected_form.find('input[name="vendor_id"]').val(e.vendor_id); selected_form.find('input[name="location_id"]').val(e.vendor_loc_id); } }); // HANDELS RECOMMENDATION THINGS $('#tout form.active input[name="thing"]').live('blur', function(e) { var placeholder = 'e.g. Canon Rebel T3I, Crayola Bathtub Crayons, Beach Ball'; if($(this).val() !== '' && $(this).val() !== placeholder && $(this).val() !== thing) populateThingResults(); }); // HANDELS RECOMMENDATION VENDOR SEARCH NAME $('#tout form.active input[name="vendor"]').live('blur', function(e) { var input_location = $(this).closest('form').find('input[name="location"]'); if(input_location.val() !== '' && input_location.val() !== 'i.e. New York, NY' && $(this).val() !== vendor_q) populateVendorResults(); }); // FORGOT PASSWORD LIGHTBOX STUFF $('a.forgotPassword').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } lightboxAJAX('/lightbox/forgot_password?lightbox=1'); }); // EDIT GROUP LIGHTBOX STUFF $('a[lightbox="edit_group"]').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } lightboxAJAX('/lightbox/edit_group?lightbox=1&group_id='+$(this).data('group-id')); }); // LOGIN / SIGNUP LIGHTBOX STUFF $('a[lightbox="signup_login"]').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } lightboxAJAX('/lightbox/signup_login?lightbox=1'); }); if (!mobile) { //TOOLTIPPER ACTIVATE var path = window.location.pathname.split('/')[1]; var area; if (path === 'activity') { area = 'first_activity'; } else if(false) { } if(area) { toolTipper(area, 'false').done(function(response) { if(response) { showTooltip(getTooltip(area, parseInt(response[area]))); } }); } $('#facebookUnlink').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } showLoading(); fb_window('/oauth/unlink'); }); $('.facebookLogin').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } showLoading(); fb_window('/oauth/authenticate'); }); // AK -- added login and unlink for google $('#googleUnlink').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } showLoading(); fb_window('/oauth/unlink/google'); }); $('#windowsUnlink').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } showLoading(); fb_window('/oauth/unlink/windowslive'); }); $('#googleLogin').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } showLoading(); fb_window('/oauth/authenticate/google'); }); $('#windowsLogin').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } showLoading(); fb_window('/oauth/authenticate/windowslive'); }); } $('a.createTab').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } $('#signupLogin .nonFacebook .login').slideUp(200, function() { $('#signupLogin .nonFacebook .create').slideDown(400); }); }); $('a.loginTab').live('click', function(e) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } $('#signupLogin .nonFacebook .create').slideUp(200, function() { $('#signupLogin .nonFacebook .login').slideDown(400); }); }); //----------- Filter Network Buttons -------------- //old dropdown code below // $('#filters li').on('click', function() { // set_filter_param(this); // }); }); // SETTING UP GEOCODER FOR USAGE geocoder = new google.maps.Geocoder(); if(window.opener) { window.opener.callback_complete(error); } var vendorAdded; var searchQ; var grid_index; var dashboardQueue = null; var currentSlide; var slideCount; var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase())); var slideDelay = 7000; var vendorSearch; var count; var sliderQueue; var cta = false; // FUNCTIONS function activateSearchbar() { $('form#search input[name="q"]').live('keydown', function(e) { if(e.which == 13) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } $('form#search input[name="q"]').blur(); $('#searchResults li.hover a.resultContainer')[0].click(); } else if(e.which == 27 || (e.which == 8 && $('form#search input[name="q"]').val().length < 4)) { closeSearchResults(); } else if (e.which == 38 || e.which == 40) { // Up and Down Key Controls if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } if(e.which == 40) { // Down Key next = $('#searchResults ul li.hover').next('li'); if(next.length == 0) { next = $('#searchResults ul li.hover').closest('ul').find('li:first'); } } if(e.which == 38) { // Up Key next = $('#searchResults ul li.hover').prev('li'); if(next.length == 0) { next = $('#searchResults ul li.hover').closest('ul').find('li:last'); } } $('#searchResults li.hover').removeClass('hover'); next.addClass('hover'); grid_index = next.index(); } else if (e.which == 37 || e.which == 39) { // Left and Right Key Controls if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } if(e.which == 39) { // Right Key next = $('#searchResults ul li.hover').closest('td').next('td'); if(next.length == 0) { next = $('#searchResults td:first'); } } if(e.which == 37) { // Left Key next = $('#searchResults ul li.hover').closest('td').prev('td'); if(next.length == 0) { next = $('#searchResults td:last'); } } $('#searchResults li.hover').removeClass('hover'); if(grid_index > (next.find('li').length-1)) { next.find('li:last').addClass('hover'); } else { next.find('li:eq('+grid_index+')').addClass('hover'); } } }).live('keyup', function(e) { if (e.which == 37 || e.which == 38 || e.which == 39 || e.which == 40 || e.which == 13 || e.which == 27) { if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } } else if($('form#search input[name="q"]').val().length >= 3) { //RVS - prevent the backspace keystrokes to ping the search results if (e.which === 8 || e.which === 46) { return; } 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 { closeSearchResults(); } }); } function openSearchResults(data) { if($('#searchResults').is(':visible')) { refreshSearchResults(data); } else { $('#searchResults').fadeIn(200, function() { $('#searchResults .container').empty().html(data).slideDown(200, function() { $('#searchResults li:not(.noResults) .resultContainer').highlight($('form#search input[name="q"]').val()); $('#searchResults li .resultContainer input[name="category"]').val($('form#search input[name="q"]').val()); activateSearchResults(); activateShowLocationButtons(); if($('form#search input[name="location"]').val() !== '' && $('form#search input[name="location"]').val() !== 'i.e. New York, NY or 10007') { $('#searchResults li .resultContainer input[name="location"]').val($('form#search input[name="location"]').val()); $('#searchResults li .resultContainer input[name="location_id"]').val($('form#search input[name="location_id"]').val()); $('a.showLocation').trigger('click'); } }); }); } } function refreshSearchResults(data) { $('#searchResults .container').empty().html(data); $('#searchResults li:not(.noResults) .resultContainer').highlight($('form#search input[name="q"]').val()); $('#searchResults li .resultContainer input[name="category"]').val($('form#search input[name="q"]').val()); if($('form#search input[name="location"]').val() !== '' && $('form#search input[name="location"]').val() !== 'i.e. New York, NY or 10007') { $('#searchResults li .resultContainer input[name="location"]').val($('form#search input[name="location"]').val()); $('#searchResults li .resultContainer input[name="location_id"]').val($('form#search input[name="location_id"]').val()); $('a.showLocation').trigger('click',['impact']); } activateSearchResults(); } function activateSearchResults() { bindSelect('select:not(".chzn-select"), input[type="checkbox"]'); $('#searchResults .bottom').on('click', function(){ closeSearchResults(); }); $('#searchResults').click(function(e) { // Only executed witht he No Results Lightbox if($('#searchResults table tr td').hasClass('noResults')) { var searchResultsWidth = 980; var minX = ($(window).width() - searchResultsWidth ) / 2; var maxX = ( ($(window).width() - searchResultsWidth ) / 2 ) + searchResultsWidth; if(e.pageX <= minX || e.pageX >= maxX ) closeSearchResults(); } else closeSearchResults(); }); $(document).keydown(function(key) { if(key.keyCode == '27') { closeSearchResults(); } }); first = $('#searchResults li:not(.noResults)').first(); grid_index = first.index(); first.addClass('hover') $('#searchResults li:not(.noResults)').hover(function() { $('#searchResults li.hover').removeClass('hover'); $(this).addClass('hover'); }, function() { $('#searchResults li.hover').removeClass('hover'); $('#searchResults li:first').addClass('hover'); }); } function closeSearchResults() { if(searchQ) { searchQ.abort(); } $('#searchResults .container').stop(true, true).slideUp(200, function() { $('#searchResults').stop(true, true).fadeOut(200); }); } function submitForm(link, formSelector, data) { showLoading(); //disable submit ask buttons if (link.attr('form') && (link.attr('form') == 'ask')) { link.bind('click', false); } data = typeof data !== 'undefined' ? data : $(formSelector).serialize(); if (cta && !td_globals.lgd_in) { data += '&cta=true'; } $.ajax({ url: link.attr('submit'), type: 'post', data: data, dataType: 'json', cache: false, success: function(response) { $('input, select').removeClass('error'); $('.labelField').removeClass('error').find('p.error').remove(); $('.errorMsg').stop(true, true).fadeOut(200); if(response.success) { if($('#lightbox').hasClass('settings')) { $('#lightbox #loading span').text('Updating...'); lightboxAJAX('/lightbox/account_settings?tab='+$('#accountSettings .tabContent.active').attr('tab')+'&lightbox=1'); } else if(typeof response.redirect !== 'undefined') { if(link.attr('form') == 'login') { $('#lightbox #loading span').text('Logging In...'); } window.location = response.redirect; } else if(response.reload) { window.location.reload(); } else if(response.friendifier) { if(typeof response.freq !== 'undefined') { $('#friendDropdown-'+response.id+' ul.options li a').each(function() { $(this).removeClass('active'); if(parseInt($(this).attr('frequency')) == response.freq) { $(this).addClass('active'); } }); } else { var button = $('a.friendifier[friend_id="'+response.id+'"]').first(); if ($('a.friendifier[area="lightbox"]').length > 0) { removeLoading(); closeLightbox(); } if(button.attr('friendship') == '0') { // SEND BUTTON button.fadeOut(100, function() { button.text('Cancel Friend Request').attr('friendship', '2').attr('submit', '/restapi/unfriend.json').fadeIn(400); }); } else if(button.attr('friendship') == '1') { // UNFRIEND BUTTON if(button.attr('area') == 'user_profile') { button.closest('.userContainer').slideUp(200, function() { $(this).closest('tr').remove(); }); } else { button.parent().find('.dropdownContainer').fadeOut(100, function() { $(this).remove(); }); button.fadeOut(100, function() { button.text('Send Friend Request').attr('friendship', '0').attr('submit', '/restapi/friend.json').fadeIn(400); }); } } else if(button.attr('friendship') == '2') { // CANCEL BUTTON button.fadeOut(100, function() { button.text('Send Friend Request').attr('friendship', '0').attr('submit', '/restapi/friend.json').fadeIn(400); }); } else if(button.attr('friendship') == '3') { // ACCEPT BUTTON if(button.attr('area') == 'pending') { button.closest('.userContainer').slideUp(200, function() { $(this).closest('tr').remove(); }); } else { friendDropdown = ''; button.parent().find('a.friendifier[friendship="4"]').fadeOut(100, function() { $(this).remove(); }); button.fadeOut(100, function() { button.text('Unfriend').attr('friendship', '1').attr('submit', '/restapi/unfriend.json').fadeIn(400); }); $(friendDropdown).hide().appendTo('#ctaContainer-'+response.id).delay(100).fadeIn(400, function() { bindDropdown($(this).find('.dropdown').attr('id')); }); button.closest('.user-CTA').append($(friendDropdown)).find('.dropdownContainer').delay(100).fadeIn(400, function() { bindDropdown($(this).find('.dropdown').attr('id')); }); } } else if(button.attr('friendship') == '4') { // IGNORE BUTTON if(button.attr('area') == 'pending') { button.closest('.userContainer').slideUp(200, function() { $(this).closest('tr').remove(); }); } else { button.fadeOut(100, function() { button.text('Send Friend Request').attr('friendship', '0').attr('submit', '/restapi/friend.json').fadeIn(400); }); } } } } else { removeLoading(); lightboxAJAX('/lightbox/success?title='+response.title+'&msgs='+response.msgs+'&lightbox=1'); } } else { removeLoading(); //in the case of errors rebind the ask submit if (link.attr('form') && (link.attr('form') == 'ask')) { link.unbind('click', false); } $.each(response.msgs, function(variable, msg) { if(typeof msg == 'object') { $.each(msg, function(index, error) { $($('input[name="'+variable+'[]"], select[name="'+variable+'[]"], textarea[name="'+variable+'[]"]')[index]).addClass('error').closest('.labelField').addClass('error').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.

    Filter between My Villij and Everyone using the tabs at the top of the feed.", append : ".main .pageHeading", step : 'next 1 / 5' } } else if( n == 1) { tooltip = { area : area, n : n, title: "Main Action Buttons", message : "At the top of every page you will see the Invite, Recommend, and Ask buttons

    Use them to start building your network, to ask for help, or to tell others about all of the great things they should check out. Keep in mind… A larger network means more people will be available to answer your questions.", append : ".main .pageHeading", step : 'next 2 / 5' } } else if( n == 2) { tooltip = { area : area, n : n, title: "Main Navigation Buttons", message : "At the top of every page you will also see your 3 Main Navigation Buttons. Scroll over each of these to quickly navigate to other parts of Villij.", append : "#header .container", step : 'next 3 / 5' } } else if( n == 3) { tooltip = { area : area, n : n, title: "Search Bar", message : "Use the Search Bar to view all the previously submitted content on the site. Feel free to enter a location (if location based) to filter the content to a particular geography.

    Suggestion: Keep it short & sweet (ex: Sushi, Book, Camera, Thai Restaurant, etc)", append : "#header .container", step : 'next 4 / 5' } } else if( n == 4) { tooltip = { area : area, n : n, title: "Your Profile & Account Settings", message : "Here you will find your personal profile where you can manage your account settings, sync with other social sites, and manage your notification frequency.

    Welcome to Villij!", append : "#header .container", step : 'close 5 / 5' } } } return tooltip; } function showTooltip(tooltip) { // Display Toolitps only when you first login if(!$.cookie("tooltip_closed")) { var called = false; if(tooltip && ($("[id^=tooltip-]").length === 0 || $("[id^=tooltip-]").length === 1)) { var attach = '
    X'; if(tooltip.title) attach += '

    '+tooltip.title; attach += '

    '+tooltip.message+'

    '+tooltip.step+'
    '; $(attach).appendTo(tooltip.append).delay(1000).animate({ scrollTop: 0 }, 800, function() { $(this).slideDown(400, function() { // Close Tooltip and save it on a cookie $('.tooltip a.close').live('click', function() { $.cookie("tooltip_closed", true , { expires: 1 }) ; closeTooltip($(this).closest('.tooltip'),true);}); $('.tooltip a.step').live('click', function(e) { if (!called) { closeTooltip($(this).closest('.tooltip')); called = true; } }); }) }); } } } function closeTooltip(tooltip,close) { var area = tooltip.attr('area'); tooltip.slideUp(400, function() { $(this).remove(); }); if(tooltip && ($("[id^=tooltip-]").length === 0 || $("[id^=tooltip-]").length === 1)) { toolTipper(area,true).done(function(response) { if(!close) showTooltip(getTooltip(area, parseInt(response[area]))); }); } } function set_vendor_data() { var vendor_id = $('input[name="vendor_data"]').val(); var vendor_type = $('input[name="vendor_data"]').data('vendor-type'); var vendor_name = $('input[name="vendor_data"]').data('vendor-name'); var vendor_location = $('input[name="vendor_data"]').data('vendor-location'); var vendor_loc_id = $('input[name="vendor_data"]').data('vendor-loc-id'); answer_type = $('#tout .typeSelector td a').filter(function() { return $.trim($(this).text()) == vendor_type; }); $(answer_type).trigger({type: 'click', vendor_id: vendor_id , vendor_name: vendor_name, vendor_location: vendor_location, vendor_loc_id: vendor_loc_id, vendor_type: vendor_type}); } // Activate Placeholders only on browser that are not // compatible with html5 placeholder function activatePlaceholders() { if(!Modernizr.input.placeholder){ $('[placeholder]').focus(function() { var input = $(this); if (input.val() == input.attr('dText')) { if(input.attr('type') != "password") { input.val(''); input.removeClass('placeholder'); if(input.attr('color')) input.css('color',input.attr('color')); } } }).blur(function() { var input = $(this); if (input.val() == '' || input.val() == input.attr('placeholder')) { if(input.attr('type') != "password") { input.addClass('placeholder'); input.val(input.attr('placeholder')); if(input.css('color') == "#4f1b46" || input.css('color') == "#05606c") { input.attr('color',input.css('color')); input.css('color','#BBBBBB') }; } } }).blur(); } } // Only for IE if(typeof String.prototype.trim !== 'function') { String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); } } //-------Show Location & Back to Show Location (X) Buttons ----------------- function activateShowLocationButtons() { var parentId = '#askQuestion'; $(parentId +' a.showLocation').live('click', function(e,impact) { $(this).hide(); $(parentId +' .category').width('100%'); if(impact != 'impact') $(parentId +' .addLocation').slideDown(400); else $(parentId +' .addLocation').show(); }); $(parentId +' a#closeLocation').live('click', function() { $(parentId +' a.showLocation').show(); $(parentId +' .category').width(''); $(parentId +' .addLocation').slideUp(400); }); $(parentId +' input[name="location"]').live('focus', function() { $(parentId +' a#closeLocation').css('background','#FFFFFF'); }).live('blur', function() { $(parentId +' a#closeLocation').css('background','#F9F9F9'); }); }