4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
12 var DOM = tinymce.DOM;
15 * This class is used to create a UI button. A button is basically a link
16 * that is styled to look like a button or icon.
18 * @class tinymce.ui.Button
19 * @extends tinymce.ui.Control
21 tinymce.create('tinymce.ui.Button:tinymce.ui.Control', {
23 * Constructs a new button control instance.
27 * @param {String} id Control id for the button.
28 * @param {Object} s Optional name/value settings object.
29 * @param {Editor} ed Optional the editor instance this button is for.
31 Button : function(id, s, ed) {
32 this.parent(id, s, ed);
33 this.classPrefix = 'mceButton';
37 * Renders the button as a HTML string. This method is much faster than using the DOM and when
38 * creating a whole toolbar with buttons it does make a lot of difference.
41 * @return {String} HTML for the button control element.
43 renderHTML : function() {
44 var cp = this.classPrefix, s = this.settings, h, l;
46 l = DOM.encode(s.label || '');
47 h = '<a role="button" id="' + this.id + '" href="javascript:;" class="' + cp + ' ' + cp + 'Enabled ' + s['class'] + (l ? ' ' + cp + 'Labeled' : '') +'" onmousedown="return false;" onclick="return false;" aria-labelledby="' + this.id + '_voice" title="' + DOM.encode(s.title) + '">';
48 if (s.image && !(this.editor &&this.editor.forcedHighContrastMode) )
49 h += '<img class="mceIcon" src="' + s.image + '" alt="' + DOM.encode(s.title) + '" />' + l;
51 h += '<span class="mceIcon ' + s['class'] + '"></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '');
53 h += '<span class="mceVoiceLabel mceIconOnly" style="display: none;" id="' + this.id + '_voice">' + s.title + '</span>';
59 * Post render handler. This function will be called after the UI has been
60 * rendered so that events can be added.
64 postRender : function() {
65 var t = this, s = t.settings;
67 tinymce.dom.Event.add(t.id, 'click', function(e) {
69 return s.onclick.call(s.scope, e);