PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/js/old/common.js

https://github.com/coderiver/grenka
JavaScript | 496 lines | 409 code | 49 blank | 38 comment | 33 complexity | f2c3ba358714147f6592a5275d001671 MD5 | raw file
  1. $(document).ready(function() {
  2. // Created by Eugene Godun!
  3. // init variables
  4. var prod_carousel = $('.recent-product__carousel');
  5. var prod = $(".product");
  6. var prod_image = $(".product__image");
  7. var key_text = $('.js-text-key');
  8. var recent_key = $(".js-recent-key");
  9. var hidden_block = $(".js-hidden-block").hide();
  10. //input number
  11. function input_number() {
  12. $('.js-input-number').each(function() {
  13. var el = $(this);
  14. var el_plus = el.find('.input-number__plus');
  15. var el_minus = el.find('.input-number__minus');
  16. var el_value = el.find('.input-number__value');
  17. el_plus.click(function() {
  18. var value = el_value.val();
  19. value = parseInt(value);
  20. if (value >= 1) {
  21. value++;
  22. el_value.val(value);
  23. };
  24. });
  25. el_minus.click(function() {
  26. var value = el_value.val();
  27. value = parseInt(value);
  28. if (value > 1) {
  29. value--;
  30. el_value.val(value);
  31. };
  32. });
  33. });
  34. }
  35. input_number();
  36. //stop propagation
  37. $(document).click(function() {
  38. $('.js-select').removeClass('is-open');
  39. $('.label__select-options').hide();
  40. $('.js-top-popup').removeClass('is-active');
  41. });
  42. $('.js-top-popup').click(function(event){
  43. event.stopPropagation();
  44. });
  45. //location
  46. $('.js-top-popup').click(function() {
  47. $('.js-top-popup').removeClass('is-active');
  48. $(this).toggleClass('is-active');
  49. return false;
  50. });
  51. //select
  52. function select() {
  53. var el = $('.js-select');
  54. var title = el.find('.label__select-val');
  55. var option = el.find('.label__select-options li');
  56. title.click(function() {
  57. if (!$(this).parent().hasClass('is-open')) {
  58. el.removeClass('is-open');
  59. el.find('.label__select-options').hide();
  60. $(this).parent().addClass('is-open');
  61. $(this).next().slideDown('fast');
  62. }
  63. else {
  64. $(this).parent().removeClass('is-open');
  65. $(this).next().hide();
  66. };
  67. });
  68. option.click(function() {
  69. var value = $(this).text();
  70. $(this).parent().prev().find('span').html(value);
  71. $(this).parent().parent().removeClass('is-open');
  72. $(this).parent().hide();
  73. });
  74. title.click(function(event){
  75. event.stopPropagation();
  76. });
  77. };
  78. select();
  79. $('.js-select').click(function(event){
  80. event.stopPropagation();
  81. });
  82. // show/hide recent products
  83. recent_key.click(function() {
  84. $('.recent__carousel').slideToggle();
  85. if ($(this).hasClass("js-inactive")) {
  86. $(this).removeClass("js-inactive");
  87. $(this).find("span").text("Свернуть");
  88. prod_carousel.slideDown();
  89. }
  90. else {
  91. $(this).addClass("js-inactive");
  92. $(this).find("span").text("Развернуть");
  93. prod_carousel.slideUp();
  94. }
  95. });
  96. // ---------------- hide slider text -------------------- //
  97. key_text.live("hover", function(){
  98. $(this).parent().find(".slider-info, .shadow-slider").fadeToggle();
  99. });
  100. // ---------------- info-block visible -------------------- //
  101. $('.js-show-hidden').click(function() {
  102. $(this).parent().find(hidden_block).slideToggle();
  103. $(this).parent().find('.js-show-hidden').toggleClass("is-active");
  104. return false;
  105. });
  106. //tabs
  107. function tabs() {
  108. $(".js-tabs-content").first().show();
  109. $('.tabs__top').next().show();
  110. $('.js-tabs-nav button').click(function() {
  111. if (!$(this).hasClass('active')) {
  112. $(this).parent().find('button').removeClass('is-active');
  113. var value = $(this).attr('data-tab');
  114. var count = $(this).attr('data-count');
  115. $(this).addClass('is-active');
  116. $(this).parent().parent().parent().find('.js-tabs-content').hide();
  117. $('#' + value).show();
  118. $(this).parent().next().find('.js-tabs-count').html('('+count+')');
  119. };
  120. });
  121. };
  122. tabs();
  123. // zomm product item on hover
  124. prod_image.hover(
  125. function () {
  126. $(this).parent().parent().addClass("is-hover");
  127. },
  128. function () {
  129. //$(this).parent().parent().removeClass("is-hover");
  130. }
  131. );
  132. prod.hover(
  133. function () {
  134. //$(this).parent().parent().addClass("is-hover");
  135. },
  136. function () {
  137. $(this).removeClass("is-hover");
  138. }
  139. );
  140. $(".add-order__pic img").hover(
  141. function () {
  142. $(this).addClass("is-hover");
  143. },
  144. function () {
  145. $(this).removeClass("is-hover");
  146. }
  147. );
  148. // prod.hover(
  149. // function () {
  150. // //$(this).parent().parent().addClass("is-hover");
  151. // },
  152. // function () {
  153. // $(this).removeClass("is-hover");
  154. // }
  155. // );
  156. // ------------------- Fancybox ----------------------//
  157. $('.js-popup-link').on('click', function() {
  158. $this = $(this);
  159. $.fancybox({
  160. href: $this.attr('href'),
  161. padding: 0
  162. });
  163. return false;
  164. });
  165. if ($('#reg-message').length > 0) {
  166. $.fancybox.open('#reg-message');
  167. }
  168. if ($('#recovery_pass').length > 0) {
  169. $.fancybox.open('#recovery_pass');
  170. }
  171. if ($('#created-wish-popup').length > 0) {
  172. $.fancybox.open('#created-wish-popup');
  173. }
  174. if ($('#message-ok').length > 0) {
  175. $.fancybox.open('#message-ok');
  176. }
  177. if ($('#popup-order').length > 0) {
  178. $.fancybox.open('#popup-order');
  179. }
  180. // ------------------- END Fancybox ----------------------//
  181. function offer() {
  182. var active_slide = $(".cycle-slide-active");
  183. var offer_1 = $('.js-offer-slider1');
  184. var offer_2 = $('.js-offer-slider2');
  185. var price_1 = offer_1.find(active_slide).attr("data-price");
  186. var discount_1 = offer_1.find(active_slide).attr("data-discount");
  187. var price_2 = offer_2.find(active_slide).attr("data-price");
  188. var discount_2 = offer_2.find(active_slide).attr("data-discount");
  189. var price = +price_1 + +price_2;
  190. if (+discount_1 > (+discount_2)) {
  191. var discount = discount_2;
  192. }
  193. else {
  194. var discount = discount_1;
  195. }
  196. var econom = (+price*(+discount/100)).toFixed(1);
  197. var new_price = (+price*(1-(+discount)/100)).toFixed(1);
  198. $(".js-offer-price").text(price);
  199. $(".js-offer-discount").text(discount+'%');
  200. $(".js-offer-econom").text(econom);
  201. $(".js-offer-new-price").text(new_price);
  202. }
  203. offer();
  204. $(".offer__slider button").on("click", function(event){
  205. $('.js-offer-slider').on( 'cycle-after', function( event, opts ) {
  206. offer();
  207. //alert();
  208. });
  209. });
  210. var replace_popup = $(".js-replace-popup");
  211. $(".js-replace-wish-link").click(function(){
  212. $(".product__remove-popup").hide();
  213. $(this).parent().find(replace_popup).toggle();
  214. return false;
  215. });
  216. $(".js-replace-close").click(function(){
  217. replace_popup.hide();
  218. })
  219. var del_popup = $(".js-del-popup");
  220. $(".js-del-wish-link").click(function(){
  221. $(".product__remove-popup").hide();
  222. $(this).parent().find(del_popup).toggle();
  223. return false;
  224. });
  225. $(".js-del-close").click(function(){
  226. del_popup.hide();
  227. })
  228. if ($('#slider-left-main').length > 0) {
  229. // Главный слайдер
  230. $('#slider-left-main').veronica_slider(
  231. {
  232. active : true, // режим выбора активного элемента
  233. autoplay : true, // автоматическая прокрутка
  234. height: 107, // высота блока
  235. step : 5000, // время в милисикундах для автоматического режима
  236. callback : function(el)
  237. {
  238. $('.slider-biggest').html($('#slider-left-main').find('ul li.active:first').find('div.big_info').html());
  239. }, // callback функция при смене активного элемента
  240. stop: ['#main_slider_pause','table.main-menu'], // идентификаторы элментов, при наведении на которые автопрокрутка останавливается
  241. fixed: true, // режим прокрутки если активный элемент вверху или внизу
  242. click : function(el) {
  243. $('#slider-left-main').find('li.active').removeClass('active');
  244. $(el).addClass('active');
  245. $('.slider-biggest').html($('#slider-left-main').find('ul li.active:first').find('div.big_info').html());
  246. } // callback функция при клике
  247. }
  248. );
  249. }
  250. // Search example
  251. $(".js-search-example a").click(function(){
  252. var text = $(this).text();
  253. $(".js-searc-input").val(text);
  254. return false;
  255. });
  256. var btn_edit = $(".js-edit-input");
  257. var btn_add = $(".js-add-field");
  258. var field_edited = $(".js-edit-me");
  259. var will_add_field = $(".js-will-add");
  260. var new_field = $(".js-new-field");
  261. will_add_field.hide();
  262. btn_edit.live("click", function(event){
  263. //$(this).parent().find(field_edited).removeAttr("disabled").removeClass("is-inactive").hide().fadeIn("fast").focus();
  264. $(this).prev().children(field_edited).removeAttr("disabled").removeClass("is-inactive").hide().fadeIn("fast").focus();
  265. console.log("edit");
  266. return false;
  267. });
  268. btn_add.live("click", function(event){
  269. var html = will_add_field.html();
  270. console.log("add");
  271. $(this).parent().find(new_field).last().after(html);
  272. return false;
  273. });
  274. // scrollpane
  275. if ($(".js-scroll-pane").length > 0) {
  276. $('.js-scroll-pane').jScrollPane({
  277. autoReinitialise: true
  278. });
  279. }
  280. $(".js-show-order").click(function(){
  281. if ($(this).hasClass("js-active")) {
  282. $(this).text("Посмотреть");
  283. $(this).removeClass("js-active");
  284. $(this).parent().parent().next().find(".cart__table").hide();
  285. }
  286. else {
  287. $(this).text("Скрыть");
  288. $(this).addClass("js-active");
  289. $(this).parent().parent().next().find(".cart__table").show();
  290. }
  291. return false;
  292. });
  293. $(".js-detail-order").click(function(){
  294. $(this).parent().parent().next().find(".cart__table").toggle();
  295. return false;
  296. });
  297. var c_days = $(".js-counter").attr("data-days");
  298. var c_hours = $(".js-counter").attr("data-hours");
  299. var c_minutes = $(".js-counter").attr("data-minutes");
  300. if ($(".js-counter").length > 0) {
  301. $('.js-counter').countdown({
  302. until: '+'+c_days +' '+ '+'+c_hours + ' ' + '+'+c_minutes,
  303. format: 'YOWDHMS',
  304. layout: $('.js-counter-list').html()
  305. });
  306. }
  307. // delite compare product
  308. $(".js-del-compare").click(function(){
  309. var index = $(this).parent().parent().index();
  310. $(this).parent().parent().hide();
  311. $(".js-compare tr").each(function(){
  312. $(this).children("td").eq(index).hide();
  313. });
  314. });
  315. // delite filter
  316. $(".js-del-filter").click(function(){
  317. $(this).parent().hide();
  318. });
  319. $(".js-del-all-filters").click(function(){
  320. $(this).parent().parent().remove();
  321. return false;
  322. });
  323. // accordion filter
  324. $(".js-accord-body").hide();
  325. $(".js-accord-key").click(function(){
  326. $(this).next().slideToggle("fast");
  327. });
  328. // remove telephone number
  329. var number_html = $(".js-number").html();
  330. var add_number = $(".js-add-number");
  331. var del_number = $(".js-del-number");
  332. var number_last = $(".js-new-number").last();
  333. add_number.live("click", function(event){
  334. number_last.after(number_html);
  335. return false;
  336. });
  337. del_number.live("click", function(event){
  338. $(this).parent().remove();
  339. return false;
  340. });
  341. // -------------------------------- Created by Artur Moroz!
  342. //rating
  343. if ($('.js-rating').length > 0) {
  344. $('.js-rating').raty({
  345. width: 80,
  346. starOff: 'img/icons/rating.png',
  347. starOn : 'img/icons/rating-act.png',
  348. score: function() {
  349. return $(this).attr('data-score');
  350. }
  351. });
  352. }
  353. if ($('.js-rating-big').length > 0) {
  354. $('.js-rating-big').raty({
  355. width: 130,
  356. starOff: 'img/icons/rating-big.png',
  357. starOn : 'img/icons/rating-big-act.png',
  358. score: function() {
  359. return $(this).attr('data-score');
  360. }
  361. });
  362. }
  363. if ($('.js-rating-read').length > 0) {
  364. $('.js-rating-read').raty({
  365. readOnly: true,
  366. noRatedMsg: "",
  367. width: 80,
  368. starOff: 'img/icons/rating.png',
  369. starOn : 'img/icons/rating-act.png',
  370. score: function() {
  371. return $(this).attr('data-score');
  372. }
  373. });
  374. }
  375. //hide address on cart
  376. $('.js-hide-address').click(function() {
  377. if ($(this).find('input').is(':checked')) {
  378. $(this).next().slideUp("fast");
  379. }
  380. else {
  381. $(this).next().slideDown("fast");
  382. }
  383. });
  384. //placeholder
  385. $('.js-placeholder').focus(function() {
  386. if ($(this).val() == '') {
  387. $(this).next().hide();
  388. };
  389. });
  390. $('.js-placeholder').blur(function() {
  391. if ($(this).val() == '') {
  392. $(this).next().show();
  393. };
  394. });
  395. //read all description
  396. $('.js-read-all').click(function() {
  397. if (!$(this).hasClass('is-open')) {
  398. $(this).addClass('is-open');
  399. $(this).html('скрыть');
  400. $(this).parent().prev().height('auto');
  401. }
  402. else {
  403. $(this).removeClass('is-open');
  404. $(this).html('Читать полностью...');
  405. $(this).parent().prev().height('135px');
  406. }
  407. })
  408. //gallery
  409. function gallery() {
  410. var el = $('.js-gallery');
  411. el.each(function(){
  412. $(this).find('.gallery__slide a').click(function() {
  413. if (!$(this).hasClass('is-active')) {
  414. var pic = $(this).attr('href');
  415. $(this).parent().parent().find('a').removeClass('is-active');
  416. $(this).addClass('is-active');
  417. $(this).parent().parent().parent().parent().next().find('img').attr('src', pic);
  418. };
  419. return false;
  420. });
  421. $(this).find('.gallery__up').click(function() {
  422. var act = $(this).parent().find('.gallery__slide a.is-active');
  423. act.removeClass('is-active');
  424. act.parent().prev().find('a').addClass('is-active');
  425. var pic = act.parent().prev().find('a').attr('href');
  426. $(this).parent().next().find('img').attr('src', pic);
  427. });
  428. $(this).find('.gallery__down').click(function() {
  429. var act = $(this).parent().find('.gallery__slide a.is-active');
  430. act.removeClass('is-active');
  431. act.parent().next().find('a').addClass('is-active');
  432. var pic = act.parent().prev().find('a').attr('href');
  433. $(this).parent().next().find('img').attr('src', pic);
  434. });
  435. });
  436. };
  437. gallery();
  438. if ($("a.js-fancy-img").length > 0) {
  439. $("a.js-fancy-img").fancybox();
  440. }
  441. if ($('.js-cycle').length > 0) {
  442. $('.js-cycle').cycle({
  443. speed: 200,
  444. manualSpeed: 50
  445. });
  446. }
  447. });