awesome_tooltip 0.1.6 → 0.1.12

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: d27f390318b9b90c3f0bfaf3ba557e5794505862aa0ec4f197ae2bc2f1ede003
4
- data.tar.gz: 4850f277a12711b7b8adbef4167f9f58b83580956a97b5688a68b63a8ad09ac6
3
+ metadata.gz: b4333fbdabb7aafcf0d982f404459cc6d30567dc616b58f2fe752a206d0a6943
4
+ data.tar.gz: 810a29db2d57b379936fd6c50d5efc23de2506a79c3143aae26f42af0602df66
5
5
  SHA512:
6
- metadata.gz: 128b87a5ff59fabafc54b3635ee066ad8f17dc9817447154516b55bd80dca11bb25a981b1fb51c4b9e34eeae67cefdd89773858cb24af9a319b92dc69873475f
7
- data.tar.gz: 5b8ad0d1f03b45bd27b76f588c8c38acc0b9f2ebf3fef707ec6259ac5e22a656a6408ab76628afc24ef5d5409054b01775812081df0df3d6a1f0431966de490a
6
+ metadata.gz: 6432fe70dd74c8051a69a3ddfc9706f6474be105d41426970189482cf45463398b4e47230026fdde472442a2e432235a8b50ae463d382dd71b89d5e0feb5acfe
7
+ data.tar.gz: 2a8c34935d1e5ef9b26243e8293cbcc38528d718f7149543fe5107b4132c54cb6cd3597a7f4715f250ce68a0a92ebb28b79ecaf9dcf312622a49f7cfba7f5db6
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
- display: inline;
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.6'
2
+ VERSION = '0.1.12'
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.6
4
+ version: 0.1.12
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-19 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