1(function( $ ) { 2 3 /** 4 * Equalize Function. 5 * 6 * @param object (required) var settings 7 * 8 * @since 1.0.0 9 */ 10 CMWP_Mega_Teaser_Equalizer = function( settings ) { 11 12 // Set equalizer 13 var equalizer = this; 14 15 // Set default properties. 16 equalizer.parent = {}; 17 equalizer.priorities = {}; 18 equalizer.settings = settings; 19 equalizer.force = false; 20 21 // Set resize flags. 22 equalizer.timeout = null; 23 equalizer.windowWidth = $( window ).width(); 24 25 // Construct equalizer. 26 equalizer.construct = function() { 27 28 // Try to get all datas we need. 29 if ( false === equalizer.collectDatas() ) { 30 return false; 31 } 32 33 // If we are in builder mode we need to call directly. 34 if ( equalizer.inEdit() ) { 35 equalizer.init(); 36 } 37 38 // Set events. 39 equalizer.setEvents(); 40 } 41 42 43 44 // Collector method for getting initial informations. 45 equalizer.collectDatas = function() { 46 47 // Try to get the force. 48 if ( equalizer.settings.hasOwnProperty( 'force' ) ) { 49 equalizer.force = equalizer.settings.force; 50 } 51 52 // Try to get parent. 53 if ( ! $( equalizer.settings.parent ).length ) { 54 return false; 55 } 56 equalizer.parent = $( equalizer.settings.parent ); 57 58 // Check if we got some elements to equalize, else we dont need to equalize. 59 if ( 0 == equalizer.settings.priorities.length ) { 60 return false; 61 } 62 63 // Check inactive elements to delete them. 64 for ( var priority in equalizer.settings.priorities ) { 65 var element_settings = equalizer.settings.priorities[ priority ]; 66 var count_elements = equalizer.parent.find( element_settings.selector ).length; 67 68 // Check if selector goes to nothing or status is false to delete elements. 69 if ( 1 >= count_elements || 'false' == element_settings.status ) { 70 delete equalizer.settings.priorities[ priority ]; 71 } 72 } 73 74 // Check after cleaning if we have some elements left to equalize. 75 if ( 0 == equalizer.settings.priorities.length ) { 76 return false; 77 } 78 79 // Set priorities property and return true for success collecting datas. 80 equalizer.priorities = equalizer.settings.priorities; 81 return true; 82 } 83 84 85 86 // Method to set events. 87 equalizer.setEvents = function() { 88 89 // Init on load if there is no force. 90 if ( ! equalizer.force ) { 91 $( window ).load( function() { 92 equalizer.init(); 93 }); 94 } else { 95 equalizer.init(); 96 } 97 98 // Init on resize. 99 $( window ).resize( equalizer.resizeInit ); 100 $( document ).on( 'filtered', equalizer.reinit ); 101 } 102 103 104 105 // Method to reinit equalizer. 106 equalizer.reinit = function() { 107 equalizer.collectDatas(); 108 equalizer.init(); 109 } 110 111 112 113 // Method to go through priorities to set heights if necessary. 114 equalizer.init = function() { 115 116 // Unset heights to calculate fresh. 117 equalizer.unsetHeights(); 118 119 // Go through all elements. 120 for ( var priority in equalizer.priorities ) { 121 var element_settings = equalizer.priorities[ priority ]; 122 123 // Check if child is allowed to equalize. 124 if ( ! equalizer.inBreakpoints( element_settings.breakpoints ) ) { 125 return true; 126 } 127 128 // Set equalized height. 129 var element_height = equalizer.getMaxHeight( equalizer.priorities[ priority ].selector ); 130 equalizer.parent.find( element_settings.selector ).css( 'height', element_height + 'px' ); 131 } 132 133 equalizer.windowWidth = $( window ).width(); 134 } 135 136 137 138 // Method to check if actual window width is in breakpoint range. 139 equalizer.inBreakpoints = function( breakpoints ) { 140 141 // Set vars. 142 var min = breakpoints.min; 143 var max = breakpoints.max; 144 145 // Check breakpoints. 146 if ( '' !== min && '' !== max ) { 147 if ( $( window ).width() <= max && $( window ).width() >= min ) { 148 return true; 149 } 150 } else if ( '' !== min && '' === max ) { 151 if ( $( window ).width() >= min ) { 152 return true; 153 } 154 } else if ( '' !== max && '' === min ) { 155 if ( $( window ).width() <= min ) { 156 return true; 157 } 158 } else { 159 return true; 160 } 161 return false; 162 } 163 164 165 166 // Method to wrap init for resize action. 167 equalizer.resizeInit = function() { 168 169 // Check if timeout has been set. 170 if ( equalizer.timeout ) {
171 clearTimeout( equalizer.timeout ); 172 } 173 174 // Call this wrapped functions after timeout. 175 equalizer.timeout = setTimeout( function() { 176 equalizer.timeout = null; 177 178 // Check if there are changes in window width. 179 if ( equalizer.windowWidth !== $( window ).width() ) { 180 equalizer.init(); 181 } 182 }, 500 ); 183 } 184 185 186 187 // Method to normalize a child by selector. 188 equalizer.normalize = function( selector ) { 189 $( equalizer.parent ).find( selector ).css( 'height', '' ); 190 } 191 192 193 194 // Method for equalize heights for 195 equalizer.getMaxHeight = function( selector ) { 196 197 var max_height = 0; 198 var element = equalizer.parent.find( selector ); 199 200 element.each( function() { 201 var height = 0; 202 203 if ( ! $( this ).hasClass( 'cycle-sentinel' ) ) { 204 height = $( this ).outerHeight(); 205 } 206 207 if ( height > max_height ) { 208 max_height = height; 209 } 210 }); 211 212 return max_height; 213 } 214 215 216 217 // Method to unset all heights. 218 equalizer.unsetHeights = function() { 219 220 // Go through all priorities. 221 for ( var priority in equalizer.priorities ) { 222 var element_settings = equalizer.priorities[ priority ]; 223 equalizer.parent.find( element_settings.selector ).css( 'height', 'auto' ); 224 } 225 } 226 227 228 229 // Returns boolean if we are in builder mode. 230 equalizer.inEdit = function() { 231 if ( $( 'body' ).hasClass( 'fl-builder-edit' ) ) { 232 return true; 233 } 234 return false; 235 } 236 237 equalizer.construct(); 238 } 239 240 241 242 $( document ).ready( function() { 243 new CMWP_Mega_Teaser_Equalizer({ 244 parent: '.equalize-section', 245 priorities: { 246 10: { 247 selector: '.flex_column > .av_textblock_section', 248 status: true, 249 breakpoints: { 250 min: 768, 251 max: 1920 252 } 253 } 254 } 255 }); 256 }); 257 258})( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.