aboutsummaryrefslogtreecommitdiffstats
path: root/test/helpers/privateMocks.js
blob: 6d9fb34fc47478a8093803c5a021765e89f9f3e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function createMockStyleSheet(doc, wind) {
  doc = doc ? doc[0] : document;
  wind = wind || window;

  var node = doc.createElement('style');
  var head = doc.getElementsByTagName('head')[0];
  head.appendChild(node);

  var ss = doc.styleSheets[doc.styleSheets.length - 1];

  return {
    addRule : function(selector, styles) {
      try {
        ss.insertRule(selector + '{ ' + styles + '}', 0);
      }
      catch(e) {
        try {
          ss.addRule(selector, styles);
        }
        catch(e) {}
      }
    },

    destroy : function() {
      head.removeChild(node);
    }
  };
};