Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  • Thread Tools
  • Rate This Thread
  1. #1
    New 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...

  2. #2
    Supreme Master coder! Philip M's Avatar
    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.

  3. #3
    New to the CF scene
    Join Date
    Apr 2016
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    None of these libraries is recommended. They add an unacceptable overhead to the code. You should prefer plain vanilla Javascript.
    cool thanks

  4. #4
    Regular Coder
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    311
    Thanks
    0
    Thanked 42 Times in 40 Posts
    Here...

    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;
    }
    DONE, and the only reason it's "that massive" is it provides support all the way back to IE5.

    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...

    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);
    });
    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...

    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

  5. #5
    New to the CF scene
    Join Date
    Apr 2016
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by deathshadow View Post
    Here...

    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;
    }
    DONE, and the only reason it's "that massive" is it provides support all the way back to IE5.

    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...

    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);
    });
    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...

    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.
    thanks Dr. DeathShadow


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •