Skip to content

Commit

Permalink
Merge pull request #2 from dollarshaveclub/bookmarklet
Browse files Browse the repository at this point in the history
Bookmarklet
  • Loading branch information
jakiestfu committed Dec 17, 2015
2 parents 4f91890 + 91d1b23 commit 55b3c83
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# AB Tester

An AB testing library that supports weights, callbacks, CSS based tests, persistence, and an interface.

## Developing
```bash
npm install # Install dependencies
Expand Down
12 changes: 12 additions & 0 deletions bookmarklet/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AB Tester Bookmarklet</title>
</head>
<body>
<p>Drag the link below to your bookmarks bar</p>
<a href="_BOOKMARKLET_">AB Tests</a>
</body>
</html>
12 changes: 12 additions & 0 deletions build/bookmarklet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AB Tester Bookmarklet</title>
</head>
<body>
<p>Drag the link below to your bookmarks bar</p>
<a href="javascript:(function()%7Bfunction%20callback()%7B%7Dvar%20s%3Ddocument.createElement(%22script%22)%3Bs.addEventListener%3Fs.addEventListener(%22load%22%2Ccallback%2C!1)%3As.readyState%26%26(s.onreadystatechange%3Dcallback)%2Cs.src%3D%22http%3A%2F%2Fdollarshaveclub.github.io%2Fab-tester.js%2Fbuild%2Ftest-interface.min.js%22%2Cdocument.body.appendChild(s)%3B%7D)()">AB Tests</a>
</body>
</html>
2 changes: 1 addition & 1 deletion build/test-interface.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/test.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import babelify from 'babelify';
import bookmarklet from 'bookmarklet';
import browserify from 'browserify';
import buffer from 'vinyl-buffer';
import fs from 'fs';
import gulp from 'gulp';
import rename from 'gulp-rename';
import source from 'vinyl-source-stream';
Expand All @@ -25,11 +27,24 @@ gulp.task('default', () => {
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('build'));

});

gulp.task('do-watch', () => {
gulp.watch('lib/**/*.js', ['default']);
gulp.watch('lib/**/*.js', ['default', 'bookmarklet']);
});

gulp.task("bookmarklet", cb => {
var html = fs.readFileSync('./bookmarklet/index.html', 'utf-8');
var escaped = bookmarklet.convert('', {
script: ['http://dollarshaveclub.github.io/ab-tester.js/build/test-interface.min.js']
});

fs.writeFile(
'./build/bookmarklet.html',
html.replace('_BOOKMARKLET_', escaped),
cb
);
});

gulp.task('watch', ['default', 'do-watch']);
gulp.task('watch', ['default', 'bookmarklet', 'do-watch']);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ab-tester",
"version": "0.3.0",
"version": "0.3.1",
"homepage": "https://github.com/dollarshaveclub/ab-tester.js",
"main": "./index.js",
"repository": {
Expand All @@ -14,6 +14,7 @@
},
"devDependencies": {
"babelify": "^7.2.0",
"bookmarklet": "0.0.4",
"browserify": "^12.0.1",
"chai": "3.2.0",
"gulp": "^3.9.0",
Expand Down
24 changes: 18 additions & 6 deletions vendor/storage.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
const supportsStorage = ((store) => {
if (!store) return false;
try {
store.setItem('a','a');
return true;
} catch(e) {
return false;
}
})(window.localStorage);

function Storage (type) {

function createCookie(name, value, days) {
var date, expires;
let date
let expires;

if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = `; expires=${date.toGMTString()}`;
} else {
expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
document.cookie = `${name}=${value + expires}; path=/`;
}

function readCookie(name) {
Expand Down Expand Up @@ -89,6 +101,6 @@ function Storage (type) {
};

export default {
local: window.localStorage || new Storage('local'),
session: window.sessionStorage || new Storage('session')
local: supportsStorage ? window.localStorage : new Storage('local'),
session: supportsStorage ? window.sessionStorage : new Storage('session')
};

0 comments on commit 55b3c83

Please sign in to comment.