-
Notifications
You must be signed in to change notification settings - Fork 0
/
livegrid.js
95 lines (79 loc) · 2.21 KB
/
livegrid.js
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
/*
* Livegrid.js
*
* Licensed under the WTFPL license:
* http://www.wtfpl.net/
*
* Author: @antonigiske - 2012
*
*/
;(function ( $, window, document, undefined ) {
// Change this to your fittings.
var options = {
gridBg: "rgba(0,0,0,0.1)", // Background of the grid (so the gutters are shown)
colBg: "rgba(0,0,0,0.2)", // Background of the columns
center: true, // If you want to center the grid in document.
cols: 4, // How many columns.
colWidth: 280, // Width of each individual column.
gutterWidth: 20 // Width of the gutter. 0 for none.
};
function liveGrid( element ) {
this.element = element;
this.opts = options;
this.init();
}
liveGrid.prototype = {
init: function() {
this.gridWidth = (this.opts.cols * this.opts.colWidth) + (this.opts.cols * (this.opts.gutterWidth));
if (this.createGrid(this.element, this.opts) === false) {
return;
}
$(document).on('keyup', function(e) {
if(e.keyCode === 71) {
$('#livegrid').toggle();
}
});
},
createGrid: function(el, options) {
$(el).append('<div id="livegrid"></div>');
this.container = $('#livegrid');
for(i = 1; i <= this.opts.cols; i++) {
this.container.append('<span class="row-' + i + '"></span>');
}
this.container.css({
'position' : 'fixed',
'width' : this.gridWidth + 'px',
'height' : '100%',
'top': 0,
'background': this.opts.gridBg,
'z-index': '9999',
'display': 'none'
});
if(this.opts.center) {
this.container.css({
'left': '50%',
'marginLeft': '-' + (this.gridWidth / 2) + 'px'
});
}
this.container.find('span').css({
'background': this.opts.colBg,
'height': '100%',
'width': this.opts.colWidth + 'px',
'display': 'block',
'margin': '0 ' + (this.opts.gutterWidth / 2) + 'px 0',
'float':'left'
});
}
};
$.fn['liveGrid'] = function () {
return this.each(function () {
if (!$.data(this, 'liveGrid')) {
$.data(this, 'liveGrid', new liveGrid( this ));
}
});
};
})( jQuery, window, document );
// Go live!
$(document).ready(function() {
$('body').liveGrid();
});