27 Jun, 2009

:before & :after voor blockquote

Categoriën: IE6 |javascript |solution

Blockquotes zouden naar aanleiding van het W3C moeten worden voorzien van ” “.
Dit kan men voor de moderne browser eenvoudig via CSS bepalen door gebruik van :before & :after, voor Internet Explorer 6 is er een JavaScript oplossing.

HTML

<blockquote cite="http://www.somewebsite.com/jan">
<p>They went in single file, running like hounds on a strong scent,
and an eager light was in their eyes. Nearly due west the broad
swath of the marching Orcs tramped its ugly slot; the sweet grass
of Rohan had been bruised and blackened as they passed.</p>
</blockquote>

CSS

blockquote:before, blockquote:after
{
  content: "";
}

JavaScript oplossing voor IE6

<![CDATA[
function fixIEQuotes()
{
  var objQuotes = document.getElementsByTagName('blockquote');
  var strOpen, strClose;
  for (var i=0; i<objQuotes.length; i++)
  {
    if (isNested(objQuotes[i]))
    {
      // Double-quotes
      strOpen = document.createTextNode('\u2018');
      strClose = document.createTextNode('\u2019');
    }
    else
    {
      // Single-quotes
      strOpen = document.createTextNode('\u201c');
      strClose = document.createTextNode('\u201d');
    }
    // Insert quotation marks around quote
    objQuotes[i].parentNode.insertBefore(strOpen, objQuotes[i]);
    objQuotes[i].appendChild(strClose);
  }
  objQuotes = null;
}
function isNested(objElement)
{
  var objParent = objElement;
  do // Check if nested quote
  {
    objParent = objParent.parentNode;
    if (objParent.tagName && objParent.tagName.toLowerCase() == 'blockquote')
      return true;
  } while (objParent.parentNode);
  return false;
}
]]>

Gerelateerde Snippets

Geen reacties op ":before & :after voor blockquote"

Reactie formulier


Advertenties

Volgende nieuwe Snippet:

  • Momenteel niks gepland.