1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
<!DOCTYPE html>
<html>
<!--
Copyright The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<title>
goog.ui.ImagelessButtonRenderer Demo
</title>
<script src="../base.js"></script>
<script>
goog.require('goog.array');
goog.require('goog.debug.DivConsole');
goog.require('goog.events');
goog.require('goog.log');
goog.require('goog.object');
goog.require('goog.ui.CustomButton');
goog.require('goog.ui.ImagelessButtonRenderer');
goog.require('goog.ui.ToggleButton');
goog.require('goog.ui.decorate');
goog.require('goog.dom.TagName');
</script>
<link rel="stylesheet" href="css/demo.css">
<link rel="stylesheet" href="../css/imagelessbutton.css">
<style>
/* Base class for all icon elements. */
.icon {
height: 16px;
width: 16px;
margin: 0 4px 0 0;
background-image: url(../images/toolbar_icons.gif);
background-repeat: no-repeat;
vertical-align: middle;
}
/* "Highlight" icon. */
.highlight-icon{
background-position: -64px;
}
/* "Insert Image" icon. */
.insert-image-icon {
background-position: -80px;
}
/* Custom style for the "default" button. */
.default-button {
font-weight: bold;
}
</style>
</head>
<body>
<h1>goog.ui.ImagelessButtonRenderer</h1>
<fieldset>
<legend>
These buttons were rendered using
<strong>goog.ui.ImagelessButtonRenderer</strong>:
</legend>
<br/>
These buttons were created programmatically:<br/>
<div id="cb1"></div>
<br/>
These buttons were created by decorating some DIVs, and they dispatch
state transition events (watch the event log):<br/>
<div id="cb2">
<!-- On FF2, if you don't enclose the contents of the button in a SPAN,
the bold element isn't rendered. Works on every other browser. -->
<div id="foo" class="goog-imageless-button"
title="Title specified in HTML">
<span>Decorated <b>Button</b>, yay!</span>
</div>
<div id="bar" class="goog-imageless-button goog-imageless-button-disabled"
title="Initialized to DISABLED in HTML...">Decorated Disabled</div>
<div id="fee" class="goog-imageless-button">Another Button</div>
<div id="btn1"
class="goog-imageless-button goog-imageless-button-collapse-right">
Archive
</div><div id="btn2"
class="goog-imageless-button goog-imageless-button-collapse-right goog-imageless-button-collapse-left">
Delete
</div><div id="btn3"
class="goog-imageless-button goog-imageless-button-collapse-left">
Report Spam
</div>
</div>
<br/>
Use these <strong>ToggleButton</strong>s to hide/show and enable/disable
the middle button:<br/>
<div id="toggleEnable" class="goog-imageless-toggle-button"
title="Click here to enable/disable the button above">Enable</div>
<div id="hideShow"
class="goog-imageless-toggle-button goog-imageless-button-checked"
title="Click here to hide/show the button above">Show</div>
<br/><br/>
Combined toggle buttons<br/>
<div id="btn4" class="goog-imageless-toggle-button goog-imageless-button-collapse-right">
Bold
</div><div id="btn5" class="goog-imageless-toggle-button goog-imageless-button-collapse-right goog-imageless-button-collapse-left">
Italics
</div><div id="btn6" class="goog-imageless-toggle-button goog-imageless-button-collapse-left goog-imageless-button-checked">
Underlined
</div>
<br/><br/>
These buttons have icons, and the second one has an extra CSS class:<br/>
<div id="iconbuttons"></div>
<br/>
</fieldset>
<br/>
<div id="perf"></div>
<!-- Event log. -->
<fieldset class="goog-debug-panel">
<legend>Event Log</legend>
<div id="log"></div>
</fieldset>
<script type="text/javascript">
var timer = goog.now();
// Set up a logger.
goog.log.setLevel(goog.log.getRootLogger(), goog.log.Level.ALL);
var logger = goog.log.getLogger('demo');
var logconsole = new goog.debug.DivConsole(goog.dom.getElement('log'));
logconsole.setCapturing(true);
var EVENTS = goog.object.getValues(goog.ui.Component.EventType);
goog.log.fine(logger, 'Listening for: ' + EVENTS.join(', ') + '.');
function logEvent(e) {
goog.log.info(logger, '"' + e.target.getCaption() + '" dispatched: ' + e.type);
}
// Create some buttons using CustomButton with the
// ImagelessButtonRenderer renderer.
var disabledButton;
var customButtons = [
new goog.ui.CustomButton('Button',
goog.ui.ImagelessButtonRenderer.getInstance()),
new goog.ui.CustomButton('Another Button',
goog.ui.ImagelessButtonRenderer.getInstance()),
disabledButton = new goog.ui.CustomButton('Disabled Button',
goog.ui.ImagelessButtonRenderer.getInstance()),
new goog.ui.CustomButton('Yet Another Button',
goog.ui.ImagelessButtonRenderer.getInstance())
];
disabledButton.setEnabled(false);
goog.array.forEach(customButtons, function(b) {
b.render(goog.dom.getElement('cb1'));
goog.events.listen(b, goog.ui.Component.EventType.ACTION,
function(e) {
var newCaption = window.prompt('Enter new caption for button:');
b.setCaption(newCaption || 'Empty');
});
goog.events.listen(b, EVENTS, logEvent);
});
// Decorate some buttons.
var cb2 = [];
var decoratedButtons = goog.array.map([
'foo', 'bar', 'fee', 'btn1', 'btn2', 'btn3', 'btn4', 'btn5', 'btn6'
], goog.dom.getElement);
goog.array.forEach(decoratedButtons, function(element) {
// Since the elements to be decorated each have the correct "marker" CSS
// class ("goog-imageless-button"), we can use the renderer
// registry to get the appropriate control instance to decorate them.
var button = goog.ui.decorate(element);
button.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
cb2.push(button);
goog.events.listen(button, EVENTS, logEvent);
});
// Decorate toggle buttons.
var toggleEnableElem = goog.dom.getElement('toggleEnable');
var toggleEnable = goog.ui.decorate(toggleEnableElem);
toggleEnable.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
goog.events.listen(toggleEnable, EVENTS, logEvent);
goog.events.listen(toggleEnable, goog.ui.Component.EventType.ACTION,
function(e) {
cb2[1].setEnabled(e.target.isChecked());
});
var hideShowElem = goog.dom.getElement('hideShow');
var hideShow = new goog.ui.decorate(hideShowElem);
hideShow.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
goog.events.listen(hideShow, EVENTS, logEvent);
goog.events.listen(hideShow, goog.ui.Component.EventType.ACTION,
function(e) {
cb2[1].setVisible(e.target.isChecked());
});
// Use a DIV with a background image as the icon, and a SPAN as the caption.
var iconbutton1 = new goog.ui.ToggleButton([
goog.dom.createDom(goog.dom.TagName.DIV, 'icon insert-image-icon goog-inline-block'),
'Insert Image'
], goog.ui.ImagelessButtonRenderer.getInstance());
iconbutton1.render(goog.dom.getElement('iconbuttons'));
goog.events.listen(iconbutton1, EVENTS, logEvent);
// Add a custom style, too.
var iconbutton2 = new goog.ui.ToggleButton([
goog.dom.createDom(goog.dom.TagName.DIV, 'icon highlight-icon goog-inline-block'),
'Highlight Text'
], goog.ui.ImagelessButtonRenderer.getInstance());
iconbutton2.addClassName('default-button');
iconbutton2.render(goog.dom.getElement('iconbuttons'));
goog.events.listen(iconbutton2, EVENTS, logEvent);
goog.dom.setTextContent(goog.dom.getElement('perf'),
(goog.now() - timer) + 'ms');
</script>
</body>
</html>
|