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