Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/editor/plugins/emoticons.js
2868 views
1
// Copyright 2009 The Closure Library Authors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS-IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
// All Rights Reserved
15
16
/**
17
* @fileoverview Plugin for generating emoticons.
18
*
19
* @author [email protected] (Nick Santos)
20
*/
21
22
goog.provide('goog.editor.plugins.Emoticons');
23
24
goog.require('goog.dom.TagName');
25
goog.require('goog.editor.Plugin');
26
goog.require('goog.editor.range');
27
goog.require('goog.functions');
28
goog.require('goog.ui.emoji.Emoji');
29
goog.require('goog.userAgent');
30
31
32
33
/**
34
* Plugin for generating emoticons.
35
*
36
* @constructor
37
* @extends {goog.editor.Plugin}
38
* @final
39
*/
40
goog.editor.plugins.Emoticons = function() {
41
goog.editor.plugins.Emoticons.base(this, 'constructor');
42
};
43
goog.inherits(goog.editor.plugins.Emoticons, goog.editor.Plugin);
44
45
46
/** The emoticon command. */
47
goog.editor.plugins.Emoticons.COMMAND = '+emoticon';
48
49
50
/** @override */
51
goog.editor.plugins.Emoticons.prototype.getTrogClassId =
52
goog.functions.constant(goog.editor.plugins.Emoticons.COMMAND);
53
54
55
/** @override */
56
goog.editor.plugins.Emoticons.prototype.isSupportedCommand = function(command) {
57
return command == goog.editor.plugins.Emoticons.COMMAND;
58
};
59
60
61
/**
62
* Inserts an emoticon into the editor at the cursor location. Places the
63
* cursor to the right of the inserted emoticon.
64
* @param {string} command Command to execute.
65
* @param {*=} opt_arg Emoji to insert.
66
* @return {!Object|undefined} The result of the command.
67
* @override
68
*/
69
goog.editor.plugins.Emoticons.prototype.execCommandInternal = function(
70
command, opt_arg) {
71
var emoji = /** @type {goog.ui.emoji.Emoji} */ (opt_arg);
72
73
var styleProperties = 'margin:0 0.2ex;vertical-align:middle;';
74
var emojiHeight = emoji.getHeight();
75
styleProperties += emojiHeight ? 'height:' + emojiHeight + 'px;' : '';
76
var emojiWidth = emoji.getWidth();
77
styleProperties += emojiWidth ? 'width:' + emojiWidth + 'px;' : '';
78
79
var dom = this.getFieldDomHelper();
80
var imgAttributes = {'src': emoji.getUrl(), 'style': styleProperties};
81
if (emoji.getAltText()) {
82
imgAttributes['alt'] = emoji.getAltText();
83
}
84
var img = dom.createDom(goog.dom.TagName.IMG, imgAttributes);
85
86
img.setAttribute(goog.ui.emoji.Emoji.ATTRIBUTE, emoji.getId());
87
img.setAttribute(goog.ui.emoji.Emoji.DATA_ATTRIBUTE, emoji.getId());
88
89
this.getFieldObject().getRange().replaceContentsWithNode(img);
90
91
// IE8 does the right thing with the cursor, and has a js error when we try
92
// to place the cursor manually.
93
// IE9 loses the cursor when the window is focused, so focus first.
94
if (!goog.userAgent.IE || goog.userAgent.isDocumentModeOrHigher(9)) {
95
this.getFieldObject().focus();
96
goog.editor.range.placeCursorNextTo(img, false);
97
}
98
};
99
100