Include code to position one element over another
authorJoey Schulze <joey@infodrom.org>
Thu, 27 Jul 2017 21:08:08 +0000 (23:08 +0200)
committerJoey Schulze <joey@infodrom.org>
Sat, 6 Oct 2018 17:30:26 +0000 (19:30 +0200)
src/infodrom.js

index 1190b40..6325fc0 100644 (file)
@@ -80,6 +80,29 @@ function make_editable(selector)
        return this;
     };
 
        return this;
     };
 
+    $.fn.positionOn = function(element, align) {
+       return this.each(function() {
+           var target   = $(this);
+           var position = element.offset();
+
+           var x      = position.left;
+           var y      = position.top;
+
+           if(align == 'right') {
+               x -= (target.outerWidth() - element.outerWidth());
+           } else if(align == 'center') {
+               x -= target.outerWidth() / 2 - element.outerWidth() / 2;
+           }
+
+           target.css({
+               position: 'absolute',
+               zIndex:   5000,
+               top:      y,
+               left:     x
+           });
+       });
+    };
+
 $.invoke = function(name, parms, callback) {
     if (typeof(parms) == 'string' && parms.length)
        parms = 'route='+name+'&'+parms;
 $.invoke = function(name, parms, callback) {
     if (typeof(parms) == 'string' && parms.length)
        parms = 'route='+name+'&'+parms;