modalist 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE +21 -0
- data/README.md +302 -0
- data/app/helpers/modalist/modal_helper.rb +29 -0
- data/app/helpers/modalist/render_helper.rb +9 -0
- data/app/views/layouts/modalist.html.erb +19 -0
- data/app/views/modalist/_close.html.erb +4 -0
- data/app/views/modalist/_modal.html.erb +2 -0
- data/lib/modalist/ajax.rb +9 -0
- data/lib/modalist/engine.rb +6 -0
- data/lib/modalist/railtie.rb +13 -0
- data/lib/modalist/version.rb +5 -0
- data/lib/modalist.rb +10 -0
- data/vendor/javascripts/iziModal.js +1440 -0
- data/vendor/javascripts/iziModal.min.js +6 -0
- data/vendor/javascripts/modalist.js +111 -0
- data/vendor/stylesheets/iziModal.css +1097 -0
- data/vendor/stylesheets/iziModal.min.css +6 -0
- data/vendor/stylesheets/modalist.sass +86 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1cbf3abd0b4787f3ab6afb23b2846b05a0dd92a4de370e388ce249242e29f0f3
|
4
|
+
data.tar.gz: 38dfacf7c7d68db70b7444e7e8e7bd03a775773287ca35adf36b7b94c175fa1b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 47caee6ccf5fb50518790a4ae534448110b4836262651f284b729471c14fa8132bb1dc1c91f0ed3a050479a8bb8a091b591203c6fb793d85bd243dad614f07ca
|
7
|
+
data.tar.gz: dc75cd91513f0e666c01914e2bb3b6c6467c22f3077d9d0f8371c110bef7b1c5b2a8f2d35b23f2c167ca1d3cf2a21d2db442e12c50e1c6eb6a173ac44b698a81
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jonas Hübotter
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,302 @@
|
|
1
|
+
# Modalist
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/modalist) <img src="https://travis-ci.org/jonhue/modalist.svg?branch=master" />
|
4
|
+
|
5
|
+
Modalist is a powerful ajaxified modal solution for Rails. Here is how it works:
|
6
|
+
|
7
|
+
1) You trigger a modal opening from your frontend code
|
8
|
+
2) Modalist fetches the modal contents from your specific modal-controller-action with AJAX
|
9
|
+
3) The modal opens
|
10
|
+
|
11
|
+
Modalist does not reinvent the wheel and uses the best modal-engine [iziModal.js](https://github.com/dolce/iziModal) to backup its code.
|
12
|
+
|
13
|
+
---
|
14
|
+
|
15
|
+
## Table of Contents
|
16
|
+
|
17
|
+
* [Installation](#installation)
|
18
|
+
* [Usage](#usage)
|
19
|
+
* [Controllers](#controllers)
|
20
|
+
* [Views](#views)
|
21
|
+
* [Trigger a modal](#trigger-a-modal)
|
22
|
+
* [Modalist functions](#modalist-functions)
|
23
|
+
* [Options](#options)
|
24
|
+
* [Styles](#styles)
|
25
|
+
* [Events](#events)
|
26
|
+
* [To Do](#to-do)
|
27
|
+
* [Contributing](#contributing)
|
28
|
+
* [Contributors](#contributors)
|
29
|
+
* [License](#license)
|
30
|
+
|
31
|
+
---
|
32
|
+
|
33
|
+
## Installation
|
34
|
+
|
35
|
+
Modalist works with Rails 5 onwards. You can add it to your `Gemfile` with:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
gem 'modalist'
|
39
|
+
```
|
40
|
+
|
41
|
+
And then execute:
|
42
|
+
|
43
|
+
$ bundle
|
44
|
+
|
45
|
+
Or install it yourself as:
|
46
|
+
|
47
|
+
$ gem install modalist
|
48
|
+
|
49
|
+
If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
gem 'modalist', github: 'jonhue/modalist'
|
53
|
+
```
|
54
|
+
|
55
|
+
## Usage
|
56
|
+
|
57
|
+
First let's add the necessary assets to your pipeline:
|
58
|
+
|
59
|
+
```js
|
60
|
+
//= require jquery
|
61
|
+
//= require iziModal
|
62
|
+
//= require modalist
|
63
|
+
```
|
64
|
+
|
65
|
+
```css
|
66
|
+
/*
|
67
|
+
*= require iziModal
|
68
|
+
*= require modalist
|
69
|
+
*/
|
70
|
+
```
|
71
|
+
|
72
|
+
**Note:** If you are using a package manager like Yarn, import the latest [iziModal](https://github.com/dolce/iziModal) and [modalist](https://github.com/jonhue/modalist.js) code instead.
|
73
|
+
|
74
|
+
Specify where modals should be located in your view:
|
75
|
+
|
76
|
+
```haml
|
77
|
+
!!!
|
78
|
+
%html
|
79
|
+
%head
|
80
|
+
-# ...
|
81
|
+
%body
|
82
|
+
= modalist
|
83
|
+
= yield
|
84
|
+
```
|
85
|
+
|
86
|
+
### Controllers
|
87
|
+
|
88
|
+
Modallist simulates Rails' MVC structure. To add a new modal to your app you have to create a new controller action, route and view:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
class SettingsController < ApplicationController
|
92
|
+
|
93
|
+
def index
|
94
|
+
# a regular controller action
|
95
|
+
end
|
96
|
+
|
97
|
+
def modalist
|
98
|
+
modalist
|
99
|
+
# a modalist controller action
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
Rails.application.routes.draw do
|
107
|
+
|
108
|
+
get 'settings', to: 'settings#index'
|
109
|
+
scope :settings, as: :settings do
|
110
|
+
get 'modalist', to: 'settings#modalist'
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
```
|
115
|
+
|
116
|
+
In most cases you only want to allow AJAX requests to be able to reach your modal-controller-actions:
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
get 'modalist', to: 'settings#modalist', constraints: Modalist::Ajax.new
|
120
|
+
```
|
121
|
+
|
122
|
+
### Views
|
123
|
+
|
124
|
+
In your Modalist views are a couple of helper methods available:
|
125
|
+
|
126
|
+
**`modalist_title(title)`:** This will specify a title for your modal. If you omit this in your view, your modal will not have a header. Takes a string.
|
127
|
+
|
128
|
+
**`modalist_subtitle(subtitle)`:** Add a subtitle to your modal header. Takes a string.
|
129
|
+
|
130
|
+
**`modalist_actions(&block)`:** Specify actions (preferably icons wrapped in links) which will be displayed on the right side of your modal header. Takes a block.
|
131
|
+
|
132
|
+
**`modalist_close`:** Renders a default modal close action. Can be passed to `modalist_actions`.
|
133
|
+
|
134
|
+
#### Example
|
135
|
+
|
136
|
+
```haml
|
137
|
+
- modalist_title 'Modal'
|
138
|
+
- modalist_subtitle 'Subtitle'
|
139
|
+
- modalist_actions do
|
140
|
+
= modalist_close
|
141
|
+
|
142
|
+
Content ...
|
143
|
+
```
|
144
|
+
|
145
|
+
### Trigger a modal
|
146
|
+
|
147
|
+
There are numerous ways to trigger/open a modal with Modalist.
|
148
|
+
|
149
|
+
One options is to open the modal by calling a JavaScript function - more on that [here](#functions).
|
150
|
+
|
151
|
+
#### Links
|
152
|
+
|
153
|
+
The most common scenario is using a link to trigger the opening of a modal:
|
154
|
+
|
155
|
+
```haml
|
156
|
+
= link_to 'Open modal', settings_modalist_url, class: 'modalist--trigger'
|
157
|
+
```
|
158
|
+
|
159
|
+
You can use [data attributes](#options) to pass options customizing the modal.
|
160
|
+
|
161
|
+
#### Forms
|
162
|
+
|
163
|
+
When you want to open a modal after submitting a form - this is as simple as it gets:
|
164
|
+
|
165
|
+
```haml
|
166
|
+
= simple_form_for @setting, settings_modalist_url(id: @setting.id), method: :get do |f|
|
167
|
+
-# ...
|
168
|
+
= f.input :submit, input_html: { class: 'modalist--trigger', data: { modalist_form: true } }
|
169
|
+
```
|
170
|
+
|
171
|
+
You can use [data attributes](#options) to pass options customizing the modal.
|
172
|
+
|
173
|
+
#### Elements
|
174
|
+
|
175
|
+
You can also trigger a modal from any other HTML element in your view:
|
176
|
+
|
177
|
+
```haml
|
178
|
+
.modalist--trigger{ data: { modalist_url: settings_modalist_url } }
|
179
|
+
```
|
180
|
+
|
181
|
+
You can use [data attributes](#options) to pass options customizing the modal.
|
182
|
+
|
183
|
+
### Modalist functions
|
184
|
+
|
185
|
+
Modalist's JavaScript component provides a set of functions to handle your modals:
|
186
|
+
|
187
|
+
#### Open modals
|
188
|
+
|
189
|
+
```js
|
190
|
+
Modalist.open({ url: 'http://localhost:3000/settings/modal' });
|
191
|
+
```
|
192
|
+
|
193
|
+
You can pass [options](#options) to customize the modal:
|
194
|
+
|
195
|
+
```js
|
196
|
+
Modalist.open({
|
197
|
+
url: 'http://localhost:3000/settings/modal',
|
198
|
+
form: false,
|
199
|
+
fullScreen: false
|
200
|
+
});
|
201
|
+
```
|
202
|
+
|
203
|
+
#### Close modals
|
204
|
+
|
205
|
+
```js
|
206
|
+
Modalist.close();
|
207
|
+
```
|
208
|
+
|
209
|
+
### Options
|
210
|
+
|
211
|
+
There are two sets of options you can pass to Modalist. Those who get passed on initialization and those who get passed on any subsequent calls of a function.
|
212
|
+
|
213
|
+
#### Initialization
|
214
|
+
|
215
|
+
**`ìziModal`:** Options hash utilized to initialize [iziModal](https://github.com/dolce/iziModal).
|
216
|
+
|
217
|
+
#### Subsequent calls
|
218
|
+
|
219
|
+
**`url`:** URL to fetch content of the modal from. Takes a string.
|
220
|
+
|
221
|
+
**`form`:** Submit a form and use the response to populate the modal. Takes a string to specify a jQuery selector for the form or `false`.
|
222
|
+
|
223
|
+
**`fullScreen`:** Show a full screen modal instead of the default windowed modal. Takes a 'true', `'mobile'` (uses a full screen modal on devices smaller than `800px`) or `false`.
|
224
|
+
|
225
|
+
### Styles
|
226
|
+
|
227
|
+
To customize the styles of your modals, require the vendored default styles and then override them with your custom CSS.
|
228
|
+
|
229
|
+
It is often useful to be able to provide view-specific styles. Modalist therefore adds classes for controller and action to the `.modalist--content` element which wraps your modals content. Here is how you can utilize it:
|
230
|
+
|
231
|
+
```css
|
232
|
+
/* settings#modalist */
|
233
|
+
.modalist--content.settings.modalist {
|
234
|
+
/* ... */
|
235
|
+
}
|
236
|
+
/* nested/settings#modalist */
|
237
|
+
.modalist--content.nested.settings.modalist {
|
238
|
+
/* ... */
|
239
|
+
}
|
240
|
+
```
|
241
|
+
|
242
|
+
### Events
|
243
|
+
|
244
|
+
Modalist emits events that allow you to track the navigation lifecycle and respond to content loading. Modalist fires events on the `$(document)` object.
|
245
|
+
|
246
|
+
* `modalist:click` fires when you click a Modal enabled link to trigger a modal opening. The clicked element is the event target. Access the requested location with `event.data.url`.
|
247
|
+
|
248
|
+
* `modalist:request-start` fires before Modal issues a network request to fetch the modal content.
|
249
|
+
|
250
|
+
* `modalist:request-end` fires after the network request completes.
|
251
|
+
|
252
|
+
* `modalist:before-render` fires before rendering the content.
|
253
|
+
|
254
|
+
* `modalist:render` fires after Modal renders the content in the modal.
|
255
|
+
|
256
|
+
* `modalist:load` fires after Modal completed preparing and opened the modal.
|
257
|
+
|
258
|
+
---
|
259
|
+
|
260
|
+
## To Do
|
261
|
+
|
262
|
+
[Here](https://github.com/jonhue/modalist/projects/1) is the full list of current projects.
|
263
|
+
|
264
|
+
To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/modalist/issues/new).
|
265
|
+
|
266
|
+
---
|
267
|
+
|
268
|
+
## Contributing
|
269
|
+
|
270
|
+
We hope that you will consider contributing to Modalist. Please read this short overview for some information about how to get started:
|
271
|
+
|
272
|
+
[Learn more about contributing to this repository](CONTRIBUTING.md), [Code of Conduct](CODE_OF_CONDUCT.md)
|
273
|
+
|
274
|
+
### Contributors
|
275
|
+
|
276
|
+
Give the people some :heart: who are working on this project. See them all at:
|
277
|
+
|
278
|
+
https://github.com/jonhue/modalist/graphs/contributors
|
279
|
+
|
280
|
+
## License
|
281
|
+
|
282
|
+
MIT License
|
283
|
+
|
284
|
+
Copyright (c) 2017 Jonas Hübotter
|
285
|
+
|
286
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
287
|
+
of this software and associated documentation files (the "Software"), to deal
|
288
|
+
in the Software without restriction, including without limitation the rights
|
289
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
290
|
+
copies of the Software, and to permit persons to whom the Software is
|
291
|
+
furnished to do so, subject to the following conditions:
|
292
|
+
|
293
|
+
The above copyright notice and this permission notice shall be included in all
|
294
|
+
copies or substantial portions of the Software.
|
295
|
+
|
296
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
297
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
298
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
299
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
300
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
301
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
302
|
+
SOFTWARE.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Modalist
|
2
|
+
module ModalHelper
|
3
|
+
|
4
|
+
def modalist
|
5
|
+
render 'modalist/modal'
|
6
|
+
end
|
7
|
+
|
8
|
+
def modalist_close
|
9
|
+
render 'modalist/close'
|
10
|
+
end
|
11
|
+
|
12
|
+
def modalist_title title
|
13
|
+
area :modalist_title, title
|
14
|
+
end
|
15
|
+
|
16
|
+
def modalist_subtitle subtitle
|
17
|
+
area :modalist_subtitle, subtitle
|
18
|
+
end
|
19
|
+
|
20
|
+
def modalist_actions &block
|
21
|
+
area :modalist_actions, capture(&block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def modalist_class_hierarchy options = [], delimiter = ' '
|
25
|
+
options.map(&:inspect).join(delimiter).gsub('"', '').gsub(',', '').gsub('[', '').gsub(']', '')
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<% if area(:modalist_title).length > 0 %>
|
2
|
+
<div class="modalist--header">
|
3
|
+
<div class="wrapper">
|
4
|
+
<h4><%= area :modalist_title %></h4>
|
5
|
+
<% if area(:modalist_subtitle).length > 0 %>
|
6
|
+
<p>
|
7
|
+
<%= area :modalist_subtitle %>
|
8
|
+
</p>
|
9
|
+
<% end %>
|
10
|
+
</div>
|
11
|
+
<div class="wrapper">
|
12
|
+
<%= area :modalist_actions %>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<div class="modalist--content <%= modalist_class_hierarchy( [params[:controller].split('/').each { |n| n }, action_name] %>">
|
18
|
+
<%= yield %>
|
19
|
+
</div>
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<%= link_to 'javascript:void(0)', class: 'modalist--close', data: { izimodal_close: true } do %>
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="24px" height="24px" viewBox="0 0 24 24"><g stroke-width="2" transform="translate(0, 0)"><line fill="none" stroke="#657786" stroke-width="2" stroke-linecap="square" stroke-miterlimit="10" x1="16" y1="8" x2="8" y2="16" stroke-linejoin="miter"></line>
|
3
|
+
<line fill="none" stroke="#657786" stroke-width="2" stroke-linecap="square" stroke-miterlimit="10" x1="16" y1="16" x2="8" y2="8" stroke-linejoin="miter"></line></g></svg>
|
4
|
+
<% end %>
|