1/// <reference path="../../../../../../../global.d.ts" /> 2/// <reference path="../../../../../../../iu.d.ts" /> 3function _assert_this_initialized(self) { 4 if (self === void 0) { 5 throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); 6 } 7 return self; 8} 9function _class_call_check(instance, Constructor) { 10 if (!(instance instanceof Constructor)) { 11 throw new TypeError("Cannot call a class as a function"); 12 } 13} 14function _defineProperties(target, props) { 15 for(var i = 0; i < props.length; i++){ 16 var descriptor = props[i]; 17 descriptor.enumerable = descriptor.enumerable || false; 18 descriptor.configurable = true; 19 if ("value" in descriptor) descriptor.writable = true; 20 Object.defineProperty(target, descriptor.key, descriptor); 21 } 22} 23function _create_class(Constructor, protoProps, staticProps) { 24 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 25 if (staticProps) _defineProperties(Constructor, staticProps); 26 return Constructor; 27} 28function _define_property(obj, key, value) { 29 if (key in obj) { 30 Object.defineProperty(obj, key, { 31 value: value, 32 enumerable: true, 33 configurable: true, 34 writable: true 35 }); 36 } else { 37 obj[key] = value; 38 } 39 return obj; 40} 41function _get_prototype_of(o) { 42 _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) { 43 return o.__proto__ || Object.getPrototypeOf(o); 44 }; 45 return _get_prototype_of(o); 46} 47function _inherits(subClass, superClass) { 48 if (typeof superClass !== "function" && superClass !== null) { 49 throw new TypeError("Super expression must either be null or a function"); 50 } 51 subClass.prototype = Object.create(superClass && superClass.prototype, { 52 constructor: { 53 value: subClass, 54 writable: true, 55 configurable: true 56 } 57 }); 58 if (superClass) _set_prototype_of(subClass, superClass); 59} 60function _possible_constructor_return(self, call) { 61 if (call && (_type_of(call) === "object" || typeof call === "function")) { 62 return call; 63 } 64 return _assert_this_initialized(self); 65} 66function _set_prototype_of(o, p) { 67 _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) { 68 o.__proto__ = p; 69 return o; 70 }; 71 return _set_prototype_of(o, p); 72} 73function _type_of(obj) { 74 "@swc/helpers - typeof"; 75 return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; 76} 77function _is_native_reflect_construct() { 78 if (typeof Reflect === "undefined" || !Reflect.construct) return false; 79 if (Reflect.construct.sham) return false; 80 if (typeof Proxy === "function") return true; 81 try { 82 Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {})); 83 return true; 84 } catch (e) { 85 return false; 86 } 87} 88function _create_super(Derived) { 89 var hasNativeReflectConstruct = _is_native_reflect_construct(); 90 return function _createSuperInternal() { 91 var Super = _get_prototype_of(Derived), result; 92 if (hasNativeReflectConstruct) { 93 var NewTarget = _get_prototype_of(this).constructor; 94 result = Reflect.construct(Super, arguments, NewTarget); 95 } else { 96 result = Super.apply(this, arguments); 97 } 98 return _possible_constructor_return(this, result); 99 }; 100} 101import { Controller } from "@hotwired/stimulus"; 102import Swiper from "swiper"; 103import { Navigation } from "swiper/modules"; 104import "swiper/swiper-bundle.css"; 105import { fetchFeedbacks } from "../../helpers/feedback-api.js"; 106import { openReviewsModal } from "../../helpers/open-reviews-modal.js"; 107import { formatRelativeTime } from "../../helpers/relative-time.js"; 108import { setControllerValues } from "../../helpers/stimulus-values.js"; 109import { isMobileViewport } from "../../helpers/viewport.js"; 110var PREVIEW_ITEMS_PER_PAGE = "4"; 111var MIN_REVIEWS_FOR_SHOW_ALL = 4; 112var AUTO_HEIGHT_UPDATE_DELAY = 50; 113var REVIEW_CARD_CONTROLLER = "feedback-review-card"; 114var REVIEW_CARD_SELECTOR = ".feedback-review-card"; 115var _class = /*#__PURE__*/ function(Controller) { 116 "use strict"; 117 _inherits(_class, Controller); 118 var _super = _create_super(_class); 119 function _class() { 120 _class_call_check(this, _class); 121 var _this; 122 _this = _super.apply(this, arguments); 123 _define_property(_assert_this_initialized(_this), "reviews", []); 124 _define_property(_assert_this_initialized(_this), "swiper", null); 125 _define_property(_assert_this_initialized(_this), "isMobile", false); 126 _define_property(_assert_this_initialized(_this), "abortController", null); 127 _define_property(_assert_this_initialized(_this), "autoHeightTimer", null); 128 _define_property(_assert_this_initialized(_this), "onResize", function() { 129 var isMobile = isMobileViewport(); 130 if (isMobile === _this.isMobile) { 131 return; 132 } 133 _this.isMobile = isMobile; 134 _this.render(); 135 }); 136 return _this; 137 } 138 _create_class(_class, [ 139 { 140 key: "connect", 141 value: function connect() { 142 var _this = this; 143 this.isMobile = isMobileViewport(); 144 window.addEventListener("resize", this.onResize); 145 this.abortController = new AbortController(); 146 var params = new URLSearchParams({ 147 itemsPerPage: PREVIEW_ITEMS_PER_PAGE 148 }); 149 fetchFeedbacks(this.targetTypeValue, this.targetIdValue, params, this.abortController.signal).then(function(collection) { 150 return _this.showReviews(collection["hydra:member"]); 151 }).catch(function() { 152 return undefined; 153 }); 154 } 155 }, 156 { 157 key: "disconnect", 158 value: function disconnect() { 159 var _this_abortController; 160 window.removeEventListener("resize", this.onResize); 161 (_this_abortController = this.abortController) === null || _this_abortController === void 0 ? void 0 : _this_abortController.abort(); 162 this.clearAutoHeightTimer(); 163 this.destroySwiper(); 164 } 165 }, 166 { 167 key: "openModal", 168 value: function openModal() { 169 openReviewsModal({ 170 targetId: this.targetIdValue, 171 targetType: this.targetTypeValue, 172 averageRating: this.averageRatingValue, 173 ratingCount: this.ratingCountValue, 174 feedbackCount: this.feedbackCountValue 175 }); 176 } 177 }, 178 { 179 key: "onCardExpanded", 180 value: function onCardExpanded() { 181 var _this = this; 182 this.clearAutoHeightTimer(); 183 this.autoHeightTimer = window.setTimeout(function() { 184 var _this_swiper; 185 (_this_swiper = _this.swiper) === null || _this_swiper === void 0 ? void 0 : _this_swiper.updateAutoHeight(); 186 _this.autoHeightTimer = null; 187 }, AUTO_HEIGHT_UPDATE_DELAY); 188 } 189 }, 190 { 191 key: "showReviews", 192 value: function showReviews(reviews) { 193 if (reviews.length === 0) { 194 return; 195 } 196 this.reviews = reviews; 197 this.showAllTarget.hidden = reviews.length < MIN_REVIEWS_FOR_SHOW_ALL; 198 this.element.hidden = false;
199 this.render(); 200 } 201 }, 202 { 203 key: "render", 204 value: function render() { 205 this.destroySwiper(); 206 this.listTarget.replaceChildren(); 207 this.navTarget.hidden = !this.isMobile; 208 if (this.isMobile) { 209 this.renderSlider(); 210 } else { 211 this.renderGrid(); 212 } 213 } 214 }, 215 { 216 key: "renderGrid", 217 value: function renderGrid() { 218 var _this = this; 219 var grid = document.createElement("div"); 220 grid.className = "feedback-course-reviews__grid"; 221 this.reviews.forEach(function(review) { 222 grid.appendChild(_this.buildCard(review, false)); 223 }); 224 this.listTarget.appendChild(grid); 225 } 226 }, 227 { 228 key: "renderSlider", 229 value: function renderSlider() { 230 var _this = this; 231 var slider = document.createElement("div"); 232 slider.className = "swiper feedback-course-reviews__slider"; 233 var wrapper = document.createElement("div"); 234 wrapper.className = "swiper-wrapper"; 235 this.reviews.forEach(function(review) { 236 var slide = document.createElement("div"); 237 slide.className = "swiper-slide"; 238 slide.appendChild(_this.buildCard(review, true)); 239 wrapper.appendChild(slide); 240 }); 241 slider.appendChild(wrapper); 242 this.listTarget.appendChild(slider); 243 this.swiper = new Swiper(slider, { 244 modules: [ 245 Navigation 246 ], 247 slidesPerView: 1, 248 autoHeight: true, 249 observer: true, 250 observeParents: true, 251 observeSlideChildren: true, 252 navigation: { 253 prevEl: this.prevButtonTarget, 254 nextEl: this.nextButtonTarget 255 } 256 }); 257 } 258 }, 259 { 260 key: "buildCard", 261 value: function buildCard(review, isMobile) { 262 var fragment = this.reviewTemplateTarget.content.cloneNode(true); 263 var card = fragment.querySelector(REVIEW_CARD_SELECTOR); 264 if (card) { 265 var _review_userData, _review_userData1; 266 var _review_userData_fullName, _review_userData_avatarBig; 267 setControllerValues(card, REVIEW_CARD_CONTROLLER, { 268 author: (_review_userData_fullName = (_review_userData = review.userData) === null || _review_userData === void 0 ? void 0 : _review_userData.fullName) !== null && _review_userData_fullName !== void 0 ? _review_userData_fullName : "", 269 avatar: (_review_userData_avatarBig = (_review_userData1 = review.userData) === null || _review_userData1 === void 0 ? void 0 : _review_userData1.avatarBig) !== null && _review_userData_avatarBig !== void 0 ? _review_userData_avatarBig : "", 270 stars: review.rating, 271 dateLabel: formatRelativeTime(review.createdAt, this.localeValue), 272 text: review.text, 273 answer: "", 274 limitText: isMobile, 275 limitHeight: !isMobile 276 }); 277 } 278 return fragment; 279 } 280 }, 281 { 282 key: "destroySwiper", 283 value: function destroySwiper() { 284 var _this_swiper; 285 (_this_swiper = this.swiper) === null || _this_swiper === void 0 ? void 0 : _this_swiper.destroy(true, true); 286 this.swiper = null; 287 } 288 }, 289 { 290 key: "clearAutoHeightTimer", 291 value: function clearAutoHeightTimer() { 292 if (this.autoHeightTimer !== null) { 293 window.clearTimeout(this.autoHeightTimer); 294 this.autoHeightTimer = null; 295 } 296 } 297 } 298 ]); 299 return _class; 300}(Controller); 301_define_property(_class, "values", { 302 targetId: Number, 303 targetType: Number, 304 averageRating: Number, 305 ratingCount: Number, 306 feedbackCount: Number, 307 locale: String 308}); 309_define_property(_class, "targets", [ 310 "nav", 311 "prevButton", 312 "nextButton", 313 "list", 314 "showAll", 315 "reviewTemplate" 316]); 317/* stimulusFetch: 'lazy' */ export { _class as default };
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.