Advertisement
Guest User

unidings michiel sikma

a guest
Jan 16th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * UniDings - converts text nodes to Wingdings text
  3.  * Copyright (C) 2011, Michiel Sikma <michiel@wedemandhtml.com>
  4.  * This code is in the public domain.
  5.  * Date: 2011/05/06
  6.  *
  7.  * @author Michiel Sikma
  8.  * @version 0.1
  9.  *
  10.  **/
  11.    
  12. window.UniDings = new function()
  13. {
  14.     var self = this;
  15.    
  16.     self.tables = {};
  17.    
  18.     /* Which table type will we retrieve Unicode characters from?
  19.        Only "strict" is available at this moment. */
  20.     self.tableType = "strict";
  21.     self.table;
  22.    
  23.     self.initializeTranslationTable = function()
  24.     {
  25.         /* Initializes the translation table. Note: this table was
  26.            taken from <http://www.alanwood.net/demos/wingdings.html>. */
  27.         self.tables["table_strict"] = {
  28.             32: 32,     // space -> space
  29.             33: 9999,   // pencil -> pencil
  30.             34: 9986,   // scissors -> black scissors
  31.             35: 9985,   // scissorscutting -> upper blade scissors
  32.             36: 36,     // readingglasses
  33.             37: 37,     // bell
  34.             38: 38,     // book
  35.             39: 39,     // candle
  36.             40: 9742,   // telephonesolid -> black telephone
  37.             41: 9990,   // telhandsetcirc -> telephone location sign
  38.             42: 9993,   // envelopeback -> envelope
  39.             43: 43,     // envelopefront
  40.             44: 44,     // mailboxflagdwn
  41.             45: 45,     // mailboxflagup
  42.             46: 46,     // mailbxopnflgup
  43.             47: 47,     // mailbxopnflgdwn
  44.             48: 48,     // folder
  45.             49: 49,     // folderopen
  46.             50: 50,     // filetalltext1
  47.             51: 51,     // filetalltext
  48.             52: 52,     // filetalltext3
  49.             53: 53,     // filecabinet
  50.             54: 8987,   // hourglass -> hourglass
  51.             55: 9000,   // keyboard -> keyboard
  52.             56: 56,     // mouse2button
  53.             57: 57,     // ballpoint
  54.             58: 58,     // pc
  55.             59: 59,     // harddisk
  56.             60: 60,     // floppy3
  57.             61: 61,     // floppy5
  58.             62: 9991,   // tapereel -> tape drive
  59.             63: 9997,   // handwrite -> writing hand
  60.             64: 64,     // handwriteleft
  61.             65: 9996,   // handv -> victory hand
  62.             66: 66,     // handok
  63.             67: 67,     // thumbup
  64.             68: 68,     // thumbdown
  65.             69: 9756,   // handptleft -> white left pointing index
  66.             70: 9758,   // handptright -> white right pointing index
  67.             71: 9757,   // handptup -> white up pointing index
  68.             72: 9759,   // handptdown -> white down pointing index
  69.             73: 73,     // handhalt
  70.             74: 9786,   // smileface -> white smiling face
  71.             75: 75,     // neutralface
  72.             76: 9785,   // frownface -> white frowning face
  73.             77: 77,     // bomb
  74.             78: 9760,   // skullcrossbones -> skull and crossbones
  75.             79: 9872,   // flag -> white flag
  76.             80: 80,     // pennant
  77.             81: 9992,   // airplane -> airplane
  78.             82: 9788,   // sunshine -> white sun with rays
  79.             83: 83,     // droplet
  80.             84: 10052,  // snowflake -> snowflake
  81.             85: 85,     // crossoutline
  82.             86: 10014,  // crossshadow -> shadowed white latin cross
  83.             87: 87,     // crossceltic
  84.             88: 10016,  // crossmaltese -> maltese cross
  85.             89: 10017,  // starofdavid -> star of david
  86.             90: 9770,   // crescentstar -> star and crescent
  87.             91: 9775,   // yinyang -> yin yang
  88.             92: 2384,   // om -> devanagari om
  89.             93: 9784,   // wheel -> wheel of dharma
  90.             94: 9800,   // aries -> aries
  91.             95: 9801,   // taurus -> taurus
  92.             96: 9802,   // gemini -> gemini
  93.             97: 9803,   // cancer -> cancer
  94.             98: 9804,   // leo -> leo
  95.             99: 9805,   // virgo -> virgo
  96.             100: 9806,  // libra -> libra
  97.             101: 9807,  // scorpio -> scorpio
  98.             102: 9808,  // saggitarius -> sagittarius
  99.             103: 9809,  // capricorn -> capricorn
  100.             104: 9810,  // aquarius -> aquarius
  101.             105: 9811,  // pisces -> pisces
  102.             106: 38,    // ampersanditlc -> ampersand (italic, lower-case)
  103.             107: 38,    // ampersandit -> ampersand (italic)
  104.             108: 9679,  // circle6 -> black circle
  105.             109: 10061, // circleshadowdwn -> shadowed white circle
  106.             110: 9632,  // square6 -> black square
  107.             111: 9633,  // box3 -> white square
  108.             112: 112,   // box4
  109.             113: 10065, // boxshadowdwn -> lower right shadowed white square
  110.             114: 10066, // boxshadowup -> upper right shadowed white square
  111.             115: 11047, // lozenge4 -> black medium lozenge
  112.             116: 10731, // lozenge6 -> black lozenge
  113.             117: 9670,  // rhombus6 -> black diamond
  114.             118: 10070, // xrhombus -> black diamond minus white x
  115.             119: 11045, // rhombus4 -> black medium diamond
  116.             120: 8999,  // clear -> x in a rectangle box
  117.             121: 9043,  // escape -> apl functional symbol quad up caret
  118.             122: 8984,  // command -> place of interest sign
  119.             123: 10048, // rosette -> white florette
  120.             124: 10047, // rosettesolid -> black florette
  121.             125: 10077, // quotedbllftbld -> heavy double turned comma quotation mark ornament
  122.             126: 10078, // quotedblrtbld -> heavy double comma quotation mark ornament
  123.             127: 9647,  // .notdef -> white vertical rectangle
  124.             128: 9450,  // zerosans -> circled digit zero
  125.             129: 9312,  // onesans -> circled digit one
  126.             130: 9313,  // twosans -> circled digit two
  127.             131: 9314,  // threesans -> circled digit three
  128.             132: 9315,  // foursans -> circled digit four
  129.             133: 9316,  // fivesans -> circled digit five
  130.             134: 9317,  // sixsans -> circled digit six
  131.             135: 9318,  // sevensans -> circled digit seven
  132.             136: 9319,  // eightsans -> circled digit eight
  133.             137: 9320,  // ninesans -> circled digit nine
  134.             138: 9321,  // tensans -> circled number ten
  135.             139: 9471,  // zerosansinv -> negative circled digit zero
  136.             140: 10102, // onesansinv -> dingbat negative circled digit one
  137.             141: 10103, // twosansinv -> dingbat negative circled digit two
  138.             142: 10104, // threesansinv -> dingbat negative circled digit three
  139.             143: 10105, // foursansinv -> dingbat negative circled digit four
  140.             144: 10106, // fivesansinv -> dingbat negative circled digit five
  141.             145: 10107, // sixsansinv -> dingbat negative circled digit six
  142.             146: 10108, // sevensansinv -> dingbat negative circled digit seven
  143.             147: 10109, // eightsansinv -> dingbat negative circled digit eight
  144.             148: 10110, // ninesansinv -> dingbat negative circled digit nine
  145.             149: 10111, // tensansinv -> dingbat negative circled number ten
  146.             150: 150,   // budleafne
  147.             151: 151,   // budleafnw
  148.             152: 152,   // budleafsw
  149.             153: 153,   // budleafse
  150.             154: 154,   // vineleafboldne
  151.             155: 155,   // vineleafboldnw
  152.             156: 156,   // vineleafboldsw
  153.             157: 157,   // vineleafboldse
  154.             158: 183,   // circle2 -> middle dot
  155.             159: 8226,  // circle4 -> bullet
  156.             160: 9642,  // square2 -> black small square
  157.             161: 9675,  // ring2 -> white circle
  158.             162: 162,   // ring4
  159.             163: 163,   // ring6
  160.             164: 9673,  // ringbutton2 -> fisheye
  161.             165: 9678,  // target -> bullseye
  162.             166: 166,   // circleshadowup
  163.             167: 9642,  // square4 -> black small square
  164.             168: 9723,  // box2 -> white medium square
  165.             169: 169,   // tristar2
  166.             170: 10022, // crosstar2 -> black four pointed star
  167.             171: 9733,  // pentastar2 -> black star
  168.             172: 10038, // hexstar2 -> six pointed black star
  169.             173: 10036, // octastar2 -> eight pointed black star
  170.             174: 10041, // dodecastar3 -> twelve pointed black star
  171.             175: 10037, // octastar4 -> eight pointed pinwheel star
  172.             176: 176,   // registersquare
  173.             177: 8982,  // registercircle -> position indicator
  174.             178: 10209, // cuspopen -> white concave-sided diamond
  175.             179: 8977,  // cuspopen1 -> square lozenge
  176.             180: 180,   // query
  177.             181: 10026, // circlestar -> circled white star
  178.             182: 10032, // starshadow -> shadowed white star
  179.             183: 183,   // oneoclock
  180.             184: 184,   // twooclock
  181.             185: 185,   // threeoclock
  182.             186: 186,   // fouroclock
  183.             187: 187,   // fiveoclock
  184.             188: 188,   // sixoclock
  185.             189: 189,   // sevenoclock
  186.             190: 190,   // eightoclock
  187.             191: 191,   // nineoclock
  188.             192: 192,   // tenoclock
  189.             193: 193,   // elevenoclock
  190.             194: 194,   // twelveoclock
  191.             195: 195,   // arrowdwnleft1
  192.             196: 196,   // arrowdwnrt1
  193.             197: 197,   // arrowupleft1
  194.             198: 198,   // arrowuprt1
  195.             199: 199,   // arrowleftup1
  196.             200: 200,   // arrowrtup1
  197.             201: 201,   // arrowleftdwn1
  198.             202: 202,   // arrowrtdwn1
  199.             203: 203,   // quiltsquare2
  200.             204: 204,   // quiltsquare2inv
  201.             205: 205,   // leafccwsw
  202.             206: 206,   // leafccwnw
  203.             207: 207,   // leafccwse
  204.             208: 208,   // leafccwne
  205.             209: 209,   // leafnw
  206.             210: 210,   // leafsw
  207.             211: 211,   // leafne
  208.             212: 212,   // leafse
  209.             213: 9003,  // deleteleft -> erase to the left
  210.             214: 8998,  // deleteright -> erase to the right
  211.             215: 215,   // head2left
  212.             216: 10146, // head2right -> three-d top-lighted rightwards arrowhead
  213.             217: 217,   // head2up
  214.             218: 218,   // head2down
  215.             219: 219,   // circleleft
  216.             220: 10162, // circleright -> circled heavy white rightwards arrow
  217.             221: 221,   // circleup
  218.             222: 222,   // circledown
  219.             223: 223,   // barb2left
  220.             224: 224,   // barb2right
  221.             225: 225,   // barb2up
  222.             226: 226,   // barb2down
  223.             227: 227,   // barb2nw
  224.             228: 228,   // barb2ne
  225.             229: 229,   // barb2sw
  226.             230: 230,   // barb2se
  227.             231: 231,   // barb4left
  228.             232: 10132, // barb4right -> heavy wide-headed rightwards arrow
  229.             233: 233,   // barb4up
  230.             234: 234,   // barb4down
  231.             235: 235,   // barb4nw
  232.             236: 236,   // barb4ne
  233.             237: 237,   // barb4sw
  234.             238: 238,   // barb4se
  235.             239: 8678,  // bleft -> leftwards white arrow
  236.             240: 8680,  // bright -> rightwards white arrow
  237.             241: 8679,  // bup -> upwards white arrow
  238.             242: 8681,  // bdown -> downwards white arrow
  239.             243: 11012, // bleftright -> left right white arrow
  240.             244: 8691,  // bupdown -> up down white arrow
  241.             245: 11008, // bnw -> north east white arrow
  242.             246: 11009, // bne -> north west white arrow
  243.             247: 11011, // bsw -> south west white arrow
  244.             248: 11010, // bse -> south east white arrow
  245.             249: 9645,  // bdash1 -> white rectangle
  246.             250: 9643,  // bdash2 -> white small square
  247.             251: 10007, // xmarkbld -> ballot x
  248.             252: 10003  // checkbld -> check mark
  249.         };
  250.         self.table = self.tables["table_"+self.tableType];
  251.     }
  252.    
  253.     self.convert = function(str)
  254.     {
  255.         /* Converts a string to make it look like it was written using
  256.            the Wingdings font, by using Unicode characters. */
  257.         var a, z;
  258.         var code, equi;
  259.         var trans = [];
  260.         for (a = 0, z = str.length; a < z; ++a) {
  261.             code = str.charCodeAt(a);
  262.             equi = self.table[code];
  263.             trans.push(equi != null ? equi : code);
  264.         }
  265.         /* The String.fromCharCode() method accepts an arbitrary number
  266.            of arguments, so we use apply() to provide them. */
  267.         return String.fromCharCode.apply(null, trans);
  268.     }
  269.    
  270.     var isEmpty = new RegExp('/^\s+$/');
  271.     self.walkTextnode = function(node, func)
  272.     {
  273.         /* Iterates recursively through XML text nodes and applies a function to their contents, if they're not empty. */
  274.         var child;
  275.         for (child = node.firstChild; child !== null; child = child.nextSibling) {
  276.             if (child.nodeType === 3) {
  277.                 if (isEmpty.test(child.nodeValue) != true) {
  278.                     child.nodeValue = func(child.nodeValue);
  279.                 }
  280.             }
  281.             if (child.nodeType === 1) {
  282.                 self.walkTextnode(child, func);
  283.             }
  284.         }
  285.     }
  286.    
  287.     self.convertNode = function(node)
  288.     {
  289.         /* Converts an entire node to Wingdings.
  290.            
  291.            Example usage:
  292.            
  293.            UniDings.convertNode(getElementById("myElement")); */
  294.        
  295.         self.walkTextnode(node, self.convert);
  296.     }
  297.    
  298.     self.__init__ = (function()
  299.     {
  300.         self.initializeTranslationTable();
  301.     }).apply(self);
  302. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement