jsmenubuilder 0.2.11 → 0.2.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb06d9035172ed7f1953aba9dbf4b03956ad156ffe83b36fb48da1c896fbc36a
4
- data.tar.gz: 8d637454f4c39aaf2e51c96d5306124c4476a973773cd28a7564e020c413f59f
3
+ metadata.gz: 1fdc2c1787fb134b36c6d883e8809b822cbff1642542d103c8e6b965464fd227
4
+ data.tar.gz: 33dd4cec053d48d5a47f2239d1d97f9428853c18ca79012a41c798c5fa239beb
5
5
  SHA512:
6
- metadata.gz: 3619ef849c88c6df06a36740d59a16ff4dda0d1515131050d3c7df13a5583b93c5f22897b1b8735a586f5ee07cc9cac5b88ed382d0ffcfc0f4d061856932fcc9
7
- data.tar.gz: 23d1c8e9923d3d3d9fba0351aa53fada3ce52e1c3ec9a385e2c32b7665b6a51b7e1f2eb1f3865eff8fc387326408be2515e4acea054d28e1891255c021caabdc
6
+ metadata.gz: 89fc1f800e9781ed67d488b65d78b1de8fac89c3bf9181200725e35295fcdceffe71ec1abb99800ad4ba64a708d1f4dec5c1536442b4e8d9cc0dd01c8ccbe784
7
+ data.tar.gz: 3c058822cbe2013afc605610b3c22f4f65745c8418e077de4523820cc0dd87f86068e04c9aa77b857abcecdfa4c53fe2112d7e0aa93f243cfd83785759b9731c
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/jsmenubuilder.rb CHANGED
@@ -115,6 +115,9 @@ button.active {
115
115
  EOF
116
116
 
117
117
  ACCORDION_CSS = %q(
118
+
119
+
120
+
118
121
  .accordion {
119
122
  background-color: #eee;
120
123
  color: #444;
@@ -153,6 +156,42 @@ ACCORDION_CSS = %q(
153
156
  }
154
157
  )
155
158
 
159
+ STICKY_NAVBAR_CSS =<<EOF
160
+ /* Style the navbar */
161
+ #navbar {
162
+ overflow: hidden;
163
+ background-color: #333;
164
+ }
165
+
166
+ /* Navbar links */
167
+ #navbar a {
168
+ float: left;
169
+ display: block;
170
+ color: #f2f2f2;
171
+ text-align: center;
172
+ padding: 14px;
173
+ text-decoration: none;
174
+ }
175
+
176
+ /* Page content */
177
+ .content {
178
+ padding: 16px;
179
+ }
180
+
181
+ /* The sticky class is added to the navbar with JS when it reaches its scroll position */
182
+ .sticky {
183
+ position: fixed;
184
+ top: 0;
185
+ width: 100%;
186
+ }
187
+
188
+ /* Add some top padding to the page content to prevent sudden quick movement (as the navigation bar gets a new position at the top of the page (position:fixed and top:0) */
189
+ .sticky + .content {
190
+ padding-top: 60px;
191
+ }
192
+
193
+ EOF
194
+
156
195
  FULL_PAGE_TABS_JS =<<EOF
157
196
  function openPage(pageName,elmnt) {
158
197
  var i, tabcontent;
@@ -206,6 +245,26 @@ for (i = 0; i < acc.length; i++) {
206
245
 
207
246
  EOF
208
247
 
248
+ STICKY_NAVBAR_JS =<<EOF
249
+
250
+ // When the user scrolls the page, execute myFunction
251
+ window.onscroll = function() {myFunction()};
252
+
253
+ // Get the navbar
254
+ var navbar = document.getElementById("navbar");
255
+
256
+ // Get the offset position of the navbar
257
+ var sticky = navbar.offsetTop;
258
+
259
+ // Add the sticky class to the navbar when you reach its scroll position. Remove "sticky" when you leave the scroll position
260
+ function myFunction() {
261
+ if (window.pageYOffset >= sticky) {
262
+ navbar.classList.add("sticky")
263
+ } else {
264
+ navbar.classList.remove("sticky");
265
+ }
266
+ }
267
+ EOF
209
268
 
210
269
  attr_reader :html, :css, :js
211
270
 
@@ -231,7 +290,7 @@ EOF
231
290
  options = unknown
232
291
  end
233
292
 
234
- @types = %i(tabs full_page_tabs accordion)
293
+ @types = %i(tabs full_page_tabs accordion sticky_navbar)
235
294
 
236
295
  build(type, options) if type
237
296
 
@@ -366,6 +425,7 @@ EOF
366
425
  headings = options[:headings]
367
426
  headings.zip(headings.map {|heading| ['h3', {}, heading]}).to_h
368
427
  else
428
+ return unless options.has_key?(type.to_sym)
369
429
  options[type.to_sym]
370
430
  end
371
431
 
@@ -473,18 +533,40 @@ EOF
473
533
 
474
534
  def accordion(opt={})
475
535
 
476
- panels = opt[:accordion]
536
+ puts ('opt: ' + opt.inspect).debug if @debug
537
+
538
+ panels = opt[:accordion]
539
+
540
+ h = panels.group_by {|key, value| key.upcase[0]}
541
+
477
542
  debug = @debug
543
+
544
+ puts ('panels: ' + panels.inspect).debug if @debug
478
545
 
479
546
  a = RexleBuilder.build do |xml|
480
- xml.html do
481
-
482
- panels.each do |heading, inner_html|
483
- puts 'inner_html: ' + inner_html.inspect if debug
484
- xml.a({name: heading.downcase.gsub(/\W/,'-').gsub(/-{2,}/,'-')\
485
- .gsub(/^-|-$/,'')})
486
- xml.button({class:'accordion'}, heading.to_s)
487
- xml.div({class:'panel'}, inner_html)
547
+
548
+ xml.html do
549
+
550
+ xml.div(id: 'navbar') do
551
+
552
+ h.each do |char, _|
553
+ xml.a({href: '#' + char.downcase}, char)
554
+ end
555
+
556
+ end
557
+
558
+ h.each do |char, rows|
559
+
560
+ xml.h2({id: char.downcase}, char)
561
+
562
+ rows.each do |heading, inner_html|
563
+ puts 'inner_html: ' + inner_html.inspect if debug
564
+ xml.a({name: heading.downcase.gsub(/\W/,'-').gsub(/-{2,}/,'-')\
565
+ .gsub(/^-|-$/,'')})
566
+ xml.button({class:'accordion'}, heading.to_s)
567
+ xml.div({class:'panel'}, inner_html)
568
+
569
+ end
488
570
  end
489
571
 
490
572
  end
@@ -496,5 +578,37 @@ EOF
496
578
 
497
579
  end
498
580
 
581
+ def sticky_navbar(opt={})
582
+
583
+
584
+ navhtml = if opt[:html] then
585
+
586
+ opt[:html]
587
+
588
+ elsif opt[:sticky_navbar]
589
+
590
+ RexleBuilder.build do |xml|
591
+
592
+ xml.html do
593
+
594
+ xml.div(id: 'navbar') do
595
+
596
+ h.each do |char, _|
597
+ xml.a({href: '#' + char.downcase}, char)
598
+ end
599
+
600
+ end
601
+
602
+ end
603
+ end
604
+ end
605
+
606
+ doc = Rexle.new(navhtml)
607
+ puts 'doc: ' + doc.xml.inspect if @debug
608
+
609
+ return doc
610
+
611
+
612
+ end
499
613
 
500
614
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsmenubuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  haYJPATx3zs+9jtQoiFg+keM0CPYk/5LgCv9jxxzQcSS20C8O9MWRVvYfIr47ak7
36
36
  yXrDPmRvbJLTNjDv6Tkg3vU6
37
37
  -----END CERTIFICATE-----
38
- date: 2020-02-04 00:00:00.000000000 Z
38
+ date: 2020-02-23 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rexle
metadata.gz.sig CHANGED
Binary file