Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Development #1

Merged
merged 61 commits into from
Nov 13, 2014
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
33e48f0
[#MmLRZ2E2] [#MmLRZ2E2] [#MmLRZ2E2] Make README less opinionated, add…
localjo Sep 4, 2014
327f21b
[#MmLRZ2E2] Add templates and render into demo, add gulp
localjo Sep 5, 2014
79c0cfb
[#MmLRZ2E2] Add Universe Support
localjo Sep 9, 2014
5376e6f
[#MmLRZ2E2] Add Messaging and Events
localjo Sep 9, 2014
e8b4c40
[#MmLRZ2E2] Add option to override the template
localjo Sep 10, 2014
4760fdf
[#MmLRZ2E2] Add SendGrid Support
localjo Sep 10, 2014
84e90a5
[#MmLRZ2E2] refactor as node module
localjo Sep 12, 2014
4bc3e0f
[#MmLRZ2E2] package as UMD
localjo Sep 12, 2014
6cb8dfe
[#MmLRZ2E2] add derequire
localjo Sep 12, 2014
23d151e
[#MmLRZ2E2] move handlebars to dependencies instead of dev
localjo Sep 12, 2014
8cc6ab6
[#MmLRZ2E2] add default options and make template BEM
localjo Sep 15, 2014
897ae33
[#MmLRZ2E2] include instanceof check
localjo Sep 15, 2014
1b060b8
[#MmLRZ2E2] move hbsfy transform to gulp
localjo Sep 15, 2014
d95e7bc
[#MmLRZ2E2] Add events API, clean up docs
localjo Sep 16, 2014
419128f
[#MmLRZ2E2] update readme and simplify some things
localjo Sep 17, 2014
03f114e
[#MmLRZ2E2] Add tests
localjo Sep 17, 2014
a9127d3
[#MmLRZ2E2] Bind events to object instance
localjo Sep 17, 2014
83c0833
[#MmLRZ2E2] Update test configuration
localjo Sep 17, 2014
3938c81
[#MmLRZ2E2] add mailchimp support, jquery support, and events
localjo Sep 19, 2014
a51f83e
[#MmLRZ2E2] add IE9 fallbacks for all services
localjo Sep 22, 2014
383d295
[#MmLRZ2E2] Add Automated Mocha Tests
localjo Sep 23, 2014
e2f4c66
[#MmLRZ2E2] Add mocha task to gulp and make tests more DRY
localjo Sep 24, 2014
379f0af
[#MmLRZ2E2] Add tests for all supported browsers
localjo Sep 25, 2014
9dc885c
[#MmLRZ2E2] Add browserstack tunnel to gulp tasks
localjo Sep 25, 2014
93454fd
[#MmLRZ2E2] fire event on xhr failure
localjo Oct 3, 2014
2ae1cb9
[#MmLRZ2E2] use production api instead of staging
localjo Oct 3, 2014
088f4ee
[#MmLRZ2E2] fix JSONP in IE9, other cleanup
localjo Oct 7, 2014
5a6e78b
[#MmLRZ2E2] return success for JSONP requests
localjo Oct 7, 2014
5674bcd
[#MmLRZ2E2] add check for blank submission
localjo Oct 8, 2014
50ace19
[#MmLRZ2E2] change entry point to unbuilt src
localjo Oct 9, 2014
2e30380
[#MmLRZ2E2] ignore built version
localjo Oct 10, 2014
c72d3dc
[#MmLRZ2E2] remove console log
localjo Oct 13, 2014
5b8c183
[#MmLRZ2E2] remove testling badges
localjo Oct 15, 2014
9683f6a
[#MmLRZ2E2] add helpful error message for empty form
localjo Oct 15, 2014
17a8f0d
[#MmLRZ2E2] add template option to override template
localjo Oct 17, 2014
412d6bc
[#MmLRZ2E2] simplify hbsfy require
localjo Oct 17, 2014
0522ea9
[#MmLRZ2E2] add repo field, remove extra handlebars dep
localjo Oct 17, 2014
369f17f
[#MmLRZ2E2] add tests for template option, rm overrideTemplate
localjo Oct 17, 2014
91aa867
[#MmLRZ2E2] update default template markup
localjo Oct 17, 2014
ff4cd6f
[#MmLRZ2E2] remove responseElement from test
localjo Oct 17, 2014
6c4a383
[#MmLRZ2E2] switch to alerter module for messaging
localjo Oct 20, 2014
1725fb9
[#MmLRZ2E2] clear up private method definitions
localjo Oct 20, 2014
d209950
[#MmLRZ2E2] add in page mocha tests
localjo Oct 21, 2014
09b07ea
[#MmLRZ2E2] improve testing workflow and write pending tests
localjo Oct 22, 2014
1295b0e
[#MmLRZ2E2] add browser tests
localjo Oct 22, 2014
eab4133
[#MmLRZ2E2] add sinon fake server for universe and sendgrid
localjo Oct 23, 2014
5b46c7e
[#MmLRZ2E2] mock JSONP responses and more
localjo Oct 24, 2014
55c1d77
[#MmLRZ2E2] fix sinon XDomainRequest, clean up CORS request
localjo Oct 27, 2014
7766368
[#MmLRZ2E2] remove console logs
localjo Oct 27, 2014
da83586
[#MmLRZ2E2] test iPhone 6 instead of 5
localjo Oct 27, 2014
3593ab1
[#MmLRZ2E2] add doctype to mocha test page for ie9
localjo Oct 28, 2014
d969836
[#MmLRZ2E2] add event tests
localjo Oct 29, 2014
b1bc875
[#MmLRZ2E2] update readme
localjo Oct 29, 2014
05bdb24
[#MmLRZ2E2] replace placeholder with template
localjo Oct 30, 2014
eafad14
[#MmLRZ2E2] add friendlier message for mocha test errors
localjo Oct 30, 2014
72b7657
[#MmLRZ2E2] address review feedback
localjo Nov 12, 2014
9ba64cb
[#MmLRZ2E2] address review feedback
localjo Nov 12, 2014
8fb5dce
Merge branch 'MmLRZ2E2-development' of https://github.com/blocks/subs…
localjo Nov 12, 2014
86a23a8
[#MmLRZ2E2] change api urls to https
localjo Nov 12, 2014
4eaeffc
[#MmLRZ2E2] move hbsfy to package.json instead of gulp task
localjo Nov 13, 2014
d7090d9
[#MmLRZ2E2] update metadata
localjo Nov 13, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build
54 changes: 27 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,50 @@ Subscribe Email is a UMD JavaScript module for rendering a mailing list sign up

It allows developers to quickly include an email collection form on a page without being concerned with the implementation details of a specific mailing list platform. We're currently aiming to support mailing lists on SendGrid, MailChimp and Universe.

# Including the Module in Your Project
You can include the module any way that fits with your workflow;
# Getting Started

**If you use bower (recommended):**
`bower install subscribe-email --save`
## 1) Get the Module
If you're doing things manually, you can download the ZIP and extract the contents of the `/dist` directory into your project's assets folder.

**If you use npm:**
`npm install subscribe-email --save`
If you're using a package manager like [npm](https://www.npmjs.org/) or [Bower](http://bower.io/), you can install the module to your devDependencies.

**If you're not using a package manager:**
Just copy and paste the `/dist` directory to wherever you want it in your project.
## 2) Include the Module in Your Page
If you're doing things manually, just drop `<script src="subscribe-email.min.js">` into your page, and make sure you update the `src` attribute to point to wherever you saved the module.

Alternatively, you can bundle the module along with the rest of your projects assets using a tool like [Browserify](http://browserify.org/), [Grunt](http://gruntjs.com/), [Gulp](http://gulpjs.com/), etc.

# Wiring Things Up
Once you've got the module included in your project, getting started using it is simple.
## 3) Use the Module
After you've gotten the module and included it in your page, you can start using it.

1. Include subscribe-email.js in your page. You can use your preferred script loader, concatenate it with the rest of your scripts during your build process, or just drop `<script src="subscribe-email.min.js">` into your page. Just make sure you update the path to point to wherever you've saved or included it.
2. Create an empty placeholder element for the subscription form on the page; `<div id="subscribe-form"></div>`.
1) Create an empty placeholder element where you want to include the form on the page. You can use any block-level HTML element, given that it has a unique way to select it;

## Quick Start
`<div id="subscribe-form"></div>`

Create a new `SubscribeEmail` instance somewhere in the page's JavaScript. The only parameter that's required is the `element`. You can either use the ID of the placeholder HTML element you created or pass in a jQuery object;
2) Create a new `SubscribeEmail` instance somewhere in the page's JavaScript. The only parameters that are required are `element`, which is a DOM element, jQuery element, or selector string to refer to the placeholder element and `service` which is the name of mailing list platform you are using.
```
new SubscribeEmail({
element: subscribe-form
element: '#subscribe-form',
service: 'mailchimp'
});
```

## Advanced Options
3) Profit?

There are also some advanced configuration options available.
```
new SubscribeEmail({
element: subscribe-form, //required
template: 'minimal-BEM', //defaults to 'minimal-BEM'
async: true //defaults to false
});
```
# Advanced Usage

## Options
The module can be configured with several optional parameters passed to it's constructor. Here is the full list of options:

- `element`: **(Required)** A DOM element, jQuery element, or selector string to refer to the placeholder element.
- `service`: **(Required)** The mailing list platform you are using. Available options are `mailchimp`, `sendgrid` and `universe`.
- `template`: A string of the name of the compiled handlebars template to use to render the form. Available templates are `'BEM-with-messaging'` or `'BEM-minimal'` (default). See "Customizing the Templates" below for more information.
- `async`: Whether the form with be submitted asynchronously (defaults to false).

## Customizing the Template
The Subscribe Email module comes with some compiled Handlebars templates that you can choose from. If you want to create custom HTML template(s), you can add a Handlebars template to `/src/templates` and run `gulp build` from the project directory to build the module from source and compile the template.
The Subscribe Email module comes with some compiled Handlebars templates that you can choose from. If you want to create custom HTML template(s), you can add a Handlebars template to `/src/templates` and run `gulp build` from the module's root directory to build the module from source and compile the template (note: this may require running `npm install` first to install subscribe-email's devDependencies).

## Events
Some mailing list platforms may send response messages for things like confirmation or validation errors. The default template will display these messages along-side the form, but alternatively you can easily integrate the messages into other parts of your page by listening for the following events to fire;

`subscriptionError`: This event will fire if the mailing list provider returns an error and fails to add the email address to the list. Specific details about the error will be included in a payload object when available.
`subscriptionSuccess`: This event will fire if the mailing list provider returns a confirmation that the email address has been added to the list. Specific details will be included in a payload object when available.
- `subscriptionError`: This event will fire if the mailing list provider returns an error and fails to add the email address to the list. Specific details about the error will be included in a payload object when available.
- `subscriptionSuccess`: This event will fire if the mailing list provider returns a confirmation that the email address has been added to the list. Specific details will be included in a payload object when available.
35 changes: 35 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<html>
<head>
<title>Subscribe Email Demo</title>
<script src="../build/subscribe-email.js"></script>
</head>
<body>
<p>Here's a MailChimp subscribe form!</p>
<div id="subscribe-form1">1</div>
<p>Here's a SendGrid subscribe form!</p>
<div id="subscribe-form2">2</div>
<p>Here's a Universe subscribe form!</p>
<div id="subscribe-form3">3</div>
<script>
new SubscribeEmail({
element: '#subscribe-form1',
submitText: 'Sign Up',
service: 'mailchimp'
});
</script>
<script>
new SubscribeEmail({
element: '#subscribe-form2',
submitText: 'Subscribe',
service: 'sendgrid'
});
</script>
<script>
new SubscribeEmail({
element: '#subscribe-form3',
submitText: 'Send',
service: 'universe'
});
</script>
</body>
</html>
38 changes: 38 additions & 0 deletions gulp/browserify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var browserify = require('browserify');
var bundleLogger = require('./util/bundleLogger');
var gulp = require('gulp');
var handleErrors = require('./util/handleErrors');
var source = require('vinyl-source-stream');

gulp.task('browserify', function() {
var bundler = browserify({
// Required watchify args
cache: {}, packageCache: {}, fullPaths: true,
// Specify the entry point of your app
entries: ['./src/subscribe-email.js'],
// Add file extentions to make optional in your requires
extensions: ['.hbs'],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe entries is redundant with the source call below, shouldn't need the extensions either, or is there another dependency other than hbsfy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source call below is different than gulp.src. It's actually calling vinyl-source-stream: https://www.npmjs.org/package/vinyl-source-stream

// Enable source maps!
debug: true
});

var bundle = function() {
// Log when bundling starts
bundleLogger.start();

return bundler
.bundle()
// Report compile errors
.on('error', handleErrors)
// Use vinyl-source-stream to make the
// stream gulp compatible. Specifiy the
// desired output filename here.
.pipe(source('subscribe-email.js'))
// Specify the output destination
.pipe(gulp.dest('./build/'))
// Log when bundling completes!
.on('end', bundleLogger.end);
};

return bundle();
});
21 changes: 21 additions & 0 deletions gulp/util/bundleLogger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* bundleLogger
------------
Provides gulp style logs to the bundle method in browserify.js
*/

var gutil = require('gulp-util');
var prettyHrtime = require('pretty-hrtime');
var startTime;

module.exports = {
start: function() {
startTime = process.hrtime();
gutil.log('Running', gutil.colors.green("'bundle'") + '...');
},

end: function() {
var taskTime = process.hrtime(startTime);
var prettyTime = prettyHrtime(taskTime);
gutil.log('Finished', gutil.colors.green("'bundle'"), 'in', gutil.colors.magenta(prettyTime));
}
};
15 changes: 15 additions & 0 deletions gulp/util/handleErrors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var notify = require("gulp-notify");

module.exports = function() {

var args = Array.prototype.slice.call(arguments);

// Send error to notification center with gulp-notify
notify.onError({
title: "Compile Error",
message: "<%= error.message %>"
}).apply(this, args);

// Keep gulp from hanging on this task
this.emit('end');
};
19 changes: 19 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
gulpfile.js
===========
Rather than manage one giant configuration file responsible
for creating multiple tasks, each task has been broken out into
its own file in `/gulp`. Any file in that folder gets automatically
required below.

To add a new task, simply add a new task file to the `/gulp` directory.
*/
var gulp = require('gulp');
var requireDir = require('require-dir');

// Require all tasks in gulp/tasks, including subfolders
requireDir('./gulp', { recurse: true });

// Task groups
gulp.task('default', ['build']);
gulp.task('build', ['browserify']);
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "subscribe-email",
"version": "0.0.0",
"private": true,
"main": "subscribe-email.js",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be src/subscribe-email.js right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, yep. I moved that and forgot to update package.json. I'll update it with the next commit.

"browserify": {
"transform": [
"hbsfy"
]
},
"devDependencies": {
"browserify": "^5.11.1",
"gulp": "^3.8.7",
"gulp-notify": "^1.5.1",
"gulp-util": "^3.0.1",
"handlebars": "1.3.x",
"hbsfy": "^2.1.0",
"pretty-hrtime": "^0.2.1",
"require-dir": "^0.1.0",
"vinyl-source-stream": "^0.1.1"
}
}
45 changes: 45 additions & 0 deletions src/subscribe-email.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// This JavaScript module is exported as UMD following the pattern which can be
// found here: https://github.com/umdjs/umd/blob/master/returnExports.js

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['handlebars'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('./templates/BEM-with-messaging.hbs'));
} else {
root.SubscribeEmail = factory(root.handlebars);
}
}(this, function (template) {

this.SubscribeEmail = function(options){
var placeholder = document.querySelector(options.element);
var serviceConfig = {};
switch (options.service) {
case 'mailchimp':
serviceConfig = {
formAction: 'http://mailchimp-api.com/route',
formMethod: 'POST',
emailName: 'EMAIL'
};
break;
case 'sendgrid':
serviceConfig = {
formAction: 'http://sendgrid-api.com/route',
formMethod: 'POST'
};
break;
default:
serviceConfig = {
formAction: '',
formMethod: ''
};
break;
}
//Merge the serviceConfig object into the template options
for (var attrname in serviceConfig) { options[attrname] = serviceConfig[attrname]; }

placeholder.innerHTML = template(options);
};

return this.SubscribeEmail;
}));
4 changes: 4 additions & 0 deletions src/templates/BEM-with-messaging.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<form action="{{formAction}}" method="{{formMethod}}">
<input type="email" value="" name="{{emailName}}">
<input type="submit" value="{{submitText}}" name="{{submitName}}">
</form>