-
Notifications
You must be signed in to change notification settings - Fork 24
06. Add Remove Click Events (pARCE.js)
| << Previous | Back to Table of Contents | Next >> |
"You want in my clique?" - PT
Dependency: pDA (disableable)
This will add or remove a click callback associated with an element. It also allows for use of the optional once attribute that will automatically remove the event listener from the element once it fires the first time, therefore, it only fires "once".
pARCE will also use pDA to cancel out any highlighting caused from accidental double clicking by adding it as a dblclick listener. Remove e.addEventListener("dblclick",pDA); to disable this feature.
const pARCE=(a,e,c,o)=>{if(a){e.addEventListener("click",c,(o?{once:true}:false));e.addEventListener("dblclick",pDA);}else e.removeEventListener("click",c);}pARCE(true,myElementA,myCallbackFuncA,true); // Add click event, single use (automatic removal).
pARCE(true,myElementB,myCallbackFuncB,false); // Add click event, multi use.
pARCE(true,myElementB,myCallbackFuncB); // Add click event, multi use, default setting.
pARCE(false,myElementB,myCallbackFuncB); // Manual remove click eventNothing, get used to it. But your thing works now.
pARCE(a,e,c,o)
a = < Add/Remove Boolean > * REQUIRED
- A true or false equivalent boolean used to add or remove the click event, respectively. Suggested to use
trueorfalse.
e = < HTML Element > * REQUIRED
- The element to which to add or remove the
clickevent. - If
aabove is set totruethenpDAwill also be added as an event listener fordblclick(double clicks) on this element.
c = < Callback Function > * REQUIRED
- The callback function to which to attach to or remove from the
clickevent on the specifed element (eabove).
o = < Once/Multi Boolean > Optional
- A true or false equivalent boolean used to set the
onceattribute. Suggested to usetrueorfalse. - The
onceattribute will allow the event listener to run only once, then the browswer will remove it from the element automatically. - If omitted,
pARCEwill default to a multi-use event listener. - Skipped if
aisfalse.
"Programming comfortably with my PJs." - PT