home *** CD-ROM | disk | FTP | other *** search
/ developer.apple.com / developer.apple.com.tar / developer.apple.com / js / adc.js next >
Text File  |  2009-11-09  |  6KB  |  195 lines

  1. <!--
  2. function visByClass(className, state)
  3. {
  4.     if (document.getElementsByTagName) { //check for obj
  5.          var nodes = document.getElementsByTagName("DIV");
  6.          for (var i = 0;i < nodes.length;i++) {
  7.             var nodeObj = nodes.item(i);
  8.             var attrMax = nodeObj.attributes.length
  9.             for (var j = 0; j < attrMax; j++) {
  10.                 if (nodeObj.attributes.item(j).nodeName == 'class') {
  11.                     if (nodeObj.attributes.item(j).nodeValue == className) {
  12.                         vista = (state) ? 'block'    : 'none';
  13.                         nodeObj.style.display = vista;
  14.                      }
  15.                 }
  16.              }
  17.         }
  18.     }
  19.     var nodes = document.getElementsByTagName("SPAN");
  20.          
  21.     var max = nodes.length
  22.     for (var i = 0;i < max;i++) {
  23.         var nodeObj = nodes.item(i);
  24.         for (var j = 0; j < nodeObj.attributes.length; j++)  {
  25.             if (nodeObj.attributes.item(j).nodeName == 'class') {
  26.                 if (nodeObj.attributes.item(j).nodeValue == className) {
  27.                     vista = (state) ? 'block'    : 'none';
  28.                     nodeObj.style.display = vista;
  29.                  }
  30.             }
  31.         }
  32.     }    
  33. }
  34.  
  35. // Modify the display state of the CSS style with the given class name 
  36. var foundStylesheet;
  37. function visByClass2(className, state)
  38. {
  39.     var stylesheets = document.styleSheets;
  40.     if( stylesheets && stylesheets.length > 0 ) {
  41.         // Safari sometimes fails to return any stylesheets here when called
  42.         // before the page finishes loading.  Flag that we did find a style sheet
  43.         // so that we can tell if we should repeat the test after the page loads.
  44.         foundStylesheet = 1;
  45.         var rules = stylesheets[0].cssRules;
  46.         if( rules == null ) {
  47.             // IE6/Win uses rules, not cssRules to get style sheet rules
  48.             rules = stylesheets[0].rules;
  49.         }
  50.         for( var i=0; i < rules.length; i++ ) {
  51.             if( rules[i].selectorText.indexOf( className ) != -1 ) {
  52.                 var style = rules[i].style;
  53.                 vista = (state) ? 'block' : 'none';
  54.                 style.display = vista;
  55.                 return;
  56.             }
  57.         }
  58.     } else {
  59.         // Falling back to old code
  60.         visByClass(className, state);
  61.     }
  62. }
  63.  
  64.  
  65. // Pop A Window
  66. function MM_openBrWindow(theURL,winName,features) { //v2.0
  67.     window.open(theURL,winName,features);
  68. }
  69.  
  70.  
  71. // Redirect user with the item selected with a drop-down menu
  72. function redirect(categoryName, selectedItem)
  73. {    
  74.     //window.location.href = "http://www.apple.com";
  75.     //alert(categoryName);
  76.     var q = selectedItem.indexOf("WONoSelectionString"); 
  77.     //alert(q);
  78.     if ( q == 0 ) {
  79.         //user selected the first item, so take them back to the page listing all docs
  80.         //you have to somehow pass in the name of the category
  81.         //alert("../" + categoryName + "/" + categoryName + "-date.html");
  82.         window.location.href = "../" + categoryName + "/" + categoryName + "-date.html";
  83.     } else {
  84.         window.location.href = selectedItem;
  85.     }
  86. }
  87.  
  88. function busNav(newPage,defaultIndex) {
  89.     newLoc = newPage.options[newPage.selectedIndex].value
  90.     if (newLoc != "") {
  91.             window.location.href = newLoc;
  92.     }
  93.     if( typeof defaultIndex != "undefined" && defaultIndex >= 0 ) {
  94.         newPage.selectedIndex = defaultIndex;
  95.     }
  96. }
  97.  
  98. // Check whether the descriptions should be hidden based on a cookie
  99. function testDescriptionFlag() {
  100.     var value = getCookie("RefLib_Descriptions");
  101.     if( value && value == 'off' ) {
  102.         //  The default setting is to show descriptions, so we only need to
  103.         //    act if the cookie is set to 'off'
  104.         hideDescriptions(0);
  105.     }
  106. }
  107.  
  108. // If we failed to find any stylesheet while the page was loading, repeat the test
  109. function retestDescriptionFlag() {
  110.     if( foundStylesheet ) {
  111.         return;
  112.     }
  113.     testDescriptionFlag();
  114. }
  115.  
  116. //  Turn on the descriptions.  If the needCookie flag is true, set a cookie
  117. //  to remember this flag.
  118. function showDescriptions( needCookie ) {
  119.     visByClass2("description", 1);
  120.     if( needCookie ) {
  121.         // Set expiration date to 20 years in the future
  122.         // (Maximum date is ~2038)
  123.         var expires = new Date();
  124.         expires.setTime( expires.getTime() + 1000*60*60*24*365*20 );
  125.         setCookie('RefLib_Descriptions', 'on', expires, '/');
  126.     }
  127.     var onButton = document.getElementById( 'DescriptionsOn' );
  128.     if( onButton ) {
  129.         onButton.checked = 1;
  130.     }
  131. }
  132.  
  133. //  Turn off the descriptions.  If the needCookie flag is true, set a cookie
  134. //  to remember this flag.
  135. function hideDescriptions( needCookie ) {
  136.     visByClass2("description", 0);
  137.     if( needCookie ) {
  138.         // Set expiration date to 20 years in the future
  139.         // (Maximum date is ~2038)
  140.         var expires = new Date();
  141.         expires.setTime( expires.getTime() + 1000*60*60*24*365*20 );
  142.         setCookie('RefLib_Descriptions', 'off', expires, '/');
  143.     }
  144.     var offButton = document.getElementById( 'DescriptionsOff' );
  145.     if( offButton ) {
  146.         offButton.checked = 1;
  147.     }
  148. }
  149.  
  150. // Get a cookie
  151. // Code from: http://www.webreference.com/js/column8/functions.html
  152. function getCookie(name) {
  153.     var dc = document.cookie;
  154.     var prefix = name + "=";
  155.     var begin = dc.indexOf("; " + prefix);
  156.     if (begin == -1) {
  157.         begin = dc.indexOf(prefix);
  158.         if (begin != 0) return null;
  159.     } else {
  160.         begin += 2;
  161.     }
  162.     var end = document.cookie.indexOf(";", begin);
  163.     if (end == -1) {
  164.         end = dc.length;
  165.     }
  166.     return unescape(dc.substring(begin + prefix.length, end));
  167. }
  168.  
  169. // Set a cookie
  170. // Code from: http://www.webreference.com/js/column8/functions.html
  171. function setCookie(name, value, expires, path, domain, secure) {
  172.     var curCookie = name + "=" + escape(value) +
  173.         ((expires) ? "; expires=" + expires.toGMTString() : "") +
  174.         ((path) ? "; path=" + path : "") +
  175.         ((domain) ? "; domain=" + domain : "") +
  176.         ((secure) ? "; secure" : "");
  177.     document.cookie = curCookie;
  178. }
  179.  
  180. //Javascript add 2006-03-09
  181. function closeWatermark() {
  182.  
  183.     if(document.all){
  184.         watermark.style.visibility = "hidden";
  185.     } else if(document.layers) {
  186.         document.watermark.visibility = "hidden";
  187.     } else if(document.getElementById && !document.all) {
  188.         document.getElementById("watermark").style.visibility = "hidden";
  189.     }
  190.  
  191. }
  192.  
  193.  
  194. //-->
  195.