On a discussion elsewhere (http://tinyurl.com/3tcm6l5), I ran across the fact that jQuery.Event starts like this:
jQuery.Event = function( src ) {
// Allow instantiation without the 'new' keyword
if ( !this.preventDefault ) {
return new jQuery.Event( src );
}
I'm curious as to why it's done this way rather than the more obvious
jQuery.Event = function( src ) {
// Allow instantiation without the 'new' keyword
if (!(this instanceof jQuery.Event) ) {
return new jQuery.Event( src );
}
Although the current code works, if someone somehow did this:
jQuery.preventDefault = true;
it would wreak havoc This would stop events from processing, except those constructed with "new" and would overwrite the jQuery.type function, and perhaps steal your girlfriend.
Is there some reason that the more obvious code won't work?
In another thread (http://forum.jquery.com/topic/queueing-up-animations) there's a discussion about a fairly simply animation. It works fine in IE8, and in recent versions of Firefox, Opera, Safari, and Chrome. But it is pretty haywire in IE6 and IE7. I'm afraid I don't know nearly what I should about browser quirks. Can anyone suggest a reason, or even better, a fix? A sample of the animation is at
In response to a recent thread, I created a quick plug-in. You can see it at http://jsbin.com/ocodi/21/edit. It has a strange feature, and I wonder if others would find it wrong-headed.
This plug-in treats the jQuery wrapper object as a group, and passes the whole wrapper in as the context object (the "this") for the functions supplied. Generally, when functions are supplied as parameters, either the context is irrelevant, or each DOM element in the jQuery wrapper is passed. But I don't do that. My plug-in keeps a reference to the jQuery wrapper and calls the functions in that context.
This is necessary, because the whole idea is to act on a number of elements as a group -- in this case by fading in and out all members of the group when any individual one is hovered -- but I don't recall seeing this done elsewhere in the jQuery ecosphere. Are there other examples of this behavior? Does it seem reasonable? Or is it likely to trip up someone?
I was wondering if anyone had already built the jQuery equivalent of the menu on Google's livingstories that scrolls with the page to the top then sits at the top until the page is scrolled back down.
It doesn't work in IE, but in other modern browsers, the menu on the right ("Timeline of important events") starts out 450+ pixels down the page, below headers and other page chrome, but when it would otherwise scroll off the screen it switches to "position: fixed; top: 0" If the whole thing does not fit on the page, as you scroll near the bottom it switches again to "position: relative; top: NNNpx" where NNN is presumably the difference between the position of the top of the footer and height of the menu.
It's a nice effect that I haven't seen before, and I was wondering if anyone had already created something like this as a jQuery plug-in.
I need to highlight and work with the innermost of several hovered items. My markup is for now nested lists, although that may change, and if the user hovers over one several layers deep, only that one should be highlighted. I have code that is working for my initial case, with a demo here: http://jsbin.com/ipova (code: http://jsbin.com/ipova/edit) My full interface will have something substantially more than the CSS generated id on the left, but I think this gets the point across. I would probably also add in hoverIntent to stop some annoying flashing... I'm reasonably happy with this code, although if I were to want to distribute it as a real plug-in, it would still take some work, as I reuse events in an inappropriate manner. But I want to know if there are better tools already out there to do the same thing. Has anyone created or seen something better than my implementation (and maybe found a better name for it!?) This is the relevant code for a method that can be used in place of hover: $.fn.hoverOne = function(fnOver, fnOut) { var currentElt = false; var $jqObject = this; $(this).hover(function(event) { if (currentElt) fnOut.call(currentElt, event); fnOver.call(this, event); currentElt = this; }, function(event) { fnOut.call(this, event); if ($.inArray(event.relatedTarget, $jqObject) > -1) { fnOver.call(event.relatedTarget, event); currentElt = event.relatedTarget; } else { currentElt = false; } }); } Any suggestions, pointers? Thanks, -- Scott Sauyet
I'm having an odd issue with links inside sortables. I have a simple demo here: http://scott.sauyet.com/issues/2008-04-12a/ The links inside the sortable don't work on a single left-click. I can right click and open them (here or in a new window or a new tab depending upon browser) or I can middle-click them and open in a new tab. On Firefox, they work with a double-click, but they add two copies of the new location to the history. Has anyone run into this before? Is there any straightforward way of fixing it? Thanks, -- Scott
Hi Folks, I think there's a problem with the serialization of nested lists inside Sortables. I have an altered version of the demo here: http://scott.sauyet.com/issues/2008-04-08a/ The Serialize button logs to the console if you have Firebug, otherwise it just does an alert. The original layout looks like this: * Drag us * around * and change o Lorem o Ipsum * our * positions o Something else o Foo bar and it serializes as
item[]=0&item[]=1&item[]=2&item-2[]=0&item-2[]=1&item[]=3&item[]=4&item-4[]=0&item-4[]=1 If you move "our" after "Ipsum" in the nested list, you get * Drag us * around * and change o Lorem o Ipsum o our * positions o Something else o Foo bar which serializes as
item[]=0&item[]=1&item[]=2&item-2[]=0&item-2[]=1&item[]=3&item[]=4&item-4[]=0&item-4[]=1 exactly the same as above. Clearly these two different structures should serialize differently. I can see that there is an extension point for the attribute, the key value, and the regex used in serialization, but I don't think there's a straightforward way to replace the actual serialization function without hacking into the source code. Can anyone suggest a way that I could get different behavior here? Thanks, -- Scott