Skip to content
Snippets Groups Projects
Commit 30c7486f authored by Rafael Caferati's avatar Rafael Caferati
Browse files

fixed sideNav/accountBox toggle

Now the accoutBox also closes the flexNav; Removed deprecated userPop.
parent 04e73568
No related branches found
No related tags found
No related merge requests found
@AccountBox = (->
status = 0
self = {}
toggleArrow = (status) ->
if self.arrow.hasClass "left" or status? is -1
self.arrow.removeClass "left"
return
if not self.arrow.hasClass "left" or status? is 1
self.arrow.addClass "left"
setStatus = (status) ->
Meteor.call('UserPresence:setDefaultStatus', status)
toggle = ->
if status then close() else open()
open = ->
if self.arrow.hasClass "left"
SideNav.closeFlex()
return;
status = 1
self.options.removeClass("_hidden")
self.box.addClass("active")
toggleArrow 1
close = ->
status = 0
self.options.addClass("_hidden")
self.box.removeClass("active")
toggleArrow -1
init = ->
self.box = $(".account-box")
self.options = self.box.find(".options")
self.arrow = self.box.find(".arrow")
setStatus: setStatus
toggle: toggle
open: open
close: close
init: init
toggleArrow: toggleArrow
)()
\ No newline at end of file
......@@ -13,9 +13,11 @@
flexNav.removeClass "hidden"
openFlex = ->
AccountBox.toggleArrow 1
toggleFlex 1
closeFlex = ->
AccountBox.toggleArrow -1
toggleFlex -1
setFlex = (template, data={}) ->
......
@UserPop = (->
self = {}
self.pop = {}
win = $(window)
create = ->
if not self.pop.length
self.pop = $("<div/>").addClass("flex-pop")
self.wrapper = $("<div/>").addClass("wrapper")
self.pop.append self.wrapper
self.container.append self.pop
Blaze.render Template.userCard, self.wrapper.get(0)
else
self.wrapper.empty()
Blaze.render Template.userCard, self.wrapper.get(0)
return
empty = ->
self.wrapper.empty() if self.pop.length
###
* Position the self.pop element afer the user line
* @param {el} user element
* @return {}
###
position = (el) ->
if self.pop.length
last = getLastEl(el)
self.pop.insertAfter last
self.top = self.pop.position().top
getLineLength = ->
length = 0
self.$els.each ->
$item = $(@)
if $item.position().left < 40 and length > 0
return false;
else
length++
length
updateEls = ->
self.$els = self.container.children(self.el.tagName);
getCurrentLine = (el) ->
updateEls()
Math.ceil((self.$els.index(el) + 1) / getLineLength())
getLastEl = (el) ->
info = {}
info.top = $(el).position().top
self.$els.each ->
$item = $(@)
if $item.position().top > info.top
return false
info.current = $item
return info.current if info.current and info.current.length
animeIn = (callback) ->
startInterval()
getLineLength()
self.opening = 1
self.pop.addClass("opened")
setTimeout ->
self.opening = 0
self.opened = 1
callback() if callback
, 400
animeOut = (callback) ->
stopInterval()
self.opening = 1
self.pop.removeClass("opened")
unSelect()
setTimeout ->
self.opening = 0
self.opened = 0
self.pop.appendTo "body"
callback() if callback
, 400
enter = ($el) ->
selected $el
position($el.get(0))
Session.set 'userProfileActive', $el.find("a").data('userid')
unSelect = ->
self.$els.each ->
$(@).removeClass("selected")
selected = ($el) ->
unSelect()
$el.addClass("selected")
startInterval = ->
stopInterval()
self.interval = setInterval ->
if(!checkLine())
close()
, 250
stopInterval = ->
if self.interval
clearInterval self.interval
###
* Check if the selected user is in the same line as when the self.pop was opened.
* Also checks if the self.pop is in the same position as it was when first opened.
* @return {boolean}
###
checkLine = ->
if self.top != self.pop.position().top
return false
if self.currentLine != getCurrentLine self.el
return false
return true
open = (el) ->
$el = $(el)
self.el = el
self.container = $el.parent()
self.$els = self.container.children(el.tagName);
self.$el = $el
self.currentLine = getCurrentLine el
if $el.hasClass "selected"
close()
return
create()
if self.opened then close ->
enter($el)
setTimeout ->
animeIn()
, 10
else
enter($el)
setTimeout ->
animeIn()
, 10
resize = ->
if self.opened
close()
init = ->
$(window).unbind("resize.pop").bind "resize.pop", ->
resize()
close = (callback) ->
if self.opened
animeOut(callback)
open: open
close: close
init: init
)()
......@@ -395,7 +395,6 @@ Template.chatWindowDashboard.events
"click .flex-tab .user-image > a" : (e) ->
Session.set('flexOpened', true)
Session.set('showUserInfo', $(e.currentTarget).data('userid'))
# UserPop.open event.currentTarget
'click .user-card-message': (e) ->
roomData = Session.get('roomData' + this.rid)
......@@ -472,7 +471,6 @@ Template.chatWindowDashboard.onCreated ->
Template.chatWindowDashboard.onRendered ->
FlexTab.check()
UserPop.init()
ChatMessages.init()
console.log 'chatWindowDashboard.rendered' if window.rocketDebug
......
AccountBox = (->
status = 0
self = {}
setStatus = (status) ->
Meteor.call('UserPresence:setDefaultStatus', status)
toggle = ->
if status then close() else open()
open = ->
status = 1
self.options.removeClass("_hidden")
self.box.addClass("active")
self.arrow.addClass "left"
close = ->
status = 0
self.options.addClass("_hidden")
self.box.removeClass("active")
self.arrow.removeClass "left"
init = ->
self.box = $(".account-box")
self.options = self.box.find(".options")
self.arrow = self.box.find(".arrow")
setStatus: setStatus
toggle: toggle
open: open
close: close
init: init
)()
Template.userStatus.helpers
myUserInfo: ->
visualStatus = "online"
......@@ -45,7 +16,6 @@ Template.userStatus.helpers
}
Template.userStatus.events
'click .options .status': (event) ->
event.preventDefault()
AccountBox.setStatus(event.currentTarget.dataset.status)
......
......@@ -32,9 +32,6 @@ Template.userCard.events
if result.rid?
Router.go('room', { _id: result.rid })
"click .-close" : (event) ->
UserPop.close()
'click .remove-user': (event) ->
Meteor.call 'removeUserFromRoom', { rid: Router.current().params._id, uid: Session.get('userProfileActive') }, (error, result) ->
if error
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment