OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 cr.define('options', function() { | |
6 | |
7 var OptionsPage = options.OptionsPage; | |
8 | |
9 ///////////////////////////////////////////////////////////////////////////// | |
10 // CookiesView class: | |
11 | |
12 /** | |
13 * Encapsulated handling of the cookies and other site data page. | |
14 * @constructor | |
15 */ | |
16 function CookiesView(model) { | |
17 OptionsPage.call(this, 'cookies', | |
18 templateData.cookiesViewPageTabTitle, | |
19 'cookiesViewPage'); | |
20 } | |
21 | |
22 cr.addSingletonGetter(CookiesView); | |
23 | |
24 CookiesView.prototype = { | |
25 __proto__: OptionsPage.prototype, | |
26 | |
27 /** | |
28 * The timer id of the timer set on search query change events. | |
29 * @type {number} | |
30 * @private | |
31 */ | |
32 queryDelayTimerId_: 0, | |
33 | |
34 /** | |
35 * The most recent search query, or null if the query is empty. | |
36 * @type {?string} | |
37 * @private | |
38 */ | |
39 lastQuery_ : null, | |
40 | |
41 initializePage: function() { | |
42 OptionsPage.prototype.initializePage.call(this); | |
43 | |
44 $('cookies-search-box').addEventListener('search', | |
45 this.handleSearchQueryChange_.bind(this)); | |
46 | |
47 $('remove-all-cookies-button').onclick = function(e) { | |
48 chrome.send('removeAllCookies', []); | |
49 }; | |
50 | |
51 var cookiesList = $('cookies-list'); | |
52 options.CookiesList.decorate(cookiesList); | |
53 window.addEventListener('resize', this.handleResize_.bind(this)); | |
54 | |
55 this.addEventListener('visibleChange', this.handleVisibleChange_); | |
56 }, | |
57 | |
58 /** | |
59 * Search cookie using text in |cookies-search-box|. | |
60 */ | |
61 searchCookie: function() { | |
62 this.queryDelayTimerId_ = 0; | |
63 var filter = $('cookies-search-box').value; | |
64 if (this.lastQuery_ != filter) { | |
65 this.lastQuery_ = filter; | |
66 chrome.send('updateCookieSearchResults', [filter]); | |
67 } | |
68 }, | |
69 | |
70 /** | |
71 * Handles search query changes. | |
72 * @param {!Event} e The event object. | |
73 * @private | |
74 */ | |
75 handleSearchQueryChange_: function(e) { | |
76 if (this.queryDelayTimerId_) | |
77 window.clearTimeout(this.queryDelayTimerId_); | |
78 | |
79 this.queryDelayTimerId_ = window.setTimeout( | |
80 this.searchCookie.bind(this), 500); | |
81 }, | |
82 | |
83 initialized_: false, | |
84 | |
85 /** | |
86 * Handler for OptionsPage's visible property change event. | |
87 * @param {Event} e Property change event. | |
88 * @private | |
89 */ | |
90 handleVisibleChange_: function(e) { | |
91 if (!this.visible) | |
92 return; | |
93 | |
94 // Resize the cookies list whenever the options page becomes visible. | |
95 this.handleResize_(null); | |
96 if (!this.initialized_) { | |
97 this.initialized_ = true; | |
98 this.searchCookie(); | |
99 } else { | |
100 $('cookies-list').redraw(); | |
101 } | |
102 | |
103 $('cookies-search-box').focus(); | |
104 }, | |
105 | |
106 /** | |
107 * Handler for when the window changes size. Resizes the cookies list to | |
108 * match the window height. | |
109 * @param {?Event} e Window resize event, or null if called directly. | |
110 * @private | |
111 */ | |
112 handleResize_: function(e) { | |
113 if (!this.visible) | |
114 return; | |
115 var cookiesList = $('cookies-list'); | |
116 // 25 pixels from the window bottom seems like a visually pleasing amount. | |
117 var height = window.innerHeight - cookiesList.offsetTop - 25; | |
118 cookiesList.style.height = height + 'px'; | |
119 }, | |
120 }; | |
121 | |
122 // CookiesViewHandler callbacks. | |
123 CookiesView.onTreeItemAdded = function(args) { | |
124 $('cookies-list').addByParentId(args[0], args[1], args[2]); | |
125 }; | |
126 | |
127 CookiesView.onTreeItemRemoved = function(args) { | |
128 $('cookies-list').removeByParentId(args[0], args[1], args[2]); | |
129 }; | |
130 | |
131 CookiesView.loadChildren = function(args) { | |
132 $('cookies-list').loadChildren(args[0], args[1]); | |
133 }; | |
134 | |
135 // Export | |
136 return { | |
137 CookiesView: CookiesView | |
138 }; | |
139 | |
140 }); | |
OLD | NEW |