Repository navigation
Expand file tree
/
Copy pathddbasic.common.js
More file actions
87 lines (74 loc) · 2.49 KB
/
Copy pathddbasic.common.js
File metadata and controls
87 lines (74 loc) · 2.49 KB
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
(function($) {
/**
* Toggle opening hours
*/
function toggle_opening_hours() {
// Create toggle link
$('<a />', {
'class' : 'opening-hours-toggle js-opening-hours-toggle js-collapsed',
'href' : Drupal.t('#toggle-opening-hours'),
'text' : Drupal.t('Opening hours')
}).insertBefore('.js-opening-hours-toggle-element');
// Set variables
var element = $('.js-opening-hours-toggle');
var siteHeader = $('.site-header');
var scrollOffset = 0;
var scrollToTarget;
// Attach click
element.on('click touchstart', function(event) {
// Store clicked element for later use
var element = this;
// Toggle
$(this).next('.js-opening-hours-toggle-element').slideToggle('fast', function() {
// Toggle class
$(element).toggleClass('js-collapsed js-expanded');
// Set scroll offset
if ($('.site-header.js-fixed').length) {
// If the site header is fixed use the height
scrollOffset = $(siteHeader).height();
}
// Scroll to the top of the element
if ($(element).parents('.js-library-opening-hours-target').length) {
// If there is a wrapper element with the target class
scrollToTarget = $(element).parents('.js-library-opening-hours-target');
} else {
// Else let's scroll to the element clicked
scrollToTarget = $(element);
}
$.scrollTo(scrollToTarget, 500, {
offset: -scrollOffset,
axis: 'y'
});
// Remove focus from link
$(element).blur();
});
// Prevent default (href)
event.preventDefault();
});
}
// When ready start the magic.
$(document).ready(function () {
// Toggle opening hours.
toggle_opening_hours();
// Toggle footer menu.
$('.footer .pane-title').on('click', function() {
var element = $(this).parent();
$('.menu', element).toggle();
$(this).toggleClass('js-toggled');
});
// Check an organic group and library content.
// If a group does not contain both news and events
// then add an additional class to the content lists.
[
'.ding-group-news,.ding-group-events',
'.ding-library-news,.ding-library-events'
].forEach(function(e) {
var selector = e;
$(selector).each(function() {
if ($(this).parent().find(selector).size() < 2) {
$(this).addClass('js-og-single-content-type');
}
});
});
});
})(jQuery);