1/* From the group, find the tallest .banner_frame, 2 * and return its height (in px, but without the 'px') 3*/ 4var cb_get_tallest_frame = function (group) 5{ 6 var tallest = 0; 7 jQuery(group).find('.banner_frame').each(function () { 8 if ( jQuery(this).height() > tallest ) { 9 tallest = jQuery(this).height(); 10 } 11 }); 12 return tallest; 13}; 14 15var cb_determine_height_for_banners = function(img, sentinel) 16{ 17 // if the sentinel exists, use its height 18 // otherwise use the image's height + width attrs 19 var img_height; 20 if ( sentinel.length > 0 ) { 21 img_height = sentinel.height(); 22 } else { 23 img_height = img.attr('height'); 24 } 25 return img_height; 26}; 27 28var cb_determine_width_for_banners = function(img, sentinel) 29{ 30 // if the sentinel exists, use its height 31 // otherwise use the image's height + width attrs 32 var img_width; 33 if ( sentinel.length > 0 ) { 34 img_width = sentinel.width(); 35 } else { 36 img_width = img.attr('width'); 37 } 38 return img_width; 39}; 40 41// apply a full_height or full_width class (whichever is the shorter) 42var cb_set_banner_class_for_fullsize = function(img, sentinel) 43{ 44 var my_frame = jQuery(img).parents('.banner_frame:first'); 45 var img = jQuery(img); 46 var uniform_height = cb_determine_height_for_banners(img, sentinel); 47 var uniform_width = cb_determine_width_for_banners(img, sentinel); 48 if ( img.height() < 1 || img.width() < 1 ) { 49 return; 50 } 51 52 ratio_h = ( my_frame.height() / img.height() ); 53 ratio_w = ( my_frame.width() / img.width() ); 54 55 if (ratio_w < ratio_h ) { 56 img.removeClass('custom_banners_slide_full_width'); 57 img.addClass('custom_banners_slide_full_height'); 58 img.height( uniform_height ); 59 } 60 else { 61 img.removeClass('custom_banners_slide_full_height'); 62 img.addClass('custom_banners_slide_full_width'); 63 img.width( uniform_width ); 64 } 65}; 66 67var cb_fix_slideshows_after_init = function() 68{ 69 jQuery('.custom-banners-cycle-slideshow').each(function () { 70 if ( jQuery(this).find('.banner_frame').length == 0 ) { 71 return; 72 } 73 if ( jQuery(this).hasClass('cb_frame_fixed') ) { 74 return; 75 } 76 jQuery(this).addClass('cb_frame_fixed'); 77 //jQuery(this).gp_cycle('reinit'); 78 setTimeout(function () { 79 cb_fix_frame_dimensions(); 80 }, 100); 81 }); 82}; 83 84/* Sets CSS properties and classes needed to make an individual banner play well 85 * with cycle2 slideshows and its transitions. Should be called for each banner. 86 * 87 * @param img The banner image to setup 88 * @param sentinel The sentinel object for the slideshow (can be an empty group) 89 */ 90var cb_setup_slideshow_banner = function(img, sentinel) 91{ 92 // fix a couple of CSS properties to make the transitions look right 93 // (esp. scrollHoriz). Else the slides sort of stretch out as resize 94 var banner_wrapper = img.parents('.banner_wrapper:first'); 95 cb_fix_frame_dimensions(); 96 banner_wrapper.css('right', 'auto'); 97 98 // setup a callback to apply some needed classes to the banner images 99 // if the image is loaded, then we can run the callback now. 100 // else, we'll run the callback when the image finishes loading 101 if (img.complete) { 102 cb_set_banner_class_for_fullsize.call(img, sentinel); 103 } else { 104 jQuery(window).on('load', function () { 105 cb_set_banner_class_for_fullsize(img, sentinel); 106 }); 107 } 108} 109 110/* Upon initialization and before each slide is shown, update the image 111 * sizes and CSS classes to make the transitions run smoothly. (width:100% 112 * causes all kinds of problems with transitions.) 113 */ 114var cb_update_slideshow_image_sizes = function(event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag){ 115 var slideshow = jQuery(this); 116 var sentinel = jQuery(this).find('.cycle-sentinel'); 117 118 // find the height of the tallest frame, and set all images to this height 119 var tallest = cb_get_tallest_frame(this); 120 if (tallest == 0) { 121 return; 122 } 123 slideshow.find('.banner_frame').height(tallest); 124 125 slideshow.find('.banner_frame img').each( function () { 126 cb_setup_slideshow_banner( jQuery(this), sentinel ); 127 return true; 128 } ); 129 130 slideshow.on('cycle-prev, cycle-next', function () { 131 jQuery(this).find('.banner_frame img').each( function () { 132 cb_set_banner_class_for_fullsize(jQuery(this), sentinel); 133 cb_fix_slideshows_after_init(); 134 return true; 135 }); 136 }); 137 138 cb_fix_slideshows_after_init(); 139 140}; 141 142/* Sets up a series of callbacks to update various image sizes as needed */ 143var cb_setup_banner_size_callbacks = function () 144{ 145 jQuery('.custom-banners-cycle-slideshow').each(function () { 146 jQuery.call(this, cb_update_slideshow_image_sizes); 147 jQuery(this).on('cycle-initialized', cb_update_slideshow_image_sizes); 148 jQuery(this).on('cycle-before', cb_update_slideshow_image_sizes); 149 }); 150}; 151 152var cb_get_banner_padding = function (banner) { 153 return { 154 'top' : parseInt( banner.css('padding-top'), 10 ), 155 'bottom' : parseInt( banner.css('padding-bottom'), 10 ), 156 'left' : parseInt( banner.css('padding-left'), 10 ), 157 'right' : parseInt( banner.css('padding-right'), 10 ), 158 }; 159}; 160 161var cb_get_banner_margin = function (banner) { 162 return { 163 'top' : parseInt( banner.css('margin-top'), 10 ), 164 'bottom' : parseInt( banner.css('margin-bottom'), 10 ), 165 'left' : parseInt( banner.css('margin-left'), 10 ), 166 'right' : parseInt( banner.css('margin-right'), 10 ), 167 }; 168}; 169 170var cb_get_banner_border = function (banner) { 171 return { 172 'top' : parseInt( banner.css('border-top'), 10 ), 173 'bottom' : parseInt( banner.css('border-bottom'), 10 ), 174 'left' : parseInt( banner.css('border-left'), 10 ), 175 'right' : parseInt( banner.css('border-right'), 10 ), 176 }; 177}; 178 179 180/* In each slideshow, explicitly set the height& width of the .banner_frame's 181 * to the height of the sentinel div 182 */ 183var cb_fix_frame_dimensions = function () 184{ 185 jQuery('.custom-banners-cycle-slideshow').each(function () 186 { 187 var sentinel = jQuery(this).find('.cycle-sentinel'); 188 var first_banner = jQuery(this).find('.banner:first'); 189 var first_banner_img = jQuery(this).find('.banner:first img'); 190 var padding = cb_get_banner_padding(first_banner); 191 var margin = cb_get_banner_margin(first_banner); 192 var total_w_offset = (padding.left + padding.right + margin.left + margin.right); 193 var total_h_offset = (padding.top + padding.bottom + margin.top + margin.bottom); 194 195 var w = jQuery(this).attr('data-w');
196 var h = jQuery(this).attr('data-h'); 197 198 if ( typeof( w ) == 'undefined' || typeof( h ) == 'undefined') { 199 h = first_banner_img.attr('height') - total_h_offset; 200 w = jQuery(this).width() - total_w_offset; 201 jQuery(this).attr('data-w', w); 202 jQuery(this).attr('data-h', h); 203 } 204 if ( w > 0 && h > 0 ) { 205 jQuery(this).find('.banner_frame') 206 .height(h) 207 .width(w); 208 } 209 }); 210} 211 212/* Updates some CSS properties and sets the dimensions of several 213 * banner elements esplicitly, so that our banners play nicely with 214 * Cycle2 and its transitions. 215 */ 216var cb_fix_slideshow_banner_css = function () { 217 // the ordering of these functions is, sadly, important 218 cb_fix_frame_dimensions(); 219 cb_update_slideshow_image_sizes(); 220 cb_setup_banner_size_callbacks(); 221}; 222 223jQuery( function () { 224 setTimeout(cb_fix_slideshow_banner_css, 100); 225});
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.