browser/metro/base/content/Site.js

changeset 2
7e26c7da4463
equal deleted inserted replaced
-1:000000000000 0:0ae8a75249d1
1 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 'use strict';
6
7 /**
8 * dumb model class to provide default values for sites.
9 * link parameter/model object expected to have a .url property, and optionally .title
10 */
11 function Site(aLink) {
12 if (!aLink.url) {
13 throw Cr.NS_ERROR_INVALID_ARG;
14 }
15 this._link = aLink;
16 }
17
18 Site.prototype = {
19 icon: '',
20 get url() {
21 return this._link.url;
22 },
23 get title() {
24 // use url if no title was recorded
25 return this._link.title || this._link.url;
26 },
27 get label() {
28 // alias for .title
29 return this.title;
30 },
31 get pinned() {
32 return NewTabUtils.pinnedLinks.isPinned(this);
33 },
34 get contextActions() {
35 return [
36 'delete', // delete means hide here
37 this.pinned ? 'unpin' : 'pin'
38 ];
39 },
40 get blocked() {
41 return NewTabUtils.blockedLinks.isBlocked(this);
42 },
43 get attributeValues() {
44 return {
45 value: this.url,
46 label: this.title,
47 pinned: this.pinned ? true : undefined,
48 selected: this.selected,
49 customColor: this.color,
50 customImage: this.backgroundImage,
51 iconURI: this.icon,
52 "data-contextactions": this.contextActions.join(',')
53 };
54 },
55 applyToTileNode: function(aNode) {
56 // apply this site's properties as attributes on a tile element
57 // the decorated node acts as a view-model for the tile binding
58 let attrs = this.attributeValues;
59 for (let key in attrs) {
60 if (undefined === attrs[key]) {
61 aNode.removeAttribute(key);
62 } else {
63 aNode.setAttribute(key, attrs[key]);
64 }
65 }
66 // is binding already applied?
67 if ('refresh' in aNode) {
68 // just update it
69 aNode.refresh();
70 } else {
71 // these attribute values will get picked up later when the binding is applied
72 }
73 }
74 };

mercurial