Debian Codegraph @

closure-library/closure/goog/ui/filterobservingmenuitem.js

raw
1 // Copyright 2007 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview Menu item observing the filter text in a
17 * {@link goog.ui.FilteredMenu}. The observer method is called when the filter
18 * text changes and allows the menu item to update its content and state based
19 * on the filter.
20 *
21 * @author [email protected] (Emil A Eklund)
22 */
23
24 goog.provide('goog.ui.FilterObservingMenuItem');
25
26 goog.require('goog.ui.FilterObservingMenuItemRenderer');
27 goog.require('goog.ui.MenuItem');
28 goog.require('goog.ui.registry');
29
30
31
32 /**
33 * Class representing a filter observing menu item.
34 *
35 * @param {goog.ui.ControlContent} content Text caption or DOM structure to
36 * display as the content of the item (use to add icons or styling to
37 * menus).
38 * @param {*=} opt_model Data/model associated with the menu item.
39 * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper used for
40 * document interactions.
41 * @param {goog.ui.MenuItemRenderer=} opt_renderer Optional renderer.
42 * @constructor
43 * @extends {goog.ui.MenuItem}
44 */
45 goog.ui.FilterObservingMenuItem = function(
46 content, opt_model, opt_domHelper, opt_renderer) {
47 goog.ui.MenuItem.call(
48 this, content, opt_model, opt_domHelper,
49 opt_renderer || new goog.ui.FilterObservingMenuItemRenderer());
50 };
51 goog.inherits(goog.ui.FilterObservingMenuItem, goog.ui.MenuItem);
52 goog.tagUnsealableClass(goog.ui.FilterObservingMenuItem);
53
54
55 /**
56 * Function called when the filter text changes.
57 * @type {Function} function(goog.ui.FilterObservingMenuItem, string)
58 * @private
59 */
60 goog.ui.FilterObservingMenuItem.prototype.observer_ = null;
61
62
63 /** @override */
64 goog.ui.FilterObservingMenuItem.prototype.enterDocument = function() {
65 goog.ui.FilterObservingMenuItem.superClass_.enterDocument.call(this);
66 this.callObserver();
67 };
68
69
70 /**
71 * Sets the observer functions.
72 * @param {Function} f function(goog.ui.FilterObservingMenuItem, string).
73 */
74 goog.ui.FilterObservingMenuItem.prototype.setObserver = function(f) {
75 this.observer_ = f;
76 this.callObserver();
77 };
78
79
80 /**
81 * Calls the observer function if one has been specified.
82 * @param {?string=} opt_str Filter string.
83 */
84 goog.ui.FilterObservingMenuItem.prototype.callObserver = function(opt_str) {
85 if (this.observer_) {
86 this.observer_(this, opt_str || '');
87 }
88 };
89
90
91 // Register a decorator factory function for
92 // goog.ui.FilterObservingMenuItemRenderer.
93 goog.ui.registry.setDecoratorByClassName(
94 goog.ui.FilterObservingMenuItemRenderer.CSS_CLASS, function() {
95 // FilterObservingMenuItem defaults to using
96 // FilterObservingMenuItemRenderer.
97 return new goog.ui.FilterObservingMenuItem(null);
98 });