Invisible if css is enabled, don't click
This shouldn't be displaying, if you have css disabled, don't click

Archive for the 'javascript' Category

Make VS.NET 2008 intellisense a little more intelligent

Thursday, September 11th, 2008

Looking for a solution to Visual Studio 2008’s Intellisense’s poor performance while editing large HTML documents I came across an awesome discovery. You can extend the intellisense to include jQuery (well any framework provided you have it properly documented.) This is awesome because even though I love the new Ajax Control Toolkit in VS.NET 2008 it just doesn’t hold a candle to jQuery and it’s plethora of plugins.

To gain this functionality, first grab the intellisense stub from InfoBasis’ jQuery Intellisense Header Generator, or as I lovingly call it, Ijihg. [Direct Link]

Add it to your project and then the really easy part, drag the file into the javascript file(s) you wish to enable jQuery intellisense on, or you can type in the reference manually

  1. /// <reference path="jquery.intellisense.js" />

You should get something looking like:

And that’s all there is too it. Once you begin coding intellisense will pick up jQuery and make your life a little bit easier. Here’s a couple screens to give you an idea of what you can expect:

Technorati Tags: , ,

Popularity: 21% [?]

Finally an Acid test I’m excited about

Thursday, January 10th, 2008

Now that all major browsers support the Acid2, or at least have announced they have development builds that pass it, Ian “Hixie” Hickson has begun work on the Acid3. The exciting news is that it is going to focus on ECMAScript (aka. Javascript) and the DOM. The first two Acid tests focused mostly on error handling and emerging technologies of CSS. A lot of people tend to assume that if you pass the Acid tests your browser is standards compliant but they fail to realise that CSS is only a portion of Web Standards. They are important, don’t get me wrong, but most browsers are progressing along with support these days and I’m excited the focus is being shifted to an area that is somewhat neglected.

I do a lot of development in ECMAScript and work heavily in the DOM so it’s no end of frustration to support all browser’s quirks. Having the next Acid test focus on this makes me giddy, this will hopefully force Microsoft to support DOM levels 2 and 3, as of right now they only support DOM level 1 and poorly. I’m sure the guys that develop libraries like Prototype.js and jQuery will be equally as excited.

Technorati Tags: , , , , , , , , , ,

Popularity: 80% [?]

Find the position of an element in the DOM [Javascript]

Tuesday, October 23rd, 2007

I ran into a problem of placing an element I created via javascript, it was a calender for a date picker. I wanted the calender to appear directly under the textbox that would accept the selection from the user. This is a deceptively tricky thing to do on websites. This is because it doesn’t store the Top and Left of the element relative to the Top/Left of the current window, rather it stores the Top and Left relative to it’s offsetParent. What’s an offsetParent? It’s the property of an element whose parent affects it’s positioning, this can be it’s actual parent but it can also be a parent further up the tree depending on if it affects its offsetLeft and offsetTop peroperties. If an element is positioned fixed its offsetParent will be null, so you won’t always have to traverse to the top of the DOM tree to get the actual offset of your element relative to the window.

(more…)

Popularity: 87% [?]

Javascript: determine if element (or any of it’s parents) is hidden. Pt. 2 (a better solution)

Monday, December 4th, 2006

I while ago I posted my code to find out if an element is hidden (with added complexity that if it’s parent is hidden it will also be hidden despite the fact that it’s own display style may not be set.) Originally I came up with the following code:

  1. function displayNoneSet(element){
  2. if(element.parentNode == null){
  3. //we’ve reached the top of the tree #document doesn’t have a style property
  4. //this means that no element is set to hidden on the tree from the original element sent
  5. return false;
  6. }else{
  7. if(element.style.display == "none"){
  8. ///We’ve found a node that is hidden
  9. return true;
  10. }else{
  11. //check the element’s parent, I don’t like recursion, but the only way I see this working
  12. return displayNoneSet(element.parentNode);
  13. }
  14. }

Right away I knew it was a less than perfect example of finding what I needed, I prefer to avoid recursion as much as possible. Eventually I came to the realization that I was overthinking the problem and I came up with a much more elegant solution to the problem. And here it is:

  1. function displayNoneSet(element){
  2. while(element.parentNode){
  3. if(element.style.display=="none"){
  4. //if we have found an element on the DOM tree that is not displayed
  5. return true;
  6. }
  7. element=element.parentNode;
  8. }
  9. //if we’ve got to this point no element was found that had style.display set
  10. return false;
  11. }

This I can live with much easier.

Technorati Tags: , , , ,

Popularity: 50% [?]

Javascript: determine if element (or any of it’s parents) is hidden.

Wednesday, October 25th, 2006

I ran into a problem building a webapp today, I needed a way to determine if a specific element is hidden. Most of the time you can just check it’s style display:

  1. if(document.getElementById("someElement").style.display=="none"){
  2. //…do something
  3. }

… but what happens when it’s parent (or parents parent, or parents parents parent, ad nauseum ad infinitum) is hidden? There is no way (I could tell anyways) to tell if an element is hidden as a result of a parent node somewhere being hidden. Someone had suggested that .offsetParent was set to null in Firefox if the element was hidden, it worked, initially. I found out however this doesn’t work in Internet Explorer and even in Firefox elements such as Select never have an offsetParent. So back to the drawing board, and what I came up with was what I originally had thought would be the solution I’d have to use. The reason I didn’t initially develop it was because it uses recursion, I don’t like recursion, it’s inefficient and looks sloppy but without a better solution I came up with the following:

  1. function displayNoneSet(element){
  2. if(element.parentNode == null){
  3. //we’ve reached the top of the tree #document doesn’t have a style property
  4. //this means that no element is set to hidden on the tree from the original element sent
  5. return false;
  6. }else{
  7. if(element.style.display == "none"){
  8. ///We’ve found a node that is hidden
  9. return true;
  10. }else{
  11. //check the element’s parent, I don’t like recursion, but the only way I see this working
  12. return displayNoneSet(element.parentNode);
  13. }
  14. }
  15. }

And there it is in all it’s simplistic glory, if anyone reading has a better solution, I would like to hear it.

Technorati Tags: , , , ,

Popularity: 57% [?]

We did not invent the algorithm. The algorithm killed Jeeves. The algorithm constantly finds Jesus. This is not the algorithm. This is close.