Click here to Skip to main content
15,882,152 members
Articles / Web Development / IIS

xLibrary - Using a custom IHttpHandler to access embedded JavaScript

Rate me:
Please Sign up or sign in to vote.
4.33/5 (4 votes)
28 Feb 2009CPOL15 min read 44.6K   446   41  
This article covers how to make a custom IHttpHandler to use the X Library from www.cross-browser.com embedded in an assembly.
<?xml version="1.0" encoding="ISO-8859-1"?>

<x_symbol id='xDisplay'>

<sources>
  <src><file>xdisplay.js</file><note><![CDATA[Default.]]></note></src>
</sources>

<copyright>Copyright 2003-2007 Michael Foster (Cross-Browser.com)</copyright>
<license>Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL</license>
<groups>
  <grp>Style</grp>
</groups>
<type>Function</type>

<description><![CDATA[A safe wrapper for element.style.display.]]></description>

<syntax>xDisplay(e[, sProp])</syntax>

<parameters>
  <par>
    <name>e</name>
    <note><![CDATA[id string or element reference]]></note>
  </par>
  <par>
    <name>sProp</name>
    <note><![CDATA[One of the valid CSS strings for this property]]></note>
  </par>
</parameters>

<return>string, element.style.display if it exists else null</return>

<dependencies>
  <dep>xGetElementById</dep>
  <dep>xDef</dep>
  <dep>xStr</dep>
</dependencies>

<demos>
  <demo>
    <url>http://cross-browser.com/toys/</url>
    <note><![CDATA[Index of all X demos.]]></note>
  </demo>
</demos>

<comments>
  <comment><date>2Jul07</date><author>mf</author><note><![CDATA[Don't use this function, access the native property directly. This function is provided only for backwards-compatibility.]]></note></comment>
  <comment><date>1Nov06</date><author>mf</author><note><![CDATA[
<br>Original:
[code]function xDisplay(e,s)
{
  if(!(e=xGetElementById(e))) return null;
  if(e.style && xDef(e.style.display)) {
    if (xStr(s)) e.style.display = s;
    return e.style.display;
  }
  return null;
}[/code]
Alternative 2:
[code]function xDisplay(e,s)
{
  if ((e=xGetElementById(e)) && e.style && xDef(e.style.display)) {
    if (xStr(s)) {
      if (s == 'block' && e.nodeName) { /////// ???
        var ie = 'block';
        switch (e.nodeName.toLowerCase()) {
          case 'table': s = 'table'; break;
          case 'tr': s = 'table-row'; break;
          case 'td': case 'th': s = 'table-cell'; break;
          case 'li': s = 'list-item'; break;
          case 'caption': s = 'table-caption'; ie = 'inline'; break; // inline (IE6dn)
          case 'tbody': s = 'table-row-group'; ie = ''; break; // not rendered
          case 'thead': s = 'table-header-group'; ie = ''; break; // not rendered
          case 'tfoot': s = 'table-footer-group'; ie = ''; break; // not rendered
          case 'col': s = 'table-column'; break;
          case 'colgroup': s = 'table-column-group'; break;
        }
        try { e.style.display = s; }
        catch (e) { e.style.display = ie; }
      }
      else e.style.display = s;
    }
    return e.style.display;
  }
  return null;
}[/code]
  ]]></note></comment>
</comments>

<revisions>
  <rev>
    <num>3</num><date>1Nov06</date><author>mf</author>
    <note><![CDATA[Using try/catch since IE6dn doesn't support the table css properties. Thanks very much to Edward Glowacki.]]></note>
  </rev>
  <rev>
    <num>2</num><date>15Mar05</date><author>mf</author>
    <note><![CDATA[Reduced 13 bytes]]></note>
  </rev>
  <rev>
    <num>1</num><date>11Mar05</date><author>mf</author>
    <note><![CDATA[put into its own file for XC]]></note>
  </rev>
</revisions>

</x_symbol>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
I have been a software developer since 2005, focusing on .Net applications with MS SQL backends, and recently, C++ applications in Linux, Mac OS X, and Windows.

Comments and Discussions