Skip to content

Instantly share code, notes, and snippets.

@ivan-hilckov
Created July 25, 2012 12:25
Show Gist options
  • Select an option

  • Save ivan-hilckov/3175907 to your computer and use it in GitHub Desktop.

Select an option

Save ivan-hilckov/3175907 to your computer and use it in GitHub Desktop.
Menu
# # Меню Menu
# Связывает текущий экран и пункт меню ( через урл )
class window.Elections.Menu extends Backbone.View
events:
"click li" : "openMenuItem"
@init: ( params ) ->
new this( params )
initialize: ->
@options.app.on "viewOpen", ( view ) =>
this.activateMenuItem( view )
@options.app.on "viewClose", ( view ) =>
this.deactivateMenuItem( view )
activateMenuItem: ( view ) =>
this.$( "a[ href *= #{view.link} ]" ).parents( "li" ).addClass( "active" )
deactivateMenuItem: ( view ) =>
this.$( "a[ href *= #{view.link} ]" ).parents( "li" ).removeClass( "active" )
# Перехватывает повторный клик по меню, закрывая текущий экран и показывает предыдущий
openMenuItem: ( event ) ->
if $(event.target).parents( "li" ).hasClass( "active" )
event.preventDefault()
@options.app.router.gotoBack()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment