dismissible_blocks 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -11
- data/app/assets/javascripts/dismissible_blocks.js +35 -32
- data/app/assets/javascripts/dismissible_blocks_loader.js +7 -3
- data/app/controllers/dismissible_blocks_controller.rb +8 -2
- data/config/routes.rb +1 -1
- data/dismissible_blocks.gemspec +2 -1
- data/lib/dismissible_blocks/version.rb +1 -1
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 145a0ac22b989d3f165280b7203087d2bc6b5c1b434eceb0875f38b282136134
|
4
|
+
data.tar.gz: 146bec7c1c582eef33bb4367698459dd5e2bfba3ce811ddb9f0766ce5a74f109
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6816d384f8175983ce60b20463ce1c2ab428661d8ebb3f27173ce6be4341e2eb8a4a3adeef0d14ff88f4289b4c66f08e61d8e708dd4e53eac2795e3c0145ddf
|
7
|
+
data.tar.gz: d5d4f21dca16061981216bafccd73e329ec76b5472d940e0cad37872f0dd490fd4ef82af25bf0e033f196fe1fa68263f9de5e350a46005173f2e485ac814e008
|
data/README.md
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
## Overview
|
4
4
|
[DismissibleBlocks](https://github.com/pbougie/dismissible_blocks) is a simple gem for [Ruby on Rails](http://rubyonrails.org/) projects to add blocks of content to a webpage that can be dismissed by the user. Dismissed blocks are remembered and persisted to the database using [Ajax](https://en.wikipedia.org/wiki/Ajax_%28programming%29). DismissibleBlocks is ORM agnostic and works with MySQL, PostgreSQL, MongoDB, etc.
|
5
5
|
|
6
|
+
> **WARNING:** DismissibleBlocks 2+ removed jQuery as a dependency. If you are not using the loader, you will have to make changes to your code. See examples below.
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
### Requirements
|
9
|
-
The DismissibleBlocks gem has the following
|
10
|
+
The DismissibleBlocks gem has the following requirement:
|
10
11
|
|
11
12
|
- [Ruby on Rails](http://rubyonrails.org/) 3.2 or above
|
12
|
-
- [jQuery](http://jquery.com/)
|
13
13
|
|
14
14
|
### Gemfile
|
15
15
|
Add the following line to your application's Gemfile:
|
@@ -35,23 +35,25 @@ Add the following JavaScript to `app/assets/javascripts/application.js`.
|
|
35
35
|
|
36
36
|
In its simplest form, you can require all the needed JavaScript using:
|
37
37
|
|
38
|
-
//= require jquery
|
39
38
|
//= require dismissible_blocks
|
40
39
|
//= require dismissible_blocks_loader
|
41
40
|
|
42
41
|
If you want to customize how a block of HTML is hidden using — for example — a slide up effect, you can customize the JavaScript like so:
|
43
42
|
|
44
|
-
//= require jquery
|
45
43
|
//= require dismissible_blocks
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
|
45
|
+
document.addEventListener('DOMContentLoaded', function() {
|
46
|
+
document.querySelectorAll('[data-dismissible]').dismissible({
|
49
47
|
dismiss: function(helper) {
|
50
|
-
helper.slideUp()
|
48
|
+
helper.slideUp().then(function(el) {
|
49
|
+
el.remove();
|
50
|
+
});
|
51
51
|
}
|
52
52
|
});
|
53
53
|
});
|
54
54
|
|
55
|
+
**Note:** The above example is using the `slideUp()` method from the [dom-slider](https://github.com/BrentonCozby/dom-slider) JavaScript library by Brenton Cozby.
|
56
|
+
|
55
57
|
### Helper
|
56
58
|
DismissibleBlocks uses the `current_user` helper method to access the current user/account. Make sure the helper method is also available in your views:
|
57
59
|
|
@@ -59,7 +61,7 @@ DismissibleBlocks uses the `current_user` helper method to access the current us
|
|
59
61
|
...
|
60
62
|
end
|
61
63
|
helper_method :current_user
|
62
|
-
|
64
|
+
|
63
65
|
By default, DismissibleBlocks saves the state to the database using the `current_user` helper method. If your user/account helper method is named something else — for example `current_employee`:
|
64
66
|
|
65
67
|
def current_employee
|
@@ -83,7 +85,7 @@ ActiveRecord's serialization feature can achieve this. First, create a database
|
|
83
85
|
def up
|
84
86
|
add_column :users, :dismissed_blocks, :text
|
85
87
|
end
|
86
|
-
|
88
|
+
|
87
89
|
def down
|
88
90
|
remove_column :users, :dismissed_blocks
|
89
91
|
end
|
@@ -102,7 +104,7 @@ If you are using [PostgreSQL](http://www.postgresql.org/) with native array supp
|
|
102
104
|
def up
|
103
105
|
add_column :users, :dismissed_blocks, :string, :array => true
|
104
106
|
end
|
105
|
-
|
107
|
+
|
106
108
|
def down
|
107
109
|
remove_column :users, :dismissed_blocks
|
108
110
|
end
|
@@ -1,37 +1,40 @@
|
|
1
1
|
(function() {
|
2
|
-
(function($) {
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
NodeList.prototype.dismissible = function(options) {
|
4
|
+
this.forEach(function(el) {
|
5
|
+
el.dismissible(options);
|
6
|
+
});
|
7
|
+
}
|
8
|
+
|
9
|
+
HTMLElement.prototype.dismissible = function(options) {
|
10
|
+
this.querySelector('[data-dismissible-hide]').addEventListener('click', function(event) {
|
11
|
+
event.preventDefault();
|
12
|
+
this.dismiss(options);
|
13
|
+
});
|
14
|
+
}
|
15
|
+
|
16
|
+
HTMLElement.prototype.dismiss = function(options) {
|
17
|
+
var block_name = this.getAttribute('data-dismissible-hide');
|
18
|
+
var block = document.querySelector('[data-dismissible=' + block_name + ']');
|
19
|
+
var csrf = document.querySelector('meta[name=csrf-token]');
|
20
|
+
var token = csrf != null ? csrf.getAttribute('content') : null;
|
21
|
+
var xhr = new XMLHttpRequest();
|
13
22
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
block
|
22
|
-
|
23
|
-
|
24
|
-
success: (function(_this) {
|
25
|
-
return function() {
|
26
|
-
if ((options != null) && options.dismiss !== void 0) {
|
27
|
-
return options.dismiss(_this);
|
28
|
-
} else {
|
29
|
-
return $(_this).remove();
|
30
|
-
}
|
31
|
-
}
|
32
|
-
})(this)
|
33
|
-
});
|
23
|
+
xhr.open('PUT', '/dismissible_blocks.json');
|
24
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
25
|
+
xhr.onload = function() {
|
26
|
+
if (xhr.status === 200) {
|
27
|
+
if (options !== undefined && options.dismiss !== undefined) {
|
28
|
+
return options.dismiss(block);
|
29
|
+
} else {
|
30
|
+
return block.remove();
|
31
|
+
}
|
32
|
+
}
|
34
33
|
};
|
34
|
+
xhr.send(JSON.stringify({
|
35
|
+
block: block_name,
|
36
|
+
authenticity_token: token
|
37
|
+
}));
|
38
|
+
}
|
35
39
|
|
36
|
-
|
37
|
-
}).call(this);
|
40
|
+
})();
|
@@ -1,8 +1,10 @@
|
|
1
1
|
class DismissibleBlocksController < ApplicationController
|
2
2
|
def create
|
3
3
|
if current_user_available
|
4
|
-
current_user.dismissed_blocks
|
5
|
-
|
4
|
+
unless current_user.dismissed_blocks.include?(block)
|
5
|
+
current_user.dismissed_blocks.push(block)
|
6
|
+
current_user.save!
|
7
|
+
end
|
6
8
|
render json: {}, status: :ok
|
7
9
|
else
|
8
10
|
render json: {}, status: :unprocessable_entity
|
@@ -14,4 +16,8 @@ class DismissibleBlocksController < ApplicationController
|
|
14
16
|
def current_user_available
|
15
17
|
respond_to?(:current_user) && current_user.respond_to?(:dismissed_blocks)
|
16
18
|
end
|
19
|
+
|
20
|
+
def block
|
21
|
+
params[:block].to_s
|
22
|
+
end
|
17
23
|
end
|
data/config/routes.rb
CHANGED
data/dismissible_blocks.gemspec
CHANGED
@@ -20,8 +20,9 @@ Gem::Specification.new do |s|
|
|
20
20
|
'LICENSE.txt'
|
21
21
|
]
|
22
22
|
|
23
|
+
s.post_install_message = 'DismissibleBlocks 2+ removed jQuery as a dependency. See README.'
|
24
|
+
|
23
25
|
s.add_runtime_dependency 'rails', '>= 3.2'
|
24
|
-
s.add_runtime_dependency 'jquery-rails'
|
25
26
|
|
26
27
|
s.add_development_dependency 'bundler'
|
27
28
|
s.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dismissible_blocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Bougie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.2'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: jquery-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
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -160,7 +146,7 @@ homepage: https://github.com/pbougie/dismissible_blocks
|
|
160
146
|
licenses:
|
161
147
|
- MIT
|
162
148
|
metadata: {}
|
163
|
-
post_install_message:
|
149
|
+
post_install_message: DismissibleBlocks 2+ removed jQuery as a dependency. See README.
|
164
150
|
rdoc_options: []
|
165
151
|
require_paths:
|
166
152
|
- lib
|