Re: [jQuery] Dynamic call

2006-10-16 Thread Dave Benjamin
On Mon, 16 Oct 2006, Aaron Heimlich wrote:

 On 10/16/06, Blair McKenzie [EMAIL PROTECTED] wrote:
 
 $(#div)[call]()

 Blair's right.

 $(#div).call()

 tries to call the call method on $, but since there is no call method
 (that I know of), it's not working.

Actually, there is:
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Function:call

Using call or apply is another approach to solving this type of problem, 
but you have to be careful to pass in the appropriate thisArg, which in 
this case would be the jQuery object itself.

Dave

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Dynamic call

2006-10-16 Thread Dave Benjamin
On Mon, 16 Oct 2006, Michael Geary wrote:

 The return value from $() isn't a function and doesn't have a call method.

 In any case, Blair's code is the way to do it:

 $(#div)[call]();

Right - I should have been more clear. To use call/apply, you'd have to do 
it like this:

var obj = $('#div');
var meth = 'hide';

obj[meth].call(obj, 'slow');

var args = ['slow'];

obj[meth].apply(obj, args);

This probably isn't useful for the original poster's question, but it's 
good to know in many cases when you're trying to resolve method calls 
dynamically.

Dave

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Single Value Attributes

2006-10-03 Thread Dave Benjamin
On Tue, 3 Oct 2006, Michael Geary wrote:

 No need to go to the extra work. jquery.js begins with this:

 window.undefined = window.undefined;

 So undefined exists in every browser. This is a handy line of code to put
 in any JavaScript - it's completely compatible with both old and new
 browsers.

Hah! JavaScript is SO WEIRD!

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


[jQuery] Getting x- and y-positions of elements

2006-10-03 Thread Dave Benjamin
Is there any plan to add jQuery methods to retrieve and set the 
coordinates of an element on the page? It seems like a good addition to 
dimensions.js, perhaps. Here's what I currently use:

$.fn.x = function(n) {
 var result = null;
 this.each(function() {
 var o = this;
 if (n === undefined) {
 var x = 0;
 if (o.offsetParent) {
 while (o.offsetParent) {
 x += o.offsetLeft;
 o = o.offsetParent;
 }
 }
 if (result === null) {
 result = x;
 } else {
 result = Math.min(result, x);
 }
 } else {
 o.style.left = n + 'px';
 }
 });
 return result;
};

$.fn.y = function(n) {
 var result = null;
 this.each(function() {
 var o = this;
 if (n === undefined) {
 var y = 0;
 if (o.offsetParent) {
 while (o.offsetParent) {
 y += o.offsetTop;
 o = o.offsetParent;
 }
 }
 if (result === null) {
 result = y;
 } else {
 result = Math.min(result, y);
 }
 } else {
 o.style.top = n + 'px';
 }
 });
 return result;
};

If there are multiple elements matched, they will all get the same x- or 
y-position. On retreival, they return the minimum position of all the 
elements in the query result.

Perhaps it might be better to have a single method that returns a pair of 
{x, y} values... though there's something elegant about being able to say 
things like:

$('#obj1').x($('#obj2').x() + 20);

Dave

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Getting x- and y-positions of elements

2006-10-03 Thread Dave Benjamin
On Tue, 3 Oct 2006, Brandon Aaron wrote:

 jQuery has two methods named .top() and .left() for setting the top
 and left offset via css. I just wrote a plugin for getting the offset
 of an element and did some pretty extensive cross-browser testing.

I'm not too crazy about .top() and .left() because of the need to 
concatenate and un-concatenate 'px' everywhere.

 Here is the blog entry:
 http://brandonaaron.net/articles/2006/10/02/jquery-plugin-offset

Wow. I saw your post about this earlier but I must not have been paying 
enough attention. Very nice, Brandon!

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Getting x- and y-positions of elements

2006-10-03 Thread Dave Benjamin
On Tue, 3 Oct 2006, Brandon Aaron wrote:

 On 10/3/06, Dave Benjamin [EMAIL PROTECTED] wrote:
 I'm not too crazy about .top() and .left() because of the need to
 concatenate and un-concatenate 'px' everywhere.

 I can understand this and it is something I'm trying to decide how I
 want to handle. The offset plugin I wrote returns a unit-less number
 and it should be that way but I was thinking about including a
 property: toppx and leftpx that would include + 'px'. Not sure how
 useful that really is though ... and while I talking about this plugin
 ...

Well, it's not much of a savings... o.toppx vs o.top+'px' is about the 
same to me.

 I was thinking about allowing it to take another element or expression
 as a parm and get the relative offset instead of going all the way to
 the body. Does anyone think this would be useful? It shouldn't add
 much overhead to the method for those that don't need it.

Yeah, this is one thing that troubles me about my .x() and .y() methods - 
they are asymmetrical with respect to reads and writes, since writes 
modify the CSS attribute directly, but reads take nesting into account. 
Being able to choose between local and global coordinates seems helpful.

 I was also thinking about taking a hash of top and left as a param.
 The top and left would be numbers to relatively offset the element by.
 This sounds like what you are talking about and would remove the
 annoyance of the + 'px' all over the place. However, the call would
 look like this: $().offset({ top: 10, left: 10 }); I guess that is
 less typing than: $().top(10+'px').left(10+'px');

I much prefer $().offset({ top: 10, left: 10 }) to the chaining of .top() 
and .left(). It's more readable, and easier to modify. (IMHO)

 One issue I have with this is what should it actually return? I don't
 think it is a good idea to change return types but it would make most
 sense in this situation to return the jQuery object. The other issue
 is that calling offset like this would suggest that it acts on all the
 elements in the jQuery object whereas just $().offset() acts only on
 the first. So  yeah I've thinking hard about it and could use some
 opinions.

Well, I'm personally not a big fan of method chaining, period. ;) However, 
I would normally ignore the result of .offset( {...} ), so I don't really 
care. Might as well be the jQuery object.

Regarding multiple matched elements, I think it makes the most sense to 
take the minimum of left and top... and if there is also right and 
bottom, take the maximum of those. That way it gives you a bounding box 
for all matched elements.

For setting... that's trickier. The simplest thing would be to set all 
elements to be the same. But that's inconsistent with the bounding box 
metaphor, which would suggest only setting the outermost matched element, 
or otherwise maintaining that the relative position of the elements to 
each other remains stable.

Dave

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] NEWS: JQuery being used for Bookmarklets

2006-10-03 Thread Dave Benjamin
On Tue, 3 Oct 2006, Patrick Hall wrote:

 On 10/3/06, Rey Bango [EMAIL PROTECTED] wrote:
 Another mention of JQuery, this time in a bookmarklet.

 http://blogs.pathf.com/agileajax/2006/10/using_bookmarkl.html

 That's cool. How does this get around the no opening content from
 other domains restriction?

This restriction does not currently apply to script tags. However, relying 
on this behavior may be risky - the Douglas Crockford quote on the 
following page comes to mind:

http://www.mindsack.com/uxe/dynodes/

He's not kidding, however, when he says It cannot be easily fixed because 
the whole advertising infrastructure depends on the hole.. This includes 
Google. =)

-- 
.. Dave Benjamin - Software Developer - ramenlabs.com
.. AIM: ramenlabs / MSN: [EMAIL PROTECTED]

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Widget Challenge

2006-09-27 Thread Dave Benjamin
On Wed, 27 Sep 2006, Paul Bakaus wrote:

 as you may know, the jQuery website is going to be updated soon, 
 supported by a famous cms. Maybe it would be good to build in a plugins 
 platform into the page, where every developer can add his plugin, like 
 for example Firefox Plugins, mozdev. etc.

I like the idea. And I've got a few simple plugins I could contribute.

Dave

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Form plugin - move to core?

2006-09-25 Thread Dave Benjamin
On Mon, 25 Sep 2006, Rey Bango wrote:

 I refer back to EasyDOM that, at the moment, will only work on v1.0a.
 The upgrade to v1.0.1 broke the functionality. Further, I recall an
 email that I sent out early this month that referred to the set()
 method, which is used in EasyDOM, to which John replied letting me know
 that it had been superseded by attr(). This affected EasyDOM and I'm
 sure others that took advantage of the original method.

You can create an alias for set() like this:

if (!$.fn.set) $.fn.set = $.fn.attr;

I agree that breaking backward compatibility like this is a bit 
frustrating. However, it was a pre-release, so I'd say John picked a 
reasonable time to do it.

Dave

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Digg push

2006-09-25 Thread Dave Benjamin
On Mon, 25 Sep 2006, Yehuda Katz wrote:

 Good fyi. I'd quibble about the front-page of the programming section. 
 I'm sure there are *some* people that check sections of interest to 
 them. May not be a whole lot of people, but there are certainly *some.* 
 Am I missing something?

I get the programming RSS feeds for both reddit and digg. However, I find 
the digg feed rather boring, and the articles there to be of lesser 
quality on average. So, while I will possibly glance at an article on the 
programming digg, if it makes it to the front of the programming reddit 
I've probably read it.

Dave

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Ready blocks not always firing

2006-09-25 Thread Dave Benjamin
On Mon, 25 Sep 2006, Brandon Aaron wrote:

 The current revision in SVN is 346. A quick glance over the check-ins
 didn't show a particular reversion # that the issue you are having was
 fixed in. I have been using the latest SVN revision since around 289
 and haven't seen this issue.

I can't find a link anywhere on jquery.com for the latest SVN release, and 
I don't have a Java environment handy to build it with ant at the moment, 
but I did manage to get revision 303 at 
http://jquery.com/src/jquery-svn.js so I tried that. Still having the same 
problem.

One place where the problem occurs for me is here:
http://spoomusic.com/

If you look at the list of links on the left-hand navigation under 
Net.Radio, there should be a link that says (more). If this link does 
not appear (and instead you see the full list of net radio links at page 
load), then the $(document).ready(...) did not fire. One way I'm able to 
reliably produce this effect on IE is to click the spoomusic logo in the 
top-left corner of the page. If I hit reload, it works fine, but if I 
click that logo, the (more) link doesn't show up when the page redraws.

Thanks,
Dave

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Ready blocks not always firing

2006-09-25 Thread Dave Benjamin
Well, I removed some code that was creating the Flash-based MP3 player and 
the erratic behavior on IE went away. The other site that I had this 
problem with had Flash as well, and in both sites I was using the 
SWFObject JavaScript library according to the instructions, by creating a 
DIV to receive the Flash movie, and immediately following that a SCRIPT 
block that loads the movie into the DIV. If I put this code in a 
$(document).ready(...), the problem goes away. However, doing this results 
in the DIV's no-Flash placeholder content displaying for a second before 
being replaced with the SWF, which isn't really desirable.

I don't know at this point if it's specifically SWFObject+JQuery, or if 
it's due to the general technique of inline SCRIPT blocks that manipulate 
the document.

Thanks for the help,
Dave

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Synchronizing

2006-09-02 Thread Dave Benjamin
On Sat, 2 Sep 2006, John Resig wrote:

 Neil Mix has released a library that lets you write Javascript code just 
 like that: http://www.neilmix.com/narrativejs/doc/index.html

Wow, that is really impressive. I've been thinking about different ways to 
approach the sync vs. async barrier. One approach has been to chain 
functions together, which I've described here:

http://dev.bestpartyever.com/2006/08/05/taking-the-pain-out-of-async/

Lately I've been experimenting with Parenscript, which is a 
Lisp-to-JavaScript translator that allows you to write macros; if anyone's 
interested I can post some sequencing macro code I've been working on... 
=)

Dave

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Synchronizing

2006-09-02 Thread Dave Benjamin
On Sat, 2 Sep 2006, John Resig wrote:

 Lately I've been experimenting with Parenscript, which is a 
 Lisp-to-JavaScript translator that allows you to write macros; if 
 anyone's interested I can post some sequencing macro code I've been 
 working on...

 Go ahead! I'm interested :-)

Right on.

So, for a simple example, here's a snippet of Parenscript code that 
creates a DIV, puts some text in it, and fades it in, out, and back in 
again:

   (.append #$body (html ((:div :id mydiv
  :style (css-inline :background white))
Hello, world!)))
   (seq
(.fade-in #$div #mydiv slow)
(.fade-out #$div #mydiv slow)
(.fade-in #$div #mydiv fast)))

A few notes about the syntax: The #$ is a reader-macro I wrote for for 
convenience; #$body gets transformed into ($ body). I haven't yet 
decided if this is a good thing or not. ;) In Parenscript, functions that 
start with a . such as .append and .fade-in, above, are treated as 
method calls. Capitalization is translated by Parenscript from Lisp-style 
to JavaScript-style, which is why the jQuery methods end up looking like 
.fade-in. The html and css-inline macros are part of Parenscript, 
and allow you to generate JavaScript that builds HTML and CSS from 
s-expressions.

The sequencing macro is seq. The above seq call gets transformed into 
the following:

   (.fade-in #$div #mydiv slow
  (lambda ()
 (.fade-out #$div #mydiv slow
(lambda ()
   (.fade-in #$div #mydiv fast)

The resulting JavaScript is this:

   function main() {
 $('body').append('div id=mydiv style=' + ('background:white')
  + 'Hello, world!/div');
 $('div #mydiv').fadeIn('slow',
function () {
  $('div #mydiv').fadeOut('slow',
  function () {
$('div 
#mydiv').fadeIn('fast');
  });
});
   }

So, this has similar effects to what I think you're trying to achieve with 
method chaining, but is more general because you are not limited to a 
single jQuery object for the dispatch of each chained operation.

Here's my working definition of seq:

   (defjsmacro seq (rest forms)
 (labels
 ((aux (lst)
   (cond
((null lst) nil)
((and (consp lst) (not (cdr lst))) (car lst))
(t (append (car lst) (list `(lambda () ,(aux (cdr lst)
   (aux forms)))

I'd like to extend it to allow inserting ordinary code in the middle of 
the sequence with a par construct - I'm lifting this terminology out of 
an interesting but obscure concurrent language called Occam:

   http://en.wikipedia.org/wiki/Occam_programming_language

Ironically, in an event-driven model, par is really the default 
behavior. When working with background functions, everything is parallel; 
you have to really work at making things sequential.

Dave

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


[jQuery] Interface Sortables scrollbar issue

2006-08-27 Thread Dave Benjamin
On Thu, 24 Aug 2006, Stefan Petre wrote:

 Great news. I can finally release the Interface with the new changes,
 website and plugins.

Hi Stefan,

I'm trying out your new Sortables demo:
http://interface.eyecon.ro/demos/sort.html

If you make your browser window smaller than the content and scroll down 
to the bottom, the drag'n'drop causes the screen to jump around a bit (IE 
and FF). It also flickers to white in FF.

Though the current behavior is much improved over the previous version 
(where using the scrollbar would almost completely break the sorting 
ability) I wonder if it would not be too difficult to get rid of the 
flickering and jumping artefacts as well.

Thanks,
Dave

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Early Docs Prorotype

2006-08-09 Thread Dave Benjamin
If you put an overflow-y: scroll on the body, it'll keep the page from 
jumping around when the scrollbar appears. This works in recent versions 
of FireFox, though it started out as an IE-only extension.

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] cant parseInt

2006-08-08 Thread Dave Benjamin
On Tue, 8 Aug 2006, Rafael Santos wrote:

 i just want to increase a value...

 by jQuery:
 var cont = $(#img_counter).val(); //its an input value
 cont = parseInt(cont + 5);
 $(#img_counter).val(cont);
 ...
 =( where am i wrong?

You want:
cont = parseInt(cont) + 5

The input value is a string. To ensure that it is treated like a number, 
you have to convert it before you use the + operator, since + is 
overloaded for numbers and strings.

-- 
.. Dave Benjamin - Software Developer - ramenlabs.com
.. AIM: ramenlabs / MSN: [EMAIL PROTECTED]

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/