navbar_highlighter 0.2.1 → 0.3.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 +4 -0
- data/lib/navbar_highlighter/helper.rb +6 -0
- data/lib/navbar_highlighter/version.rb +1 -1
- data/vendor/assets/javascripts/navbar_highlighter.js +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26e9b3dc30f4c312af686a0da61e5cb5ce1a47b3
|
4
|
+
data.tar.gz: 22cef1cf299b5755891c80e81b58ef0d32dcfe57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83a9b2d6a655667120b23fb4fd599d6dc8eb8d58f378bdf9b1312a3253d80c6e696488b1f2f0f721f569c2225b7ab79c8dfdce78fd88c3e2310e40826da5d4bf
|
7
|
+
data.tar.gz: 86306988a1b31d94c8067a595be46c630843743330fa3b746915e518f2505fdffee2798beaae7f4f821e0aaed65c2ee4e443386169a15b0e9e916e125b7f6bf1
|
data/README.md
CHANGED
@@ -68,9 +68,13 @@ Add`<%= navbar_highlighter_tags %>` to any layout that you are using.
|
|
68
68
|
**Note:**
|
69
69
|
|
70
70
|
As user hits `sessions_controller` `index` action `Home` link will be active, and when user clicks `Users` link `Users` link will be get `active-link` class.
|
71
|
+
|
71
72
|
# New feature
|
73
|
+
|
72
74
|
Adding a `data-parent='controller_name'` to link will add class to parent link as well as the child link.
|
73
75
|
|
76
|
+
Different un-related links can be highlighted using `data-highlight-on=<%= current_url %>`. This can be useful when you want to highlight links based on current url.
|
77
|
+
|
74
78
|
## Contributing
|
75
79
|
|
76
80
|
Bug reports and pull requests are welcome on GitHub at https://github.com/abhikanojia/navbar_highlighter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
@@ -4,8 +4,14 @@ module Helper
|
|
4
4
|
str.concat("<meta name='controller' content='#{controller_name}'>")
|
5
5
|
str.concat("\n")
|
6
6
|
str.concat("<meta name='action' content='#{action_name}'>")
|
7
|
+
str.concat("\n")
|
8
|
+
str.concat("<meta name='current_url' content='#{request.original_url}'>")
|
7
9
|
end.html_safe
|
8
10
|
end
|
11
|
+
|
12
|
+
def current_url
|
13
|
+
request.original_url
|
14
|
+
end
|
9
15
|
end
|
10
16
|
|
11
17
|
ActionView::Base.send :include, Helper
|
@@ -4,6 +4,7 @@ function NavbarHighlighter(data) {
|
|
4
4
|
this.classNameToAdd = data.classNameToAdd;
|
5
5
|
this.actionName = $('meta[name=action]').attr('content');
|
6
6
|
this.controllerName = $('meta[name=controller]').attr('content');
|
7
|
+
this.currentUrl = $('meta[name=current_url]').attr('content');
|
7
8
|
}
|
8
9
|
|
9
10
|
NavbarHighlighter.prototype.getControllerSelector = function(selector) {
|
@@ -18,6 +19,10 @@ NavbarHighlighter.prototype.getActionSelector = function() {
|
|
18
19
|
return '[data-action=' + this.actionName + ']';
|
19
20
|
};
|
20
21
|
|
22
|
+
NavbarHighlighter.prototype.getUrlSelector = function() {
|
23
|
+
return "[data-highlight-on='" + this.currentUrl + "']";
|
24
|
+
};
|
25
|
+
|
21
26
|
NavbarHighlighter.prototype.classSelector = function(className) {
|
22
27
|
return '.' + className;
|
23
28
|
};
|
@@ -29,6 +34,10 @@ NavbarHighlighter.prototype.highlightParentIfExist = function(element) {
|
|
29
34
|
}
|
30
35
|
};
|
31
36
|
|
37
|
+
NavbarHighlighter.prototype.highlightUrlSpecificLinks = function() {
|
38
|
+
$(this.getUrlSelector()).addClass(this.classNameToAdd);
|
39
|
+
};
|
40
|
+
|
32
41
|
NavbarHighlighter.prototype.init = function() {
|
33
42
|
|
34
43
|
this.navBar.find(
|
@@ -43,5 +52,7 @@ NavbarHighlighter.prototype.init = function() {
|
|
43
52
|
|
44
53
|
this.highlightParentIfExist(element);
|
45
54
|
|
55
|
+
this.highlightUrlSpecificLinks();
|
56
|
+
|
46
57
|
};
|
47
58
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: navbar_highlighter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abhishek Kanojia
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jquery-rails
|