1717//= require bootstrap-tab-history
1818//= require cytoscape
1919//= require cytoscape-panzoom
20- //= require jscolor
2120//= require jquery.simplecolorpicker.js
2221//= require split
2322//= require handlebars.runtime
4140//= require ol
4241//= require ol-geocoder
4342
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- }
43+ const Index = {
44+ applySorting : function ( ) {
45+ Index . setParam ( "sort" , $ ( "#sort" ) . val ( ) ) ;
46+ } ,
6347
64- function reposition_tiles ( container , tileClass ) {
65- var $container = $ ( "." + container ) ;
48+ applyPerPage : function ( ) {
49+ Index . setParam ( "per_page" , $ ( "#per_page" ) . val ( ) ) ;
50+ } ,
6651
67- $container . imagesLoaded ( function ( ) {
68- $container . masonry ( {
69- // options...
70- itemSelector : "." + tileClass ,
71- columnWidth : 20
52+ applyDateParam : function ( param , value ) {
53+ const url = new URL ( window . location . href ) ;
54+ if ( param === 'start' && value === '/' ) {
55+ url . searchParams . delete ( param ) ;
56+ } else {
57+ url . searchParams . set ( param , value ) ;
58+ }
59+ window . location . replace ( url . toString ( ) ) ;
60+ } ,
61+
62+ setParam : function ( param , value ) {
63+ const url = new URL ( window . location . href ) ;
64+ url . searchParams . set ( param , value ) ;
65+ window . location . replace ( url . toString ( ) ) ;
66+ } ,
67+
68+ repositionTiles ( containerSelector , itemSelector ) {
69+ const container = $ ( containerSelector ) ;
70+ container . imagesLoaded ( function ( ) {
71+ container . masonry ( {
72+ // options...
73+ itemSelector : itemSelector ,
74+ columnWidth : 20
75+ } ) ;
7276 } ) ;
73- } ) ;
77+ }
7478}
7579
7680// Perform an ajax request to load the calendar and replace the contents
@@ -152,7 +156,7 @@ document.addEventListener("turbolinks:load", function(e) {
152156 $ ( 'a[data-toggle="tab"]' ) . on ( 'shown.bs.tab' , function ( e ) {
153157 addTabToFilters ( e . target . href . split ( '#' ) . pop ( ) ) ;
154158 // and reposition masonry tiles
155- reposition_tiles ( ' masonry', 'masonry-brick' ) ;
159+ Index . repositionTiles ( '. masonry', '. masonry-brick' ) ;
156160 } ) ;
157161
158162 // Manually trigger bootstrap tab history (we should probably remove the dependency and reimplement in a turbolink-compatible way)
@@ -168,12 +172,14 @@ document.addEventListener("turbolinks:load", function(e) {
168172
169173 // Masonry
170174 $ ( ".nav-tabs a" ) . on ( "shown.bs.tab" , function ( e ) {
171- reposition_tiles ( ' masonry', 'masonry-brick' ) ;
175+ Index . repositionTiles ( '. masonry', '. masonry-brick' ) ;
172176 } ) ;
177+
173178 $ ( window ) . on ( "orientationchange" , function ( ) {
174- reposition_tiles ( " masonry" , " masonry-brick" ) ;
179+ Index . repositionTiles ( '. masonry' , '. masonry-brick' ) ;
175180 } ) ;
176- reposition_tiles ( "masonry" , "masonry-brick" ) ;
181+
182+ Index . repositionTiles ( '.masonry' , '.masonry-brick' ) ;
177183
178184 new Clipboard ( ".clipboard-btn" ) ;
179185
0 commit comments