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 redirect_with_updated_search ( param , paramVal ) {
54- url = new URL ( window . location . href ) ;
55- // special case for empty range types
56- if ( param == 'start' && paramVal == '/' ) {
57- url . searchParams . delete ( param ) ;
58- } else {
59- url . searchParams . set ( param , paramVal ) ;
60- }
61- window . location . replace ( url . toString ( ) ) ;
62- }
63-
64- function reposition_tiles ( container , tileClass ) {
65- var $container = $ ( "." + container ) ;
66-
67- $container . imagesLoaded ( function ( ) {
68- $container . masonry ( {
69- // options...
70- itemSelector : "." + tileClass ,
71- 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+ } ) ;
7277 } ) ;
73- } ) ;
78+ }
7479}
7580
7681// Perform an ajax request to load the calendar and replace the contents
@@ -152,7 +157,7 @@ document.addEventListener("turbolinks:load", function(e) {
152157 $ ( 'a[data-toggle="tab"]' ) . on ( 'shown.bs.tab' , function ( e ) {
153158 addTabToFilters ( e . target . href . split ( '#' ) . pop ( ) ) ;
154159 // and reposition masonry tiles
155- reposition_tiles ( ' masonry', 'masonry-brick' ) ;
160+ Index . repositionTiles ( '. masonry', '. masonry-brick' ) ;
156161 } ) ;
157162
158163 // Manually trigger bootstrap tab history (we should probably remove the dependency and reimplement in a turbolink-compatible way)
@@ -168,12 +173,14 @@ document.addEventListener("turbolinks:load", function(e) {
168173
169174 // Masonry
170175 $ ( ".nav-tabs a" ) . on ( "shown.bs.tab" , function ( e ) {
171- reposition_tiles ( ' masonry', 'masonry-brick' ) ;
176+ Index . repositionTiles ( '. masonry', '. masonry-brick' ) ;
172177 } ) ;
178+
173179 $ ( window ) . on ( "orientationchange" , function ( ) {
174- reposition_tiles ( " masonry" , " masonry-brick" ) ;
180+ Index . repositionTiles ( '. masonry' , '. masonry-brick' ) ;
175181 } ) ;
176- reposition_tiles ( "masonry" , "masonry-brick" ) ;
182+
183+ Index . repositionTiles ( '.masonry' , '.masonry-brick' ) ;
177184
178185 new Clipboard ( ".clipboard-btn" ) ;
179186
0 commit comments