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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
|
<!DOCTYPE HTML>
<html id="t" jsvalues="dir:textdirection;">
<head>
<meta charset="utf-8">
<title jscontent="title"></title>
<link rel="icon" href="../../app/theme/history_favicon.png">
<script type="text/javascript">
///////////////////////////////////////////////////////////////////////////////
// Globals:
var RESULTS_PER_PAGE = 150;
var MAX_SEARCH_DEPTH_MONTHS = 18;
// Amount of time between pageviews that we consider a 'break' in browsing,
// measured in milliseconds.
var BROWSING_GAP_TIME = 15 * 60 * 1000;
function $(o) {return document.getElementById(o);}
function createElementWithClassName(type, className) {
var elm = document.createElement(type);
elm.className = className;
return elm;
}
// Escapes a URI as appropriate for CSS.
function encodeURIForCSS(uri) {
// CSS uris need to have '(' and ')' escaped.
return uri.replace(/\(/g, "\\(").replace(/\)/g, "\\)");
}
// TODO(glen): Get rid of these global references, replace with a controller
// or just make the classes own more of the page.
var historyModel;
var historyView;
var localStrings;
var pageState;
var deleteQueue = [];
var deleteInFlight = false;
///////////////////////////////////////////////////////////////////////////////
// localStrings:
/**
* We get strings into the page by using JSTemplate to populate some elements
* with localized content, then reading the content of those elements into
* this global strings object.
* @param {Node} node The DOM node containing all our strings.
*/
function LocalStrings(node) {
this.strings_ = {};
var children = node.childNodes;
for (var i = 0, child; child = children[i]; i++) {
var id = child.id;
if (id) {
this.strings_[id] = child.innerHTML;
}
}
}
/**
* Gets a localized string by its id.
* @param {string} s The id of the string we want
* @return {string} The localized string
*/
LocalStrings.prototype.getString = function(s) {
return (s in this.strings_) ? this.strings_[s] : '';
}
/**
* Returns a formatted localized string (where all %s contents are replaced
* by the second argument).
* @param {string} s The id of the string we want
* @param {string} d The string to include in the formatted string
* @return {string} The formatted string.
*/
LocalStrings.prototype.formatString = function(s, d) {
return (s in this.strings_) ? this.strings_[s].replace(/\%s/, d) : '';
}
///////////////////////////////////////////////////////////////////////////////
// Page:
/**
* Class to hold all the information about an entry in our model.
* @param {Object} result An object containing the page's data.
* @param {boolean} continued Whether this page is on the same day as the
* page before it
*/
function Page(result, continued, model) {
this.model_ = model;
this.title_ = result.title;
this.url_ = result.url;
this.starred_ = result.starred;
this.snippet_ = result.snippet || "";
this.changed = false;
// All the date information is public so that owners can compare properties of
// two items easily.
// We get the time in seconds, but we want it in milliseconds.
this.time = new Date(result.time * 1000);
// See comment in BrowsingHistoryHandler::QueryComplete - we won't always
// get all of these.
this.dateRelativeDay = result.dateRelativeDay || "";
this.dateTimeOfDay = result.dateTimeOfDay || "";
this.dateShort = result.dateShort || "";
// Whether this is the continuation of a previous day.
this.continued = continued;
}
// Page, Public: --------------------------------------------------------------
/**
* @return {DOMObject} Gets the DOM representation of the page
* for use in browse results.
*/
Page.prototype.getBrowseResultDOM = function() {
var node = createElementWithClassName('div', 'entry');
var time = createElementWithClassName('div', 'time');
time.appendChild(document.createTextNode(this.dateTimeOfDay));
node.appendChild(time);
node.appendChild(this.getTitleDOM_());
return node;
}
/**
* @return {DOMObject} Gets the DOM representation of the page for
* use in search results.
*/
Page.prototype.getSearchResultDOM = function() {
var row = createElementWithClassName('tr', 'entry');
var datecell = createElementWithClassName('td', 'time');
datecell.appendChild(document.createTextNode(this.dateShort));
row.appendChild(datecell);
var titleCell = document.createElement('td');
titleCell.valign = 'top';
titleCell.appendChild(this.getTitleDOM_());
var snippet = createElementWithClassName('div', 'snippet');
snippet.appendChild(document.createTextNode(this.snippet_));
this.highlightNodeContent_(snippet);
titleCell.appendChild(snippet);
row.appendChild(titleCell);
return row;
}
// Page, private: -------------------------------------------------------------
/**
* Highlights the content of a node with the current search text.
* @param {DOMObject} node to highlight
*/
Page.prototype.highlightNodeContent_ = function(node) {
node.innerHTML = Page.getHighlightedText_(node.innerHTML,
this.model_.getSearchText());
}
/**
* @return {DOMObject} DOM representation for the title block.
*/
Page.prototype.getTitleDOM_ = function() {
var node = document.createElement('div');
node.className = 'title';
var link = document.createElement('a');
link.href = this.url_;
link.style.backgroundImage =
'url(chrome-ui://favicon/' + encodeURIForCSS(this.url_) + ')';
link.appendChild(document.createTextNode(this.title_));
this.highlightNodeContent_(link);
node.appendChild(link);
if (this.starred_) {
node.appendChild(createElementWithClassName('div', 'starred'));
}
return node;
}
// Page, private, static: -----------------------------------------------------
/**
* Case-insensitively highlights a string.
* @param {string} str The source string
* @param {string} opt_highlight The string to highlight with
* @return {string} The highlighted string
*/
Page.getHighlightedText_ = function(str, opt_highlight ) {
if (!opt_highlight) return str;
var r = new RegExp(Page.pregQuote_(opt_highlight), 'gim');
return str.replace(r, "<b>\$&</b>");
}
/**
* Quote a string so it can be used in a regular expression.
* @param {string} str The source string
* @return {string} The escaped string
*/
Page.pregQuote_ = function(str) {
return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1");
}
///////////////////////////////////////////////////////////////////////////////
// HistoryModel:
/**
* Global container for history data. Future optimizations might include
* allowing the creation of a HistoryModel for each search string, allowing
* quick flips back and forth between results.
*
* The history model is based around pages, and only fetching the data to
* fill the currently requested page. This is somewhat dependent on the view,
* and so future work may wish to change history model to operate on
* timeframe (day or week) based containers.
*/
function HistoryModel() {
this.clearModel_();
this.view_;
}
// HistoryModel, Public: ------------------------------------------------------
/**
* Sets our current view that is called when the history model changes.
* @param {HistoryView} view The view to set our current view to.
*/
HistoryModel.prototype.setView = function(view) {
this.view_ = view;
}
/**
* Start a new search - this will clear out our model.
* @param {String} searchText The text to search for
* @param {Number} opt_page The page to view - this is mostly used when setting
* up an initial view, use #requestPage otherwise.
*/
HistoryModel.prototype.setSearchText = function(searchText, opt_page) {
this.clearModel_();
this.searchText_ = searchText;
this.requestedPage_ = opt_page ? opt_page : 0;
this.getSearchResults_();
}
/**
* Reload our model with the current parameters.
*/
HistoryModel.prototype.reload = function() {
var search = this.searchText_;
var page = this.requestedPage_;
this.clearModel_();
this.searchText_ = search;
this.requestedPage_ = page;
this.getSearchResults_();
}
/**
* @return {String} The current search text.
*/
HistoryModel.prototype.getSearchText = function() {
return this.searchText_;
}
/**
* Tell the model that the view will want to see the current page. When
* the data becomes available, the model will call the view back.
* @page {Number} page The page we want to view.
*/
HistoryModel.prototype.requestPage = function(page) {
this.requestedPage_ = page;
this.changed = true;
this.updateSearch_(false);
}
/**
* Receiver for history query.
* @param {String} term The search term that the results are for.
* @param {Array} results A list of results
*/
HistoryModel.prototype.addResults = function(info, results) {
this.inFlight_ = false;
if (info.term != this.searchText_) {
// If our results aren't for our current search term, they're rubbish.
return;
}
// Currently we assume we're getting things in date order. This needs to
// be updated if that ever changes.
if (results) {
var lastURL, lastDay;
var oldLength = this.pages_.length;
if (oldLength) {
var oldPage = this.pages_[oldLength - 1];
lastURL = oldPage.url;
lastDay = oldPage.dateRelativeDay;
}
for (var i = 0, thisResult; thisResult = results[i]; i++) {
var thisURL = thisResult.url;
var thisDay = thisResult.dateRelativeDay;
// Remove adjacent duplicates.
if (!lastURL || lastURL != thisURL) {
// Figure out if this page is in the same day as the previous page,
// this is used to determine how day headers should be drawn.
this.pages_.push(new Page(thisResult, thisDay == lastDay, this));
lastDay = thisDay;
lastURL = thisURL;
}
}
if (results.length)
this.changed = true;
}
this.updateSearch_(info.finished);
}
/**
* @return {Number} The number of pages in the model.
*/
HistoryModel.prototype.getSize = function() {
return this.pages_.length;
}
/**
* @return {boolean} Whether our history query has covered all of
* the user's history
*/
HistoryModel.prototype.isComplete = function() {
return this.complete_;
}
/**
* Get a list of pages between specified index positions.
* @param {Number} start The start index
* @param {Number} end The end index
* @return {Array} A list of pages
*/
HistoryModel.prototype.getNumberedRange = function(start, end) {
if (start >= this.getSize())
return [];
var end = end > this.getSize() ? this.getSize() : end;
return this.pages_.slice(start, end);
}
// HistoryModel, Private: -----------------------------------------------------
HistoryModel.prototype.clearModel_ = function() {
this.inFlight_ = false; // Whether a query is inflight.
this.searchText_ = '';
this.searchDepth_ = 0;
this.pages_ = []; // Date-sorted list of pages.
// The page that the view wants to see - we only fetch slightly past this
// point. If the view requests a page that we don't have data for, we try
// to fetch it and call back when we're done.
this.requestedPage_ = 0;
this.complete_ = false;
}
/**
* Figure out if we need to do more searches to fill the currently requested
* page. If we think we can fill the page, call the view and let it know
* we're ready to show something.
*/
HistoryModel.prototype.updateSearch_ = function(finished) {
if ((this.searchText_ && this.searchDepth_ >= MAX_SEARCH_DEPTH_MONTHS) ||
finished) {
// We have maxed out. There will be no more data.
this.complete_ = true;
this.view_.onModelReady();
this.changed = false;
} else {
// If we can't fill the requested page, ask for more data unless a request
// is still in-flight.
if (!this.canFillPage_(this.requestedPage_) && !this.inFlight_) {
this.getSearchResults_(this.searchDepth_ + 1);
}
// If we have any data for the requested page, show it.
if (this.changed && this.haveDataForPage_(this.requestedPage_)) {
this.view_.onModelReady();
this.changed = false;
}
}
}
/**
* Get search results for a selected depth. Our history system is optimized
* for queries that don't cross month boundaries, but an entire month's
* worth of data is huge. When we're in browse mode (searchText is empty)
* we request the data a day at a time. When we're searching, a month is
* used.
*
* TODO: Fix this for when the user's clock goes across month boundaries.
* @param {number} opt_day How many days back to do the search.
*/
HistoryModel.prototype.getSearchResults_ = function(depth) {
this.searchDepth_ = depth || 0;
if (this.searchText_ == "") {
chrome.send('getHistory',
[String(this.searchDepth_)]);
} else {
chrome.send('searchHistory',
[this.searchText_, String(this.searchDepth_)]);
}
this.inFlight_ = true;
}
/**
* Check to see if we have data for a given page.
* @param {number} page The page number
* @return {boolean} Whether we have any data for the given page.
*/
HistoryModel.prototype.haveDataForPage_ = function(page) {
return (page * RESULTS_PER_PAGE < this.getSize());
}
/**
* Check to see if we have data to fill a page.
* @param {number} page The page number.
* @return {boolean} Whether we have data to fill the page.
*/
HistoryModel.prototype.canFillPage_ = function(page) {
return ((page + 1) * RESULTS_PER_PAGE <= this.getSize());
}
///////////////////////////////////////////////////////////////////////////////
// HistoryView:
/**
* Functions and state for populating the page with HTML. This should one-day
* contain the view and use event handlers, rather than pushing HTML out and
* getting called externally.
* @param {HistoryModel} model The model backing this view.
*/
function HistoryView(model) {
this.summaryDiv_ = $('results-summary');
this.summaryDiv_.innerHTML = localStrings.getString('loading');
this.resultDiv_ = $('results-display');
this.pageDiv_ = $('results-pagination');
this.model_ = model
this.pageIndex_ = 0;
this.lastDisplayed_ = [];
this.model_.setView(this);
}
// HistoryView, public: -------------------------------------------------------
/**
* Do a search and optionally view a certain page.
* @param {string} term The string to search for.
* @param {number} opt_page The page we wish to view, only use this for
* setting up initial views, as this triggers a search.
*/
HistoryView.prototype.setSearch = function(term, opt_page) {
this.pageIndex_ = parseInt(opt_page || 0, 10);
window.scrollTo(0, 0);
this.model_.setSearchText(term, this.pageIndex_);
pageState.setUIState(term, this.pageIndex_);
}
/**
* Reload the current view.
*/
HistoryView.prototype.reload = function() {
this.model_.reload();
}
/**
* Switch to a specified page.
* @param {string} term The string to search for.
* @param {number} opt_page The page we wish to view.
*/
HistoryView.prototype.setPage = function(page) {
this.pageIndex_ = parseInt(page, 10);
window.scrollTo(0, 0);
this.model_.requestPage(page);
pageState.setUIState(this.model_.getSearchText(), this.pageIndex_);
}
/**
* @return {number} The page number being viewed.
*/
HistoryView.prototype.getPage = function() {
return this.pageIndex_;
}
/**
* Callback for the history model to let it know that it has data ready for us
* to view.
*/
HistoryView.prototype.onModelReady = function() {
this.displayResults_();
}
// HistoryView, private: ------------------------------------------------------
/**
* Update the page with results.
*/
HistoryView.prototype.displayResults_ = function() {
this.resultDiv_.innerHTML = '';
var results = this.model_.getNumberedRange(
this.pageIndex_ * RESULTS_PER_PAGE,
this.pageIndex_ * RESULTS_PER_PAGE + RESULTS_PER_PAGE);
if (this.model_.getSearchText()) {
var resultTable = createElementWithClassName('table', 'results');
resultTable.cellSpacing = 0;
resultTable.cellPadding = 0;
resultTable.border = 0;
for (var i = 0, page; page = results[i]; i++) {
resultTable.appendChild(page.getSearchResultDOM());
}
this.resultDiv_.appendChild(resultTable);
} else {
var lastTime = Math.infinity;
for (var i = 0, page; page = results[i]; i++) {
// Break across day boundaries and insert gaps for browsing pauses.
var thisTime = page.time.getTime();
if ((i == 0 && page.continued) || !page.continued) {
var day = createElementWithClassName('div', 'day');
day.appendChild(document.createTextNode(page.dateRelativeDay));
if (i == 0 && page.continued) {
day.appendChild(document.createTextNode(' ' +
localStrings.getString('cont')));
}
var link = createElementWithClassName('a', 'delete-day');
link.href = '#';
link.time = page.time.toString();
link.onclick = deleteDay;
link.appendChild(
document.createTextNode(localStrings.getString("deleteday")));
day.appendChild(link);
this.resultDiv_.appendChild(day);
} else if (lastTime - thisTime > BROWSING_GAP_TIME) {
this.resultDiv_.appendChild(createElementWithClassName('div', 'gap'));
}
lastTime = thisTime;
// Add entry.
this.resultDiv_.appendChild(page.getBrowseResultDOM());
}
}
this.displaySummaryBar_();
this.displayNavBar_();
}
/**
* Update the summary bar with descriptive text.
*/
HistoryView.prototype.displaySummaryBar_ = function() {
var searchText = this.model_.getSearchText();
if (searchText != '') {
this.summaryDiv_.innerHTML = localStrings.formatString('searchresultsfor',
searchText);
} else {
this.summaryDiv_.innerHTML = localStrings.getString('history');
}
}
/**
* Update the pagination tools.
*/
HistoryView.prototype.displayNavBar_ = function() {
var navOutput = '';
if (this.pageIndex_ > 0) {
navOutput += this.createPageNavHTML_(0, localStrings.getString('newest'));
navOutput += this.createPageNavHTML_(this.pageIndex_ - 1,
localStrings.getString('newer'));
}
if (this.model_.getSize() > (this.pageIndex_ + 1) * RESULTS_PER_PAGE) {
navOutput += this.createPageNavHTML_(this.pageIndex_ + 1,
localStrings.getString('older'));
}
this.pageDiv_.innerHTML = navOutput;
}
/**
* Get the HTML representation of a page navigation link.
* @param {number} page The page index the navigation element should link to
* @param {string} name The text content of the link
* @return {string} HTML representation of the pagination link
*/
HistoryView.prototype.createPageNavHTML_ = function(page, name) {
var hashString = PageState.getHashString(this.model_.getSearchText(), page);
return '<a href="chrome-ui://history/' +
(hashString ? '#' + hashString : '') +
'"' +
'class="page-navigation"' +
'onclick="setPage(' + page + '); return false;"' +
'>' + name + '</a>';
}
///////////////////////////////////////////////////////////////////////////////
// State object:
/**
* An 'AJAX-history' implementation.
* @param {HistoryModel} model The model we're representing
* @param {HistoryView} view The view we're representing
*/
function PageState(model, view) {
// Enforce a singleton.
if (PageState.instance) {
return PageState.instance;
}
this.model = model;
this.view = view;
if (typeof this.checker_ != 'undefined' && this.checker_) {
clearInterval(this.checker_);
}
// TODO(glen): Replace this with a bound method so we don't need
// public model and view.
this.checker_ = setInterval((function(state_obj) {
var hashData = state_obj.getHashData();
if (hashData.q != state_obj.model.getSearchText(term)) {
state_obj.view.setSearch(hashData.q, parseInt(hashData.p, 10));
} else if (parseInt(hashData.p, 10) != state_obj.view.getPage()) {
state_obj.view.setPage(hashData.p);
}
}), 50, this);
}
PageState.instance = null;
/**
* @return {Object} An object containing parameters from our window hash.
*/
PageState.prototype.getHashData = function() {
var result = {
q : '',
p : 0
};
if (!window.location.hash) {
return result;
}
var hashSplit = window.location.hash.substr(1).split("&");
for (var i = 0; i < hashSplit.length; i++) {
var pair = hashSplit[i].split("=");
if (pair.length > 1) {
result[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' '));
}
}
return result;
}
/**
* Set the hash to a specified state, this will create an entry in the
* session history so the back button cycles through hash states, which
* are then picked up by our listener.
* @param {string} term The current search string.
* @param {string} page The page currently being viewed.
*/
PageState.prototype.setUIState = function(term, page) {
// Make sure the form looks pretty.
document.forms[0].term.value = term;
var currentHash = this.getHashData();
if (currentHash.q != term || currentHash.p != page) {
window.location.hash = PageState.getHashString(term, page);
}
}
/**
* Static method to get the hash string for a specified state
* @param {string} term The current search string.
* @param {string} page The page currently being viewed.
* @return {string} The string to be used in a hash.
*/
PageState.getHashString = function(term, page) {
var newHash = [];
if (term) {
newHash.push("q=" + encodeURIComponent(term));
}
if (page) {
newHash.push("p=" + page);
}
return newHash.join("&");
}
///////////////////////////////////////////////////////////////////////////////
// Document Functions:
/**
* Window onload handler, sets up the page.
*/
function load() {
$('term').focus();
localStrings = new LocalStrings($('l10n'));
historyModel = new HistoryModel();
historyView = new HistoryView(historyModel);
pageState = new PageState(historyModel, historyView);
// Create default view.
var hashData = pageState.getHashData();
historyView.setSearch(hashData.q, hashData.p);
}
/**
* TODO(glen): Get rid of this function.
* Set the history view to a specified page.
* @param {String} term The string to search for
*/
function setSearch(term) {
if (historyView) {
historyView.setSearch(term);
}
}
/**
* TODO(glen): Get rid of this function.
* Set the history view to a specified page.
* @param {number} page The page to set the view to.
*/
function setPage(page) {
if (historyView) {
historyView.setPage(page);
}
}
/**
* Delete a day from history.
* TODO: Add UI to indicate that something is happening.
* @param {number} time A time from the day we wish to delete.
*/
function deleteDay() {
var time = this.time;
// Check to see if item is already being deleted.
for (var i = 0, deleting; deleting = deleteQueue[i]; i++) {
if (deleting == time)
return false;
}
if (confirm(localStrings.getString("deletedaywarning"))) {
deleteQueue.push(time);
deleteNextInQueue();
}
return false;
}
/**
* Delete the next item in our deletion queue.
*/
function deleteNextInQueue() {
if (!deleteInFlight && deleteQueue.length) {
deleteInFlight = true;
chrome.send("deleteDay", [deleteQueue[0]]);
}
}
///////////////////////////////////////////////////////////////////////////////
// Chrome callbacks:
/**
* Our history system calls this function with results from searches.
*/
function historyResult(info, results) {
historyModel.addResults(info, results);
}
/**
* Our history system calls this function when a deletion has finished.
*/
function deleteComplete() {
window.console.log("Delete complete");
deleteInFlight = false;
if (deleteQueue.length > 1) {
deleteQueue = deleteQueue.slice(1, deleteQueue.length);
deleteNextInQueue();
}
}
/**
* Our history system calls this function if a delete is not ready (e.g.
* another delete is in-progress).
*/
function deleteFailed() {
window.console.log("Delete failed");
// The deletion failed - try again later.
deleteInFlight = false;
setTimeout(deleteNextInQueue, 500);
}
/**
* We're called when something is deleted (either by us or by someone
* else).
*/
function historyDeleted() {
window.console.log("History deleted");
historyView.reload();
}
</script>
<style type="text/css">
body {
background-color:white;
color:black;
margin:10px;
}
.header {
overflow:auto;
clear:both;
}
.header .logo {
float:left;
}
.header .form {
float:left;
margin-top:22px;
margin-left:12px;
}
html[dir='rtl'] .logo {
float:right;
}
html[dir='rtl'] .form {
float:right;
margin-right:12px;
}
#results-summary {
margin-top:12px;
border-top:1px solid #9cc2ef;
background-color:#ebeff9;
font-weight:bold;
padding:3px;
margin-bottom:-8px;
}
#results-display {
max-width:740px;
}
.day {
margin-top:18px;
padding:0px 3px;
display:inline-block;
}
.delete-day {
padding:0px 9px;
display:inline-block;
}
.gap {
margin-left:18px;
width:15px;
border-right:1px solid #ddd;
height:14px;
}
.entry {
margin-left:18px;
margin-top:6px;
overflow:auto;
}
table.results {
margin-left:4px;
}
.entry .time {
color:#888;
float:left;
min-width:56px;
margin-right:5px;
padding-top:1px;
white-space:nowrap;
}
html[dir='rtl'] .time {
margin-right:0px;
margin-left:5px;
float:right;
}
.entry .title {
max-width:600px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.results .time, .results .title {
margin-top:18px;
}
.starred {
background:url('../../app/theme/star_small.png');
background-repeat:no-repeat;
display:inline-block;
margin-left:12px;
width:11px;
height:11px;
}
.entry .title a {
background-repeat:no-repeat;
background-size:16px;
background-position:0px 1px;
padding:1px 0px 4px 22px;
}
html[dir='rtl'] .entry .title a {
background-position:right;
padding-left:0px;
padding-right:22px;
}
#results-pagination {
padding-top:24px;
margin-left:18px;
}
.page-navigation {
padding:8px;
background-color:#ebeff9;
margin-right:4px;
}
.footer {
height:24px;
}
</style>
</head>
<body onload="load();" jsvalues=".style.fontFamily:fontfamily;.style.fontSize:fontsize">
<div class="header">
<a href="" onclick="setSearch(''); return false;">
<img src="../../app/theme/history_section.png"
width="67" height="67" class="logo" border="0" /></a>
<form method="post" action=""
onsubmit="setSearch(this.term.value); return false;"
class="form">
<input type="text" name="term" id="term" />
<input type="submit" name="submit" jsvalues="value:searchbutton" />
</form>
</div>
<div class="main">
<div id="results-summary"></div>
<div id="results-display"></div>
<div id="results-pagination"></div>
</div>
<div class="footer">
</div>
<div id="l10n" style="display:none;">
<span id="loading" jscontent="loading">Loading...</span>
<span id="newest" jscontent="newest">« Newest</span>
<span id="newer" jscontent="newer">‹ Newer</span>
<span id="older" jscontent="older">Older ›</span>
<span id="searchresultsfor" jscontent="searchresultsfor">Search results for '%s'</span>
<span id="history" jscontent="history">History</span>
<span id="cont" jscontent="cont">(cont.)</span>
<span id="noresults" jscontent="noresults">No results</span>
<span id="noitems" jscontent="noitems">No items</span>
<span id="deleteday" jscontent="deleteday">Delete history for this day</span>
<span id="deletedaywarning" jscontent="deletedaywarning">Are you sure you want to delete this day?</span>
</div>
</body>
</html>
|