bootstrap_builders 0.0.12 → 0.0.13

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: 69aba106e86b2b88ad340319aa6dd7253c080db3
4
- data.tar.gz: 26f9e557f7eb1db22dc67db0246b6a6521cd2014
3
+ metadata.gz: 871085f57ae41b057c60bae61417ded98714eca8
4
+ data.tar.gz: e2faf748dd49c93a425aec8e107e3592f7c976cd
5
5
  SHA512:
6
- metadata.gz: 68771a2f960b0b51f63a07a51df5ef83caa935414ff08fe7a01ce2fa6cd71cdcf3af7dc75e81f916ac4011f354e26a8fdce9ab3095cf83a63a3e749b68d35740
7
- data.tar.gz: aa069a5b2332d29bd3b0b1a018374e13708388a8177f37af3db0990fbf9d86b5a91fba41afebd13b6b0d6bea47f5163260a16a6bb11a577a0f6eb97d73293d14
6
+ metadata.gz: 8bd67268a0c668e10f288b6df3b650c9c19ca1030dc010e982f22e196872680745ae003d1e35e2650f4a8abfcc0afaddebae4ca0a680f41eaf38c2549f792f0f
7
+ data.tar.gz: aa374e5c6162e0391cb6789fcf9cbad156372755f07c253abf4b73cf1bbc4bccfa31d5a38110586df11973e78649616b7d3033f95c1b2b200847f5d6ea0cad18
@@ -1,14 +1,26 @@
1
1
  $ ->
2
- $("body").on "click", ".bb-tabs-container .nav li[data-ajax-url]", ->
3
- li = $(this)
2
+ loadAjaxTab = (li) ->
4
3
  link = $("a", li)
5
4
  content_id = link.attr("href").substring(1, 999)
6
5
  content = $(".bb-tabs-container #" + content_id + " .bb-tab-container")
7
6
 
8
- return if li.data("ajax-loaded")
9
7
  li.data("ajax-loaded", true)
10
-
11
8
  content.fadeOut 0, ->
12
9
  $.get li.data("ajax-url"), (data) ->
13
10
  content.html(data)
14
11
  content.fadeIn "fast"
12
+
13
+ $("body").on "click", ".bb-tabs-container .nav li", ->
14
+ li = $(this)
15
+
16
+ if li.data("specific-id-given")
17
+ urlb = new UrlBuilder(window.location.href)
18
+ urlb.queryParameters["bb_selected_tab"] = $(this).data("tab-container-id")
19
+
20
+ window.history.pushState("bb-tab-change", "", urlb.pathWithQueryParameters())
21
+
22
+ if li.data("ajax-url") && !li.data("ajax-loaded")
23
+ loadAjaxTab(li)
24
+
25
+ active_tab = $(".bb-tabs-container .nav li.active[data-ajax-url]")
26
+ loadAjaxTab(active_tab) if active_tab.length > 0
@@ -7,6 +7,12 @@ class BootstrapBuilders::Tab
7
7
  @label = args.fetch(:label)
8
8
  @ajax_url = args[:ajax_url]
9
9
 
10
+ if args[:container_id]
11
+ @specific_id_given = true
12
+ else
13
+ @specific_id_given = false
14
+ end
15
+
10
16
  @container_id = args[:container_id].presence
11
17
  @container_id ||= SecureRandom.hex
12
18
  end
@@ -14,4 +20,8 @@ class BootstrapBuilders::Tab
14
20
  def active?
15
21
  @active
16
22
  end
23
+
24
+ def specific_id_given?
25
+ @specific_id_given
26
+ end
17
27
  end
@@ -26,7 +26,7 @@ class BootstrapBuilders::Tabs
26
26
  container.add_ele(:div, classes: ["clearfix"])
27
27
 
28
28
  @tabs.each do |tab|
29
- li = ul.add_ele(:li)
29
+ li = ul.add_ele(:li, data: {specific_id_given: tab.specific_id_given?, tab_container_id: tab.container_id})
30
30
  li.add_ele(:a, str: tab.label, attr: {href: "##{tab.container_id}"}, data: {toggle: "tab"})
31
31
  li.classes << "active" if tab.active?
32
32
  li.data[:ajax_url] = tab.ajax_url if tab.ajax_url.present?
@@ -62,6 +62,18 @@ private
62
62
 
63
63
  def set_default_first_active
64
64
  return if @tabs.any?(&:active?)
65
- @tabs.first.active = true if @tabs.any?
65
+
66
+ active_found = false
67
+
68
+ if @context.params["bb_selected_tab"].present?
69
+ tab = @tabs.find { |tab_i| tab_i.container_id == @context.params["bb_selected_tab"] }
70
+
71
+ if tab
72
+ tab.active = true
73
+ active_found = true
74
+ end
75
+ end
76
+
77
+ @tabs.first.active = true if @tabs.any? && !active_found
66
78
  end
67
79
  end
@@ -1,3 +1,3 @@
1
1
  module BootstrapBuilders
2
- VERSION = "0.0.12".freeze
2
+ VERSION = "0.0.13".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_builders
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-26 00:00:00.000000000 Z
11
+ date: 2016-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -276,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
276
276
  version: '0'
277
277
  requirements: []
278
278
  rubyforge_project:
279
- rubygems_version: 2.4.0
279
+ rubygems_version: 2.2.2
280
280
  signing_key:
281
281
  specification_version: 4
282
282
  summary: A library to generate Bootstrap HTML for Rails.