liebling/assets/js/helpers.js
2021-02-15 19:56:34 +01:00

189 lines
6.8 KiB
JavaScript

(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["/js/helpers"],{
/***/ "./js/helpers.js":
/*!***********************!*\
!*** ./js/helpers.js ***!
\***********************/
/*! exports provided: isRTL, isMobile, isDarkMode, formatDate, getParameterByName, adjustImageGallery, managePostImages, makeImagesZoomable */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isRTL", function() { return isRTL; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isMobile", function() { return isMobile; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isDarkMode", function() { return isDarkMode; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "formatDate", function() { return formatDate; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getParameterByName", function() { return getParameterByName; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "adjustImageGallery", function() { return adjustImageGallery; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "managePostImages", function() { return managePostImages; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "makeImagesZoomable", function() { return makeImagesZoomable; });
var isRTL = function isRTL() {
var $html = document.querySelector('html');
return ['ar', 'he', 'fa'].includes($html.getAttribute('lang'));
};
var isMobile = function isMobile() {
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '768px';
return window.matchMedia("(max-width: ".concat(width, ")")).matches;
};
var isDarkMode = function isDarkMode() {
var darkModeMatcher = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)');
return darkModeMatcher && darkModeMatcher.matches;
};
var formatDate = function formatDate(date) {
if (date) {
return new Date(date).toLocaleDateString(document.documentElement.lang, {
year: 'numeric',
month: 'long',
day: 'numeric'
});
}
return '';
};
var getParameterByName = function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp("[?&]".concat(name, "(=([^&#]*)|&|#|$)"));
var results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
};
var adjustImageGallery = function adjustImageGallery() {
var images = document.querySelectorAll('.kg-gallery-image img');
for (var i = 0, len = images.length; i < len; i++) {
var container = images[i].closest('.kg-gallery-image');
var width = images[i].attributes.width.value;
var height = images[i].attributes.height.value;
var ratio = width / height;
container.style.flex = "".concat(ratio, " 1 0%");
}
};
var managePostImages = function managePostImages($) {
$('.js-post-content').find('img').each(function () {
if (!$(this).closest('figure').hasClass('kg-bookmark-card') && !$(this).parent().is('a')) {
$(this).addClass('js-zoomable');
}
var $figcaption = $(this).parent().find('figcaption');
if ($figcaption) {
$(this).attr('alt', $figcaption.text());
} else {
$(this).attr('alt', '');
}
});
};
var makeImagesZoomable = function makeImagesZoomable($, mediumZoom) {
var zoom = mediumZoom('.js-zoomable');
zoom.on('opened', function () {
setTimeout(function () {
var $mediumZoomImages = $('.medium-zoom-image--opened');
if ($mediumZoomImages.length > 1) {
$mediumZoomImages.last().hide();
}
}, 10);
});
};
/***/ }),
/***/ "./sass/404.scss":
/*!***********************!*\
!*** ./sass/404.scss ***!
\***********************/
/*! no static exports found */
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ }),
/***/ "./sass/app.scss":
/*!***********************!*\
!*** ./sass/app.scss ***!
\***********************/
/*! no static exports found */
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ }),
/***/ "./sass/home.scss":
/*!************************!*\
!*** ./sass/home.scss ***!
\************************/
/*! no static exports found */
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ }),
/***/ "./sass/listing.scss":
/*!***************************!*\
!*** ./sass/listing.scss ***!
\***************************/
/*! no static exports found */
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ }),
/***/ "./sass/newsletter.scss":
/*!******************************!*\
!*** ./sass/newsletter.scss ***!
\******************************/
/*! no static exports found */
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ }),
/***/ "./sass/post.scss":
/*!************************!*\
!*** ./sass/post.scss ***!
\************************/
/*! no static exports found */
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ }),
/***/ "./sass/tags.scss":
/*!************************!*\
!*** ./sass/tags.scss ***!
\************************/
/*! no static exports found */
/***/ (function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ }),
/***/ 0:
/*!***********************************************************************************************************************************************************!*\
!*** multi ./js/helpers.js ./sass/app.scss ./sass/home.scss ./sass/listing.scss ./sass/post.scss ./sass/newsletter.scss ./sass/tags.scss ./sass/404.scss ***!
\***********************************************************************************************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(/*! /Users/eddie/Code/own/liebling/src/js/helpers.js */"./js/helpers.js");
__webpack_require__(/*! /Users/eddie/Code/own/liebling/src/sass/app.scss */"./sass/app.scss");
__webpack_require__(/*! /Users/eddie/Code/own/liebling/src/sass/home.scss */"./sass/home.scss");
__webpack_require__(/*! /Users/eddie/Code/own/liebling/src/sass/listing.scss */"./sass/listing.scss");
__webpack_require__(/*! /Users/eddie/Code/own/liebling/src/sass/post.scss */"./sass/post.scss");
__webpack_require__(/*! /Users/eddie/Code/own/liebling/src/sass/newsletter.scss */"./sass/newsletter.scss");
__webpack_require__(/*! /Users/eddie/Code/own/liebling/src/sass/tags.scss */"./sass/tags.scss");
module.exports = __webpack_require__(/*! /Users/eddie/Code/own/liebling/src/sass/404.scss */"./sass/404.scss");
/***/ })
},[[0,"/js/manifest"]]]);