123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <!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.events.InputHandler</title>
- <script src="../base.js"></script>
- <script>
- goog.require('goog.debug.DivConsole');
- goog.require('goog.dom');
- goog.require('goog.events');
- goog.require('goog.events.InputHandler');
- goog.require('goog.log');
- </script>
- <link rel="stylesheet" href="css/demo.css">
- </head>
- <body>
- <h1>goog.events.InputHandler</h1>
- <p><button onclick="addSome('text')">Add Some</button>
- <input type="text" id="text"><span></span>
- <p><button onclick="addSome('password')">Add Some</button>
- <input type="password" id="password"><span></span>
- <p><button onclick="addSome('textarea')">Add Some</button>
- <textarea id="textarea"></textarea><span></span>
- <br><br>
- <fieldset class="goog-debug-panel">
- <legend>Event Log</legend>
- <div id="log" style="height: 400px;"></div>
- </fieldset>
- <script>
- var $ = goog.dom.getElement;
- var logger = goog.log.getLogger('demo');
- var logconsole = new goog.debug.DivConsole(goog.dom.getElement('log'));
- goog.debug.LogManager.getRoot().setLevel(goog.log.Level.FINER);
- logconsole.setCapturing(true);
- var DOM_EVENTS = ['keydown', 'keyup', 'keypress', 'change', 'cut', 'paste',
- 'drop', 'input'];
- var INPUTHANDLER_EVENTS =
- goog.object.getValues(goog.events.InputHandler.EventType);
- function logEvent(src, e) {
- goog.log.info(logger, '[Event from ' + src + ']: ' + e.type);
- }
- function addSome(id) {
- var el = $(id);
- el.value += '.';
- }
- function updateText(e) {
- var inputEl = e.target;
- var outputEl = inputEl.nextSibling;
- while (outputEl.hasChildNodes()) {
- outputEl.removeChild(outputEl.lastChild);
- }
- outputEl.appendChild(document.createTextNode(inputEl.value));
- }
- goog.object.forEach(['text', 'password', 'textarea'], function(id) {
- var el = $(id);
- var ih = new goog.events.InputHandler(el);
- goog.events.listen(ih, goog.events.InputHandler.EventType.INPUT, updateText);
- goog.events.listen(ih, INPUTHANDLER_EVENTS,
- goog.partial(logEvent, 'InputHandler'));
- goog.events.listen(el, DOM_EVENTS,
- goog.partial(logEvent, 'DOM'));
- });
- </script>
- </body>
- </html>
|