7604 |
25 Feb 19 |
nicklas |
/* $Id$ |
7604 |
25 Feb 19 |
nicklas |
2 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
Copyright (C) 2014 Nicklas Nordborg |
7604 |
25 Feb 19 |
nicklas |
4 |
|
7604 |
25 Feb 19 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
7604 |
25 Feb 19 |
nicklas |
Available at http://base.thep.lu.se/ |
7604 |
25 Feb 19 |
nicklas |
7 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is free software; you can redistribute it and/or |
7604 |
25 Feb 19 |
nicklas |
modify it under the terms of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
as published by the Free Software Foundation; either version 3 |
7604 |
25 Feb 19 |
nicklas |
of the License, or (at your option) any later version. |
7604 |
25 Feb 19 |
nicklas |
12 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is distributed in the hope that it will be useful, |
7604 |
25 Feb 19 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7604 |
25 Feb 19 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7604 |
25 Feb 19 |
nicklas |
GNU General Public License for more details. |
7604 |
25 Feb 19 |
nicklas |
17 |
|
7604 |
25 Feb 19 |
nicklas |
You should have received a copy of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
7604 |
25 Feb 19 |
nicklas |
20 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
21 |
|
7604 |
25 Feb 19 |
nicklas |
22 |
*/ |
7604 |
25 Feb 19 |
nicklas |
'use strict'; |
7604 |
25 Feb 19 |
nicklas |
24 |
|
7604 |
25 Feb 19 |
nicklas |
var Popup = function() |
7604 |
25 Feb 19 |
nicklas |
26 |
{ |
7604 |
25 Feb 19 |
nicklas |
var popup = {}; |
7604 |
25 Feb 19 |
nicklas |
var internal = {}; |
7604 |
25 Feb 19 |
nicklas |
var dx = 0; |
7604 |
25 Feb 19 |
nicklas |
var dy = 0; |
7604 |
25 Feb 19 |
nicklas |
31 |
|
7604 |
25 Feb 19 |
nicklas |
var saveDialogPosition = false; |
7604 |
25 Feb 19 |
nicklas |
33 |
|
7604 |
25 Feb 19 |
nicklas |
// If the popup dialog is read-only BASE will not |
7604 |
25 Feb 19 |
nicklas |
// display a warning when trying to re-open the same dialog |
7604 |
25 Feb 19 |
nicklas |
popup.isReadOnly = function() |
7604 |
25 Feb 19 |
nicklas |
37 |
{ |
7604 |
25 Feb 19 |
nicklas |
return Data.int(document.body, 'read-only'); |
7604 |
25 Feb 19 |
nicklas |
39 |
} |
7604 |
25 Feb 19 |
nicklas |
40 |
|
7604 |
25 Feb 19 |
nicklas |
// Need short delay to ensure that window is properly initialized |
7604 |
25 Feb 19 |
nicklas |
internal.delayInitPosition = function() |
7604 |
25 Feb 19 |
nicklas |
43 |
{ |
7604 |
25 Feb 19 |
nicklas |
saveDialogPosition = window.top.name && App.rememberDialogPositions(); |
7604 |
25 Feb 19 |
nicklas |
if (saveDialogPosition) setTimeout(internal.initPosition, 200); |
7604 |
25 Feb 19 |
nicklas |
46 |
} |
7604 |
25 Feb 19 |
nicklas |
47 |
|
7604 |
25 Feb 19 |
nicklas |
// Correct size of the window if the actual size is different from the requested |
7604 |
25 Feb 19 |
nicklas |
// Firefox has -1 pixel height and IE has +4 pixels width and height |
7604 |
25 Feb 19 |
nicklas |
internal.initPosition = function() |
7604 |
25 Feb 19 |
nicklas |
51 |
{ |
7604 |
25 Feb 19 |
nicklas |
var key = 'dialog-position-req:'+window.top.name; |
7604 |
25 Feb 19 |
nicklas |
var rpos = JSON.parse(App.getLocal(key)); |
7604 |
25 Feb 19 |
nicklas |
if (rpos) |
7604 |
25 Feb 19 |
nicklas |
55 |
{ |
7604 |
25 Feb 19 |
nicklas |
App.removeLocal(key); |
7604 |
25 Feb 19 |
nicklas |
var cpos = App.getWindowPosition(window.top); |
7604 |
25 Feb 19 |
nicklas |
dx = Math.min(rpos.width, screen.availWidth) - cpos.width; |
7604 |
25 Feb 19 |
nicklas |
dy = Math.min(rpos.height, screen.availHeight) - cpos.height; |
7604 |
25 Feb 19 |
nicklas |
// window.top.opener.App.debug('requested:'+JSON.stringify(rpos)); |
7604 |
25 Feb 19 |
nicklas |
// window.top.opener.App.debug('actual:'+JSON.stringify(cpos)); |
7604 |
25 Feb 19 |
nicklas |
// window.top.opener.App.debug('delta:'+dx+','+dy); |
7604 |
25 Feb 19 |
nicklas |
// window.top.opener.App.debug('screen:'+screen.availWidth+','+screen.availHeight); |
7604 |
25 Feb 19 |
nicklas |
64 |
} |
7604 |
25 Feb 19 |
nicklas |
65 |
} |
7604 |
25 Feb 19 |
nicklas |
66 |
|
7604 |
25 Feb 19 |
nicklas |
internal.savePosition = function() |
7604 |
25 Feb 19 |
nicklas |
68 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (!saveDialogPosition || Data.int(document.body, 'no-dialog-position')) return; |
7604 |
25 Feb 19 |
nicklas |
70 |
|
7604 |
25 Feb 19 |
nicklas |
var pos = App.getWindowPosition(window.top); |
7604 |
25 Feb 19 |
nicklas |
pos.width += dx; |
7604 |
25 Feb 19 |
nicklas |
pos.height += dy; |
7604 |
25 Feb 19 |
nicklas |
App.setLocal('dialog-position:'+window.top.name, JSON.stringify(pos)); |
7604 |
25 Feb 19 |
nicklas |
75 |
} |
7604 |
25 Feb 19 |
nicklas |
76 |
|
7604 |
25 Feb 19 |
nicklas |
document.addEventListener('DOMContentLoaded', internal.delayInitPosition, false); |
7604 |
25 Feb 19 |
nicklas |
window.addEventListener('beforeunload', internal.savePosition, false); |
7604 |
25 Feb 19 |
nicklas |
79 |
|
7604 |
25 Feb 19 |
nicklas |
return popup; |
7604 |
25 Feb 19 |
nicklas |
81 |
}(); |
7604 |
25 Feb 19 |
nicklas |
82 |
|
7604 |
25 Feb 19 |
nicklas |
83 |
|
7604 |
25 Feb 19 |
nicklas |
84 |
|