2012-12-11 00:34:06 +08:00
|
|
|
define [
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
2012-12-15 08:58:14 +08:00
|
|
|
'globals',
|
2013-11-01 03:36:38 +08:00
|
|
|
'text!templates/session_navbar.html'
|
|
|
|
], ($, _, Backbone, globals, sessionNavbarTemplate) ->
|
2012-12-11 00:34:06 +08:00
|
|
|
|
|
|
|
# The navbar in a session
|
|
|
|
# The contents are rendered by SessionView, this class is Used to
|
|
|
|
# manage the events in the navbar.
|
2013-11-01 21:22:02 +08:00
|
|
|
# @todo it triggers window.resize() in several methods so the svg inside the presentation is
|
|
|
|
# redraw properly, but this should be more dynamic in the future
|
2012-12-11 00:34:06 +08:00
|
|
|
SessionNavbarView = Backbone.View.extend
|
|
|
|
events:
|
2013-11-01 03:36:38 +08:00
|
|
|
"click #hide-menu-btn": "_hideMenu"
|
2012-12-15 08:41:30 +08:00
|
|
|
"click #users-btn": "_toggleUsers"
|
2013-11-01 03:36:38 +08:00
|
|
|
"click #chat-btn": "_toggleChat"
|
2013-09-24 21:13:09 +08:00
|
|
|
"click #video-btn": "_toggleVideo"
|
2013-11-01 03:36:38 +08:00
|
|
|
"click #audio-btn": "_toggleAudio"
|
|
|
|
"click #logout-btn": "_logout"
|
2012-12-11 00:34:06 +08:00
|
|
|
|
|
|
|
initialize: ->
|
|
|
|
@$parentEl = null
|
|
|
|
|
2012-12-15 08:41:30 +08:00
|
|
|
render: ->
|
2012-12-15 08:58:14 +08:00
|
|
|
compiledTemplate = _.template(sessionNavbarTemplate)
|
|
|
|
@$el.html compiledTemplate
|
2012-12-15 08:41:30 +08:00
|
|
|
@_setToggleButtonsStatus()
|
|
|
|
|
2012-12-13 10:04:43 +08:00
|
|
|
# Ensure the status of the toggle buttons is ok
|
2012-12-15 08:41:30 +08:00
|
|
|
_setToggleButtonsStatus: ->
|
2013-11-01 03:36:38 +08:00
|
|
|
$("#chat-btn", @$el).toggleClass "active", @$parentEl.hasClass("chat-on")
|
|
|
|
$("#users-btn", @$el).toggleClass "active", @$parentEl.hasClass("users-on")
|
|
|
|
$("#video-btn", @$el).toggleClass "active", @$parentEl.hasClass("video-on")
|
|
|
|
$("#audio-btn", @$el).toggleClass "active", @$parentEl.hasClass("audio-on")
|
|
|
|
|
2012-12-13 10:04:43 +08:00
|
|
|
# Toggle the visibility of the chat panel
|
2012-12-15 08:41:30 +08:00
|
|
|
_toggleChat: ->
|
2013-11-01 22:53:41 +08:00
|
|
|
@_scheduleResize('#chat') # has to be the first method called!
|
2013-11-01 03:36:38 +08:00
|
|
|
@$parentEl.toggleClass('chat-on')
|
2012-12-15 08:41:30 +08:00
|
|
|
@_setToggleButtonsStatus()
|
2012-12-11 00:34:06 +08:00
|
|
|
|
2012-12-13 10:04:43 +08:00
|
|
|
# Toggle the visibility of the users panel
|
2012-12-15 08:41:30 +08:00
|
|
|
_toggleUsers: ->
|
2013-11-01 03:36:38 +08:00
|
|
|
@$parentEl.toggleClass('users-on')
|
|
|
|
@_setToggleButtonsStatus()
|
|
|
|
|
|
|
|
_toggleVideo: ->
|
2013-11-01 22:53:41 +08:00
|
|
|
@_scheduleResize('#video') # has to be the first method called!
|
2013-11-01 03:36:38 +08:00
|
|
|
@$parentEl.toggleClass('video-on')
|
|
|
|
@_setToggleButtonsStatus()
|
|
|
|
|
|
|
|
_toggleAudio: ->
|
|
|
|
@$parentEl.toggleClass('audio-on')
|
2012-12-15 08:41:30 +08:00
|
|
|
@_setToggleButtonsStatus()
|
2013-01-06 07:40:29 +08:00
|
|
|
|
2013-11-01 03:36:38 +08:00
|
|
|
_hideMenu: ->
|
|
|
|
@$parentEl.removeClass('navbar-on')
|
|
|
|
@_setToggleButtonsStatus()
|
2013-11-01 22:53:41 +08:00
|
|
|
|
|
|
|
# Waits for an element with id `id` to be displayed or hidden in the page.
|
|
|
|
# Hackishy way to update the size of the presentation when a section of the page
|
|
|
|
# is made visible or hidden.
|
|
|
|
_scheduleResize: (id) ->
|
|
|
|
attempts = 0
|
|
|
|
before = $(id).is(':visible')
|
|
|
|
interval = setInterval( ->
|
|
|
|
if $(id).is(':visible') != before or attempts > 20
|
|
|
|
attempts += 1
|
|
|
|
clearInterval(interval)
|
|
|
|
# @todo why do we have to do it twice? doing only once doesn't work as expected!
|
|
|
|
$(window).resize()
|
|
|
|
$(window).resize()
|
|
|
|
, 100)
|
2012-12-11 00:34:06 +08:00
|
|
|
|
|
|
|
# Log out of the session
|
2012-12-15 08:41:30 +08:00
|
|
|
_logout: ->
|
2012-12-11 00:34:06 +08:00
|
|
|
globals.connection.emitLogout()
|
2012-12-11 09:51:01 +08:00
|
|
|
globals.currentAuth = null
|
2013-11-01 03:36:38 +08:00
|
|
|
|
2012-12-11 00:34:06 +08:00
|
|
|
SessionNavbarView
|