Skip to content

Instantly share code, notes, and snippets.

/*
Remove dynamic IDs from elements in Optimizely's visual editor
Note: The optimizely_evaluate comments ensure the IDs aren't removed on the live site and should not be omitted.
*/
/* _optimizely_evaluate=editor_only */
$("[id*='string']").each(function() {
$(this).removeAttr('id');
}
});
/*
Remove hyperlinks from text using jQuery
The contents() function includes child text nodes.
https://api.jquery.com/contents/
*/
$("elem").contents().unwrap();
@bwll
bwll / gist:d9c5362e69a7a6b914c0
Last active December 27, 2015 06:14
Firing in Optimizely page view goal in AngularJS
/*
Send an Optimizely page view tracking call in AngularJS
*/
window.scope = window.angular.element(document).find('body').scope();
window.scope.$on('$locationChangeSuccess', function(event, next, current) {
window['optimizely'] = window['optimizely'] || [];
window.optimizely.push(['trackEvent', next]);
});
// Prevent submission unless checked
$("form").bind('submit',function(event) {
if(!$("input[type=checkbox]").is(":checked")) {
event.preventDefault();
// Do something
}
});
// jshint esversion: 6
'use strict';
const _ = require('lodash');
const request = require('request-promise');
const artist = process.argv[2];
let options = {
@bwll
bwll / counter.jsx
Created November 5, 2016 22:52
Counter Component in React
var Counter = React.createClass({
getInitialState: function() {
return {
count: 0
}
},
incrementCount: function() {
this.setState({
count: this.state.count + 1
})
/*
* Fetch API
* https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
*/
const uri = 'https://api.spotify.com/v1/albums/21KIagsx1ZvYcv0sVkEAWv/tracks';
const req = new Request(uri, {
method: 'get',
headers: new Headers({
@bwll
bwll / DemandbaseFirstPageLoad.js
Created December 10, 2016 00:10
Callback function for activating a Page in Optimizely X when Demandbase object has loaded
function callbackFn(activate, options) {
// Interval in ms for polling Demandbase visitor data
var POLL_INTERVAL = 50;
// Max number of poll attempts
var MAX_POLL_COUNT = 5;
var pollCount = 0;
function poll() {
pollCount++;
/*
* https://developer.mozilla.org/en-US/Add-ons/Code_snippets/QuerySelector
*/
function $ (selector, el) {
if (!el) {el = document;}
return el.querySelector(selector);
}
function $$ (selector, el) {
if (!el) {el = document;}
window.optimizely.get('behavior')
.query({"version": "0.2", "filter": [{
"field": ["type"],
"value": "pageview"
}]
}).length