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 14 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build/*
!build/subscribe-email.js
62 changes: 34 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,56 @@ 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 `/build/subscribe-email.js` into your project's scripts folder.
Copy link

Choose a reason for hiding this comment

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

I'd roll these 3 points up into a quick section that:

  • Links to the GitHub Releases page to download the latest release (we can attach the build files as the release binaries in our release process)
  • Links to the package pages on npm and Bower, let's defer to them for install instructions.
  • Complete code example showing the script tag, markup element, and instantiation. We can leave it up to the developer to know how they use this within a modular setup, etc.


**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.js">` into your page, pointing the `src` attribute to wherever you saved the file.

Alternatively, you can require the module with [Browserify](http://browserify.org/), [RequireJS](http://requirejs.org/) or one of many other JavaScript module loaders.

# 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 `<form>` element wherever you want it on the page. This will serve as a placeholder.

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

2) Create a new `SubscribeEmail` instance somewhere in the page's JavaScript. The required parameters are `element`, which is a DOM element, jQuery element, or selector string to refer to the placeholder element, `service` which is the name of mailing list platform you are using, and `key` which is the API key for that service.

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;
```
new SubscribeEmail({
element: subscribe-form
element: '#subscribe-form',
service: 'universe',
key: 'your-api-key-here'
});
```

## 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`.
- `key`: **(Required)** A string of the API key for your mailing list platform.
- `submitText`: A string to be used on the form's submit button. Defaults to "Subscribe".
- `overrideTemplate`: Set this to true to override the markup that is automatically generated by the plugin. See "Customizing the Template" below (defaults to `false`).
- `responseElement`: A selector string for the element you want to display response (validation, errors, confirmation) messages from your platform's API (defaults to `'.subscribe-email__response'`).
- `async`: Whether the form with be submitted asynchronously (defaults to `true`).
Copy link

Choose a reason for hiding this comment

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

Would be good to clean the formatting up here a bit to let the descriptions breathe better, see:

https://github.com/tschaub/gulp-newer#api
https://github.com/desandro/imagesloaded#events


## 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.
Out of the box, the Subscribe Email module will generate BEM markup with the namespace `subscribe-email` that contains all of the elements your form needs. If you want to customize the markup, set `overrideTemplate: true` when you initialize the module to use the markup from the target element instead. This gives you full control over the markup, but you'll have to make sure that your form contains all of the required fields.

## 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;
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 on the form element;
Copy link

Choose a reason for hiding this comment

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

These should also trigger on the instantiated object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could do this using something like EventEmitter https://github.com/Wolfy87/EventEmitter

What's the use case for doing that? If this is only running in the browser aren't the DOM events enough? Why add another dependency?

Copy link

Choose a reason for hiding this comment

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

Browserify actually comes with an emitter:

https://github.com/substack/node-browserify#compatibility
https://www.npmjs.org/package/events-browserify
http://nodejs.org/api/events.html#events_class_events_eventemitter

The problem with doing it on the DOM element is that it's going to ultimately lead to some duplication of the selector. It's just much cleaner to listen to the instances. I rather use:

subscribe.on('subscriptionSuccess', callback);

... than:

document.querySelector('.subscribe-email').on('subscriptionSuccess', callback);

Course jQuery or a simple alias can get that on more equal footing, but it's even longer still! Also for something like an API response this is more appropriate than a DOM event, which are otherwise all about handling user interactions and user-facing browser features.


`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.
- `subscriptionMessage`: Fires whenever the mailing list provider returns a response (both success and failure).
- `subscriptionError`: This event will fire if the mailing list provider returns an error. 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.
Loading