yamlandar 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f77aeed87a63c42cfe7eb1d82e0bbdb7ac0c4789
4
- data.tar.gz: 4c2d0cce622654063a4a84a697c2e8ab25db49dd
3
+ metadata.gz: 1f5c097a14ff1e52e9922266513f9e91f64278ec
4
+ data.tar.gz: 5c3499b64b2c14f1b551192409c1a757b3d5f9f9
5
5
  SHA512:
6
- metadata.gz: 3c92ceb5895dbd4278fd144392044dffede8e7a4b25ecfb8d0c709118292d3dc2386aae88dd9be9b4183756272961d02b4a3a43bcdb0f6d2f29b2893d5718862
7
- data.tar.gz: 3b292c1564c649429d8652dd83577610b19d44969c19f4eb05c6113dd7627990cd805615aad620e5f1f6dd430b28a16aeb32e252849aec5312b541472f5ed825
6
+ metadata.gz: 002796fbac8a15685606fb1990a3fe2b04fd86623dcf323b60e1449a86dcdada9e9b8a7d426d71db6270c9f75ddec905592530f6a050222356831f28efcd4799
7
+ data.tar.gz: 9231dd3b37be1ef3fd340321b427d6e1433cc17b3b6b69d1273f80dd3001ed8c8919a3d7e48f23e03a0c436a2d6208d5f03968098a8aa2c7a15d6989b0b2b20a
@@ -0,0 +1,278 @@
1
+ // Sticky Plugin v1.0.4 for jQuery
2
+ // =============
3
+ // Author: Anthony Garand
4
+ // Improvements by German M. Bravo (Kronuz) and Ruud Kamphuis (ruudk)
5
+ // Improvements by Leonardo C. Daronco (daronco)
6
+ // Created: 02/14/2011
7
+ // Date: 07/20/2015
8
+ // Website: http://stickyjs.com/
9
+ // Description: Makes an element on the page stick on the screen as you scroll
10
+ // It will only set the 'top' and 'position' of your element, you
11
+ // might need to adjust the width in some cases.
12
+
13
+ (function (factory) {
14
+ if (typeof define === 'function' && define.amd) {
15
+ // AMD. Register as an anonymous module.
16
+ define(['jquery'], factory);
17
+ } else if (typeof module === 'object' && module.exports) {
18
+ // Node/CommonJS
19
+ module.exports = factory(require('jquery'));
20
+ } else {
21
+ // Browser globals
22
+ factory(jQuery);
23
+ }
24
+ }(function ($) {
25
+ var slice = Array.prototype.slice; // save ref to original slice()
26
+ var splice = Array.prototype.splice; // save ref to original slice()
27
+
28
+ var defaults = {
29
+ topSpacing: 0,
30
+ bottomSpacing: 0,
31
+ className: 'is-sticky',
32
+ wrapperClassName: 'sticky-wrapper',
33
+ center: false,
34
+ getWidthFrom: '',
35
+ widthFromWrapper: true, // works only when .getWidthFrom is empty
36
+ responsiveWidth: false,
37
+ zIndex: 'auto'
38
+ },
39
+ $window = $(window),
40
+ $document = $(document),
41
+ sticked = [],
42
+ windowHeight = $window.height(),
43
+ scroller = function() {
44
+ var scrollTop = $window.scrollTop(),
45
+ documentHeight = $document.height(),
46
+ dwh = documentHeight - windowHeight,
47
+ extra = (scrollTop > dwh) ? dwh - scrollTop : 0;
48
+
49
+ for (var i = 0, l = sticked.length; i < l; i++) {
50
+ var s = sticked[i],
51
+ elementTop = s.stickyWrapper.offset().top,
52
+ etse = elementTop - s.topSpacing - extra;
53
+
54
+ //update height in case of dynamic content
55
+ s.stickyWrapper.css('height', s.stickyElement.outerHeight());
56
+
57
+ if (scrollTop <= etse) {
58
+ if (s.currentTop !== null) {
59
+ s.stickyElement
60
+ .css({
61
+ 'width': '',
62
+ 'position': '',
63
+ 'top': '',
64
+ 'z-index': ''
65
+ });
66
+ s.stickyElement.parent().removeClass(s.className);
67
+ s.stickyElement.trigger('sticky-end', [s]);
68
+ s.currentTop = null;
69
+ }
70
+ }
71
+ else {
72
+ var newTop = documentHeight - s.stickyElement.outerHeight()
73
+ - s.topSpacing - s.bottomSpacing - scrollTop - extra;
74
+ if (newTop < 0) {
75
+ newTop = newTop + s.topSpacing;
76
+ } else {
77
+ newTop = s.topSpacing;
78
+ }
79
+ if (s.currentTop !== newTop) {
80
+ var newWidth;
81
+ if (s.getWidthFrom) {
82
+ newWidth = $(s.getWidthFrom).width() || null;
83
+ } else if (s.widthFromWrapper) {
84
+ newWidth = s.stickyWrapper.width();
85
+ }
86
+ if (newWidth == null) {
87
+ newWidth = s.stickyElement.width();
88
+ }
89
+ s.stickyElement
90
+ .css('width', newWidth)
91
+ .css('position', 'fixed')
92
+ .css('top', newTop)
93
+ .css('z-index', s.zIndex);
94
+
95
+ s.stickyElement.parent().addClass(s.className);
96
+
97
+ if (s.currentTop === null) {
98
+ s.stickyElement.trigger('sticky-start', [s]);
99
+ } else {
100
+ // sticky is started but it have to be repositioned
101
+ s.stickyElement.trigger('sticky-update', [s]);
102
+ }
103
+
104
+ if (s.currentTop === s.topSpacing && s.currentTop > newTop || s.currentTop === null && newTop < s.topSpacing) {
105
+ // just reached bottom || just started to stick but bottom is already reached
106
+ s.stickyElement.trigger('sticky-bottom-reached', [s]);
107
+ } else if(s.currentTop !== null && newTop === s.topSpacing && s.currentTop < newTop) {
108
+ // sticky is started && sticked at topSpacing && overflowing from top just finished
109
+ s.stickyElement.trigger('sticky-bottom-unreached', [s]);
110
+ }
111
+
112
+ s.currentTop = newTop;
113
+ }
114
+
115
+ // Check if sticky has reached end of container and stop sticking
116
+ var stickyWrapperContainer = s.stickyWrapper.parent();
117
+ var unstick = (s.stickyElement.offset().top + s.stickyElement.outerHeight() >= stickyWrapperContainer.offset().top + stickyWrapperContainer.outerHeight()) && (s.stickyElement.offset().top <= s.topSpacing);
118
+
119
+ if( unstick ) {
120
+ s.stickyElement
121
+ .css('position', 'absolute')
122
+ .css('top', '')
123
+ .css('bottom', 0)
124
+ .css('z-index', '');
125
+ } else {
126
+ s.stickyElement
127
+ .css('position', 'fixed')
128
+ .css('top', newTop)
129
+ .css('bottom', '')
130
+ .css('z-index', s.zIndex);
131
+ }
132
+ }
133
+ }
134
+ },
135
+ resizer = function() {
136
+ windowHeight = $window.height();
137
+
138
+ for (var i = 0, l = sticked.length; i < l; i++) {
139
+ var s = sticked[i];
140
+ var newWidth = null;
141
+ if (s.getWidthFrom) {
142
+ if (s.responsiveWidth) {
143
+ newWidth = $(s.getWidthFrom).width();
144
+ }
145
+ } else if(s.widthFromWrapper) {
146
+ newWidth = s.stickyWrapper.width();
147
+ }
148
+ if (newWidth != null) {
149
+ s.stickyElement.css('width', newWidth);
150
+ }
151
+ }
152
+ },
153
+ methods = {
154
+ init: function(options) {
155
+ var o = $.extend({}, defaults, options);
156
+ return this.each(function() {
157
+ var stickyElement = $(this);
158
+
159
+ var stickyId = stickyElement.attr('id');
160
+ var wrapperId = stickyId ? stickyId + '-' + defaults.wrapperClassName : defaults.wrapperClassName;
161
+ var wrapper = $('<div></div>')
162
+ .attr('id', wrapperId)
163
+ .addClass(o.wrapperClassName);
164
+
165
+ stickyElement.wrapAll(function() {
166
+ if ($(this).parent("#" + wrapperId).length == 0) {
167
+ return wrapper;
168
+ }
169
+ });
170
+
171
+ var stickyWrapper = stickyElement.parent();
172
+
173
+ if (o.center) {
174
+ stickyWrapper.css({width:stickyElement.outerWidth(),marginLeft:"auto",marginRight:"auto"});
175
+ }
176
+
177
+ if (stickyElement.css("float") === "right") {
178
+ stickyElement.css({"float":"none"}).parent().css({"float":"right"});
179
+ }
180
+
181
+ o.stickyElement = stickyElement;
182
+ o.stickyWrapper = stickyWrapper;
183
+ o.currentTop = null;
184
+
185
+ sticked.push(o);
186
+
187
+ methods.setWrapperHeight(this);
188
+ methods.setupChangeListeners(this);
189
+ });
190
+ },
191
+
192
+ setWrapperHeight: function(stickyElement) {
193
+ var element = $(stickyElement);
194
+ var stickyWrapper = element.parent();
195
+ if (stickyWrapper) {
196
+ stickyWrapper.css('height', element.outerHeight());
197
+ }
198
+ },
199
+
200
+ setupChangeListeners: function(stickyElement) {
201
+ if (window.MutationObserver) {
202
+ var mutationObserver = new window.MutationObserver(function(mutations) {
203
+ if (mutations[0].addedNodes.length || mutations[0].removedNodes.length) {
204
+ methods.setWrapperHeight(stickyElement);
205
+ }
206
+ });
207
+ mutationObserver.observe(stickyElement, {subtree: true, childList: true});
208
+ } else {
209
+ stickyElement.addEventListener('DOMNodeInserted', function() {
210
+ methods.setWrapperHeight(stickyElement);
211
+ }, false);
212
+ stickyElement.addEventListener('DOMNodeRemoved', function() {
213
+ methods.setWrapperHeight(stickyElement);
214
+ }, false);
215
+ }
216
+ },
217
+ update: scroller,
218
+ unstick: function(options) {
219
+ return this.each(function() {
220
+ var that = this;
221
+ var unstickyElement = $(that);
222
+
223
+ var removeIdx = -1;
224
+ var i = sticked.length;
225
+ while (i-- > 0) {
226
+ if (sticked[i].stickyElement.get(0) === that) {
227
+ splice.call(sticked,i,1);
228
+ removeIdx = i;
229
+ }
230
+ }
231
+ if(removeIdx !== -1) {
232
+ unstickyElement.unwrap();
233
+ unstickyElement
234
+ .css({
235
+ 'width': '',
236
+ 'position': '',
237
+ 'top': '',
238
+ 'float': '',
239
+ 'z-index': ''
240
+ })
241
+ ;
242
+ }
243
+ });
244
+ }
245
+ };
246
+
247
+ // should be more efficient than using $window.scroll(scroller) and $window.resize(resizer):
248
+ if (window.addEventListener) {
249
+ window.addEventListener('scroll', scroller, false);
250
+ window.addEventListener('resize', resizer, false);
251
+ } else if (window.attachEvent) {
252
+ window.attachEvent('onscroll', scroller);
253
+ window.attachEvent('onresize', resizer);
254
+ }
255
+
256
+ $.fn.sticky = function(method) {
257
+ if (methods[method]) {
258
+ return methods[method].apply(this, slice.call(arguments, 1));
259
+ } else if (typeof method === 'object' || !method ) {
260
+ return methods.init.apply( this, arguments );
261
+ } else {
262
+ $.error('Method ' + method + ' does not exist on jQuery.sticky');
263
+ }
264
+ };
265
+
266
+ $.fn.unstick = function(method) {
267
+ if (methods[method]) {
268
+ return methods[method].apply(this, slice.call(arguments, 1));
269
+ } else if (typeof method === 'object' || !method ) {
270
+ return methods.unstick.apply( this, arguments );
271
+ } else {
272
+ $.error('Method ' + method + ' does not exist on jQuery.sticky');
273
+ }
274
+ };
275
+ $(function() {
276
+ setTimeout(scroller, 0);
277
+ });
278
+ }));
data/lib/views/index.erb CHANGED
@@ -5,6 +5,9 @@
5
5
  <meta name='viewport' content='width=device-width, initial-scale=1'>
6
6
  <link rel='stylesheet' type='text/css' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'>
7
7
  <style>
8
+ :target{
9
+ padding-top:100px;
10
+ }
8
11
  h2 a{
9
12
  color:inherit;
10
13
  }
@@ -12,6 +15,11 @@
12
15
  max-width:50px;
13
16
  margin-right:.5em;
14
17
  }
18
+ .sticky{
19
+ background:#fff;
20
+ margin:0;
21
+ padding:1em 0;
22
+ }
15
23
  </style>
16
24
  <script>
17
25
  function formatDate(date) {
@@ -46,5 +54,12 @@
46
54
  <a href='#' class='js-jump'>Jump to Today</a>
47
55
  </div>
48
56
  <%= @html %>
57
+ <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
58
+ <script src='jquery.sticky.js'></script>
59
+ <script>
60
+ $(".sticky").each(function(){
61
+ $(this).sticky({topSpacing:0});
62
+ })
63
+ </script>
49
64
  </body>
50
65
  </html>
data/lib/yamlandar.rb CHANGED
@@ -4,14 +4,20 @@ require 'erb'
4
4
 
5
5
  class Yamlandar < Sinatra::Base
6
6
  def self.generate
7
+ weeknum = 1
7
8
  @html = ""
8
9
  days = YAML.load_file('schedule.yml')
9
10
  counter = 0
10
11
  start = Date.parse(days[0]["start-date"])
12
+ @html += "<div class='container'><h2 class='sticky '>Week #{weeknum}</h2></div>"
11
13
  days[1]["days"].each_with_index do |day, index|
12
14
  @html += "<div class='day container'>"
13
15
  is_saturday = (start + counter).wday == 6
14
- counter += 2 if is_saturday
16
+ if is_saturday
17
+ counter += 2
18
+ weeknum += 1
19
+ @html += "<h2 class='sticky'>Week #{weeknum}</h2>"
20
+ end
15
21
  today = (start + counter).strftime("%A, %m/%d")
16
22
  yyyymmdd = Date.parse(today).strftime("%F")
17
23
  @html += "<h2 id='#{yyyymmdd}'><a href='##{yyyymmdd}'>#{today}</a></h2>"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yamlandar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Olds
@@ -33,6 +33,7 @@ extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
35
  - bin/yamlandar
36
+ - lib/public/jquery.sticky.js
36
37
  - lib/views/index.erb
37
38
  - lib/yamlandar.rb
38
39
  homepage: http://rubygems.org/gems/yamlandar