[jQuery] Re: What does === equate to?

2007-08-02 Thread Ian Struble

!== and === are identity operators.  It is a good idea to use them
instead of the equality operators (!= and ==) unless you know why you
would want to use equality (and the possible type coercion) over
identity.  Probably the biggest gotcha with equality is with falsy
values (false, 0, undefined, /empty string, null and NaN).   The
truthy / falsy issue is probably what bit you Rob.

It may be worth reading a bit of Douglas Crockford's ideas about
javascript if you are trying to figure out identity and equality
operators:

   http://javascript.crockford.com/code.html

And here is something about truthy and falsy:

  
http://developer.mozilla.org/en/docs/A_re-introduction_to_JavaScript#Other_types

Ian


On 8/2/07, Rob Desbois [EMAIL PROTECTED] wrote:
 I had a discussion on the use of the === and !== operators recently on this
 list, my opinion was, and still is, that unless you explicitly WANT to allow
 type conversion, you should be using these. Only use == and != if you really
 want type conversion.

 It's bitten me once, although I can't for the life of me remember how, but
 it involved lots of in-depth debugging and head-scratching to find the
 problem. I'm more wary now and think that these operators are the way to go.

 --rob


 On 8/2/07, Sam Collett [EMAIL PROTECTED] wrote:
 
  I don't think many actually use !== (and when you would want to use
  it) and many sites that show usage of operators don't cover !== (but
  do have ===).
 
  3 != '3' false
  3 !== '3'true
  3 == '3' true
  3 === '3'false
 
 
  On Aug 1, 9:33 pm, Michael Geary [EMAIL PROTECTED] wrote:
I...cannot figure how what the heck === is.
  
   I see that Jake answered your question, but just for next time...
  
   You may have tried a Google search for javascript === and been
   disappointed to find it returned no useful results (because Google seems
 to
   ignore the === in the search).
  
   The key thing to know is that ===, like most special symbols in
 JavaScript
   such as + and -, is an operator. Now you can do a more productive Google
   search:
  
   http://www.google.com/search?q=javascript+operators
  
   This will help when you run into !== and wonder what the heck *that* one
 is.
   :-)
  
   -Mike
 
 



 --
 Rob Desbois
 Eml: [EMAIL PROTECTED]
 Tel: 01452 760631
 Mob: 07946 705987
  There's a whale there's a whale there's a whale fish he cried, and the
 whale was in full view.
 ...Then ooh welcome. Ahhh. Ooh mug welcome.


[jQuery] Re: Need to attach .click() event to HTML anchor link but it won't stop bubbling...

2007-05-06 Thread Ian Struble


You can also try to attach a single event handler to the root node of
your tree and then only process the clicks on A-tags.

function iEatEventsForBreakfast(event) {
 var target = $(target.event);
 if (target.is(a)) {
   // search for and open/close the folder associated with target
   // something like this maybe?
   target.siblings().filter(ul)
   .filter(:visible).hide().end()
   .filter(:hidden).show().end();
   return false;
 }
}

$(#root).click( iEatEventsForBreakfast );

This works because the click event will bubble all the way up from the
event.target up to the top of the body unless it is stopped.

On 5/5/07, Yansky [EMAIL PROTECTED] wrote:


I was doing something similar recently. I'm not sure if this is the
best/right way to do it, but I just added an unbind at the start of
the function (before the click event handler is applied) to prevent
bubling.

e.g.

function foo(){

$('a').unbind( click );

$('a').click(function(){
 $.get(test.html, function(data){
$('#divId').append(data);
foo();
});
});

}

On May 5, 4:13 am, summea [EMAIL PROTECTED] wrote:
 I've been asking about the same problem (and still searching (in
 vain?) for an answer to the question here on the jQuery group...).

 I have a click function that I bind to each folder link in an
 imaginary file manager script.  The problem is still, when I click on
 one folder and it displays its contents, the click function keeps
 going and opens and closed the folder when it should STOP after being
 clicked once.  And it should attach its click function (in an
 UNCLICKED state,) to the just-clicked folder's children folders...

 I've been reading up on events bubbling and stopping propagation,
 returning false, etc.  But nothing seems to be working.  I've tried
 adding a parameter even to the bindFolderAction function to check if
 it's been clicked or not.  But when I tried that, the children
 folder's wouldn't have bindFolderAction binded to them, and that's
 what I need to do as well.

 Here is the function I have so far, I've tried it another way since I
 last posted... and still have had no suggestions... or replies on the
 other post.  Any help?

 bindFolderAction = function(){

 $('.myTree').find('a').bind('click', function(evt){

 evt.stopPropagation();
 evt.preventDefault();

 alert('this is not stopping...');

 var linkval = $(this).attr('href');

 subbranch = $('ul', this.parentNode).eq(0);
 $.log(subbranch.css('display'));

 $.log(this.firstChild);

 if (subbranch.css('display') == 'none') {

 //$.log('OPENED');
 subbranch.show();
 this.firstChild.src = '../img/open.gif';

 $
 (this.parentNode.getElementsByTagName('ul')).load(linkval, function()
 {

 bindFolderAction();
 return false;
 });

 } else {

 //$.log('CLOSED');
 subbranch.hide();

 this.firstChild.src = '../img/closed.gif';

 }

 return false;
 });

 }




[jQuery] Re: click event and z-order

2007-04-28 Thread Ian Struble


The event is not passed down to the underlying event but rather it
bubbles up through the dom tree from the event where the event was
triggered.

http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow-bubbling

An example is probably easier to digest.  This code has click handlers
at body, td and div elements.  Some the .stopTheEventBubbling elements
will stop the event.

Ian


html
head
script src=http://code.jquery.com/jquery-latest.pack.js;/script
script
$(document).ready(function(){
 function setupHandler() {
   var tag = this.toString();
   $(tag).click(function(event) {
 $('#log').append('event for ' + event.target.tagName + ' caught
@ ' + this.tagName + ' - ' + event.timeStamp + 'br/');
 if ($(this).is(.stopTheEventBubbling)) {
   $(this).css(background, #c44); var that = this;
setTimeout(function() { $(that).css(background, #fff); }, 2000);
   //return false;
   // or
   event.stopPropagation();
 }
   });
 }
 $(['body','td','div']).each( setupHandler );

});
/script
/head
body
table border=1
 tr
   td
 divI bubble all the way./div
 div class=stopTheEventBubblingOnly the div catches me./div
   /td
   td class=stopTheEventBubbling
 divThe TD stops my bubbling./div
   /td
 /tr
/table
div id=log/div
/body
/html


On 4/26/07, Stefan Kilp [sk-software] [EMAIL PROTECTED] wrote:




 or event.stopPropagation()

is there a way to make this the default behavior.

at the moment i don't see any example where is would make sence that the click 
event is
passed to the underliing element. i think it is a commen behavior in most gui's 
(win, mac, ...)
the only the first element in the z-order receives the event (if it has been 
registered).

the problem is that i have data in rows and at the and of each row there are 
some 'action
icons' (edit, delete, ...) now to select a datarow i bind click event to the 
surounding row
element (div or tr). when i now click on one of the action icons, my select 
event is triggered,
which in this case is not intended.

any idea to solve this problem?

thanks
stefan


 - Original Message 
 From: (J)(a)(k)(e) [EMAIL PROTECTED]
 To: jquery-en@googlegroups.com
 Sent: Wednesday, April 25, 2007 2:00:50 PM
 Subject: [jQuery] Re: click event and z-order

 I believe your answer is false.

 if you return false at the end of the click code, no other element will be 
bothered with the click event.

 On 4/25/07,
 Stefan Kilp [sk-software] [EMAIL PROTECTED] wrote:

 hi,

 if have two elements (a image in a table) which have a click event registered (on 
img and
 tr element). if i click on the img in the table both click events are 
executed. i would expect

 that only the first element in the z-order gets the click event.

 it there something i missed, how can i change the behavior?

 thanks
 stefan
 --
 Stefan Kilp
 SK-Software, Entwicklung  Beratung


 email: [EMAIL PROTECTED]

 fon  : +49 6151 93344-0
 fax  : +49 6151 93344-20
 Herta-Mansbacher-Str. 98
 64289 Darmstadt, Germany.
 -






 --
 (J)(a)(k)(e) -






--
Stefan Kilp
SK-Software, Entwicklung  Beratung

email: [EMAIL PROTECTED]

fon  : +49 6151 93344-0
fax  : +49 6151 93344-20
Herta-Mansbacher-Str. 98
64289 Darmstadt, Germany.
-




[jQuery] Re: Interacting with TR an TD

2007-04-28 Thread Ian Struble



[...] isn't there a big performance impact using this piece of code?


That's why I said play around a bit ;^)  I threw that idea out there
mostly because it is sort of inside-out from style that I would
probably have tried first and it was just building off the previous
example.  That sort of thing helps me get out of a rut sometimes.  My
first stab at it would have normally been closer to Mike's #2
suggestion; a nested for loop for the td's.

Just out of curiosity is there a way to break out while iterating with
.each()? Again building on the previous example (Mike's #2 this time):

$(function() {
  $('tr').each( function() {
  var allEmpty = true;
  $('td', this).each(funcion() {
  if(this.innerHTML !== 'nbsp;' ) {
  allEmpty = false;
  // Is it possible to break out of the td.each() here?
  }
  });
  allEmpty  $(this).addClass( 'allEmptyTds' );
  });
});

Mike - Thanks but I can't take credit for mark and sweep.  I think I
got it while working on garbage collection in an OS class years ago.

On 4/27/07, Feed [EMAIL PROTECTED] wrote:


Thanks Ian, it seem to be working perfectly. I just have one more
question: isn't there a big performance impact using this piece of
code? It looks like the page it taking a while do load, but I guess
you have to choose between the time the page takes to load and the
time you take to do everything manually.. am I right?

On Apr 28, 1:20 am, Ian Struble [EMAIL PROTECTED] wrote:
 Building on Karl's example and your new all-td's-must-be-empty
 requirement; mark all the TR's with a target class then sweep through
 the TD's and get rid of the target class if you find a td that is not
 empty.   Play around a bit and see what else you can come up with.

 Ian
 

 $(document).ready(function() {
   $('tr').addClass('allEmptyTds');// mark
   $('td').each(function() {
 var $this = $(this);
 if ($this.html() !== 'nbsp;') {
   $this.parent().removeClass('allEmptyTds');  // and sweep
 }
   });

 });

 On 4/27/07, Feed [EMAIL PROTECTED] wrote:



  Feed wrote:
   Hello all, I'm getting used to the excellent jQuery library and I need
   some help of more experienced programmers. I have this simple table:

   table class=table
 tr
 tdcontent/td
 tdcontent/td
 tdcontent/td
 /tr
 tr
 tdnbsp;/td
 tdnbsp;/td
 tdnbsp;/td
 /tr
 tr
 tdcontent/td
 tdcontent/td
 tdcontent/td
 /tr
   /table

   What I need is to add a class to the TRs that have children TDs that
   have nbsp; inside (and ONLY nbsp;)... I'm having problems because
   nbps; is not text, it's html code...

   Thanks in advance!

  Thanks guys, that really helped, specially Karl Swedberg's piece of
  code. The problem is: the class must only be applied to the TR only if
  ALL children TDs have nbsp; inside... I'm having a hard time making
  it work, I'm still learning how to use jQuery properly.




[jQuery] Re: Interacting with TR an TD

2007-04-28 Thread Ian Struble


On 4/28/07, Michael Geary [EMAIL PROTECTED] wrote:

Indeed there is, return false. See my #1 example which is similar to
yours...


I should have used my eyes before I started typing.  My question's
code is almost exactly what you wrote, just cosmetic differences.  I
missed the assignment + return (return empty = false) on my first
read.  Glad I asked it though, it is definitely in my quiver now.

Thanks,
Ian


[jQuery] Re: Interacting with TR an TD

2007-04-27 Thread Ian Struble


Building on Karl's example and your new all-td's-must-be-empty
requirement; mark all the TR's with a target class then sweep through
the TD's and get rid of the target class if you find a td that is not
empty.   Play around a bit and see what else you can come up with.

Ian


$(document).ready(function() {
 $('tr').addClass('allEmptyTds');// mark
 $('td').each(function() {
   var $this = $(this);
   if ($this.html() !== 'nbsp;') {
 $this.parent().removeClass('allEmptyTds');  // and sweep
   }
 });
});

On 4/27/07, Feed [EMAIL PROTECTED] wrote:



Feed wrote:
 Hello all, I'm getting used to the excellent jQuery library and I need
 some help of more experienced programmers. I have this simple table:

 table class=table
   tr
   tdcontent/td
   tdcontent/td
   tdcontent/td
   /tr
   tr
   tdnbsp;/td
   tdnbsp;/td
   tdnbsp;/td
   /tr
   tr
   tdcontent/td
   tdcontent/td
   tdcontent/td
   /tr
 /table

 What I need is to add a class to the TRs that have children TDs that
 have nbsp; inside (and ONLY nbsp;)... I'm having problems because
 nbps; is not text, it's html code...

 Thanks in advance!

Thanks guys, that really helped, specially Karl Swedberg's piece of
code. The problem is: the class must only be applied to the TR only if
ALL children TDs have nbsp; inside... I'm having a hard time making
it work, I'm still learning how to use jQuery properly.




[jQuery] Re: What does this do - transport.setRequestHeader(connection, close)

2007-04-18 Thread Ian Struble


At the risk of beating a dead horse; a few links to related (and
fixed) bugs in other projects (including firefox).

The root cause of the hack (Dan just touched on it):
 https://bugzilla.mozilla.org/show_bug.cgi?id=246651

Message reporting that the above bug was fixed in the 11 Sep 2004 build :
 http://forums.mozillazine.org/viewtopic.php?p=788974

Two bugs from prototype (the second is marked duplicate):
 http://dev.rubyonrails.org/ticket/5606
 http://dev.rubyonrails.org/ticket/5809

With this info, the discussion we have already had in this thread,
Jake's beforeSend tip and a bit of luck, we might be able to get away
with one more message on the subject.   One saying that the close
code/work around has gone away.

Ian

On 4/18/07, Dan G. Switzer, II [EMAIL PROTECTED] wrote:


Jörn,

if ( xml.overrideMimeType )
   xml.setRequestHeader(Connection, close);

I'm still not sure when that is really necessary to set. Could someone
summarize the conclusion from this thread?

In older Gecko builds v1.0.x, the content length was incorrect unless you
passed in the connection close instruction. This meant that your AJAX
packets would get corrupted.

-Dan




[jQuery] Re: What does this do - transport.setRequestHeader(connection, close)

2007-04-10 Thread Ian Struble


Correct, this was a work around for a pre-1.5 FF issue.  My notes on
it say see mozilla bug #246651 but I remember thinking that jQuery
was using the same work around as another js library (prototype?) and
that that project had its own bug to get rid of the work around.  I
thought I saw that the work around had finally been removed in more
recent versions of jQuery.  I last patched a 1.0.4 version for local
use at work but I think it was there until 1.1.

There was also another reason for explicitly closing the connection
that Jake Cigar(?) asked for when overriding the mime type of the
request.  I forget his reasons for that right now.

Ian

On 4/10/07, Aaron Heimlich [EMAIL PROTECTED] wrote:

I vaguely remember there being some issue with older versions of Firefox
that this solved, but don't quote me on that.


On 4/10/07, Priest, James (NIH/NIEHS) [C] [EMAIL PROTECTED] wrote:

 I've been implementing Dan Switzer's autocomplete plugin on my site and
 I have everything sort of working (thanks Dan!) but ran into an issue
 with authentication.  My site uses Windows Integrated Authentication (on
 IIS) and every Ajax request kicks off a login prompt...

 Dan found this:

http://anotherdan.com/2006/6/8/ajax-and-integrated-windows-authenticatio
 n

 I replaced my compressed jQuery script with the source and commented out
 that line:

 // transport.setRequestHeader(connection, close);

 Which seems to have solved this issue.  But I want to make sure this
 doesn't screw up anything else??

 Also - how can I re-compress my source with this modification included?

 Thanks,
 Jim




--
Aaron Heimlich
Web Developer
[EMAIL PROTECTED]
http://aheimlich.freepgs.com


[jQuery] Re: What does this do - transport.setRequestHeader(connection, close)

2007-04-10 Thread Ian Struble

Ditto :)

On 4/10/07, Ⓙⓐⓚⓔ [EMAIL PROTECTED] wrote:

thank you John, it always bothered me!


On 4/10/07, John Resig [EMAIL PROTECTED] wrote:

 Personally, I think this fix should just be removed - especially
 considering that we don't even support versions of Firefox, that old,
 any more.

 --John

 On 4/10/07, Dan G. Switzer, II  [EMAIL PROTECTED] wrote:
 
  I vaguely remember there being some issue with older versions of
Firefox
  that this solved, but don't quote me on that.
 
  Oddly enough, Ajaxian just had reference to a blog entry that talks
about
  Prototype's fix for this:
 
  /* Force Connection: close for older Mozilla browsers to work
  * around a bug where XMLHttpRequest sends an incorrect
  * Content-length header. See Mozilla Bugzilla #246651.
  */
  if (this.transport.overrideMimeType 
  (navigator.userAgent.match(/Gecko/(d{4})/) ||
   [0,2005])[1] 2005)
headers['Connection'] = 'close';
 
  As you can see, they only do the Connection: close header if you're
  running a Gecko version in a certain year. I'd imagine they're doing
this to
  fix other issues--such as the issue Jim is pointing out.
 
  While I know that generally Browser sniffing is frowned upon, I can see
why
  they're doing it in this case--because there doesn't appear to be any
kind
  of DOM sniffing trick you can use. We could do:
 
  // Make sure the browser sends the right content length
  if ( xml.overrideMimeType  !document.all )
  xml.setRequestHeader(Connection, close);
 
  That might fix the problem, but I wonder if sending the Connection:
close
  string causes issues in other browsers outside of IE.
 
  -Dan
 
 




--
Ⓙⓐⓚⓔ - יעקב   ʝǡǩȩ   ᎫᎪᏦᎬ