public
Description: Random things I've written in JavaScript. Most are untested and/or half-baked.
Homepage:
Clone URL: git://github.com/savetheclocktower/javascript-stuff.git
javascript-stuff / quotes.js
100644 32 lines (31 sloc) 0.875 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
* A script for fixing the Q tag in Internet Explorer.
*
* Inspired by [http://plugins.jquery.com/project/QinIE].
*
* KNOWN ISSUES:
* Doesn't yet handle quotation marks from non-American locales.
*
* NOTE:
* This script does no browser checking. Load it via an IE
* conditional comment.
*
*/
(function() {
  var QUOTES = {
    'single': ["‘", "&rsquo"],
    'double': ["“", "”"]
  };
  
  function fixQuotes(q, quoteType) {
    if (q._handledByPrototype) return;
    var nestedQ = q.down('q');
    if (nestedQ) {
      arguments.callee(nestedQ, quoteType == "double" ? "single" : "double");
    }
    q.insert({ top: QUOTES[quoteType][0], bottom: QUOTES[quoteType][1] });
    q._handledByPrototype = true;
  }
  document.observe("dom:loaded", function() {
    $$('q').each( function(q) { fixQuotes(q, "double"); });
  });
})();