SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member Randy_A's Avatar
    Join Date
    Mar 2004
    Location
    Sugar Land, Tx
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question X or CBE xInclude() and window.onload=

    I'm Green (new) or really just a seedling, without any green showing, yet.
    I grabbed the X lib and example xMenu 2 and played with it.
    Question: Does anyone know of a reason this would not work cross-browser (see below)? It is working for me, now, in IE 5, but it is the only browser I have to test with.

    <script type='text/javascript' src='../js/x_load.js'></script>
    <script type='text/javascript'>
    if (xInclude('../js/x.js','../menu/xmenu_html.js','../js/x_menu2.js')) {
    window.onload = function(){ setTimeout('winOnload()',1000); }
    // winOnload() is found in ../menu/xmenu_html.js
    }
    </script>

    using just window.onload=winOnload; did not work giving a "winOnload" is undefined error, but with the setTimeout did...

  2. #2
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Randy,

    Small world... I am originally from Sugar Land (went to Dulles High School).

    Could you put a link to where you have this script running? I can check it with Firefox .8

  3. #3
    SitePoint Member Randy_A's Avatar
    Join Date
    Mar 2004
    Location
    Sugar Land, Tx
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Hartmann
    Randy,

    Small world... I am originally from Sugar Land (went to Dulles High School).

    Could you put a link to where you have this script running? I can check it with Firefox .8
    "It" was not uploaded, so I did that, had problems, then a backbone some where when down and I could not get back here to sitepoint til now. I hate Yahoo, ads generating errors, uploads adding crap to or mergeing files... So I looked harder and found www.1asphost.com . Link http://ee.1asphost.com/AhhAgain/cprs/menu/xmenu.htm .

  4. #4
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I just checked it out in FireFox .8 and it works!

  5. #5
    SitePoint Member Randy_A's Avatar
    Join Date
    Mar 2004
    Location
    Sugar Land, Tx
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks

    Quote Originally Posted by Hartmann
    I just checked it out in FireFox .8 and it works!
    Now on to putting something real in it.

  6. #6
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Randy, welcome to SitePoint Forums!

    Thanks Hartmann!

    I'm not ignoring this thread. Been very busy this weekend and I'm working on a response now. xInclude is quite experimental and I'm working on another version of it. I'll be back later tonight.

  7. #7
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are a couple of 'moving targets' in the X library right now... xInclude is one of them.

    I would like to be able to "conditionally include" in javascript, just like I do in C. That's the ultimate purpose for the xInclude experiment. The idea is that each file should only include what it uses. If two different files use xGetElementById - then both of those files should call xInclude('x_core.js') and xInclude will make sure that x_core.js is only included once. xInclude will also use x_core_nn4.js instead of x_core.js, if the browser is NN4.

    The problem is that (like Randy) I've run into a few situations where it seems that window.onload is called 'before' all the js files get parsed by the browser. So far, I resolved those situations by realising that my order of 'includes' was not appropriate. The demos in my download package are not yet done like this - but here's the idea for a page which has menu and popup code (this assumes that xInclude works as I've described above):

    mainPage.html: xInclude('myApplication.js');

    myApplication.js: if (xInclude('x_core.js', 'menu.js', 'popup.js')) window.onload = ...;

    menu.js: xInclude('x_core.js', 'x_event.js');

    popup.js: xInclude('x_core.js', 'x_event.js', 'x_timer.js');

    x_timer.js: xInclude('x_core.js', 'x_event.js', 'x_dom.js');

    At any rate - that's the idea.

    ***

    Using the xInclude version currently available, and looking at Randy's code and noticing that the onload listener is in 'xmenu_html.js', I suggest the following:

    mainPage.html: xInclude('xmenu_html.js');

    xmenu_html.js: if (xInclude('../js/x.js', '../js/x_menu2.js')) window.onload = winOnload;

    ***

    The following is my current xInclude. Its not optimized - it is very much experimental - but I'm open to suggestions and constructive criticism.

    Code:
    if (!window.xIncludeList) {
      window.xIncludeList = new Array();
    }  
    
    function xInclude(url1, url2, etc)
    {
      if (document.getElementById || document.all || document.layers) { // minimum dhtml support required
        var h, f, i, j, a, n, inc;
    
        for (var i=0; i<arguments.length; ++i) { // loop thru all the url arguments
    
          h = ''; // html (script or link element) to be written into the document
          f = arguments[i].toLowerCase(); // f is current url in lowercase
          inc = false; // if true the file has already been included
    
          // extract the filename from the url
          // (should I do this? what if there are two files with the same name but in different directories?)
          a = f.split('/');
          n = a[a.length-1]; // the file name
    
          // loop thru the list to see if this file has already been included
          for (j = 0; j < xIncludeList.length; ++j) {
            if (n == xIncludeList[j]) {
              inc = true;
              break;
            }
          }
    
          if (!inc) { // if the file has not yet been included
    
            xIncludeList[xIncludeList.length] = n; // add it to the list of included files
    
            // is it a .js file?
            if (f.indexOf('.js') != -1) {
              if (xNN4) { // if nn4 use nn4 versions of certain lib files
                var c='x_core', e='x_event', n='_nn4';
                if (f.indexOf(c) != -1) { f = f.replace(c, c+n); }
                else if (f.indexOf(e) != -1) { f = f.replace(e, e+n); }
              }
              h = "<script type='text/javascript' src='" + f + "'></script>";
            }
    
            // else is it a .css file?
            else if (f.indexOf('.css') != -1) { // CSS file
              h = "<link rel='stylesheet' type='text/css' href='" + f + "'>";
            }    
            
            // write the link or script element into the document
            if (h.length) { document.writeln(h); window.status = h; }
    
          } // end if (!inc)
        } // end outer for
        return true;
      } // end if (min dhtml support)
      return false;
    }
    Please keep in mind that I'm not doing this as a web developer - I'm doing this as a dhtml hobbyist at least, that's the hat I have on at this moment

  8. #8
    SitePoint Member Randy_A's Avatar
    Join Date
    Mar 2004
    Location
    Sugar Land, Tx
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks, I have to leave soon, but

    Quote Originally Posted by MikeFoster
    There are a couple of 'moving targets' in the X library right now... xInclude is one of them.
    I thought I'd shoot off something and get back with you later, after I've had
    more time to look at your response.

    in the mean time, what browser are you using? and take a look-see
    at this I slammed together to view all properties and style attributes of
    any element, I used your x stuff (code) Uknown if it works on anything other than my browser IE 5.00.???? http://ee.1asphost.com/AhhAgain/jsco...Properties.htm

  9. #9
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Randy,

    Very slick!

    I had a very quick look with the following browsers (all on Win2K):

    Opera 7.23 - works.

    IE 6.0 - works.

    Mozilla 1.6 - doesn't work.

    Maybe later tonight I'll have a chance to look at the code.

  10. #10
    SitePoint Member Randy_A's Avatar
    Join Date
    Mar 2004
    Location
    Sugar Land, Tx
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Very good, so far.

    Quote Originally Posted by MikeFoster
    Hi Randy,

    Very slick!

    I had a very quick look with the following browsers (all on Win2K):

    Opera 7.23 - works.

    IE 6.0 - works.

    Mozilla 1.6 - doesn't work.

    Maybe later tonight I'll have a chance to look at the code.

    Good, glad to hear that.
    I'm busting my nuts trying to debug and make reason of this **** ...
    (not your stuff) just everything in general. That's my 1st ANYTHING
    written in javascript. I figured I needed a window into understanding
    what values are making the elements do what and cause syntax errors can
    make you nuts in HTML, CSS and Javascript.

    Speed is a major problem with it (on my 350 mhz), it takes just under 2
    seconds to display. I worked some on the speed issues, that I know of.
    It was taking over 5 seconds before I tweeked it some.

    Other than the speed issue, killing the host site's ad would be nice.
    BUT !!!
    I could not get 'delete' to work? How do you trash/dump/destroy/void/null
    or nothing an object or an element ? (see file http://ee.1asphost.com/AhhAgain/jscode/elemprop/init.js )

    Nice extra, would be simulated auto-scrolling of the page. Ideas ?


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
  •