| 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.ComboBox</title> |
| 11 |
<script src="../base.js"></script> |
| 12 |
<script> |
| 13 |
goog.require('goog.events'); |
| 14 |
goog.require('goog.ui.ComboBox'); |
| 15 |
goog.require('goog.debug.DivConsole'); |
| 16 |
goog.require('goog.dispose'); |
| 17 |
goog.require('goog.dom'); |
| 18 |
</script> |
| 19 |
<link rel="stylesheet" href="css/demo.css"> |
| 20 |
<link rel="stylesheet" href="../css/menu.css"> |
| 21 |
<link rel="stylesheet" href="../css/menuitem.css"> |
| 22 |
<link rel="stylesheet" href="../css/menuseparator.css"> |
| 23 |
<link rel="stylesheet" href="../css/combobox.css"> |
| 24 |
<style> |
| 25 |
|
| 26 |
html, body { |
| 27 |
overflow:hidden; |
| 28 |
margin: 0; |
| 29 |
padding: 5px; |
| 30 |
} |
| 31 |
|
| 32 |
#log { |
| 33 |
position: absolute; |
| 34 |
top: 50%; |
| 35 |
width: 100%; |
| 36 |
right: 0%; |
| 37 |
height: 50%; |
| 38 |
overflow: auto; |
| 39 |
} |
| 40 |
|
| 41 |
#c { |
| 42 |
margin-bottom: 10px; |
| 43 |
font-size: small; |
| 44 |
} |
| 45 |
|
| 46 |
/* Size the combobox so that it is sufficiently small to demonstrate the menu |
| 47 |
being positioned to left-align with the control. */ |
| 48 |
.goog-combobox input { |
| 49 |
width: 100px; |
| 50 |
} |
| 51 |
|
| 52 |
fieldset { |
| 53 |
display: inline-block; |
| 54 |
margin: 10px; |
| 55 |
text-align: initial; |
| 56 |
} |
| 57 |
</style> |
| 58 |
</head> |
| 59 |
<body> |
| 60 |
<h1>goog.ui.ComboBox</h1> |
| 61 |
<div id="c">cb.value = '<span id="v"></span>'</div> |
| 62 |
|
| 63 |
<fieldset style="float:left"> |
| 64 |
<legend>LTR</legend> |
| 65 |
<div class="combo"></div> |
| 66 |
</fieldset> |
| 67 |
|
| 68 |
<fieldset style="float:right"> |
| 69 |
<legend>LTR</legend> |
| 70 |
<div class="combo"></div> |
| 71 |
</fieldset> |
| 72 |
|
| 73 |
<div style="text-align:center"> |
| 74 |
<fieldset> |
| 75 |
<legend>LTR</legend> |
| 76 |
<div class="combo"></div> |
| 77 |
</fieldset> |
| 78 |
</div> |
| 79 |
|
| 80 |
<div style="clear:both"></div> |
| 81 |
|
| 82 |
<fieldset dir="rtl" style="float:left"> |
| 83 |
<legend>RTL</legend> |
| 84 |
<div class="combo"></div> |
| 85 |
</fieldset> |
| 86 |
|
| 87 |
<fieldset dir="rtl" style="float:right"> |
| 88 |
<legend>RTL</legend> |
| 89 |
<div class="combo"></div> |
| 90 |
</fieldset> |
| 91 |
|
| 92 |
<div style="text-align:center"> |
| 93 |
<fieldset dir="rtl"> |
| 94 |
<legend>RTL</legend> |
| 95 |
<div class="combo"></div> |
| 96 |
</fieldset> |
| 97 |
</div> |
| 98 |
|
| 99 |
|
| 100 |
<div style="clear:both"></div> |
| 101 |
|
| 102 |
<a href="javascript:void(logconsole.clear())">Clear Log</a> |
| 103 |
<div id="log"></div> |
| 104 |
|
| 105 |
<script type="text/javascript"> |
| 106 |
|
| 107 |
// Set up a logger to track responses |
| 108 |
goog.debug.LogManager.getRoot().setLevel(goog.debug.Logger.Level.ALL); |
| 109 |
var logconsole = new goog.debug.DivConsole(document.getElementById('log')); |
| 110 |
logconsole.setCapturing(true); |
| 111 |
|
| 112 |
function createTestComboBox() { |
| 113 |
var cb = new goog.ui.ComboBox(); |
| 114 |
cb.setUseDropdownArrow(true); |
| 115 |
cb.setDefaultText('Select a folder...'); |
| 116 |
|
| 117 |
var caption = new goog.ui.ComboBoxItem('Select folder...'); |
| 118 |
caption.setSticky(true); |
| 119 |
caption.setEnabled(false); |
| 120 |
cb.addItem(caption); |
| 121 |
|
| 122 |
cb.addItem(new goog.ui.ComboBoxItem('Inbox')); |
| 123 |
cb.addItem(new goog.ui.ComboBoxItem('Bills & statements')); |
| 124 |
cb.addItem(new goog.ui.ComboBoxItem('Cal alumni')); |
| 125 |
cb.addItem(new goog.ui.ComboBoxItem('Calendar Stuff')); |
| 126 |
cb.addItem(new goog.ui.ComboBoxItem('Design')); |
| 127 |
cb.addItem(new goog.ui.ComboBoxItem('Music')); |
| 128 |
cb.addItem(new goog.ui.ComboBoxItem('Netflix')); |
| 129 |
cb.addItem(new goog.ui.ComboBoxItem('Personal')); |
| 130 |
cb.addItem(new goog.ui.ComboBoxItem('Photos')); |
| 131 |
cb.addItem(new goog.ui.ComboBoxItem('Programming languages')); |
| 132 |
cb.addItem(new goog.ui.MenuSeparator()); |
| 133 |
|
| 134 |
var newfolder = new goog.ui.ComboBoxItem('New Folder...'); |
| 135 |
newfolder.setSticky(true); |
| 136 |
cb.addItem(newfolder); |
| 137 |
|
| 138 |
return cb; |
| 139 |
} |
| 140 |
|
| 141 |
var controls = []; |
| 142 |
var containerEls = goog.dom.getElementsByClass(goog.getCssName('combo')); |
| 143 |
for (var i = 0; i < containerEls.length; i++) { |
| 144 |
var cb = createTestComboBox(); |
| 145 |
cb.render(containerEls[i]); |
| 146 |
goog.events.listen(cb, 'change', handleChangeEvent); |
| 147 |
controls.push(cb); |
| 148 |
} |
| 149 |
|
| 150 |
function handleChangeEvent(e) { |
| 151 |
goog.dom.setTextContent(document.getElementById('v'), e.target.getValue()); |
| 152 |
} |
| 153 |
|
| 154 |
window.onbeforeunload = function() { |
| 155 |
goog.disposeAll(controls); |
| 156 |
}; |
| 157 |
|
| 158 |
</script> |
| 159 |
</body> |
| 160 |
</html> |