| 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.PopupMenu</title> |
| 11 |
<script src="../base.js"></script> |
| 12 |
<script> |
| 13 |
goog.require('goog.positioning.Corner'); |
| 14 |
goog.require('goog.object'); |
| 15 |
goog.require('goog.ui.MenuItem'); |
| 16 |
goog.require('goog.ui.PopupMenu'); |
| 17 |
goog.require('goog.dom.TagName'); |
| 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 |
<style> |
| 24 |
.event-log { |
| 25 |
border: 1px solid #CCC; |
| 26 |
height: 300px; |
| 27 |
position: absolute; |
| 28 |
right: 20px; |
| 29 |
width: 400px; |
| 30 |
} |
| 31 |
|
| 32 |
.event-log-content { |
| 33 |
height: 280px; |
| 34 |
overflow: auto; |
| 35 |
} |
| 36 |
</style> |
| 37 |
</head> |
| 38 |
<body> |
| 39 |
<h1>goog.ui.PopupMenu</h1> |
| 40 |
<div> |
| 41 |
This shows a 2 popup menus, each menu has been attached to two targets. |
| 42 |
<br><br> |
| 43 |
</div> |
| 44 |
|
| 45 |
<fieldset class="event-log"> |
| 46 |
<legend>Event log</legend> |
| 47 |
<div id="event-log" class="event-log-content"></div> |
| 48 |
</fieldset> |
| 49 |
<div id="foo" style="width: 600px; height: 300px; background-color: #EEE"> |
| 50 |
<div> |
| 51 |
<span>Hello there <i>I'm italic!</i></span> |
| 52 |
</div> |
| 53 |
<div><button id="bar">Decorated Popup attached to a Button</button></div> |
| 54 |
</div> |
| 55 |
|
| 56 |
<button id="bar2" style="position:absolute;left: 600px;top:330px;">Button</button> |
| 57 |
|
| 58 |
<button id="dButton">Decorated Popup</button> |
| 59 |
<div id="dMenu" for="dButton" class="goog-menu" style="display:none"> |
| 60 |
<div class="goog-menuitem">A a</div> |
| 61 |
<div class="goog-menuitem">B b</div> |
| 62 |
<div class="goog-menuitem">C c</div> |
| 63 |
<div class="goog-menuitem">D d</div> |
| 64 |
<div class="goog-menuitem">E e</div> |
| 65 |
<div class="goog-menuitem">F f</div> |
| 66 |
</div> |
| 67 |
|
| 68 |
<script> |
| 69 |
var pm = new goog.ui.PopupMenu(); |
| 70 |
pm.addItem(new goog.ui.MenuItem('One')); |
| 71 |
pm.addItem(new goog.ui.MenuItem('Two')); |
| 72 |
pm.addItem(new goog.ui.MenuItem('Three')); |
| 73 |
pm.addItem(new goog.ui.MenuItem('Four')); |
| 74 |
pm.addItem(new goog.ui.MenuItem('Five')); |
| 75 |
pm.addItem(new goog.ui.MenuItem('Six')); |
| 76 |
pm.addItem(new goog.ui.MenuItem('Seven')); |
| 77 |
pm.render(document.body); |
| 78 |
|
| 79 |
//pm.attach(document.getElementById('foo'), null, null); |
| 80 |
|
| 81 |
pm.attach( |
| 82 |
document.getElementById('bar2'), |
| 83 |
goog.positioning.Corner.TOP_LEFT, |
| 84 |
goog.positioning.Corner.BOTTOM_LEFT); |
| 85 |
|
| 86 |
pm.attach(document.getElementById('foo')); |
| 87 |
|
| 88 |
|
| 89 |
var pm2 = new goog.ui.PopupMenu(); |
| 90 |
pm2.setToggleMode(true); |
| 91 |
pm2.decorate(document.getElementById('dMenu')); |
| 92 |
|
| 93 |
pm2.attach( |
| 94 |
document.getElementById('bar'), |
| 95 |
goog.positioning.Corner.BOTTOM_LEFT, |
| 96 |
goog.positioning.Corner.TOP_LEFT); |
| 97 |
|
| 98 |
function logEvent(e) { |
| 99 |
var entry = goog.dom.createDom(goog.dom.TagName.DIV, null, |
| 100 |
'type: ' + e.type + |
| 101 |
', target: ' + e.target.constructor.name + |
| 102 |
(e.target.getCaption ? ', caption: ' + e.target.getCaption() : '')); |
| 103 |
var eventLog = goog.dom.getElement('event-log'); |
| 104 |
eventLog.appendChild(entry); |
| 105 |
// Scroll to the bottom. |
| 106 |
eventLog.scrollTop = eventLog.scrollHeight; |
| 107 |
} |
| 108 |
|
| 109 |
goog.object.forEach(goog.ui.Component.EventType, function(type) { |
| 110 |
goog.events.listen(pm, type, logEvent); |
| 111 |
goog.events.listen(pm2, type, logEvent); |
| 112 |
}); |
| 113 |
|
| 114 |
</script> |
| 115 |
</body> |
| 116 |
</html> |