-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlayout-maker.html
369 lines (301 loc) · 12.2 KB
/
layout-maker.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<!doctype html>
<!--[if IEMobile]> <html class="no-js ie-mobile" lang="en"> <![endif]-->
<!--[if (lt IE 7)&!(IEMobile) ]> <html class="no-js ie6" lang="en"> <![endif]-->
<!--[if (IE 7)&!(IEMobile) ]> <html class="no-js ie7" lang="en"> <![endif]-->
<!--[if (IE 8)&!(IEMobile) ]> <html class="no-js ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<title>CHASSIS 2.0</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<!-- uncomment and remove above to lockdown a specific version of
IE rendering. Not recommended: may be required to testing deltas.
<meta http-equiv="X-UA-Compatible" content="IE=8" />
-->
<meta name="description" content="CSS HTML And Structured Scripts In Standards" />
<meta name="author" content="Rozario Chivers" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="search" type="application/opensearchdescription+xml" title="Site Search" href="http://www.site.com/osd.xml" />
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link rel="apple-touch-startup-image" href="img/startup.png" />
<link rel="apple-touch-startup-image" href="img/Default-Portrait.png" />
<!--iOS web app, deletable if not needed -->
<!--
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
-->
<!-- Mobile IE allows us to activate ClearType technology for smoothing fonts for easy reading -->
<meta http-equiv="cleartype" content="on">
<!-- Uncomment if you are specifically targeting less enabled mobile browsers
<link rel="stylesheet" media="handheld" href="css/handheld.css?v=1"> -->
<link rel="stylesheet" href="css/site.css" />
<link rel="copyright" href="#copyright" />
<!-- uncomment if HTML5 tags are required
<script src="js/lib/modernizr-min.js"></script> -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script>
<script>window.jQuery || document.write('<script src="js/lib/jquery-min.js">\x3C/script>')</script>
<!-- development QA only (remove), not for production use -->
<link rel="stylesheet" href="dev/css/debug.css" />
<!-- Less CSS: for development only, should not be used on production -->
<!-- -->
<link rel="stylesheet/less" type="text/css" href="dev/less/templates/layouts/layouts.less" />
<link rel="stylesheet/less" type="text/css" href="dev/less/templates/components/components.less" />
<link rel="stylesheet/less" type="text/css" href="dev/less/templates/pages/pages.less" />
<script src="dev/less/less.js"></script>
<script> less.env = "development"; less.watch(); </script>
<!-- Compiled Less CSS
<link rel="stylesheet" type="text/css" href="css/templates/layouts/layouts.css" />
<link rel="stylesheet" type="text/css" href="css/templates/components/components.css" />
<link rel="stylesheet" type="text/css" href="css/templates/pages/pages.css" />
-->
</head>
<body class="cms-bg-1 debug-grid">
<!-- begin Component: Accessibility links -->
<div id="skiplinks" data-component-name="skip-links">
<ul>
<li><a href="#header">Jump to main navigation</a></li>
<li><a href="#main">Jump to main content</a></li>
<li><a href="#footer">Jump to footer</a></li>
</ul>
</div>
<!-- end Component accessibility links -->
<div id="wrapper" class="layout-store"><!-- wrapper used to provide extra stylistic hooks e.g. LHS and RHS shadows -->
<div id="container" class="en-gb chassis home cat-1 cat-1-2 cms-seasonal"><!-- to allow for customised seasonal layouts -->
<div id="main"><!-- components: source order important for layout, order can be changed to cater for new layout requirements -->
<!-- layout -->
<style type="text/css">
body {
margin: 0;
}
#header {
border-bottom: 2px solid #333;
}
.message {
text-align: center;
}
#footer {
display: none;
}
#container .area {
outline: 1px solid #999;
margin: 0;
position: absolute;
}
#container .draggable {
z-index: 5;
top: 0;
left: 0;
width: 180px;
height: 108px;
padding: 0;
margin: 0;
opacity: 0.7;
border: 0!important;
}
.draggable h2 {
padding: 5px;
font-size: 15px;
font-family: arial, helvetica;
color: #999;
text-align: center;
}
.ui-widget-header p, .ui-widget-content p {
margin: 0;
}
.add,
.remove,
.save {
position: absolute;
top: 10px;
left: 85%;
background-color: #666;
color: #fff;
font-size: 15px;
}
.remove {
top: 50px;
}
.save {
top: 90px;
}
#linkto-generated {
position: absolute;
top: 140px;
left: 85%;
text-decoration: underline;
color: #333;
font-size: 14px;
}
.arrow-down {
float: left;
position: relative;
top: 3px;
width: 0;
height: 0;
margin-right: 5px;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid #333;
}
#container {
min-height: 600px;
}
</style>
<link type="text/css" href="dev/layout-creator/js/jquery.ui.all.css" rel="stylesheet" />
<script type="text/javascript" src="dev/layout-creator/js/base64encoder.js"></script>
<script type="text/javascript" src="dev/layout-creator/js/jquery.ui.core.js"></script>
<script type="text/javascript" src="dev/layout-creator/js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="dev/layout-creator/js/jquery.ui.mouse.js"></script>
<script type="text/javascript" src="dev/layout-creator/js/jquery.ui.draggable.js"></script>
<script type="text/javascript" src="dev/layout-creator/js/jquery.ui.resizable.js"></script>
<script>
var layoutMaker = (function($) {
var generatedLess = "",
GRID_BASELINE,
GRID_COLUMN,
GRID_GUTTER,
init = function() {
createXhr();
}();
function createXhr() {
// read baseline grid constants from Less
$.ajax({
url: "dev/less/baseplate.grid.constants.less",
beforeSend: function() {
// e.g. loading indicators here
},
cache: false,
dataType : "html",
success: function(data) {
var tempData = [];
tempData = data.split("@"),
GRID_BASELINE = parseInt(tempData[1].split(";")[0].split(":")[1].replace("px","")),
GRID_COLUMN = parseInt(tempData[2].split(";")[0].split(":")[1].replace("px","")),
GRID_GUTTER = parseInt(tempData[3].split(";")[0].split(":")[1].replace("px",""));
// loaded data now setup editor
createButtons();
addEvents();
},
complete: function(){
},
error: function() {
},
dataFilter : function (data, type) {
// Parsing JSON strings can throw a SyntaxError exception,
// so we wrap the call in a try catch block
try {
// check validity
}
catch (e) {
// Invalid data;
}
return data;
}
}); // end $.ajax
}
function createButtons() {
$('<button class="add">Add</button>').appendTo("body");
$('<button class="remove">Remove</button>').appendTo("body");
$('<button class="save">Snap to and Save to link</button>').appendTo("body");
$('<a href="#" id="linkto-generated"><span class="arrow-down"></span>Save Generated Layout</a>').appendTo("body");
$('<div class="message">You can only generate layouts in browsers that support <a href="http://en.wikipedia.org/wiki/Data_URI_scheme">Data URIs</a></div>').appendTo("body");
}
function createArea() {
layoutMaker.areaCount++;
$("#container").append('<div id="area-'+layoutMaker.areaCount+'" class="area draggable resizable ui-widget-content"><h2>Area '+layoutMaker.areaCount+'</h2></div>');
$('#area-'+layoutMaker.areaCount)
.draggable({ grid: [1,(GRID_BASELINE/2)] })
.resizable({
containment: '#container',
grid: [1,(GRID_BASELINE/2)],
resize : function() {
}
})
.position().top = 0;
} // creaetArea()
function removeArea() {
$('#area-'+layoutMaker.areaCount).detach();
layoutMaker.areaCount -=1;
}
function saveAreas() {
var gridLeft = 0;
var adjustedLeft = 0;
var gridWidth = 0;
var adjustedWidth = 0;
var today = new Date();
generatedLess = "/* --- Begin Generated Less Layout "+
"on Date: " + today.getDate() + "/" +
(today.getMonth() +1) + "/" +
today.getFullYear() + " | Time:" + " " +
today.getHours() + ":" +
today.getMinutes() + ":" +
today.getSeconds() +
" -- */\n";
$(".area").each(function(i){
var id = $(this).attr("id");
var top = $(this).position().top;
var left = $(this).position().left;
var height = $(this).height();
var width = $(this).width();
// adjustments
gridLeft = left / (GRID_COLUMN + GRID_GUTTER);
adjustedLeft = (Math.round(gridLeft) * (GRID_COLUMN + GRID_GUTTER)) + GRID_GUTTER;
gridWidth = width / (GRID_COLUMN + GRID_GUTTER);
adjustedWidth = (Math.round(gridWidth) * (GRID_COLUMN + GRID_GUTTER)) - GRID_GUTTER;
//console.log(adjustedWidth);
$(this).width(adjustedWidth);
$(this).css({
left: adjustedLeft
});
// log data to console
generatedLess += "."+ id + " {\n ";
generatedLess += " .top("+ layoutMaker.convertToBaseline(top) + ");\n ";
generatedLess += " .left("+ layoutMaker.convertToColumn(adjustedLeft) + ");\n ";
generatedLess += " .width("+ layoutMaker.convertToColumn(adjustedWidth) + ");\n ";
generatedLess += " .height("+ layoutMaker.convertToBaseline(height) + ");\n ";
generatedLess += "}\n";
});
generatedLess += "/* --- End Layout CSS (copy above) -- */\n";
generatedLess += "\n ";
encodeLink(generatedLess);
} // saveAreas()
function encodeLink(generatedLess) {
var base64encodeDataUri = "data:text/plain;base64," + Base64.encode(generatedLess);
$("#linkto-generated").hide()
.fadeIn("slow")
.attr("href", base64encodeDataUri);
}
function addEvents() {
$(function() {
$(".add").bind("click", function(){
createArea();
});
$(".remove").bind("click", function(){
removeArea();
});
$(".save").bind("click", function(){
saveAreas();
});
});
};
return {
areaCount: 0,
convertToBaseline : function(yValue) {
return Math.round(yValue / GRID_BASELINE);
},
convertToColumn : function(xValue) {
return Math.round(xValue / (GRID_COLUMN + GRID_GUTTER));
}
}
}(jQuery));
</script>
</div><!-- id="main" -->
<!--
<div id="header" role="banner">
<h1><acronym title="CSS HTML And Structured Scripts in Standards">CHASSIS</acronym></h1>
</div> --> <!-- id="header" -->
</div><!-- id="container" -->
</div><!-- id="wrapper" -->
</body>
</html>