aboutsummaryrefslogtreecommitdiffstats
path: root/view/tpl/cover_photo_widget.tpl
blob: 7739d24b8ed58e0ba0301813f93b7d64d293c2b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<script>
	var aside_padding_top;
	var section_padding_top;
	var coverSlid = false;
	var hide_cover = Boolean({{$hide_cover}});
	var cover_height;

	$(document).ready(function() {
		if(! $('#cover-photo').length)
			return;

		if($(window).width() < 755) {
			$('#cover-photo').remove();
			coverSlid = true;
			return;
		}

		$('#cover-photo').removeClass('d-none');
		cover_height = Math.ceil($(window).width()/2.75862069);
		$('#cover-photo').css('height', cover_height + 'px');
		datasrc2src('#cover-photo > img');

		$(document).on('click mouseup keyup', slideUpCover);

		if(hide_cover) {
			hideCover();
		}
		else if(!hide_cover && !coverSlid)  {
			coverVisibleActions();
		}
	});

	$(window).scroll(function () {
		if($(window).scrollTop() >= cover_height) {
			coverHiddenActions();
			coverSlid = true;
		}
		else if ($(window).scrollTop() < cover_height){
			if(coverSlid) {
				$(window).scrollTop(cover_height);
				setTimeout(function(){ coverSlid = false; }, 1000);
			}
			else {
				if($(window).scrollTop() < cover_height) {
					coverVisibleActions();
				}
			}
		}
		if($('main').css('opacity') < 1) {
			$('main').css('opacity', ($(window).scrollTop()/cover_height).toFixed(1));
		}
	});

	$(window).resize(function () {
		cover_height = Math.ceil($(window).width()/2.75862069);
		$('#cover-photo').css('height', cover_height + 'px');
		if($(window).width() < 755) {
			$('#cover-photo').remove();
			$('.navbar').addClass('fixed-top');
			$('main').css('opacity', 1);
			coverSlid = true;
		}

	});

	function slideUpCover() {
		if(coverSlid) {
			return;
		}
		$('html, body').animate({scrollTop: cover_height + 'px'}, 'fast');
		return;
	}

	function hideCover() {
		if(coverSlid) {
			return;
		}
		window.scrollTo(0, cover_height);
		return;
	}

	function coverVisibleActions() {
		$('body').css('cursor', 'n-resize');
		$('.navbar').removeClass('fixed-top');
		$('main').css('margin-top', - $('nav').outerHeight(true) + 'px');
		$('main').css('opacity', 0);
	}

	function coverHiddenActions() {
		$('body').css('cursor', '');
		$('.navbar').addClass('fixed-top');
		$('main').css('margin-top', '');
		$('main').css('opacity', 1);
	}
</script>

<div class="d-none" id="cover-photo" title="{{$hovertitle}}">
	{{$photo_html}}
	<div id="cover-photo-caption">
		<h1>{{$title}}</h1>
		<h3>{{$subtitle}}</h3>
	</div>
</div>