awesome_tooltip 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee17f8477a6ae94f8d6f7011f2133cbd58f0a33663f28bc3010792a6e826b735
4
- data.tar.gz: f80d0cf419a9d75ff5cf8be288b957d1bf49d9a23f08bdca0e2d9b68a0cf583c
3
+ metadata.gz: 0f032dee2c48043e724be7173e3f7ba3e11a7ed7597939b343dc96b4a2e3a632
4
+ data.tar.gz: 426a4d6bc6980fe95c2c8d80eeb04a0387438cfdb1aad6e1135c5bd19a93eeb4
5
5
  SHA512:
6
- metadata.gz: 71bba3c47aa1b1dcd60328d19014feb26d0372324b9ad142eaf5974d228da0e971be35fc44c011b3fdf95aef5103ef2c52ea65beb03b6507682ddf5c76f8085f
7
- data.tar.gz: b873d5a38d29cb132daab27187b6a0e20023ba52ac65650342b433c98b678087c0d801db4e3f8cac61eb6307f08efef94d1de24f4608a2deb91b7efb31ab7ea8
6
+ metadata.gz: 8fd64bd6850dfa6fd2f53872ce57f7a8e8257d1f4d0be09243f7abd8bab48422f8ec45543665150e892d4b614a3697b54f1476aa9978f7dacbf438361f9485fc
7
+ data.tar.gz: 8eada3a339bbab7e8b33279c3ec6af6c6ed3b7a4d79b72c32a1cf8f004697ecb9c72bd296bd9f388b239932f873a4a5c81fdddf17de440a0f25a8a69879f3dc4
data/README.md CHANGED
@@ -2,10 +2,7 @@
2
2
  [![Build Status](https://travis-ci.com/BogdanBusko/awesome_tooltip.svg?branch=master)](https://travis-ci.com/BogdanBusko/awesome_tooltip)
3
3
  [![Maintainability](https://api.codeclimate.com/v1/badges/13a8f6106b17b50e9943/maintainability)](https://codeclimate.com/github/BogdanBusko/awesome_tooltip/maintainability)
4
4
 
5
- Short description and motivation.
6
-
7
- ## Usage
8
- How to use my plugin.
5
+ Lightwere get for loading tooltips on your page without preloading this data on page. With this gem you can load static template and templates with data from database.
9
6
 
10
7
  ## Installation
11
8
  Add this line to your application's Gemfile:
@@ -24,6 +21,60 @@ Or install it yourself as:
24
21
  $ gem install awesome_tooltip
25
22
  ```
26
23
 
24
+ ## Configuration
25
+
26
+ Mount AwesomeTooltip routes in to your config/routes.rb
27
+ ```ruby
28
+ mount AwesomeTooltip::Engine => '/', as: 'awesome_tooltip'
29
+ ```
30
+
31
+ Require AwesomeTooltip javascript in to your application.js
32
+ ```javascript
33
+ //= require awesome_tooltip/tootlip
34
+ ```
35
+
36
+ If you are using Rails 6 with webpack you must create folder javascripts with file application.js in your assets folder and require javascript there.
37
+
38
+ Require AwesomeTooltip styles
39
+ ```css
40
+ /*
41
+ *= require awesome_tooltip/tooltip
42
+ */
43
+ ```
44
+
45
+ Create folder for you tooltip templates
46
+ ```bash
47
+ $ mkdir app/awesome_tooltips
48
+ ```
49
+
50
+ And now just add template.
51
+ ```bash
52
+ $ touch app/awesome_tooltips/template.html.erb
53
+ ```
54
+
55
+ ## Usage
56
+
57
+ To start using AwesomeTooltip add following attributes to HTML element
58
+ ```html
59
+ <div class="awesome_tooltip"
60
+ data-template="user_template"
61
+ data-object="user-1"
62
+ data-loacation="bottom">John Doe</div>
63
+ ```
64
+
65
+ Also you can use static templates
66
+
67
+ | Option | Description | Value example | Optional |
68
+ |--------|-------------|---------------|----------|
69
+ | data-template | Path to your template(root dir for template is app/awesome_tooltips) | project | false |
70
+ | data-object | Model name and object id separated by dash | project-1 | true |
71
+ | data-location | Tooltip location | bottom | true |
72
+
73
+ ## TODO:
74
+ - Add generators
75
+ - Add configs
76
+ - Add ability to place tooltip on the left and right side
77
+
27
78
  ## Contributing
28
79
  Contribution directions go here.
29
80
 
@@ -1,6 +1,7 @@
1
1
  (function (W, D) {
2
2
  var loadType;
3
- var timerId;
3
+ var hideDelayTimeId;
4
+ var showDelayTimeId;
4
5
  var config = {
5
6
  tooltipPath: "/tooltip/",
6
7
  delay: 1500,
@@ -15,21 +16,29 @@
15
16
 
16
17
  function handleMouseEnter(element) {
17
18
  element.addEventListener("mouseenter", function(e) {
18
- clearTimeout(timerId);
19
+ var element = e.currentTarget;
19
20
 
20
- if(e.currentTarget.getAttribute("data-template") && !e.currentTarget.querySelector(".awesome-tooltip")) {
21
- fetchData(e.currentTarget);
22
- }
21
+ clearTimeout(hideDelayTimeId);
22
+
23
+ showDelayTimeId = setTimeout(function() {
24
+ if(element.getAttribute("data-template") && !element.querySelector(".awesome-tooltip")) {
25
+ fetchData(element);
26
+ }
27
+ }, 500);
23
28
  });
24
29
  }
25
30
 
26
31
  function handleMouseLeave(element) {
27
32
  element.addEventListener("mouseleave", function(e){
28
- var tooltip = e.currentTarget.querySelector("." + e.currentTarget.className.split(" ").join(".") + " .awesome-tooltip");
33
+ var element = e.currentTarget;
34
+ var tooltip = element.querySelector("." + element.className.split(" ").join(".") + " .awesome-tooltip");
29
35
 
30
- timerId = setTimeout(function() {
31
- if(tooltip)
36
+ clearTimeout(showDelayTimeId);
37
+
38
+ hideDelayTimeId = setTimeout(function() {
39
+ if(tooltip) {
32
40
  tooltip.remove();
41
+ }
33
42
  }, config.delay);
34
43
  });
35
44
  }
@@ -39,10 +48,14 @@
39
48
  var tooltipTriangle = tooltip.querySelector(".content-wrapper .triangle");
40
49
  var elementRects = element.getClientRects()[0];
41
50
 
42
- var leftEnoughSpace = tooltip.offsetWidth / 2 + element.offsetWidth / 2 < elementRects.left;
43
- var rightEnoughSpace = tooltip.offsetWidth / 2 < D.body.offsetWidth - elementRects.right;
44
- var bottomEnoughSpace = tooltip.offsetHeight < W.outerHeight - elementRects.bottom;
45
- var topEnoughSpace = tooltip.offsetHeight + tooltipTriangle.offsetHeight < elementRects.top;
51
+ var tHeight = tooltip.offsetHeight;
52
+ var tWidth = tooltip.offsetWidth;
53
+ var eWidth = element.offsetWidth;
54
+
55
+ var leftEnoughSpace = tWidth / 2 + eWidth / 2 < elementRects.left;
56
+ var rightEnoughSpace = tWidth / 2 < D.body.offsetWidth - elementRects.right;
57
+ var bottomEnoughSpace = tHeight < W.outerHeight - elementRects.bottom;
58
+ var topEnoughSpace = tHeight + tooltipTriangle.offsetHeight < elementRects.top;
46
59
 
47
60
  if(leftEnoughSpace && rightEnoughSpace && topEnoughSpace && bottomEnoughSpace) {
48
61
  tooltip.style.cssText = "left: " + ((elementRects.width / 2) - (tooltip.getClientRects()[0].width / 2)) + "px;";
@@ -71,8 +84,8 @@
71
84
 
72
85
  if(!leftEnoughSpace || !rightEnoughSpace) {
73
86
  if(W.innerWidth / 2 > elementRects.right) {
74
- tooltip.style.cssText = "left: -" + (elementRects.right - element.offsetWidth) + "px;";
75
- tooltipTriangle.style.cssText = "left: " + (elementRects.right - element.offsetWidth + tooltipTriangle.offsetWidth + tooltipTriangle.offsetWidth / 2) + "px;";
87
+ tooltip.style.cssText = "left: -" + (elementRects.right - eWidth) + "px;";
88
+ tooltipTriangle.style.cssText = "left: " + (elementRects.right - eWidth + tooltipTriangle.offsetWidth + tooltipTriangle.offsetWidth / 2) + "px;";
76
89
  } else {
77
90
  tooltip.style.cssText = "right: -" + (D.body.offsetWidth - elementRects.right) + "px;";
78
91
  tooltipTriangle.style.cssText = "right: " + (D.body.offsetWidth - elementRects.right + tooltipTriangle.offsetWidth + tooltipTriangle.offsetWidth / 2) + "px;";
@@ -1,6 +1,7 @@
1
1
  .awesome-tooltip-wrapper {
2
2
  position: relative;
3
3
  display: inline-block;
4
+ cursor: pointer;
4
5
 
5
6
  .awesome-tooltip {
6
7
  position: absolute;
@@ -1,3 +1,3 @@
1
1
  module AwesomeTooltip
2
- VERSION = '0.1.10'
2
+ VERSION = '0.1.11'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_tooltip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Busko Bogdan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-20 00:00:00.000000000 Z
11
+ date: 2020-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails