3ec4a8080400933346691fc1c819f8ab619285ca
[Packages/TYPO3.CMS.git] / t3lib / js / adminpanel.js
1 /***************************************************************
2 * Admin Panel drag and drop
3 *
4 * $Id$
5 *
6 * Copyright notice
7 *
8 * (c) 2009-2010 Ingo Renner <ingo@typo3.org>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * @author Ingo Renner <ingo@typo3.org>
30 * @author Oliver Hader <oliver@typo3.org>
31 * @author Ingmar Schlecht <ingmar@typo3.org>
32 * @author Jonas Dübi <jd@cabag.ch>
33 */
34
35 var TYPO3AdminPanel = {
36
37 positionRestored: false,
38 dragObject: null,
39 dragX: 0,
40 dragY: 0,
41 posX: 0,
42 posY: 0,
43
44 savePosition: function(panel) {
45 var admPanelPosX = panel.offsetLeft;
46 var admPanelPosY = panel.offsetTop;
47
48 TYPO3AdminPanel.setCookie('admPanelPosX', admPanelPosX, '', '/');
49 TYPO3AdminPanel.setCookie('admPanelPosY', admPanelPosY, '', '/');
50 },
51
52 restorePosition: function() {
53 if (TYPO3AdminPanel.positionRestored == false) {
54
55 var admPanelPosX = TYPO3AdminPanel.getCookie('admPanelPosX');
56 if (admPanelPosX > 0) {
57 document.getElementById('admPanel').style.left = admPanelPosX + 'px';
58 }
59
60 var admPanelPosY = TYPO3AdminPanel.getCookie('admPanelPosY');
61 if (admPanelPosY > 0) {
62 document.getElementById('admPanel').style.top = admPanelPosY + 'px';
63 }
64
65 TYPO3AdminPanel.positionRestored = true;
66 }
67 },
68
69 setCookie: function(name, value, expires, path, domain, secure) {
70 document.cookie = name + '=' + escape(value)
71 + (expires ? '; expires=' + expires.toGMTString() : '')
72 + (path ? '; path=' + path : '')
73 + (domain ? '; domain=' + domain : '')
74 + (secure ? '; secure' : '');
75 },
76
77 getCookie: function(name) {
78 var dc = document.cookie;
79 var prefix = name + '=';
80 var begin = dc.indexOf('; ' + prefix);
81
82 if (begin == -1) {
83 begin = dc.indexOf(prefix);
84 if (begin != 0) {
85 return null;
86 }
87 } else {
88 begin += 2;
89 }
90
91 var end = dc.indexOf(';', begin);
92 if (end == -1) {
93 end = dc.length;
94 }
95
96 return unescape(dc.substring(begin + prefix.length, end));
97 },
98
99 dragInit: function() {
100 document.onmousemove = TYPO3AdminPanel.drag;
101 document.onmouseup = TYPO3AdminPanel.dragStop;
102 },
103
104 dragStart: function(element) {
105 TYPO3AdminPanel.dragObject = element;
106 TYPO3AdminPanel.dragX = TYPO3AdminPanel.posX - TYPO3AdminPanel.dragObject.offsetLeft;
107 TYPO3AdminPanel.dragY = TYPO3AdminPanel.posY - TYPO3AdminPanel.dragObject.offsetTop;
108 },
109
110 dragStop: function() {
111 TYPO3AdminPanel.dragObject = null;
112 },
113
114 drag: function(dragEvent) {
115 TYPO3AdminPanel.posX = document.all ? window.event.clientX : dragEvent.pageX;
116 TYPO3AdminPanel.posY = document.all ? window.event.clientY : dragEvent.pageY;
117
118 if (TYPO3AdminPanel.dragObject != null) {
119 TYPO3AdminPanel.dragObject.style.left = (TYPO3AdminPanel.posX - TYPO3AdminPanel.dragX) + 'px';
120 TYPO3AdminPanel.dragObject.style.top = (TYPO3AdminPanel.posY - TYPO3AdminPanel.dragY) + 'px';
121 }
122 }
123 };