JavaScript DHTML/GUI Components/Toggle

Материал из Web эксперт
Перейти к: навигация, поиск

Create custom page and replace current document with it

   <source lang="html4strict">

<html> <head> <title>Welcome Page</title> <script language="JavaScript" type="text/javascript"> // create custom page and replace current document with it function rewritePage(form) {

   // accumulate HTML content for new page
   var newPage = "<html>\n<head>\n<title>Page for ";
   newPage += form.entry.value;
   newPage += "</title>\n</head>\n<body bgcolor="cornflowerblue">\n";
newPage += "

Hello, " + form.entry.value + "!

\n";
   newPage += "</body>\n</html>";
   // write it in one blast
   document.write(newPage);
   // close writing stream
   document.close();

} </script> <body>

Welcome!


<form onsubmit="return false;">

Enter your name here: <input type="text" name="entry" id="entry">

<input type="button" value="New Custom Page" onclick="rewritePage(this.form);"> </form> </body> </html>


      </source>
   
  


Dynamic Content: click show and re-click disappear (IE)

   <source lang="html4strict">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Dynamic Content</title> <script language="javascript"> // Location of this script: // http://www.qiksearch.ru/javascripts/dynamic_content.htm //********************************************* //* Dynamic Content * //* (c) Premshree Pillai, * //* http://www.qiksearch.ru * //* E-mail : premshree@hotmail.ru * //* Use the script freely as long as this * //* message is intact * //********************************************* document.write("<form name="form1">"); document.write("<input type="hidden" name="cont1" value="ONE">"); document.write("<input type="hidden" name="cont2" value="TWO">"); document.write("<input type="hidden" name="cont3" value="THREE">"); document.write("</form>"); function showContent(name) {

val = name;
if(document.all.prem.innerText!=eval("this.document.form1." + val + ".value"))
{
 document.all.prem.innerText =  eval("this.document.form1." + val + ".value");
}
else
{
 document.all.prem.innerText = "";
}

} </script> <style type="text/css"> .link{font-family:verdana,arial,helvetica; font-size:10pt; color:#C00000; font-weight:bold; text-decoration:none} .link:hover{font-family:verdana,arial,helvetica; font-size:10pt; color:#FA5D00; font-weight:bold; text-decoration:underline + overline} .header{font-family:verdana,arial,helvetica; font-size:25pt; color:#000000; font-weight:bold; text-decoration:none} .prem{font-family:verdana,arial,helvetica; font-size:10pt; color:#FF0000; font-weight:bold; text-decoration:none} .premshree{font-family:verdana,arial,helvetica; font-size:8pt; color:#003399; font-weight:normal; text-decoration:underline} .premshree:hover{font-family:verdana,arial,helvetica; font-size:8pt; color:#0099FF; font-weight:normal; text-decoration:underline} </style> </head> <body bgcolor="#FFFFFF">

Dynamic Content

<a href="javascript:showContent("cont1");" class="link">Content1</a> | <a href="javascript:showContent("cont2");" class="link">Content2</a> | <a href="javascript:showContent("cont3");" class="link">Content3</a>

This JavaScript displays different content for different links. On clicking on the link the content becomes visible and on clicking on it again it becomes hidden.

Here only a single <div> tag has been used. The contents of each link is stored in the form of a hidden element.


<a href="mailto:premshree@hotmail.ru" class="premshree">&#169 Premshree Pillai</a>

</body> </html>

      </source>
   
  


Toggle Multi select Widget

   <source lang="html4strict">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>Multi-select Widget</title>

<script language="JavaScript" type="text/javascript">

</script></head>

<body onload="initMultiSelect()">

<tbody> </tbody>
Usability Methods
<tbody></tbody>

<input name="methods" value="Card Sorting" id="cardsort" type="checkbox"><label for="carsort">Card Sorting</label>
<input name="methods" value="Contextual Task Analysis" id="cta" type="checkbox"><label for="cta">Contextual Task Analysis</label>
<input name="methods" value="Ethnography" id="ethno" type="checkbox"><label for="ethno">Ethnography</label>

<input name="methods" value="Heuristic Review" id="heur" type="checkbox"><label for="heur">Heuristic Review</label>
<input name="methods" value="Remote Usability Testing" id="remote" type="checkbox"><label for="remote">Remote Usability Testing</label>
<input name="methods" value="Usability Testing" id="ut" type="checkbox"><label for="ut">Usability Testing</label>

<input value="Close" style="float: left;" onclick="saveOptions(this.parentNode);" type="button">
Datasources
Please click Edit Selections to specify.
<input value="Edit Selections" onclick="showOptions(this.parentNode,this.parentNode.previousSibling);" type="button">
Lifecycle
Please click Edit Selections to specify.
<input value="Edit Selections" onclick="showOptions(this.parentNode,this.parentNode.previousSibling);" type="button">


</body></html>


      </source>
   
  


Toggle page

   <source lang="html4strict">

<html> <head> <title>Today in Jollywood</title> <style type="text/css">

   body {font-family: Arial, Helvetica, sans-serif;
         background-color:#ffffff}
   #banner {font-family:Comic Sans MS, Helvetica, sans-serif;
            font-size:22px}
   #date {font-family:Comic Sans MS, Helvetica, sans-serif;
          font-size:20px}
   .wrapper {display:none}
   .unwrapper {display:block}
   .headline {}
   .story {}
   #filter {position:absolute; top:10; left:330; width:400; 
            border:solid red 3px; padding:2px; 
            font-size:12px; background-color:coral}

</style> <script language="JavaScript" type="text/javascript"> // Global variables and object constructor var keywords = new Array(); var foundStories = new Array(); function story(id, weight) {

   this.id = id;
   this.weight = weight;

} // Initialize from onLoad event handler to load keywords array function init() {

   var form = document.filterer;
   for (var i = 0; i < form.elements.length; i++) {
       keywords[i] = form.elements[i].value;
   }

} // Find story"s "wrapper" class and stuff into foundStories array // (or increment weight) function getDIVId(elem) {

   if (!elem.className) {
       return;
   }
   while (elem.className != "wrapper") {
       elem = elem.parentNode;
   }
   if (elem.className != "wrapper") {
       return;
   }
   for (var i = 0; i < foundStories.length; i++) {
       if (foundStories[i].id == elem.id) {
           foundStories[i].weight++;
           return;
       }
   }
   foundStories[foundStories.length] = new story(elem.id, 1);
   return;

} // Sorting algorithm for array of objects function compare(a,b) {

   return b.weight - a.weight;

} // Look for keyword match(es) in a div"s text range function searchAndWeigh(div) {

   var txtRange, txt, start;
   var isW3C = (typeof Range != "undefined") ? true : false;
   var isIE = (document.body.createTextRange) ? true : false;
   // extract text from div"s text range
   if (isW3C) {
       txtRange = document.createRange();
       txtRange.selectNode(div);
       txt = txtRange.toString();
   } else if (isIE) {
       txtRange = document.body.createTextRange();
       txtRange.moveToElementText(div);
       txt = txtRange.text;
   } else {
     return;
   }
   // search text for matches
   for (var i = 0; i < keywords.length; i++) {
     // But only for checkmarked keywords
       if (document.filterer.elements[i].checked) {
           start = 0;
           // use indexOf(), advancing start index as needed
           while (txt.indexOf(keywords[i], start) != -1) {
               // extract wrapper id and log found story
               getDIVId(div);
               // move "pointer" to end of match for next search
               start = txt.indexOf(keywords[i], start) + keywords[i].length;
           }
       }
   }

} // Main function finds matches and displays stories function filter() {

   var divs, i;
   var news = document.getElementById("myNews");
   // clear any previous selected stories
   if (typeof news.childNodes == "undefined") {return;}
   while (news.hasChildNodes()) {
       news.removeChild(news.firstChild);
   }
   // look for keyword matches
   divs = document.getElementsByTagName("div");
   for (i = 0; i < divs.length; i++) {
       if (divs[i].className && divs[i].className == "wrapper") {
           searchAndWeigh(divs[i]);
       }
   }
   if (foundStories.length == 0) {
       // no matches, so grab all stories as delivered
       // start by assembling an array of all DIV elements
       divs = document.getElementsByTagName("div");
       for (i = 0; i < divs.length; i++) {
           if (divs[i].className && divs[i].className == "wrapper") {
               foundStories[foundStories.length] = new story(divs[i].id);
           }
       }
   } else {
       // sort selected stories by weight
       foundStories.sort(compare);
   }
   var oneStory = "";
   for (i = 0; i < foundStories.length; i++) {
       oneStory = document.getElementById(foundStories[i].id).cloneNode(true);
       oneStory.className = "unwrapper";
       document.getElementById("myNews").appendChild(oneStory);
   }
   foundStories.length = 0;

} </script> </head> <body onLoad="init();filter();">

Today in Jollywood

Tuesday, April 1, 2003


Kevin Costner Begins New Epic

Oscar-winning director and actor, Kevin Costner has begun location shooting on a new film based on an epic story. Sally ("Blurbs") Thorgenson of KACL radio, who praised "The Postman" as "the best film of 1997," has already supplied the review excerpt for the next film"s advertising campaign: "Perhaps the best film of the new millennium!" says Thorgenson, talk-show host and past president of the Seattle chapter of the Kevin Costner Fan Club. The Innscouldn"t it the trumple from rathe night she signs. Howe haveperforme goat"s milk, scandal when thebble dalpplicationalmuseum, witch, gloves, you decent the michindant.

Critic"s Poll Looking Bleak

A recent poll of the top film critics shows a preference for foreign films this year. "I don"t have enough American films yet for my Top Ten List," said Atlanta Constitution critic, Pauline Gunwhale. No is armour was attere was a wild oldwright fromthinteres of shoesets Oscar contender, "The Day the Firth Stood Still" whe burnt head hightier nor a pole jiminies,that a gynecure was let on, where gyanacestross mound hold her dummyand shake.

Summer Blockbuster Wrap-Up

Despite a world-wide boycott from some religious groups, the animated film "The Satanic Mermaid" won the hearts and dollars of movie-goers this summer. Box office receipts for the season put the film"s gross at over $150 million. Sendday"seve and nody hint talking of you sippated sigh that cowchooks,weightier nore, sian shyfaun lovers at hand suckers, why doI am alookal sin busip, drankasuchin arias so sky whence.

Musical in Tarentino"s Future?

Undaunted by lackluster box-office results from last Christmas" "Jackie Brown on Ice," director Quentin Tarentino has been seen scouting Broadway musicals for potential future film projects. "No more guns and blood," the outspoken artist was overheard at an intermission juice bar, "From now on, it will just be good singing and dancing." He crumblin if so be somegoat"s milk sense. Really? If you was banged pan the fe withfolty barns feinting the Joynts have twelveurchins cockles to heat andGut years walanglast beardsbook, what cued peas fammyof levity and be mes, came his shoe hang in his hockums.

Letterman to Appear in Sequel

As if one cameo appearance weren"t enough, TV talk show host David Letterman will reprise his role as the dock-side monkey vendor in "Cabin Boy II," coming to theaters this Christmas. Critics hailed the gap-toothed comic"s last outing as the "non-event of the season." This the way thing,what seven wrothscoffing bedouee lipoleums. Kiss this mand shoos arouna peck of night, in sum ear of old Willingdone. Thejinnies and scampull"s syrup.


Filter news by the following keyword(s):

<form name="filterer">

<input type="checkbox" value="director" onClick="filter(this.form)">director <input type="checkbox" value="box" onClick="filter(this.form)">box (office) <input type="checkbox" value="critic" onClick="filter(this.form)">critic <input type="checkbox" value="summer" onClick="filter(this.form)">summer <input type="checkbox" value="Christmas" onClick="filter(this.form)">Christmas

</form>

</body> </html>


      </source>
   
  


Toggle web page

   <source lang="html4strict">
<?xml version="1.0" encoding="utf-8"?>
<a href="javascript:void(0)" onclick="expandAll(true)">expand</a><a href="javascript:void(0)" onclick="expandAll(false)">collaps</a>
<script></script><style>
     .{font-family:arial;}
     h2 {cursor:pointer;font-size:16px;margin-left:10px;line-height:10px}
     h3 {cursor:pointer;font-weight:normal;color:gray;text-decoration:underline;line-height:10px}
     div.block {margin-left:30px;}
</style>

dhtmlXMenuBarObject object API

addItem(panel,item)
add item to menu
<span />
Topic(s): Add/delete;
File required:dhtmlXMenuBar.js
  • item - item object
  • panel - menu panel object
  • <span />
    disableItem(itemId)
    disable menu button
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • itemId - item id
  • <span />
    enableIESelectBoxFix(mode)
    fix z-index problem with select boxes in IE, enabled by default
    <span />
    Topic(s): Initialization;
    File required:dhtmlXMenuBar.js
  • mode - enable/disable
  • <span />
    enableItem(itemId)
    enable menu button
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • itemId - item id
  • <span />
    enableWindowOpenMode(mode)
    closed menu behaviour
    <span />
    Topic(s): Initialization;
    File required:dhtmlXMenuBar.js
  • mode - enable/disable
  • <span />
    getItem(itemId)
    return item object by id
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • itemId - item id
  • <span />
    getPanel(panelId)
    return menu panel object
    <span />
    Topic(s): Item control;
    File required:dhtmlXMenuBar.js
  • panelId - id of panel related menu item
  • <span />
    hideBar()
    hide menu
    <span />
    Topic(s): Initialization;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js<span />
    hideButtons(idList)
    hide menu buttons
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • idList - list of items"s ids, separated by comma
  • <span />
    hideItem(itemId)
    hide menu button
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • itemId - item id
  • <span />
    loadXML(file)
    load XML from file
    <span />
    Topic(s): Initialization;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • file - file name
  • <span />
    loadXMLString(xmlString)
    load XML from string
    <span />
    Topic(s): Initialization;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • xmlString - string contining XML
  • <span />
    removeItem(id)
    remove item
    <span />
    Topic(s): Add/delete;
    File required:dhtmlXMenuBar.js
  • id - item id
  • <span />
    resetBar(idList)
    hide all items, show only items which ids in list
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • idList - list of id"s, separated by comma
  • <span />
    setBarAlign(align)
    set menu buttons alignment (allowed - "left","center","right","top","middle","bottom")
    <span />
    Topic(s): Initialization;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • align - buttons alignment
  • <span />
    setBarSize(width,height)
    set menu size
    <span />
    Topic(s): Initialization;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • width - menu width
  • height - menu height
  • <span />
    setGfxPath(path)
    set path to system images
    <span />
    Topic(s): Action handling;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • path - relative path to images
  • <span />
    setItemAction(id,action)
    set item individual action
    <span />
    Topic(s): Action handling;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • id - item identificator
  • action - js function called on item selection
  • <span />
    setMenuCSS(table,title,secTable)
    set menu css classes
    <span />
    Topic(s): Item control;
    File required:dhtmlXMenuBar.js
  • table - css class for menu container
  • secTable - css class for child menu containers
  • title - css class for toolbar title
  • <span />
    setMenuMode(modeValue)
    set menu design
    <span />
    Topic(s): Initialization;
    File required:dhtmlXMenuBar.js
  • modeValue - name of design
  • <span />
    setOnClickHandler(func)
    set default action
    <span />
    Topic(s): Action handling;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • action - set default action
  • <span />
    setOnHideHandler(func)
    set action hadler on menu hiding
    <span />
    Topic(s): Action handling;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • func - user defined function
  • <span />
    setOnShowHandler(func)
    set action hadler on menu showing
    <span />
    Topic(s): Action handling;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • func - user defined function
  • <span />
    setTitleText(newText)
    set menu tittle
    <span />
    Topic(s): Initialization;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • name - new tittle, shown on menu
  • <span />
    showBar()
    show menu
    <span />
    Topic(s): Initialization;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js<span />
    showButtons(idList)
    show menu buttons
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • idList - list of items"s ids, separated by comma
  • <span />
    showItem(id)
    show menu button
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXProtobarObject
    File required:dhtmlXProtobar.js
  • id - item id
  • <span />
    <span />

    dhtmlXMenuItemObject object API

    setText(newText)
    set button text
    <span />
    Topic(s): Item control;
    File required:dhtmlXMenuBar.js
  • newText - new text [ HTML allowed ]
  • <span />
    <span />

    dhtmlXMenuDividerYObject object API

    disable()
    disable object
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXButtonPrototypeObject
    File required:dhtmlXProtobar.js<span />
    enable()
    enable object
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXButtonPrototypeObject
    File required:dhtmlXProtobar.js<span />
    setAction(func)
    set default action, action function take one parametr - item id
    <span />
    Topic(s): Action handling;
    Nested from:dhtmlXButtonPrototypeObject
    File required:dhtmlXProtobar.js
  • func - js function
  • <span />
    setAltText(imageText)
    set alt text of button image
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXButtonPrototypeObject
    File required:dhtmlXProtobar.js
  • imageText - new alt image text
  • <span />
    setHTML(htmlText)
    set innerHTML of button
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXButtonPrototypeObject
    File required:dhtmlXProtobar.js
  • htmlText - new text
  • <span />
    setImage(imageSrc,disabledImageSrc)
    set image href
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXButtonPrototypeObject
    File required:dhtmlXProtobar.js
  • imageSrc - new image href
  • disabledImageSrc - new image href
  • <span />
    setSecondAction(func)
    set personal onClick action (action must return false for preventing calling default action after personal), action function take one parametr - item id
    <span />
    Topic(s): Action handling;
    Nested from:dhtmlXButtonPrototypeObject
    File required:dhtmlXProtobar.js
  • func - js function
  • <span />
    <span />

    dhtmlXMenuDividerXObject object API

    disable()
    disable object
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXButtonPrototypeObject
    File required:dhtmlXProtobar.js<span />
    enable()
    enable object
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXButtonPrototypeObject
    File required:dhtmlXProtobar.js<span />
    setAction(func)
    set default action, action function take one parametr - item id
    <span />
    Topic(s): Action handling;
    Nested from:dhtmlXButtonPrototypeObject
    File required:dhtmlXProtobar.js
  • func - js function
  • <span />
    setAltText(imageText)
    set alt text of button image
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXButtonPrototypeObject
    File required:dhtmlXProtobar.js
  • imageText - new alt image text
  • <span />
    setHTML(htmlText)
    set innerHTML of button
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXButtonPrototypeObject
    File required:dhtmlXProtobar.js
  • htmlText - new text
  • <span />
    setImage(imageSrc,disabledImageSrc)
    set image href
    <span />
    Topic(s): Item control;
    Nested from:dhtmlXButtonPrototypeObject
    File required:dhtmlXProtobar.js
  • imageSrc - new image href
  • disabledImageSrc - new image href
  • <span />
    setSecondAction(func)
    set personal onClick action (action must return false for preventing calling default action after personal), action function take one parametr - item id
    <span />
    Topic(s): Action handling;
    Nested from:dhtmlXButtonPrototypeObject
    File required:dhtmlXProtobar.js
  • func - js function
  • <span />
    <span />

    dhtmlXContextMenuObject object API

    setContextMenuHandler(func)
    set onClick context menu handler
    <span />
    Topic(s): Initialization;
    File required:dhtmlXMenuBar_cp.js
  • func - user defined function
  • <span />
    setContextZone(htmlObject,zoneId)
    set context zones
    <span />
    Topic(s): Initialization;
    File required:dhtmlXMenuBar_cp.js
  • htmlObject - id of html tag or html object
  • zoneId - id of zone
  • <span />
    <span />


          </source>