From dfe13c23554b5f1cfcc0e22e906a1aa75212847c Mon Sep 17 00:00:00 2001 From: Stephen James Date: Mon, 6 Jul 2015 10:57:36 -0400 Subject: [PATCH] Add namespace to placard events --- index.js | 7 +++++++ js/placard.js | 19 ++++++++++--------- test/placard-test.js | 10 +++++----- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index a6e27d03f..608aa0cd1 100644 --- a/index.js +++ b/index.js @@ -440,6 +440,13 @@ define(function (require) { }); }); + $('#myPlacard3').on('accept.fu.placard', function() { + console.log('accepted.fu.placard'); + }); + + $('#myPlacard3').on('cancel.fu.placard', function() { + console.log('cancelled.fu.placard'); + }); /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - RADIO diff --git a/js/placard.js b/js/placard.js index da510ce0e..4ad7603dd 100644 --- a/js/placard.js +++ b/js/placard.js @@ -51,9 +51,9 @@ this.$field.on('focus.fu.placard', $.proxy(this.show, this)); this.$field.on('keydown.fu.placard', $.proxy(this.keyComplete, this)); - this.$accept.on('click.fu.placard', $.proxy(this.complete, this, 'accept')); + this.$accept.on('click.fu.placard', $.proxy(this.complete, this, 'accepted')); this.$cancel.on('click.fu.placard', function (e) { - e.preventDefault(); self.complete('cancel'); + e.preventDefault(); self.complete('cancelled'); }); this.ellipsis(); @@ -63,30 +63,31 @@ constructor: Placard, complete: function (action) { - var func = this.options['on' + action[0].toUpperCase() + action.substring(1)]; + var eventName = action === 'accepted' ? 'accept' : 'cancel'; + var func = this.options['on' + eventName[0].toUpperCase() + eventName.substring(1)]; var obj = { previousValue: this.previousValue, value: this.$field.val() }; if (func) { func(obj); - this.$element.trigger(action, obj); + this.$element.trigger(action + '.fu.placard', obj); } else { - if (action === 'cancel' && this.options.revertOnCancel) { + if (action === 'cancelled' && this.options.revertOnCancel) { this.$field.val(this.previousValue); } - this.$element.trigger(action, obj); + this.$element.trigger(action + '.fu.placard', obj); this.hide(); } }, keyComplete: function (e) { if (this.isInput && e.keyCode === 13) { - this.complete('accept'); + this.complete('accepted'); this.$field.blur(); } else if (e.keyCode === 27) { - this.complete('cancel'); + this.complete('cancelled'); this.$field.blur(); } }, @@ -261,7 +262,7 @@ $.fn.placard.defaults = { onAccept: undefined, onCancel: undefined, - externalClickAction: 'cancel', + externalClickAction: 'cancelled', externalClickExceptions: [], explicit: false, revertOnCancel: -1//negative 1 will check for an '.placard-accept' button. Also can be set to true or false diff --git a/test/placard-test.js b/test/placard-test.js index 825fb2f3e..791e9948e 100644 --- a/test/placard-test.js +++ b/test/placard-test.js @@ -27,7 +27,7 @@ define(function(require){ $('body').append($placard); $placard.placard(); - $placard.on('cancel', function(e, helpers){ + $placard.on('cancelled.fu.placard', function(e, helpers){ ok(1===1, 'default action event (cancel) triggered upon external click'); }); @@ -43,7 +43,7 @@ define(function(require){ var $placard = $(html).find('#placard2'); $placard.placard(); - $placard.on('cancel', function(e, helpers){ + $placard.on('cancelled.fu.placard', function(e, helpers){ ok(1===1, 'default action event (cancel) triggered upon external click'); }); $('body').append($placard); @@ -71,13 +71,13 @@ define(function(require){ var $placard = $(html).find('#placard1'); $placard.placard(); - $placard.on('accept', function(e, helpers){ + $placard.on('accepted.fu.placard', function(e, helpers){ ok(1===1, 'accept event triggers on accept'); equal(typeof e, 'object', 'event object passed in accept event'); equal(typeof helpers, 'object', 'helpers object passed in accept event'); equal((helpers.previousValue!==undefined && helpers.value!==undefined), true, 'helpers object contains correct attributes'); }); - $placard.on('cancel', function(e, helpers){ + $placard.on('cancelled.fu.placard', function(e, helpers){ ok(1===1, 'cancel event triggers on cancel'); equal(typeof e, 'object', 'event object passed in cancel event'); equal(typeof helpers, 'object', 'helpers object passed in cancel event'); @@ -146,7 +146,7 @@ define(function(require){ var $placard = $(html).find('#placard1'); $placard.placard({ - externalClickAction: 'accept' + externalClickAction: 'accepted' }); $placard.find('input').focus().focus().val('test');