]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/styles.jsm
Imported Upstream version 1.1+hg7904
[dactyl.git] / common / modules / styles.jsm
index 6584a7ef704482fa9c6efd0c1b5697d8569ea023..ee635c20bbd3476ff11f97b44449e3d2ec70eabd 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (c) 2008-2013 Kris Maglione <maglione.k at Gmail>
+// Copyright (c) 2008-2014 Kris Maglione <maglione.k at Gmail>
 //
 // This work is licensed for reuse under an MIT license. Details are
 // given in the LICENSE.txt file included with this file.
@@ -111,8 +111,10 @@ var Hive = Class("Hive", {
     },
 
     cleanup: function cleanup() {
-        for (let sheet in values(this.sheets))
-            sheet.enabled = false;
+        for (let sheet of this.sheets)
+            util.trapErrors(() => {
+                sheet.enabled = false;
+            });
     },
 
     __iterator__: function () Iterator(this.sheets),
@@ -137,8 +139,12 @@ var Hive = Class("Hive", {
      */
     add: function add(name, filter, css, agent, lazy) {
 
-        if (!isArray(filter))
+        if (isArray(filter))
+            // Need an array from the same compartment.
+            filter = Array.slice(filter);
+        else
             filter = filter.split(",");
+
         if (name && name in this.names) {
             var sheet = this.names[name];
             sheet.agent = agent;
@@ -212,7 +218,7 @@ var Hive = Class("Hive", {
             name = null;
         }
 
-        if (filter && filter.indexOf(",") > -1)
+        if (filter && filter.contains(","))
             return filter.split(",").reduce(
                 (n, f) => n + this.removeSheet(name, f, index), 0);
 
@@ -261,7 +267,7 @@ var Styles = Module("Styles", {
         update(services["dactyl:"].providers, {
             "style": function styleProvider(uri, path) {
                 let id = parseInt(path);
-                if (Set.has(styles.allSheets, id))
+                if (hasOwnProperty(styles.allSheets, id))
                     return ["text/css", styles.allSheets[id].fullCSS];
                 return null;
             }
@@ -269,7 +275,7 @@ var Styles = Module("Styles", {
     },
 
     cleanup: function cleanup() {
-        for each (let hive in this.hives)
+        for (let hive of this.hives || [])
             util.trapErrors("cleanup", hive);
         this.hives = [];
         this.user = this.addHive("user", this, true);
@@ -277,8 +283,7 @@ var Styles = Module("Styles", {
     },
 
     addHive: function addHive(name, ref, persist) {
-        let hive = array.nth(this.hives, h => h.name === name,
-                             0);
+        let hive = this.hives.find(h => h.name === name);
         if (!hive) {
             hive = Hive(name, persist);
             this.hives.push(hive);
@@ -369,7 +374,7 @@ var Styles = Module("Styles", {
 }, {
     append: function (dest, src, sort) {
         let props = {};
-        for each (let str in [dest, src])
+        for (let str of [dest, src])
             for (let prop in Styles.propertyIter(str))
                 props[prop.name] = prop.value;
 
@@ -382,7 +387,7 @@ var Styles = Module("Styles", {
         return val;
     },
 
-    completeSite: function (context, content, group = styles.user) {
+    completeSite: function (context, content, group=styles.user) {
         context.anchored = false;
         try {
             context.fork("current", 0, this, function (context) {
@@ -553,7 +558,7 @@ var Styles = Module("Styles", {
             let uris = util.visibleURIs(window.content);
             context.compare = modules.CompletionContext.Sort.number;
             context.generate = () => args["-group"].sheets;
-            context.keys.active = sheet => uris.some(sheet.closure.match);
+            context.keys.active = sheet => uris.some(sheet.bound.match);
             context.keys.description = sheet => [sheet.formatSites(uris), ": ", sheet.css.replace("\n", "\\n")];
             if (filter)
                 context.filters.push(({ item }) => filter(item));