SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 30 of 30
  1. #26
    SitePoint Addict
    Join Date
    Aug 2005
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JVLB
    Perhaps not, but it has been a reality in the computing world for decades.
    I've been a software engineer for decades, designing software for scientific and medical devices with lots of hardware and multiple processors and we would never dream of doing this. One product I'm working on now has three processors and one of the processors has >25 threads - we'd be screwed if we tried to do it with timeouts.
    It isn't fair to blame JavaScript for the limitations of the world it inhabits. That said, yes everything in the world of the browser is like this. It isn't just JavaScript, it's CSS .
    In another forum here people are telling me to forget Javascript and use PHP for this. Does that have the same problems?

  2. #27
    SitePoint Enthusiast ceetee's Avatar
    Join Date
    Apr 2005
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure if this is what you're after. But simply repeatedly testing for the image dimension works for IE and Mozilla. You can see it working here Photo Search . Hope it makes sense.

    The only thing you have to look out for is changing the image but not the file name. Mozilla detects a new dimension and content, IE refreshes the content only.

    function popup(img)
    {
    newImage= new Image();
    newImage.src=img;
    testImage(img);
    }


    function testImage(img)
    {
    if((newImage.width!=0) && (newImage.height!=0))
    {
    openWindow(img);
    }
    else
    {
    funcTestImage="testImage('"+img+"')";
    interval=setTimeout(funcTestImage,100);
    }
    }

    openWindow(img)
    {
    blah blah;
    }

  3. #28
    SitePoint Addict
    Join Date
    Aug 2005
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ceetee

    function testImage(img)
    {
    if((newImage.width!=0) && (newImage.height!=0))
    {
    openWindow(img);
    }
    else
    {
    funcTestImage="testImage('"+img+"')";
    interval=setTimeout(funcTestImage,100);
    }
    }
    OK, I admit there's a certain devious (or is it deviant? ) cleverness to this approach. I'll try it when I get home tonight. But the hard-coded version I described a few answers back works fine and seems safer.

    One thing I'd be worried about with your approach is that Javascript is (nominally) single-threaded. So as long as it's sitting in a loop testing stuff, if the load activity is in (or dependent on) that same thread then it will never load, or at least never know that it's loaded, while the tests are going on. It'd be interesting to put a counter in there and see how many tries it took.

    Of course the details of the threading model are, like everything else in Javascript, implementation-dependent and subject to change But it's an interesting idea.

  4. #29
    SitePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP cannot open a window at the client, only JavaScript can, but PHP (or other server languages) can more directly read the dimensions of a graphic and pass those to JavaScript. It is probably a preferable approach.

    I have to apologize, I meant to mention that approach earlier, but apparently forgot. To actually pass the dimension variables to JavaScript on the fly, you'll probably need to look into AJAX.

    For a quick fix with only 32 images, however, you might simply create a .js file that is an associative array with image dimensions indexed by filename. It then would be easy to pair the dimensions with the URL of the file being downloaded and set the window size accordingly.

    Depending on how often the file list changes, maintaining the .js file may or may not be burdensome. You could also use the contents of the .js file to construct your page, but that would make your page too dependent on JavaScript.

  5. #30
    SitePoint Addict
    Join Date
    Aug 2005
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JVLB
    PHP cannot open a window at the client, only JavaScript can, but PHP (or other server languages) can more directly read the dimensions of a graphic and pass those to JavaScript. It is probably a preferable approach.

    I have to apologize, I meant to mention that approach earlier, but apparently forgot. To actually pass the dimension variables to JavaScript on the fly, you'll probably need to look into AJAX.

    For a quick fix with only 32 images, however, you might simply create a .js file that is an associative array with image dimensions indexed by filename. It then would be easy to pair the dimensions with the URL of the file being downloaded and set the window size accordingly.

    Depending on how often the file list changes, maintaining the .js file may or may not be burdensome. You could also use the contents of the .js file to construct your page, but that would make your page too dependent on JavaScript.
    As I said, I have a perfectly good, simple, foolproof, working solution. Since, for every thumbnail I have to call a Javascript function with the name of the file (e.g., "foo.jpg"), a caption, and a background color, it's not THAT much harder to add height and width parameters, so that's what I've done. It's a bit brute force but it's extremely simple and reliable.

    Doing it in AJAX/PHP would add a level of server-side programming currently not necessary. Doing it in an associative array would require a separate array for every gallery (there are 8 galleries), which would make the .js file dramatically bigger and harder to maintain, and it would mean that every time I had a new image I'd have to change it in two places - the HTML file AND the .js file.


Bookmarks

Posting Permissions

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