Last active
September 18, 2020 02:53
Rachel Nabors: touch and click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://coderwall.com/p/yzlqpq | |
(function($){ | |
function touch(event) { | |
event.preventDefault(); | |
var runFunc = $(this).data('activateRunFunc'); | |
runFunc && runFunc(); | |
} | |
function click(event) { | |
event.preventDefault(); | |
event.stopImmediatePropagation(); | |
var runFunc = $(this).data('activateRunFunc'); | |
runFunc && runFunc(); | |
} | |
$.fn.activate = function(runFunc) { | |
return $(this).data('activateRunFunc', runFunc).on({ | |
touchend: touch, | |
click: click | |
}); | |
}; | |
})(jQuery); |
Are you willing to explain what's happening here? Where do I place the functionality that I need once the event is triggered?
$('your-selector').activate(function (event) {
console.log('event was dispatched', event)
})
does that help?
Thank you, it does.
…On Mon, Sep 23, 2019 at 3:29 PM Rodney Rehm ***@***.***> wrote:
$('your-selector').activate(function (event) {
console.log('event was dispatched', event)
})
does that help?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/6464641?email_source=notifications&email_token=AGZ6SBJT47TK2AHKOUVGPDTQLEYMXA5CNFSM4IZO4RGKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFZIXY#gistcomment-3035516>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGZ6SBNAM6LYLL35JD5UFV3QLEYMXANCNFSM4IZO4RGA>
.
--
Regards,
Andre Nell
972.672.6179
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I kept Rachel's example intact but changed a couple of things around. Here's a brief list:
$.noConflict()
were to be invoked later on..on()
accepts maps for a more concise registration$(this)
jQuery knows Special Events, something they redefined as Event Extensions. If you are to process more complex event handling, this is an infrastructure you want to look into. It allows you to handle all that "touch or click" business behind the scenes and use
$(selector).on('your-custom-event', runFunc)
- making stuff simpler and easier to maintain in the long run.