Sha256: 5ddda6459e634887e64fa2aea76a9bb6f1936ba0532492fb9a656025f897bf6c

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

(function () {
	if (!self.Prism || !self.document || !document.querySelector) {
		return;
	}

	self.Prism.fileHighlight = function() {

		var Extensions = {
			'js': 'javascript',
			'html': 'markup',
			'svg': 'markup',
			'xml': 'markup',
			'py': 'python',
			'rb': 'ruby',
			'ps1': 'powershell',
			'psm1': 'powershell'
		};

		Array.prototype.slice.call(document.querySelectorAll('pre[data-src]')).forEach(function(pre) {
			var src = pre.getAttribute('data-src');
			var extension = (src.match(/\.(\w+)$/) || [,''])[1];
			var language = Extensions[extension] || extension;

			var code = document.createElement('code');
			code.className = 'language-' + language;

			pre.textContent = '';

			code.textContent = 'Loading…';

			pre.appendChild(code);

			var xhr = new XMLHttpRequest();

			xhr.open('GET', src, true);

			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4) {

					if (xhr.status < 400 && xhr.responseText) {
						code.textContent = xhr.responseText;

						Prism.highlightElement(code);
					}
					else if (xhr.status >= 400) {
						code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText;
					}
					else {
						code.textContent = '✖ Error: File does not exist or is empty';
					}
				}
			};

			xhr.send(null);
		});

	};

	self.Prism.fileHighlight();

})();

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
polymer-elements-rails-1.0.1 app/assets/components/prism/plugins/file-highlight/prism-file-highlight.js
polymer-elements-rails-1.0.0 app/assets/components/prism/plugins/file-highlight/prism-file-highlight.js
polymer-elements-rails-1.0.0.pre.rc.1 app/assets/components/prism/plugins/file-highlight/prism-file-highlight.js
polymer-iron-rails-1.0.0.pre.rc.3 app/assets/components/prism/plugins/file-highlight/prism-file-highlight.js
polymer-iron-rails-1.0.0.pre.rc.2 app/assets/components/prism/plugins/file-highlight/prism-file-highlight.js
polymer-iron-rails-1.0.0.pre.rc.1 app/assets/components/prism/plugins/file-highlight/prism-file-highlight.js