1function ampromo_init() 2{ 3 var itemsNode = $('ampromo-items'); 4 5 if (!itemsNode) 6 return; 7 8 $$('#ampromo-items form').each(function (form) { 9 var validation = new Validation(form); 10 form.validation = validation; 11 12 var button = form.down('.button.add'); 13 if (button) { 14 button.observe('click', function () { 15 if (validation.validate()) { 16 $$('#ampromo-items button').each(function(element){ 17 element.setAttribute('disabled', 'disabled'); 18 }); 19 this.up('form').submit(); 20 } 21 }); 22 } 23 24 form.select('.mark input[type=radio]').each(function (radio) { 25 radio.observe('change', function () { 26 var rule = this.up('[data-role="rule"]'); 27 rule.select('.mark input[type=radio]').each(function (radioToUncheck) { 28 radioToUncheck.checked = false; 29 }); 30 31 rule.select('[data-role="item"]').each(function (item) { 32 item.removeClassName('checked'); 33 }); 34 35 this.checked = true; 36 }); 37 }); 38 39 form.select('.mark input').each(function (input) { 40 input.observe('change', function () { 41 this.up('[data-role="item"]').toggleClassName('checked', this.checked); 42 }); 43 }); 44 }); 45 46 $$('[data-role="rule"] [data-role="ampromo-rule-header"]').each(function (header) { 47 header.observe('click', function () { 48 this.up('[data-role="rule"]').toggleClassName('collapsed'); 49 }); 50 }); 51 52 $$('.bundle-option-select option,' + 53 '.product-custom-option option').each(function(element){ 54 element.text = element.text.replace(/\s+\+.+$/, ''); 55 }); 56 57 if ($$('.bundle-option-select').length > 0) { 58 if (!('bundle' in window)) { 59 Object.extend(Product.Bundle.prototype, { 60 initialize: function(){}, 61 changeSelection: function(){}, 62 reloadPrice: function(){} 63 }); 64 window.bundle = new Product.Bundle({defaultValues: false}); 65 } 66 } 67 68 69 var overlay = $('ampromo-overlay'); 70 71 if (overlay) { 72 var close = overlay.down('.close'); 73 if (close) { 74 close.observe('click', function () { 75 $('ampromo-overlay').fade(); 76 }); 77 } 78 79 overlay.observe('click', function(event){ 80 if (event.target.id == 'ampromo-overlay') 81 $('ampromo-overlay').fade(); 82 }); 83 84 if (itemsNode.hasClassName('amcarousel')) 85 { 86 window.ampromo_carousel = new Carousel( 87 'ampromo-carousel-wrapper', 88 $$('#ampromo-carousel-content .ampromo-slide'), 89 $$('.ampromo-carousel-control'), { 90 visibleSlides: 3, 91 controlClassName: 'ampromo-carousel-control' 92 } 93 ); 94 95 ampromo_update_width(); 96 Event.observe(window, 'resize', ampromo_update_width); 97 } 98 99 var addAll = overlay.down('[data-role="add-all"]'); 100 101 if (addAll) { 102 addAll.observe('click', ampromo_send_all); 103 } 104 } 105} 106 107function ampromo_send_all() { 108 var data = []; 109 110 var validationPassed = true; 111 112 $$('#ampromo-items form').each(function (form) { 113 var formData = form.serialize(true); 114 if (formData.checked) { 115 if (validationPassed &= form.validation.validate()) { 116 data.push(formData); 117 } 118 } 119 }); 120 121 if (validationPassed) { 122 if (data.length > 0) { 123 $$('#ampromo-overlay [data-role="add-all"]').each(function (button) { 124 button.setAttribute('disabled', 'disabled'); 125 }); 126 127 var form = $('ampromo_metaform'); 128 form.down('[name=data]').value = JSON.stringify(data); 129 form.submit(); 130 } else { 131 alert('Please select any item'); 132 } 133 } 134} 135 136function ampromo_update_width() 137{ 138 var visibleSlides = $$('body')[0].clientWidth <= 820 ? 1 : 3; 139 140 window.ampromo_carousel.options.visibleSlides = visibleSlides; 141} 142 143 144/** 145 * Used to fix issues related to ajax reloads 146 */ 147 148function ampromo_check_initialization(e) 149{ 150 e.stop(); 151 var addBlock = $('ampromo-items-add'); 152 if (addBlock.readAttribute('data-initialized') === null) 153 { 154 addBlock.down('a').observe('click', ampromo_popup); 155 ampromo_init(); 156 ampromo_popup(); 157 addBlock.setAttribute('data-initialized', '1'); 158 } 159} 160 161function ampromo_popup() 162{
163 var overlay = $('ampromo-overlay'); 164 165 if (overlay.visible()) 166 return; 167 168 var items = $('ampromo-items'); 169 overlay.show(); 170 centerVertically(items); 171 overlay.hide(); 172 173 overlay.appear(); 174 175 if (items.getStyle('position') == 'static' && $('amscheckout-main')) 176 window.scroll(items.offsetLeft, items.offsetTop); 177} 178 179function centerVertically(element) 180{ 181 var vpHeight = $(document).viewport.getHeight(); 182 var height = element.clientHeight; 183 184 var avTop = (vpHeight / 2) - (height / 2); 185 186 if (avTop <= 10) 187 avTop = 10; 188 189 element.style.top = avTop+ 'px'; 190} 191 192function am_get_cookie(cname) { 193 var name = cname + "="; 194 var ca = document.cookie.split(';'); 195 for (var i = 0; i < ca.length; i++) { 196 var c = ca[i]; 197 while (c.charAt(0) == ' ') c = c.substring(1); 198 if (c.indexOf(name) == 0) return c.substring(name.length, c.length); 199 } 200 return ""; 201} 202 203document.observe('dom:loaded', function(){ 204 if (+am_get_cookie('am_promo_notification')) { 205 $$('.ampromo-notification').each(function (e) { 206 e.show(); 207 }) 208 } 209}); 210 211function ampromo_tooltip_show(evt){ 212 var img = Event.findElement(evt, 'img'); 213 var txt = img.alt; 214 215 var data = $(img.id + '-data'); 216 var tooltip = $(img.id + '-tooltip'); 217 218 if (!tooltip && data) { 219 tooltip = document.createElement('div'); 220 tooltip.className = 'ampromo-tooltip'; 221 tooltip.id = img.id + '-tooltip'; 222 tooltip.innerHTML = data.innerHTML; 223 224 document.body.appendChild(tooltip); 225 } 226 227 var offset = Element.cumulativeOffset(img); 228 tooltip.style.top = (offset[1] + img.getHeight() + 5) + 'px'; 229 tooltip.style.left = (offset[0] ) + 'px'; 230 tooltip.show(); 231} 232 233function ampromo_tooltip_hide(evt){ 234 var img = Event.findElement(evt, 'img'); 235 var tooltip = $(img.id + '-tooltip'); 236 if (tooltip) { 237 tooltip.remove(); 238 } 239}
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.