1 | define([ |
---|
2 | "dojo", |
---|
3 | "dijit", |
---|
4 | "dojox", |
---|
5 | "dijit/_Widget", |
---|
6 | "dijit/_TemplatedMixin", |
---|
7 | "dijit/_PaletteMixin", |
---|
8 | "dojo/_base/connect", |
---|
9 | "dojo/_base/declare", |
---|
10 | "dojo/i18n", |
---|
11 | "dojo/i18n!dojox/editor/plugins/nls/Smiley" |
---|
12 | ], function(dojo, dijit, dojox, _Widget, _TemplatedMixin, _PaletteMixin) { |
---|
13 | |
---|
14 | dojo.experimental("dojox.editor.plugins._SmileyPalette"); |
---|
15 | |
---|
16 | var Emoticon = dojo.declare("dojox.editor.plugins.Emoticon", |
---|
17 | null, |
---|
18 | { |
---|
19 | // summary: |
---|
20 | // JS Object representing an emoticon |
---|
21 | |
---|
22 | constructor: function(/*String*/ id){ |
---|
23 | // summary: |
---|
24 | // Create emoticon object from an id (like "smile") |
---|
25 | // value: String |
---|
26 | // alias name 'smile', 'cool' .. |
---|
27 | this.id = id; |
---|
28 | }, |
---|
29 | |
---|
30 | getValue: function(){ |
---|
31 | // summary: |
---|
32 | // Returns a emoticon string in ascii representation, ex: :-) |
---|
33 | return Emoticon.ascii[this.id]; |
---|
34 | }, |
---|
35 | |
---|
36 | imgHtml: function(/*String*/ clazz){ |
---|
37 | // summary: |
---|
38 | // Return the HTML string for an `<img>` node that shows this smiley |
---|
39 | var eId = "emoticon" + this.id.substr(0,1).toUpperCase() + this.id.substr(1), |
---|
40 | src = dojo.moduleUrl("dojox.editor.plugins", "resources/emoticons/" + eId + ".gif"), |
---|
41 | label = dojo.i18n.getLocalization("dojox.editor.plugins", "Smiley")[eId], |
---|
42 | html = ['<img src=\"', |
---|
43 | src, |
---|
44 | '\" class=\"', |
---|
45 | clazz, |
---|
46 | '\" alt=\"', |
---|
47 | this.getValue(), |
---|
48 | '\" title=\"', |
---|
49 | label, |
---|
50 | '\">']; |
---|
51 | return html.join(""); |
---|
52 | }, |
---|
53 | |
---|
54 | fillCell: function(/*DOMNode*/cell, /*String*/ blankGif){ |
---|
55 | dojo.place(this.imgHtml("dijitPaletteImg"), cell); |
---|
56 | } |
---|
57 | }); |
---|
58 | |
---|
59 | Emoticon.ascii = { |
---|
60 | smile: ":-)", |
---|
61 | laughing: "lol", |
---|
62 | wink: ";-)", |
---|
63 | grin: ":-D", |
---|
64 | cool: "8-)", |
---|
65 | angry: ":-@", |
---|
66 | half: ":-/", |
---|
67 | eyebrow: "/:)", |
---|
68 | frown: ":-(", |
---|
69 | shy: ":-$", |
---|
70 | goofy: ":-S", |
---|
71 | oops: ":-O", |
---|
72 | tongue: ":-P", |
---|
73 | idea: "(i)", |
---|
74 | yes: "(y)", |
---|
75 | no: "(n)", |
---|
76 | angel: "0:-)", |
---|
77 | crying: ":'(", |
---|
78 | happy: "=)" |
---|
79 | }; |
---|
80 | |
---|
81 | Emoticon.fromAscii = function(/*String*/str){ |
---|
82 | // summary: |
---|
83 | // Factory to create Emoticon object based on string like ":-)" rather than id like "smile" |
---|
84 | var ascii = Emoticon.ascii; |
---|
85 | for(var i in ascii){ |
---|
86 | if(str == ascii[i]){ |
---|
87 | return new Emoticon(i); |
---|
88 | } |
---|
89 | } |
---|
90 | return null; |
---|
91 | }; |
---|
92 | |
---|
93 | var SmileyPalette = dojo.declare("dojox.editor.plugins._SmileyPalette", [_Widget, _TemplatedMixin, _PaletteMixin], { |
---|
94 | // summary: |
---|
95 | // A keyboard accessible emoticon-picking widget (for inserting smiley characters) |
---|
96 | // description: |
---|
97 | // Grid showing various emoticons. |
---|
98 | // Can be used standalone, or as a popup. |
---|
99 | |
---|
100 | // templateString: |
---|
101 | // The template of this widget. |
---|
102 | templateString: |
---|
103 | '<table class="dijitInline dijitEditorSmileyPalette dijitPaletteTable"' + |
---|
104 | ' cellSpacing=0 cellPadding=0><tbody dojoAttachPoint="gridNode"></tbody></table>', |
---|
105 | |
---|
106 | baseClass: "dijitEditorSmileyPalette", |
---|
107 | |
---|
108 | _palette: [ |
---|
109 | ["smile", "laughing", "wink", "grin"], |
---|
110 | ["cool", "angry", "half", "eyebrow"], |
---|
111 | ["frown", "shy", "goofy", "oops"], |
---|
112 | ["tongue", "idea", "angel", "happy"], |
---|
113 | ["yes", "no", "crying", ""] |
---|
114 | ], |
---|
115 | |
---|
116 | dyeClass: Emoticon, |
---|
117 | |
---|
118 | buildRendering: function(){ |
---|
119 | // Instantiate the template, which makes a skeleton into which we'll insert a bunch of |
---|
120 | // <img> nodes |
---|
121 | this.inherited(arguments); |
---|
122 | |
---|
123 | var i18n = dojo.i18n.getLocalization("dojox.editor.plugins", "Smiley"); |
---|
124 | |
---|
125 | // Generate hash from emoticon standard name (like "smile") to translation |
---|
126 | var emoticonI18n = {}; |
---|
127 | for(var name in i18n){ |
---|
128 | if(name.substr(0,8) == "emoticon"){ |
---|
129 | emoticonI18n[name.substr(8).toLowerCase()] = i18n[name]; |
---|
130 | } |
---|
131 | } |
---|
132 | this._preparePalette( |
---|
133 | this._palette, |
---|
134 | emoticonI18n |
---|
135 | ); |
---|
136 | } |
---|
137 | }); |
---|
138 | |
---|
139 | // For monkey-patching |
---|
140 | SmileyPalette.Emoticon = Emoticon; |
---|
141 | |
---|
142 | return SmileyPalette; |
---|
143 | }); |
---|