Created
February 25, 2010 14:58
-
-
Save Mikr0Tik/314596 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Methods for extending Prototype | |
*/ | |
var Position = { | |
/** | |
* Centers an element against the parent or body | |
* parent should be display: relative | |
*/ | |
center: function(elem, parent){ | |
var elem = $(elem); | |
var parent; | |
var dims = elem.getDimensions(); | |
var scroll = document.viewport.getScrollOffsets(); | |
var bgDims; | |
if(parent){ | |
bgDims = $(parent).getDimensions(); | |
} else { | |
bgDims = document.viewport.getDimensions(); | |
} | |
var t = parseInt( ( ( ( bgDims.height ) - dims.height) / 2 ), 10); | |
var l = parseInt( ( ( ( bgDims.width ) - dims.width) / 2 ), 10 ); | |
elem.setStyle({ | |
position: 'absolute', | |
top: t + scroll.top + 'px', | |
left: l + scroll.left + 'px' | |
}); | |
}, | |
/** | |
* Used to keep ensure an element stays within a scrollable div | |
*/ | |
keepWithin: function(elem, parent, padding){ | |
elem = $(elem); | |
parent = $(parent); | |
padding = padding || 0; | |
// return if no scrollbars | |
if(parent.scrollHeight < 1) return elem; | |
var elemViewportBottom = elem.getBoundingClientRect().bottom.ceil(); | |
var parentViewportBottom = parent.viewportOffset().top + parent.getHeight(); | |
if(parentViewportBottom < elemViewportBottom) | |
parent.scrollTop = elemViewportBottom - parentViewportBottom + padding; | |
return elem; | |
} | |
}; | |
Element.addMethods(Position); | |
Draggable.prototype.initialize = Draggable.prototype.initialize.wrap(function(callOriginal, el){ | |
var ret = callOriginal(el, {handle: 'head'}); | |
var boddy = $$('body')[0]; | |
this.element.center(document.body); | |
var iframe = Element.insert(this.element, {after: new Element('iframe', {style: 'position:absolute; z-index:20;', | |
id: "popup_bg", frameborder: "0", scrolling: "no"}) | |
}); | |
document.enabled = false; | |
this.element.show(); | |
Element.clonePosition('popup_bg', this.element); | |
this.element.select('.close').each(function(close_el){ | |
close_el.observe('click', function(event){ | |
$$('.reset').each(function(el){el.reset()}) | |
var dragable = this.up('.dragable'); | |
Draggables.destroy(dragable); | |
event.stop(); | |
}); | |
}) | |
this.element.observe('keypress', formSubmitOnEnter); | |
return ret; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment