From a40bb2fa0b401fac8d41b6b51f55bd488ac613d6 Mon Sep 17 00:00:00 2001 From: Satvik Kumar Date: Mon, 24 Mar 2014 17:32:20 +1100 Subject: [PATCH] Removed duplicated stylesheet error handling --- webodf/lib/odf/ListStylesToCss.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/webodf/lib/odf/ListStylesToCss.js b/webodf/lib/odf/ListStylesToCss.js index 2034acb8..06791984 100644 --- a/webodf/lib/odf/ListStylesToCss.js +++ b/webodf/lib/odf/ListStylesToCss.js @@ -53,6 +53,19 @@ */ odf.ListStyleToCss = function ListStyleToCss() { + /** + * Appends the rule into the stylesheets and logs any errors that occur + * @param {!CSSStyleSheet} styleSheet + * @param {!string} rule + */ + function appendRule(styleSheet, rule) { + try { + styleSheet.insertRule(rule, styleSheet.cssRules.length); + } catch (/**@type{!DOMException}*/e) { + runtime.log("cannot load rule: " + rule); + } + } + /** * Gets the CSS content for a numbered list * @param {!Element} node @@ -148,11 +161,7 @@ listItemRule = itemSelector + "{"; listItemRule += 'margin-left:' + listIndent + ';'; listItemRule += "}"; - try { - styleSheet.insertRule(listItemRule, styleSheet.cssRules.length); - } catch (/**@type{!DOMException}*/e1) { - runtime.log("cannot load rule: " + listItemRule); - } + appendRule(styleSheet, listItemRule); } // insert a block before every immediate child of the list-item, except for lists selector += ' > text|list-item > *:not(text|list):first-child:before'; @@ -163,11 +172,7 @@ rule += 'width:' + bulletWidth + ';'; rule += 'display:inline-block}'; - try { - styleSheet.insertRule(rule, styleSheet.cssRules.length); - } catch (/**@type{!DOMException}*/e2) { - runtime.log("cannot load rule: " + rule); - } + appendRule(styleSheet, rule); } /**