vendor
7 years ago
admin.js
4 years ago
front.js
3 years ago
index.html
7 years ago
pdfobject.min.js
4 years ago
preview.js
3 years ago
settings.js
6 years ago
front.js
279 lines
| 1 | /** |
| 2 | * @package EmbedPress |
| 3 | * @author EmbedPress <help@embedpress.com> |
| 4 | * @copyright Copyright (C) 2022 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 | |
| 173 | |
| 174 | delegate(playerWrap, "click", ".item", function (event) { |
| 175 | var embed = "https://www.youtube.com/embed/"; |
| 176 | var vid = this.getAttribute("data-vid"); |
| 177 | var iframe = playerWrap.getElementsByTagName("iframe"); |
| 178 | if (vid) { |
| 179 | if (iframe) { |
| 180 | var vidSrc = iframe[0].src.replace(/(.*\/embed\/)([^\?&"'>]+)(.+)?/, `\$1${vid}\$3`); |
| 181 | if (vidSrc.indexOf('autoplay') > 0) { |
| 182 | vidSrc = vidSrc.replace('autoplay=0', 'autoplay=1'); |
| 183 | } |
| 184 | else { |
| 185 | vidSrc += '&autoplay=1'; |
| 186 | } |
| 187 | iframe[0].src = vidSrc; |
| 188 | playerWrap.scrollIntoView(); |
| 189 | } |
| 190 | } |
| 191 | }); |
| 192 | |
| 193 | |
| 194 | var currentPage = 1; |
| 195 | |
| 196 | let nearestEpContentId = playerWrap.querySelector('.ep-youtube__content__block').getAttribute('data-unique-id'); |
| 197 | |
| 198 | delegate(playerWrap, "click", ".ep-next, .ep-prev", function (event) { |
| 199 | const totalPages = event.target.closest('.ose-youtube').getAttribute('data-total-pages'); |
| 200 | const closestClass = event.target.closest('.ose-youtube').classList; |
| 201 | |
| 202 | const activePage = document.querySelector(`.${closestClass[1]} .embedpress-page-active`); |
| 203 | if (activePage) { |
| 204 | document.querySelector(`.${closestClass[1]} .embedpress-page-active`).classList.remove('embedpress-page-active'); |
| 205 | } |
| 206 | |
| 207 | |
| 208 | |
| 209 | var isNext = this.classList.contains("ep-next"); |
| 210 | |
| 211 | if (isNext) { |
| 212 | currentPage++; |
| 213 | } else { |
| 214 | currentPage--; |
| 215 | } |
| 216 | |
| 217 | var data = { |
| 218 | action: "youtube_rest_api", |
| 219 | playlistid: this.getAttribute("data-playlistid"), |
| 220 | pagetoken: this.getAttribute("data-pagetoken"), |
| 221 | pagesize: this.getAttribute("data-pagesize"), |
| 222 | currentpage: currentPage |
| 223 | }; |
| 224 | |
| 225 | var formBody = []; |
| 226 | for (var property in data) { |
| 227 | var encodedKey = encodeURIComponent(property); |
| 228 | var encodedValue = encodeURIComponent(data[property]); |
| 229 | formBody.push(encodedKey + "=" + encodedValue); |
| 230 | } |
| 231 | formBody = formBody.join("&"); |
| 232 | |
| 233 | var galleryWrapper = playerWrap.getElementsByClassName( |
| 234 | "ep-youtube__content__block" |
| 235 | ); |
| 236 | |
| 237 | playerWrap.setAttribute('data-current-page', currentPage); |
| 238 | |
| 239 | |
| 240 | let x = 1; |
| 241 | |
| 242 | sendRequest("/wp-admin/admin-ajax.php", formBody, function (request) { |
| 243 | if (galleryWrapper && galleryWrapper[0] && request.responseText) { |
| 244 | var response = JSON.parse(request.responseText); |
| 245 | galleryWrapper[0].outerHTML = response.html; |
| 246 | |
| 247 | var currentPageNode = |
| 248 | galleryWrapper[0].getElementsByClassName("current-page"); |
| 249 | if (currentPageNode && currentPageNode[0]) { |
| 250 | currentPageNode[0].textContent = currentPage; |
| 251 | |
| 252 | } |
| 253 | } |
| 254 | }); |
| 255 | |
| 256 | const intervalID = setInterval(() => { |
| 257 | x++ |
| 258 | |
| 259 | if (playerWrap.querySelector('.ep-youtube__content__block')) { |
| 260 | const newNearestEpContentId = playerWrap |
| 261 | .querySelector('.ep-youtube__content__block') |
| 262 | .getAttribute('data-unique-id'); |
| 263 | |
| 264 | if (newNearestEpContentId !== nearestEpContentId && playerWrap.querySelector(`[data-page="${currentPage}"]`)) { |
| 265 | playerWrap.querySelector(`[data-page="${currentPage}"]`).classList.add('embedpress-page-active'); |
| 266 | nearestEpContentId = newNearestEpContentId; |
| 267 | clearInterval(intervalID); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | if (x > 100) { |
| 272 | clearInterval(intervalID); |
| 273 | } |
| 274 | }, 100); |
| 275 | |
| 276 | }); |
| 277 | } |
| 278 | })(); |
| 279 |