Permalink
Browse files

Add compressed embed

  • Loading branch information...
1 parent 20ac5f2 commit 964c07b9df83d05f1404b88d3b7641d99a9fdbba @remy remy committed Jun 24, 2015
Showing with 38 additions and 41 deletions.
  1. +7 −1 Gruntfile.js
  2. +30 −40 public/js/embed.js
  3. +1 −0 public/js/embed.min.js
View
@@ -53,7 +53,8 @@ module.exports = function (grunt) {
// map: 'public/js/prod/<%= pkg.name %>.map.json', // don't version this so we overwrite
min: 'public/js/prod/<%= pkg.name %>-<%= pkg.version %>.min.js',
runner: 'public/js/prod/runner-<%= pkg.version %>.js',
- runnermin: 'public/js/prod/runner-<%= pkg.version %>.min.js'
+ runnermin: 'public/js/prod/runner-<%= pkg.version %>.min.js',
+ embed: 'public/js/embed.min.js',
};
var config = {
@@ -133,6 +134,11 @@ module.exports = function (grunt) {
src: distpaths.runner,
dest: distpaths.runnermin
},
+ embed: {
+ options: {},
+ src: distpaths.embed.replace(/min\./, ''),
+ dest: distpaths.embed,
+ },
addons: {
files: '<%= addonsRelative %>'
}
View
@@ -1,6 +1,5 @@
(function (window, document, undefined) {
'use strict';
- var jsbinEmbed = {};
var addEventListener = window.addEventListener ? 'addEventListener' : 'attachEvent';
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
@@ -33,13 +32,6 @@
}
}());
- /*!
- * verge 1.9.1+201402130803
- * https://github.com/ryanve/verge
- * MIT License 2013 Ryan Van Etten
- */
- !function (a, b, c) {"undefined" != typeof module && module.exports?module.exports = c():a[b] = c()}(jsbinEmbed, "verge", function () {function a() {return {width: k(), height: l()}}function b(a, b) {var c = {};return b = +b || 0, c.width = (c.right = a.right + b) - (c.left = a.left - b), c.height = (c.bottom = a.bottom + b) - (c.top = a.top - b), c}function c(a, c) {return a = a && !a.nodeType?a[0]:a, a && 1 === a.nodeType?b(a.getBoundingClientRect(), c):!1}function d(b) {b = null == b?a():1 === b.nodeType?c(b):b;var d = b.height, e = b.width;return d = "function" == typeof d?d.call(b):d, e = "function" == typeof e?e.call(b):e, e / d}var e = {}, f = "undefined" != typeof window && window, g = "undefined" != typeof document && document, h = g && g.documentElement, i = f.matchMedia || f.msMatchMedia, j = i?function (a) {return !!i.call(f, a).matches}:function () {return !1}, k = e.viewportW = function () {var a = h.clientWidth, b = f.innerWidth;return b > a?b:a}, l = e.viewportH = function () {var a = h.clientHeight, b = f.innerHeight;return b > a?b:a};return e.mq = j, e.matchMedia = i?function () {return i.apply(f, arguments)}:function () {return {}}, e.viewport = a, e.scrollX = function () {return f.pageXOffset || h.scrollLeft}, e.scrollY = function () {return f.pageYOffset || h.scrollTop}, e.rectangle = c, e.aspect = d, e.inX = function (a, b) {var d = c(a, b);return !!d && d.right >= 0 && d.left <= k()}, e.inY = function (a, b) {var d = c(a, b);return !!d && d.bottom >= 0 && d.top <= l()}, e.inViewport = function (a, b) {var d = c(a, b);return !!d && d.bottom >= 0 && d.right >= 0 && d.top <= l() && d.left <= k()}, e}); // jshint ignore:line
-
// exit if we already have a script in place doing this task
if (window.jsbinified !== undefined) {
return;
@@ -52,25 +44,32 @@
* domready (c) Dustin Diaz 2012 - License MIT
*/
var domready = (function domready() {
-
- var fns = [], listener
- , doc = document
- , hack = doc.documentElement.doScroll
- , domContentLoaded = 'DOMContentLoaded'
- , loaded = (hack ? /^loaded|^c/ : /^loaded|^i|^c/).test(doc.readyState)
-
-
- if (!loaded)
- doc.addEventListener(domContentLoaded, listener = function () {
- doc.removeEventListener(domContentLoaded, listener)
- loaded = 1
- while (listener = fns.shift()) listener()
- })
+ var fns = [],
+ listener,
+ doc = document,
+ hack = doc.documentElement.doScroll,
+ domContentLoaded = 'DOMContentLoaded',
+ loaded = (hack ? /^loaded|^c/ : /^loaded|^i|^c/).test(doc.readyState);
+
+
+ if (!loaded) {
+ doc.addEventListener(domContentLoaded, listener = function () {
+ doc.removeEventListener(domContentLoaded, listener);
+ loaded = 1;
+ while (listener = fns.shift()) { // jshint ignore:line
+ listener();
+ }
+ });
+ }
return function (fn) {
- loaded ? setTimeout(fn, 0) : fns.push(fn)
- }
- })()
+ if (loaded) {
+ setTimeout(fn, 0);
+ } else {
+ fns.push(fn);
+ }
+ };
+ })();
function getQuery(querystring) {
var query = {};
@@ -208,7 +207,6 @@
}
function hookMessaging(iframe) {
- console.log('fully loaded ' + iframe.src);
var onmessage = function (event) {
if (!event) { event = window.event; }
// * 1 to coerse to number, and + 2 to compensate for border
@@ -241,10 +239,6 @@
iframe.style.maxHeight = query.height;
}
- console.log('is link %s in view? %s', link, inview(link), link);
-
- console.log(viewportH());
-
// track when it comes into view and reload
if (inview(link, 100)) {
// the iframe is full view, let's render it
@@ -272,7 +266,6 @@
if (className.indexOf(' jsbin-scoop ') !== -1) {
scoop(links[i]);
} else if (className.indexOf(' jsbin-embed ') !== -1) {
- console.log('embed', links[i]);
links[i].className = links[i].className.replace(/jsbin\-embed/, '');
embed(links[i]);
}
@@ -282,28 +275,27 @@
var docElem = document && document.documentElement;
function viewportW() {
- var a = docElem['clientWidth'];
+ var a = docElem.clientWidth;
var b = window.innerWidth;
return a < b ? b : a;
- };
+ }
function viewportH() {
- var a = docElem['clientHeight'];
+ var a = docElem.clientHeight;
var b = window.innerHeight;
return a < b ? a : b;
- };
+ }
function calibrate(coords, cushion) {
var o = {};
cushion = +cushion || 0;
- o['width'] = (o['right'] = coords['right'] + cushion) - (o['left'] = coords['left'] - cushion);
- o['height'] = (o['bottom'] = coords['bottom'] + cushion) - (o['top'] = coords['top'] - cushion);
+ o.width = (o.right = coords.right + cushion) - (o.left = coords.left - cushion);
+ o.height = (o.bottom = coords.bottom + cushion) - (o.top = coords.top - cushion);
return o;
}
function inview(el, cushion) {
var r = calibrate(el.getBoundingClientRect(), cushion);
- // var bottom = (window.innerHeight || document.documentElement.clientHeight);
return !!r && r.bottom >= 0 && r.right >= 0 && r.top <= viewportH() && r.left <= viewportW();
}
@@ -327,8 +319,6 @@
// this supports early embeding - probably only applies to Google's slides.js
readLinks();
- window.verge = jsbinEmbed.verge;
-
// try to read more links once the DOM is done
domready(function () {
readLinks();
@@ -0,0 +1 @@
+!function(a,b,c){"use strict";function d(a){for(var b={},d=a.split("&"),e=d.length,f=[],g=0;e>g;g++){f=d[g].split("=",2);try{f[0]=decodeURIComponent(f[0]),f[1]=decodeURIComponent(f[1])}catch(h){}b[f[0]]===c?b[f[0]]=f[1]:b[f[0]]+=","+f[1]}return b}function e(){var a,c,d=[],e=0;for(a=b.getElementsByTagName("a"),c=a.length;c>e;e++)-1!==(" "+a[e].className).indexOf(" jsbin-")&&d.push(a[e]);return d}function f(a){for(var b=a;(b=b.previousSibling)&&"PRE"!==b.nodeName;)if(b.getElementsByTagName&&(b=b.getElementsByTagName("pre"),b.length)){b=b[0];break}return b?b:(b=a.parentNode.getElementsByTagName("pre"),b.length?b[0]:a.parentNode?f(a.parentNode):null)}function g(a){var c,d,e=a.rel;return e&&(c=b.getElementById(e.substring(1)))?d=c[u]:(c=f(a),c&&(d=c[u])),d}function h(a){var b=a.split("<").length-1,c=a.split("{").length-1,d=a.split(".").length-1;return b>c&&b>d?"html":c>b&&c>d?"css":"javascript"}function i(a){var b=g(a),c=h(b),d=a.search.substring(1);"html"===c&&-1===b.toLowerCase().indexOf("<html")&&(c="code"),-1===d.indexOf(c)?d+=","+c+"="+encodeURIComponent(b):d=d.replace(c,c+"="+encodeURIComponent(b)),a.search="?"+d}function j(b){var c=function(c){c||(c=a.event),b.style.height=1*c.data.height+2+"px"};a[s]("message",c)}function k(a){var b=a.getAttribute("data-url");a.src=b.split("&")[0],a._src=b.split("&")[0],j(a)}function l(a){var c=b.createElement("iframe"),e=a.href.replace(/edit/,"embed");c.className=a.className,c.id=a.id,c.style.border="1px solid #aaa";var f=d(a.search);c.style.width=f.width||"100%",c.style.minHeight=f.height||"300px",f.height&&(c.style.maxHeight=f.height),q(a,100)?(c.src=e.split("&")[0],c._src=e.split("&")[0],j(c)):(c.setAttribute("data-url",e),c.src="https://jsbin.com/embed-holding",w.push(c)),a.parentNode.replaceChild(c,a)}function m(){for(var a=e(),b=0,c=a.length,d="";c>b;b++)d=" "+a[b].className+" ",-1!==d.indexOf(" jsbin-scoop ")?i(a[b]):-1!==d.indexOf(" jsbin-embed ")&&(a[b].className=a[b].className.replace(/jsbin\-embed/,""),l(a[b]))}function n(){var b=v.clientWidth,c=a.innerWidth;return c>b?c:b}function o(){var b=v.clientHeight,c=a.innerHeight;return c>b?b:c}function p(a,b){var c={};return b=+b||0,c.width=(c.right=a.right+b)-(c.left=a.left-b),c.height=(c.bottom=a.bottom+b)-(c.top=a.top-b),c}function q(a,b){var c=p(a.getBoundingClientRect(),b);return!!c&&c.bottom>=0&&c.right>=0&&c.top<=o()&&c.left<=n()}function r(){var a=0,b=[];for(a=0;a<w.length;a++)q(w[a],100)&&b.unshift({iframe:w[a],i:a});for(a=0;a<b.length;a++)w.splice(b[a].i,1),k(b[a].iframe)}var s=a.addEventListener?"addEventListener":"attachEvent";if(function(){for(var b=0,c=["ms","moz","webkit","o"],d=0;d<c.length&&!a.requestAnimationFrame;++d)a.requestAnimationFrame=a[c[d]+"RequestAnimationFrame"],a.cancelAnimationFrame=a[c[d]+"CancelAnimationFrame"]||a[c[d]+"CancelRequestAnimationFrame"];a.requestAnimationFrame||(a.requestAnimationFrame=function(c){var d=(new Date).getTime(),e=Math.max(0,16-(d-b)),f=a.setTimeout(function(){c(d+e)},e);return b=d+e,f}),a.cancelAnimationFrame||(a.cancelAnimationFrame=function(a){clearTimeout(a)})}(),a.jsbinified===c){a.jsbinified=!0;var t=function(){var a,c=[],d=b,e=d.documentElement.doScroll,f="DOMContentLoaded",g=(e?/^loaded|^c/:/^loaded|^i|^c/).test(d.readyState);return g||d.addEventListener(f,a=function(){for(d.removeEventListener(f,a),g=1;a=c.shift();)a()}),function(a){g?setTimeout(a,0):c.push(a)}}(),u=b.createElement("i").innerText===c?"textContent":"innerText",v=b&&b.documentElement,w=[];m(),t(function(){function b(){w.length&&(cancelAnimationFrame(c),c=requestAnimationFrame(r))}m();var c=null;a[s]("scroll",b)})}}(this,document);

0 comments on commit 964c07b

Please sign in to comment.