_SmileyPalette.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.editor.plugins._SmileyPalette"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.editor.plugins._SmileyPalette"] = true;
  8. dojo.provide("dojox.editor.plugins._SmileyPalette");
  9. dojo.require("dijit._Widget");
  10. dojo.require("dijit._PaletteMixin");
  11. dojo.require("dojo.i18n");
  12. dojo.requireLocalization("dojox.editor.plugins", "Smiley", null, "ROOT,ar,bg,ca,cs,da,de,el,es,fi,fr,he,hr,hu,it,ja,kk,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw");
  13. dojo.experimental("dojox.editor.plugins._SmileyPalette");
  14. dojo.declare("dojox.editor.plugins._SmileyPalette",
  15. [dijit._Widget, dijit._Templated, dijit._PaletteMixin],
  16. {
  17. // summary:
  18. // A keyboard accessible emoticon-picking widget (for inserting smiley characters)
  19. // description:
  20. // Grid showing various emoticons.
  21. // Can be used standalone, or as a popup.
  22. //
  23. // example:
  24. // | <div dojoType="dojox.editor.plugins._SmileyPalette"></div>
  25. //
  26. // example:
  27. // | var picker = new dojox.editor.plugins._SmileyPalette({ },srcNode);
  28. // | picker.startup();
  29. // The template of this widget.
  30. templateString:
  31. '<table class="dijitInline dijitEditorSmileyPalette dijitPaletteTable"' +
  32. ' cellSpacing=0 cellPadding=0><tbody dojoAttachPoint="gridNode"></tbody></table>',
  33. baseClass: "dijitEditorSmileyPalette",
  34. _palette: [
  35. ["smile", "laughing", "wink", "grin"],
  36. ["cool", "angry", "half", "eyebrow"],
  37. ["frown", "shy", "goofy", "oops"],
  38. ["tongue", "idea", "angel", "happy"],
  39. ["yes", "no", "crying", ""]
  40. ],
  41. dyeClass: 'dojox.editor.plugins.Emoticon',
  42. buildRendering: function(){
  43. // Instantiate the template, which makes a skeleton into which we'll insert a bunch of
  44. // <img> nodes
  45. this.inherited(arguments);
  46. var i18n = dojo.i18n.getLocalization("dojox.editor.plugins", "Smiley");
  47. // Generate hash from emoticon standard name (like "smile") to translation
  48. var emoticonI18n = {};
  49. for(var name in i18n){
  50. if(name.substr(0,8) == "emoticon"){
  51. emoticonI18n[name.substr(8).toLowerCase()] = i18n[name];
  52. }
  53. }
  54. this._preparePalette(
  55. this._palette,
  56. emoticonI18n
  57. );
  58. }
  59. });
  60. dojo.declare("dojox.editor.plugins.Emoticon",
  61. null,
  62. {
  63. // summary:
  64. // JS Object representing an emoticon
  65. constructor: function(/*String*/ id){
  66. // summary:
  67. // Create emoticon object from an id (like "smile")
  68. // value: String
  69. // alias name 'smile', 'cool' ..
  70. this.id = id;
  71. },
  72. getValue: function(){
  73. // summary:
  74. // Returns a emoticon string in ascii representation, ex: :-)
  75. return dojox.editor.plugins.Emoticon.ascii[this.id];
  76. },
  77. imgHtml: function(/*String*/ clazz){
  78. // summary:
  79. // Return the HTML string for an <img> node that shows this smiley
  80. var eId = "emoticon" + this.id.substr(0,1).toUpperCase() + this.id.substr(1),
  81. src = dojo.moduleUrl("dojox.editor.plugins", "resources/emoticons/" + eId + ".gif"),
  82. label = dojo.i18n.getLocalization("dojox.editor.plugins", "Smiley")[eId],
  83. html = ['<img src=\"',
  84. src,
  85. '\" class=\"',
  86. clazz,
  87. '\" alt=\"',
  88. this.getValue(),
  89. '\" title=\"',
  90. label,
  91. '\">'];
  92. return html.join("");
  93. },
  94. fillCell: function(/*DOMNode*/cell, /*String*/ blankGif){
  95. dojo.place(this.imgHtml("dijitPaletteImg"), cell);
  96. }
  97. });
  98. dojox.editor.plugins.Emoticon.ascii = {
  99. smile: ":-)",
  100. laughing: "lol",
  101. wink: ";-)",
  102. grin: ":-D",
  103. cool: "8-)",
  104. angry: ":-@",
  105. half: ":-/",
  106. eyebrow: "/:)",
  107. frown: ":-(",
  108. shy: ":-$",
  109. goofy: ":-S",
  110. oops: ":-O",
  111. tongue: ":-P",
  112. idea: "(i)",
  113. yes: "(y)",
  114. no: "(n)",
  115. angel: "0:-)",
  116. crying: ":'(",
  117. happy: "=)"
  118. };
  119. dojox.editor.plugins.Emoticon.fromAscii = function(/*String*/str){
  120. // summary:
  121. // Factory to create Emoticon object based on string like ":-)" rather than id like "smile"
  122. var ascii = dojox.editor.plugins.Emoticon.ascii;
  123. for(var i in ascii){
  124. if(str == ascii[i]){
  125. return new dojox.editor.plugins.Emoticon(i);
  126. }
  127. }
  128. return null;
  129. };
  130. }