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
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('ntp4', function() {
'use strict';
var TilePage = ntp4.TilePage;
/**
* Creates a new Most Visited object for tiling.
* @constructor
* @extends {HTMLAnchorElement}
*/
function MostVisited() {
var el = cr.doc.createElement('a');
el.__proto__ = MostVisited.prototype;
el.initialize();
return el;
}
MostVisited.prototype = {
__proto__: HTMLAnchorElement.prototype,
initialize: function() {
this.reset();
},
/**
* Clears the DOM hierarchy for this node, setting it back to the default
* for a blank thumbnail.
*/
reset: function() {
this.className = 'most-visited filler';
// TODO(estade): why do we need edit-mode-border?
this.innerHTML =
'<div class="edit-mode-border fills-parent">' +
'<div class="edit-bar-wrapper">' +
'<div class="edit-bar">' +
'<div class="pin"></div>' +
'<div class="spacer"></div>' +
'<div class="remove"></div>' +
'</div>' +
'</div>' +
'<span class="thumbnail-wrapper fills-parent">' +
'<span class="thumbnail fills-parent"></span>' +
'</span>' +
'<span class="title"></span>' +
'</div>';
this.tabIndex = -1;
},
/**
* Update the appearance of this tile according to |data|.
* @param {Object} data A dictionary of relevant data for the page.
*/
updateForData: function(data) {
if (data.filler) {
this.reset();
return;
}
this.tabIndex = 0;
this.classList.remove('filler');
var thumbnailUrl = data.thumbnailUrl || 'chrome://thumb/' + data.url;
this.querySelector('.thumbnail').style.backgroundImage =
url(thumbnailUrl);
},
/**
* Set the size and position of the most visited tile.
* @param {number} size The total size of |this|.
* @param {number} x The x-position.
* @param {number} y The y-position.
* animate.
*/
setBounds: function(size, x, y) {
this.style.width = this.style.height = size + 'px';
this.style.left = x + 'px';
this.style.top = y + 'px';
},
};
var mostVisitedPageGridValues = {
// The fewest tiles we will show in a row.
minColCount: 2,
// The most tiles we will show in a row.
maxColCount: 4,
// TODO(estade): Change these to real values.
// The smallest a tile can be.
minTileWidth: 200,
// The biggest a tile can be.
maxTileWidth: 240,
};
TilePage.initGridValues(mostVisitedPageGridValues);
var THUMBNAIL_COUNT = 8;
/**
* Creates a new MostVisitedPage object.
* @param {string} name The display name for the page.
* @constructor
* @extends {TilePage}
*/
function MostVisitedPage(name) {
var el = new TilePage(name, mostVisitedPageGridValues);
el.__proto__ = MostVisitedPage.prototype;
el.initialize();
return el;
}
MostVisitedPage.prototype = {
__proto__: TilePage.prototype,
initialize: function() {
this.classList.add('most-visited-page');
this.data_ = null;
this.mostVisitedTiles_ = this.getElementsByClassName('most-visited');
},
/**
* Create blank (filler) tiles.
* @private
*/
createTiles_: function() {
for (var i = 0; i < THUMBNAIL_COUNT; i++) {
this.appendTile(new MostVisited());
}
},
/**
* Update the tiles after a change to |data_|.
*/
updateTiles_: function() {
for (var i = 0; i < THUMBNAIL_COUNT; i++) {
var page = this.data_[i];
var tile = this.mostVisitedTiles_[i];
if (i >= this.data_.length)
tile.reset();
else
tile.updateForData(page);
}
},
/**
* Array of most visited data objects.
* @type {Array}
*/
get data() {
return this.data_;
},
set data(data) {
// The first time data is set, create the tiles.
if (!this.data_)
this.createTiles_();
// We append the class name with the "filler" so that we can style fillers
// differently.
this.data_ = data.slice(0, THUMBNAIL_COUNT);
this.updateTiles_();
},
};
return {
MostVisitedPage: MostVisitedPage,
};
});
|