Skip to content

Commit f811c64

Browse files
committed
Namespace and camelCase some JS functions
1 parent 257210b commit f811c64

File tree

4 files changed

+44
-46
lines changed

4 files changed

+44
-46
lines changed

app/assets/javascripts/application.js

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,45 +41,41 @@
4141
//= require ol
4242
//= require ol-geocoder
4343

44-
function redirect_to_sort_url(){
45-
url = new URL(window.location.href);
46-
url.searchParams.set(
47-
"sort",
48-
$("#sort").find(":selected").val()
49-
);
50-
window.location.replace(url.toString());
51-
}
52-
53-
function apply_per_page(){
54-
url = new URL(window.location.href);
55-
url.searchParams.set(
56-
"per_page",
57-
$("#per_page").val()
58-
);
59-
window.location.replace(url.toString());
60-
}
61-
62-
function redirect_with_updated_search(param, paramVal) {
63-
url = new URL(window.location.href);
64-
// special case for empty range types
65-
if (param == 'start' && paramVal == '/') {
66-
url.searchParams.delete(param);
67-
} else {
68-
url.searchParams.set(param, paramVal);
69-
}
70-
window.location.replace(url.toString());
71-
}
72-
73-
function reposition_tiles(container, tileClass){
74-
var $container = $("." + container);
75-
76-
$container.imagesLoaded(function () {
77-
$container.masonry({
78-
// options...
79-
itemSelector: "." + tileClass,
80-
columnWidth: 20
44+
const Index = {
45+
applySorting: function () {
46+
Index.setParam("sort", $("#sort").val());
47+
},
48+
49+
applyPerPage: function () {
50+
Index.setParam("per_page", $("#per_page").val());
51+
},
52+
53+
applyDateParam: function (param, value) {
54+
const url = new URL(window.location.href);
55+
if (param === 'start' && value === '/') {
56+
url.searchParams.delete(param);
57+
} else {
58+
url.searchParams.set(param, value);
59+
}
60+
window.location.replace(url.toString());
61+
},
62+
63+
setParam: function (param, value) {
64+
const url = new URL(window.location.href);
65+
url.searchParams.set(param, value);
66+
window.location.replace(url.toString());
67+
},
68+
69+
repositionTiles(containerSelector, itemSelector) {
70+
const container = $(containerSelector);
71+
container.imagesLoaded(function () {
72+
container.masonry({
73+
// options...
74+
itemSelector: itemSelector,
75+
columnWidth: 20
76+
});
8177
});
82-
});
78+
}
8379
}
8480

8581
// Perform an ajax request to load the calendar and replace the contents
@@ -161,7 +157,7 @@ document.addEventListener("turbolinks:load", function(e) {
161157
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
162158
addTabToFilters(e.target.href.split('#').pop());
163159
// and reposition masonry tiles
164-
reposition_tiles('masonry', 'masonry-brick');
160+
Index.repositionTiles('.masonry', '.masonry-brick');
165161
});
166162

167163
// Manually trigger bootstrap tab history (we should probably remove the dependency and reimplement in a turbolink-compatible way)
@@ -177,12 +173,14 @@ document.addEventListener("turbolinks:load", function(e) {
177173

178174
// Masonry
179175
$(".nav-tabs a").on("shown.bs.tab", function(e) {
180-
reposition_tiles('masonry', 'masonry-brick');
176+
Index.repositionTiles('.masonry', '.masonry-brick');
181177
});
178+
182179
$(window).on("orientationchange", function() {
183-
reposition_tiles("masonry", "masonry-brick");
180+
Index.repositionTiles('.masonry', '.masonry-brick');
184181
});
185-
reposition_tiles("masonry", "masonry-brick");
182+
183+
Index.repositionTiles('.masonry', '.masonry-brick');
186184

187185
new Clipboard(".clipboard-btn");
188186

app/views/search/common/_facet_sidebar_date_filter.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
</li>
1111

1212
<li class="nav-item active" style="display: none; font-size: 15px; text-align: center;">
13-
<input type="date" name="<%= facet_field %>_lb" value="<%= lb %>" style="width: 47%;" onchange="redirect_with_updated_search('<%= facet_field %>', this.value + '/' + '<%= ub %>');">
13+
<input type="date" name="<%= facet_field %>_lb" value="<%= lb %>" style="width: 47%;" onchange="Index.applyDate('<%= facet_field %>', this.value + '/' + '<%= ub %>');">
1414
-
15-
<input type="date" name="<%= facet_field %>_ub" value="<%= ub %>" style="width: 47%;" onchange="redirect_with_updated_search('<%= facet_field %>', '<%= lb %>' + '/' + this.value);">
15+
<input type="date" name="<%= facet_field %>_ub" value="<%= ub %>" style="width: 47%;" onchange="Index.applyDate('<%= facet_field %>', '<%= lb %>' + '/' + this.value);">
1616
</li>
1717
</ul>
1818
</li>

app/views/search/common/_search_panel.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</div>
3030
<div class="search-results-per-page form-inline pull-right">
3131
<label for="per_page"><%= t('sidebar.per_page') %></label>
32-
<%= select_tag('per_page', per_page_options_for_select, onchange: 'apply_per_page()', class: 'font-size-sm') %>
32+
<%= select_tag('per_page', per_page_options_for_select, onchange: 'Index.applyPerPage()', class: 'font-size-sm') %>
3333
</div>
3434
<% end %>
3535
</div>

app/views/search/common/_sort_by.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ e.g.
2929
<li class="facet-sort-group">
3030
<span class="icon icon-lg sort-icon facet-sort-icon"></span>
3131
<%= select_tag(:sort, options_for_select(options, @sort_by),
32-
onchange: 'redirect_to_sort_url()', class: 'form-control facet-select font-size-sm facet-sort')
32+
onchange: 'Index.applySorting()', class: 'form-control facet-select font-size-sm facet-sort')
3333
%>
3434
</li>
3535
</ul>

0 commit comments

Comments
 (0)