| 20210 | |
| 20211 | /* insert a rule safely and return whether it was actually injected */ |
| 20212 | var safeInsertRule = function safeInsertRule(sheet, cssRule, index) { |
| 20213 | /* abort early if cssRule string is falsy */ |
| 20214 | if (!cssRule) return false; |
| 20215 | |
| 20216 | var maxIndex = sheet.cssRules.length; |
| 20217 | |
| 20218 | try { |
| 20219 | /* use insertRule and cap passed index with maxIndex (no of cssRules) */ |
| 20220 | sheet.insertRule(cssRule, index <= maxIndex ? index : maxIndex); |
| 20221 | } catch (err) { |
| 20222 | /* any error indicates an invalid rule */ |
| 20223 | return false; |
| 20224 | } |
| 20225 | |
| 20226 | return true; |
| 20227 | }; |
| 20228 | |
| 20229 | /* deletes `size` rules starting from `removalIndex` */ |
| 20230 | var deleteRules = function deleteRules(sheet, removalIndex, size) { |