spans 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,424 @@
1
+ /**
2
+ * hashgrid (jQuery version, adapters are on the way)
3
+ * http://github.com/dotjay/hashgrid
4
+ * Version 8, 06 Oct 2012
5
+ * Written by Jon Gibbins
6
+ *
7
+ * Contibutors:
8
+ * James Aitken, http://loonypandora.co.uk/
9
+ * Tom Arnold, http://www.tomarnold.de/
10
+ * Sean Coates, http://seancoates.com/
11
+ * Phil Dokas, http://jetless.org/
12
+ * Andrew Jaswa, http://andrewjaswa.com/
13
+ * Callum Macrae, http://lynx.io/
14
+ */
15
+
16
+ /**
17
+ * @license Copyright 2011 Analog Coop Limited
18
+ *
19
+ * Licensed under the Apache License, Version 2.0 (the "License");
20
+ * you may not use this file except in compliance with the License.
21
+ * You may obtain a copy of the License at
22
+ *
23
+ * http://www.apache.org/licenses/LICENSE-2.0
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software
26
+ * distributed under the License is distributed on an "AS IS" BASIS,
27
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ * See the License for the specific language governing permissions and
29
+ * limitations under the License.
30
+ */
31
+
32
+ /**
33
+ * Usage
34
+ *
35
+ * // The basic #grid setup looks like this
36
+ * var grid = new hashgrid();
37
+ *
38
+ * // But there are a whole bunch of additional options you can set
39
+ * var grid = new hashgrid({
40
+ * id: 'mygrid', // set a custom id for the grid container
41
+ * modifierKey: 'alt', // optional 'ctrl', 'alt' or 'shift'
42
+ * showGridKey: 's', // key to show the grid
43
+ * holdGridKey: 'enter', // key to hold the grid in place
44
+ * foregroundKey: 'f', // key to toggle foreground/background
45
+ * jumpGridsKey: 'd', // key to cycle through the grid classes
46
+ * numberOfGrids: 2, // number of grid classes used
47
+ * classPrefix: 'myclass', // prefix for the grid classes
48
+ * cookiePrefix: 'mygrid' // prefix for the cookie name
49
+ * });
50
+ */
51
+
52
+
53
+ /**
54
+ * Make sure we have the library
55
+ * TODO: Use an adapter
56
+ */
57
+ if (typeof jQuery == "undefined") {
58
+ alert("Hashgrid: jQuery not loaded. Make sure it's linked to your pages.");
59
+ }
60
+
61
+
62
+ /**
63
+ * hashgrid overlay
64
+ * @constructor
65
+ */
66
+ spans = {};
67
+ spans.hashgrid = function(set) {
68
+
69
+ var options = {
70
+ id: 'grid', // id for the grid container
71
+ modifierKey: null, // optional 'ctrl', 'alt' or 'shift'
72
+ showGridKey: 'g', // key to show the grid
73
+ holdGridKey: 'h', // key to hold the grid in place
74
+ foregroundKey: 'f', // key to toggle foreground/background
75
+ jumpGridsKey: 'j', // key to cycle through the grid classes
76
+ numberOfGrids: 1, // number of grid classes used
77
+ classPrefix: 'grid-', // prefix for the grid classes
78
+ cookiePrefix: 'hashgrid', // prefix for the cookie name
79
+ container: $('body')
80
+ },
81
+ alreadyDown,
82
+ classNumber = 1,
83
+ gridLines,
84
+ gridWidth,
85
+ i,
86
+ line,
87
+ lineHeight,
88
+ numGridLines,
89
+ overlay,
90
+ overlayCookie,
91
+ overlayEl,
92
+ overlayOn = false,
93
+ overlayVert,
94
+ overlayZState = 'B',
95
+ overlayZBackground = -1,
96
+ overlayZForeground = 9999,
97
+ pageHeight,
98
+ setKey,
99
+ state,
100
+ sticky = false,
101
+ top;
102
+
103
+ // Apply options
104
+ if (typeof set == 'object') {
105
+ for (setKey in set) {
106
+ options[setKey] = set[setKey];
107
+ }
108
+ }
109
+ else if (typeof set == 'string') {
110
+ options.id = set;
111
+ }
112
+
113
+ // Remove any conflicting overlay
114
+ if ($('#' + options.id).length > 0) {
115
+ $('#' + options.id).remove();
116
+ }
117
+
118
+ // Create overlay, hidden before adding to DOM
119
+ overlayEl = $('<div></div>');
120
+ overlayEl
121
+ .attr('id', options.id)
122
+ .css({
123
+ display: 'none',
124
+ pointerEvents: 'none'
125
+ });
126
+ options.container.prepend(overlayEl);
127
+ overlay = $('#' + options.id);
128
+
129
+ // Unless a custom z-index is set, ensure the overlay will be behind everything
130
+ if (overlay.css('z-index') == 'auto') overlay.css('z-index', overlayZBackground);
131
+
132
+ // Override the default overlay height with the actual page height
133
+ pageHeight = parseFloat($(document).height());
134
+ overlay.height(pageHeight);
135
+
136
+ // Add the first grid line so that we can measure it
137
+ overlay.append('<div id="' + options.id + '-horiz" class="horiz first-line">');
138
+
139
+ // Position off-screen and display to calculate height
140
+ top = overlay.css("top");
141
+ overlay.css({
142
+ top: '-999px',
143
+ display: 'block'
144
+ });
145
+
146
+ // Calculate the number of grid lines needed
147
+ line = $('#' + options.id + '-horiz');
148
+ lineHeight = line.outerHeight();
149
+
150
+ // Hide and reset top
151
+ overlay.css({
152
+ display: 'none',
153
+ top: top
154
+ });
155
+
156
+ // Break on zero line height
157
+ if (lineHeight <= 0) {
158
+ return false;
159
+ }
160
+
161
+ // Add the remaining grid lines
162
+ numGridLines = Math.floor(pageHeight / lineHeight);
163
+ gridLines = '';
164
+
165
+ for (i = numGridLines - 1; i >= 1; i--) {
166
+ gridLines += '<div class="horiz"></div>';
167
+ }
168
+ overlay.append(gridLines);
169
+
170
+ // vertical grid
171
+ overlay.append($('<div class="vert-container"></div>'));
172
+ overlayVert = overlay.children('.vert-container');
173
+ gridWidth = overlay.width();
174
+ overlayVert.css({width: gridWidth, position: 'absolute', top: 0});
175
+ overlayVert.append('<div class="vert first-line">&nbsp;</div>');
176
+
177
+ // 30 is an arbitrarily large number...
178
+ // can't calculate the margin width properly
179
+ gridLines = '';
180
+ for (i = 0; i < 30; i++) {
181
+ gridLines += '<div class="vert">&nbsp;</div>';
182
+ }
183
+ overlayVert.append(gridLines);
184
+ overlayVert.children()
185
+ .height(pageHeight)
186
+ .css({ display: 'inline-block' });
187
+
188
+ // Check for saved state
189
+ overlayCookie = readCookie(options.cookiePrefix + options.id);
190
+ if (typeof overlayCookie == 'string') {
191
+ state = overlayCookie.split('-');
192
+ state[2] = Number(state[2]);
193
+ if ((typeof state[2] == 'number') && !isNaN(state[2])) {
194
+ classNumber = state[2].toFixed(0);
195
+ overlay.addClass(options.classPrefix + classNumber);
196
+ }
197
+ if (state[1] == 'F') {
198
+ overlayZState = 'F';
199
+ overlay.css('z-index', overlayZForeground);
200
+ }
201
+ if (state[0] == '1') {
202
+ overlayOn = true;
203
+ sticky = true;
204
+ showOverlay();
205
+ }
206
+ }
207
+ else {
208
+ overlay.addClass(options.classPrefix + classNumber);
209
+ }
210
+
211
+ // Keyboard controls
212
+ $(document).bind('keydown', keydownHandler);
213
+ $(document).bind('keyup', keyupHandler);
214
+
215
+ /**
216
+ * Helpers
217
+ */
218
+
219
+ function getModifier(e) {
220
+ if (options.modifierKey == null) return true; // Bypass by default
221
+ var m = true;
222
+ switch(options.modifierKey) {
223
+ case 'ctrl':
224
+ m = (e.ctrlKey ? e.ctrlKey : false);
225
+ break;
226
+
227
+ case 'alt':
228
+ m = (e.altKey ? e.altKey : false);
229
+ break;
230
+
231
+ case 'shift':
232
+ m = (e.shiftKey ? e.shiftKey : false);
233
+ break;
234
+ }
235
+ return m;
236
+ }
237
+
238
+ function getKey(e) {
239
+ var k = false, c = (e.keyCode ? e.keyCode : e.which);
240
+ // Handle keywords
241
+ if (c == 13) k = 'enter';
242
+ // Handle letters
243
+ else k = String.fromCharCode(c).toLowerCase();
244
+ return k;
245
+ }
246
+
247
+ function saveState() {
248
+ createCookie(options.cookiePrefix + options.id, (sticky ? '1' : '0') + '-' + overlayZState + '-' + classNumber, 1);
249
+ }
250
+
251
+ function showOverlay() {
252
+ overlay.show();
253
+ overlayVert.css({width: overlay.width()});
254
+ // hide any vertical blocks that aren't at the top of the viewport
255
+ overlayVert.children('.vert').each(function () {
256
+ var vCol = $(this);
257
+ vCol.css('display','inline-block');
258
+ if (vCol.offset().top > vCol.parent().offset().top) {
259
+ vCol.hide();
260
+ }
261
+ });
262
+ }
263
+
264
+ /**
265
+ * Event handlers
266
+ */
267
+
268
+ alreadyDown = {};
269
+
270
+ function keydownHandler(e) {
271
+ var k,
272
+ m,
273
+ source = e.target.tagName.toLowerCase();
274
+
275
+ if ((source == 'input') || (source == 'textarea') || (source == 'select')) {
276
+ return true;
277
+ }
278
+
279
+ m = getModifier(e);
280
+ if (!m) {
281
+ return true;
282
+ }
283
+
284
+ k = getKey(e);
285
+ if (!k) {
286
+ return true;
287
+ }
288
+
289
+ if (alreadyDown[k]) {
290
+ return true;
291
+ }
292
+ alreadyDown[k] = true;
293
+
294
+ switch(k) {
295
+ case options.showGridKey:
296
+ if (!overlayOn) {
297
+ showOverlay();
298
+ overlayOn = true;
299
+ }
300
+ else if (sticky) {
301
+ overlay.hide();
302
+ overlayOn = false;
303
+ sticky = false;
304
+ saveState();
305
+ }
306
+ break;
307
+ case options.holdGridKey:
308
+ if (overlayOn && !sticky) {
309
+ // Turn sticky overlay on
310
+ sticky = true;
311
+ saveState();
312
+ }
313
+ break;
314
+ case options.foregroundKey:
315
+ if (overlayOn) {
316
+ // Toggle sticky overlay z-index
317
+ if (overlay.css('z-index') == overlayZForeground) {
318
+ overlay.css('z-index', overlayZBackground);
319
+ overlayZState = 'B';
320
+ }
321
+ else {
322
+ overlay.css('z-index', overlayZForeground);
323
+ overlayZState = 'F';
324
+ }
325
+ saveState();
326
+ }
327
+ break;
328
+ case options.jumpGridsKey:
329
+ if (overlayOn && (options.numberOfGrids > 1)) {
330
+ // Cycle through the available grids
331
+ overlay.removeClass(options.classPrefix + classNumber);
332
+ classNumber++;
333
+ if (classNumber > options.numberOfGrids) classNumber = 1;
334
+ overlay.addClass(options.classPrefix + classNumber);
335
+ showOverlay();
336
+ if (/webkit/.test( navigator.userAgent.toLowerCase() )) {
337
+ forceRepaint();
338
+ }
339
+ saveState();
340
+ }
341
+ break;
342
+ }
343
+
344
+ return true;
345
+ }
346
+
347
+ function keyupHandler(e) {
348
+ var k,
349
+ m = getModifier(e);
350
+
351
+ if (!m) {
352
+ return true;
353
+ }
354
+
355
+ k = getKey(e);
356
+ alreadyDown[k] = false;
357
+
358
+ if (k && (k == options.showGridKey) && !sticky) {
359
+ overlay.hide();
360
+ overlayOn = false;
361
+ }
362
+
363
+ return true;
364
+ }
365
+
366
+ /**
367
+ * Cookie functions
368
+ *
369
+ * By Peter-Paul Koch:
370
+ * http://www.quirksmode.org/js/cookies.html
371
+ */
372
+ function createCookie(name, value, days) {
373
+ var date,
374
+ expires = "";
375
+
376
+ if (days) {
377
+ date = new Date();
378
+ date.setTime( date.getTime() + (days*24*60*60*1000) );
379
+ expires = "; expires=" + date.toGMTString();
380
+ }
381
+
382
+ document.cookie = name + "=" + value + expires + "; path=/";
383
+ }
384
+
385
+ function readCookie(name) {
386
+ var c,
387
+ ca = document.cookie.split(';'),
388
+ i = 0,
389
+ len = ca.length,
390
+ nameEQ = name + "=";
391
+
392
+ for (; i < len; i++) {
393
+ c = ca[i];
394
+
395
+ while (c.charAt(0) == ' ') {
396
+ c = c.substring(1, c.length);
397
+ }
398
+
399
+ if (c.indexOf(nameEQ) == 0) {
400
+ return c.substring(nameEQ.length, c.length);
401
+ }
402
+ }
403
+ return null;
404
+ }
405
+
406
+ function eraseCookie(name) {
407
+ createCookie(name, "", -1);
408
+ }
409
+
410
+ /**
411
+ * Forces a repaint (because WebKit has issues)
412
+ * http://www.sitepoint.com/forums/showthread.php?p=4538763
413
+ * http://www.phpied.com/the-new-game-show-will-it-reflow/
414
+ */
415
+ function forceRepaint() {
416
+ var ss = document.styleSheets[0];
417
+ try {
418
+ ss.addRule('.xxxxxx', 'position: relative');
419
+ ss.removeRule(ss.rules.length - 1);
420
+ } catch(e) {}
421
+ }
422
+
423
+ return {};
424
+ };
@@ -0,0 +1,23 @@
1
+ # = require spans/hashgrid
2
+
3
+ namespace = (target, name, block) ->
4
+ [target, name, block] = [(if typeof exports isnt 'undefined' then exports else window), arguments...] if arguments.length < 3
5
+ top = target
6
+ target = target[item] or= {} for item in name.split '.'
7
+ block target, top
8
+
9
+ namespace 'spans', (n) ->
10
+ class n.Helper
11
+ constructor: (options) -> @grid = new spans.hashgrid(options)
12
+
13
+ class n.Flexgrid
14
+ constructor: (@sampleFontSize, @sampleAtomWidth, @sampleAtomHeight, @modulesXCount, @modulesYCount) ->
15
+ @ratio = (@modulesYCount * @sampleAtomHeight) / (@modulesXCount * @sampleAtomWidth)
16
+ @heightToFontSize = (@modulesYCount * @sampleAtomHeight) / @sampleFontSize
17
+ $(window).resize @newFontSize
18
+ @newFontSize()
19
+
20
+ newFontSize: =>
21
+ min = Math.min($(window).innerHeight(), $(window).innerWidth() * @ratio)
22
+ fontSize = min / @heightToFontSize
23
+ $('body').css(fontSize: "#{fontSize}px")
@@ -0,0 +1,25 @@
1
+ // based on http://hashgrid.com/
2
+
3
+ #grid {
4
+ width: modules-x($modules-x-count);
5
+ position: absolute;
6
+ top: 0;
7
+ left: 0;
8
+ overflow: hidden;
9
+
10
+ .vert-container {
11
+ @extend .spans;
12
+ }
13
+ .vert{
14
+ @extend .span1;
15
+ box-sizing: border-box;
16
+ background: rgba(0, 0, 0, 0.05);
17
+ }
18
+
19
+ .horiz{
20
+ height: y(1);
21
+ box-sizing: border-box;
22
+ background: rgba(0, 0, 0, 0.05);
23
+ margin-bottom: y(1);
24
+ }
25
+ }
@@ -20,6 +20,15 @@
20
20
  }
21
21
  }
22
22
 
23
+ @mixin flex-grid-scale($times) {
24
+ $atom-y: $atom-y / $times;
25
+ $atom-x: $atom-x / $times;
26
+ font-size: #{$times}em;
27
+ @content;
28
+ $atom-y: $atom-y * $times;
29
+ $atom-x: $atom-x * $times;
30
+ }
31
+
23
32
  .spans { @include spans; }
24
33
 
25
34
  @for $i from 1 through $modules-x-count {
@@ -29,3 +38,5 @@
29
38
  @for $i from 1 through $modules-x-count {
30
39
  .spans .gap#{$i} { padding-left: modules-gap-x($i); }
31
40
  }
41
+
42
+ @import 'spans/grid';
data/lib/spans/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spans
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spans
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-02 00:00:00.000000000 Z
12
+ date: 2012-12-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: inline-blocks
@@ -34,6 +34,9 @@ executables: []
34
34
  extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
+ - app/assets/javascripts/spans/hashgrid.js
38
+ - app/assets/javascripts/spans.js.coffee
39
+ - app/assets/stylesheets/spans/grid.css.scss
37
40
  - app/assets/stylesheets/spans.css.scss
38
41
  - lib/spans/engine.rb
39
42
  - lib/spans/version.rb
@@ -55,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
58
  version: '0'
56
59
  segments:
57
60
  - 0
58
- hash: -4589111208327052847
61
+ hash: -4603871019789038408
59
62
  required_rubygems_version: !ruby/object:Gem::Requirement
60
63
  none: false
61
64
  requirements:
@@ -64,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
67
  version: '0'
65
68
  segments:
66
69
  - 0
67
- hash: -4589111208327052847
70
+ hash: -4603871019789038408
68
71
  requirements: []
69
72
  rubyforge_project:
70
73
  rubygems_version: 1.8.23