browser/metro/base/content/Site.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial