Include code to position one element over another
[infodrom.org/service.infodrom.org] / src / infodrom.js
index e76b2ae..6325fc0 100644 (file)
@@ -22,30 +22,22 @@ function hide_message(text)
     $('#message_div').hide();
 }
 
+var errorwindow = false;
 function show_error(text, timeout)
 {
-    var div = $('#error_div');
-    if (!div.length) {
-       div = $('<div>');
-       div.attr('id', 'error_div').css('z-index','1000');
-       div.hide();
-       div.append($('<p ><img src="/pix/close.gif" title="close" onclick="return hide_error()"/></p>'));
-       div.append($('<div />'));
-       $(document.body).append(div);
+    if (!errorwindow) {
+       errorwindow = new Popup('Fehler', '500px', false, '<div id="errorbody"></div>');
+       errorwindow.setId('errorwindow');
+       $('#errorwindow').css('z-index','1000');
+       errorwindow.centerPopup();
+    } else {
+       errorwindow.openPopup();
     }
 
-    div.find('div').html(text);
-    div.center();
-    div.show();
+    $('#errorbody').html(text);
 
     if (typeof timeout != 'undefined')
-       window.setTimeout(hide_error,timeout*1000);
-}
-
-function hide_error(text)
-{
-    $('#error_div').hide();
-    return false;
+       window.setTimeout(function(){errorwindow.closePopup()},timeout*1000);
 }
 
 function editable_callback(data)
@@ -88,6 +80,29 @@ function make_editable(selector)
        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;
@@ -179,6 +194,11 @@ Popup.prototype = {
        this.popup.hide();
     },
 
+    setId: function(name)
+    {
+       this.popup.attr('id', name);
+    },
+
     setTitle: function(title)
     {
        this.popup.find('div.popup_title p.popup_title').html(title);