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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 761ede6762db2ce4c45ba67b824d9e42b35c342a
4
- data.tar.gz: fe33d8158a26acc5859bfa25838e91b70ec0ae62
3
+ metadata.gz: b136a3190216a47c109c379d724223487c53f7b8
4
+ data.tar.gz: 242e8c18b2128afcbd3c6384c747a5a1e181f775
5
5
  SHA512:
6
- metadata.gz: e22bf638afb91c073843b5ea06a7d04f95907589b82a0b783a3d32c33b97f8ab77f974279f72125a09477707594215816a60469d9f7340f728d58f10072c2c57
7
- data.tar.gz: 94aff4f9609d041949d12a01c484ec4a50f6706042d068632c0eb4d4fc4c1677570366390c37ebeac381df54978a422401bc229ea43ca68526f2a1ede21e2bbf
6
+ metadata.gz: 0fcca39d85e18fcf0b9cc3ab412861db3b4beff2b9d0f71a7e2053496b47c8a21f358d25b6067e8f9fe13de0e8b0ead509e158a9adb37367c396d0671f4b48c0
7
+ data.tar.gz: '08d62b92c68ea89e3baf673ea174f57fd1fa68f954300b1f783801ece115f32b9804a3031ec64945808133f2ce78c72a1ee31d79be4dbc803186aefea96cbceb'
data/README.md CHANGED
@@ -1,9 +1,15 @@
1
- # lazy-modal
1
+ # Overview
2
2
 
3
- Show **bootstrap** modal with lazy load. sometimes we have too many modals in html body. and you know always some modal not need rendered. the best pratice to show modal i think is lazy load modal. **bootstrap** modal plugin provide remote away the load modal content when needed.
4
- this gem provide way load **bootstrap** modal from remote server. so that we can load the modal when needed it. it's start!
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
- ## Before
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** with **link_to** in same place.
30
- sometimes we have mulitple modals and even some modal have much childrens dom. also maybe some modals no need at the same time like:(**modal-dom2, modal-dom3**).
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
- ## After
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-dom
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-dom** to different file. So that we can show modal when we need it.
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
- ## Usage
57
- Use **lazy-modal** is simplest! follow this steps:
62
+ ### Install
58
63
 
59
- Add this line to your rails application's Gemfile:
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 < ActionController::Base
3
- protect_from_forgery with: :exception
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("mount LazyModal::Engine => '/'")
7
- end
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,3 @@
1
+ /*
2
+ *=require lazy_modal/application
3
+ */
@@ -0,0 +1 @@
1
+ //=require lazy_modal/application
@@ -1,5 +1,7 @@
1
1
  require "lazy_modal/engine"
2
2
 
3
3
  module LazyModal
4
- # Your code goes here...
4
+
5
+ mattr_accessor :modal_parent_controller
6
+ @@modal_parent_controller = 'ApplicationController'
5
7
  end
@@ -1,3 +1,3 @@
1
1
  module LazyModal
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
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.3
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-16 00:00:00.000000000 Z
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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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