Skip to content

Commit

Permalink
Update library name from ouiBounce to ouibounce. Close #23
Browse files Browse the repository at this point in the history
  • Loading branch information
carlsednaoui committed May 2, 2014
1 parent 5ab6816 commit feb1cc0
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ You can also get OuiBounce from [cdnjs.com](http://cdnjs.com/libraries/ouibounce
## Usage

1. Create a hidden modal
1. Select the modal with vanilla JavaScript (or jQuery) and call `ouiBounce`
1. Select the modal with vanilla JavaScript (or jQuery) and call `ouibounce`
1. Optional: Save the function's return value to use the public API, allowing you to `fire` or `disable` OuiBounce on demand

_Example:_
```js
ouiBounce(document.getElementById('ouibounce-modal'));
ouibounce(document.getElementById('ouibounce-modal'));
```

_Example with jQuery:_
```js
ouiBounce($('#ouibounce-modal')[0]);
ouibounce($('#ouibounce-modal')[0]);
```

_Example using the public api:_
```js
var modal = ouiBounce(document.getElementById('ouibounce-modal'));
var modal = ouibounce(document.getElementById('ouibounce-modal'));
modal.fire()
```

Expand All @@ -70,7 +70,7 @@ Define how far the mouse has to be from the window breakpoint. The higher value,

_Example:_
```js
ouiBounce(document.getElementById('ouibounce-modal'), { sensitivity: 40 });
ouibounce(document.getElementById('ouibounce-modal'), { sensitivity: 40 });
```

##### Aggressive mode
Expand All @@ -80,51 +80,51 @@ There are cases, however, when you may want to be more aggressive (as in, you wa

_Example:_
```js
ouiBounce(document.getElementById('ouibounce-modal'), { aggressive: true });
ouibounce(document.getElementById('ouibounce-modal'), { aggressive: true });
```

##### Set a min time before OuiBounce fires
By default, OuiBounce won't fire in the first second to prevent false positives, as it's unlikely the user will be able to exit the page within less than a second. If you want to change the amount of time that firing is surpressed for, you can pass in a number of milliseconds to `timer`.

_Example:_
```js
ouiBounce(document.getElementById('ouibounce-modal'), { timer: 0 });
ouibounce(document.getElementById('ouibounce-modal'), { timer: 0 });
```

##### Callback
You can add a callback, which is a function that will run once OuiBounce has been triggered, by using the `callback` option.

_Example:_
```js
ouiBounce(document.getElementById('ouibounce-modal'), { callback: function() { console.log('OuiBounce fired!'); } });
ouibounce(document.getElementById('ouibounce-modal'), { callback: function() { console.log('OuiBounce fired!'); } });
```

##### Cookie expiration
Ouibounce sets a cookie by default to prevent the modal from appearing more than once per user. You can add a cookie expiration (in days) using `cookieExpire` to adjust the time period before the modal will appear again for a user. By default, the cookie will expire at the end of the session, which for most browsers is when the browser is closed entirely.

_Example:_
```js
ouiBounce(document.getElementById('ouibounce-modal'), { cookieExpire: 10 });
ouibounce(document.getElementById('ouibounce-modal'), { cookieExpire: 10 });
```

__Multiple options:__ The options are just a javascript object, so if you want, you can also combine multiple options.

_Example:_
```js
ouiBounce(document.getElementById('ouibounce-modal'), {
ouibounce(document.getElementById('ouibounce-modal'), {
aggressive: true,
timer: 0,
callback: function() { console.log('ouiBounce fired!'); }
callback: function() { console.log('ouibounce fired!'); }
});
```

### OuiBounce API

If you save the object returned by the `ouiBounce` function, you get access to a small public API. Use this API to `fire` or `disable` OuiBounce on demand.
If you save the object returned by the `ouibounce` function, you get access to a small public API. Use this API to `fire` or `disable` OuiBounce on demand.

_Example:_
```js
var modal = ouiBounce(document.getElementById('ouibounce-modal'));
var modal = ouibounce(document.getElementById('ouibounce-modal'));
modal.fire(); // fire the ouibounce event
modal.disable() // disable ouibounce, it will not fire on page exit
```
Expand Down
4 changes: 2 additions & 2 deletions build/ouibounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
} else if (typeof exports === 'object') {
module.exports = factory(require,exports,module);
} else {
root.ouiBounce = factory();
root.ouibounce = factory();
}
}(this, function(require,exports,module) {

return function ouiBounce(el, config) {
return function ouibounce(el, config) {
var config = config || {},
aggressive = config.aggressive || false,
sensitivity = setDefault(config.sensitivity, 20),
Expand Down
2 changes: 1 addition & 1 deletion build/ouibounce.min.js

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

4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ var gulp = require('gulp'),
gulp.task('build', function() {

gulp.src('source/ouibounce.js')
.pipe(umd_wrap({ namespace: 'ouiBounce' }))
.pipe(umd_wrap({ namespace: 'ouibounce' }))
.pipe(gulp.dest('build'));

gulp.src('source/ouibounce.js')
.pipe(umd_wrap({ namespace: 'ouiBounce' }))
.pipe(umd_wrap({ namespace: 'ouibounce' }))
.pipe(uglify())
.pipe(rename('ouibounce.min.js'))
.pipe(gulp.dest('build'));
Expand Down
2 changes: 1 addition & 1 deletion source/ouibounce.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function ouiBounce(el, config) {
function ouibounce(el, config) {
var config = config || {},
aggressive = config.aggressive || false,
sensitivity = setDefault(config.sensitivity, 20),
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/aggressive.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

<script>
// initialize a counter, to test aggressive mode
window.ouiBounceCounter = 0;
window.ouibounceCounter = 0;

// if the cookie was already dropped, set counter to 1
if (window.document.cookie === 'viewedOuibounceModal=true') window.ouiBounceCounter = 1;
if (window.document.cookie === 'viewedOuibounceModal=true') window.ouibounceCounter = 1;

ouiBounce(document.getElementById('ouibounce-modal'), {
callback: function() { window.ouiBounceCounter++; },
ouibounce(document.getElementById('ouibounce-modal'), {
callback: function() { window.ouibounceCounter++; },
aggressive: true
});
</script>
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

<script>
// initialize a counter, to test aggressive mode
window.ouiBounceCounter = 0;
window.ouibounceCounter = 0;

ouiBounce(document.getElementById('ouibounce-modal'), {
callback: function() { window.ouiBounceCounter++; }
ouibounce(document.getElementById('ouibounce-modal'), {
callback: function() { window.ouibounceCounter++; }
});
</script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ <h3>This is a OuiBounce modal!</h3>

// if you want to use the 'fire' or 'disable' fn,
// you need to save OuiBounce to an object
var _ouiBounce = ouiBounce(document.getElementById('ouibounce-modal'), {
var _ouibounce = ouibounce(document.getElementById('ouibounce-modal'), {
aggressive: true,
timer: 0,
callback: function() { console.log('ouiBounce fired!'); }
callback: function() { console.log('ouibounce fired!'); }
});

$('body').on('click', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/ouibounce.min.css

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

16 changes: 8 additions & 8 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var should = require('should'),
Zombie = require('zombie'),
path = require('path');

var browser = new Zombie();
var browser = new Zombie();

describe('Performs basic OuiBounce functionality', function() {

Expand All @@ -11,7 +11,7 @@ describe('Performs basic OuiBounce functionality', function() {
});

it('should be present', function() {
should(this.window.ouiBounce).be.type('function');
should(this.window.ouibounce).be.type('function');
});

it('should fire and drop cookie', function(done) {
Expand All @@ -20,14 +20,14 @@ describe('Performs basic OuiBounce functionality', function() {

// ensure cookies are blank
should(_this.window.document.cookie).be.empty;
should(_this.window.ouiBounceCounter).equal(0);
should(_this.window.ouibounceCounter).equal(0);

// fire OuiBounce, ensure OuiBouce cookie was dropped
browser
.fire('html', 'mouseout')
.then(function() {
should(_this.window.document.cookie).eql('viewedOuibounceModal=true');
should(_this.window.ouiBounceCounter).equal(1);
should(_this.window.ouibounceCounter).equal(1);
})
.then(done);
});
Expand All @@ -37,13 +37,13 @@ describe('Performs basic OuiBounce functionality', function() {
_this = this;

// ensure ouiBouce already fired
should(_this.window.ouiBounceCounter).equal(1);
should(_this.window.ouibounceCounter).equal(1);

// fire OuiBounce, ensure OuiBouce does NOT go off again
browser
.fire('html', 'mouseout')
.then(function() {
should(_this.window.ouiBounceCounter).equal(1);
should(_this.window.ouibounceCounter).equal(1);
})
.then(done);
});
Expand All @@ -61,13 +61,13 @@ describe('Performs basic OuiBounce functionality', function() {
_this = this;

// ensure ouiBouce already fired
should(_this.window.ouiBounceCounter).equal(1);
should(_this.window.ouibounceCounter).equal(1);

// fire OuiBounce, ensure OuiBouce does NOT go off again
browser
.fire('html', 'mouseout')
.then(function() {
should(_this.window.ouiBounceCounter).equal(2);
should(_this.window.ouibounceCounter).equal(2);
})
.then(done);
});
Expand Down

0 comments on commit feb1cc0

Please sign in to comment.