Last active
August 29, 2015 13:58
-
-
Save dbernar1/10285679 to your computer and use it in GitHub Desktop.
Some "literate CoffeeScript"
This file contains 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
when_the 'page_loads', -> | |
display_weather_analysis_map() | |
enable_changing_display_option_by_clicking_display_options() | |
enable_navigating_map_by_using_search() | |
display_weather_analysis_map = -> | |
when_the 'current_station_info_is_available', -> | |
show_map "analysis-map", false | |
show_what_station_is_being_shown() | |
enable_changing_display_option_by_clicking_display_options = -> | |
when_the_user_clicks any_of_the_display_options, ( clicked_element ) -> | |
perform_actions_that_should_happen_when( | |
'user_changes_display_option', | |
context = [ selected_display_option = clicked_element.hash.replace '#', ''] | |
) | |
when_the 'user_changes_display_option', switch_to_showing_selected_display_option | |
enable_navigating_map_by_using_search = -> | |
when_the_user_clicks the_magnifying_glass_button, -> | |
show_or_hide_search_form() | |
when_the_user_submits the_search_form, -> | |
perform_actions_that_should_happen_when( | |
'user_searches_for_a_location_in_analysis_map', | |
[ address = search_field().val() ] | |
) | |
when_the 'user_searches_for_a_location_in_analysis_map', recenter_the_map_on_the_searched_location | |
remember_the = ( selected_display_option ) -> | |
setCookie 'wf_fbc_analysis_display_option', selected_display_option, 365 | |
check_whether_the_user_has_selected_a_display_option = -> | |
selected_display_option = getCookie 'wf_fbc_analysis_display_option' | |
a_display_option_was_selected = selected_display_option != null | |
if a_display_option_was_selected | |
WF_FBC_MAP_GLOBALS.map_display_information = selected_display_option | |
highlight_the selected_display_option | |
highlight_the = ( selected_display_option ) -> | |
page_element( ".btn--deep-grey" ).toggleClass 'btn--deep-grey btn--white' | |
page_element( "a[href='#" + selected_display_option + "']" ).toggleClass 'btn--white btn--deep-grey' | |
recenter_the_map_on_the_searched_location = ( e, address ) -> | |
recenter_map_on_address address | |
display_data_for_the = ( selected_display_option ) -> | |
WF_FBC_MAP_GLOBALS.map_display_information = selected_display_option | |
WF_FBC_MAP_GLOBALS.remove_current_markers() | |
WF_FBC_MAP_GLOBALS.add_markers() | |
switch_to_showing_selected_display_option = ( e, selected_display_option ) -> | |
remember_the selected_display_option | |
highlight_the selected_display_option | |
display_data_for_the selected_display_option | |
log_that_the_user selected_display_option | |
log_that_the_user = ( selected_display_option ) -> | |
wf_fbc_log_event( | |
'UI usage tracking', | |
'User changed a display option on the analysis page to', | |
selected_display_option | |
) | |
update_analysis_interface_with_shown_station_info = ( e, shown_station ) -> | |
page_element( '#analysed-station-name' ).html shown_station.name | |
page_element( '#analysed-station-city-province' ).html shown_station.city_province | |
search_field().val shown_station.city_province | |
check_whether_the_user_has_selected_a_display_option() | |
show_or_hide_search_form = -> | |
the_search_form().toggleClass 'hidden' | |
the_magnifying_glass_button().toggleClass 'activated' | |
show_what_station_is_being_shown = -> | |
a_specific_station_was_requested_through_the_url = 'undefined' != typeof share_station | |
if a_specific_station_was_requested_through_the_url | |
when_the 'current_station_override_info_is_available', update_analysis_interface_with_shown_station_info | |
else | |
update_analysis_interface_with_shown_station_info null, WF_FBC.current_station |
This file contains 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
the_magnifying_glass_button = -> page_element '.magnifying-glass' | |
the_search_form = -> page_element '#search-analysis-map' | |
search_field = -> page_element '#analyse-search-field' | |
any_of_the_display_options = -> page_element '#display-options a:not(.magnifying-glass)' |
This file contains 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
when_the_user_clicks = ( selector, then_do_this ) -> | |
selector().on 'click', ( e ) -> | |
then_do_this( e.target ) | |
false | |
when_the_user_submits = ( selector, then_do_this ) -> | |
selector().on 'submit', -> | |
then_do_this() | |
false | |
page_element = jQuery | |
when_the = ( event_occurs, then_do_this ) -> | |
jQuery( document ).on event_occurs, then_do_this | |
jQuery -> | |
jQuery( document ).trigger 'page_loads' | |
perform_actions_that_should_happen_when = ( event_occurs, context ) -> | |
jQuery( document ).trigger( event_occurs, context ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment