var MainRouter = Backbone.Router.extend({ init: false, currentEdit: null, experiences: null, routes : { "" : "showExperiences", "index/index/*rest": "showExperiences", "experience/show/id/:id": "showExperience", "Stoneman-Miriquidi": "showExperienceSMQ", "portal/region/*rest": "showExperienceByIds", "portal/category/*rest": "showExperienceByIds", "experience/:name" : "showExperienceFullScreen", "experience/show-by-user/*rest": "showExperienceByUser", }, initialize: function() { var that = this; that.initButtons(); that.initInput(); }, showExperienceFullScreen: function() { var that = this; $('.control-fullscreen').parent().hide(); application.controller.map.toggleFullscreen(); that.showExperience(application.options.experienceId); }, showExperienceByUser: function() { var that = this; var id = application.options.experienceId; application.controller.experience.loadExperiences(id, 'type,trackpoints,position,mainType,tourData,difficulty', function(experiences) { that.experiences = experiences; application.controller.map.options.forceTourMarker = true; application.controller.map.options.hoverTour = true; application.controller.map.drawExperiences(experiences); }); }, showExperienceByIds: function() { application.controller.map.options.forceTourMarker = true; application.controller.map.options.hoverTour = true; this.showExperience(application.options.ids); }, showExperienceSMQ: function() { this.showExperience(755); }, showExperience: function(id){ var that = this; application.controller.card.initCard($('.abs-card')); application.controller.experience.loadExperiences(id, 'type,trackpoints,position,mainType,tourData,difficulty', function(experiences) { that.experiences = experiences; if (that.experiences[0].type == 'tour') { application.controller.map.nextFitBounds = false; application.controller.map.drawExperiences(that.experiences); var track = that.experiences[0].track; var profile = application.controller.experience.addProfile(track, $('#abs-map-profile-wrapper'), application.controller.map); application.controller.map.fitTrackBounds(); var bounds = {north:track.NORTH, south:track.SOUTH, east:track.EAST, west:track.WEST}; application.controller.experience.loadPoisInBounds(bounds, true, function(experiences) { application.controller.map.setExperienceMode('marker'); application.controller.map.nextFitBounds = false; var marker = application.controller.map.drawExperiences(experiences, false); application.controller.map.setExperienceMode('full'); profile.addMarkers(marker, 'experienceMarker'); }); } else { application.controller.map.drawExperiences(that.experiences); } }); }, showExperiences: function(){ var id = ($.getUrlVar('ids') !== undefined) ? $.getUrlVar('ids') : '*'; var that = this; if (application.options.router.main.startExperienceMode == 'marker') { application.controller.experience.loadExperiences(id, null, function(experiences) { that.experiences = experiences; application.controller.map.setExperienceMode('marker'); application.controller.map.drawExperiences(that.experiences); }); } else { application.controller.experience.loadExperiences(id, 'type,trackpoints,position,mainType,tourData,difficulty', function(experiences) { that.experiences = experiences; application.controller.map.options.forceTourMarker = true; application.controller.map.setExperienceMode('full'); application.controller.map.drawExperiences(that.experiences); }); } }, initButtons: function() { $('#search-filter .option').click(function() { $(this).toggleClass('active'); }); $('.select').click(function() { $(this).toggleClass('checked'); }); $('#search-filter .select[data=selectAll]').click(function() { if ($(this).hasClass('checked')) { $(this).parents('.filter-select').find('.option').addClass('active'); } else { $(this).parents('.filter-select').find('.option').removeClass('active'); } }); $('.div-select .option').click(function () { var data = $(this).parent().attr('data'); if (data == 'radio') { $(this).parent().find('.option').removeClass('active').find('.experience-icon').addClass('inverted'); $(this).addClass('active').find('.experience-icon').removeClass('inverted'); } else { $(this).toggleClass('active'); $(this).find('.experience-icon').toggleClass('inverted'); } }); }, initInput: function() { $('input[type="text"], input[type="password"], textarea').addClass("idleField"); $('input[type="text"], input[type="password"], textarea').focus(function() { $(this).removeClass("idleField").addClass("focusField"); if ($(this).hasClass('default')) { if (this.value == this.defaultValue){ this.value = ''; } if(this.value != this.defaultValue){ this.select(); } } }); $('input[type="text"], input[type="password"], textarea').blur(function() { $(this).removeClass("focusField").addClass("idleField"); if ($(this).hasClass('default')) { if ($.trim(this.value) == '') { this.value = (this.defaultValue ? this.defaultValue : ''); } } }); }, }); $(document).ready(function() { application.addRouter('main', new MainRouter()); }); $.extend({ getUrlVars : function() { var vars = [], hash; var hashes = window.location.href.slice( window.location.href.indexOf('?') + 1).split('&'); for ( var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; }, getUrlVar : function(name) { return $.getUrlVars()[name]; } });