PageSourceSearch

https://www.bespokeboxesco.co.uk/js/magiccart/magicproduct.js

js bespokeboxesco.co.uk collected 2026-10-08 22:42:05 UTC 7,510 bytes, 205 lines download raw bytes

1/**
2 * Magiccart 
3 * @category 	Magiccart 
4 * @copyright 	Copyright (c) 2014 Magiccart (http://www.magiccart.net/) 
5 * @license 	http://www.magiccart.net/license-agreement.html
6 * @Author: DOng NGuyen<[email protected]>
7 * @@Create Date: 2014-04-25 13:16:48
8 * @@Modify Date: 2015-12-09 15:05:00
9 * @@Function:
10 */
11
12(function ($) {
13	"use strict";
14    $.fn.magicproduct = function (options) {
15        var defaults = {
16            //selector : '.magicproduct', // Selector product grid
17            tabs 	 : '.magictabs',
18            loading  : '.ajax_loading',
19            product  : '.content-products',
20            margin 	 : 30, // Margin product
21        };
22        var options = $.extend(defaults, options);
23        return this.each(function () {
24            //var selector 	= options.selector;
25            var tabs 	 	= options.tabs;
26            var loading 	= options.loading;
27            var product 	= options.product;
28            var margin 		= options.margin;
29			var $content 	= $(this);
30			var $tabs 		= $(tabs, $content);
31			var $infotabs 	= $tabs.data('ajax')
32			var $itemtabs 	= $('.item',$tabs);
33			// var $toggleTab  = $('.toggle-tab.mobile', $content);
34			var $loading 	= $(loading, $content);
35			// $toggleTab.click(function(){
36			// 	$tabs.parent().toggleClass('visible');
37			// });
38			magicProduct();
39			$itemtabs.click(function() {
40				var $this 	= $(this);
41				var type  	= $this.data('type');
42				var info 	= $infotabs;
43				//var info 	= $infotabs.push(type:type);
44				var $class 	= '.mc-'+type;
45				var $product = $(product, $content);
46				var $cnt_type = $($class, $product);
47
48				if(type != "random" && $this.hasClass('active')) return;
49				$itemtabs.removeClass('active');
50				$this.addClass('active');
51				if(type != "random" && $this.hasClass('loaded')){
52					resetAnimate($cnt_type);
53					$product.children().hide();  // not fadeOut()
54					$($class, $product).fadeIn(); // not show()
55					setAnimate($cnt_type); //require for Animate
56					magicProduct(); // call again
57				} else {
58					if(type == undefined) return;
59					$loading.show();
60					$.ajax({
61						type: 'post',
62						data: { type: type, info: info },
63						url : $loading.data('url'),
64						success:function(data){
65							$loading.hide();
66							$(product, $content).children().hide();
67							if(type=='random') $($class, $(product, $content)).remove();
68							$(product, $content).append(data);
69							$itemtabs.each(function(){
70								if($(this).data('type') == type) $(this).addClass('loaded');
71							});
72							magicProduct();
73							$product.magiccart({url: getMagicUrl('magicshop/ajax')});  // callback ajaxcart
74							$product.quickview({
75								// itemClass : '.products-grid li.item', //selector for each items in catalog product list,use to insert quickview image
76								itemClass : '.products-grid .item', //selector for each items in catalog product list,use to insert quickview image
77								aClass : 'a.product-image', //selector for each a tag in product items,give us href for one product
78								imgClass: '.product-image img' //class for quickview href product-collateral
79							});	
80						}
81					});
82				}
83			});
84
85			function magicProduct(){
86				var $product = $(product, $content);
87				var $slide  = $product.data('slider');
88				if($slide) getSlider(); else gridProduct();
89			}
90
91			// slide Product
92			function getSlider(){
93				$itemtabs.each(function() {
94					var $this = $(this);
95					if($this.hasClass('active')){
96						var type = $this.data('type');
97						var $class = '.mc-'+type;
98						var $product = $(product, $content);
99						var $content_active = $($class, $product);
100						var $options  = $product.data('slider');
101						var slide = $('.flexisel-content', $content_active);
102						var bxSliderInit = $content_active.find('.bx-wrapper');
103						if (bxSliderInit.length){
104							slide.unwrap().unwrap();
105							var bxControl = $content_active.find('.bx-controls');
106							if(bxControl.length) bxControl.remove();
107						} 
108						slide.bxSlider( $options );
109					}
110				});
111			}
112
113			// Grid Product
114			function gridProduct(){
115				var $window  = $(window).width();
116				var $tabs 		= $(tabs, $content);
117				var $itemtabs 	= $('.item.active',$tabs);
118				var $type 	 = '.mc-' + $itemtabs.data('type');
119				var $product = $(product, $content);
120				var $pdt 	 = $($type, $product);
121				var $options = $product.data('options');
122				var margin 	 = $product.data('margin');
123
124				setReponsive($window);
125				$(window).resize(function(){
126					var $window = $(window).width();
127					setReponsive($window);
128			 	})
129
130				function setReponsive($window){
131					var $items 	 = $('.item', $pdt);
132					var $width 	 = $content.find('.content-products').width();
133					var $widthInfo 	 = $content.find('.content-products .trademark-info:visible').outerWidth();
134					if($widthInfo && $widthInfo < $width) $width -= $widthInfo;
135					var obj = $options;
136					var contentWidth = $window;
137					var itemsVisible = 1;
138					var responsiveItemsObjects = [];
139					var responsiveChangePointObjects = [];
140					var largestCustom = 0;
141					for(var i in obj) {
142						responsiveItemsObjects.push({visibleItems:obj[i]});
143						responsiveChangePointObjects.push({changePoint:i});
144						if(i > largestCustom){
145							itemsVisible = obj[i];
146							largestCustom = i;
147						} 
148					}
149                    for(var i in responsiveItemsObjects) {
150                        
151                        if(contentWidth >= largestCustom) { // set to default if width greater than largest custom responsiveBreakpoint 
152                            break;
153                        }else { // determine custom responsiveBreakpoint to use
154                            if(contentWidth <= responsiveChangePointObjects[i].changePoint) {
155                                itemsVisible = responsiveItemsObjects[i].visibleItems;
156                                break;
157                            }
158                            else
159                                continue;
160                        }
161                    }
162					var n = parseInt(itemsVisible);
163					calculator($items, n, $width, margin); // break jQuery.each()
164
165				}		
166
167		 		function calculator($items, n, $width, margin){	
168					var temp = ($width- margin*(n-1))/n;
169					var width = (temp*n + Math.floor(temp))/(n + 1); // approximately down
170					$items.each(function(idx) {
171						$(this).width(width);
172						if(idx % n ==0) $(this).css({"margin-left": "0", "clear": "both"});
173						else $(this).css({"margin-left": margin, "clear": ""});
174					});	
175			 	}
176			}
177
178			// Effect
179			function resetAnimate(cnt){
180				var parent = cnt.parent();
181				$('.products-grid', parent).removeClass("play");
182				$('.products-grid .item', parent).removeAttr('style');
183			}
184
185			function setAnimate(cnt, time){
186				var animate = cnt;
187				var  time = time || 300; // if(typeof time == 'undefined') {time =300}
188				var $_items = $('.item-animate', animate);
189				$_items.each(function(i){
190					$(this).attr("style", "-webkit-animation-delay:" + i * time + "ms;"
191						                + "-moz-animation-delay:" + i * time + "ms;"
192						                + "-o-animation-delay:" + i * time + "ms;"
193						                + "animation-delay:" + i * time + "ms;");
194					if (i == $_items.size() -1){
195						$('.products-grid', animate).addClass("play");  // require for Animate
196					}
197				});
198			}
199
200        });
201
202    };
203
204})(jQuery);
205

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.