simple_sidebar 0.0.1.pre → 0.0.2.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -0
- data/app/assets/javascripts/simple_sidebar/application/core.js.coffee +97 -73
- data/app/assets/stylesheets/simple_sidebar/application/core.css +20 -22
- data/app/assets/stylesheets/simple_sidebar/default_theme.css +4 -0
- data/app/view_helpers/simple_sidebar/application_view_helper.rb +71 -0
- data/app/views/simple_sidebar/application_view_helper/_render_sidebar.html.erb +9 -0
- data/config/initializers/assets.rb +1 -1
- data/lib/simple_sidebar/version.rb +1 -1
- data/lib/simple_sidebar.rb +3 -0
- metadata +105 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6c8cfb26fe5f3067b7f90aa1877e35310286ec547953b8fe105b0347b872d53
|
4
|
+
data.tar.gz: e7cf4ec723265a31cae6b8a0a70e12fb2958fd1bde1b599b881c6d44e45b7b63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86a5a613c1c626c439e518f2e1c5b0b2aaa60e9e6ece42999b9f13b86dca8047eea533d48a6ac69fee2ae74b25631293f0a3df478fe9d1b014f3c6c41ca19790
|
7
|
+
data.tar.gz: 3d7d44cec8e331f42cb22da8baf120d486860db960edb355de5f4c07fefc4a36a1ba9faa4750de4e20b7d5e44a65970ef4442a927d064bbd93ea90e612ce8f3e
|
data/Rakefile
CHANGED
@@ -9,12 +9,12 @@
|
|
9
9
|
# </button>
|
10
10
|
# </div>
|
11
11
|
# <aside
|
12
|
-
# id="example-sidebar"
|
12
|
+
# id="example-sidebar"
|
13
13
|
# data-sidebar-load="/de/backend/authentifizierung/user_sidebar.html"
|
14
14
|
# data-sidebar-mode="overlay"
|
15
15
|
# data-sidebar-position="right"
|
16
16
|
# data-sidebar-size="20rem"
|
17
|
-
# data-sidebar-state="closed"
|
17
|
+
# data-sidebar-state="closed">
|
18
18
|
# <h3>Hello from the example sidebar!</h3>
|
19
19
|
# </aside>
|
20
20
|
# </body>
|
@@ -30,75 +30,99 @@
|
|
30
30
|
# size: size that the sidebar will take up (width for left and right, height for top and bottom). Pass any css size in px, rem or whatever you like.
|
31
31
|
#
|
32
32
|
$ ->
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
33
|
+
initializeSidebars = ->
|
34
|
+
$('[data-sidebar-position]').each (_, e) ->
|
35
|
+
# add css classes
|
36
|
+
position = $(@).data('sidebar-position')
|
37
|
+
mode = $(@).data('sidebar-mode')
|
38
|
+
size = $(@).data('sidebar-size')
|
39
|
+
$(e).addClass("sidebar sidebar-#{position} sidebar-#{mode}")
|
40
|
+
|
41
|
+
# set correct size
|
42
|
+
if position in ['top', 'bottom']
|
43
|
+
$(e).outerHeight(size)
|
44
|
+
else
|
45
|
+
$(e).outerWidth(size)
|
46
|
+
|
47
|
+
# position outside of viewport
|
48
|
+
outer_width = $(e).outerWidth()
|
49
|
+
$(e).css(position, "-#{outer_width}px")
|
50
|
+
|
51
|
+
# display it
|
52
|
+
$(e).css("display", "inherit")
|
53
|
+
|
54
|
+
initializeSidebars()
|
55
|
+
|
56
|
+
initializeModalBackground = ->
|
57
|
+
$('body').on 'click', '#sidebar-modal-background', ->
|
58
|
+
target = $("##{$(@).data('sidebar-target')}")
|
59
|
+
closeSidebar(target)
|
60
|
+
|
61
|
+
initializeModalBackground()
|
62
|
+
|
63
|
+
initializeTriggers = ->
|
64
|
+
$('[data-sidebar-trigger]').on 'click', ->
|
65
|
+
target = $($(@).data('sidebar-trigger'))
|
66
|
+
state = target.data('sidebar-state')
|
67
|
+
|
68
|
+
if state == 'closed'
|
69
|
+
openSidebar(target)
|
70
|
+
else
|
71
|
+
closeSidebar(target)
|
72
|
+
|
73
|
+
initializeTriggers()
|
74
|
+
|
75
|
+
openSidebar = (target) ->
|
76
|
+
main_content = $('#main-content')
|
77
|
+
|
78
|
+
position = target.data('sidebar-position')
|
79
|
+
mode = target.data('sidebar-mode')
|
80
|
+
size = target.data('sidebar-size')
|
81
|
+
|
82
|
+
# Move sidebar into viewport
|
83
|
+
target.css(position, 0)
|
84
|
+
|
85
|
+
# Add margin equal to sidebar width/height to main content to make room
|
86
|
+
# for the sidebar if in push mode
|
87
|
+
main_content.css("margin-#{position}", size) if mode == 'push'
|
88
|
+
|
89
|
+
|
90
|
+
# add modal if in modal mode
|
91
|
+
if mode == 'modal'
|
92
|
+
$("body").append("<div id=\"sidebar-modal-background\" data-sidebar-target=\"#{target.attr('id')}\"></div>")
|
93
|
+
$('#sidebar-modal-background').fadeIn()
|
94
|
+
|
95
|
+
# load content via ajay if the load option was given
|
96
|
+
if target.data('sidebar-load')
|
97
|
+
url = target.data('sidebar-load')
|
98
|
+
$.ajax
|
99
|
+
type: 'GET'
|
100
|
+
url: url
|
101
|
+
success: (response) ->
|
102
|
+
$(target).html(response)
|
103
|
+
return
|
104
|
+
|
105
|
+
# set state
|
106
|
+
target.data('sidebar-state', 'opened')
|
107
|
+
|
108
|
+
closeSidebar = (target) ->
|
109
|
+
main_content = $('#main-content')
|
110
|
+
|
111
|
+
position = target.data('sidebar-position')
|
112
|
+
mode = target.data('sidebar-mode')
|
113
|
+
size_attribute = if position in ['top', 'bottom'] then 'height' else 'width'
|
114
|
+
size = target.data('sidebar-size')
|
46
115
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
target.css("display", "inherit")
|
61
|
-
target.css(size_attribute, size)
|
62
|
-
main_content.css("margin-#{position}", size) if mode == 'push'
|
63
|
-
|
64
|
-
|
65
|
-
# modal
|
66
|
-
if mode == 'modal'
|
67
|
-
$("body").append("<div id=\"sidebar-modal-background\" data-sidebar-target=\"#{target.attr('id')}\"></div>")
|
68
|
-
|
69
|
-
# load
|
70
|
-
if target.data('sidebar-load')
|
71
|
-
url = target.data('sidebar-load')
|
72
|
-
$.ajax
|
73
|
-
type: 'GET'
|
74
|
-
url: url
|
75
|
-
success: (response) ->
|
76
|
-
$(target).html(response)
|
77
|
-
return
|
78
|
-
|
79
|
-
# set state
|
80
|
-
target.data('sidebar-state', 'opened')
|
81
|
-
|
82
|
-
closeModal = (target) ->
|
83
|
-
main_content = $('#main-content')
|
84
|
-
|
85
|
-
position = target.data('sidebar-position')
|
86
|
-
mode = target.data('sidebar-mode')
|
87
|
-
size_attribute = if position in ['top', 'bottom'] then 'height' else 'width'
|
88
|
-
size = target.data('sidebar-size')
|
89
|
-
|
90
|
-
# push
|
91
|
-
if mode == 'push'
|
92
|
-
main_content.css("margin-#{position}", size)
|
93
|
-
|
94
|
-
# modal
|
95
|
-
if mode == 'modal'
|
96
|
-
$("#sidebar-modal-background").remove()
|
97
|
-
|
98
|
-
target.css(size_attribute, '0px')
|
99
|
-
|
100
|
-
if mode == 'push'
|
101
|
-
main_content.css("margin-#{position}", '0px')
|
102
|
-
|
103
|
-
# set state
|
104
|
-
target.data('sidebar-state', 'closed')
|
116
|
+
# push
|
117
|
+
if mode == 'push'
|
118
|
+
# main_content.css("margin-#{position}", size)
|
119
|
+
main_content.css("margin-#{position}", '0px')
|
120
|
+
|
121
|
+
# modal
|
122
|
+
if mode == 'modal'
|
123
|
+
$("#sidebar-modal-background").remove()
|
124
|
+
|
125
|
+
target.css(position, "-#{target.outerWidth()}px")
|
126
|
+
|
127
|
+
# set state
|
128
|
+
target.data('sidebar-state', 'closed')
|
@@ -1,51 +1,49 @@
|
|
1
|
-
.sidebar {
|
1
|
+
.sidebar, [data-sidebar-position] {
|
2
2
|
position: fixed;
|
3
|
+
display: none;
|
3
4
|
z-index: 3000;
|
4
|
-
overflow-x: hidden;
|
5
|
-
transition: 0.5s;
|
6
5
|
}
|
6
|
+
.sidebar {}
|
7
|
+
|
8
|
+
.sidebar-push {}
|
9
|
+
.sidebar-overlay {}
|
10
|
+
.sidebar-modal {}
|
11
|
+
|
12
|
+
.sidebar-closed {}
|
13
|
+
.sidebar-opened {}
|
7
14
|
|
8
15
|
.sidebar-left {
|
9
16
|
height: 100%;
|
10
|
-
width: 0;
|
11
17
|
top: 0;
|
12
|
-
|
18
|
+
transition: left .5s;
|
13
19
|
}
|
14
20
|
.sidebar-right {
|
15
21
|
height: 100%;
|
16
|
-
width: 0;
|
17
22
|
top: 0;
|
18
|
-
|
23
|
+
transition: right .5s;
|
19
24
|
}
|
20
25
|
.sidebar-top {
|
21
26
|
width: 100%;
|
22
|
-
height: 0;
|
23
27
|
left: 0;
|
24
|
-
|
28
|
+
transition: top .5s;
|
25
29
|
}
|
26
30
|
.sidebar-bottom {
|
27
31
|
width: 100%;
|
28
|
-
height: 0;
|
29
32
|
left: 0;
|
30
|
-
|
33
|
+
transition: bottom .5s;
|
34
|
+
}
|
35
|
+
|
36
|
+
#main-content {
|
37
|
+
transition: margin .5s;
|
31
38
|
}
|
32
39
|
|
33
40
|
#sidebar-modal-background {
|
41
|
+
display: none;
|
34
42
|
position: fixed;
|
35
43
|
z-index: 2000;
|
36
44
|
left: 0;
|
37
45
|
top: 0;
|
38
46
|
width: 100%;
|
39
47
|
height: 100%;
|
40
|
-
background
|
41
|
-
background-color: rgba(0,0,0,0.4);
|
42
|
-
}
|
43
|
-
|
44
|
-
#main-content {
|
45
|
-
transition: margin .5s;
|
48
|
+
background: rgba(0,0,0,0.4);
|
46
49
|
}
|
47
|
-
|
48
|
-
/* @media screen and (max-height: 450px) {
|
49
|
-
.sidebar {padding-top: 15px;}
|
50
|
-
.sidebar a {font-size: 18px;}
|
51
|
-
} */
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module SimpleSidebar
|
2
|
+
# Usage:
|
3
|
+
#
|
4
|
+
# # app/controllers/application_controller.rb
|
5
|
+
# class ApplicationController < AcitonController::Base
|
6
|
+
# view_helper SimpleSidebar::ApplicationViewHelper, as: :simple_sidebar_helper
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
class ApplicationViewHelper < Rao::ViewHelper::Base
|
10
|
+
# Usage
|
11
|
+
#
|
12
|
+
# Adding a sidebar:
|
13
|
+
#
|
14
|
+
#
|
15
|
+
# This will add a sidebar on the left in push mode and add some custom html to the
|
16
|
+
# sidebar container:
|
17
|
+
#
|
18
|
+
# <div id="main-content">
|
19
|
+
# <button data-sidebar-trigger="#sidebar1">Sidebar 1</button>
|
20
|
+
# </div>
|
21
|
+
#
|
22
|
+
# <%= simple_sidebar_helper(self).render_sidebar(:sidebar1, position: :left, mode: :push, container_html: { style: 'padding: 20px; overflow: scroll;'}) do %>
|
23
|
+
# <h3>This is sidebar 1</h3>
|
24
|
+
# <button data-sidebar-trigger="#sidebar1">Close me</button>
|
25
|
+
# <% end %>
|
26
|
+
#
|
27
|
+
# This will add a sidebar to the right in default mode (overlay):
|
28
|
+
#
|
29
|
+
# <div id="main-content">
|
30
|
+
# <button data-sidebar-trigger="#sidebar2">Sidebar 2</button>
|
31
|
+
# </div>
|
32
|
+
# <%= simple_sidebar_helper(self).render_sidebar(:sidebar2, position: :right) do %>
|
33
|
+
# <h3>This is sidebar 2</h3>
|
34
|
+
# <button data-sidebar-trigger="#sidebar2">Close me</button>
|
35
|
+
# <% end %>
|
36
|
+
#
|
37
|
+
# This will add a sidebar to the top, loading custom content into the sidebar via ajax:
|
38
|
+
#
|
39
|
+
# <div id="main-content">
|
40
|
+
# <button data-sidebar-trigger="#sidebar3">Sidebar 3</button>
|
41
|
+
# </div>
|
42
|
+
# <%= simple_sidebar_helper(self).render_sidebar(:sidebar3, position: :top, load: '/current_user_profile') do %>
|
43
|
+
# <h3>This is sidebar 3</h3>
|
44
|
+
# <button data-sidebar-trigger="#sidebar3">Close me</button>
|
45
|
+
# <% end %>
|
46
|
+
#
|
47
|
+
# If you want to load content from external urls you will have to add the correct policies to the cors settings.
|
48
|
+
#
|
49
|
+
# This will render a sidebar to the bottom in modal mode:
|
50
|
+
#
|
51
|
+
# <div id="main-content">
|
52
|
+
# <button data-sidebar-trigger="#sidebar4">Sidebar 4</button>
|
53
|
+
# </div>
|
54
|
+
# <%= simple_sidebar_helper(self).render_sidebar(:sidebar4, position: :bottom, mode: :modal) do %>
|
55
|
+
# <h3>This is sidebar 4</h3>
|
56
|
+
# <button data-sidebar-trigger="#sidebar4">Close me</button>
|
57
|
+
# <% end %>
|
58
|
+
#
|
59
|
+
def render_sidebar(name, options = {}, &block)
|
60
|
+
options.reverse_merge!(
|
61
|
+
load: nil,
|
62
|
+
mode: :overlay,
|
63
|
+
position: :left,
|
64
|
+
size: '25rem',
|
65
|
+
state: :closed,
|
66
|
+
container_html: {}
|
67
|
+
)
|
68
|
+
c.render partial: '/simple_sidebar/application_view_helper/render_sidebar', locals: { name: name, options: options, block: block }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<aside
|
2
|
+
id="<%= name %>"
|
3
|
+
data-sidebar-load="<%= options[:load] %>"
|
4
|
+
data-sidebar-mode="<%= options[:mode] %>"
|
5
|
+
data-sidebar-position="<%= options[:position] %>"
|
6
|
+
data-sidebar-size="<%= options[:size] %>"
|
7
|
+
data-sidebar-state="<%= options[:state] %>" <%= options[:container_html].collect { |k,v| "#{k}=\"#{v}\"" }.join(' ').html_safe %>>
|
8
|
+
<%= capture(&block) %>
|
9
|
+
</aside>
|
@@ -1,4 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
Rails.application.config.assets.precompile += %w( simple_sidebar.css )
|
3
|
+
Rails.application.config.assets.precompile += %w( simple_sidebar.css simple_sidebar/default_theme.css )
|
4
4
|
Rails.application.config.assets.precompile += %w( simple_sidebar.js )
|
data/lib/simple_sidebar.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_sidebar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Vasquez Angel
|
@@ -9,7 +9,105 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2019-04-03 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coffee-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rao-view_helper
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.17.pre
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.17.pre
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.6
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.3.6
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rails-dummy
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
13
111
|
description:
|
14
112
|
email:
|
15
113
|
- roberto@vasquez-angel.de
|
@@ -25,6 +123,9 @@ files:
|
|
25
123
|
- app/assets/stylesheets/simple_sidebar.css
|
26
124
|
- app/assets/stylesheets/simple_sidebar/application.css
|
27
125
|
- app/assets/stylesheets/simple_sidebar/application/core.css
|
126
|
+
- app/assets/stylesheets/simple_sidebar/default_theme.css
|
127
|
+
- app/view_helpers/simple_sidebar/application_view_helper.rb
|
128
|
+
- app/views/simple_sidebar/application_view_helper/_render_sidebar.html.erb
|
28
129
|
- config/initializers/assets.rb
|
29
130
|
- lib/simple_sidebar.rb
|
30
131
|
- lib/simple_sidebar/engine.rb
|
@@ -41,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
142
|
requirements:
|
42
143
|
- - ">="
|
43
144
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
145
|
+
version: 2.5.0
|
45
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
147
|
requirements:
|
47
148
|
- - ">"
|
@@ -49,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
150
|
version: 1.3.1
|
50
151
|
requirements: []
|
51
152
|
rubyforge_project:
|
52
|
-
rubygems_version: 2.7.
|
153
|
+
rubygems_version: 2.7.6
|
53
154
|
signing_key:
|
54
155
|
specification_version: 4
|
55
156
|
summary: Simple sidebar.
|