-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreview.html
188 lines (182 loc) · 7.41 KB
/
preview.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Icon Cheat Sheet</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<link rel="stylesheet" href="css/index.css" >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/utils.js"></script>
<script src="js/app-icons.js"></script>
<script type="text/javascript">
function log(message) {
if (window.console) {
window.console.log("[{0}] PAGE: {1}".format(new Date(), message));
}
else {
alert( message );
}
}
$(function() {
"use strict";
log("document load");
var template = $("#template").detach(),
symbol = $("#symbol").detach(),
db = sessionStorage;
template.removeAttr("id");
symbol.removeAttr("id");
function displayIcons(outletId, data) {
log("displayIcons called. (total: {0}, outlet: {1})".format(data.length, outletId))
var outlet = $(outletId);
if (!data) {
outlet.append("<h1>No Data Provided</h1>");
}
else {
$(data).each(function(i,e){
var row = template.clone(),
idVal = "#" + $(e).attr("id");
row.find("label").html(idVal);
row.find(".ic")
.attr("xlink:href", idVal)
.attr("href", idVal);
outlet.append(row);
});
}
}
$("#grid-toggle").click(function() {
$(".grid").toggle();
});
$("#app-icons").on("icons-loaded", function() {
displayIcons("#app", $("#app-icons").find("symbol"));
$("#app-icons")
.toggle() // Safari correction for auto-display
.css("display", ""); // Reset display settings
});
log("bind complete");
$(".row").on("click", ".ic-mod", function() {
var ic = $(this).find("use").attr("href");
var sym = $(ic);
log("loading definition for {0}".format(ic));
$("#def").val(
sym.html()
.replace(/\t+</g,"<")
.replace(/\t+"/g,"\"")
.replace(/\t/g," ")
.replace(/^\n/,"")
);
$("#viewBox").val(sym[0].getAttribute("viewBox"));
$("#symbolId").val(ic.replace("#",""));
});
$("#draw").click(function() {
$("#canvas").html($("#def").val())
[0].setAttribute("viewBox", $("#viewBox").val());
});
$("#save").click(function(){
var ic = $("#symbolId").val();
if (ic) {
var sym = $("#"+ ic);
if(sym[0]) {
log("updating defintion for #{0}".format(ic));
sym.html($("#def").val());
sym[0].setAttribute("viewBox",$("#viewBox").val());
}
else {
log("creating definition #{0}".format(ic));
sym = symbol.clone();
sym.attr("id", ic);
sym.html($("#def").val());
sym[0].setAttribute("viewBox", $("#viewBox").val());
$("#local-icons").append(sym);
$("#local").html("");
displayIcons("#local",$("#local-icons").find("symbol"));
}
}
});
$("#def").keydown(function(event) {
if (event.which === 9) {
event.preventDefault();
var startPos = $(this).prop("selectionStart"),
stopPos = $(this).prop("selectionEnd"),
lvc = this.value
;
this.value = lvc.substring(0,startPos);
this.value += " ";
this.value += lvc.substring(stopPos);
$(this).prop("selecttionStart", startPos + 3)
.prop("selectionEnd", startPos + 3);
}
});
});
</script>
<style type="text/css">
#def {font-family: "Courier New"; width: 100%; height: 15em; font-size:10pt;}
.app-icon { border: 1px solid black; fill:blue;}
.boat {
display:inline-block;
position: fixed;
text-align: right;
top: 0;
right: 1em;
width: 60em;
max-width:65%;
z-index: 99;
background:white;
}
.ic-mod {font-size: 12pt;}
.ic-mod:hover {cursor:pointer; border: 1px solid #36c;}
.ide {text-align:left;}
.ide .app-icon {width:15em; height:15em;}
.ide label {margin: 0em 0.5em 0.5em 0em; text-decoration: underline; font-weight: bold;}
</style>
</head>
<body class="container-fluid">
<div class="boat">
<label>Toggle Grid: <input id="grid-toggle" type="checkbox" checked/></label>
<div class="ide">
<div>
<div class="row">
<div class="col-sm-6 form-group">
<label for="symbolId">Icon ID</label>
<input type="text" id="symbolId" name="symbolId" value=""/>
</div>
<div class="col-sm-6 form-group">
<label for="viewBox">viewBox</label>
<input type="text" id="viewBox" name="viewBox" value="0,0,16,16" placeholder="minX,minY,totalX,totalY"/>
</div>
</div>
<label for="def">Definition</label>
<textarea id="def" name="def"></textarea>
<button id="draw">Draw</button>
<button id="save">Save</button>
</div>
<svg class="app-icon" viewBox="0,0,16,16" style="font-size:13pt;">
<svg id="canvas" viewBox="0,0,16,16" >
</svg>
<use class="grid" href="#u-grid" xlink:href="#u-grid" ></use>
</svg>
</div>
</div>
<div id="template" class="ic-mod">
<svg class="app-icon"><use class="ic" xlink:href="" href=""></use></svg>
<label></label>
</div>
<div class="row">
<div class="col-sm-4">
<section>
<h3>Local Icons</h3>
<div id="local"></div>
</section>
<section>
<h3>App Icons</h3>
<div id="app"></div>
</section>
</div>
</div>
<svg id="local-icons" class="render-canvas">
<symbol id="symbol" viewBox="0,0,16,16"></symbol>
</svg>
</body>
</html>