Skip to content

Instantly share code, notes, and snippets.

View nleush's full-sized avatar

Nazar Leush nleush

  • http://itteco.com
View GitHub Profile
# Bypass oEmbed sandbox for store links, add UTM params into the summary card
add_filter( 'pre_oembed_result', 'add_utm_params_to_barstool_store', PHP_INT_MAX, 3 );
function add_utm_params_to_barstool_store ( $result, $url, $args ) {
if ( strpos($url, 'https://store.barstoolsports.com') !== false && strpos($url, 'utm_') === false ) {
$api_key = trim( get_site_option( 'iframely_api_key' ) );
$link = $url;
$link = add_query_arg( array(
'utm_source' => 'barstoolsports',
@nleush
nleush / exec_body_scripts.js
Last active December 10, 2018 15:30
native javascript insert <script> (code or link) in DOM
function exec_body_scripts(body_el) {
function nodeName(elem, name) {
return elem.nodeName && elem.nodeName.toUpperCase() ===
name.toUpperCase();
}
function evalScript(elem) {
var data = (elem.text || elem.textContent || elem.innerHTML || "" ),
script = document.createElement("script");
<script type="text/javascript">
function loadIframelyEmbedJs() {
// Replace 'iframe.ly' with your custom CDN if available.
if (document.querySelectorAll("[data-iframely-url]").length === 0
&& document.querySelectorAll("iframe[src*='iframe.ly']").length === 0) return;
var iframely = window.iframely = window.iframely || {};
if (iframely.load) {
iframely.load();
} else {
var ifs = document.createElement('script'); ifs.type = 'text/javascript'; ifs.async = true;
@nleush
nleush / iframely-iframe-onload-event.js
Created December 11, 2017 17:42
'onload' event example for Iframely iframe
var receiveMessage = function(callback) {
function cb(e) {
var message;
try {
message = JSON.parse(e.data);
} catch (ex) {
}
callback(e, message);
@nleush
nleush / iframely-load-event.html
Created October 2, 2017 16:53
Example of using iframely.events.on('heightChanged') event with dynamic embed.js script loading.
<script>
var iframely = window.iframely = window.iframely || {};
var widgets = iframely.widgets = iframely.widgets || {};
function iframelyLoaded() {
iframely.events.on('heightChanged', function(iframe, oldHeight, newHeight) {
// your handler here, like
// adjustScroll(newHeight - oldHeight);
// iframe is a dom element, heights are numbers
@nleush
nleush / loadIframelyEmbedJs.js
Last active September 9, 2015 16:07
Load iframe.ly/embed.js dynamically
<script type="text/javascript">
function loadIframelyEmbedJs() {
var iframely = window.iframely = window.iframely || {};
var widgets = iframely.widgets = iframely.widgets || {};
if (widgets.load) {
widgets.load();
} else {
var ifs = document.createElement('script'); ifs.type = 'text/javascript'; ifs.async = true;
ifs.src = ('https:' == document.location.protocol ? 'https:' : 'http:') + '//cdn.iframe.ly/embed.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ifs, s);
@nleush
nleush / gist:ab375976eb9e6de4d849
Created June 30, 2015 14:58
Centering responsive 100% width block with width contraint.
<style>
.centering-fullwidth {
width: 100%;
}
.constraint-container {
width: 500px;
margin: auto;
}
</style>
@nleush
nleush / gist:00e9b4df2c344f4f1687
Created June 30, 2015 14:08
Centering responsive 100% width block with max-width contraint.
<style>
.centering-fullwidth {
width: 100%;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}