Fixes
This commit is contained in:
parent
75de95acc3
commit
d5c3b25447
4 changed files with 296 additions and 79 deletions
218
popup.js
218
popup.js
|
|
@ -202,3 +202,221 @@ $=jQuery;
|
|||
}
|
||||
|
||||
})( jQuery );
|
||||
|
||||
$=jQuery;
|
||||
|
||||
(function( $ ){
|
||||
|
||||
$.fn.simplePopUp=function (popup, width, pre_callback, post_callback, options) {
|
||||
|
||||
var after_show=false;
|
||||
|
||||
var after_click=false;
|
||||
|
||||
if(options!=undefined)
|
||||
{
|
||||
|
||||
if(options.hasOwnProperty("popup_container"))
|
||||
{
|
||||
|
||||
popup_container=options.popup_container;
|
||||
|
||||
}
|
||||
|
||||
if(options.hasOwnProperty("after_show"))
|
||||
{
|
||||
|
||||
after_show=options.after_show;
|
||||
|
||||
}
|
||||
|
||||
if(options.hasOwnProperty("after_click"))
|
||||
{
|
||||
|
||||
after_click=options.after_click;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$(this).on('click', function (e) {
|
||||
|
||||
//Show layer_popup
|
||||
|
||||
body_height=$("body").height();
|
||||
|
||||
$('#layer_popup').height(body_height);
|
||||
|
||||
$('body').prepend('<div id="layer_popup"></div>');
|
||||
|
||||
//$('body').css('overflow', 'hidden');
|
||||
|
||||
//Show popup
|
||||
|
||||
$(popup).css('position', 'absolute');
|
||||
|
||||
$(popup).css('width', width);
|
||||
|
||||
$(popup).addClass('content_popup');
|
||||
|
||||
/*var position=$(popup).offset();
|
||||
|
||||
var left=position.left;
|
||||
var top=position.top;
|
||||
|
||||
console.log($(popup).css('left'));*/
|
||||
|
||||
scr_width=$(window).width();
|
||||
|
||||
scr_height=$(window).height();
|
||||
|
||||
center_left=parseInt(scr_width/2)-parseInt(width/2);
|
||||
|
||||
center_top=parseInt(scr_height/2)-parseInt($(popup).height()/2);
|
||||
|
||||
$(popup).css('left', center_left);
|
||||
$(popup).css('top', center_top);
|
||||
|
||||
if(!after_show)
|
||||
{
|
||||
|
||||
$(popup).fadeIn();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$(popup).fadeIn({'done': after_show(popup)});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$('.close_popup').click(function () {
|
||||
|
||||
if(after_click)
|
||||
{
|
||||
|
||||
after_click();
|
||||
|
||||
}
|
||||
|
||||
$('#layer_popup').remove();
|
||||
|
||||
$(popup).hide();
|
||||
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
})( jQuery );
|
||||
|
||||
//From https://www.w3schools.com/howto/howto_js_draggable.asp
|
||||
|
||||
function dragElement(draggable, header) {
|
||||
|
||||
elmnt=document.getElementById(draggable);
|
||||
|
||||
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
|
||||
if (document.getElementById(header)) {
|
||||
// if present, the header is where you move the DIV from:
|
||||
document.getElementById(header).onmousedown = dragMouseDown;
|
||||
} else {
|
||||
// otherwise, move the DIV from anywhere inside the DIV:
|
||||
elmnt.onmousedown = dragMouseDown;
|
||||
}
|
||||
|
||||
function dragMouseDown(e) {
|
||||
e = e || window.event;
|
||||
e.preventDefault();
|
||||
// get the mouse cursor position at startup:
|
||||
pos3 = e.clientX;
|
||||
pos4 = e.clientY;
|
||||
document.onmouseup = closeDragElement;
|
||||
// call a function whenever the cursor moves:
|
||||
document.onmousemove = elementDrag;
|
||||
}
|
||||
|
||||
function elementDrag(e) {
|
||||
e = e || window.event;
|
||||
e.preventDefault();
|
||||
// calculate the new cursor position:
|
||||
pos1 = pos3 - e.clientX;
|
||||
pos2 = pos4 - e.clientY;
|
||||
pos3 = e.clientX;
|
||||
pos4 = e.clientY;
|
||||
// set the element's new position:
|
||||
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
|
||||
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
|
||||
}
|
||||
|
||||
function closeDragElement() {
|
||||
// stop moving when mouse button is released:
|
||||
document.onmouseup = null;
|
||||
document.onmousemove = null;
|
||||
}
|
||||
}
|
||||
|
||||
(function( $ ){
|
||||
|
||||
$.fn.draggable = function (header) {
|
||||
|
||||
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
|
||||
|
||||
var popup=this;
|
||||
|
||||
$(header).on('mousedown', function (e) {
|
||||
|
||||
e = e || window.event;
|
||||
|
||||
e.preventDefault();
|
||||
// get the mouse cursor position at startup:
|
||||
pos3 = e.clientX;
|
||||
pos4 = e.clientY;
|
||||
|
||||
document.onmouseup = closeDragElement;
|
||||
|
||||
// call a function whenever the cursor moves:
|
||||
document.onmousemove = elementDrag;
|
||||
|
||||
console.log('Moving...');
|
||||
|
||||
});
|
||||
|
||||
function elementDrag(e) {
|
||||
|
||||
console.log('Moving windows...');
|
||||
|
||||
e = e || window.event;
|
||||
e.preventDefault();
|
||||
// calculate the new cursor position:
|
||||
pos1 = pos3 - e.clientX;
|
||||
pos2 = pos4 - e.clientY;
|
||||
pos3 = e.clientX;
|
||||
pos4 = e.clientY;
|
||||
// set the element's new position:
|
||||
/*elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
|
||||
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";*/
|
||||
|
||||
offset=$(popup).offset();
|
||||
|
||||
offset_top=parseInt(offset.top);
|
||||
offset_left=parseInt(offset.left);
|
||||
|
||||
$(popup).css('top', (offset_top - pos2) + "px");
|
||||
$(popup).css('left', (offset_left - pos1) + "px");
|
||||
|
||||
}
|
||||
|
||||
function closeDragElement() {
|
||||
// stop moving when mouse button is released:
|
||||
document.onmouseup = null;
|
||||
document.onmousemove = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})( jQuery );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue