simple_sidebar 0.0.4.pre → 0.0.5.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/simple_sidebar/application/core.js.coffee +32 -14
- data/app/assets/javascripts/simple_sidebar/application/core.js.coffee~ +151 -0
- data/app/assets/stylesheets/simple_sidebar/application/core.css +1 -7
- data/lib/simple_sidebar/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e7a64b43e41a0c5e8329c8a7ea796c2f48dd99ead237f91f3709ebd2b523aea
|
4
|
+
data.tar.gz: b53501cea0aeeceaa9715559dfb6359fed536e636662426aeb8b0f2d2340f618
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 119cc66208ea5e6f7f4930fff4d69d10a8ac2cc2da9659682e3015e0ba7c136fc49de45e352423fc937d5ad45d0cb875e1a4abb76f6f121d6e17fa9ebf449156
|
7
|
+
data.tar.gz: c4461c81889535cac550f56f3d51757214e7b73939d862a14602497e5522c9293e6ba57e10278389bdbec93b4c0830dbfccfec8a4bc24b95513c0b8165b97d51
|
@@ -28,6 +28,7 @@
|
|
28
28
|
# modal: Like overlay, but with a modal background.
|
29
29
|
# position: left|right|top|bottom
|
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
|
+
# state: open|closed
|
31
32
|
#
|
32
33
|
$ ->
|
33
34
|
initializeSidebars = ->
|
@@ -36,6 +37,8 @@ $ ->
|
|
36
37
|
position = $(@).data('sidebar-position')
|
37
38
|
mode = $(@).data('sidebar-mode')
|
38
39
|
size = $(@).data('sidebar-size')
|
40
|
+
state = $(@).data('sidebar-state')
|
41
|
+
|
39
42
|
$(e).addClass("sidebar sidebar-#{position} sidebar-#{mode}")
|
40
43
|
|
41
44
|
# set correct size
|
@@ -51,14 +54,16 @@ $ ->
|
|
51
54
|
# display it
|
52
55
|
$(e).css("display", "inherit")
|
53
56
|
|
54
|
-
|
57
|
+
# set initial state
|
58
|
+
if state == 'open'
|
59
|
+
openSidebar($(@), false)
|
60
|
+
|
55
61
|
|
56
62
|
initializeModalBackground = ->
|
57
63
|
$('body').on 'click', '#sidebar-modal-background', ->
|
58
64
|
target = $("##{$(@).data('sidebar-target')}")
|
59
65
|
closeSidebar(target)
|
60
66
|
|
61
|
-
initializeModalBackground()
|
62
67
|
|
63
68
|
initializeTriggers = ->
|
64
69
|
$('[data-sidebar-trigger]').on 'click', ->
|
@@ -66,13 +71,12 @@ $ ->
|
|
66
71
|
state = target.data('sidebar-state')
|
67
72
|
|
68
73
|
if state == 'closed'
|
69
|
-
openSidebar(target)
|
74
|
+
openSidebar(target, true)
|
70
75
|
else
|
71
|
-
closeSidebar(target)
|
76
|
+
closeSidebar(target, true)
|
72
77
|
|
73
|
-
initializeTriggers()
|
74
78
|
|
75
|
-
openSidebar = (target) ->
|
79
|
+
openSidebar = (target, animate = false) ->
|
76
80
|
main_content = $('#main-content')
|
77
81
|
|
78
82
|
position = target.data('sidebar-position')
|
@@ -80,12 +84,17 @@ $ ->
|
|
80
84
|
size = target.data('sidebar-size')
|
81
85
|
|
82
86
|
# Move sidebar into viewport
|
83
|
-
|
87
|
+
if(animate == true)
|
88
|
+
target.animate({ "#{position}": 0 }, 500);
|
89
|
+
else
|
90
|
+
target.css(position, 0)
|
84
91
|
|
85
92
|
# Add margin equal to sidebar width/height to main content to make room
|
86
93
|
# for the sidebar if in push mode
|
87
|
-
|
88
|
-
|
94
|
+
if(animate == true)
|
95
|
+
main_content.animate({ "margin-#{position}": size }, 500);
|
96
|
+
else
|
97
|
+
main_content.css("margin-#{position}", size) if mode == 'push'
|
89
98
|
|
90
99
|
# add modal if in modal mode
|
91
100
|
if mode == 'modal'
|
@@ -103,9 +112,9 @@ $ ->
|
|
103
112
|
return
|
104
113
|
|
105
114
|
# set state
|
106
|
-
target.data('sidebar-state', '
|
115
|
+
target.data('sidebar-state', 'open')
|
107
116
|
|
108
|
-
closeSidebar = (target) ->
|
117
|
+
closeSidebar = (target, animate = false) ->
|
109
118
|
main_content = $('#main-content')
|
110
119
|
|
111
120
|
position = target.data('sidebar-position')
|
@@ -115,14 +124,23 @@ $ ->
|
|
115
124
|
|
116
125
|
# push
|
117
126
|
if mode == 'push'
|
118
|
-
|
119
|
-
|
127
|
+
if(animate == true)
|
128
|
+
main_content.animate({ 'marginLeft': 0 }, 500);
|
129
|
+
else
|
130
|
+
main_content.css("margin-#{position}", '0px')
|
120
131
|
|
121
132
|
# modal
|
122
133
|
if mode == 'modal'
|
123
134
|
$("#sidebar-modal-background").remove()
|
124
135
|
|
125
|
-
|
136
|
+
if(animate == true)
|
137
|
+
target.animate({ "#{position}": "-#{target.outerWidth()}px" }, 500);
|
138
|
+
else
|
139
|
+
target.css(position, "-#{target.outerWidth()}px")
|
126
140
|
|
127
141
|
# set state
|
128
142
|
target.data('sidebar-state', 'closed')
|
143
|
+
|
144
|
+
initializeSidebars()
|
145
|
+
initializeModalBackground()
|
146
|
+
initializeTriggers()
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# Usage:
|
2
|
+
#
|
3
|
+
# Put all the content that is not in the sidebar in a container with the id #main-content a trigger button and add a sidebar.
|
4
|
+
#
|
5
|
+
# <body>
|
6
|
+
# <div id="main-content">
|
7
|
+
# <button data-sidebar-trigger="#example-sidebar">
|
8
|
+
# Toggle the example sidebar!
|
9
|
+
# </button>
|
10
|
+
# </div>
|
11
|
+
# <aside
|
12
|
+
# id="example-sidebar"
|
13
|
+
# data-sidebar-load="/de/backend/authentifizierung/user_sidebar.html"
|
14
|
+
# data-sidebar-mode="overlay"
|
15
|
+
# data-sidebar-position="right"
|
16
|
+
# data-sidebar-size="20rem"
|
17
|
+
# data-sidebar-state="closed">
|
18
|
+
# <h3>Hello from the example sidebar!</h3>
|
19
|
+
# </aside>
|
20
|
+
# </body>
|
21
|
+
#
|
22
|
+
# Options:
|
23
|
+
#
|
24
|
+
# load: Passing an url to load will load the content of the url via ajax and display it in the sidebar.
|
25
|
+
# mode:
|
26
|
+
# push: This will decrease the size of the main content, making room for the sidebar.
|
27
|
+
# overlay: This will show the sidebar on top of the content, without moving it.
|
28
|
+
# modal: Like overlay, but with a modal background.
|
29
|
+
# position: left|right|top|bottom
|
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
|
+
#
|
32
|
+
$ ->
|
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
|
+
state = $(@).data('sidebar-state')
|
40
|
+
console.log(state)
|
41
|
+
$(e).addClass("sidebar sidebar-#{position} sidebar-#{mode}")
|
42
|
+
|
43
|
+
# set correct size
|
44
|
+
if position in ['top', 'bottom']
|
45
|
+
$(e).outerHeight(size)
|
46
|
+
else
|
47
|
+
$(e).outerWidth(size)
|
48
|
+
|
49
|
+
# position outside of viewport
|
50
|
+
outer_width = $(e).outerWidth()
|
51
|
+
$(e).css(position, "-#{outer_width}px")
|
52
|
+
|
53
|
+
# display it
|
54
|
+
$(e).css("display", "inherit")
|
55
|
+
|
56
|
+
# set initial state
|
57
|
+
if state == 'opened'
|
58
|
+
openSidebar($(@), false)
|
59
|
+
|
60
|
+
|
61
|
+
initializeModalBackground = ->
|
62
|
+
$('body').on 'click', '#sidebar-modal-background', ->
|
63
|
+
target = $("##{$(@).data('sidebar-target')}")
|
64
|
+
closeSidebar(target)
|
65
|
+
|
66
|
+
|
67
|
+
initializeTriggers = ->
|
68
|
+
$('[data-sidebar-trigger]').on 'click', ->
|
69
|
+
target = $($(@).data('sidebar-trigger'))
|
70
|
+
state = target.data('sidebar-state')
|
71
|
+
|
72
|
+
if state == 'closed'
|
73
|
+
openSidebar(target)
|
74
|
+
else
|
75
|
+
closeSidebar(target)
|
76
|
+
|
77
|
+
|
78
|
+
openSidebar = (target, fadeIn = true) ->
|
79
|
+
main_content = $('#main-content')
|
80
|
+
|
81
|
+
position = target.data('sidebar-position')
|
82
|
+
mode = target.data('sidebar-mode')
|
83
|
+
size = target.data('sidebar-size')
|
84
|
+
|
85
|
+
# Add margin equal to sidebar width/height to main content to make room
|
86
|
+
# for the sidebar if in push mode
|
87
|
+
if(mode == 'push')
|
88
|
+
if(fadeIn == true)
|
89
|
+
# main_content.toggleClass('transition-none')
|
90
|
+
main_content.css("transition", "margin .5s")
|
91
|
+
|
92
|
+
# Move sidebar into viewport
|
93
|
+
target.css(position, 0)
|
94
|
+
|
95
|
+
main_content.css("margin-#{position}", size)
|
96
|
+
|
97
|
+
if(fadeIn == true)
|
98
|
+
main_content.offsetHeight;
|
99
|
+
target.offsetHeight;
|
100
|
+
# main_content.toggleClass('transition-none')
|
101
|
+
main_content.css("transition", "none")
|
102
|
+
else
|
103
|
+
# Move sidebar into viewport
|
104
|
+
target.css(position, 0)
|
105
|
+
|
106
|
+
# add modal if in modal mode
|
107
|
+
if mode == 'modal'
|
108
|
+
$("body").append("<div id=\"sidebar-modal-background\" data-sidebar-target=\"#{target.attr('id')}\"></div>")
|
109
|
+
if(fadeIn == true)
|
110
|
+
$('#sidebar-modal-background').fadeIn()
|
111
|
+
else
|
112
|
+
$('#sidebar-modal-background').show()
|
113
|
+
|
114
|
+
# load content via ajax if the load option was given
|
115
|
+
if target.data('sidebar-load')
|
116
|
+
url = target.data('sidebar-load')
|
117
|
+
$.ajax
|
118
|
+
type: 'GET'
|
119
|
+
url: url
|
120
|
+
success: (response) ->
|
121
|
+
$(target).html(response)
|
122
|
+
return
|
123
|
+
|
124
|
+
# set state
|
125
|
+
target.data('sidebar-state', 'opened')
|
126
|
+
|
127
|
+
closeSidebar = (target) ->
|
128
|
+
main_content = $('#main-content')
|
129
|
+
|
130
|
+
position = target.data('sidebar-position')
|
131
|
+
mode = target.data('sidebar-mode')
|
132
|
+
size_attribute = if position in ['top', 'bottom'] then 'height' else 'width'
|
133
|
+
size = target.data('sidebar-size')
|
134
|
+
|
135
|
+
# push
|
136
|
+
if mode == 'push'
|
137
|
+
# main_content.css("margin-#{position}", size)
|
138
|
+
main_content.css("margin-#{position}", '0px')
|
139
|
+
|
140
|
+
# modal
|
141
|
+
if mode == 'modal'
|
142
|
+
$("#sidebar-modal-background").remove()
|
143
|
+
|
144
|
+
target.css(position, "-#{target.outerWidth()}px")
|
145
|
+
|
146
|
+
# set state
|
147
|
+
target.data('sidebar-state', 'closed')
|
148
|
+
|
149
|
+
initializeSidebars()
|
150
|
+
initializeModalBackground()
|
151
|
+
initializeTriggers()
|
@@ -15,29 +15,23 @@
|
|
15
15
|
.sidebar-left {
|
16
16
|
height: 100%;
|
17
17
|
top: 0;
|
18
|
-
transition: left .5s;
|
19
18
|
overflow-y: auto;
|
20
19
|
}
|
21
20
|
.sidebar-right {
|
22
21
|
height: 100%;
|
23
22
|
top: 0;
|
24
|
-
transition: right .5s;
|
25
23
|
overflow-y: auto;
|
26
24
|
}
|
27
25
|
.sidebar-top {
|
28
26
|
width: 100%;
|
29
27
|
left: 0;
|
30
|
-
transition: top .5s;
|
31
28
|
}
|
32
29
|
.sidebar-bottom {
|
33
30
|
width: 100%;
|
34
31
|
left: 0;
|
35
|
-
transition: bottom .5s;
|
36
32
|
}
|
37
33
|
|
38
|
-
#main-content {
|
39
|
-
transition: margin .5s;
|
40
|
-
}
|
34
|
+
#main-content {}
|
41
35
|
|
42
36
|
#sidebar-modal-background {
|
43
37
|
display: none;
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.5.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Vasquez Angel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- app/assets/javascripts/simple_sidebar.js
|
121
121
|
- app/assets/javascripts/simple_sidebar/application.js
|
122
122
|
- app/assets/javascripts/simple_sidebar/application/core.js.coffee
|
123
|
+
- app/assets/javascripts/simple_sidebar/application/core.js.coffee~
|
123
124
|
- app/assets/stylesheets/simple_sidebar.css
|
124
125
|
- app/assets/stylesheets/simple_sidebar/application.css
|
125
126
|
- app/assets/stylesheets/simple_sidebar/application/core.css
|
@@ -149,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
150
|
- !ruby/object:Gem::Version
|
150
151
|
version: 1.3.1
|
151
152
|
requirements: []
|
152
|
-
rubygems_version: 3.0.
|
153
|
+
rubygems_version: 3.0.8
|
153
154
|
signing_key:
|
154
155
|
specification_version: 4
|
155
156
|
summary: Simple sidebar.
|