-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 14 commits
33e48f0
327f21b
79c0cfb
5376e6f
e8b4c40
4760fdf
84e90a5
4bc3e0f
6cb8dfe
23d151e
8cc6ab6
897ae33
1b060b8
d95e7bc
419128f
03f114e
a9127d3
83c0833
3938c81
a51f83e
383d295
e2f4c66
379f0af
9dc885c
93454fd
2ae1cb9
088f4ee
5a6e78b
5674bcd
50ace19
2e30380
c72d3dc
5b8c183
9683f6a
17a8f0d
412d6bc
0522ea9
369f17f
91aa867
ff4cd6f
6c4a383
1725fb9
d209950
09b07ea
1295b0e
eab4133
5b46c7e
55c1d77
7766368
da83586
3593ab1
d969836
b1bc875
05bdb24
eafad14
72b7657
9ba64cb
8fb5dce
86a23a8
4eaeffc
d7090d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
build/* | ||
!build/subscribe-email.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
||
**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`). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
## 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should also trigger on the instantiated object. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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:
... than:
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. |
There was a problem hiding this comment.
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: