Skip to content

Instantly share code, notes, and snippets.

@MaxPower15
MaxPower15 / ready-mixin.coffee
Created August 28, 2012 22:34
The "ready" pattern in coffeescript, distilled
#
# myObject = new MyObject();
# myObject.ready = readyMixin;
# myObject.asyncInit(function(){ myObject.ready(true); });
#
# myObject.ready(function() {
# console.log("I'm ready now!");
# });
#
# myObject.ready(function() {
@MaxPower15
MaxPower15 / gist:3702165
Created September 11, 2012 21:20
Code to preserve time and play/pause state when switching tabs
var lastT = 0;
var downT = 0;
var lastState = "unknown";
wistiaEmbed.bind("timechange", function(t) {
lastT = t;
});
wistiaEmbed.bind("down", function() {
@MaxPower15
MaxPower15 / gist:3750671
Created September 19, 2012 16:39
Turnstile example starting at nth video in playlist
<div id="wistia_1d35830d05" class="wistia_embed" style="width:947px;height:360px;" data-video-width="640" data-video-height="360">&nbsp;</div>
<script charset="ISO-8859-1" src="http://fast.wistia.com/static/concat/E-v1%2Cplaylist-v1%2Cplaylist-v1-bento%2CrequireEmail-v1.js"></script>
<script>
wistiaPlaylist = Wistia.playlist("1d35830d05", {
version: "v1",
theme: "bento",
videoOptions: {
autoPlay: true,
videoWidth: 640,
videoHeight: 360
@MaxPower15
MaxPower15 / gist:4019868
Last active January 27, 2016 00:27
Conditional A/B testing with Wistia's API embed
<!--
Steps to do A/B testing.
1. Pick any number of videos in your Wistia account. If they're in the same project, you can compare them in the Project View.
2. Get the hashed ID for each of them (this is the alphanumeric code after /medias/ in the URL bar).
3. Go into the Embed Builder for one of the videos, and grab an API embed code.
4. Change the id attribute in the API embed code to something legible. I renamed it to "thumbnail_test" below.
5. Add a `container` option to the embed code and specify your ID.
5. Modify the embed code to use a different hashed ID based on whatever conditions you want.
The code below chooses one hashed ID if they've come from an email (wemail is in the URL), and one of two others if not.
Valid HTML4 Transitional Doctype:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Valid HTML5 Doctype:
<!DOCTYPE html>
@MaxPower15
MaxPower15 / gist:4278527
Created December 13, 2012 18:31
Programmatically launch an existing popover on the page.
<a id="my_popover" href="http://fast.wistia.com/embed/iframe/fcf31a497a?autoPlay=true&controlsVisibleOnLoad=true&playerColor=81c2f0&popover=true&version=v1&videoHeight=360&videoWidth=640" class="wistia-popover[height=360,playerColor=81c2f0,width=640]"><img src="http://embed.wistia.com/deliveries/e45e6fd93899ef7abbbd0d1dc643e99e8d2f84d7.jpg?image_play_button=true&image_play_button_color=4991C4e0&image_crop_resized=150x84" alt="" /></a><script charset="ISO-8859-1" src="http://fast.wistia.com/static/popover-v1.js"></script>
<script>
wistiaJQuery("#my_popover").click();
</script>
@MaxPower15
MaxPower15 / gist:4333664
Last active December 9, 2015 21:58
How to asyncify Wistia API embed codes
<!-- A default Wistia embed code, plus the 'container' attribute so we can have multiples of the same video on the page. -->
<div id="wistia_4d8229898d_1" class="wistia_embed" style="width:640px;height:360px;" data-video-width="640" data-video-height="360">&nbsp;</div>
<script charset="ISO-8859-1" src="http://fast.wistia.com/static/concat/E-v1.js"></script>
<script>
wistiaEmbed1 = Wistia.embed("4d8229898d", {
version: "v1",
videoWidth: 640,
videoHeight: 360,
container: "wistia_4d8229898d_1"
});
@MaxPower15
MaxPower15 / gist:4498734
Created January 10, 2013 01:56
Pseudocode for pre-roll on playlist
wistiaPlaylist = Wistia.playlist("playlisthashedid", {
... the options generated by Wistia ...
});
var savedSection, savedVideo;
wistiaPlaylist.bind("play", function() {
savedSection = wistiaPlaylist.currentSectionIndex();
savedVideo = wistiaPlaylist.currentVideoIndex();
wistiaPlaylist.remove();
wistiaEmbed = Wistia.embed("prerollhashedid", {
... whatever options you want ...
<div id="wistia_036h4wlrgo" class="wistia_embed" style="width:500px;height:281px;" data-video-width="500" data-video-height="281">&nbsp;</div>
<script charset="ISO-8859-1" src="http://fast.wistia.net/static/concat/E-v1%2Cplaylist-v1.js"></script>
<script>
wistiaPlaylist = Wistia.playlist("036h4wlrgo", {
version: "v1",
videoOptions: {
volumeControl: true,
autoPlay: true,
videoWidth: 500,
videoHeight: 281
@MaxPower15
MaxPower15 / gist:5537604
Created May 8, 2013 01:46
jQuery line/word dimensions
(function($) {
var deNthWordize, mode, nthWordize;
nthWordize = function(el) {
var $escaper, $this, $tns, textNode, textNodes, _i, _len;
$this = $(el);
textNodes = $this.find(":not(iframe)").andSelf().contents().filter(function() {
return this.nodeType === 3;
});
for (_i = 0, _len = textNodes.length; _i < _len; _i++) {
textNode = textNodes[_i];