Created
September 6, 2019 17:15
-
-
Save levelsio/52fab0141c2c484f4c4a715e44ce7a50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function updateSlug() { | |
| if( | |
| $('.filters .filter.month .choice.active').length>0 && | |
| $('.filters .filter.region .choice.active').length>0 | |
| ) { | |
| slug=''; | |
| } | |
| firstTemperatureDoneAlready=false; | |
| firstAirQualityDoneAlready=false; | |
| firstWithDoneAlready=false; | |
| firstRegionDoneAlready=false; | |
| firstCountryDoneAlready=false; | |
| beforeIsSelected=false; | |
| firstMonthDoneAlready=false; | |
| beforeSlugPart=''; | |
| afterSlugPart=''; | |
| monthSlugPart=''; | |
| temperatureSlugPart=''; | |
| countrySlugPart=''; | |
| regionSlugPart=''; | |
| withSlugPart=''; | |
| timeSlugPart=''; | |
| visaFreePart=''; | |
| slug=''; | |
| $('.filters .filter .choice.active').each(function() { | |
| key=$(this).data('filter-target'); | |
| filterSlug=$(this).data('filter-slug'); | |
| filterSlugPosition=$(this).data('filter-slug-position') | |
| if(!empty($(this).data('filter-slug'))) { | |
| value=$(this).data('filter-slug'); | |
| // | |
| } | |
| else if(!empty($(this).data('text'))) { | |
| value=$(this).data('text'); | |
| } | |
| else { | |
| value=$(this).text(); | |
| } | |
| value=str_replace('-',' ',makeUrlSlug(value)); | |
| value=value.trim(); | |
| if(!empty($(this).find('span').data('original-text'))) { | |
| value=$(this).find('span').data('original-text'); | |
| } | |
| if(key=='temperatureC_feels_like' || key=='temperatureC') { | |
| if(!firstTemperatureDoneAlready) { | |
| firstTemperatureDoneAlready=true; | |
| temperatureSlugPart= | |
| temperatureSlugPart+'-'+makeUrlSlug( | |
| value.toLowerCase() | |
| ); | |
| } | |
| else { | |
| temperatureSlugPart= | |
| temperatureSlugPart+'-or-'+makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'; | |
| } | |
| } | |
| else if(key=='air_quality' && !firstTemperatureDoneAlready) { | |
| monthsSelectedSlug='in-'; | |
| $('.filters .filter.month .choice.active').each(function() { | |
| monthsSelectedSlug=monthsSelectedSlug+makeUrlSlug($(this).data('filter-slug'))+'-and-'; | |
| }); | |
| monthsSelectedSlug=monthsSelectedSlug.substr(0,monthsSelectedSlug.length-4); | |
| // | |
| // | |
| if(monthsSelectedSlug=='in-') monthsSelectedSlug=''; | |
| if(!firstAirQualityDoneAlready) { | |
| firstAirQualityDoneAlready=true; | |
| withSlugPart= | |
| withSlugPart+'with-'+makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'+monthsSelectedSlug; | |
| } | |
| else { | |
| withSlugPart= | |
| withSlugPart+makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'+'or-'; | |
| } | |
| } | |
| else if(key=='24_hour') { | |
| timeSlugPart=timeSlugPart+'-'+filterSlug; | |
| } | |
| else if(key=='month') { | |
| if($('.filters .filter.month .choice.active').length>0) { | |
| value='to-visit-in-'+$('.filters .filter.month .choice.active').data('filter-slug'); | |
| monthSlugPart=monthSlugPart+'-'+ | |
| makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'; | |
| } | |
| } | |
| else if(key=='country') { | |
| if($('.filters .filter.country .choice.active').length==($('.filters .filter.country .choice').length-1)) { | |
| if(!firstCountryDoneAlready) { | |
| firstCountryDoneAlready=true; | |
| value=$('.filters .filter.country .choice:not(.active)').text(); | |
| countrySlugPart=countrySlugPart+'outside-'+ | |
| makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'; | |
| } | |
| } | |
| else { | |
| if(!firstCountryDoneAlready) { | |
| firstCountryDoneAlready=true; | |
| if($('.filters .filter.country .choice.active').length==1) { | |
| countrySlugPart=countrySlugPart+'in-'+makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'; | |
| } | |
| else { | |
| countrySlugPart=countrySlugPart+'in-'+ | |
| makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'; | |
| } | |
| } | |
| else { | |
| countrySlugPart=countrySlugPart+'or-'+ | |
| makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'; | |
| } | |
| } | |
| } | |
| else if(key=='region') { | |
| if($('.filters .filter.region .choice.active').length==($('.filters .filter.region .choice').length-1)) { | |
| if(!firstRegionDoneAlready) { | |
| firstRegionDoneAlready=true; | |
| value=$('.filters .filter.region .choice:not(.active)').text(); | |
| regionSlugPart=regionSlugPart+'outside-'+ | |
| makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'; | |
| } | |
| } | |
| else if($('.filters .filter.region .choice.active').length==($('.filters .filter.region .choice').length-2)) { | |
| if(!firstRegionDoneAlready) { | |
| firstRegionDoneAlready=true; | |
| i=0; | |
| $('.filters .filter.region .choice:not(.active)').each(function() { | |
| value=$(this).text(); | |
| if(i==0) { | |
| regionSlugPart=regionSlugPart+'outside-'+ | |
| makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'; | |
| } | |
| else { | |
| regionSlugPart='or-'+ | |
| makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'+regionSlugPart; | |
| } | |
| i++; | |
| }); | |
| } | |
| } | |
| else { | |
| if(!firstRegionDoneAlready) { | |
| firstRegionDoneAlready=true; | |
| if($('.filters .filter.region .choice.active').length==1) { | |
| regionSlugPart=regionSlugPart+'-in-'+makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'; | |
| } | |
| else { | |
| regionSlugPart=regionSlugPart+'-in-'+ | |
| makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'; | |
| } | |
| } | |
| else { | |
| regionSlugPart=regionSlugPart+'-or-'+ | |
| makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'; | |
| } | |
| } | |
| } | |
| else if(filterSlugPosition=='before') { | |
| if(!empty(filterSlug)) { | |
| beforeSlugPart=beforeSlugPart+'-'+filterSlug; | |
| } | |
| else { | |
| beforeSlugPart=beforeSlugPart+'-'+makeUrlSlug(value.toLowerCase()); | |
| } | |
| } | |
| else if(filterSlugPosition=='after') { | |
| if(!empty(filterSlug)) { | |
| afterSlugPart=afterSlugPart+'-'+filterSlug; | |
| } | |
| else { | |
| afterSlugPart=afterSlugPart+'-'+makeUrlSlug(value.toLowerCase()); | |
| } | |
| } | |
| else if(!empty(filterSlug)) { | |
| afterSlugPart=afterSlugPart+'-'+ | |
| filterSlug+'-'; | |
| } | |
| else { | |
| if(!firstWithDoneAlready) { | |
| firstWithDoneAlready=true; | |
| if(empty(filterSlug)) { | |
| withSlugPart=withSlugPart+'-with-'+ | |
| makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'; | |
| } | |
| else { | |
| withSlugPart=withSlugPart+'-with-'+ | |
| filterSlug+'-'; | |
| } | |
| } | |
| else { | |
| if(empty(filterSlug)) { | |
| withSlugPart=withSlugPart+'and-'+ | |
| makeUrlSlug( | |
| value.toLowerCase() | |
| )+'-'; | |
| } | |
| else { | |
| withSlugPart=withSlugPart+'and-'+ | |
| filterSlug+'-'; | |
| } | |
| } | |
| } | |
| //console.log('filterSlug',filterSlug); | |
| //console.log('beforeSlugPart',beforeSlugPart); | |
| //console.log('afterSlugPart',afterSlugPart); | |
| }); | |
| visaFreePart=''; | |
| $('.filters .filter.visa_free_for select.choices.active').each(function() { | |
| if(!empty(visaFreePart)) { | |
| visaFreePart=visaFreePart+'-and'; | |
| } | |
| visaFreePart=visaFreePart+'-'+$(this).find(':selected').data('filter-slug')+'-'; | |
| }); | |
| $('.filters .filter.visa_free_for_partner select.choices.active').each(function() { | |
| if(!empty(visaFreePart)) { | |
| visaFreePart=visaFreePart+'-and'; | |
| } | |
| visaFreePart=visaFreePart+'-'+str_replace('visa-free-for-citizens-of','',$(this).find(':selected').data('filter-slug'))+'-'; | |
| }); | |
| slug=slug.substr(0,slug.length-1); | |
| slug=str_replace('--','-',slug); | |
| slug=slug.trim('-'); | |
| if(slug.substr(0,1)=='-') slug=slug.substr(1,slug.length); | |
| if(slug.substr(slug.length-1,slug.length)=='-') slug=slug.substr(0,slug.length-1); | |
| if(!empty(activeSearch)) { | |
| slug='search'; | |
| } | |
| if(slug=='cities') { | |
| slug=''; | |
| } | |
| slug=temperatureSlugPart+beforeSlugPart+timeSlugPart+'-cities-'+afterSlugPart+countrySlugPart+regionSlugPart+withSlugPart+monthSlugPart+visaFreePart; | |
| slug=str_replace('----','-',slug); | |
| slug=str_replace('---','-',slug); | |
| slug=str_replace('--','-',slug); | |
| if(!empty(activeSearch)) { | |
| slug='/search'; | |
| value=activeSearch; | |
| if(hasEmojis(value)) { | |
| slug=slug+'/'+value; | |
| } | |
| else { | |
| slug=slug+'/'+ | |
| makeUrlSlug( | |
| value.toLowerCase() | |
| ); | |
| } | |
| } | |
| if(slug=='-cities-'+countrySlugPart) { | |
| slug=countrySlugPart.substr(2,countrySlugPart.length); | |
| } | |
| if(slug=='-cities-'+regionSlugPart) { | |
| slug=regionSlugPart.substr(2,regionSlugPart.length); | |
| } | |
| if(slug.substr(0,1)=='-') slug=slug.substr(1,slug.length); | |
| if(slug.substr(slug.length-1,slug.length)=='-') slug=slug.substr(0,slug.length-1); | |
| if(slug=='cities') slug=''; | |
| if(isLoggedIn && | |
| ( | |
| slug=='best-cities-in-my-favorites' || | |
| slug=='cities-in-my-favorites' || | |
| slug=='best-cities-in-my-wishlist' || | |
| slug=='cities-in-my-wishlist' || | |
| slug=='best-cities-in-my-wish-list' || | |
| slug=='cities-in-my-wish-list' | |
| ) | |
| ) { | |
| slug='/@'+userUsername+'/wish-list'; | |
| } | |
| if(slug.substr(0,6)=='cities' && slug.length<25) { | |
| slug='best-'+slug; | |
| } | |
| // | |
| pageUri=slug; | |
| if(typeof activeView==='undefined') { | |
| activeView=''; | |
| } | |
| if(typeof activeSort==='undefined') { | |
| activeSort=''; | |
| } | |
| if(typeof defaultSort==='undefined') { | |
| defaultSort='nomad_score'; | |
| } | |
| if(activeView=='map-3d') { | |
| pageUri=pageUri+'/3d'; | |
| } | |
| else if(activeView=='map') { | |
| pageUri=pageUri+'/map'; | |
| } | |
| else if(activeView=='chart') { | |
| if(!empty(activeSortAttributeToShow) && !empty(activeChartX)) { | |
| pageUri=pageUri+'/chart/'+activeChartY+'/vs/'+activeChartX; | |
| } | |
| else { | |
| pageUri=pageUri+'/chart'; | |
| } | |
| } | |
| // | |
| if(empty(slug)) { | |
| pageTitle='Nomad List'; | |
| } | |
| else { | |
| pageTitle=properlyCapitalize(str_replace('-',' ',str_replace('/',' ',slug))); | |
| } | |
| changeUrl(pageUri,pageHash,pageTitle); | |
| return [slug,pageTitle]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment