forked from johnpolacek/Responsivator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
263 lines (227 loc) · 11.7 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Responsivator</title>
<link rel="stylesheet" href="css/style.css">
<!-- Facebook sharing. http://developers.facebook.com/docs/opengraph/ -->
<meta property="og:site_name" content="Responsivator" />
<meta property="og:title" content="Responsivator" />
<meta property="og:description" content="See and share how web pages look at different screen sizes" />
<meta property="og:image" content="http://dfcb.github.com/Responsivator/img/responsivator-icon.png" />
<!-- Thumbnail for sharing. Use absolute URL. Minimum 50x50 -->
<link rel="shortcut icon" href="img/favicon.ico">
<link rel="apple-touch-icon" href="img/responsivator-icon.png">
</head>
<body>
<header>
<h1>Responsivator</h1>
<h2>View & share how sites look at different screen sizes</h2>
<span class="author"><small>an <a href="https://github.com/dfcb/Responsivator" target="_blank">open source project</a> by <a href="http://twitter.com/johnpolacek" target="_blank">@johnpolacek</a> of the <a href="http://dfcb.github.com" target="_blank">dev group</a> at draftfcb chicago</small></span>
</header>
<div class="controls">
<fieldset>
<label>Enter website url:</label>
<input type="text" id="input-site">
<a href="#" id="view-btn" class="btn">Responsivate!</a>
<a href="./" class="btn">view random</a>
<a href="#" class="btn" id="btn-customize">customize</a>
</fieldset>
<fieldset class="share-field">
<label>Share link:</label>
<input type="text" id="share-field-input" value="" readonly="readonly">
<label><input type="checkbox" id="hide-header"> hide header in link</label>
<a href="#" class="social-btn" id="facebook-btn" target="_blank"><img src="img/facebook.png" /></a>
<a href="#" class="social-btn" id="twitter-btn" target="_blank"><img src="img/twitter.png" /></a>
</fieldset>
<form id="form-customize" class="collapsed"></form>
</div>
<!-- WRAPPER (iFrames) -->
<label id="curr-site"></label>
<div id="frames-wrapper"></div>
<script id="form-customize-tpl" type="text/x-jsrender">
<div id="form-customize-fields">
{{for frames}}
<fieldset><input type="text" class="input-width" value="{{>width}}"> x <input type="text" class="input-height" value="{{>height}}"> <input type="text" class="input-label" value="{{>label}}"><a href="#" class="btn btn-delete">×</a>
</fieldset>
{{/for}}
<fieldset><input type="text" class="input-width" value=""> x <input type="text" class="input-height" value=""> <input type="text" class="input-label" value=""><a href="#" class="btn btn-delete">×</a>
</fieldset>
</div>
<a href="#" id="customize-btn-finish" class="btn">Finish</a>
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-1.8.2.min.js"><\/script>')</script>
<script src="js/jsrender.js"></script>
<script src="js/jquery.framer.js"></script>
<script src="js/jquery.configurator.js"></script>
<script>
$(function() {
// default random sites to show if no user selection
var sitesArray = [
'http://mountaindew.com',
'http://www.anderssonwise.com',
'http://www.bostonglobe.com',
'http://us.illyissimo.com',
'http://www.starbucks.com',
'http://mediaqueri.es',
'http://www.alistapart.com/d/responsive-web-design/ex/ex-site-FINAL.html',
'http://corporate.target.com',
'http://clearairchallenge.com',
'http://foodsense.is',
'http://sweethatclub.org',
'http://morehazards.com',
'http://www.microsoft.com',
'http://css-tricks.com'
];
// get sizes from url params or use default
var frames = [];
var isCustomSizes = false;
var sizes = $.Configurator().getConfig().sizes;
if (sizes) {
isCustomSizes = true;
$.each(sizes, function(i,val) {
frame = val.split(':');
size = frame[0].toLowerCase().split('x');
frames.push({ width:size[0], height:size[1], label:frame[1] || '' });
});
} else {
frames = [
{ width:320, height:480, label:'Phone (portrait)' },
{ width:480, height:320, label:'Phone (landscape)' },
{ width:480, height:800, label:'Small Tablet (portrait)' },
{ width:800, height:480, label:'Small Tablet (landscape)' },
{ width:768, height:1024, label:'Large Tablet (portrait)' },
{ width:1024, height:768, label:'Large Tablet (landscape)' },
{ width:1280, height:800, label:'Desktop' }
];
}
// url of responsivator web page for share outs
var responsivatorURL = window.location.protocol + '//' + window.location.host + window.location.pathname;
// responsivate site to show from url parameters or do random
var site = $.Configurator().getConfig().site || getRandomSite();
responsivate(site);
// create customize form
$('#form-customize').html($('#form-customize-tpl').render({frames:frames}));
// hide the header if that is option is set in the url
if ($.Configurator().getConfig().header === 'hide') {
$('header, .controls, #curr-site').css('display','none');
}
// button event to responsivate! the url in the input site field
$('#view-btn').on('click',function(e) {
e.preventDefault();
window.location = './?site='+$('#input-site').val()+getSizeParams();
});
// when you click the share field, auto-select it so it can be copied
$('#share-field-input').on('click',function() {$(this).select();});
// update share link when hide header option is checked
$('#hide-header').on('change',function() {
if ($(this).is(':checked')) {
$('#share-field-input').val(responsivatorURL+'?site='+site+'&header=hide'+getSizeParams());
} else {
$('#share-field-input').val(responsivatorURL+'?site='+site+getSizeParams());
}
});
// responsivate! on enter keypress
$('#input-site').keypress(function(e) {
if (e.keyCode == 13) {
window.location = './?site='+$('#input-site').val()+getSizeParams();
}
});
// customize modal
$()
$('#btn-customize').on('click', function (e) {
e.preventDefault();
isCustomSizes = true;
$('#form-customize').removeClass('collapsed');
});
$('#customize-btn-finish').on('click', function(e) {
e.preventDefault();
var valid = true;
$('.input-width,.input-height').removeClass('error');
var sizeConfig = '';
$('#form-customize').find('fieldset').each(function(){
var width = $(this).find('.input-width').val();
var height = $(this).find('.input-height').val();
var label = $(this).find('.input-label').val();
if (width === '' && height !== '') {
valid = false;
$(this).find('.input-width').addClass('error');
}
if (height === '' && width !== '') {
valid = false;
$(this).find('.input-height').addClass('error');
}
if (valid && width !== '' && height !== '') {
if (sizeConfig !== '') sizeConfig += ',';
sizeConfig += width+'x'+height+':'+label;
}
});
if (valid) {
$('#form-customize').addClass('collapsed');
window.location = './?site='+site+'&sizes='+sizeConfig;
}
})
$('#form-customize').on('click','.btn-delete', function(e) {
e.preventDefault();
$(this).parent().remove();
})
function getRandomSite() {
return sitesArray[Math.floor(Math.random()*sitesArray.length)];
}
function getSizeParams() {
var sizeParams = '';
if (isCustomSizes) {
sizeParams += '&sizes='
$.each(frames, function(i,val){
sizeParams += frames[i].width+'x'+frames[i].height+':'+frames[i].label;
if (i !== frames.length-1) {
sizeParams += ',';
}
});
}
return sizeParams;
}
function responsivate(url) {
// add http:// if it is missing
if ( url.indexOf('http:') === -1 && url.indexOf('https:')===-1) {
url = 'http://'+url;
}
// create share url (and check if header hide option is checked)
var shareURL = responsivatorURL+'?site='+url;
if ($('#hide-header').is(':checked')) {
shareURL += '&header=hide';
}
shareURL += getSizeParams();
$('#share-field-input').val(shareURL);
// update frames
$.Framer({ url:url, target:'#frames-wrapper', frames:frames });
// update width of page
var pageWidth = 0;
$('.frame').each(function() { pageWidth += $(this).outerWidth(true); } );
pageWidth = (pageWidth > 1200) ? pageWidth+60 : 1200;
$('header, .controls, .wrapper').css('width',pageWidth+20);
// update current site label
$('#curr-site').html('website: <a href="'+url+'" target="_blank">'+url.replace('http://','')+'</a>');
// update facebook link
$('#facebook-btn').attr('href','http://www.facebook.com/sharer.php?u=http://dfcb.github.com/Responsivator?site='+url);
// update twitter link
$('#twitter-btn').attr('href','https://twitter.com/share?url=http%3A%2F%2Fdfcb.github.com%2FResponsivator?site='+encodeURIComponent(site)+'&text=See%20how%20websites%20look%20at%20different%20screensizes%20with%20Responsivator&hashtags=responsivewebdesign');
// update site var
site = url;
}
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-34145020-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>