Kaynağa Gözat

Global handler for tooltips

j8
Maxim Voloshin 9 yıl önce
ebeveyn
işleme
212798ad19
2 değiştirilmiş dosya ile 41 ekleme ve 6 silme
  1. 2
    0
      modules/UI/UI.js
  2. 39
    6
      modules/UI/util/UIUtil.js

+ 2
- 0
modules/UI/UI.js Dosyayı Görüntüle

329
     // to the UI (depending on the moderator role of the local participant) and
329
     // to the UI (depending on the moderator role of the local participant) and
330
     // (2) APP.conference as means of communication between the participants.
330
     // (2) APP.conference as means of communication between the participants.
331
     followMeHandler = new FollowMe(APP.conference, UI);
331
     followMeHandler = new FollowMe(APP.conference, UI);
332
+
333
+    UIUtil.activateTooltips();
332
 };
334
 };
333
 
335
 
334
 UI.mucJoined = function () {
336
 UI.mucJoined = function () {

+ 39
- 6
modules/UI/util/UIUtil.js Dosyayı Görüntüle

84
         context.putImageData(imgData, 0, 0);
84
         context.putImageData(imgData, 0, 0);
85
     },
85
     },
86
 
86
 
87
+    /**
88
+     * Sets global handler for all tooltips. Once this function is invoked
89
+     * all you need to create new tooltip is to update DOM node with
90
+     * appropriate class (ex. "tooltip-n") and "content" attribute.
91
+     */
92
+    activateTooltips: function () {
93
+        var positions = [
94
+            {side: 'top', gravity: 's'},
95
+            {side: 'left', gravity: 'e'},
96
+            {side: 'right', gravity: 'w'},
97
+            {side: 'bottom', gravity: 'n'},
98
+            {side: 'top-left', gravity: 'se'},
99
+            {side: 'top-right', gravity: 'sw'},
100
+            {side: 'bottom-left', gravity: 'ne'},
101
+            {side: 'bottom-right', gravity: 'nw'}
102
+        ];
103
+
104
+        function getTitle () {
105
+            return this.getAttribute('content');
106
+        }
107
+
108
+        positions.forEach(function (config) {
109
+            AJS.$('.tooltip-' + config.gravity).tooltip({
110
+                gravity: config.gravity,
111
+                title: getTitle,
112
+                html: true,      // handle multiline tooltips
113
+                // two options to prevent tooltips from being stuck:
114
+                live: true,      // attach listener to document element
115
+                hoverable: false // make custom tooltips to behave like native
116
+            });
117
+        });
118
+    },
119
+
87
     /**
120
     /**
88
      * Sets the tooltip to the given element.
121
      * Sets the tooltip to the given element.
89
      *
122
      *
103
             'top-right': 'sw'
136
             'top-right': 'sw'
104
         };
137
         };
105
 
138
 
106
-        element.setAttribute("data-i18n", "[content]" + key);
107
-        APP.translation.translateElement($(element));
139
+        $(element).each(function () {
140
+            var el = $(this);
141
+
142
+            el.addClass('tooltip-' + positions[position])
143
+              .attr("data-i18n", "[content]" + key);
108
 
144
 
109
-        AJS.$(element).tooltip({
110
-            gravity: positions[position],
111
-            title: this._getTooltipText.bind(this, element),
112
-            html: true
145
+            APP.translation.translateElement(el);
113
         });
146
         });
114
     },
147
     },
115
 
148
 

Loading…
İptal
Kaydet