-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhugrid.js
161 lines (138 loc) · 4.69 KB
/
hugrid.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
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
/*
* Heads-Up Grid
* Simple HTML + CSS grid overlay for web design and development.
*
* Files: hugrid.css, hugrid.js, example.html
*
* Example and documentation at: http://bohemianalps.com/tools/grid
*
* Shurane, thanks for your help! https://github.com/shurane
*
* Copyright (c) 2011 Jason Simanek
*
* Version: 1.5 (09/03/2011)
* Requires: jQuery v1.6+
*
* Licensed under the GPL license:
* http://www.gnu.org/licenses/gpl.html
*/
;(function ($) {
// "use strict";
window.hugrid = {
toggleState : function() {
// change our indicators of state
if (window.hugrid.state == 'on') {
window.hugrid.state = 'off' ;
}
else if( window.hugrid.state == 'off'){
window.hugrid.state = 'on' ;
}
}
} ;
makehugrid = function () {
// called at startup. Remove grids, clear state.
initialCleanUp() ;
/* Column Container */
var hugridDiv = document.createElement("div");
hugridDiv.id = "hugrid";
/* Left Margin Column */
leftDiv = document.createElement("div");
leftDiv.className = "mline mlineL";
hugridDiv.appendChild(leftDiv);
/* Create Columns */
for (var i = 0; i < (columns - 1); i++) {
colDiv = document.createElement("div");
colDiv.className = "hugcol";
hugridDiv.appendChild(colDiv);
lineLDiv = document.createElement("div");
lineLDiv.className = "lineL";
colDiv.appendChild(lineLDiv);
lineRDiv = document.createElement("div");
lineRDiv.className = "lineR";
colDiv.appendChild(lineRDiv);
}
/* Right Margin Column */
rightDiv = document.createElement("div");
rightDiv.className = "mline mlineR";
hugridDiv.appendChild(rightDiv);
document.body.appendChild(hugridDiv);
/* If Rows */
if (rowheight !== 0) {
/* Row Container */
pageheight = $(document.body).height();
var hugridRows = document.createElement("div") ;
hugridRows.id = "hugridRows";
/* Create Rows */
for (var i = 0; i < (pageheight / rowheight); i++) {
rowDiv = document.createElement("div");
rowDiv.className = "hugrow";
hugridRows.appendChild(rowDiv);
lineB = document.createElement("div");
lineB.className = "lineB";
rowDiv.appendChild(lineB);
}
document.body.appendChild(hugridRows);
}
/* Apply CSS Properties */
$('#hugrid').css('width', pagewidth + pageUnits);
if (typeof window.pageleftmargin === 'number') {
$('#hugrid').css('left', pageleftmargin + pageUnits);
$('#hugrid').css('margin', '0');
} else if (typeof window.pagerightmargin === 'number') {
$('#hugrid').css('right', pagerightmargin + pageUnits);
$('#hugrid').css('left', 'auto');
$('#hugrid').css('margin', '0');
} else {
if (pageUnits === '%') {
$('#hugrid').css('left', ((100 - pagewidth) / 2) + pageUnits);
$('#hugrid').css('margin-left', 'auto');
} else {
$('#hugrid').css('margin-left', '-' + (pagewidth / 2) + pageUnits);
}
}
$('#hugrid div.hugcol').css('margin-left', columnwidth + colUnits);
$('#hugrid div.hugcol').css('width', gutterwidth + colUnits);
$('#hugridRows').css('margin-top', pagetopmargin + 'px');
$('#hugridRows div.hugrow').css('margin-top', (rowheight - 1) + 'px');
/* Create hugridUX and button */
var hugridUX = document.createElement("div");
hugridUX.id = "hugridUX";
document.body.appendChild(hugridUX);
$('#hugridUX').append('<div id="hugridButtonBkgd"></div><button id="hugridButton"></button>');
$('#hugridButton').append('<span id="hugbuttonON">ON</span>');
$('#hugridButton').append('<span id="hugbuttonOFF" style="display:none;">OFF</span>');
/* On/Off Button - click functionality */
$('#hugridButton').click(function () {
$('#hugridButton').toggleClass('buttonisoff') ;
$('#hugrid').toggle();
$('#hugridRows').toggle();
$("#hugridButton span").toggle();
window.hugrid.toggleState() ;
});
};
function initialCleanUp() {
/* Remove Previously Existing Grid Elements */
$('#hugrid').remove();
$('#hugridRows').remove();
$('#hugridUX').remove();
}
setgridonload = function () {
if ( gridonload === 'off') {
$('#hugridButton').toggleClass('buttonisoff') ;
$('#hugrid').toggle();
$('#hugridRows').toggle();
$("#hugridButton span").toggle();
window.hugrid.state = 'off'
} else {
window.hugrid.state = 'on'
}
} ;
setgridonresize = function () {
if ( window.hugrid.state === 'off') {
$('#hugridButton').toggleClass('buttonisoff') ;
$('#hugrid').toggle();
$('#hugridRows').toggle();
$("#hugridButton span").toggle();
}
} ;
})(jQuery);