-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.js
302 lines (273 loc) · 11.1 KB
/
functions.js
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/**
* Muis - Theme functions file
*
* @package Muis
*/
var _window = jQuery(window);
var _document = jQuery(document);
var _body = jQuery('body');
var _navbar_visible_area =100;
var _tablet_width = 950;
var _smallscreen_width = 481;
var _gallery_image_height_factor =0.75;
var _gallery_image_width_factor =0.9;
var _gallery_image_border =20;
var _ajax_loader_edge =150;
var _vmin =function() {
if( _window.height() < _window.width() )
return _window.height();
else
return _window.width();
};
var _vmax =function() {
if( _window.height() > _window.width() )
return _window.height();
else
return _window.width();
};
( function($) {
// Custom frontpage header
var header = {
widget_el: false,
widget_content_el: false,
media_el: false,
font_size_vmax: 0.04,
init: function() {
this.widget_el =$('#header-widget');
this.widget_content_el =this.widget_el.find( '#header-widget-contents' );
this.media_el =$('#custom-header-media');
if( this.widget_el.length == 1 && this.media_el.length == 1 ) {
_window.on( 'ready load resize', this.update );
}
},
update: function() {
var mediaHeight =header.media_el.height();
header.widget_el.css( 'height', mediaHeight + 'px' );
if( header.widget_content_el.length == 1 ) {
var text_el =header.widget_content_el.find( '.header-text h1' );
if( text_el.length == 1 ) {
text_el.css( 'font-size', Math.round( _vmax() * header.font_size_vmax ) + 'px' );
}
var contentHeight =header.widget_content_el.height();
if( contentHeight < mediaHeight )
header.widget_content_el.css( 'margin-top', Math.round( mediaHeight / 2 - contentHeight / 2 ) );
else
header.widget_content_el.css( 'margin-top', '0' );
}
}
};
header.init();
// Navbar
var navbar = {
header: false,
menu_button: false,
init: function() {
this.header =$('#masthead');
if( this.header.length == 1 ) {
_window.on( 'ready load resize', this.update );
_window.on( 'scroll.fixed', navbar.scroll );
}
this.menu_button =$('#menu-button');
if( this.menu_button.length == 1 ) {
this.menu_button.on( 'click', function() { navbar.header.fadeIn( 'fast' ); } );
}
},
update: function() {
// Make room for the admin panel
var wpadmin =$('#wpadminbar');
if( wpadmin.length == 1 ) {
navbar.header.css( 'top', wpadmin.height() + 'px' );
}
else {
navbar.header.css( 'top', '0' );
}
if( _window.width() < _tablet_width ) {
navbar.header.hide();
}
navbar.scroll();
},
scroll: function() {
if( _window.width() < _tablet_width ) {
navbar.header.fadeOut( 'fast' );
}
else if( _window.scrollTop() > _navbar_visible_area && navbar.header.css( 'display' ) !== 'none' ) {
navbar.header.fadeOut( 'fast' );
} else if( _window.scrollTop() <= _navbar_visible_area && navbar.header.css( 'display' ) === 'none' ) {
navbar.header.fadeIn( 'fast' );
}
}
};
navbar.init();
// Sidebar
var sidebar = {
el: false,
main: false,
default_width: false,
init: function() {
this.el =$('#sidebar');
this.main =$('#main');
if( this.el.length == 1 && this.main.length == 1 ) {
this.default_width =this.main.css( 'width' );
_window.on( 'load ready resize', this.update );
}
},
update: function() {
if( _window.width() < _tablet_width ) {
sidebar.el.hide();
sidebar.main.css( 'width', '100%' );
}
else {
sidebar.main.css( 'width', sidebar.default_width );
sidebar.el.show();
}
}
};
sidebar.init();
// Gallery mode - enables if posts of the image-class are shown
var gallery = {
images: false,
init: function() {
/*this.update();
if( this.images.length > 0 ) {
this.update();*/
_window.on( 'ready load resize', gallery.update );
//}
},
update: function() {
gallery.images =$('.gallery-backdrop');
var winWidth =_window.width();
var winHeight =_window.height();
// Center every image and make the backdrop window-sized
var previous =null;
gallery.images.each( function(index) {
var backdrop =$(this);
backdrop.css( 'width', winWidth + 'px' );
backdrop.css( 'height', winHeight + 'px' );
var container =backdrop.find('.gallery-image');
if( container.length == 0 )
return;
var image =container.find('img').first();
// Scale image depending on image and window width-height ratio
if( image.height() / image.width() < winHeight / winWidth ) {
image.css( 'height', 'auto' );
if( winWidth < _smallscreen_width )
image.css( 'width', winWidth + 'px' );
else
image.css( 'width', Math.round( winWidth * _gallery_image_width_factor ) + 'px' );
if( image.height() <= 0 )
return;
} else {
image.css( 'width', 'auto' );
image.css( 'height', Math.round( winHeight * _gallery_image_height_factor ) + 'px' );
if( image.width() <= 0 )
return;
}
/*container.css( 'margin-top', -Math.round( container.height() / 2 ) + 'px' );
container.css( 'margin-left', -Math.round( container.width() / 2 ) + 'px' );*/
container.css( 'margin-top', -Math.round( image.height() / 2 + _gallery_image_border ) + 'px' );
container.css( 'margin-left', -Math.round( image.width() / 2 + _gallery_image_border ) + 'px' );
image.fadeIn( 'fast' );
// Fix the 'prev image' button
var prev_top =previous != null ? previous.position().top : 0;
var prev_bttn =backdrop.find( '.gallery-prev-button' );
prev_bttn.off( 'click' );
prev_bttn.on( 'click', function(e) {
e.preventDefault();
$('html,body').animate( { scrollTop: prev_top }, 400 );
} );
// Now fix the 'next image' button
var next_bttn =backdrop.find( '.gallery-next-button' );
next_bttn.off( 'click' );
if( index == gallery.images.length - 1 ) {
next_bttn.on( 'click', function(e) {
e.preventDefault();
var link =$(this);
link.off( 'click' );
$("html, body").animate( { scrollTop: _document.height() - _window.height() }, 400 );
loading.forceLoad( true );
} );
}
else {
next_bttn.on( 'click', function(e) {
e.preventDefault();
$("html, body").animate( { scrollTop: backdrop.position().top + backdrop.height() }, 400 );
} );
}
previous =backdrop;
} );
}
};
gallery.init();
// Infinite loading for index page
var loading = {
start_from: _ajax_loader_edge,
el: false,
nav: false,
loader: false,
enabled: false,
ajax: false,
init: function() {
this.el = $('.paging-navigation a');
if (this.el.length == 1) {
this.nav = this.el.parent();
this.loader = $('#infinite-loader');
this.enabled =true;
_window.on('ready load resize scroll.loading', loading.process);
}
},
process: function() {
if (loading.enabled && !loading.ajax) {
if (_window.scrollTop() > (_document.height() - _window.height()) - loading.start_from) {
loading.load(false);
}
}
},
forceLoad: function() {
if (loading.enabled && !loading.ajax) {
loading.load(true);
}
},
load: function( focus ) {
loading.loader.addClass('active');
loading.ajax = true;
$.ajax({
type: 'GET',
url: loading.el.attr('href'),
dataType: 'html',
success: function(response) {
var html = $(response);
var next_link = html.find('.paging-navigation a');
var items = html.find('.entry');
items.each(function() {
var $entry =$(this);
$entry.insertBefore(loading.nav);
var $gimage =$entry.find( '.gallery-image img' );
// Lazy loading can prevent the load event from being triggered, so we disable it for the gallery images
$gimage.attr('loading', 'eager' );
if( $gimage.length == 1 ) {
$gimage.one( 'load', function() {
gallery.update();
$entry.hide();
$entry.fadeIn('slow');
} );
}
});
if (next_link.length == 1) {
loading.el.attr('href', next_link.attr('href'));
loading.ajax = false;
}
else {
_window.off('scroll.loading');
}
loading.loader.removeClass('active');
// Optionally, scroll to the first new element
if( focus ) {
var first_item =items.first();
$("html, body").animate( { scrollTop: first_item.position().top }, 400 );
}
}
});
}
};
loading.init();
})( jQuery );