Skip to content

Instantly share code, notes, and snippets.

View nleush's full-sized avatar

Nazar Leush nleush

  • http://itteco.com
View GitHub Profile
@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 / 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");
// Include Iframely embed.js in your page using preferred method. E.g.:
// <script src="//cdn.iframe.ly/embed.js?api_key=[your key here]"></script>
// Add following methods to your component.
componentDidMount: function() {
// Builds widget after embed code rendered.
window.iframely && iframely.load();
},
<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 / 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;
}
@nleush
nleush / server-part.js
Created May 10, 2012 15:50
Node.JS + MongoDB: automatic anonymous user creation
// This function implements anonymous creation logic.
function loadOrCreateAnonymousProfile(req, res, next) {
var sess = req.session,
auth = sess && sess.auth;
if (!auth || !auth.userId) {
dbCounter('anonymousUsers', function(err, counter) {
if (err) {
console.log('Error getting anonymous users counter', err);
next();