Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 273 lines (235 sloc) 9.28 kb
ace5acc @Leegorous add webapp, the grid system calculator
authored
1 <!DOCTYPE html>
2 <!--
3 The MIT License (MIT)
4 Copyright (c) <2012> <leegorous>
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 -->
822c610 @Leegorous link and add meta data in grids.html
authored
12 <html>
ace5acc @Leegorous add webapp, the grid system calculator
authored
13 <head>
14 <meta charset="utf-8" />
822c610 @Leegorous link and add meta data in grids.html
authored
15 <meta name="keywords" content="webapp, grid system, calculator, bootstrap, 960gs, 栅格系统计算器" />
16 <meta name="description" content="a grid system calculator webapp. 栅格系统计算器" />
17 <meta name="author" content="Leegorous" />
18 <meta name="copyright" content="Jun 2012" />
ace5acc @Leegorous add webapp, the grid system calculator
authored
19 <title>Grid System Calculator - leegorous.net</title>
20
21 <link rel="shortcut icon" href="/favicon.ico" />
22 <link rel="stylesheet" href="http://leegorous.net/css/bootstrap/2.0.3/css/bootstrap.min.css" />
23
24 <!--[if IE]>
25 <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
26 <![endif]-->
27 <style>
28 body {
29 background: #f5f5f5;
30 }
31 .container {
32 background: #fff;
33 }
34 .header {
35 -webkit-border-bottom-right-radius: 10px;
36 -webkit-border-bottom-left-radius: 10px;
37 -moz-border-radius-bottomright: 10px;
38 -moz-border-radius-bottomleft: 10px;
39 border-bottom-right-radius: 10px;
40 border-bottom-left-radius: 10px;
41 margin-bottom: 6px;
42 }
43 h1 {
44 padding: 20px;
45 color: #bbb;
46 text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.45);
47 }
822c610 @Leegorous link and add meta data in grids.html
authored
48 .header h2 {
49 display: none;
50 }
ace5acc @Leegorous add webapp, the grid system calculator
authored
51 .settings {
52 -webkit-border-top-left-radius: 10px;
53 -webkit-border-top-right-radius: 10px;
54 -moz-border-radius-topleft: 10px;
55 -moz-border-radius-topright: 10px;
56 border-top-left-radius: 10px;
57 border-top-right-radius: 10px;
58 padding-top: 10px;
59 }
60 .docs {
61 color: #999;
62 padding: 10px 0 0 20px;
63 }
64 .form {
65 margin: 10px 20px 0 0;
66 }
67 .page {
68 background: #ecf8fc;
69 padding-top: 10px 0;
70 margin-bottom: 10px;
71 }
72 .span {
73 background: #68cae3;
74 color: #fff;
75 float: left;
76 padding: 20px 0;
77 height: 200px;
78 text-align: center;
79 }
80 .output {
81 padding: 0 0 20px;
82 }
83 .grid {
84 margin-top: 30px;
85 margin-bottom: 50px;
86 }
87 .grid p {
88 color: #bbb;
89 }
90 .footer {
91 border-top: 1px solid #e5e5e5;
92 }
93 .copyright {
94 padding: 20px 0;
95 text-align: center;
96 }
97 </style>
98 </head>
99
100 <body>
101 <header class="container header">
102 <div class="row">
103 <div class="span12">
104 <h1>Grid System Calculator</h1>
822c610 @Leegorous link and add meta data in grids.html
authored
105 <h2>栅格系统计算器</h2>
ace5acc @Leegorous add webapp, the grid system calculator
authored
106 </div>
107 </div>
108 </header>
109
110 <section class="container settings">
111 <div class="row">
112
113 <div class="span4">
114 <div class="docs">
115 <p>This app helps you figure out all the possibilities of column and gutter width under the same <strong>page width</strong> and <strong>column amount</strong>.</p>
116 <p>Let the computer do the calculation.</p>
117 <p>All you need to do is select the nice one.</p>
118 <p>Enjoy!</p>
df09899 @Leegorous add a share2weibo script
authored
119 <p class="weibo"></p>
ace5acc @Leegorous add webapp, the grid system calculator
authored
120 </div>
121 </div>
122
123 <div class="span8">
124 <div class="form form-vercital">
125 <div class="control-group">
126 <label for="page-width">Page width: </label>
127 <input id="page-width" name="page-width" value="940"/><span class="help-inline">px</span>
128 </div>
129 <div class="control-group">
130 <label for="columns">Columns: </label>
131 <input id="columns" name="columns" type="number" value="12" />
132 </div>
133 <div class="form-actions">
134 <button class="btn btn-primary" id="ok">See all possibilities</button>
135 </div>
136 </div>
137 </div>
138
139 </div>
140 </section>
141
142 <section class="container">
143 <div class="row">
144 <div class="span12">
145 <div class="output"></div>
146 </div>
147 </div>
148 </section>
149
150 <footer class="footer container">
151 <div class="row">
152 <div class="span12">
153 <div class="copyright">
154 <p><a href="http://leegorous.net/tools/grids.html">Grid System Tool</a> designed &amp; coded by <a href="http://weibo.com/leegorous">@leegorous</a>, licensed under <a href="http://www.opensource.org/licenses/mit-license.php">MIT</a>.</p>
155 <p><a href="http://leegorous.net/"><i class="icon-home"></i> leegorous.net</a></p>
156 </div>
157 </div>
158 </div>
159 </footer>
160
161 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
162 <script src="http://underscorejs.org/underscore-min.js"></script>
df09899 @Leegorous add a share2weibo script
authored
163 <script src="/js/share2weibo.js"></script>
ace5acc @Leegorous add webapp, the grid system calculator
authored
164 <script>
165 $(document.body).ready(function() {
166 function getColumnWidth(pageWidth, columns, gutterWidth) {
167 var columnWidth = (pageWidth + gutterWidth) / columns
168
169 if (columnWidth % 1 === 0) return columnWidth - gutterWidth
170 }
171
172 function camelCase2Words(str) {
173 return str.replace(/[A-Z]/g, function(str, offset, s) { return ' ' + str.toLowerCase() })
174 }
175
176 function unit(str) {
177 return /width$/i.test(str) ? 'px' : ''
178 }
179
180 function toPre(obj) {
181 var arr = []
182
183 arr.push('@gridColumns: ' + obj.columns + ';')
184 arr.push('@gridColumnWidth: ' + obj.columnWidth + 'px;')
185 arr.push('@gridGutterWidth: ' + obj.gutterWidth + 'px;')
186 return arr.join('\n')
187 }
188
189 function toString(obj) {
190 var arr = []
191 , obj = obj || this
192
193 for(var i in obj) {
194 if ($.isFunction(obj[i])) continue
195 arr.push(camelCase2Words(i) + ': ' + obj[i] + unit(i))
196 }
197 return arr.join('<br/>')
198 }
199
200 function toColumn(i, columnWidth, gutterWidth) {
201 var style = [
202 'margin-left:' + gutterWidth + 'px'
203 , 'width:' + columnWidth + 'px'
204 ]
205 return '<div class="span" style="' + style.join('; ') + '">' + i + '</div>'
206 }
207
208 function toGrids(obj) {
209 var arr = []
210
211 arr.push('<div class="grid">')
212
213 arr.push('<div class="page" style="width: ' + obj.pageWidth + 'px">')
214 arr.push('<div class="row" style="margin-left: -' + obj.gutterWidth + 'px">')
215 for (var i = 1; i <= obj.columns; i++) arr.push(toColumn(i, obj.columnWidth, obj.gutterWidth))
216 arr.push('</div>')
217 arr.push('</div>')
218
219 if (obj.gutterWidth > obj.columnWidth) {
220 arr.push('<div class="row"><div class="span10 offset1"><div class="alert"><span class="label label-warning">Oh,</span> It looks not good for webpage.</div></div></div>')
221 }
222
223 arr.push('<div class="row">')
224 arr.push('<div class="span5 offset1"><p>Variables for <a href="http://twitter.github.com/bootstrap/" target="_blank">Bootstrap</a>.</p><pre>' + toPre(obj) + '</pre></div>')
225 arr.push('<div class="span5"><p>Or <a href="http://grids.heroku.com/grid.css?column_width=' + obj.columnWidth + '&column_amount=' + obj.columns + '&gutter_width=' + obj.gutterWidth + '" target="_blank">download the CSS</a> which base on <a href="http://960.gs/" target="_blank">960 Grid System</a></p></div>')
226 arr.push('</div>')
227
228 arr.push('</div>')
229
230 return arr.join('')
231 }
232
233 function calculate(pageWidth, columns) {
234 var arr = []
235 , max = pageWidth / columns
236
237 for(var gutterWidth = 0; gutterWidth < max; gutterWidth++) {
238 var columnWidth = getColumnWidth(pageWidth, columns, gutterWidth)
239
240 if (columnWidth) arr.push({
241 pageWidth: pageWidth
242 , columns: columns
243 , columnWidth: columnWidth
244 , gutterWidth: gutterWidth
245 })
246 }
247
248 return arr
249 }
250
251 function render(arr, fn) {
252 return _.map(arr, fn).join('')
253 }
254
255 $('#ok').click(function() {
256 var pageWidth = parseInt($('#page-width').val())
257 , columns = parseInt($('#columns').val())
258
259 $('.output').html(render(calculate(pageWidth, columns), toGrids))
260
261 return false
262 })
263
264 $('#ok').click()
265 })
266 </script>
df09899 @Leegorous add a share2weibo script
authored
267 <script>
268 share2weibo({container: $('.weibo')[0]})
269 </script>
b9a0430 @Leegorous add web track code in grids.html
authored
270 <script src="http://leegorous.net/js/ga-track.min.js"></script>
ace5acc @Leegorous add webapp, the grid system calculator
authored
271 </body>
b9a0430 @Leegorous add web track code in grids.html
authored
272 </html>
Something went wrong with that request. Please try again.