   1.  <public:attach event="oncontentready" onevent="init();" />
   2. <script>
   3. /*
   4. * This will make each level of nested quotes alternate between
   5. * single and double quotes.
   6. * Reference: http://en.wikipedia.org/wiki/Quotation_mark
   7. */
   8. var quotes = {
   9.   even : {open:0x201C, close:0x201D },
  10.   odd  : {open:0x2018, close:0x2019 }
  11. };
  12. /* Returns the level that a tag is nested within itself  */
  13. function getNestedLevel(tagName,node,cLevel){
  14.   var level = 0;
  15.   var parent = node.parentNode;
  16.   if(parent != null){
  17.     if(node.parentNode.tagName == tagName){
  18.       level++;
  19.     }
  20.     level += getNestedLevel(tagName,parent,level);
  21.   }
  22.   return level;
  23. }
  24. function init() {
  25.   var nestedLevel = getNestedLevel(this.tagName,this,0);
  26.   var type = (nestedLevel%2==0) ? "even":"odd";
  27.   var openQ  = document.createTextNode(
  28.     String.fromCharCode(quotes[type].open));
  29.   var closeQ = document.createTextNode(
  30.     String.fromCharCode(quotes[type].close));
  31.   this.insertBefore(openQ,this.firstChild);
  32.   this.appendChild(closeQ);
  33. }
  34. </script>
