7604 |
25 Feb 19 |
nicklas |
/* $Id $ |
7604 |
25 Feb 19 |
nicklas |
2 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
Copyright (C) 2012 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 |
@author Nicklas |
7604 |
25 Feb 19 |
nicklas |
23 |
*/ |
7604 |
25 Feb 19 |
nicklas |
'use strict'; |
7604 |
25 Feb 19 |
nicklas |
25 |
|
7604 |
25 Feb 19 |
nicklas |
var Zoom = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var zoomField; |
7604 |
25 Feb 19 |
nicklas |
29 |
|
7604 |
25 Feb 19 |
nicklas |
var zoom = {}; |
7604 |
25 Feb 19 |
nicklas |
31 |
|
7604 |
25 Feb 19 |
nicklas |
zoom.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
33 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Dialog buttons |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSave', Zoom.save); |
7604 |
25 Feb 19 |
nicklas |
37 |
|
7604 |
25 Feb 19 |
nicklas |
// Get the text from the parent window |
7604 |
25 Feb 19 |
nicklas |
zoomField = window.opener.document.getElementById(Data.get('page-data', 'textarea')); |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['zoom']; |
7604 |
25 Feb 19 |
nicklas |
frm.zoom.value = zoomField.value; |
7604 |
25 Feb 19 |
nicklas |
frm.zoom.focus(); |
7604 |
25 Feb 19 |
nicklas |
frm.zoom.disabled = zoomField.disabled; |
7604 |
25 Feb 19 |
nicklas |
44 |
} |
7604 |
25 Feb 19 |
nicklas |
45 |
|
7604 |
25 Feb 19 |
nicklas |
zoom.initializeToolbarElements = function(element, autoInit) |
7604 |
25 Feb 19 |
nicklas |
47 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (autoInit == 'enclose-selection') |
7604 |
25 Feb 19 |
nicklas |
49 |
{ |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler(element, zoom.textButtonOnClick); |
7604 |
25 Feb 19 |
nicklas |
51 |
} |
7604 |
25 Feb 19 |
nicklas |
52 |
} |
7604 |
25 Feb 19 |
nicklas |
53 |
|
7604 |
25 Feb 19 |
nicklas |
zoom.textButtonOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
55 |
{ |
7604 |
25 Feb 19 |
nicklas |
var prefix = Data.get(event.currentTarget, 'prefix', ''); |
7604 |
25 Feb 19 |
nicklas |
var suffix = Data.get(event.currentTarget, 'suffix', ''); |
7604 |
25 Feb 19 |
nicklas |
zoom.encloseSelection(prefix, suffix); |
7604 |
25 Feb 19 |
nicklas |
59 |
} |
7604 |
25 Feb 19 |
nicklas |
60 |
/* |
7604 |
25 Feb 19 |
nicklas |
Enclose the selected text with prefix and suffix. Code taken |
7604 |
25 Feb 19 |
nicklas |
from Trac: http://projects.edgewall.com/trac/ |
7604 |
25 Feb 19 |
nicklas |
63 |
*/ |
7604 |
25 Feb 19 |
nicklas |
zoom.encloseSelection = function(prefix, suffix) |
7604 |
25 Feb 19 |
nicklas |
65 |
{ |
7604 |
25 Feb 19 |
nicklas |
var textarea = document.forms['zoom'].zoom; |
7604 |
25 Feb 19 |
nicklas |
textarea.focus(); |
7604 |
25 Feb 19 |
nicklas |
var start, end, sel, scrollPos, subst; |
7604 |
25 Feb 19 |
nicklas |
if (typeof(document["selection"]) != "undefined") |
7604 |
25 Feb 19 |
nicklas |
70 |
{ |
7604 |
25 Feb 19 |
nicklas |
sel = document.selection.createRange().text; |
7604 |
25 Feb 19 |
nicklas |
72 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (typeof(textarea["setSelectionRange"]) != "undefined") |
7604 |
25 Feb 19 |
nicklas |
74 |
{ |
7604 |
25 Feb 19 |
nicklas |
start = textarea.selectionStart; |
7604 |
25 Feb 19 |
nicklas |
end = textarea.selectionEnd; |
7604 |
25 Feb 19 |
nicklas |
scrollPos = textarea.scrollTop; |
7604 |
25 Feb 19 |
nicklas |
sel = textarea.value.substring(start, end); |
7604 |
25 Feb 19 |
nicklas |
79 |
} |
7604 |
25 Feb 19 |
nicklas |
if (sel.match(/ $/)) |
7604 |
25 Feb 19 |
nicklas |
81 |
{ |
7604 |
25 Feb 19 |
nicklas |
// exclude ending space char, if any |
7604 |
25 Feb 19 |
nicklas |
sel = sel.substring(0, sel.length - 1); |
7604 |
25 Feb 19 |
nicklas |
suffix = suffix + " "; |
7604 |
25 Feb 19 |
nicklas |
85 |
} |
7604 |
25 Feb 19 |
nicklas |
subst = prefix + sel + suffix; |
7604 |
25 Feb 19 |
nicklas |
if (typeof(document["selection"]) != "undefined") |
7604 |
25 Feb 19 |
nicklas |
88 |
{ |
7604 |
25 Feb 19 |
nicklas |
var range = document.selection.createRange().text = subst; |
7604 |
25 Feb 19 |
nicklas |
textarea.caretPos -= suffix.length; |
7604 |
25 Feb 19 |
nicklas |
91 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (typeof(textarea["setSelectionRange"]) != "undefined") |
7604 |
25 Feb 19 |
nicklas |
93 |
{ |
7604 |
25 Feb 19 |
nicklas |
textarea.value = textarea.value.substring(0, start) + subst + |
7604 |
25 Feb 19 |
nicklas |
textarea.value.substring(end); |
7604 |
25 Feb 19 |
nicklas |
if (sel) |
7604 |
25 Feb 19 |
nicklas |
97 |
{ |
7604 |
25 Feb 19 |
nicklas |
textarea.setSelectionRange(start + subst.length, start + subst.length); |
7604 |
25 Feb 19 |
nicklas |
99 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
101 |
{ |
7604 |
25 Feb 19 |
nicklas |
textarea.setSelectionRange(start + prefix.length, start + prefix.length); |
7604 |
25 Feb 19 |
nicklas |
103 |
} |
7604 |
25 Feb 19 |
nicklas |
textarea.scrollTop = scrollPos; |
7604 |
25 Feb 19 |
nicklas |
105 |
} |
7604 |
25 Feb 19 |
nicklas |
106 |
} |
7604 |
25 Feb 19 |
nicklas |
107 |
|
7604 |
25 Feb 19 |
nicklas |
108 |
|
7604 |
25 Feb 19 |
nicklas |
109 |
/** |
7604 |
25 Feb 19 |
nicklas |
Save and close the popup. |
7604 |
25 Feb 19 |
nicklas |
111 |
*/ |
7604 |
25 Feb 19 |
nicklas |
zoom.save = function() |
7604 |
25 Feb 19 |
nicklas |
113 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (!zoomField.disabled) |
7604 |
25 Feb 19 |
nicklas |
115 |
{ |
7604 |
25 Feb 19 |
nicklas |
var value = document.forms['zoom'].zoom.value; |
7604 |
25 Feb 19 |
nicklas |
zoomField.value = value; |
7604 |
25 Feb 19 |
nicklas |
// Fire an 'onchange' event |
7604 |
25 Feb 19 |
nicklas |
Events.sendChangeEvent(zoomField); |
7604 |
25 Feb 19 |
nicklas |
zoomField.focus(); |
7604 |
25 Feb 19 |
nicklas |
121 |
} |
7604 |
25 Feb 19 |
nicklas |
window.close(); |
7604 |
25 Feb 19 |
nicklas |
123 |
} |
7604 |
25 Feb 19 |
nicklas |
124 |
|
7604 |
25 Feb 19 |
nicklas |
return zoom; |
7604 |
25 Feb 19 |
nicklas |
126 |
}(); |
7604 |
25 Feb 19 |
nicklas |
127 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(Zoom.initPage); |
7604 |
25 Feb 19 |
nicklas |
Doc.addElementInitializer(Zoom.initializeToolbarElements); |
7604 |
25 Feb 19 |
nicklas |
130 |
|