aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/demos/popupmenu.html
blob: ca0064912b7619c2d8a2cda454de24b49fec1ff9 (plain)
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
<!DOCTYPE html>
<html>
<!--
Copyright 2010 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.PopupMenu</title>
  <script src="../base.js"></script>
  <script>
    goog.require('goog.debug.reflect');
    goog.require('goog.positioning.Corner');
    goog.require('goog.object');
    goog.require('goog.ui.MenuItem');
    goog.require('goog.ui.PopupMenu');
  </script>
  <link rel="stylesheet" href="css/demo.css">
  <link rel="stylesheet" href="../css/menu.css">
  <link rel="stylesheet" href="../css/menuitem.css">
  <link rel="stylesheet" href="../css/menuseparator.css">
  <style>
    .event-log {
      border: 1px solid #CCC;
      height: 300px;
      position: absolute;
      right: 20px;
      width: 400px;
    }

    .event-log-content {
      height: 280px;
      overflow: auto;
    }
  </style>
</head>
<body>
  <h1>goog.ui.PopupMenu</h1>
  <div>
    This shows a 2 popup menus, each menu has been attached to two targets.
    <br><br>
  </div>

  <fieldset class="event-log">
    <legend>Event log</legend>
    <div id="event-log" class="event-log-content"></div>
  </fieldset>
  <div id="foo" style="width: 600px; height: 300px; background-color: #EEE">
    <div>
      <span>Hello there <i>I'm italic!</i></span>
    </div>
    <div><button id="bar">Decorated Popup attached to a Button</button></div>
  </div>

  <button id="bar2" style="position:absolute;left: 600px;top:330px;">Button</button>

  <button id="dButton">Decorated Popup</button>
  <div id="dMenu" for="dButton" class="goog-menu" style="display:none">
    <div class="goog-menuitem">A a</div>
    <div class="goog-menuitem">B b</div>
    <div class="goog-menuitem">C c</div>
    <div class="goog-menuitem">D d</div>
    <div class="goog-menuitem">E e</div>
    <div class="goog-menuitem">F f</div>
  </div>

  <script>
    var pm = new goog.ui.PopupMenu();
    pm.addItem(new goog.ui.MenuItem('One'));
    pm.addItem(new goog.ui.MenuItem('Two'));
    pm.addItem(new goog.ui.MenuItem('Three'));
    pm.addItem(new goog.ui.MenuItem('Four'));
    pm.addItem(new goog.ui.MenuItem('Five'));
    pm.addItem(new goog.ui.MenuItem('Six'));
    pm.addItem(new goog.ui.MenuItem('Seven'));
    pm.render(document.body);

    //pm.attach(document.getElementById('foo'), null, null);

    pm.attach(
        document.getElementById('bar2'),
        goog.positioning.Corner.TOP_LEFT,
        goog.positioning.Corner.BOTTOM_LEFT);

    pm.attach(document.getElementById('foo'));


    var pm2 = new goog.ui.PopupMenu();
    pm2.setToggleMode(true);
    pm2.decorate(document.getElementById('dMenu'));

    pm2.attach(
        document.getElementById('bar'),
        goog.positioning.Corner.BOTTOM_LEFT,
        goog.positioning.Corner.TOP_LEFT);

    function logEvent(e) {
      var entry = goog.dom.createDom('div', null,
          'type: ' + e.type +
          ', target: ' + goog.debug.reflect.typeOf(e.target) +
          (e.target.getCaption ? ', caption: ' + e.target.getCaption() : ''));
      var eventLog = goog.dom.getElement('event-log');
      eventLog.appendChild(entry);
      // Scroll to the bottom.
      eventLog.scrollTop = eventLog.scrollHeight;
    }

    goog.object.forEach(goog.ui.Component.EventType, function(type) {
      goog.events.listen(pm, type, logEvent);
      goog.events.listen(pm2, type, logEvent);
    });

  </script>
</body>
</html>