Skip to content

Instantly share code, notes, and snippets.

@hijonathan
hijonathan / mixin.coffee
Last active August 29, 2015 13:56
Auto-update your Backbone Firebase models with server timestamps.
updateTimestamps = _.debounce (model) ->
attrs =
updatedAt: Firebase.ServerValue.TIMESTAMP
updatedBy: "SOME_USER"
model.set attrs, {silent: true}
model._updateModel? model
, 400
# It's a good idea to keep this in a mixin:
$.event.special.textchange =
setup: ->
$el = $ @
timer = null
$el.data 'lastValue', getElValue(@)
handler = (event) =>
current = getElValue(@)
lastValue = $el.data 'lastValue'
@hijonathan
hijonathan / intercomAjax.coffee
Last active August 29, 2015 13:57
A (hastily) deconstructed view of Intercom's custom AJAX main call.
JSONPEnabled = true
ajax = (options) ->
if typeof options.url is "undefined"
return
options = $.extend({}, options, defaultAjaxOptions)
# Default to XHR.
type = "XHR"
requirejs.config({
paths: {
appcues: '//d2dubfq97s02eu.cloudfront.net/appcues.min',
jquery: '//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min'
},
shims: {
appcues: {
deps: ['jquery'] // You can explicitly define jQuery as a dependency.
}
}
@hijonathan
hijonathan / index.html
Created April 4, 2014 17:45
Using ouibounce with Appcues.
<!-- Create an empty, invisible element to pass to ouibounce. -->
<div id='ouibounce-modal' style='visibility: hidden'></div>
<script>
ouiBounce(document.getElementById('ouibounce-modal'), {
callback: function() {
// Force an Appcues flow to be shown.
Appcues.show('YOUR_FLOW_ID');
}
});
// Copyright 2012 Google Inc. All Rights Reserved.
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@hijonathan
hijonathan / host.js
Last active August 29, 2015 14:04
Super simple xdomain example.
var handleResponse = function(resp) {
// This is the response that target.html ferries back to us.
}
// Pretty simple. Basically, in this script we create an iframe of target.html.
var iframe = document.createElement('iframe');
iframe.src = 'http://somedomain.com/target.html';
iframe.onload = function() {
iframe.addEventListener("message", handleResponse);
}
@hijonathan
hijonathan / config.js
Last active August 29, 2015 14:04
Using AppcuesIdentity config object.
// Create a special global variable that the Appcues script will look for upon load.
// Admittedly, this should probably be called "AppcuesConfig".
window.AppcuesIdentity = window.AppcuesIdentity || {
appcuesId: 'foo',
userId: 1234,
userEmail: 'peep@example.com'
};
// Asynchronously load Appcues embed script.
asyncLoadAppcues().then(function() {
@hijonathan
hijonathan / ajaxNavigate.js
Created August 12, 2014 21:40
Adding pushState with Appcues.
// Example click handler that uses pushState and Appcues.
$('.tab-navigation').on('click', 'a[href]', function(e) {
if (window.history && window.history.pushState) {
// Update the URL without reloading the page.
window.history.pushState({}, document.title, e.currentTarget.getAttribute('href'));
// Re-check Appcues against this new URL.
Appcues.check();
}
@hijonathan
hijonathan / snippet.js
Created August 29, 2014 01:24
Appcues + VWO integration.
var _vis_opt_queue = window._vis_opt_queue || [], _vis_counter = 0;
_vis_opt_queue.push(function() {
try {
if(!_vis_counter) {
var _vis_data = {},_vis_combination,_vis_id,_vis_l=0;
for(;_vis_l<_vwo_exp_ids.length;_vis_l++) {
_vis_id = _vwo_exp_ids[_vis_l];
if(_vwo_exp[_vis_id].ready) {
_vis_combination = _vis_opt_readCookie('_vis_opt_exp_'+_vis_id+'_combi');
if(typeof(_vwo_exp[_vis_id].combination_chosen) != "undefined")