PageRenderTime 25ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/themes/ap_food/js/modules/leocustomajax/leocustomajax.js

https://gitlab.com/elasa/shop2.elasa.ir
JavaScript | 253 lines | 222 code | 20 blank | 11 comment | 50 complexity | b7f35a545644eb30876152a5943c9bfd MD5 | raw file
  1. (function($) {
  2. $.LeoCustomAjax = function() {
  3. this.leoData = 'leoajax=1';
  4. };
  5. $.LeoCustomAjax.prototype = {
  6. processAjax: function() {
  7. var myElement = this;
  8. if (leoOption.productNumber && $("#categories_block_left .leo-qty").length) myElement.getCategoryList();
  9. else if($("#categories_block_left .leo-qty").length) $("#categories_block_left .leo-qty").remove();
  10. if (leoOption.productInfo && $(".leo-more-info").length) myElement.getProductListInfo();
  11. else if($(".leo-more-info").length) $(".leo-more-info").remove();
  12. if (leoOption.productTran && $(".product-additional").length) myElement.getProductListTran();
  13. else if($(".product-additional").length) $(".product-additional").remove();
  14. if (leoOption.productCdown && $(".leo-more-cdown").length) myElement.getProductCdownInfo();
  15. else if($(".leo-more-cdown").length) $(".leo-more-cdown").remove();
  16. if (leoOption.productCdown && $(".leo-more-color").length) myElement.getProductColorInfo();
  17. else if($(".leo-more-color").length) $(".leo-more-color").remove();
  18. if(myElement.leoData != "leoajax=1"){
  19. $.ajax({
  20. type: 'POST',
  21. headers: {"cache-control": "no-cache"},
  22. url: baseDir + 'modules/leocustomajax/leoajax.php' + '?rand=' + new Date().getTime(),
  23. async: true,
  24. cache: false,
  25. dataType: "json",
  26. data: myElement.leoData,
  27. success: function(jsonData) {
  28. if (jsonData) {
  29. if (jsonData.cat) {
  30. for (i = 0; i < jsonData.cat.length; i++) {
  31. $("#leo-cat-" + jsonData.cat[i].id_category).html(jsonData.cat[i].total);
  32. $("#leo-cat-" + jsonData.cat[i].id_category).show();
  33. }
  34. }
  35. if (jsonData.pro_info) {
  36. var listProduct = new Array();
  37. for (i = 0; i < jsonData.pro_info.length; i++) {
  38. listProduct[jsonData.pro_info[i].id] = jsonData.pro_info[i].content;
  39. }
  40. $(".leo-more-info").each(function() {
  41. $(this).html(listProduct[$(this).data("idproduct")]);
  42. });
  43. addEffectProducts();
  44. }
  45. if (jsonData.pro_cdown) {
  46. var listProduct = new Array();
  47. for (i = 0; i < jsonData.pro_cdown.length; i++) {
  48. listProduct[jsonData.pro_cdown[i].id] = jsonData.pro_cdown[i].content;
  49. }
  50. $(".leo-more-cdown").each(function() {
  51. $(this).html(listProduct[$(this).data("idproduct")]);
  52. });
  53. }
  54. if (jsonData.pro_color) {
  55. var listProduct = new Array();
  56. for (i = 0; i < jsonData.pro_color.length; i++) {
  57. listProduct[jsonData.pro_color[i].id] = jsonData.pro_color[i].content;
  58. }
  59. $(".leo-more-color").each(function() {
  60. $(this).html(listProduct[$(this).data("idproduct")]);
  61. });
  62. }
  63. if (jsonData.pro_add) {
  64. var listProductImg = new Array();
  65. for (i = 0; i < jsonData.pro_add.length; i++) {
  66. listProductImg[jsonData.pro_add[i].id] = jsonData.pro_add[i].content;
  67. }
  68. $(".product-additional").each(function() {
  69. if (listProductImg[$(this).data("idproduct")]){
  70. var str_image = listProductImg[$(this).data("idproduct")];
  71. var src_image = str_image.replace('home_default', 'food_home_default');
  72. $(this).html('<img class="img-responsive" title="" alt="" src="' + src_image + '"/>');
  73. }
  74. });
  75. //addEffOneImg();
  76. }
  77. }
  78. },
  79. error: function() {
  80. }
  81. });
  82. }
  83. },
  84. getCategoryList: function() {
  85. //get category id
  86. var leoCatList = "";
  87. $("#categories_block_left .leo-qty").each(function() {
  88. if (leoCatList)
  89. leoCatList += "," + $(this).attr("id");
  90. else
  91. leoCatList = $(this).attr("id");
  92. });
  93. if (leoCatList) {
  94. leoCatList = leoCatList.replace(/leo-cat-/g, "");
  95. this.leoData += '&cat_list=' + leoCatList;
  96. }
  97. return false;
  98. },
  99. getProductListInfo: function() {
  100. var leoProInfo = "";
  101. $(".leo-more-info").each(function() {
  102. if (!leoProInfo)
  103. leoProInfo += $(this).data("idproduct");
  104. else
  105. leoProInfo += "," + $(this).data("idproduct");
  106. });
  107. if (leoProInfo) {
  108. this.leoData += '&pro_info=' + leoProInfo;
  109. }
  110. return false;
  111. },
  112. getProductCdownInfo: function() {
  113. var leoProCdown = "";
  114. $(".leo-more-cdown").each(function() {
  115. if (!leoProCdown)
  116. leoProCdown += $(this).data("idproduct");
  117. else
  118. leoProCdown += "," + $(this).data("idproduct");
  119. });
  120. if (leoProCdown) {
  121. this.leoData += '&pro_cdown=' + leoProCdown;
  122. }
  123. return false;
  124. },
  125. getProductColorInfo: function() {
  126. var leoProColor = "";
  127. $(".leo-more-color").each(function() {
  128. if (!leoProColor)
  129. leoProColor += $(this).data("idproduct");
  130. else
  131. leoProColor += "," + $(this).data("idproduct");
  132. });
  133. if (leoProColor) {
  134. this.leoData += '&pro_color=' + leoProColor;
  135. }
  136. return false;
  137. },
  138. getProductListTran: function() {
  139. //tranditional image
  140. var leoAdditional = "";
  141. $(".product-additional").each(function() {
  142. if (!leoAdditional)
  143. leoAdditional += $(this).data("idproduct");
  144. else
  145. leoAdditional += "," + $(this).data("idproduct");
  146. });
  147. if (leoAdditional) {
  148. this.leoData += '&pro_add=' + leoAdditional;
  149. }
  150. return false;
  151. }
  152. };
  153. }(jQuery));
  154. function addJSProduct(currentProduct) {
  155. // if (typeof serialScroll == 'function') {
  156. $('.thumbs_list_' + currentProduct).serialScroll({
  157. items: 'li:visible',
  158. prev: '.view_scroll_left_' + currentProduct,
  159. next: '.view_scroll_right_' + currentProduct,
  160. axis: 'y',
  161. offset: 0,
  162. start: 0,
  163. stop: true,
  164. duration: 700,
  165. step: 1,
  166. lazy: true,
  167. lock: false,
  168. force: false,
  169. cycle: false
  170. });
  171. $('.thumbs_list_' + currentProduct).trigger('goto', 1);// SerialScroll Bug on goto 0 ?
  172. $('.thumbs_list_' + currentProduct).trigger('goto', 0);
  173. // }
  174. }
  175. function addEffectProducts(){
  176. if(leoOption != 'undefined' && leoOption.productInfo){
  177. $(".leo-more-info").each(function() {
  178. addJSProduct($(this).data("idproduct"));
  179. });
  180. addEffectProduct();
  181. }
  182. }
  183. function addEffectProduct() {
  184. var speed = 800;
  185. var effect = "easeInOutQuad";
  186. //$(".products_block .carousel-inner .ajax_block_product:first-child").mouseenter(function() {
  187. //$(".products_block .carousel-inner").css("overflow", "inherit");
  188. //});
  189. //$(".carousel-inner").mouseleave(function() {
  190. //$(".carousel-inner").css("overflow", "hidden");
  191. //});
  192. $(".leo-more-info").each(function() {
  193. var leo_preview = this;
  194. $(leo_preview).find(".leo-hover-image").each(function() {
  195. $(this).mouseover(function() {
  196. var big_image = $(this).attr("rel");
  197. imgElement = $(leo_preview).parent().find(".product_img_link img").first();
  198. if (!imgElement.length) {
  199. imgElement = $(leo_preview).parent().find(".product_image img").first();
  200. }
  201. if (imgElement.length) {
  202. $(imgElement).stop().animate({opacity: 0}, {duration: speed, easing: effect});
  203. $(imgElement).first().attr("src", big_image);
  204. $(imgElement).first().attr("data-rel", big_image);
  205. $(imgElement).stop().animate({opacity: 1}, {duration: speed, easing: effect});
  206. }
  207. });
  208. });
  209. $('.thickbox-ajax-'+$(this).data("idproduct")).fancybox({
  210. 'hideOnContentClick': true,
  211. 'transitionIn' : 'elastic',
  212. 'transitionOut' : 'elastic'
  213. });
  214. });
  215. }
  216. function addEffOneImg() {
  217. var speed = 800;
  218. var effect = "easeInOutQuad";
  219. $(".product-additional").each(function() {
  220. if ($(this).find("img").length) {
  221. var leo_hover_image = $(this).parent().find("img").first();
  222. var leo_preview = $(this);
  223. $(this).parent().mouseenter(function() {
  224. $(this).find("img").first().stop().animate({opacity: 0}, {duration: speed, easing: effect});
  225. $(leo_preview).stop().animate({opacity: 1}, {duration: speed, easing: effect});
  226. });
  227. $(this).parent().mouseleave(function() {
  228. $(this).find("img").first().stop().animate({opacity: 1}, {duration: speed, easing: effect});
  229. $(leo_preview).stop().animate({opacity: 0}, {duration: speed, easing: effect});
  230. });
  231. }
  232. });
  233. }