javascript - What is “jQuery.event.special”? -


i new jquery , have been try bootstrap transition.js(line 50) code , figure out how works in there. have stumbled across following :

$.event.special.bstransitionend = {       bindtype: $.support.transition.end,       delegatetype: $.support.transition.end,       handle: function (e) {         if ($(e.target).is(this)) return e.handleobj.handler.apply(this, arguments)       } 

i have read documentation, could't understand except following :

 bindtype: // event want bind   delegatetype: // event want delegate 

after research have found following:

those special attributes transition end event made available later use in transition.js.

i trying figure out things reading article, want know is... $.event.special, use of line? common usage?

p.s.: did read this question on has more external links answer itself. hoping have clear canonical q&a basic use of $.event.special?

what use of line?

i'm assuming meant first line of code in question. defines bstransitionend alias transition end event (the transition end event may vary browser browser - function transitionend() : determine proper transition end event browser. i've used webkittransitionend here on, else depending on browser)

why use alias? insulates handlers bootstrap attaches using alias (e.g. $('mybootstrapdialog').on('bstransitionend', bootstrap's handler) $('mybootstrapdialog').off('webkittransitionend') other code (say, code or maybe library) - bootstrap transition end animations still work!

why or library that? webkittransitionend standard event, let's decide add transition end animation bootstrap dialog - you'd $('mybootstrapdialog').on('webkittransitionend', your handler) , later on decide remove handler should going $('mybootstrapdialog').off('webkittransitionend', your handler), miscode $('mybootstrapdialog').off('webkittransitionend') - removes transition end events :-(.

but since bootstrap attached it's handlers using 'bstransitionend', way mess bootstrap $('mybootstrapdialog').off('bstransitionend') - not accidentally :-). voila! gone bugs bootstrap inexplicably stops working because of small miscoding on part.

the bindtype , delegatetype state bstransitionend alias transition events attached directly, , ones delegated (bubbles). handle filter function - triggered events go through before attached bootstrap event handlers called (if @ are)

what $.event.special?

i'm sure you'd know of - it's way hook jquery's event handling mechanism allowing large scale magic x on every attached click event on page (imagine doing 1 one, @ each , every place you've attached onclick event), define own events (with bubbly goodness , comes it), hook in , spoof events modifying event object, etc.

what common usage?

i assume rhetorical :-) - have couple of examples in ben alman blog post linked

(paraphrasing) - let's ajax submit , want disable clicks on page (you don't want user clicking on , navigating off other page via menu, or changing checkbox, etc.) , $.event.special.click should (of course might easier / traditional overlay transparent / partially transparent div submitting... animation or or not doing - after all, users wait around make sure submit successful, @ least normal ones :-))

another use case 1 saw in bootstrap code, mentioned, don't have go in , use unless you're writing library or intend distribute publicly.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -