SitePoint Sponsor

User Tag List

Results 1 to 21 of 21

Thread: Enhancing Structural Markup with JavaScript

  1. #1
    ********* Articles ArticleBot's Avatar
    Join Date
    Apr 2001
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Discussion thread for Enhancing Structural Markup with JavaScript

    This is a dedicated thread for discussing the SitePoint article 'Enhancing Structural Markup with JavaScript'

  2. #2
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,463
    Mentioned
    35 Post(s)
    Tagged
    1 Thread(s)
    maybe it's me, but i didn't see anything on the demo of the panel switching script

    i saw all three panels, all the time

    perhaps it's because i was using internet explorer 6 on windows?


    rudy
    http://r937.com/

  3. #3
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937
    maybe it's me, but i didn't see anything on the demo of the panel switching script

    i saw all three panels, all the time
    That's because the easytoggle.js script which accompanies the example doesn't appear to be on the server - I've emailed SitePoint and pointed out the error. In the meantime you can see a demo that uses a very slightly older version of the code here:

    http://simon.incutio.com/code/js/eas...e/example.html

    It works fine in IE5, 5.5 and 6. Older browsers (such as NS4 and IE4) display all of the panels at once which at least means the data in them is still accessible.

  4. #4
    SitePoint Zealot Octal's Avatar
    Join Date
    Feb 2003
    Location
    UK
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Moved on since the days of Gameplay and the 'Hub I see!

    Nice article mate, the first of many hopefully
    Octal - All your base-8 belong to us
    "Knowing is not enough, we must apply.
    Willing is not enough, we must do." - Bruce Lee

  5. #5
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Moved country as well I'm in the United States for a year on placement before heading back to the UK to finish my degree.

  6. #6
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  7. #7
    SitePoint Zealot Octal's Avatar
    Join Date
    Feb 2003
    Location
    UK
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So when's your first Sitepoint book coming out?
    Octal - All your base-8 belong to us
    "Knowing is not enough, we must apply.
    Willing is not enough, we must do." - Bruce Lee

  8. #8
    Anonymous
    SitePoint Community Guest
    I have tried substituting an image for the text link, but it doesn't work, why is this?

  9. #9
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried using an image instead of the text link, but it doesn't work, it just gives me an empty screen. Why is this?

  10. #10
    Anonymous
    SitePoint Community Guest
    I find this article very useful. I've used similar approachs on my webpages, like building tables of contents, or even building menus with links. In other words, it's like a javascript approximation to XSLT or one of those transformation languages that enhance the look of your code.

    Two thumbs up!

    Rick

  11. #11
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Where's the point?

    What's the point of posting on this forum if I don't get an answer? Is anyone reading this post at all?! I will post my question again.

    I have tried to use an image link instead of a text link to call the panels, however, when I do so, all i get is a blank screen. Is there a work around for this?

  12. #12
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by vchau76
    What's the point of posting on this forum if I don't get an answer? Is anyone reading this post at all?! I will post my question again.

    I have tried to use an image link instead of a text link to call the panels, however, when I do so, all i get is a blank screen. Is there a work around for this?
    Can we see your code, so we know what you're talking about? That's generally more helpful and will get you more responses.

  13. #13
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia
    Can we see your code, so we know what you're talking about? That's generally more helpful and will get you more responses.
    Code:
    /* easytoggle2.js
       - Simon Willison, 5th November 2003
       - See http://simon.incutio.com/archive/2003/11/06/easytoggle
    */
    addEvent(window, 'load', et_init);
    var et_toggleElements = [];
    /* Initialisation */
    function et_init() {
    	var i, link, id, target, first;
    	first = true;
    	for (i = 0; (link = document.links[i]); i++) {
    		if (/\btoggle\b/.exec(link.className)) {
    			id = link.href.split('#')[1];
    			target = document.getElementById(id);
    			et_toggleElements[et_toggleElements.length] = target;
    			if (first) {
    				first = false;
    			} else {
    				target.style.display = 'none';
    			}
    			link.onclick = et_toggle;
    		}
    	}
    }
    function et_toggle(e) {
    	/* Adapted from http://www.quirksmode.org/js/events_properties.html */
    	if (typeof e == 'undefined') {
    		var e = window.event;
    	}
    	var source;
    	if (typeof e.target != 'undefined') {
    		source = e.target;
    	} else if (typeof e.srcElement != 'undefined') {
    		source = e.srcElement;
    	} else {
    		return true;
    	}
    	/* For most browsers, targ would now be a link element; Safari however
    	   returns a text node so we need to check the node type to make sure */
    	if (source.nodeType == 3) {
    		source = source.parentNode;
    	}
    	var id = source.href.split('#')[1];
    	var elem;
    	for (var i = 0; (elem = et_toggleElements[i]); i++) {
    		if (elem.id != id) {
    			elem.style.display = 'none';
    		} else {
    			elem.style.display = 'block';
    		}
    	}
    	return false;
    }
    /* Thanks to Scott Andrew */
    function addEvent(obj, evType, fn){
    	if (obj.addEventListener) {
    		obj.addEventListener(evType, fn, true);
    		return true;
    	} else if (obj.attachEvent) {
    		var r = obj.attachEvent("on"+evType, fn);
    		return r;
    	} else {
    	 return false;
    	}
    }
    This is the easytoggle2.js script which I downloaded from the article.

    So instead of using a text link like this: <a href="#panel1" class="toggle">View</a>. I want to use an image link like this <a href="#panel1" class="toggle"><img src="image.gif"></a>. However, when I try to do this method all I get when I click on the image link is a blank screen and the panels don't show up.

  14. #14
    Anonymous
    SitePoint Community Guest
    Doesn't work in Mac IE5

  15. #15
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question No help?

    Ok, I have patiently waited to see if anyone could help me with this issue of using an image instead of a text link to switch panels and still no reply. I am starting to wonder if anyone reads these forums. Can anyone out there offer a solution to my problem?

  16. #16
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Austin, TX
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Image problem

    Quote Originally Posted by vchau76
    Ok, I have patiently waited to see if anyone could help me with this issue of using an image instead of a text link to switch panels and still no reply. I am starting to wonder if anyone reads these forums. Can anyone out there offer a solution to my problem?
    Hmm. Sure enough, the image doesn't work, but it's not immediately obvioius to me from the code why not. If you throw some text in alongside the image, clicking that seems to work (YMMV).

    Maybe using a FIR technique would work(?).

  17. #17
    Anonymous
    SitePoint Community Guest
    Ok, it seems everyone is asking the same question, and the author is not responding to e-mail enquires, so, any JS guru's care to take a good look at why images do not work with this script? I'm pretty sure everyone reading this would appreciate it greatly. Mr. Willison? Hmmm?

  18. #18
    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)
    In Simon's original code...

    (1) Wrap the IMG elements in the A elements.

    (2) In the function 'et_toggle()', don't use the event target because now the target is the IMG element. Instead, use this, which points to the A element because of...

    link.onclick = et_toggle;


  19. #19
    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)
    Like this...
    Code:
    /* easytoggle.js, by Simon Willison 
       modified by Mike Foster, 24Mar04, Cross-Browser.com */
    
    var et_toggleElements = [];
    
    if (document.getElementById && document.links) window.onload = et_init;
    
    function et_init() {
         var i, link, id, target, first;
         first = true;
         for (i = 0; (link = document.links[i]); i++) {
             if (/\btoggle\b/.exec(link.className)) {
                 id = link.href.split('#')[1];
                 target = document.getElementById(id);
                 et_toggleElements[et_toggleElements.length] = target;
                 if (first) {
                     first = false;
                 } else {
                     target.style.display = 'none';
                 }
                 link.onclick = et_toggle;
             }
         }
    }
    
    function et_toggle(e) {
         var id = this.href.split('#')[1];
         var elem;
         for (var i = 0; (elem = et_toggleElements[i]); i++) {
             if (elem.id != id) {
                 elem.style.display = 'none';
             } else {
                 elem.style.display = 'block';
             }
         }
         return false;
    }

  20. #20
    Bruno
    SitePoint Community Guest
    You can tweak this script to easily choose which panel you want to show as the default (instead of having it always show the first. Like this:

    /* Initialisation */
    function et_init() {
    var i, link, id, target, first;
    /* first = true; remove this declaration*/
    for (i = 0; (link = document.links[i]); i++) {
    if (/\btoggle\b/.exec(link.className)) {
    id = link.href.split('#')[1];
    target = document.getElementById(id);
    et_toggleElements[et_toggleElements.length] = target;

    if /*if the link class includes the word default, set first to true*/
    (/\bdefault\b/.exec(link.className)){
    first = true;

    }
    if (first) {
    first = false;
    } else {
    target.style.display = 'none';
    }
    link.onclick = et_toggle;
    }
    }
    }

    Then all you have to do is include "default" in the class attribute of the link, like so:
    <a href="#youpanel" class="toggle default">Link</a>


  21. #21
    Hallvord R. M. Steen
    SitePoint Community Guest
    The demo scripts in this article contain a bug that will cause them to fail unexpectedly in browsers that support DOM2 Events properly: event handlers are capturing by default. The line

    obj.addEventListener(evType, fn, true);

    should read

    obj.addEventListener(evType, fn, false);

    See
    http://my.opera.com/hallvors/journal/47

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
  •