Share title subtitle trimming, entity fixup logic for text/thumb views
authorEdward Lee <edilee@mozilla.com>
Sat, 14 Mar 2009 03:14:54 -0500
changeset 139 13aabcce5ba2
parent 138 b4df088cd7d9
child 140 a1d853c814da
push id99
push useredward.lee@engineering.uiuc.edu
push dateSat, 14 Mar 2009 08:14:58 +0000
Share title subtitle trimming, entity fixup logic for text/thumb views
chrome/content/tab.html
chrome/content/text.html
modules/sites.js
--- a/chrome/content/tab.html
+++ b/chrome/content/tab.html
@@ -226,17 +226,17 @@ function setupThumbs() {
       attr("id", row.id).
       append($("<img/>").attr("src", row.iconSrc).attr("class", "tb-favicon")).
       // Text for site name and feeds
       append(text = $("<p/>").
         attr("class", "tb-title").
         // Site name
         append(site = $("<div/>").
           attr("class", "siteName").
-          append(row.title.split(/[-:]/)[0] || row.uri))).
+          text(row.title))).
       // Thumbnail image
       append(thumb = $("<div/>").
         attr("class", "tb-thumb").
         hover(function(event) {
           site.addClass("hovered");
         }, function() {
           site.removeClass("hovered");
         })).
--- a/chrome/content/text.html
+++ b/chrome/content/text.html
@@ -237,24 +237,18 @@ function addSite( item ) {
   let el = $("#templates>.site").clone();
 
   // Store the item as part of the element
   el.data("site", item);
 
   // Editing the site?
   let isEdit = false;
 
-  // Strip off subtitles and trailing splitters
-  let title = item.title.split(/[-–—:<«•»>;,.!\|\/]+( |$)/)[0];
-  // Show the domain incase we don't have a title
-  if (!title)
-    title = item.uri.match(/:\/*(?:www.)?([^\/]+)/)[1];
-
   let name = el.find("name").
-    text(title);
+    text(item.title);
   let icon = el.find(".favicon").
     attr({ src: item.iconSrc });
 
   let siteCheck = el.find(".siteCheck").
     click(function(event) {
       let opacity = .3;
       let text = "remove";
 
--- a/modules/sites.js
+++ b/modules/sites.js
@@ -71,31 +71,38 @@ let Sites = {
         "SELECT f.url, " + ["title", "url", "id"].map(getCol) +
         "FROM moz_places s " +
         "JOIN moz_favicons f ON f.id = s.favicon_id " +
         "WHERE favicon_id NOT NULL AND " + baseWhere + "AND " +
           "_id NOT IN (" + removed + ") " +
         "GROUP BY favicon_id " +
         "ORDER BY MAX(frecency) DESC " +
         "LIMIT " + numSites);
-    let attrs = ["favicon", "title", "uri", "id"];
+    let attrs = ["favicon", "fullTitle", "uri", "id"];
 
     try {
       // Reset the cache
       cache = [];
 
       // Fetch each result and store them in the cache
       while (sql.executeStep()) {
         let row = {};
         for (let [index, attr] in Iterator(attrs))
           row[attr] = sql.getString(index);
   
         row.iconSrc = Cc["@mozilla.org/browser/favicon-service;1"].
           getService(Ci.nsIFaviconService).
           getFaviconLinkForIcon(toURI(row.favicon)).spec;
+
+        // Fix up the title by trimming subtitles, trailing splitters («·»–—•)
+        let title = row.fullTitle.split(/[-.:<!>;,\|\/\u00ab\u00b7\u00bb\u2013\u2014\u2022]+( |$)/)[0];
+        // Show the domain incase we don't have a title
+        if (!title)
+          title = row.uri.match(/:\/*(?:www.)?([^\/]+)/)[1];
+        row.title = title;
   
         cache.push(row);
       }
     }
     catch(ex) {
       Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).
         logStringMessage(ex);
     }