-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathController.js
More file actions
162 lines (141 loc) · 5.55 KB
/
Controller.js
File metadata and controls
162 lines (141 loc) · 5.55 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
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
/*global ContactOwnerFormView, OpenSeadragon, tileSources, ExhibitPageView, FacetFormView, ItemView, ComplexCarouselView */
/*exported setupComponents */
'use strict';
// Component Controller
// ---------------------
// `setupComponents()` acts as a controller to create/destroy JS components
// based on which selectors are available/no longer available in the DOM.
// `setupComponents()` is called on `$(document).ready()`
var setupComponents = function(globalSearchForm, qm) {
// **CALISPHERE COMPONENTS**
// Calisphere components are subclasses of Backbone.js `Backbone.View` and
// are attached to the `globalSearchForm` namespace, an instance of the
// `GlobalSearchForm` component. Their model (where applicable) is `qm`, an
// instance of the `QueryManager`.
// Calisphere components all have constructors (called using the new
// keyword here) as well as a `destroy` function. Additionally, each has
// various user-action handlers - click, submit, etc.
if ($('#js-facet').length) {
globalSearchForm.facetForm = globalSearchForm.facetForm || new FacetFormView({model: qm, popstate: globalSearchForm.popstate});
} else if (globalSearchForm.facetForm) {
globalSearchForm.facetForm.destroy();
delete globalSearchForm.facetForm;
}
if ($('#js-carouselContainer').length) {
globalSearchForm.carousel = globalSearchForm.carousel || new ItemView({model: qm});
} else if (globalSearchForm.carousel) {
globalSearchForm.carousel.destroy();
delete globalSearchForm.carousel;
}
if($('#js-contactOwner').length) {
globalSearchForm.contactOwnerForm = globalSearchForm.contactOwnerForm || new ContactOwnerFormView();
} else if (globalSearchForm.contactOwnerForm) {
delete globalSearchForm.contactOwnerForm;
}
if($('.carousel-complex').length) {
globalSearchForm.complexCarousel = globalSearchForm.complexCarousel || new ComplexCarouselView({model: qm});
} else if (globalSearchForm.complexCarousel) {
globalSearchForm.complexCarousel.destroy();
delete globalSearchForm.complexCarousel;
}
if($('#js-exhibit-title').length) {
globalSearchForm.exhibitPage = globalSearchForm.exhibitPage || new ExhibitPageView();
} else if (globalSearchForm.exhibitPage) {
globalSearchForm.exhibitPage.destroy();
delete globalSearchForm.exhibitPage;
}
// **VENDOR INITIALIZATION**
// These JS components are classes imported from external libraries and
// don't need their own Calisphere-specific componentry beyond the options
// available in their initialization.
// **OpenSeadragon Viewer for hosted image content**
if($('#obj__osd').length) {
// Unlike some other components, the viewer leaves behind some cruft,
// so we cannot just reuse the same viewer for different images.
// Instead we have to destroy the previous viewer (if one exists),
// and create a new one
if(globalSearchForm.viewer) {
globalSearchForm.viewer.destroy();
delete globalSearchForm.viewer;
$('#obj__osd').empty();
}
if ($('.openseadragon-container').length) { $('.openseadragon-container').remove(); }
globalSearchForm.viewer = new OpenSeadragon({
id: 'obj__osd',
toolbar: 'obj__osd-toolbar',
tileSources: [tileSources],
zoomInButton: 'obj__osd-button-zoom-in',
zoomOutButton: 'obj__osd-button-zoom-out',
homeButton: 'obj__osd-button-home',
fullPageButton: 'obj__osd-button-fullscreen',
rotateLeftButton: 'obj__osd-button-rotate-left',
rotateRightButton: 'obj__osd-button-rotate-right',
showRotationControl: true
});
globalSearchForm.viewer.addHandler('home', function (data) {
data.eventSource.viewport.setRotation(0);
});
}
// if the viewer exists, but the hosted image content
// selector `#obj__osd` does not, then just destroy the viewer
else if (globalSearchForm.viewer) {
globalSearchForm.viewer.destroy();
delete globalSearchForm.viewer;
}
// **Isotope Masonry grid for Exhibitions random explore page**
if($('#js-exhibit-wrapper').length) {
globalSearchForm.grid = $('#js-exhibit-wrapper').isotope({
layoutMode: 'masonry',
itemSelector: '.js-grid-item',
percentPosition: true,
masonry: {
columnWidth: '.js-grid-sizer'
}
});
}
// **Text Truncation**
//Item page, item title
$('.obj__heading').dotdotdot({
ellipsis: '…',
watch: 'window',
height: 50,
lastCharacter: { // remove these characters from the end of the truncated text:
remove: [ ' ', ',', ';', '.', '!', '?', '[', ']' ]
}
});
//Search results page, item title
$('.thumbnail__caption').dotdotdot({
ellipsis: '…',
watch: 'window',
height: 30,
lastCharacter: {
remove: [ ' ', ',', ';', '.', '!', '?', '[', ']' ]
}
});
//Item page, carousel, item title
$('.carousel__thumbnail-caption').dotdotdot({
ellipsis: '…',
watch: 'window',
height: 30,
lastCharacter: {
remove: [ ' ', ',', ';', '.', '!', '?', '[', ']' ]
}
});
// **Infinite Scroll on Collection Browse pages**
// Collections A-Z, Collections Random Explore,
// and Collections at <institution> Pages
if($('#js-mosaicContainer').length) {
if($('#js-collectionPagination a.js-next').length) {
$('#js-mosaicContainer').infiniteScroll({
path: '#js-collectionPagination a.js-next',
append: '#js-mosaicContainer div.js-collectionMosaic',
history: false,
hideNav: '#js-collectionPagination',
debug: false,
status: '#js-loading'
});
} else {
$('#js-loading').hide();
}
}
};