Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: Accessible Scripting 101: Discussion

  1. #1
    Join Date
    Jul 2003
    Boston Area, Massachusetts

    Accessible Scripting 101: Discussion

    See the relevant sticky:


    What do you think? Got anything to add?

  2. #2
    Join Date
    Nov 2002
    Nashua, NH
    Since the rotating banners seemed to be the favourite topic of the week, I'm making the first submission:
    LESSON 1. Rotating Banners.

    Shrek: - For your information, there's a lot more to ogres than people think.
    Donkey: - Example?
    Shrek: - Example? Okay. Uh... ogres are like onions.
    Donkey: - They stink?
    Shrek: - Yes. No!
    Donkey: - Oh, they make you cry?
    Shrek: - No!
    Donkey: - Oh, you leave them out in the sun, they get all brown and start sprouting little white hairs.
    Shrek: - No! Layers! Onions have layers. Ogres have layers. Onions have layers. You get it? We both have layers.
    Fundamental Accessibility Principle

    Separation of structure from presentation is the cornerstone of accessible web design. This is the first core technique that is discussed whenever the subject of accessibility is brought up. This separation is achieved by using HTML to describe document structure and CSS to describe document presentation for different types of media.
    The two are often compared to layers, HTML being the core layer accessible to all devices and CSS an optional outer layer for the devices capable of interpreting it.

    When it comes to accessibility and client side scripting the same methodology should be applied. Scripting is just another layer that provides advanced functionality on top of the existing content and presentation.

    Any web site will have up to three layers:
    - HTML defining document structure
    - CSS defining document presentation
    - JS providing additional functionality

    When these layers are designed from core out, the accessibility is assured by the design process - each underlying layer is made to work before proceeding to the next one.

    Rotating Banner Requirements
    Links to affiliate web sites are not only for human visitors. Actually, human visitors rarely use those links - just think about how many times did you click on an advertisement banner in the past day or week. The greater advantage for having other sites link to yours is the better search engine rating. But this will only work if these links are accessible to the search engine bots.
    Therefore, it only makes sense to have all affiliate links that make up rotating banners presented in HTML code.

    Core Layer - Document Structure - HTML
    The proper presentation for rotating banners is the list of links that can optionally be enclosed within a block element that also contains a heading:
    <div id="banners">
      <h4>Affiliate Links</h4>
        <li><a href="www.google.com"><img alt="Search Web with Google" src="googlelogo.png"></a></li>
        <li><a href="www.yahoo.com"><img alt="Search Web with Yahoo" src="yahoologo.png"></a></li>
        <li><a href="www.msn.com"><img alt="Search Web with MSN" src="msnlogo.png"></a></li>
    Presentation Layer - CSS
    It is a reasonable assumption that the banner list will be placed towards the end of the HTML document while its presentation in the graphical browser will usually be at the top of the page. This can be achieved using the absolute positioning of the block containing the banners:
      { position: absolute;
        top: 10px; /* top coordinate */
        right: 10px; /* puts banners in the top right corner */
    Users of graphical browsers do not really need to see the header as the images are self explanatory. Also, the default border around images inside links is usually removed. And we want to make sure that there are no margins and padding that can affect presentation:
    #banners h4
      { display: none;
    #banners img
      { border: none;
    #banners ul, #banners li, #banners a, #banners img
      { margin: 0;
        padding: 0;
    Another reasonable assumption is that all the banner images are of the same size. For illustration purposes let's say 200px wide by 80px high. We can make the height of the banners list the same as the images and setting the overflow to hidden will cause only the first banner visible as the default presentation of the page.
    #banners ul
      { display: block;
        height: 80px;
        overflow: hidden;
    #banners li
      { display: block;
        list-item-style: none;
    Another option is to set the overflow to auto for the banners list so that visitors can scroll through the list of all banners, making them accessible without significant impact (extra scrollbar) on the presentation.

    Advanced Functionality Layer - Javascript
    Now that the banners were made accessible with the basic HTML and CSS design, we can add the extra scripting functionality that will show them one at a time automatically.
    It is a good practice to encapsulate such behavior within a class (reasoning for this is beyond the scope of current discussion). I decided to name it lIterator (scripting literacy is as important as iterating through a list ). The basic template I use is as follows
    function lIterator(listElement,delay)
      { /* Constructor */ 
        /* Dynamic Methods */
    /* Static Properties */
    /* Static Methods */
    We start by writing the constructor for the class.
    First order of business is to remove all extra nodes from the ul element passed to the constructor. These could be empty text nodes added to document tree by compliant browsers, comment nodes, or HTML nodes that do not belong within the list element:
        for(var i=listElement.childNodes.length-1; i>=0; i--) 
    Next step is to hide all the list items but first one
        for(var i=1; i<listElement.childNodes.length; i++)
    	    listElement.childNodes[i].style.display = 'none';
    Then add a dynamic property to the class that will store the pointer to the currently displayed list item:
        this.currentLI = listElement.firstChild;
    Now, we need to address the timer function. Since the dynamic class method can not be passed to setInterval we create a static array containing all the class instances:
    /* Static Properties */
    lIterator.instances = new Array();
    so that next step for the constructor would be to store the class there and add another property that stores its ID:
        this.id = lIterator.instances.length;
    Now we can finish the constructor by calling the setInterval function that will start the iteration:
    All that is left to do is write the showNext() dynamic method:
    /* Dynamic Methods */
    	this.showNext = function()
    	  { this.currentLI.style.display = 'none';
    	    /* Following line is broken for readability */
    		this.currentLI =
    		    this.currentLI.nextSibling ?
                    this.currentLI.nextSibling :
    		this.currentLI.style.display = 'block';
    Now that the lIterator class is complete, instances need to be created when the page loads. Taking into consideration the HTML code above the onload event will be:
    onload="new lIterator((document.getElementById('banners')).getElementsByTagName('ul')[0],1000);"
    Lesson 1 Quiz.
    What modifications have to be done to the JS code so that it can be used to implement the basic slideshow functionality?
    Last edited by Vladdy; 04-08-2005 at 10:46 PM.

    Working web site is not the one that looks the same in a few graphical browsers, but the one that adequately delivers its content to any device accessing it.

  3. #3
    Join Date
    Feb 2005
    To make a script for this, can I just make an accessible script? Or do I have to go through it with detailed notes the way Vladdy has?

  4. #4
    Join Date
    Jan 2003
    Quote Originally Posted by BigMoosie
    To make a script for this, can I just make an accessible script? Or do I have to go through it with detailed notes the way Vladdy has?
    Originally posted by fredmv
    If you feel you have a worthy addition (i.e., an accessible script), feel free to PM me. What you should first do, however, is create a thread here in the JavaScript section explaining what it does, an example of how it use it, etc. which will be left open for discussion among the other members (e.g., if they need help setting it up on their site).
    Looks to me like you should create a thread with the script, some examples on its use, how to use it, and so on and so forth. So, yes, you must explain the basics of it, but it's advisable to explain it step-by-step. Helps to avoid confusion and questions by others who want to use it.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  5. #5
    Join Date
    Jan 2005
    San Diego, CA
    First of all, I appricate you, fredmv, giving us a "back door" to discuss your sticky, thanks!
    Quote Originally Posted by fredmv
    Welcome to the "Accessible Scripting 101" thread. This thread will feature JavaScript scripts developed with accessibility in mind. In other words, these are scripts in which will degrade properly in the case that JavaScript isn't available to your end-user (which it isn't always, believe it or not).
    I don't quite understand what kind of codes
    (I wouldn't call anything relevant to the computer a "script" because scripts are for actors and programs are code for the computer)
    that you are looking for.
    If the user has javascript disabled, what do you want from him/her!?
    are you telling me that there JavaScript statements that still work even when JS is turned off!?

    Can you explain a bit clearer what you had in mind, please? I'm sorry if I'm the only one confused.

  6. #6
    Join Date
    Jul 2004
    Canada, eh
    The idea is to make scripts such that, even with scripting disabled, the user will not miss out on any important information.

    For example, people often create sections of a page that are hidden and can be expanded/made visible with javascript. In this case, it is important that the hidden sections be visible at the start, and are then be hidden by the script, so that a user without javascript will be able to view all of the content.
    Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.

  7. #7
    Join Date
    Jan 2003

    As the name suggests, JavaScript is a scripting language. I see no reason why the homonym should not be used. It refers to a specific kind of code (usually pretranslated if I'm not mistaken).

    Anyway, what Fred is referring to when he says "degrade" is that the web site still works when JavaScript is disabled. In other words, say for some reason you want to update the content of a P tag ten seconds after the page loads. You can do this:

    <p id="myPara"></p>
    <script type="text/javascript"><!--
     if(document.getElementsByTagName) onload = function(){
       var t = setTimeout("document.getElementById('myPara').innerHTML = 'Some text.'; clearTimeout(t)", 10000);
    The problem, though, is that the content "Some text." will never be available to anyone without JavaScript. Instead of doing the above, you should make it degrade gracefully, like so:

    <p id="myPara">Some text.</p>
    <script type="text/javascript"><!--
     if(document.getElementById) document.getElementById("myPara").style.display = 'none';
     if(document.getElementById) onload = function(){
      var t = setTimeout('document.getElementById("myPara").style.display = "block"; clearTimeout(t)', 10000);
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  8. #8
    Join Date
    Jan 2005
    San Diego, CA
    Jona, I don't understand Why you changed the content inside of the SCRIPT tag.
    Why couldn't you just leave the content inside of the SCRIPT tag alone?
    <p id="myPara">Some text.</p>
    <script type="text/javascript"><!--
     if(document.getElementsByTagName) onload = function(){
       var t = setTimeout("document.getElementById('myPara').innerHTML = 'Some text.'; clearTimeout(t)", 10000);

  9. #9
    Join Date
    Jan 2003
    Because users without JavaScript won't see what's in the SCRIPT tags. As a result, we need to have the content in the HTML already, and hide it as soon as it's loaded, then display it whenever we want.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  10. #10
    Join Date
    Feb 2005
    EDIT: what that JONA sayed ^

  11. #11
    Join Date
    Jan 2005
    San Diego, CA
    Oh, I see, so the purpose of your example is to have text which blinks on and off once...
    Then you wanted users w/o JS enables to simply display the text but without any fancy maneuvers.

  12. #12
    Join Date
    Jan 2003
    Not exactly.

    The purpose of my example was to display text that is otherwise hidden ten seconds after the page loads. The first example was a bad way to do it, because if JavaScript was not enabled, the user would not ever get to see the text. The second example is an improvement, because users without JavaScript will see the text.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  13. #13
    Join Date
    Jan 2005
    San Diego, CA
    Well, 'cas I'm one of the intellectual type, I thought this should be introduced:
    I personally think that the best way to back-up JavaScript is with the <NOSCRIPT> tag.
    If you don't already know what the tag does, it is used to display its contents only when JavaScript is disabled.
    (If JavaScript is enabled, the tag's contents is totally ignored.)

    Here is a starter-level example:
    document.write("<font color=royalblue>JavaScript is enabled</font>")
    <font color=red>JavaScript is disabled</font>

  14. #14
    Join Date
    Jan 2003
    I see the NOSCRIPT tag as a last resort. It makes things more flexible, easy, and manageable if you script with accessibility in mind. That way you don’t have to rely on the NOSCRIPT tag.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  15. #15
    Join Date
    Feb 2005
    So perhaps a better solution would be:
    <SPAN style="color: red;" id="JSenabled">JavaScript is disabled</SPAN>
    <SCRIPT LANGUAGE="javascript" TYPE="text/javascript">
    var subject=document.getElementById("JSenabled");
    subject.firstChild.nodeValue="JavaScript is enabled";

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.14272 seconds
  • Memory Usage 3,058KB
  • Queries Executed 15 (?)
More Information
Template Usage (37):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (18)bbcode_code
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (15)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (15)postbit
  • (15)postbit_onlinestatus
  • (15)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (74):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates