| 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>goog.ui.SelectionMenuButton Demo</title> |
| 11 |
<script src="../base.js"></script> |
| 12 |
<script> |
| 13 |
goog.require('goog.array'); |
| 14 |
goog.require('goog.debug.DivConsole'); |
| 15 |
goog.require('goog.debug.LogManager'); |
| 16 |
goog.require('goog.events'); |
| 17 |
goog.require('goog.events.EventType'); |
| 18 |
goog.require('goog.log'); |
| 19 |
goog.require('goog.object'); |
| 20 |
goog.require('goog.ui.MenuItem'); |
| 21 |
goog.require('goog.ui.SelectionMenuButton'); |
| 22 |
goog.require('goog.ui.Separator'); |
| 23 |
goog.require('goog.ui.decorate'); |
| 24 |
</script> |
| 25 |
<link rel="stylesheet" href="css/demo.css"> |
| 26 |
<link rel="stylesheet" href="../css/menubutton.css"> |
| 27 |
<style> |
| 28 |
/* Base class for all icon elements. */ |
| 29 |
.icon { |
| 30 |
height: 16px; |
| 31 |
width: 16px; |
| 32 |
margin: 0 1px; |
| 33 |
background-image: url(../images/toolbar_icons.gif); |
| 34 |
background-repeat: no-repeat; |
| 35 |
vertical-align: middle; |
| 36 |
} |
| 37 |
|
| 38 |
/* "Format" icon. */ |
| 39 |
.format-icon{ |
| 40 |
background-position: -64px; |
| 41 |
} |
| 42 |
</style> |
| 43 |
</head> |
| 44 |
<body> |
| 45 |
<h1>goog.ui.SelectionMenuButton</h1> |
| 46 |
<table border="0" cellpadding="0" cellspacing="4" width="100%"> |
| 47 |
<tbody> |
| 48 |
<tr valign="top"> |
| 49 |
<td width="67%"> |
| 50 |
<fieldset> |
| 51 |
<legend> |
| 52 |
This <strong>SelectionMenuButton</strong> was created programmatically: |
| 53 |
|
| 54 |
</legend> |
| 55 |
<table border="0" cellpadding="0" cellspacing="4"> |
| 56 |
<tbody> |
| 57 |
<tr valign="middle"> |
| 58 |
<td> |
| 59 |
<div id="menuButtons"></div> |
| 60 |
</td> |
| 61 |
<td> |
| 62 |
Enable button: |
| 63 |
<input type="checkbox" id="b1_enable" checked> |
| 64 |
|
| 65 |
</td> |
| 66 |
</tr> |
| 67 |
</tbody> |
| 68 |
</table> |
| 69 |
<label> |
| 70 |
</label> |
| 71 |
<br> |
| 72 |
</fieldset> |
| 73 |
<fieldset> |
| 74 |
<legend> |
| 75 |
This <strong>SelectionMenuButton</strong> decorates an element: |
| 76 |
</legend> |
| 77 |
<table border="0" cellpadding="0" cellspacing="4"> |
| 78 |
<tbody> |
| 79 |
<tr valign="middle"> |
| 80 |
<td> |
| 81 |
<div id="selectButton" class="goog-selectionmenubutton-button" |
| 82 |
title="Select"> |
| 83 |
<!-- These elements will become the button's caption. --> |
| 84 |
<input type="checkbox" class="goog-selectionmenubutton-checkbox"></input> |
| 85 |
<!-- This DIV will be auto-decorated with a menu. --> |
| 86 |
<div id="selectMenu" class="goog-menu"> |
| 87 |
<div class="goog-menuitem">All</div> |
| 88 |
<div class="goog-menuitem">None</div> |
| 89 |
<div class="goog-menuseparator"></div> |
| 90 |
<div class="goog-menuitem">Starred</div> |
| 91 |
<div class="goog-menuitem goog-menuitem-disabled"> |
| 92 |
Unstarred |
| 93 |
</div> |
| 94 |
<div class="goog-menuseparator"></div> |
| 95 |
<div class="goog-menuitem">Read</div> |
| 96 |
<div class="goog-menuitem">Unread</div> |
| 97 |
</div> |
| 98 |
</div> |
| 99 |
</td> |
| 100 |
<td> |
| 101 |
Enable button: |
| 102 |
<input type="checkbox" id="selectButton_enable" checked> |
| 103 |
|
| 104 |
Show button: |
| 105 |
<input type="checkbox" id="selectButton_show" checked> |
| 106 |
|
| 107 |
</td> |
| 108 |
</tr> |
| 109 |
</tbody> |
| 110 |
</table> |
| 111 |
<label> |
| 112 |
</label> |
| 113 |
<br> |
| 114 |
</fieldset> |
| 115 |
</td> |
| 116 |
<td width="33%"> |
| 117 |
<!-- Event log. --> |
| 118 |
<fieldset class="goog-debug-panel"> |
| 119 |
<legend>Event Log</legend> |
| 120 |
<div id="log"></div> |
| 121 |
</fieldset> |
| 122 |
</td> |
| 123 |
</tr> |
| 124 |
</tbody> |
| 125 |
</table> |
| 126 |
<br> |
| 127 |
<div id="perf"></div> |
| 128 |
<script> |
| 129 |
var timer = goog.now(); |
| 130 |
|
| 131 |
// Set up a logger. |
| 132 |
goog.debug.LogManager.getRoot().setLevel(goog.log.Level.ALL); |
| 133 |
var logger = goog.log.getLogger('demo'); |
| 134 |
var logconsole = new goog.debug.DivConsole(goog.dom.getElement('log')); |
| 135 |
logconsole.setCapturing(true); |
| 136 |
|
| 137 |
var EVENTS = goog.object.getValues(goog.ui.Component.EventType); |
| 138 |
goog.log.fine(logger, 'Listening for: ' + EVENTS.join(', ') + '.'); |
| 139 |
|
| 140 |
function logEvent(e) { |
| 141 |
var component = e.target; |
| 142 |
var caption = (typeof component.getCaption == 'function') ? |
| 143 |
component.getCaption() : component.getId(); |
| 144 |
goog.log.info(logger, '"' + caption + '" dispatched: ' + e.type); |
| 145 |
} |
| 146 |
|
| 147 |
// Create the first button programmatically. |
| 148 |
var b1 = new goog.ui.SelectionMenuButton(); |
| 149 |
b1.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true); |
| 150 |
b1.setId('progSelectButton'); |
| 151 |
b1.render(goog.dom.getElement('menuButtons')); |
| 152 |
b1.setTooltip('Select menu demo'); |
| 153 |
goog.events.listen(b1, EVENTS, logEvent); |
| 154 |
b1.addItem(new goog.ui.MenuItem('Important')); |
| 155 |
b1.addItem(new goog.ui.MenuItem('Unimportant')); |
| 156 |
|
| 157 |
goog.events.listen(goog.dom.getElement('b1_enable'), |
| 158 |
goog.events.EventType.CLICK, |
| 159 |
function(e) { |
| 160 |
b1.setEnabled(e.target.checked); |
| 161 |
}); |
| 162 |
|
| 163 |
// Decorate a menu button. Note that since one of the child nodes of the |
| 164 |
// menu button element can be decorated as a menu, it is auto-decorated and |
| 165 |
// attached to the button. |
| 166 |
var selectButton = goog.ui.decorate(goog.dom.getElement('selectButton')); |
| 167 |
|
| 168 |
goog.events.listen(goog.dom.getElement('selectButton_show'), |
| 169 |
goog.events.EventType.CLICK, |
| 170 |
function(e) { |
| 171 |
selectButton.setVisible(e.target.checked); |
| 172 |
}); |
| 173 |
|
| 174 |
goog.events.listen(goog.dom.getElement('selectButton_enable'), |
| 175 |
goog.events.EventType.CLICK, |
| 176 |
function(e) { |
| 177 |
selectButton.setEnabled(e.target.checked); |
| 178 |
}); |
| 179 |
|
| 180 |
goog.events.listen(selectButton, EVENTS, logEvent); |
| 181 |
|
| 182 |
goog.dom.setTextContent(goog.dom.getElement('perf'), |
| 183 |
(goog.now() - timer) + 'ms'); |
| 184 |
</script> |
| 185 |
</body> |
| 186 |
</html> |