effective_bootstrap 0.12.7 → 0.13.1

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
  SHA256:
3
- metadata.gz: caf072e51e23f572c945c0d6a96bfe6409e7858663c7f381f26b2182b63f48e2
4
- data.tar.gz: 6e24ba3f3a68fb5d75b464ded353bbfab42f7c6712643f146ee344bb9f9b1f40
3
+ metadata.gz: 18aa82bffaabfcab3bd340de2d1125a8a6111e5a09d9ddb921abf06fac1bc99e
4
+ data.tar.gz: 95f1b53bfa7e32dcd5c49a769b5e58c824becf5ce098a50ce61c874e37e7a31c
5
5
  SHA512:
6
- metadata.gz: 8b5b92e6c0ed5fa76633e0f514dd151978aaca1c5a92ce88c86201363334c45e13f96380c796e2e2ab06eaf8f7afcbbce6bd9c59ee4b0d484ccd8a4d908c1f14
7
- data.tar.gz: 05db676088a579d304260b324a3c48114aca3f76f9382d05bc0a048fd87a155fb1297706af728b7b731912e1d9fce277de0166634e895dbf506dc360a10c16e1
6
+ metadata.gz: 0750f84d089f5c28d599ba92ab2c9b957c83d3e28abc02b5bc727317954152278b303581597e0b2ba1f1b9284ec0b0b840b67854485c58dc8e3354119be5fa69
7
+ data.tar.gz: 1849f908e4a40614cc24f27465b12185d49584d982fa243cf1e9e681ac19df68b88ec67b3d8cf5271a203a6f50c6c43ebeb6108d26d6bfb661119dc60f9449e9
@@ -1,18 +1,37 @@
1
+ // Set the document hash to the tab href
2
+ $(document).on('show.bs.tab', function (e) {
3
+ history.replaceState(null, null, '#' + e.target.getAttribute('id'));
4
+ });
5
+
6
+ // Display the tab based on form errors, the document hash, or ?tab= params
1
7
  $(document).ready(function() {
2
- var $tab_with_error = $(".form-control.is-invalid").first().closest('.tab-pane');
8
+ var href = '';
3
9
 
4
- if ($tab_with_error.length > 0) {
5
- $(".nav.nav-tabs").find("a[href^='#" + $tab_with_error.attr('id') + "']").tab('show');
6
- return true;
10
+ var $tab_with_error = $(".form-control.is-invalid").first().closest('.tab-pane')
7
11
 
12
+ if ($tab_with_error.length > 0) {
13
+ href = $tab_with_error.attr('id')
14
+ } else if (document.location.hash.length > 0) {
15
+ var hash = document.location.hash
16
+ if(hash.startsWith('#tab-')) { href = hash.replace('#tab-', '') }
8
17
  } else if (document.location.search.length > 0) {
9
- var tab = new URLSearchParams(document.location.search).get('tab');
10
- if((tab || '').length == 0) { return false; }
18
+ var param = new URLSearchParams(document.location.search).get('tab') || ''
19
+ if(param.length > 0) { href = param }
20
+ }
21
+
22
+ if (href.length > 0) {
23
+ var $tab = $(".nav.nav-tabs").find("a[href^='#" + href + "']")
11
24
 
12
- $('.nav.nav-tabs').find("a[href^='#" + tab + "']").tab('show');
25
+ $tab.parents('.tab-pane').each (function() {
26
+ $('.nav.nav-tabs').find("a[href^='#" + $(this).attr('id') + "']").tab('show')
27
+ })
28
+
29
+ $tab.tab('show')
13
30
  }
14
31
  });
15
32
 
33
+
34
+ // Click tab button
16
35
  $(document).on('click', '[data-click-tab]', function(event) {
17
36
  event.preventDefault();
18
37
 
@@ -64,15 +64,17 @@ module EffectiveBootstrapHelper
64
64
  # = card('title do')
65
65
  # %p Stuff
66
66
  # = card('Stuff', header: 'header title')
67
- def card(value = nil, opts = {}, &block)
67
+ def card(resource = nil, opts = {}, &block)
68
68
  raise('expected a block') unless block_given?
69
69
 
70
- if value.kind_of?(Hash)
71
- opts = value; value = nil
70
+ if resource.kind_of?(Hash)
71
+ opts = resource; resource = nil
72
72
  end
73
73
 
74
+ return if resource.kind_of?(Class) && !EffectiveResources.authorized?(self, :index, resource)
75
+
74
76
  header = opts.delete(:header)
75
- title = opts.delete(:title) || effective_bootstrap_human_name(value)
77
+ title = opts.delete(:title) || opts.delete(:label) || effective_bootstrap_human_name(resource, plural: (opts.key?(:plural) ? opts.delete(:plural) : true))
76
78
 
77
79
  content_tag(:div, merge_class_key(opts, 'card mb-4')) do
78
80
  header = content_tag(:div, header, class: 'card-header') if header.present?
@@ -316,7 +318,7 @@ module EffectiveBootstrapHelper
316
318
  def nav_link_to(resource, path, opts = {})
317
319
  return if resource.kind_of?(Class) && !EffectiveResources.authorized?(self, :index, resource)
318
320
 
319
- label = opts.delete(:label) || effective_bootstrap_human_name(resource, plural: true, prefer_model_name: true)
321
+ label = opts.delete(:label) || effective_bootstrap_human_name(resource, plural: (opts.key?(:plural) ? opts.delete(:plural) : true), prefer_model_name: true)
320
322
 
321
323
  if @_nav_mode == :dropdown # We insert dropdown-items
322
324
  return link_to(label, path, merge_class_key(opts, 'dropdown-item'))
@@ -596,12 +598,13 @@ module EffectiveBootstrapHelper
596
598
 
597
599
  NUMBERS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
598
600
 
599
- def tab(label, options = {}, &block)
600
- label = effective_bootstrap_human_name(label, prefer_model_name: true)
601
+ def tab(resource, opts = {}, &block)
602
+ return if resource.kind_of?(Class) && !EffectiveResources.authorized?(self, :index, resource)
603
+ label = opts.delete(:label) || effective_bootstrap_human_name(resource, plural: (opts.key?(:plural) ? opts.delete(:plural) : true), prefer_model_name: true)
601
604
 
602
605
  (@_tab_labels.push(label) and return) if @_tab_mode == :validate
603
606
 
604
- controls = options.delete(:controls) || label.to_s.parameterize.gsub('_', '-')
607
+ controls = opts.delete(:controls) || label.to_s.parameterize.gsub('_', '-')
605
608
  controls = "item-#{controls}" if NUMBERS.include?(controls[0]) # Can't start with a number
606
609
  controls = controls[1..-1] if controls[0] == '#'
607
610
  controls = "#{controls}-#{@_tab_unique}" if @_tab_unique
@@ -617,7 +620,7 @@ module EffectiveBootstrapHelper
617
620
  content_tag(:a, label, id: ('tab-' + controls), class: ['nav-link', ('active' if active)].compact.join(' '), href: '#' + controls, 'aria-controls': controls, 'aria-selected': active.to_s, 'data-toggle': 'tab', role: 'tab')
618
621
  end
619
622
  else # Inserting the content into the tab itself
620
- classes = ['tab-pane', 'fade', ('show active' if active), options[:class].presence].compact.join(' ')
623
+ classes = ['tab-pane', 'fade', ('show active' if active), opts[:class].presence].compact.join(' ')
621
624
  content_tag(:div, id: controls, class: classes, role: 'tabpanel', 'aria-labelledby': ('tab-' + controls), 'data-tab-label': label) do
622
625
  yield
623
626
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '0.12.7'.freeze
2
+ VERSION = '0.13.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.7
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-20 00:00:00.000000000 Z
11
+ date: 2023-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails