Blame view

bower_components/prism/plugins/previewer-time/prism-previewer-time.js 2.32 KB
f748e9cf   Luigi Serra   new controllet an...
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  (function() {
  
  	if (
  		typeof self !== 'undefined' && !self.Prism ||
  		typeof global !== 'undefined' && !global.Prism
  	) {
  		return;
  	}
  
  	var languages = {
  		'css': true,
  		'less': true,
  		'markup': {
  			lang: 'markup',
  			before: 'punctuation',
  			inside: 'inside',
  			root: Prism.languages.markup && Prism.languages.markup['tag'].inside['attr-value']
  		},
  		'sass': [
  			{
  				lang: 'sass',
  				inside: 'inside',
  				root: Prism.languages.sass && Prism.languages.sass['property-line']
  			},
  			{
  				lang: 'sass',
  				before: 'operator',
  				inside: 'inside',
  				root: Prism.languages.sass && Prism.languages.sass['variable-line']
  			}
  		],
  		'scss': true,
  		'stylus': [
  			{
  				lang: 'stylus',
  				before: 'hexcode',
  				inside: 'rest',
  				root: Prism.languages.stylus && Prism.languages.stylus['property-declaration'].inside
  			},
  			{
  				lang: 'stylus',
  				before: 'hexcode',
  				inside: 'rest',
  				root: Prism.languages.stylus && Prism.languages.stylus['variable-declaration'].inside
  			}
  		]
  	};
  
  	Prism.hooks.add('before-highlight', function (env) {
  		if (env.language && languages[env.language] && !languages[env.language].initialized) {
  			var lang = languages[env.language];
  			if (Prism.util.type(lang) !== 'Array') {
  				lang = [lang];
  			}
  			lang.forEach(function(lang) {
  				var before, inside, root, skip;
  				if (lang === true) {
  					before = 'important';
  					inside = env.language;
  					lang = env.language;
  				} else {
  					before = lang.before || 'important';
  					inside = lang.inside || lang.lang;
  					root = lang.root || Prism.languages;
  					skip = lang.skip;
  					lang = env.language;
  				}
  
  				if (!skip && Prism.languages[lang]) {
  					Prism.languages.insertBefore(inside, before, {
  						'time': /(?:\b|\B-|(?=\B\.))\d*\.?\d+m?s\b/i
  					}, root);
  					env.grammar = Prism.languages[lang];
  
  					languages[env.language] = {initialized: true};
  				}
  			});
  		}
  	});
  
  	if (Prism.plugins.Previewer) {
  		new Prism.plugins.Previewer('time', function(value) {
  			var num = parseFloat(value);
  			var unit = value.match(/[a-z]+$/i);
  			if (!num || !unit) {
  				return false;
  			}
  			unit = unit[0];
  			this.querySelector('circle').style.animationDuration = 2 * num + unit;
  			return true;
  		}, '*', function () {
  			this._elt.innerHTML = '<svg viewBox="0 0 64 64">' +
  				'<circle r="16" cy="32" cx="32"></circle>' +
  			'</svg>';
  		});
  	}
  
  }());