simple_tabs 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+
2
+ function changeTab(event) {
3
+
4
+ alert("FOO");
5
+ }
6
+
7
+ jQuery.fn.simple_tabs = function() {
8
+ //var args = arguments[0] || {}; // It's your object of arguments
9
+ //alert(args);
10
+ this.each(function() {
11
+ //alert("HEY");
12
+
13
+ $(this).find('a').click(function(event) {
14
+ //alert("CHANGE");
15
+ //$(this).parent().find('fieldset.active').hide();
16
+ //$(this).find('fieldset.active').hide();
17
+ //alert($(this).text());
18
+ //alert($(this).parents('form').html());
19
+ //$(this).parents('form').find('fieldset.active').hide();
20
+
21
+ // change menu li classes
22
+ $(this).parents('ul').find('li.active').removeClass('active').addClass('inactive');
23
+ $(this).parent('li').removeClass('inactive').addClass('active');
24
+
25
+ // change content fieldset classes
26
+ $('.tab_active').addClass('tab_inactive').removeClass('tab_active');
27
+ $('.tab_' + $(this).text().toLowerCase().replace(/\W/g, '_')).addClass('tab_active').removeClass('tab_inactive');
28
+
29
+ // set url
30
+ if (typeof window.history.pushState == 'function') {
31
+ history.replaceState(null, null, $(this).attr('href'));
32
+ }
33
+ return false;
34
+ });
35
+ });
36
+ };
@@ -0,0 +1,46 @@
1
+ ul.tab_list {
2
+ margin: 0;
3
+ padding: 0;
4
+ height: 30px;
5
+ list-style: none;
6
+ border-bottom: solid darkgrey 1px;
7
+ }
8
+
9
+ ul.tab_list > li {
10
+ display: inline-block;
11
+ }
12
+
13
+ ul.tab_list > li > a {
14
+ display: block;
15
+ height: 29px;
16
+ line-height: 29px;
17
+ font-size: 16px;
18
+ text-decoration: none;
19
+ font-weight: bold;
20
+ background-color: beige;
21
+ border: solid darkgrey 1px;
22
+ border-bottom: none;
23
+ padding: 0 2em;
24
+ margin-right: 1em;
25
+ }
26
+
27
+ ul.tab_list > li.active > a {
28
+ height: 30px;
29
+ }
30
+
31
+ ul.tab_list > li > a:focus {
32
+ outline: none;
33
+ border: solid orangered 1px;
34
+ border-bottom: none;
35
+ }
36
+
37
+ .tab_inactive {
38
+ display: none;
39
+ }
40
+
41
+ .tab_active {
42
+ background-color: beige;
43
+ border: solid darkgrey 1px;
44
+ border-top: none;
45
+ padding: 1em;
46
+ }
@@ -0,0 +1,177 @@
1
+ module ActionView
2
+ # = Action View Form Helpers
3
+ module Helpers
4
+
5
+
6
+ =begin
7
+ def tabs_for(tabs, &block)
8
+ raise ArgumentError, "Missing block" unless block_given?
9
+ options = {}
10
+ builder = TabsBuilder.new(tabs, self, options, block)
11
+ output = capture(builder, &block)
12
+ output
13
+ end
14
+
15
+ =end
16
+
17
+
18
+ module TabsHelper
19
+ extend ActiveSupport::Concern
20
+
21
+ module ClassMethods
22
+
23
+ end
24
+
25
+ module InstanceMethods
26
+ =begin
27
+ def build_tabs(name, &block)
28
+ raise ArgumentError, "Missing block" unless block_given?
29
+ #options = {}
30
+ builder = TabsBuilder2.new # (tabs, self, options, block)
31
+ output = capture(builder, &block)
32
+ output
33
+
34
+ end
35
+ =end
36
+ #attr_reader :current_tab, :default_tab
37
+ =begin
38
+ @current_tab = nil
39
+ def current_tab=(tab)
40
+ @current_tab = tab.blank? ? nil : tab
41
+ end
42
+
43
+ def default_tab=(tab)
44
+ @default_tab = tab.blank? ? nil : tab
45
+ end
46
+
47
+ def default_tab
48
+ @default_tab
49
+ end
50
+ =end
51
+
52
+ def current_tab?(tab)
53
+ #logger.info("Comparing #{tab} to #{@current_tab.inspect} and #{@default_tab.inspect}")
54
+ tab.to_s.casecmp(@current_tab || @default_tab || '') == 0
55
+ end
56
+
57
+ def tabs_for(name, tabs=[])
58
+ @tabs = tabs
59
+ @name = name
60
+ @default_tab ||= @tabs.try(:first)
61
+ @current_tab ||= params[@name]
62
+ #logger.info("TABLIST #{default_tab} #{@default_tab} #{current_tab}")
63
+ content_tag(:ul, :class=>'tab_list') do
64
+ safe_join(tabs.map do |tab|
65
+ tab_id = format_tab(tab)
66
+ css_class = current_tab?(tab_id) ? 'active' : 'inactive'
67
+ content_tag(:li, :class=>css_class) do
68
+ link_to(tab, params.merge(@name=>tab_id))
69
+ end # li
70
+ end)
71
+ end # ul
72
+ end
73
+
74
+ def content_tag_with_tabs(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
75
+ if block_given? && content_or_options_with_block.is_a?(Hash)
76
+ options = content_or_options_with_block
77
+ end
78
+
79
+ tab = format_tab(options.try(:delete, :tab))
80
+ #logger.info(tab)
81
+
82
+ unless tab.blank?
83
+ @default_tab ||= tab
84
+ @current_tab ||= params[@name]
85
+ options[:class] ||= ''
86
+ options[:class] << (current_tab?(tab) ? ' tab_active' : ' tab_inactive')
87
+ options[:class] << " tab_#{tab}"
88
+ end
89
+
90
+ content_tag_without_tabs(name, content_or_options_with_block, options, escape, &block)
91
+ end
92
+
93
+ private
94
+ def format_tab(tab)
95
+ return if tab.blank?
96
+ tab.gsub(/\W/, '_').downcase
97
+ end
98
+ end # InstanceMethods
99
+
100
+ included do
101
+ alias_method_chain :content_tag, :tabs
102
+ attr_reader :current_tab, :default_tab
103
+ end
104
+ end
105
+ =begin
106
+ class TabsBuilder
107
+
108
+ def initialize(tabs, template, options, proc)
109
+ @tabs, @template, @options, @proc = tabs, template, options, proc
110
+ @params = @template.controller.request.query_parameters
111
+ @current_tab = @params[:form_tab].to_s
112
+ @current_tab = nil if @current_tab.blank?
113
+ end
114
+
115
+ def tab_list
116
+ @template.content_tag(:ul, :class=>'tab_list') do
117
+ @template.safe_join(@tabs.map do |tab|
118
+ css_class = current_tab?(tab) ? 'active' : 'inactive'
119
+ @template.content_tag(:li, :class=>css_class) do
120
+ @template.link_to(tab, @params.merge(:form_tab=>tab))
121
+ end # li
122
+ end)
123
+ end # ul
124
+ end
125
+
126
+ def content_tag(tab, tag, options={}, &block)
127
+ options[:class] ||= ''
128
+ options[:class] << (current_tab?(tab) ? ' tab_active' : ' tab_inactive')
129
+ @template.content_tag(tag, options, &block)
130
+ end
131
+
132
+ private
133
+ def current_tab?(tab)
134
+ tab.to_s.casecmp(@current_tab || @default_tab || '') == 0
135
+ end
136
+ end
137
+ =end
138
+ =begin
139
+ class TabsBuilder2
140
+ include ActionView::Helpers::TagHelper
141
+
142
+ def content_tag_with_tabs(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
143
+ raise "YES"
144
+ if block_given? && content_or_options_with_block.is_a?(Hash)
145
+ options = content_or_options_with_block
146
+ end
147
+
148
+ tab = format_tab(options.try(:delete, :tab))
149
+ logger.info(tab)
150
+
151
+ unless tab.blank?
152
+ @default_tab ||= tab
153
+ @current_tab ||= params[:form_tab]
154
+ options[:class] ||= ''
155
+ options[:class] << (current_tab?(tab) ? ' tab_active' : ' tab_inactive')
156
+ options[:class] << " tab_#{tab}"
157
+ end
158
+
159
+ content_tag_without_tabs(name, content_or_options_with_block, options, escape, &block)
160
+ end
161
+
162
+ alias_method_chain :content_tag, :tabs
163
+
164
+ end
165
+ =end
166
+ end
167
+ end
168
+
169
+ #module ActionView #:nodoc:
170
+ # module Helpers #:nodoc:
171
+ # include TabsHelper
172
+ # end
173
+ #end
174
+ ActiveSupport.on_load(:action_view) do
175
+ include ActionView::Helpers::TabsHelper
176
+ end
177
+ ActionView::Helpers.send(:include, ActionView::Helpers::TabsHelper)
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_tabs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - thoughtafter
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-02 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/simple_tabs.rb
21
+ - app/assets/javascripts/simple_tabs.js
22
+ - app/assets/stylesheets/simple_tabs.css
23
+ homepage:
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.23
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: Simple Tabs
47
+ test_files: []