You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

76 regels
2.5 KiB

  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'jquery',
  7. 'tabs',
  8. 'collapsible'
  9. ], function ($) {
  10. 'use strict';
  11. /**
  12. * @param {String} url
  13. * @param {*} fromPages
  14. */
  15. function processReviews(url, fromPages) {
  16. $.ajax({
  17. url: url,
  18. cache: true,
  19. dataType: 'html',
  20. showLoader: false,
  21. loaderContext: $('.product.data.items')
  22. }).done(function (data) {
  23. $('#product-review-container').html(data).trigger('contentUpdated');
  24. $('[data-role="product-review"] .pages a').each(function (index, element) {
  25. $(element).on('click', function (event) { //eslint-disable-line max-nested-callbacks
  26. processReviews($(element).attr('href'), true);
  27. event.preventDefault();
  28. });
  29. });
  30. }).always(function () {
  31. if (fromPages == true) { //eslint-disable-line eqeqeq
  32. $('html, body').animate({
  33. scrollTop: $('#reviews').offset().top - 50
  34. }, 300);
  35. }
  36. });
  37. }
  38. return function (config) {
  39. var reviewTab = $(config.reviewsTabSelector),
  40. requiredReviewTabRole = 'tab';
  41. if (reviewTab.attr('role') === requiredReviewTabRole && reviewTab.hasClass('active')) {
  42. processReviews(config.productReviewUrl, location.hash === '#reviews');
  43. } else {
  44. reviewTab.one('beforeOpen', function () {
  45. processReviews(config.productReviewUrl);
  46. });
  47. }
  48. $(function () {
  49. $('.product-info-main .reviews-actions a').on('click', function (event) {
  50. var anchor, addReviewBlock;
  51. event.preventDefault();
  52. anchor = $(this).attr('href').replace(/^.*?(#|$)/, '');
  53. addReviewBlock = $('#' + anchor);
  54. if (addReviewBlock.length) {
  55. $('.product.data.items [data-role="content"]').each(function (index) { //eslint-disable-line
  56. if (this.id == 'reviews') { //eslint-disable-line eqeqeq
  57. $('.product.data.items').tabs('activate', index);
  58. }
  59. });
  60. $('html, body').animate({
  61. scrollTop: addReviewBlock.offset().top - 50
  62. }, 300);
  63. }
  64. });
  65. });
  66. };
  67. });