lazy_modal 0.1.3 → 0.1.4
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 +4 -4
- data/README.md +38 -13
- data/app/controllers/lazy_modal/lazy_modals_controller.rb +3 -4
- data/lib/generators/lazy_modal/install_generator.rb +4 -25
- data/lib/generators/lazy_modal/templates/lazy_modal.css +3 -0
- data/lib/generators/lazy_modal/templates/lazy_modal.js +1 -0
- data/lib/lazy_modal.rb +3 -1
- data/lib/lazy_modal/version.rb +1 -1
- metadata +16 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b136a3190216a47c109c379d724223487c53f7b8
|
4
|
+
data.tar.gz: 242e8c18b2128afcbd3c6384c747a5a1e181f775
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fcca39d85e18fcf0b9cc3ab412861db3b4beff2b9d0f71a7e2053496b47c8a21f358d25b6067e8f9fe13de0e8b0ead509e158a9adb37367c396d0671f4b48c0
|
7
|
+
data.tar.gz: '08d62b92c68ea89e3baf673ea174f57fd1fa68f954300b1f783801ece115f32b9804a3031ec64945808133f2ce78c72a1ee31d79be4dbc803186aefea96cbceb'
|
data/README.md
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
-
#
|
1
|
+
# Overview
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
**Lazy_modal** support load bs modal from remote.
|
4
|
+
normally before use bs modal you should defined modal dom in **erb** file.
|
5
5
|
|
6
|
-
|
6
|
+
If you want to show modal from remote. **lazy_modal** can help you.
|
7
|
+
|
8
|
+
**lazy_modal** best pratice is: you want to show modal when you need but you don't want to defined in **erb** file every time render.
|
9
|
+
|
10
|
+
Like this:
|
11
|
+
|
12
|
+
### Before
|
7
13
|
app/views/profile/charges.erb
|
8
14
|
|
9
15
|
``` html
|
@@ -26,12 +32,13 @@ app/views/profile/charges.erb
|
|
26
32
|
</div>
|
27
33
|
```
|
28
34
|
|
29
|
-
So you must render **modal-dom, modal-dom2, modal-dom3**
|
30
|
-
|
35
|
+
So you must render **modal-dom, modal-dom2, modal-dom3** and **link_to** in same file **app/views/profile/charges.erb** before use it.
|
36
|
+
|
37
|
+
Every time you reload this page will render **modal-dom, modal-dom2, modal-dom3** and even **modal-dom3** use in less time. so well can just move **modal-dom3** to remote file. and use **lazy_modal** load it!
|
31
38
|
|
32
39
|
Now you can use **lazy_modal** lazy load modal when we need it!
|
33
40
|
|
34
|
-
|
41
|
+
### After
|
35
42
|
app/views/profile/charges.erb
|
36
43
|
|
37
44
|
```html
|
@@ -43,20 +50,18 @@ app/views/profile/charges.erb
|
|
43
50
|
app/views/profile/charge_modal.erb
|
44
51
|
|
45
52
|
```html
|
46
|
-
#modal-
|
53
|
+
#modal-dom3
|
47
54
|
<div class='modal fade' id='charge_modal'>
|
48
55
|
modal content ...
|
49
56
|
</div>
|
50
57
|
```
|
51
58
|
|
52
|
-
You can found out difference? yes we split **link_to** and **modal-
|
59
|
+
You can found out difference? yes we split **link_to** and **modal-dom3** to different file. So that we can show modal when we need it.
|
53
60
|
|
54
|
-
It's us use **lazy_modal**
|
55
61
|
|
56
|
-
|
57
|
-
Use **lazy-modal** is simplest! follow this steps:
|
62
|
+
### Install
|
58
63
|
|
59
|
-
|
64
|
+
Use **lazy-modal** every simple, add this line to your rails application's Gemfile:
|
60
65
|
|
61
66
|
```ruby
|
62
67
|
gem 'lazy_modal'
|
@@ -102,6 +107,26 @@ title | string | **optional**,before load remote modal, you will see simple
|
|
102
107
|
size | string | **optional**,before load remote modal, you will see simple load modal with placeholder, so the options set the modal-content with custom class like: `modal-sm|modal-lg`
|
103
108
|
|
104
109
|
|
110
|
+
## JS Events
|
111
|
+
|
112
|
+
you can listen lazy_modal load completed events. lazy_modal will trigger **lm.modal.content.loaded** if remote modal loaded and append to html **body**
|
113
|
+
|
114
|
+
```javascript
|
115
|
+
|
116
|
+
//delegate event to document
|
117
|
+
$(document).on("lm.modal.content.loaded", "#remote_modal_id", function(){
|
118
|
+
// your logic
|
119
|
+
console.log('remote modal load completed')
|
120
|
+
})
|
121
|
+
|
122
|
+
//listen to lazy_modal instance
|
123
|
+
lazyModal = LM.loadRemoteModalByID('remote_modal_id',{dir: 'profile'})
|
124
|
+
lazyModal.on('lm.modal.content.loaded', function(modalOptions){
|
125
|
+
console.log(modalOptions)
|
126
|
+
})
|
127
|
+
|
128
|
+
```
|
129
|
+
**PS: LM.MODAL_CONTENT_LOADED == 'lm.modal.content.loaded'**
|
105
130
|
|
106
131
|
## License
|
107
132
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module LazyModal
|
2
|
-
class LazyModalsController <
|
3
|
-
protect_from_forgery
|
4
|
-
helper Rails.application.helpers
|
2
|
+
class LazyModalsController < LazyModal.modal_parent_controller.constantize
|
3
|
+
protect_from_forgery
|
5
4
|
|
6
5
|
rescue_from ActionView::MissingTemplate do
|
7
|
-
render plain: 'modal missing', status: :not_found
|
6
|
+
render plain: 'modal missing, your modal dirs right?', status: :not_found
|
8
7
|
end
|
9
8
|
|
10
9
|
def show
|
@@ -1,33 +1,12 @@
|
|
1
1
|
module LazyModal
|
2
2
|
class InstallGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
4
|
|
4
5
|
desc 'install lazy modal'
|
5
6
|
def install
|
6
|
-
route
|
7
|
-
|
8
|
-
|
9
|
-
def inject_js_asset_file
|
10
|
-
%w(js coffee).each do |ext|
|
11
|
-
dest_file_path = "app/assets/javascripts/application.#{ext}"
|
12
|
-
if File.exist? "#{destination_root}/#{dest_file_path}"
|
13
|
-
insert_into_file dest_file_path, :before => "//= require_tree" do
|
14
|
-
"//= require lazy_modal/application\n"
|
15
|
-
end
|
16
|
-
break
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def inject_css_asset_file
|
22
|
-
%w(css scss sass).each do |ext|
|
23
|
-
dest_file_path = "app/assets/stylesheets/application.#{ext}"
|
24
|
-
if File.exist? "#{destination_root}/#{dest_file_path}"
|
25
|
-
insert_into_file dest_file_path, :before => "*= require_self" do
|
26
|
-
"*= require lazy_modal/application\n"
|
27
|
-
end
|
28
|
-
break
|
29
|
-
end
|
30
|
-
end
|
7
|
+
route "mount LazyModal::Engine => '/'"
|
8
|
+
copy_file 'lazy_modal.js', 'app/assets/javascripts/lazy_modal.js'
|
9
|
+
copy_file 'lazy_modal.css', 'app/assets/stylesheets/lazy_modal.css'
|
31
10
|
end
|
32
11
|
|
33
12
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
//=require lazy_modal/application
|
data/lib/lazy_modal.rb
CHANGED
data/lib/lazy_modal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy_modal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MixBo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -28,30 +28,30 @@ dependencies:
|
|
28
28
|
name: jquery-rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '4'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: coffee-rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '4'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '4'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bootstrap-sass
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: sass-rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '5'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '5'
|
83
83
|
description: lazy load bootstrap modal when needed!
|
84
84
|
email:
|
85
85
|
- lb563@foxmail.com
|
@@ -96,6 +96,8 @@ files:
|
|
96
96
|
- app/views/lazy_modal/modals/demo.erb
|
97
97
|
- config/routes.rb
|
98
98
|
- lib/generators/lazy_modal/install_generator.rb
|
99
|
+
- lib/generators/lazy_modal/templates/lazy_modal.css
|
100
|
+
- lib/generators/lazy_modal/templates/lazy_modal.js
|
99
101
|
- lib/lazy_modal.rb
|
100
102
|
- lib/lazy_modal/engine.rb
|
101
103
|
- lib/lazy_modal/version.rb
|