1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/content/Site.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 1.4 +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 +'use strict'; 1.9 + 1.10 +/** 1.11 + * dumb model class to provide default values for sites. 1.12 + * link parameter/model object expected to have a .url property, and optionally .title 1.13 + */ 1.14 +function Site(aLink) { 1.15 + if (!aLink.url) { 1.16 + throw Cr.NS_ERROR_INVALID_ARG; 1.17 + } 1.18 + this._link = aLink; 1.19 +} 1.20 + 1.21 +Site.prototype = { 1.22 + icon: '', 1.23 + get url() { 1.24 + return this._link.url; 1.25 + }, 1.26 + get title() { 1.27 + // use url if no title was recorded 1.28 + return this._link.title || this._link.url; 1.29 + }, 1.30 + get label() { 1.31 + // alias for .title 1.32 + return this.title; 1.33 + }, 1.34 + get pinned() { 1.35 + return NewTabUtils.pinnedLinks.isPinned(this); 1.36 + }, 1.37 + get contextActions() { 1.38 + return [ 1.39 + 'delete', // delete means hide here 1.40 + this.pinned ? 'unpin' : 'pin' 1.41 + ]; 1.42 + }, 1.43 + get blocked() { 1.44 + return NewTabUtils.blockedLinks.isBlocked(this); 1.45 + }, 1.46 + get attributeValues() { 1.47 + return { 1.48 + value: this.url, 1.49 + label: this.title, 1.50 + pinned: this.pinned ? true : undefined, 1.51 + selected: this.selected, 1.52 + customColor: this.color, 1.53 + customImage: this.backgroundImage, 1.54 + iconURI: this.icon, 1.55 + "data-contextactions": this.contextActions.join(',') 1.56 + }; 1.57 + }, 1.58 + applyToTileNode: function(aNode) { 1.59 + // apply this site's properties as attributes on a tile element 1.60 + // the decorated node acts as a view-model for the tile binding 1.61 + let attrs = this.attributeValues; 1.62 + for (let key in attrs) { 1.63 + if (undefined === attrs[key]) { 1.64 + aNode.removeAttribute(key); 1.65 + } else { 1.66 + aNode.setAttribute(key, attrs[key]); 1.67 + } 1.68 + } 1.69 + // is binding already applied? 1.70 + if ('refresh' in aNode) { 1.71 + // just update it 1.72 + aNode.refresh(); 1.73 + } else { 1.74 + // these attribute values will get picked up later when the binding is applied 1.75 + } 1.76 + } 1.77 +};