Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
Results 1 to 5 of 5
-
04-07-2016, 02:44 PM #1New to the CF scene
- Join Date
- Apr 2016
- Posts
- 5
- Thanks
- 0
- Thanked 0 Times in 0 Posts
Need Help choosing js library for event handling
for event handling, what is the easiest js library to use jquery, gator or anything else?
Is this a dumb question?
let me know..
Thanks...
-
04-07-2016, 03:16 PM #2Supreme Master coder!
- Join Date
- Jun 2002
- Location
- London, England
- Posts
- 18,929
- Thanks
- 211
- Thanked 2,624 Times in 2,602 Posts
None of these libraries is recommended. They add an unacceptable overhead to the code. You should prefer plain vanilla Javascript.
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
-
04-07-2016, 04:08 PM #3New to the CF scene
- Join Date
- Apr 2016
- Posts
- 5
- Thanks
- 0
- Thanked 0 Times in 0 Posts
-
04-07-2016, 10:23 PM #4Regular Coder
- Join Date
- Feb 2016
- Location
- Keene, NH
- Posts
- 311
- Thanks
- 0
- Thanked 42 Times in 40 Posts
Here...
DONE, and the only reason it's "that massive" is it provides support all the way back to IE5.Code:function eventAdd(eventName, callback) { if (this.addEventListener) this.addEventListener(eventName, callback, false); else this.attachEvent('on' + eventName, callback); } function eventProcess(event, preventPropagation) { event = event || window.event; if (!event.target) event.target = event.srcElement; if (preventPropagation) { // this MAY be overkill... Oh, who are we kidding, it is! event.cancelBubble = true; if (event.stopPropagation) event.stopPropagation(); if (event.preventDefault) event.preventDefault(); event.returnValue = false; } return event; }
preventPropagate is an optional boolean (so it assumes false) that will stop the normal click behavior of the element from firing.
Example use, let's say you had an <a>nchor element called "#latest" you wanted to attach a onclick handler that adds a wrapping call for tracking to the link...
You need much more than that, you're probably doing something wrong... and about two thirds of that code could go in the trash if you don't need to support IE8/earlier. (like in a web app where you know the runtime engine is going to be something like webkit or blink). In fact in those cases, just use attachEvent and e directly without the above functions...Code:eventAdd(document.getElementById('latest'), function(e) { e = eventProcess(e, true); // true prevents anchor from following it's href window.location.href = 'wrapper.php?site=' + encodeURIComponent(e.target.href); });
Which is why SO many "frameworks" are pointless when making web apps, but do provide missing functionality in legacy browsers; still I'd rather use simply polyfills when I need them than get in the habit of relying on fat bloated steaming piles of halfwit manure like jquery.From time to time the accessibility of websites must be refreshed with the blood of designers and owners; it is its natural manure.
http://www.cutcodedown.com
-
04-08-2016, 01:10 AM #5New to the CF scene
- Join Date
- Apr 2016
- Posts
- 5
- Thanks
- 0
- Thanked 0 Times in 0 Posts



Reply With Quote
