Debian Codegraph @

closure-library/closure/goog/demos/css3button.html

raw
1 <!DOCTYPE html>
2 <html>
3 <!--
4 Copyright 2010 The Closure Library Authors. All Rights Reserved.
5
6 Use of this source code is governed by the Apache License, Version 2.0.
7 See the COPYING file for details.
8 -->
9 <head>
10 <title>
11 goog.ui.Css3ButtonRenderer Demo
12 </title>
13 <script type="text/javascript" src="../base.js"></script>
14 <script type="text/javascript">
15 goog.require('goog.array');
16 goog.require('goog.debug.DivConsole');
17 goog.require('goog.debug.LogManager');
18 goog.require('goog.events');
19 goog.require('goog.log');
20 goog.require('goog.object');
21 goog.require('goog.ui.Css3ButtonRenderer');
22 goog.require('goog.ui.CustomButton');
23 goog.require('goog.ui.ToggleButton');
24 goog.require('goog.ui.decorate');
25 </script>
26 <link rel="stylesheet" type="text/css" href="css/demo.css">
27 <link rel="stylesheet" type="text/css" href="../css/common.css">
28 <link rel="stylesheet" type="text/css" href="../css/css3button.css">
29 </head>
30 <body>
31 <h2>Demo of goog.ui.Css3ButtonRenderer</h2>
32 <fieldset>
33 <legend>
34 These buttons were rendered using
35 <strong>goog.ui.Css3ButtonRenderer</strong>:
36 </legend>
37 <br/>
38 These buttons were created programmatically:<br/>
39 <div id="cb1"></div>
40 <br/>
41 These buttons were created by decorating some DIVs, and they dispatch
42 state transition events (watch the event log):<br/>
43 <div id="cb2">
44 <div id="foo" class="goog-css3-button" title="Title specified in HTML">
45 Decorated <b>Button</b>, yay!
46 </div><div id="bar" class="goog-css3-button goog-css3-button-disabled"
47 title="Initialized to DISABLED in HTML...">Decorated Disabled
48 </div><div id="fee" class="goog-css3-button">Another Button</div><div id="btn1"
49 class="goog-css3-button goog-css3-button-collapse-right">
50 Archive
51 </div><div id="btn2"
52 class="goog-css3-button goog-css3-button-collapse-right goog-css3-button-collapse-left">
53 Delete
54 </div><div id="btn3"
55 class="goog-css3-button goog-css3-button-collapse-left">
56 Report Spam
57 </div>
58 </div>
59 <br/>
60 Use these <strong>ToggleButton</strong>s to hide/show and enable/disable
61 the middle button:<br/>
62 <div id="toggleEnable" class="goog-css3-toggle-button"
63 title="Click here to enable/disable the button above">Enable</div>
64 <div id="hideShow"
65 class="goog-css3-toggle-button goog-css3-button-checked"
66 title="Click here to hide/show the button above">Show</div>
67 <br/><br/>
68 Combined toggle buttons<br/>
69 <div id="btn4" class="goog-css3-toggle-button goog-css3-button-collapse-right">
70 Bold
71 </div><div id="btn5" class="goog-css3-toggle-button goog-css3-button-collapse-right goog-css3-button-collapse-left">
72 Italics
73 </div><div id="btn6" class="goog-css3-toggle-button goog-css3-button-collapse-left goog-css3-button-checked">
74 Underlined
75 </div>
76 </fieldset>
77 <br/>
78 <div id="perf"></div>
79 <!-- Event log. -->
80 <fieldset class="goog-debug-panel">
81 <legend>Event Log</legend>
82 <div id="log"></div>
83 </fieldset>
84
85 <script type="text/javascript">
86 var timer = goog.now();
87
88 // Set up a logger.
89 goog.debug.LogManager.getRoot().setLevel(goog.log.Level.ALL);
90 var logger = goog.log.getLogger('demo');
91 var logconsole = new goog.debug.DivConsole(goog.dom.getElement('log'));
92 logconsole.setCapturing(true);
93
94 var EVENTS = goog.object.getValues(goog.ui.Component.EventType);
95 goog.log.fine(logger, 'Listening for: ' + EVENTS.join(', ') + '.');
96
97 function logEvent(e) {
98 goog.log.info(logger, '"' + e.target.getCaption() + '" dispatched: ' + e.type);
99 }
100
101 // Create some buttons using CustomButton with the
102 // Css3ButtonRenderer renderer.
103 var disabledButton;
104 var customButtons = [
105 new goog.ui.CustomButton('Button',
106 goog.ui.Css3ButtonRenderer.getInstance()),
107 new goog.ui.CustomButton('Another Button',
108 goog.ui.Css3ButtonRenderer.getInstance()),
109 disabledButton = new goog.ui.CustomButton('Disabled Button',
110 goog.ui.Css3ButtonRenderer.getInstance()),
111 new goog.ui.CustomButton('Yet Another Button',
112 goog.ui.Css3ButtonRenderer.getInstance())
113 ];
114 disabledButton.setEnabled(false);
115 goog.array.forEach(customButtons, function(b) {
116 b.render(goog.dom.getElement('cb1'));
117 goog.events.listen(b, goog.ui.Component.EventType.ACTION,
118 function(e) {
119 var newCaption = window.prompt('Enter new caption for button:');
120 b.setCaption(newCaption || 'Empty');
121 });
122 goog.events.listen(b, EVENTS, logEvent);
123 });
124
125 // Decorate some buttons.
126 var cb2 = [];
127 var decoratedButtons = goog.array.map([
128 'foo', 'bar', 'fee', 'btn1', 'btn2', 'btn3', 'btn4', 'btn5', 'btn6'
129 ], goog.dom.getElement);
130 goog.array.forEach(decoratedButtons, function(element) {
131 // Since the elements to be decorated each have the correct "marker" CSS
132 // class ("goog-css3-custom-button"), we can use the renderer
133 // registry to get the appropriate control instance to decorate them.
134 var button = goog.ui.decorate(element);
135 button.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
136 cb2.push(button);
137 goog.events.listen(button, EVENTS, logEvent);
138 });
139
140 // Decorate toggle buttons.
141 var toggleEnableElem = goog.dom.getElement('toggleEnable');
142 var toggleEnable = goog.ui.decorate(toggleEnableElem);
143 toggleEnable.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
144
145 goog.events.listen(toggleEnable, EVENTS, logEvent);
146
147 goog.events.listen(toggleEnable, goog.ui.Component.EventType.ACTION,
148 function(e) {
149 cb2[1].setEnabled(e.target.isChecked());
150 });
151
152 var hideShowElem = goog.dom.getElement('hideShow');
153 var hideShow = new goog.ui.decorate(hideShowElem);
154 hideShow.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
155 goog.events.listen(hideShow, EVENTS, logEvent);
156
157 goog.events.listen(hideShow, goog.ui.Component.EventType.ACTION,
158 function(e) {
159 cb2[1].setVisible(e.target.isChecked());
160 });
161
162 goog.dom.setTextContent(goog.dom.getElement('perf'),
163 (goog.now() - timer) +'ms');
164 </script>
165 </body>
166 </html>