https://www.dvs-media.eu/engine/Shopware/Plugins/Community/Fronten…/javascript/jquery.swag_bundle.js
1/** 2 * Shopware 4.0 3 * Copyright © 2012 shopware AG 4 * 5 * According to our dual licensing model, this program can be used either 6 * under the terms of the GNU Affero General Public License, version 3, 7 * or under a proprietary license. 8 * 9 * The texts of the GNU Affero General Public License with an additional 10 * permission and of our proprietary license can be found at and 11 * in the LICENSE file you have received along with this program. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Affero General Public License for more details. 17 * 18 * "Shopware" is a registered trademark of shopware AG. 19 * The licensing of the program under the AGPLv3 does not imply a 20 * trademark license. Therefore any rights, title and interest in 21 * our trademarks remain entirely with us. 22 * 23 * @category Shopware 24 * @package Article 25 * @subpackage Bundle 26 * @copyright Copyright (c) 2012, shopware AG (http://www.shopware.de) 27 * @version $Id$ 28 * @author shopware AG 29 */ 30 31(function($) { 32 $.checkBundleStock = function() { 33 $('div.bundle-container').each(function(index, bundle) { 34 var buyable = true; 35 var bundle = $(bundle); 36 var button = bundle.find('.add-bundle'); 37 38 var list = bundle.find('li'); 39 list.each(function(index, article) { 40 var article = $(article); 41 if (article.hasClass('notbuyable') && !article.hasClass('skip')) { 42 buyable = false; 43 } 44 }); 45 46 if (!buyable) { 47 button.hide(); 48 } else { 49 button.show(); 50 } 51 }); 52 }; 53})(jQuery); 54 55(function($) { 56 $.urlHandler = { 57 prepareRequestUrl: function(url) { 58 var prefix = this.getUrlPrefix(); 59 if (url.indexOf("http://") === 0 && prefix == "https://"){ 60 url = url.replace("http://", prefix); 61 } else if (url.indexOf("https://") === 0 && prefix == "http://"){ 62 url = url.replace("https://", prefix); 63 } 64 65 return url; 66 }, 67 68 getUrlPrefix: function() { 69 var currentUrl = window.location.href; 70 if (currentUrl.indexOf("http://") === 0) { 71 return "http://"; 72 } else if (currentUrl.indexOf("https://") === 0) { 73 return "https://"; 74 } 75 } 76 }; 77})(jQuery); 78 79;(function($) { 80 "use strict"; 81 $(document).ready(function() { 82 83 $.checkBundleStock(); 84 85 // Add event listener for the accept configuration button 86 $('.add-configuration').live('click', function(event) { 87 event.preventDefault(); 88 var me = $(this), 89 outerContainer = me.parent('.bundle-article-configuration'), 90 bundleId = me.parents('li.item').attr('data-bundle-id'), 91 bundleArticleId = outerContainer.find('.bundle-article-configuration-id').val(), 92 requestUrl = outerContainer.find('.request-url').val(), 93 params = { 94 'bundleArticleId': bundleArticleId, 95 'bundleId': bundleId 96 }, 97 mainBundleParams = { 98 'bundleArticleId': 0 99 }, 100 // Build params array for the main bundle 101 bundleContainer = me.parents(".bundle-container"), 102 mainBundle = bundleContainer.find("[data-bundle-article-id='0']"), 103 mainBundleContainer = mainBundle.find('.bundle-article-configuration'); 104 105 mainBundleContainer.find('select').each(function(index, item) { 106 var $item = $(item), 107 key = $item.attr('name'); 108 mainBundleParams[key] = $item.val(); 109 }); 110 111 // Build params for the selected bundle article 112 outerContainer.find('select').each(function(index, item){ 113 var $item = $(item); 114 var key = $item.attr('name'); 115 params[key] = $item.val(); 116 }); 117 118 requestUrl = $.urlHandler.prepareRequestUrl(requestUrl); 119 $.ajax({ 120 'url': requestUrl, 121 'data': params, 122 'dataType': 'html', 123 'type': 'POST', 124 success: function() { 125 reloadPageWithGroups(getGroupParams(mainBundleParams)); 126 } 127 }); 128 }); 129 130 /** 131 * Reloads the page with a POST request 132 * @param groups 133 */ 134 function reloadPageWithGroups(groups) { 135 var form = $('<form>', { 136 method: 'POST', 137 name: 'bundleConfiguratorForm' 138 }); 139 140 $.each(groups, function (group, value) { 141 form.append($('<input/>', { 142 type: 'hidden', 143 name: 'group[' + group + ']', 144 value: value 145 })); 146 }); 147 form.appendTo('body').submit(); 148 } 149 150 /** 151 * Extracts the param keys from a given iterable 152 * @param params 153 * @returns Object 154 */ 155 function getGroupParams(params) { 156 var groups = { }; 157 158 $.each(params, function (key, value) { 159 if (key.substring(0, 5) == 'group') { 160 groups[key.substring(6)] = value; 161 } 162 }); 163 164 return groups; 165 } 166 }); 167})(jQuery); 168 169 170;(function($) { 171 "use strict"; 172 $(document).ready(function() { 173 $('.bundle-container .checkbox').bind('click', function(event) { 174 var $this = $(this), 175 parent = $this.parents('li.item'); 176 177 var bundleContainer = parent.parents('.bundle-container'); 178 var percentage = bundleContainer.find('input[name=discount-percentage]').val(); 179 var discountType = bundleContainer.find('input[name=discount-type]').val(); 180 var checked = $this.is(':checked'); 181 var articles = bundleContainer.find('li.item'); 182 var selectedAmount = 0; 183 var totalAmount = 0; 184 var count = 0; 185 186 var visibleItems = new Array(); 187 var imagesToHide = new Array(); 188 189 articles.each(function(index, item) { 190 var article = $(item); 191 var articleCheckbox = article.find('input.checkbox'); 192 var articleIsChecked = (articleCheckbox.is(':checked') || index === 0); 193 var price = article.find('input[name=price]').val() * 1; 194 195 // Get the id of the bundleArticle and find the corresponding image with this 196 var id = article.find('input[name=bundleArticleId]').val(); 197 var image = bundleContainer.find('#bundleImage'+ id); 198 199 totalAmount += price; 200 if (articleIsChecked) { 201 // Show the image 202 image.fadeIn('slow'); 203 204 // Store visible items 205 visibleItems.push({ 206 article: article, 207 id: id, 208 image: image 209 }); 210 211 article.removeClass('skip'); 212 // Sum price 213 selectedAmount += price; 214 count++; 215 } else {
216 // Do not hide the images directly as the whole process might be 217 // canceled when no items are remaining 218 article.addClass('skip'); 219 imagesToHide.push(image); 220 } 221 }); 222 223 if (count <= 1) { 224 event.preventDefault(); 225 return; 226 } 227 228 var lastItem = visibleItems.pop(); 229 var nextToLastItem = visibleItems.pop(); 230 231 // Mark the last item as... last-item 232 if (lastItem) { 233 lastItem.image.addClass('last-item'); 234 } 235 236 // Mark the item that was the last item before, as not being the last item 237 if (nextToLastItem) { 238 nextToLastItem.image.removeClass('last-item'); 239 } 240 241 $.each(imagesToHide, function(index, image) { 242 image.fadeOut('slow'); 243 }); 244 245 246 percentage = percentage.replace(',', '.'); 247 248 var discount = 0; 249 var bundlePriceValue = bundleContainer.find('.bundle-price-value'); 250 var bundleDiscountValue = bundleContainer.find('.discount-value'); 251 var totalPriceValue = bundleContainer.find('.total-price-value'); 252 var currencyFormat = bundleContainer.find('.currency-helper').text(); 253 254 if (discountType === 'pro') { 255 discount = selectedAmount / 100 * percentage; 256 } else { 257 discount = bundleContainer.find('input[name=discount-value-usage]').val(); 258 } 259 var price = selectedAmount - discount; 260 261 price = formatValue(price, currencyFormat); 262 discount = formatValue(discount, currencyFormat); 263 selectedAmount = formatValue(selectedAmount, currencyFormat); 264 265 bundleDiscountValue.text(discount); 266 bundlePriceValue.text(price); 267 totalPriceValue.text(selectedAmount); 268 269 $.checkBundleStock(); 270 271 parent.find('.unchecked-item-wrapper').toggleClass('unchecked-item'); 272 }); 273 274 function formatValue(value, template) { 275 value = Math.round(value * 100) / 100; 276 value = value.toFixed(2); 277 278 if (-1 != template.search('0,00')) { 279 value = template.replace('0,00', value); 280 } else { 281 value = template.replace('0.00', value); 282 } 283 284 value = value.replace('.', ','); 285 return value; 286 } 287 }); 288})(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.