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
0 commit comments