From 90383a459189ebe7b5afbec2c6656eb9ea7442b2 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 16 Apr 2013 17:57:58 -0700 Subject: [PATCH] Look through all stylesheets for sprites Needed for concantenated iD.css. --- js/id/svg/surface.js | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/js/id/svg/surface.js b/js/id/svg/surface.js index 7cc16829b..7b48e891a 100644 --- a/js/id/svg/surface.js +++ b/js/id/svg/surface.js @@ -1,10 +1,4 @@ iD.svg.Surface = function(context) { - function findStylesheet(name) { - return _.find(document.styleSheets, function(stylesheet) { - return stylesheet.href && stylesheet.href.indexOf(name) > 0; - }); - } - function autosize(image) { var img = document.createElement('img'); img.src = image.attr('xlink:href'); @@ -16,22 +10,19 @@ iD.svg.Surface = function(context) { }; } - function sprites(stylesheetName, selectorRegexp) { + function sprites(selectorRegexp) { var sprites = []; - var stylesheet = findStylesheet(stylesheetName); - if (!stylesheet) { - return sprites; - } - - _.forEach(stylesheet.cssRules, function(rule) { - var klass = rule.selectorText, - match = klass && klass.match(selectorRegexp); - if (match) { - var id = match[1].replace('feature', 'maki'); - match = rule.style.backgroundPosition.match(/(-?\d+)px (-?\d+)px/); - sprites.push({id: id, x: match[1], y: match[2]}); - } + _.forEach(document.styleSheets, function(stylesheet) { + _.forEach(stylesheet.cssRules, function(rule) { + var klass = rule.selectorText, + match = klass && klass.match(selectorRegexp); + if (match) { + var id = match[1].replace('feature', 'maki'); + match = rule.style.backgroundPosition.match(/(-?\d+)px (-?\d+)px/); + sprites.push({id: id, x: match[1], y: match[2]}); + } + }); }); return sprites; @@ -106,7 +97,7 @@ iD.svg.Surface = function(context) { .call(autosize); defs.selectAll() - .data(sprites("app.css", /^\.(icon-operation-[a-z0-9-]+)$/)) + .data(sprites(/^\.(icon-operation-[a-z0-9-]+)$/)) .enter().append('use') .attr('id', function(d) { return d.id; }) .attr('transform', function(d) { return "translate(" + d.x + "," + d.y + ")"; }) @@ -118,7 +109,7 @@ iD.svg.Surface = function(context) { .call(autosize); defs.selectAll() - .data(sprites("feature-icons.css", /^\.(feature-[a-z0-9-]+-(12|18))$/)) + .data(sprites(/^\.(feature-[a-z0-9-]+-(12|18))$/)) .enter().append('use') .attr('id', function(d) { return d.id; }) .attr('transform', function(d) { return "translate(" + d.x + "," + d.y + ")"; })