scripts_js_file.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. package template
  2. var VarScriptsJsFile = []byte(`(function(window, $) {
  3. var frontend = function(window, $) {
  4. var ShopProductsLightGalleryLastImage = '';
  5. // Private
  6. function ShopProductsInitLightGallery() {
  7. $('#product_thumbnails').lightGallery({
  8. pager: false,
  9. showThumbByDefault: false,
  10. toogleThumb: false,
  11. controls: false,
  12. download: false
  13. });
  14. $('#product_image img').css('cursor', 'pointer').click(function() {
  15. $($('#product_thumbnails a.thumbnail').get($(this).data('index'))).click();
  16. });
  17. $('#product_thumbnails a.thumbnail').each(function() {
  18. $(this).mouseover(function() {
  19. if($(this).data('hover') != ShopProductsLightGalleryLastImage) {
  20. ShopProductsLightGalleryLastImage = $(this).data('hover');
  21. $('#product_image img').attr('src', $(this).data('hover'));
  22. $('#product_image img').data('index', $(this).data('index'));
  23. }
  24. });
  25. });
  26. };
  27. function ShopBasketBlockObject(object) {
  28. if(object && !$(object).hasClass('click-blocked')) {
  29. $(object).addClass('click-blocked');
  30. }
  31. };
  32. function ShopBasketUnBlockObject(object) {
  33. if(object && $(object).hasClass('click-blocked')) {
  34. $(object).removeClass('click-blocked');
  35. }
  36. };
  37. function ShopBasketObjectIsNotBlocked(object) {
  38. if(!object) {
  39. return true;
  40. }
  41. return !$(object).hasClass('click-blocked');
  42. };
  43. function ShopBasketSetNavBtnProductsCount(value) {
  44. $('#basket-nav-btn .badge').html(value);
  45. $('#basket-mobile-btn').html(value);
  46. };
  47. function ShopBasketAjaxCommand(cmd, product_id, success, fail, always) {
  48. $.ajax({
  49. type: "GET",
  50. dataType: 'json',
  51. url: '/shop/basket/' + cmd + '/' + product_id + '/'
  52. }).done(function(data) {
  53. if(success) { success(data); }
  54. }).fail(function(xhr, status, error) {
  55. if(fail) { fail(xhr, status, error); }
  56. }).always(function() {
  57. if(always) { always(); }
  58. });
  59. };
  60. function ShopBasketAjaxGetInfo(success, fail, always) {
  61. $.ajax({
  62. type: "GET",
  63. dataType: 'json',
  64. url: '/shop/basket/info/'
  65. }).done(function(data) {
  66. if(success && data) { success(data); }
  67. }).fail(function(xhr, status, error) {
  68. if(fail) { fail(xhr, status, error); }
  69. }).always(function() {
  70. if(always) { always(); }
  71. });
  72. };
  73. function ShopBasketAjaxGetCount(success, fail, always) {
  74. ShopBasketAjaxGetInfo(function(data) {
  75. if(success && data && data.total_count != undefined) {
  76. success(data.total_count);
  77. }
  78. }, function(xhr, status, error) {
  79. if(fail) { fail(xhr, status, error); }
  80. }, function() {
  81. if(always) { always(); }
  82. });
  83. };
  84. function ShopBasketAjaxUpdateCount() {
  85. ShopBasketAjaxGetCount(function(count) {
  86. ShopBasketSetNavBtnProductsCount(count);
  87. });
  88. };
  89. function ShopBasketAjaxProductsHtml(success, fail, always) {
  90. ShopBasketAjaxGetInfo(function(data) {
  91. if(data) {
  92. if(data.total_count != undefined && data.total_count > 0) {
  93. var table = '';
  94. table += '<table class="table data-table table-striped table-bordered">';
  95. table += '<thead><tr><th class="thc-1">&nbsp;</th><th class="thc-2">' + ShopBasketTableProduct + '</th><th class="thc-3">' + ShopBasketTablePrice + '</th><th class="thc-4">' + ShopBasketTableQuantity + '</th><th class="thc-5">' + ShopBasketTableSum + '</th><th class="thc-6">&nbsp;</th></tr></thead>';
  96. table += '<tbody>';
  97. for(var i in data.products) {
  98. table += '<tr>';
  99. table += '<td class="thc-1 d-none d-md-table-cell"><img src="' + data.products[i].image + '" width="50" height="50" /></td>';
  100. table += '<td class="thc-2"><a href="' + data.products[i].link + '">' + data.products[i].name + '</a></td>';
  101. table += '<td class="thc-3">' + data.products[i].price + ' ' + data.currency.code + '</td>';
  102. table += '<td class="thc-4"><button type="button" class="btn btn-minus" onclick="frontend.ShopBasketProductMinus(this,' + data.products[i].id + ');"><span>-</span></button><input class="form-control" type="text" value="' + data.products[i].quantity + '" readonly><button type="button" class="btn btn-plus" onclick="frontend.ShopBasketProductPlus(this,' + data.products[i].id + ');"><span>+</span></button></td>';
  103. table += '<td class="thc-5">' + data.products[i].sum + ' ' + data.currency.code + '</td>';
  104. table += '<td class="thc-6"><a href="" onclick="frontend.ShopBasketProductRemove(this,' + data.products[i].id + ');return false;">&times;</a></td>';
  105. table += '</tr>';
  106. }
  107. table += '</tbody>';
  108. table += '</table>';
  109. table += '<div class="total"><span class="caption">' + ShopBasketTotal + '</span><span class="value">' + data.total_sum + ' ' + data.currency.code + '</span></div>';
  110. if(success) { success(table, data.total_count); }
  111. } else {
  112. if(success) { success(ShopBasketEmpty, 0); }
  113. }
  114. } else {
  115. window.location.reload(true);
  116. }
  117. }, function(xhr, status, error) {
  118. if(fail) { fail(xhr, status, error); }
  119. }, function() {
  120. if(always) { always(); }
  121. });
  122. };
  123. function ShopBasketEnableDisableOrderBtn(total) {
  124. $('#sys-modal-shop-basket button.btn-order').prop('disabled', total <= 0);
  125. };
  126. function Initialize() {
  127. // Check if jQuery was loaded
  128. if(typeof $ == 'function') {
  129. ShopProductsInitLightGallery();
  130. } else {
  131. console.log('Error: jQuery is not loaded!');
  132. }
  133. };
  134. // Initialize
  135. if(window.addEventListener) {
  136. // W3C standard
  137. window.addEventListener('load', Initialize, false);
  138. } else if(window.attachEvent) {
  139. // Microsoft
  140. window.attachEvent('onload', Initialize);
  141. };
  142. // Public
  143. return {
  144. ShopBasketBtnCollapse: function() {
  145. if(!$('.navbar-toggler').hasClass('collapsed')) {
  146. $('.navbar-toggler').click();
  147. }
  148. return true;
  149. },
  150. ShopBasketOpen: function(object) {
  151. if(ShopBasketObjectIsNotBlocked(object)) {
  152. ShopBasketBlockObject(object);
  153. var html = '<div class="modal fade" id="sys-modal-shop-basket" tabindex="-1" role="dialog" aria-labelledby="sysModalShopBasketLabel" aria-hidden="true"> \
  154. <div class="modal-dialog modal-dialog-centered" role="document"> \
  155. <div class="modal-content"> \
  156. <input type="hidden" name="action" value="index-user-update-profile"> \
  157. <div class="modal-header"> \
  158. <h5 class="modal-title" id="sysModalShopBasketLabel">' + ShopBasketName + '</h5> \
  159. <button type="button" class="close" data-dismiss="modal" aria-label="Close"> \
  160. <span aria-hidden="true">&times;</span> \
  161. </button> \
  162. </div> \
  163. <div class="modal-body text-left" style="position:relative;"> \
  164. <div class="blocker" style="position:absolute;left:0px;top:0px;width:100%;height:100%;background:#fff;opacity:0.5;display:none;"></div> \
  165. <div class="data"></div> \
  166. <div class="order-form mt-3" style="display:none;"> \
  167. <hr class="mb-4"> \
  168. <form class="data-form" action="/" method="post" autocomplete="off"> \
  169. <div class="hidden"><input type="hidden" name="action" value="shop-order"></div> \
  170. <div class="form-group"> \
  171. <div class="row"> \
  172. <div class="col-md-3"> \
  173. <label for="lbl_client_last_name">' + ShopOrderLabelLastName + '</label> \
  174. </div> \
  175. <div class="col-md-9"> \
  176. <input class="form-control" type="text" id="lbl_client_last_name" name="client_last_name" value="" minlength="1" maxlength="64" autocomplete="off" required> \
  177. </div> \
  178. </div> \
  179. </div> \
  180. <div class="form-group"> \
  181. <div class="row"> \
  182. <div class="col-md-3"> \
  183. <label for="lbl_client_first_name">' + ShopOrderLabelFirstName + '</label> \
  184. </div> \
  185. <div class="col-md-9"> \
  186. <input class="form-control" type="text" id="lbl_client_first_name" name="client_first_name" value="" minlength="1" maxlength="64" autocomplete="off" required> \
  187. </div> \
  188. </div> \
  189. </div> \
  190. <div class="form-group"> \
  191. <div class="row"> \
  192. <div class="col-md-3"> \
  193. <label for="lbl_client_second_name">' + ShopOrderLabelSecondName + '</label> \
  194. </div> \
  195. <div class="col-md-9"> \
  196. <input class="form-control" type="text" id="lbl_client_second_name" name="client_second_name" value="" minlength="1" maxlength="64" autocomplete="off" required> \
  197. </div> \
  198. </div> \
  199. </div> \
  200. <div class="form-group"> \
  201. <div class="row"> \
  202. <div class="col-md-3"> \
  203. <label for="lbl_client_phone">' + ShopOrderLabelMobilePhone + '</label> \
  204. </div> \
  205. <div class="col-md-9"> \
  206. <input class="form-control" type="text" id="lbl_client_phone" name="client_phone" value="" minlength="1" maxlength="20" autocomplete="off" required> \
  207. </div> \
  208. </div> \
  209. </div> \
  210. <div class="form-group"> \
  211. <div class="row"> \
  212. <div class="col-md-3"> \
  213. <label for="lbl_client_email">' + ShopOrderLabelEmailAddress + '</label> \
  214. </div> \
  215. <div class="col-md-9"> \
  216. <input class="form-control" type="text" id="lbl_client_email" name="client_email" value="" minlength="1" maxlength="64" autocomplete="off" required> \
  217. </div> \
  218. </div> \
  219. </div> \
  220. <div class="form-group"> \
  221. <div class="row"> \
  222. <div class="col-md-3"> \
  223. <label for="lbl_client_delivery_comment">' + ShopOrderLabelDelivery + '</label> \
  224. </div> \
  225. <div class="col-md-9"> \
  226. <input class="form-control" type="text" id="lbl_client_delivery_comment" name="client_delivery_comment" value="" minlength="1" maxlength="255" autocomplete="off"> \
  227. </div> \
  228. </div> \
  229. </div> \
  230. <div class="form-group"> \
  231. <div class="row"> \
  232. <div class="col-md-3"> \
  233. <label for="lbl_client_order_comment">' + ShopOrderLabelComment + '</label> \
  234. </div> \
  235. <div class="col-md-9"> \
  236. <textarea class="form-control" id="lbl_client_order_comment" name="client_order_comment" autocomplete="off"></textarea> \
  237. </div> \
  238. </div> \
  239. </div> \
  240. </form> \
  241. </div> \
  242. </div> \
  243. <div class="modal-footer"> \
  244. <button type="button" class="btn btn-close btn-secondary" data-dismiss="modal">' + ShopBasketBtnContinue + '</button> \
  245. <button type="button" class="btn btn-order btn-success" onclick="frontend.ShopBasketMakeOrder(this);return false;" disabled>' + ShopBasketBtnOrder + '</button> \
  246. </div> \
  247. </div> \
  248. </div> \
  249. </div>';
  250. $('#sys-modal-shop-basket-placeholder').html(html);
  251. // ---
  252. // var OrderForm = $('#sys-modal-shop-basket .modal-body .order-form form');
  253. // OrderForm.submit(function(e) {
  254. // if(OrderForm.hasClass('loading')) {
  255. // e.preventDefault();
  256. // return;
  257. // }
  258. // // Block send button
  259. // OrderForm.addClass('loading').addClass('alert-here');
  260. // var button = OrderForm.find('button[type=submit]');
  261. // button.addClass('progress-bar-striped')
  262. // .addClass('progress-bar-animated');
  263. // // Another button
  264. // if(button.attr('data-target') != '') {
  265. // $('#' + button.attr('data-target')).addClass('progress-bar-striped')
  266. // .addClass('progress-bar-animated');
  267. // }
  268. // // Clear form messages
  269. // form.find('.sys-messages').html('');
  270. // $.ajax({
  271. // type: "POST",
  272. // url: form.attr('action'),
  273. // data: form.serialize()
  274. // }).done(function(data) {
  275. // FormDataWasChanged = false;
  276. // if(IsDebugMode()) console.log('done', data);
  277. // AjaxDone(data)
  278. // }).fail(function(xhr, status, error) {
  279. // if(IsDebugMode()) console.log('fail', xhr, status, error);
  280. // AjaxFail(xhr.responseText, status, error);
  281. // }).always(function() {
  282. // // Add delay for one second
  283. // setTimeout(function() {
  284. // form.removeClass('loading').removeClass('alert-here');
  285. // button.removeClass('progress-bar-striped')
  286. // .removeClass('progress-bar-animated');
  287. // // Another button
  288. // if(button.attr('data-target') != '') {
  289. // $('#' + button.attr('data-target'))
  290. // .removeClass('progress-bar-striped')
  291. // .removeClass('progress-bar-animated');
  292. // }
  293. // }, 100);
  294. // });
  295. // // Prevent submit action
  296. // e.preventDefault();
  297. // });
  298. // ---
  299. $("#sys-modal-shop-basket").modal({
  300. backdrop: 'static',
  301. keyboard: true,
  302. show: false,
  303. });
  304. $('#sys-modal-shop-basket').on('hidden.bs.modal', function(e) {
  305. $('#sys-modal-shop-basket-placeholder').html('');
  306. $('#navbar-top').css('margin-right', $('#body').css('padding-right'));
  307. });
  308. ShopBasketAjaxProductsHtml(function(html, total) {
  309. $('#sys-modal-shop-basket .modal-body .data').html(html);
  310. ShopBasketEnableDisableOrderBtn(total);
  311. $("#sys-modal-shop-basket").modal('show');
  312. $('#navbar-top').css('margin-right', $('#body').css('padding-right'));
  313. }, function(xhr, status, error) {
  314. window.location.reload(true);
  315. });
  316. ShopBasketUnBlockObject(object);
  317. }
  318. return false;
  319. },
  320. ShopBasketProductAdd: function(object, product_id) {
  321. if(ShopBasketObjectIsNotBlocked(object)) {
  322. ShopBasketBlockObject(object);
  323. ShopBasketAjaxCommand('plus', product_id, function(data) {
  324. frontend.ShopBasketOpen();
  325. }, function(xhr, status, error) {
  326. window.location.reload(true);
  327. }, function() {
  328. ShopBasketAjaxUpdateCount();
  329. ShopBasketUnBlockObject(object);
  330. });
  331. }
  332. return false;
  333. },
  334. ShopBasketProductPlus: function(object, product_id) {
  335. if(ShopBasketObjectIsNotBlocked(object)) {
  336. ShopBasketBlockObject(object);
  337. $('#sys-modal-shop-basket .modal-body .blocker').css('display', 'block');
  338. ShopBasketAjaxCommand('plus', product_id, function(data) {
  339. ShopBasketAjaxProductsHtml(function(html, total) {
  340. $('#sys-modal-shop-basket .modal-body .data').html(html);
  341. ShopBasketEnableDisableOrderBtn(total);
  342. }, function(xhr, status, error) {
  343. window.location.reload(true);
  344. });
  345. }, function(xhr, status, error) {
  346. window.location.reload(true);
  347. }, function() {
  348. ShopBasketAjaxUpdateCount();
  349. ShopBasketUnBlockObject(object);
  350. $('#sys-modal-shop-basket .modal-body .blocker').css('display', 'none');
  351. });
  352. }
  353. return false;
  354. },
  355. ShopBasketProductMinus: function(object, product_id) {
  356. if(ShopBasketObjectIsNotBlocked(object)) {
  357. ShopBasketBlockObject(object);
  358. $('#sys-modal-shop-basket .modal-body .blocker').css('display', 'block');
  359. ShopBasketAjaxCommand('minus', product_id, function(data) {
  360. ShopBasketAjaxProductsHtml(function(html, total) {
  361. $('#sys-modal-shop-basket .modal-body .data').html(html);
  362. ShopBasketEnableDisableOrderBtn(total);
  363. }, function(xhr, status, error) {
  364. window.location.reload(true);
  365. });
  366. }, function(xhr, status, error) {
  367. window.location.reload(true);
  368. }, function() {
  369. ShopBasketAjaxUpdateCount();
  370. ShopBasketUnBlockObject(object);
  371. $('#sys-modal-shop-basket .modal-body .blocker').css('display', 'none');
  372. });
  373. }
  374. return false;
  375. },
  376. ShopBasketProductRemove: function(object, product_id) {
  377. if(ShopBasketObjectIsNotBlocked(object)) {
  378. ShopBasketBlockObject(object);
  379. $('#sys-modal-shop-basket .modal-body .blocker').css('display', 'block');
  380. ShopBasketAjaxCommand('remove', product_id, function(data) {
  381. ShopBasketAjaxProductsHtml(function(html, total) {
  382. $('#sys-modal-shop-basket .modal-body .data').html(html);
  383. ShopBasketEnableDisableOrderBtn(total);
  384. }, function(xhr, status, error) {
  385. window.location.reload(true);
  386. });
  387. }, function(xhr, status, error) {
  388. window.location.reload(true);
  389. }, function() {
  390. ShopBasketAjaxUpdateCount();
  391. ShopBasketUnBlockObject(object);
  392. $('#sys-modal-shop-basket .modal-body .blocker').css('display', 'none');
  393. });
  394. }
  395. return false;
  396. },
  397. ShopBasketMakeOrder: function(object) {
  398. if(ShopBasketObjectIsNotBlocked(object)) {
  399. var OrderFormBlock = $('#sys-modal-shop-basket .modal-body .order-form');
  400. if(OrderFormBlock.css('display') == 'none') {
  401. OrderFormBlock.css('display', 'block');
  402. setTimeout(function() { OrderFormBlock.find('input.form-control').first().focus(); }, 500);
  403. return;
  404. }
  405. // Validate
  406. // Send form
  407. ShopBasketBlockObject(object);
  408. var OrderForm = $('#sys-modal-shop-basket .modal-body .order-form form');
  409. $.ajax({
  410. type: "POST",
  411. url: OrderForm.attr('action'),
  412. data: OrderForm.serialize()
  413. }).done(function(data) {
  414. // FormDataWasChanged = false;
  415. // if(IsDebugMode()) console.log('done', data);
  416. // AjaxDone(data);
  417. // ---
  418. // ShopOrderSuccess
  419. // ShopOrderErrorMobilePhone
  420. // ShopOrderErrorEmailAddress
  421. console.log('Order action done', data);
  422. }).fail(function(xhr, status, error) {
  423. // if(IsDebugMode()) console.log('fail', xhr, status, error);
  424. // AjaxFail(xhr.responseText, status, error);
  425. console.log('Order action fail', xhr, status, error);
  426. }).always(function() {
  427. ShopBasketUnBlockObject(object);
  428. });
  429. }
  430. },
  431. };
  432. }(window, $);
  433. window.frontend = frontend;
  434. }(window, jQuery));`)