vendor
7 years ago
admin.js
4 years ago
front.js
3 years ago
index.html
7 years ago
pdfobject.min.js
3 years ago
preview.js
3 years ago
settings.js
6 years ago
front.js
357 lines
| 1 | /** |
| 2 | * @package EmbedPress |
| 3 | * @author EmbedPress <help@embedpress.com> |
| 4 | * @copyright Copyright (C) 2023 EmbedPress. All rights reserved. |
| 5 | * @license GPLv2 or later |
| 6 | * @since 1.7.0 |
| 7 | */ |
| 8 | (function ($) { |
| 9 | 'use strict'; |
| 10 | // function equivalent to jquery ready() |
| 11 | function ready(fn) { |
| 12 | if (document.readyState !== 'loading') { |
| 13 | fn(); |
| 14 | } else { |
| 15 | document.addEventListener('DOMContentLoaded', fn); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | ready(function () { |
| 20 | let option = { |
| 21 | forceObject: true, |
| 22 | }; |
| 23 | let selector = document.querySelectorAll('.embedpress-embed-document-pdf'); |
| 24 | if (selector.length) { |
| 25 | selector.forEach((function (value, index, thisArg) { |
| 26 | let id = value.dataset['emid']; |
| 27 | let src = value.dataset['emsrc']; |
| 28 | PDFObject.embed(src, "." + id, option); |
| 29 | })); |
| 30 | } |
| 31 | youtubeChannelGallery(); |
| 32 | }); |
| 33 | |
| 34 | /** |
| 35 | * |
| 36 | * Make embeds responsive so they don't overflow their container. |
| 37 | */ |
| 38 | |
| 39 | /** |
| 40 | * Add max-width & max-height to <iframe> elements, depending on their width & height props. |
| 41 | * |
| 42 | * |
| 43 | * @return {void} |
| 44 | */ |
| 45 | function embedPressResponsiveEmbeds() { |
| 46 | var proportion, parentWidth; |
| 47 | |
| 48 | // Loop iframe elements. |
| 49 | document.querySelectorAll('iframe').forEach(function (iframe) { |
| 50 | // Only continue if the iframe has a width & height defined. |
| 51 | if (iframe.width && iframe.height) { |
| 52 | // Calculate the proportion/ratio based on the width & height. |
| 53 | proportion = parseFloat(iframe.width) / parseFloat(iframe.height); |
| 54 | // Get the parent element's width. |
| 55 | parentWidth = parseFloat(window.getComputedStyle(iframe.parentElement, null).width.replace('px', '')); |
| 56 | // Set the max-width & height. |
| 57 | iframe.style.maxWidth = '100%'; |
| 58 | iframe.style.maxHeight = Math.round(parentWidth / proportion).toString() + 'px'; |
| 59 | } |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | // Run on initial load. |
| 64 | embedPressResponsiveEmbeds(); |
| 65 | |
| 66 | // Run on resize. |
| 67 | window.onresize = embedPressResponsiveEmbeds; |
| 68 | |
| 69 | |
| 70 | function hasClass(ele, cls) { |
| 71 | return !!ele.className.match(new RegExp("(\\s|^)" + cls + "(\\s|$)")); |
| 72 | } |
| 73 | |
| 74 | function addClass(ele, cls) { |
| 75 | if (!hasClass(ele, cls)) ele.className += " " + cls; |
| 76 | } |
| 77 | |
| 78 | function removeClass(ele, cls) { |
| 79 | if (hasClass(ele, cls)) { |
| 80 | var reg = new RegExp("(\\s|^)" + cls + "(\\s|$)"); |
| 81 | ele.className = ele.className.replace(reg, " "); |
| 82 | } |
| 83 | } |
| 84 | if (!Element.prototype.matches) { |
| 85 | Element.prototype.matches = |
| 86 | Element.prototype.matchesSelector || |
| 87 | Element.prototype.webkitMatchesSelector || |
| 88 | Element.prototype.mozMatchesSelector || |
| 89 | Element.prototype.msMatchesSelector || |
| 90 | Element.prototype.oMatchesSelector || |
| 91 | function (s) { |
| 92 | var matches = (this.document || this.ownerDocument).querySelectorAll(s), |
| 93 | i = matches.length; |
| 94 | while (--i >= 0 && matches.item(i) !== this) { } |
| 95 | return i > -1; |
| 96 | }; |
| 97 | } |
| 98 | var delegate = function (el, evt, sel, handler) { |
| 99 | el.addEventListener(evt, function (event) { |
| 100 | var t = event.target; |
| 101 | while (t && t !== this) { |
| 102 | if (t.matches(sel)) { |
| 103 | handler.call(t, event); |
| 104 | } |
| 105 | t = t.parentNode; |
| 106 | } |
| 107 | }); |
| 108 | }; |
| 109 | |
| 110 | function sendRequest(url, postData, callback) { |
| 111 | var req = createXMLHTTPObject(); |
| 112 | if (!req) return; |
| 113 | var method = postData ? "POST" : "GET"; |
| 114 | req.open(method, url, true); |
| 115 | if (postData) { |
| 116 | req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
| 117 | } |
| 118 | req.onreadystatechange = function () { |
| 119 | if (req.readyState != 4) return; |
| 120 | if (req.status != 200 && req.status != 304) { |
| 121 | return; |
| 122 | } |
| 123 | callback(req); |
| 124 | }; |
| 125 | if (req.readyState == 4) return; |
| 126 | req.send(postData); |
| 127 | } |
| 128 | |
| 129 | var XMLHttpFactories = [ |
| 130 | function () { |
| 131 | return new XMLHttpRequest(); |
| 132 | }, |
| 133 | function () { |
| 134 | return new ActiveXObject("Msxml3.XMLHTTP"); |
| 135 | }, |
| 136 | function () { |
| 137 | return new ActiveXObject("Msxml2.XMLHTTP.6.0"); |
| 138 | }, |
| 139 | function () { |
| 140 | return new ActiveXObject("Msxml2.XMLHTTP.3.0"); |
| 141 | }, |
| 142 | function () { |
| 143 | return new ActiveXObject("Msxml2.XMLHTTP"); |
| 144 | }, |
| 145 | function () { |
| 146 | return new ActiveXObject("Microsoft.XMLHTTP"); |
| 147 | }, |
| 148 | ]; |
| 149 | |
| 150 | function createXMLHTTPObject() { |
| 151 | var xmlhttp = false; |
| 152 | for (var i = 0; i < XMLHttpFactories.length; i++) { |
| 153 | try { |
| 154 | xmlhttp = XMLHttpFactories[i](); |
| 155 | } catch (e) { |
| 156 | continue; |
| 157 | } |
| 158 | break; |
| 159 | } |
| 160 | return xmlhttp; |
| 161 | } |
| 162 | function youtubeChannelGallery() { |
| 163 | var playerWraps = document.getElementsByClassName("ep-player-wrap"); |
| 164 | if (playerWraps && playerWraps.length) { |
| 165 | for (var i = 0, im = playerWraps.length; im > i; i++) { |
| 166 | youtubeChannelEvents(playerWraps[i]) |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | function youtubeChannelEvents(playerWrap) { |
| 171 | |
| 172 | delegate(playerWrap, "click", ".item", function (event) { |
| 173 | var embed = "https://www.youtube.com/embed/"; |
| 174 | var vid = this.getAttribute("data-vid"); |
| 175 | var iframe = playerWrap.getElementsByTagName("iframe"); |
| 176 | if (vid) { |
| 177 | if (iframe) { |
| 178 | var vidSrc = iframe[0].src.replace(/(.*\/embed\/)([^\?&"'>]+)(.+)?/, `\$1${vid}\$3`); |
| 179 | if (vidSrc.indexOf('autoplay') > 0) { |
| 180 | vidSrc = vidSrc.replace('autoplay=0', 'autoplay=1'); |
| 181 | } |
| 182 | else { |
| 183 | vidSrc += '&autoplay=1'; |
| 184 | } |
| 185 | iframe[0].src = vidSrc; |
| 186 | playerWrap.scrollIntoView(); |
| 187 | } |
| 188 | } |
| 189 | }); |
| 190 | |
| 191 | var currentPage = 1; |
| 192 | |
| 193 | let nearestEpContentId = playerWrap.querySelector('.ep-youtube__content__block').getAttribute('data-unique-id'); |
| 194 | |
| 195 | delegate(playerWrap, "click", ".ep-next, .ep-prev", function (event) { |
| 196 | const totalPages = event.target.closest('.ose-youtube').getAttribute('data-total-pages'); |
| 197 | const closestClass = event.target.closest('.ose-youtube').classList; |
| 198 | |
| 199 | const activePage = document.querySelector(`.${closestClass[1]} .embedpress-page-active`); |
| 200 | if (activePage) { |
| 201 | document.querySelector(`.${closestClass[1]} .embedpress-page-active`).classList.remove('embedpress-page-active'); |
| 202 | } |
| 203 | |
| 204 | |
| 205 | |
| 206 | var isNext = this.classList.contains("ep-next"); |
| 207 | |
| 208 | if (isNext) { |
| 209 | currentPage++; |
| 210 | } else { |
| 211 | currentPage--; |
| 212 | } |
| 213 | |
| 214 | var data = { |
| 215 | action: "youtube_rest_api", |
| 216 | playlistid: this.getAttribute("data-playlistid"), |
| 217 | pagetoken: this.getAttribute("data-pagetoken"), |
| 218 | pagesize: this.getAttribute("data-pagesize"), |
| 219 | currentpage: currentPage |
| 220 | }; |
| 221 | |
| 222 | var formBody = []; |
| 223 | for (var property in data) { |
| 224 | var encodedKey = encodeURIComponent(property); |
| 225 | var encodedValue = encodeURIComponent(data[property]); |
| 226 | formBody.push(encodedKey + "=" + encodedValue); |
| 227 | } |
| 228 | formBody = formBody.join("&"); |
| 229 | |
| 230 | var galleryWrapper = playerWrap.getElementsByClassName( |
| 231 | "ep-youtube__content__block" |
| 232 | ); |
| 233 | |
| 234 | playerWrap.setAttribute('data-current-page', currentPage); |
| 235 | |
| 236 | |
| 237 | let x = 1; |
| 238 | |
| 239 | sendRequest("/wp-admin/admin-ajax.php", formBody, function (request) { |
| 240 | if (galleryWrapper && galleryWrapper[0] && request.responseText) { |
| 241 | var response = JSON.parse(request.responseText); |
| 242 | galleryWrapper[0].outerHTML = response.html; |
| 243 | |
| 244 | var currentPageNode = |
| 245 | galleryWrapper[0].getElementsByClassName("current-page"); |
| 246 | if (currentPageNode && currentPageNode[0]) { |
| 247 | currentPageNode[0].textContent = currentPage; |
| 248 | |
| 249 | } |
| 250 | } |
| 251 | }); |
| 252 | |
| 253 | const intervalID = setInterval(() => { |
| 254 | x++ |
| 255 | |
| 256 | if (playerWrap.querySelector('.ep-youtube__content__block')) { |
| 257 | const newNearestEpContentId = playerWrap |
| 258 | .querySelector('.ep-youtube__content__block') |
| 259 | .getAttribute('data-unique-id'); |
| 260 | |
| 261 | if (newNearestEpContentId !== nearestEpContentId && playerWrap.querySelector(`[data-page="${currentPage}"]`)) { |
| 262 | playerWrap.querySelector(`[data-page="${currentPage}"]`).classList.add('embedpress-page-active'); |
| 263 | nearestEpContentId = newNearestEpContentId; |
| 264 | clearInterval(intervalID); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | if (x > 100) { |
| 269 | clearInterval(intervalID); |
| 270 | } |
| 271 | }, 100); |
| 272 | |
| 273 | }); |
| 274 | } |
| 275 | |
| 276 | //Load more for OpenaSea collection |
| 277 | const epLoadMore = () => { |
| 278 | |
| 279 | $('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper').each(function () { |
| 280 | let selctorEl = `[data-nftid='${$(this).data('nftid')}']`; |
| 281 | |
| 282 | let loadmorelabel = $(selctorEl).data('loadmorelabel'); |
| 283 | let iconcolor = $(selctorEl + " .nft-loadmore").data('iconcolor'); |
| 284 | |
| 285 | let spinicon = `<svg width="18" height="18" fill="${iconcolor || '#fff'}" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><style>.spinner_GuJz{transform-origin:center;animation:spinner_STY6 1.5s linear infinite}@keyframes spinner_STY6{100%{transform:rotate(360deg)}}</style><g class="spinner_GuJz"><circle cx="3" cy="12" r="2"/><circle cx="21" cy="12" r="2"/><circle cx="12" cy="21" r="2"/><circle cx="12" cy="3" r="2"/><circle cx="5.64" cy="5.64" r="2"/><circle cx="18.36" cy="18.36" r="2"/><circle cx="5.64" cy="18.36" r="2"/><circle cx="18.36" cy="5.64" r="2"/></g></svg>`; |
| 286 | |
| 287 | $(selctorEl + ` .ep_nft_item`).slice(0, $(selctorEl).data('itemparpage')).show(); |
| 288 | $('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper .ep-loadmore-wrapper button').css('display', 'flex'); |
| 289 | |
| 290 | $(selctorEl + " .nft-loadmore").click(function (e) { |
| 291 | //change the text of the button |
| 292 | $(this).html(loadmorelabel + spinicon); |
| 293 | //disable the button |
| 294 | $(this).prop("disabled", true); |
| 295 | //wait for 1 seconds |
| 296 | setTimeout(function () { |
| 297 | //change the text back |
| 298 | $(selctorEl + " .nft-loadmore").text(loadmorelabel); |
| 299 | //enable the button |
| 300 | $(selctorEl + " .nft-loadmore").prop("disabled", false); |
| 301 | $(selctorEl + " .ep_nft_item:hidden").slice(0, $(selctorEl).data('itemparpage')).fadeIn("slow"); |
| 302 | if ($(selctorEl + " .ep_nft_item:hidden").length == 0) { |
| 303 | $(selctorEl + " .nft-loadmore").fadeOut("slow"); |
| 304 | } |
| 305 | }, 500); |
| 306 | }); |
| 307 | }); |
| 308 | }; |
| 309 | |
| 310 | if ($('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper').length > 0) { |
| 311 | epLoadMore(); |
| 312 | } |
| 313 | |
| 314 | })(jQuery); |
| 315 | |
| 316 | |
| 317 | jQuery(window).on("elementor/frontend/init", function () { |
| 318 | var filterableGalleryHandler = function ($scope, $) { |
| 319 | const epElLoadMore = () => { |
| 320 | |
| 321 | const spinicon = '<svg width="18" height="18" fill="#fff" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><style>.spinner_GuJz{transform-origin:center;animation:spinner_STY6 1.5s linear infinite}@keyframes spinner_STY6{100%{transform:rotate(360deg)}}</style><g class="spinner_GuJz"><circle cx="3" cy="12" r="2"/><circle cx="21" cy="12" r="2"/><circle cx="12" cy="21" r="2"/><circle cx="12" cy="3" r="2"/><circle cx="5.64" cy="5.64" r="2"/><circle cx="18.36" cy="18.36" r="2"/><circle cx="5.64" cy="18.36" r="2"/><circle cx="18.36" cy="5.64" r="2"/></g></svg>'; |
| 322 | |
| 323 | $('.elementor-widget-container .ep-nft-gallery-wrapper').each(function () { |
| 324 | let selctorEl = `.elementor-widget-container [data-nftid='${$(this).data('nftid')}']`; |
| 325 | let loadmorelabel = $(selctorEl).data('loadmorelabel'); |
| 326 | $(selctorEl + ` .ep_nft_item`).slice(0, $(selctorEl).data('itemparpage')).show(); |
| 327 | $('.elementor-widget-container .ep-nft-gallery-wrapper .ep-loadmore-wrapper button').css('display', 'flex'); |
| 328 | |
| 329 | $(selctorEl + " .nft-loadmore").click(function (e) { |
| 330 | //change the text of the button |
| 331 | $(this).html(loadmorelabel + spinicon); |
| 332 | |
| 333 | //disable the button |
| 334 | $(this).prop("disabled", true); |
| 335 | //wait for 1 seconds |
| 336 | setTimeout(function () { |
| 337 | //change the text back |
| 338 | $(selctorEl + " .nft-loadmore").text(loadmorelabel); |
| 339 | //enable the button |
| 340 | $(selctorEl + " .nft-loadmore").prop("disabled", false); |
| 341 | $(selctorEl + " .ep_nft_item:hidden").slice(0, $(selctorEl).data('itemparpage')).fadeIn("slow"); |
| 342 | if ($(selctorEl + " .ep_nft_item:hidden").length == 0) { |
| 343 | $(selctorEl + " .nft-loadmore").fadeOut("slow"); |
| 344 | } |
| 345 | }, 500); |
| 346 | }); |
| 347 | }); |
| 348 | }; |
| 349 | |
| 350 | if ($('.elementor-widget-container .ep-nft-gallery-wrapper').length > 0) { |
| 351 | epElLoadMore(); |
| 352 | } |
| 353 | |
| 354 | }; |
| 355 | elementorFrontend.hooks.addAction("frontend/element_ready/embedpres_elementor.default", filterableGalleryHandler); |
| 356 | }); |
| 357 |