Kaynağa Gözat

Add fix to the tooltip library so tooltips never go out of the window. #106

j8
fo 11 yıl önce
ebeveyn
işleme
e956acf1fa
1 değiştirilmiş dosya ile 23 ekleme ve 0 silme
  1. 23
    0
      libs/tooltip.js

+ 23
- 0
libs/tooltip.js Dosyayı Görüntüle

@@ -185,6 +185,29 @@
185 185
         that.$element.trigger('shown.bs.' + that.type)
186 186
       }
187 187
 
188
+      var deltas = {
189
+          "bottom": $tip[0].getBoundingClientRect().bottom - window.innerHeight,
190
+          "right": $tip[0].getBoundingClientRect().right - window.innerWidth,
191
+          "left": -$tip[0].getBoundingClientRect().left,
192
+          "top": -$tip[0].getBoundingClientRect().top
193
+      };
194
+      for(var direction in deltas) {
195
+          if (deltas[direction] > 0) {
196
+              var delta = deltas[direction];
197
+              if(direction === "right" || direction === "bottom") {
198
+                  delta = -delta;
199
+              }
200
+              direction = direction === "top" || direction === "bottom" ? "top" : "left";
201
+              var currentPosition = parseInt($tip.css(direction), 10);
202
+              $tip.css(direction, currentPosition + delta);
203
+              if(direction === "left") {
204
+                  $tip.children(".arrow").css(direction, parseInt($tip.children(".arrow").css(direction), 10) - delta);
205
+              } else {
206
+                  $tip.children(".arrow").css(direction, 50 - $tip[0].getBoundingClientRect().height / delta + "%");
207
+              }
208
+          }
209
+      }
210
+
188 211
       $.support.transition && this.$tip.hasClass('fade') ?
189 212
         $tip
190 213
           .one($.support.transition.end, complete)

Loading…
İptal
Kaydet