From d0534953b7816295cdf67fa8d7005dffaae9020b Mon Sep 17 00:00:00 2001 From: carl sednaoui Date: Mon, 20 Jan 2014 20:51:34 -0500 Subject: [PATCH] Refactor as a jQuery plugin --- deprecated/_deprecated_ouibounce.js | 68 -------- example/index.html | 31 ---- example/ouibounce.min.js | 1 - source/modal.html | 13 -- source/ouibounce.js | 256 +--------------------------- source/ouibounce.min.js | 1 - test/index.html | 24 +++ {example => test}/main.css | 6 +- 8 files changed, 35 insertions(+), 365 deletions(-) delete mode 100644 deprecated/_deprecated_ouibounce.js delete mode 100644 example/index.html delete mode 100644 example/ouibounce.min.js delete mode 100644 source/modal.html delete mode 100644 source/ouibounce.min.js create mode 100644 test/index.html rename {example => test}/main.css (54%) diff --git a/deprecated/_deprecated_ouibounce.js b/deprecated/_deprecated_ouibounce.js deleted file mode 100644 index 315264f..0000000 --- a/deprecated/_deprecated_ouibounce.js +++ /dev/null @@ -1,68 +0,0 @@ -(function ouibounce() { - var direction = null, - lastY = null, - triggered = false, - windowHeight = window.innerHeight, - lastTime = new Date().getTime(); - scrolling = false; - - //- display modal or alert message - function showModal(text) { - if (triggered === false) { - console.log(text); - alert(text); - triggered = true; - } - } - - $('html').on('mousemove', function(event) { - //- ensure mouse is going up - if (event.pageY < lastY) { - direction = 'up'; - } else { - direction = null; - } - - //- check if mouse is passing top 10px - //- relative to the current window position - //- ensure that mouse is moving upwards - if (event.pageY < (document.body.scrollTop + 10) && direction == 'up') { - showModal('passed top 10'); - } - - //- make sure user is moving mouse - //- not just scrolling - window.onscroll = function(event) { - scrolling = true; - }; - - //- check if mouse is intending to exit by calculating - //- mouse velocity and comparing it to browser size. - //- the "125" is arbitrary and provided good results locally. - var now = new Date().getTime(), - time = now - lastTime; - distance = lastY - event.pageY; - - var velocity = distance / time; - - if (direction == "up" - && velocity > (windowHeight / 125) - && scrolling === false) { - showModal('mouse is moving fast ' + velocity); - } - - //- update mouse position - //- reset scrolling - //- update lastTime - lastY = event.pageY; - scrolling = false; - lastTime = now; - }); -})(); - -// Old -// if (Math.abs(lastY - event.pageY) > 45 -// && direction == 'up' -// && scrolling === false) { -// showModal('mouse is moving fast'); -// } \ No newline at end of file diff --git a/example/index.html b/example/index.html deleted file mode 100644 index 193c2ce..0000000 --- a/example/index.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - Carl's Sandbox - - - - - - - - -

Try leaving this page

-

This is the sandbox, where we sell boxes of sand.

- - - - - - diff --git a/example/ouibounce.min.js b/example/ouibounce.min.js deleted file mode 100644 index 52eb994..0000000 --- a/example/ouibounce.min.js +++ /dev/null @@ -1 +0,0 @@ -$(document).ready(function(){(function(){$("html").on("mouseout.ouibounce",function(){function e(){$("#ouibounce-modal").modal()}return function(t){if(!(t.clientY<20))return;e();$("html").off("mouseout.ouibounce")}}())})();$("head").prepend('');+function(e){"use strict";var t=function(t,n){this.options=n;this.$element=e(t);this.$backdrop=this.isShown=null;if(this.options.remote)this.$element.load(this.options.remote)};t.DEFAULTS={backdrop:true,keyboard:true,show:true};t.prototype.toggle=function(e){return this[!this.isShown?"show":"hide"](e)};t.prototype.show=function(t){var n=this;var r=e.Event("show.bs.modal",{relatedTarget:t});this.$element.trigger(r);if(this.isShown||r.isDefaultPrevented())return;this.isShown=true;this.escape();this.$element.on("click.dismiss.modal",'[data-dismiss="modal"]',e.proxy(this.hide,this));this.backdrop(function(){var r=e.support.transition&&n.$element.hasClass("fade");if(!n.$element.parent().length){n.$element.appendTo(document.body)}n.$element.show();if(r){n.$element[0].offsetWidth}n.$element.addClass("in").attr("aria-hidden",false);n.enforceFocus();var i=e.Event("shown.bs.modal",{relatedTarget:t});r?n.$element.find(".modal-dialog").one(e.support.transition.end,function(){n.$element.focus().trigger(i)}).emulateTransitionEnd(300):n.$element.focus().trigger(i)})};t.prototype.hide=function(t){if(t)t.preventDefault();t=e.Event("hide.bs.modal");this.$element.trigger(t);if(!this.isShown||t.isDefaultPrevented())return;this.isShown=false;this.escape();e(document).off("focusin.bs.modal");this.$element.removeClass("in").attr("aria-hidden",true).off("click.dismiss.modal");e.support.transition&&this.$element.hasClass("fade")?this.$element.one(e.support.transition.end,e.proxy(this.hideModal,this)).emulateTransitionEnd(300):this.hideModal()};t.prototype.enforceFocus=function(){e(document).off("focusin.bs.modal").on("focusin.bs.modal",e.proxy(function(e){if(this.$element[0]!==e.target&&!this.$element.has(e.target).length){this.$element.focus()}},this))};t.prototype.escape=function(){if(this.isShown&&this.options.keyboard){this.$element.on("keyup.dismiss.bs.modal",e.proxy(function(e){e.which==27&&this.hide()},this))}else if(!this.isShown){this.$element.off("keyup.dismiss.bs.modal")}};t.prototype.hideModal=function(){var e=this;this.$element.hide();this.backdrop(function(){e.removeBackdrop();e.$element.trigger("hidden.bs.modal")})};t.prototype.removeBackdrop=function(){this.$backdrop&&this.$backdrop.remove();this.$backdrop=null};t.prototype.backdrop=function(t){var n=this;var r=this.$element.hasClass("fade")?"fade":"";if(this.isShown&&this.options.backdrop){var i=e.support.transition&&r;this.$backdrop=e('