diff --git a/README.md b/README.md index 0a490ce1..1530fc3b 100644 --- a/README.md +++ b/README.md @@ -302,6 +302,8 @@ $.material.options = { } ``` +For the ripples, a delegate is created using the given selector. This avoids manual call to `$.fn.ripples` when new inputs are created. If you want to apply statically ripples, set option `"ripplesDelegate": false`. + ### Arrive.js support If you need to dynamically add elements to your DOM then you may need to include [`Arrive.js`](https://github.com/uzairfarooq/arrive) before `Material.js`. This will automatically apply `material.js` to every new element added via JavaScript. diff --git a/dist/js/material.js b/dist/js/material.js index 819152e1..1803dc53 100644 --- a/dist/js/material.js +++ b/dist/js/material.js @@ -216,11 +216,28 @@ } } }) - .on("focus", ".form-control, .form-group.is-fileinput", function () { - _addFormGroupFocus(this); + .on("select2-focus", function (e) { + if (!$(e.target).is('.select2-focusser')) { + _addFormGroupFocus($(e.target)); + } }) - .on("blur", ".form-control, .form-group.is-fileinput", function () { - _removeFormGroupFocus(this); + .on("select2-opening", function (e) { + if (!$(e.target).is('.select2-focusser')) { + _addFormGroupFocus($(e.target)); + } + }) + .on("select2-blur", function (e) { + _removeFormGroupFocus($(e.target)); + }) + .on("focus", ".form-control", function (e) { + if (!$(e.target).is('.select2-focusser')) { + _addFormGroupFocus(this); + } + }) + .on("blur", ".form-control, .form-group.is-fileinput", function (e) { + if (!$(e.target).is('.select2-focusser')) { + _removeFormGroupFocus(this); + } }) // make sure empty is added back when there is a programmatic value change. // NOTE: programmatic changing of value using $.val() must trigger the change event i.e. $.val('x').trigger('change') @@ -256,7 +273,17 @@ }); }, "ripples": function (selector) { - $((selector) ? selector : this.options.withRipples).ripples(); + if (this.options.ripplesDelegate) { + // Delegate mode, lazy creation + $(document).on('mousedown touchstart', selector || this.options.withRipples, function(event) { + if(!$.data($(this), "plugin_ripples")) { + $(this).ripples({}, event); + } + }); + } else { + // Immediate and static creation + $((selector) ? selector : this.options.withRipples).ripples(); + } }, "autofill": function () { // This part of code will detect autofill when the page is loading (username and password inputs for example) diff --git a/dist/js/material.min.js b/dist/js/material.min.js index 774bf8dd..ebc964ca 100644 --- a/dist/js/material.min.js +++ b/dist/js/material.min.js @@ -1,2 +1,2 @@ -!function(a){function b(a){return"undefined"==typeof a.which?!0:"number"==typeof a.which&&a.which>0?!a.ctrlKey&&!a.metaKey&&!a.altKey&&8!=a.which&&9!=a.which&&13!=a.which&&16!=a.which&&17!=a.which&&20!=a.which&&27!=a.which:!1}function c(b){var c=a(b);c.prop("disabled")||c.closest(".form-group").addClass("is-focused")}function d(a,b){var c;return c=a.hasClass("checkbox-inline")||a.hasClass("radio-inline")?a:a.closest(".checkbox").length?a.closest(".checkbox"):a.closest(".radio"),c.toggleClass("disabled",b)}function e(b){var e=!1;(b.is(a.material.options.checkboxElements)||b.is(a.material.options.radioElements))&&(e=!0),b.closest("label").hover(function(){var b=a(this).find("input"),f=b.prop("disabled");e&&d(a(this),f),f||c(b)},function(){f(a(this).find("input"))})}function f(b){a(b).closest(".form-group").removeClass("is-focused")}a.expr[":"].notmdproc=function(b){return a(b).data("mdproc")?!1:!0},a.material={options:{validate:!0,input:!0,ripples:!0,checkbox:!0,togglebutton:!0,radio:!0,arrive:!0,autofill:!1,withRipples:[".btn:not(.btn-link)",".card-image",".navbar a:not(.withoutripple)",".dropdown-menu a",".nav-tabs a:not(.withoutripple)",".withripple",".pagination li:not(.active):not(.disabled) a:not(.withoutripple)"].join(","),inputElements:"input.form-control, textarea.form-control, select.form-control",checkboxElements:".checkbox > label > input[type=checkbox], label.checkbox-inline > input[type=checkbox]",togglebuttonElements:".togglebutton > label > input[type=checkbox]",radioElements:".radio > label > input[type=radio], label.radio-inline > input[type=radio]"},checkbox:function(b){var c=a(b?b:this.options.checkboxElements).filter(":notmdproc").data("mdproc",!0).after("");e(c)},togglebutton:function(b){var c=a(b?b:this.options.togglebuttonElements).filter(":notmdproc").data("mdproc",!0).after("");e(c)},radio:function(b){var c=a(b?b:this.options.radioElements).filter(":notmdproc").data("mdproc",!0).after("");e(c)},input:function(b){a(b?b:this.options.inputElements).filter(":notmdproc").data("mdproc",!0).each(function(){var b=a(this),c=b.closest(".form-group");0!==c.length||"hidden"===b.attr("type")||b.attr("hidden")||(b.wrap("
"),c=b.closest(".form-group")),b.attr("data-hint")&&(b.after(""+b.attr("data-hint")+"
"),b.removeAttr("data-hint"));var d={"input-lg":"form-group-lg","input-sm":"form-group-sm"};if(a.each(d,function(a,d){b.hasClass(a)&&(b.removeClass(a),c.addClass(d))}),b.hasClass("floating-label")){var e=b.attr("placeholder");b.attr("placeholder",null).removeClass("floating-label");var f=b.attr("id"),g="";f&&(g="for='"+f+"'"),c.addClass("label-floating"),b.after("")}(null===b.val()||"undefined"==b.val()||""===b.val())&&c.addClass("is-empty"),c.find("input[type=file]").length>0&&c.addClass("is-fileinput")})},attachInputEventHandlers:function(){var d=this.options.validate;a(document).on("keydown paste",".form-control",function(c){b(c)&&a(this).closest(".form-group").removeClass("is-empty")}).on("keyup change",".form-control",function(){var b=a(this),c=b.closest(".form-group"),e="undefined"==typeof b[0].checkValidity||b[0].checkValidity();""===b.val()?c.addClass("is-empty"):c.removeClass("is-empty"),d&&(e?c.removeClass("has-error"):c.addClass("has-error"))}).on("focus",".form-control, .form-group.is-fileinput",function(){c(this)}).on("blur",".form-control, .form-group.is-fileinput",function(){f(this)}).on("change",".form-group input",function(){var b=a(this);if("file"!=b.attr("type")){var c=b.closest(".form-group"),d=b.val();d?c.removeClass("is-empty"):c.addClass("is-empty")}}).on("change",".form-group.is-fileinput input[type='file']",function(){var b=a(this),c=b.closest(".form-group"),d="";a.each(this.files,function(a,b){d+=b.name+", "}),d=d.substring(0,d.length-2),d?c.removeClass("is-empty"):c.addClass("is-empty"),c.find("input.form-control[readonly]").val(d)})},ripples:function(b){a(b?b:this.options.withRipples).ripples()},autofill:function(){var b=setInterval(function(){a("input[type!=checkbox]").each(function(){var b=a(this);b.val()&&b.val()!==b.attr("value")&&b.trigger("change")})},100);setTimeout(function(){clearInterval(b)},1e4)},attachAutofillEventHandlers:function(){var b;a(document).on("focus","input",function(){var c=a(this).parents("form").find("input").not("[type=file]");b=setInterval(function(){c.each(function(){var b=a(this);b.val()!==b.attr("value")&&b.trigger("change")})},100)}).on("blur",".form-group input",function(){clearInterval(b)})},init:function(b){this.options=a.extend({},this.options,b);var c=a(document);a.fn.ripples&&this.options.ripples&&this.ripples(),this.options.input&&(this.input(),this.attachInputEventHandlers()),this.options.checkbox&&this.checkbox(),this.options.togglebutton&&this.togglebutton(),this.options.radio&&this.radio(),this.options.autofill&&(this.autofill(),this.attachAutofillEventHandlers()),document.arrive&&this.options.arrive&&(a.fn.ripples&&this.options.ripples&&c.arrive(this.options.withRipples,function(){a.material.ripples(a(this))}),this.options.input&&c.arrive(this.options.inputElements,function(){a.material.input(a(this))}),this.options.checkbox&&c.arrive(this.options.checkboxElements,function(){a.material.checkbox(a(this))}),this.options.radio&&c.arrive(this.options.radioElements,function(){a.material.radio(a(this))}),this.options.togglebutton&&c.arrive(this.options.togglebuttonElements,function(){a.material.togglebutton(a(this))}))}}}(jQuery); -//# sourceMappingURL=material.min.js.map \ No newline at end of file +!function(t){function i(t){return void 0===t.which?!0:"number"==typeof t.which&&t.which>0?!t.ctrlKey&&!t.metaKey&&!t.altKey&&8!=t.which&&9!=t.which&&13!=t.which&&16!=t.which&&17!=t.which&&20!=t.which&&27!=t.which:!1}function o(i){var o=t(i);o.prop("disabled")||o.closest(".form-group").addClass("is-focused")}function e(t,i){var o;return o=t.hasClass("checkbox-inline")||t.hasClass("radio-inline")?t:t.closest(t.closest(".checkbox").length?".checkbox":".radio"),o.toggleClass("disabled",i)}function n(i){var n=!1;(i.is(t.material.options.checkboxElements)||i.is(t.material.options.radioElements))&&(n=!0),i.closest("label").hover(function(){var i=t(this).find("input"),s=i.prop("disabled");n&&e(t(this),s),s||o(i)},function(){s(t(this).find("input"))})}function s(i){t(i).closest(".form-group").removeClass("is-focused")}t.expr[":"].notmdproc=function(i){return t(i).data("mdproc")?!1:!0},t.material={options:{validate:!0,input:!0,ripples:!0,checkbox:!0,togglebutton:!0,radio:!0,arrive:!0,autofill:!1,withRipples:".btn:not(.btn-link),.card-image,.navbar a:not(.withoutripple),.dropdown-menu a,.nav-tabs a:not(.withoutripple),.withripple,.pagination li:not(.active):not(.disabled) a:not(.withoutripple)",inputElements:"input.form-control, textarea.form-control, select.form-control",checkboxElements:".checkbox > label > input[type=checkbox], label.checkbox-inline > input[type=checkbox]",togglebuttonElements:".togglebutton > label > input[type=checkbox]",radioElements:".radio > label > input[type=radio], label.radio-inline > input[type=radio]"},checkbox:function(i){var o=t(i?i:this.options.checkboxElements).filter(":notmdproc").data("mdproc",!0).after("");n(o)},togglebutton:function(i){var o=t(i?i:this.options.togglebuttonElements).filter(":notmdproc").data("mdproc",!0).after("");n(o)},radio:function(i){var o=t(i?i:this.options.radioElements).filter(":notmdproc").data("mdproc",!0).after("");n(o)},input:function(i){t(i?i:this.options.inputElements).filter(":notmdproc").data("mdproc",!0).each(function(){var i=t(this),o=i.closest(".form-group");0!==o.length||"hidden"===i.attr("type")||i.attr("hidden")||(i.wrap(""),o=i.closest(".form-group")),i.attr("data-hint")&&(i.after(""+i.attr("data-hint")+"
"),i.removeAttr("data-hint"));var e={"input-lg":"form-group-lg","input-sm":"form-group-sm"};if(t.each(e,function(t,e){i.hasClass(t)&&(i.removeClass(t),o.addClass(e))}),i.hasClass("floating-label")){var n=i.attr("placeholder");i.attr("placeholder",null).removeClass("floating-label");var s=i.attr("id"),a="";s&&(a="for='"+s+"'"),o.addClass("label-floating"),i.after("")}(null===i.val()||"undefined"==i.val()||""===i.val())&&o.addClass("is-empty"),o.find("input[type=file]").length>0&&o.addClass("is-fileinput")})},attachInputEventHandlers:function(){var e=this.options.validate;t(document).on("keydown paste",".form-control",function(o){i(o)&&t(this).closest(".form-group").removeClass("is-empty")}).on("keyup change",".form-control",function(){var i=t(this),o=i.closest(".form-group"),n=void 0===i[0].checkValidity||i[0].checkValidity();""===i.val()?o.addClass("is-empty"):o.removeClass("is-empty"),e&&(n?o.removeClass("has-error"):o.addClass("has-error"))}).on("select2-focus",function(i){t(i.target).is(".select2-focusser")||o(t(i.target))}).on("select2-opening",function(i){t(i.target).is(".select2-focusser")||o(t(i.target))}).on("select2-blur",function(i){s(t(i.target))}).on("focus",".form-control",function(i){t(i.target).is(".select2-focusser")||o(this)}).on("blur",".form-control, .form-group.is-fileinput",function(i){t(i.target).is(".select2-focusser")||s(this)}).on("change",".form-group input",function(){var i=t(this);if("file"!=i.attr("type")){var o=i.closest(".form-group"),e=i.val();e?o.removeClass("is-empty"):o.addClass("is-empty")}}).on("change",".form-group.is-fileinput input[type='file']",function(){var i=t(this),o=i.closest(".form-group"),e="";t.each(this.files,function(t,i){e+=i.name+", "}),e=e.substring(0,e.length-2),e?o.removeClass("is-empty"):o.addClass("is-empty"),o.find("input.form-control[readonly]").val(e)})},ripples:function(i){this.options.ripplesDelegate?t(document).on("mousedown touchstart",i||this.options.withRipples,function(i){t.data(t(this),"plugin_ripples")||t(this).ripples({},i)}):t(i?i:this.options.withRipples).ripples()},autofill:function(){var i=setInterval(function(){t("input[type!=checkbox]").each(function(){var i=t(this);i.val()&&i.val()!==i.attr("value")&&i.trigger("change")})},100);setTimeout(function(){clearInterval(i)},1e4)},attachAutofillEventHandlers:function(){var i;t(document).on("focus","input",function(){var o=t(this).parents("form").find("input").not("[type=file]");i=setInterval(function(){o.each(function(){var i=t(this);i.val()!==i.attr("value")&&i.trigger("change")})},100)}).on("blur",".form-group input",function(){clearInterval(i)})},init:function(i){this.options=t.extend({},this.options,i);var o=t(document);t.fn.ripples&&this.options.ripples&&this.ripples(),this.options.input&&(this.input(),this.attachInputEventHandlers()),this.options.checkbox&&this.checkbox(),this.options.togglebutton&&this.togglebutton(),this.options.radio&&this.radio(),this.options.autofill&&(this.autofill(),this.attachAutofillEventHandlers()),document.arrive&&this.options.arrive&&(t.fn.ripples&&this.options.ripples&&o.arrive(this.options.withRipples,function(){t.material.ripples(t(this))}),this.options.input&&o.arrive(this.options.inputElements,function(){t.material.input(t(this))}),this.options.checkbox&&o.arrive(this.options.checkboxElements,function(){t.material.checkbox(t(this))}),this.options.radio&&o.arrive(this.options.radioElements,function(){t.material.radio(t(this))}),this.options.togglebutton&&o.arrive(this.options.togglebuttonElements,function(){t.material.togglebutton(t(this))}))}}}(jQuery); +//# sourceMappingURL=material.min.js.map diff --git a/dist/js/ripples.js b/dist/js/ripples.js index 82b67884..51cccf25 100644 --- a/dist/js/ripples.js +++ b/dist/js/ripples.js @@ -26,7 +26,7 @@ /** * Create the main plugin function */ - function Ripples(element, options) { + function Ripples(element, options, event) { self = this; this.element = $(element); @@ -36,17 +36,16 @@ this._defaults = defaults; this._name = ripples; - this.init(); + this.init(event); } /** * Initialize the plugin */ - Ripples.prototype.init = function() { + Ripples.prototype.init = function(event) { var $element = this.element; - - $element.on("mousedown touchstart", function(event) { + var rippleStart = function(event) { /** * Verify if the user is just touching on a device and return if so */ @@ -142,7 +141,9 @@ } }); - }); + }; + $element.on("mousedown touchstart", rippleStart); + event && rippleStart(event); }; @@ -313,10 +314,10 @@ /** * Create the jquery plugin function */ - $.fn.ripples = function(options) { + $.fn.ripples = function(options, event) { return this.each(function() { if(!$.data(this, "plugin_" + ripples)) { - $.data(this, "plugin_" + ripples, new Ripples(this, options)); + $.data(this, "plugin_" + ripples, new Ripples(this, options, event)); } }); }; diff --git a/dist/js/ripples.min.js b/dist/js/ripples.min.js index 5c01e4c1..b0c23059 100644 --- a/dist/js/ripples.min.js +++ b/dist/js/ripples.min.js @@ -1,2 +1,2 @@ -!function(a,b,c,d){"use strict";function e(b,c){g=this,this.element=a(b),this.options=a.extend({},h,c),this._defaults=h,this._name=f,this.init()}var f="ripples",g=null,h={};e.prototype.init=function(){var c=this.element;c.on("mousedown touchstart",function(d){if(!g.isTouch()||"mousedown"!==d.type){c.find(".ripple-container").length||c.append('');var e=c.children(".ripple-container"),f=g.getRelY(e,d),h=g.getRelX(e,d);if(f||h){var i=g.getRipplesColor(c),j=a("");j.addClass("ripple").css({left:h,top:f,"background-color":i}),e.append(j),function(){return b.getComputedStyle(j[0]).opacity}(),g.rippleOn(c,j),setTimeout(function(){g.rippleEnd(j)},500),c.on("mouseup mouseleave touchend",function(){j.data("mousedown","off"),"off"===j.data("animating")&&g.rippleOut(j)})}}})},e.prototype.getNewSize=function(a,b){return Math.max(a.outerWidth(),a.outerHeight())/b.outerWidth()*2.5},e.prototype.getRelX=function(a,b){var c=a.offset();return g.isTouch()?(b=b.originalEvent,1===b.touches.length?b.touches[0].pageX-c.left:!1):b.pageX-c.left},e.prototype.getRelY=function(a,b){var c=a.offset();return g.isTouch()?(b=b.originalEvent,1===b.touches.length?b.touches[0].pageY-c.top:!1):b.pageY-c.top},e.prototype.getRipplesColor=function(a){var c=a.data("ripple-color")?a.data("ripple-color"):b.getComputedStyle(a[0]).color;return c},e.prototype.hasTransitionSupport=function(){var a=c.body||c.documentElement,b=a.style,e=b.transition!==d||b.WebkitTransition!==d||b.MozTransition!==d||b.MsTransition!==d||b.OTransition!==d;return e},e.prototype.isTouch=function(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)},e.prototype.rippleEnd=function(a){a.data("animating","off"),"off"===a.data("mousedown")&&g.rippleOut(a)},e.prototype.rippleOut=function(a){a.off(),g.hasTransitionSupport()?a.addClass("ripple-out"):a.animate({opacity:0},100,function(){a.trigger("transitionend")}),a.on("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd",function(){a.remove()})},e.prototype.rippleOn=function(a,b){var c=g.getNewSize(a,b);g.hasTransitionSupport()?b.css({"-ms-transform":"scale("+c+")","-moz-transform":"scale("+c+")","-webkit-transform":"scale("+c+")",transform:"scale("+c+")"}).addClass("ripple-on").data("animating","on").data("mousedown","on"):b.animate({width:2*Math.max(a.outerWidth(),a.outerHeight()),height:2*Math.max(a.outerWidth(),a.outerHeight()),"margin-left":-1*Math.max(a.outerWidth(),a.outerHeight()),"margin-top":-1*Math.max(a.outerWidth(),a.outerHeight()),opacity:.2},500,function(){b.trigger("transitionend")})},a.fn.ripples=function(b){return this.each(function(){a.data(this,"plugin_"+f)||a.data(this,"plugin_"+f,new e(this,b))})}}(jQuery,window,document); -//# sourceMappingURL=ripples.min.js.map \ No newline at end of file +!function(t,i,o,e){"use strict";function n(i,o,e){a=this,this.element=t(i),this.options=t.extend({},r,o),this._defaults=r,this._name=s,this.init(e)}var s="ripples",a=null,r={};n.prototype.init=function(o){var e=this.element,n=function(o){if(!a.isTouch()||"mousedown"!==o.type){e.find(".ripple-container").length||e.append('');var n=e.children(".ripple-container"),s=a.getRelY(n,o),r=a.getRelX(n,o);if(s||r){var l=a.getRipplesColor(e),c=t("");c.addClass("ripple").css({left:r,top:s,"background-color":l}),n.append(c),function(){return i.getComputedStyle(c[0]).opacity}(),a.rippleOn(e,c),setTimeout(function(){a.rippleEnd(c)},500),e.on("mouseup mouseleave touchend",function(){c.data("mousedown","off"),"off"===c.data("animating")&&a.rippleOut(c)})}}};e.on("mousedown touchstart",n),o&&n(o)},n.prototype.getNewSize=function(t,i){return Math.max(t.outerWidth(),t.outerHeight())/i.outerWidth()*2.5},n.prototype.getRelX=function(t,i){var o=t.offset();return a.isTouch()?(i=i.originalEvent,1===i.touches.length?i.touches[0].pageX-o.left:!1):i.pageX-o.left},n.prototype.getRelY=function(t,i){var o=t.offset();return a.isTouch()?(i=i.originalEvent,1===i.touches.length?i.touches[0].pageY-o.top:!1):i.pageY-o.top},n.prototype.getRipplesColor=function(t){var o=t.data("ripple-color")?t.data("ripple-color"):i.getComputedStyle(t[0]).color;return o},n.prototype.hasTransitionSupport=function(){var t=o.body||o.documentElement,i=t.style,n=i.transition!==e||i.WebkitTransition!==e||i.MozTransition!==e||i.MsTransition!==e||i.OTransition!==e;return n},n.prototype.isTouch=function(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)},n.prototype.rippleEnd=function(t){t.data("animating","off"),"off"===t.data("mousedown")&&a.rippleOut(t)},n.prototype.rippleOut=function(t){t.off(),a.hasTransitionSupport()?t.addClass("ripple-out"):t.animate({opacity:0},100,function(){t.trigger("transitionend")}),t.on("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd",function(){t.remove()})},n.prototype.rippleOn=function(t,i){var o=a.getNewSize(t,i);a.hasTransitionSupport()?i.css({"-ms-transform":"scale("+o+")","-moz-transform":"scale("+o+")","-webkit-transform":"scale("+o+")",transform:"scale("+o+")"}).addClass("ripple-on").data("animating","on").data("mousedown","on"):i.animate({width:2*Math.max(t.outerWidth(),t.outerHeight()),height:2*Math.max(t.outerWidth(),t.outerHeight()),"margin-left":-1*Math.max(t.outerWidth(),t.outerHeight()),"margin-top":-1*Math.max(t.outerWidth(),t.outerHeight()),opacity:.2},500,function(){i.trigger("transitionend")})},t.fn.ripples=function(i,o){return this.each(function(){t.data(this,"plugin_"+s)||t.data(this,"plugin_"+s,new n(this,i,o))})}}(jQuery,window,document); +//# sourceMappingURL=ripples.min.js.map diff --git a/scripts/material.js b/scripts/material.js index e234c208..f83c9ade 100644 --- a/scripts/material.js +++ b/scripts/material.js @@ -77,6 +77,7 @@ "validate": true, "input": true, "ripples": true, + "ripplesDelegate": true, "checkbox": true, "togglebutton": true, "radio": true, @@ -256,7 +257,17 @@ }); }, "ripples": function (selector) { - $((selector) ? selector : this.options.withRipples).ripples(); + if (this.options.ripplesDelegate) { + // Delegate mode, lazy creation + $(document).on('mousedown touchstart', selector || this.options.withRipples, function(event) { + if(!$.data($(this), "plugin_ripples")) { + $(this).ripples({}, event); + } + }); + } else { + // Immediate and static creation + $((selector) ? selector : this.options.withRipples).ripples(); + }; }, "autofill": function () { // This part of code will detect autofill when the page is loading (username and password inputs for example) diff --git a/scripts/ripples.js b/scripts/ripples.js index 82b67884..51cccf25 100644 --- a/scripts/ripples.js +++ b/scripts/ripples.js @@ -26,7 +26,7 @@ /** * Create the main plugin function */ - function Ripples(element, options) { + function Ripples(element, options, event) { self = this; this.element = $(element); @@ -36,17 +36,16 @@ this._defaults = defaults; this._name = ripples; - this.init(); + this.init(event); } /** * Initialize the plugin */ - Ripples.prototype.init = function() { + Ripples.prototype.init = function(event) { var $element = this.element; - - $element.on("mousedown touchstart", function(event) { + var rippleStart = function(event) { /** * Verify if the user is just touching on a device and return if so */ @@ -142,7 +141,9 @@ } }); - }); + }; + $element.on("mousedown touchstart", rippleStart); + event && rippleStart(event); }; @@ -313,10 +314,10 @@ /** * Create the jquery plugin function */ - $.fn.ripples = function(options) { + $.fn.ripples = function(options, event) { return this.each(function() { if(!$.data(this, "plugin_" + ripples)) { - $.data(this, "plugin_" + ripples, new Ripples(this, options)); + $.data(this, "plugin_" + ripples, new Ripples(this, options, event)); } }); };