Pony.fm/resources/assets/scripts/shared/layout.coffee

67 lines
2 KiB
CoffeeScript
Raw Normal View History

# Pony.fm - A community for pony fan music.
# Copyright (C) 2015 Peter Deltchev
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2016-07-17 14:17:09 +02:00
window.isPlaying = false
2015-08-31 17:42:21 +02:00
window.handleResize = () ->
windowHeight = $(window).height()
windowWidth = $(window).width()
isMobile = windowWidth <= 480
2015-08-31 17:42:21 +02:00
$siteBody = $ '.site-body'
2016-07-17 14:17:09 +02:00
if window.isPlaying
$siteBody.height windowHeight - ($('.top-bar').height() + $('.now-playing').height())
else
$siteBody.height windowHeight - $('.top-bar').height()
2015-08-31 17:42:21 +02:00
$('.dropdown-menu').each () ->
$this = $ this
newMaxHeight = windowHeight - $this.parent().offset().top - $this.parent().height() - 5
$this.css
'max-height': newMaxHeight
$('.stretch-to-bottom').each () ->
2016-07-17 14:25:27 +02:00
$this = $ this
newHeight = windowHeight - $this.offset().top
if isMobile
newHeight = newHeight - 5
if window.isPlaying
newHeight = newHeight - $('.now-playing').height()
if newHeight > 0
$this.height newHeight
2015-08-31 17:42:21 +02:00
$('.revealable').each () ->
$this = $ this
return if $this.data 'real-height'
$this.data 'real-height', $this.height()
$this.css
height: '15em'
$this.find('.reveal').click (e) ->
e.preventDefault()
$this.css {height: 'auto'}
$(this).fadeOut 200
window.alignVertically = (element) ->
$element = $(element)
$parent = $element.parent()
$element.css 'top', $parent.height() / 2 - $element.height() / 2
window.handleResize()
$(window).resize window.handleResize
$('.site-content').empty()