Blame view

bower_components/prism/plugins/ie8/prism-ie8.js 946 Bytes
73bcce88   luigser   COMPONENTS
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  (function(){
  
  if (!window.Prism) {
  	return;
  }
  
  var dummy = document.createElement('header');
  
  if (!String.prototype.trim) {
  	String.prototype.trim = function () {
  		return this.replace(/^\s+/g, '').replace(/\s+$/g, '');
  	};
  }
  
  // textContent polyfill
  if (!('textContent' in dummy) && ('innerText' in dummy) && Object.defineProperty) {
  	Object.defineProperty(Element.prototype, 'textContent', {
  		get: function() {
  			return this.innerText;
  		},
  		set: function(text) {
  			this.innerText = text;
  		}
  	});
  }
  
  // IE8 doesn't have DOMContentLoaded
  if (!document.addEventListener && 'textContent' in dummy) {
  	setTimeout(Prism.highlightAll, 10);
  }
  
  // Test if innerHTML line break bug is present
  dummy.innerHTML = '\r\n';
  
  if (dummy.textContent.indexOf('\n') === -1) {
  	// IE8 innerHTML bug: Discards line breaks
  	Prism.hooks.add('after-highlight', function(env) {
  		env.element.innerHTML = env.highlightedCode.replace(/\r?\n/g, '<br>');
  	});
  }
  
  })();