Bläddra i källkod

Redesigned "setTooltip" method

master
Maxim Voloshin 8 år sedan
förälder
incheckning
87ed7b7989
1 ändrade filer med 21 tillägg och 29 borttagningar
  1. 21
    29
      modules/UI/util/UIUtil.js

+ 21
- 29
modules/UI/util/UIUtil.js Visa fil

@@ -2,6 +2,17 @@
2 2
 
3 3
 import KeyboardShortcut from '../../keyboardshortcut/keyboardshortcut';
4 4
 
5
+const TOOLTIP_POSITIONS = {
6
+    'top': 's',
7
+    'left': 'e',
8
+    'right': 'w',
9
+    'bottom': 'n',
10
+    'top-left': 'se',
11
+    'top-right': 'sw',
12
+    'bottom-left': 'ne',
13
+    'bottom-right': 'nw'
14
+};
15
+
5 16
 /**
6 17
  * Created by hristo on 12/22/14.
7 18
  */
@@ -90,17 +101,13 @@ import KeyboardShortcut from '../../keyboardshortcut/keyboardshortcut';
90 101
      * appropriate class (ex. "tooltip-n") and "content" attribute.
91 102
      */
92 103
     activateTooltips: function () {
93
-        function getTitle () {
94
-            return this.getAttribute('content');
95
-        }
96
-
97
-        function getGravity () {
98
-            return this.getAttribute('data-tooltip');
99
-        }
100
-
101 104
         AJS.$('[data-tooltip]').tooltip({
102
-            gravity: getGravity,
103
-            title: getTitle,
105
+            gravity() {
106
+                return this.getAttribute('data-tooltip');
107
+            },
108
+            title() {
109
+                return this.getAttribute('content')
110
+            },
104 111
             html: true,      // handle multiline tooltips
105 112
             // two options to prevent tooltips from being stuck:
106 113
             live: true,      // attach listener to document element
@@ -116,25 +123,10 @@ import KeyboardShortcut from '../../keyboardshortcut/keyboardshortcut';
116 123
      * @param position the position of the tooltip in relation to the element
117 124
      */
118 125
     setTooltip: function (element, key, position) {
119
-        let positions = {
120
-            'top': 's',
121
-            'top-left': 'se',
122
-            'left': 'e',
123
-            'bottom-left': 'ne',
124
-            'bottom': 'n',
125
-            'bottom-right': 'nw',
126
-            'right': 'w',
127
-            'top-right': 'sw'
128
-        };
129
-
130
-        $(element).each(function () {
131
-            var el = $(this);
132
-
133
-            el.attr("data-i18n", "[content]" + key)
134
-              .attr('data-tooltip', positions[position]);
135
-
136
-            APP.translation.translateElement(el);
137
-        });
126
+        element.setAttribute('data-tooltip', TOOLTIP_POSITIONS[position]);
127
+        element.setAttribute('data-i18n', '[content]' + key);
128
+
129
+        APP.translation.translateElement($(element));
138 130
     },
139 131
 
140 132
     /**

Laddar…
Avbryt
Spara