From 816ed030d319afc4dccbf00ad557ac574e129836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Sun, 9 Oct 2011 14:06:50 +0200 Subject: [PATCH] sort styles by first rule's index --- lib/carto/renderer.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/carto/renderer.js b/lib/carto/renderer.js index 326899b..2d016ed 100644 --- a/lib/carto/renderer.js +++ b/lib/carto/renderer.js @@ -170,15 +170,20 @@ function inheritRules(definitions, env) { } function sortStyles(styles, env) { + styles.forEach(function(style) { + style.index = Infinity; + style.forEach(function(block) { + block.rules.forEach(function(rule) { + if (rule.index < style.index) { + style.index = rule.index; + } + }); + }); + }); + var result = styles.slice(); result.sort(function(a, b) { - var as = a[a.length - 1].specificity; - var bs = b[b.length - 1].specificity; - - if (as[0] != bs[0]) return bs[0] - as[0]; - if (as[1] != bs[1]) return bs[1] - as[1]; - if (as[2] != bs[2]) return bs[2] - as[2]; - return bs[3] - as[3]; + return b.index - a.index; }); return result; }