-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
88 lines (83 loc) · 3.34 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>ITCSS Specificity Graph</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div id="wrapper">
<h1>ITCSS: Specificity graph</h1>
<div class="explanation">
<p id="yourValues"></p>
</div>
<div class="chart"></div>
<h2>Paste your CSS:</h2>
<textarea id="paste">a { text-decoration: none; }
p a { color: #00F; }
div p span a { border-bottom: 1px solid #000; }
.text-center { text-align: center; }
.text-center.selected { background-color: #FF0; }
.selected.valid.new ul li a { text-shadow: 0 0 5px #FFF }
.selected.valid.new.logged-in ul li a { border-radius: 4px; }
#downloads .active { font-size: 23px; }</textarea>
<h2 id="data">Your data:</h2>
<ul id="pills">
<li data-pill="array" class="selected">Array</li>
<li data-pill="json">JSON</li>
<li data-pill="csv">CSV</li>
</ul>
<textarea class="data array"></textarea>
<textarea class="data json"></textarea>
<textarea class="data csv"></textarea>
</div>
<script type="text/javascript" src="js/ven.jquery-2.2.3.min.js"></script>
<script type="text/javascript" src="js/ven.svglinegraph.js"></script>
<script type="text/javascript" src="js/ven.selectorstoarray.js"></script>
<script type="text/javascript" src="js/ven.specificity.js"></script>
<script>
function processCSS (css) {
//define vars
var graph = [];
var graphJSON = {};
var graphCSV = [];
//Convert the CSS to JSON
var selectors = window.selectorsToArray(css);
//Loop through each rule
for (var i = 0; i < selectors.length; i++) {
var selector = selectors[i];
var spec = SPECIFICITY.calculate(selector)[0].specificityArray;
var worth = 0;
worth = worth + (spec[0] * 1000); // inline-styles
worth = worth + (spec[1] * 100); // #id
worth = worth + (spec[2] * 10); // .class[attr]:psuedo
worth = worth + (spec[3] * 1); // tag
//Add this selectors total value (111) to the graph array
graph.push(worth);
graphJSON[i] = { [selector]: worth };
graphCSV.push(selector + ', ' + worth);
}
//Update the UI
chart.createChart('.chart', graph);
$('.data.array').html(graph.join(', '));
$('.data.json').html(JSON.stringify(graphJSON, null, 2));
$('.data.csv').html(graphCSV.join('\r\n'));
}
function updateChart () {
var css = $("#paste").val();
processCSS(css);
}
$("#paste").change(updateChart);
$("#paste").keyup(updateChart);
$(".data.json,.data.csv").hide();
$("#pills li").click(function () {
var selection = $(this).data('pill');
$('#pills li').removeClass('selected');
$(this).addClass('selected');
$('.data').hide();
$('.data.' + selection).show();
});
updateChart();
</script>
</body>
</html>