2
Copyright (C) 2007 Crawford Currie http://wikiring.com and Arthur Clemens
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 2
8
of the License, or (at your option) any later version. For
9
more details read LICENSE in the root of the Foswiki distribution.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
As per the GPL, removal of this notice is prohibited.
17
function initAttachDialog() {
18
tinyMCEPopup.resizeToInnerSize();
21
// Done separately from initAttachDialog because it gets called in the
22
// wrong place in Safari otherwise
23
function getAttachInfo() {
24
// Work out the rest URL from the location
25
var scripturl = FoswikiTiny.getFoswikiVar("SCRIPTURL");
26
var suffix = FoswikiTiny.getFoswikiVar("SCRIPTSUFFIX");
27
if (suffix == null) suffix = '';
28
var url = scripturl + "/rest" + suffix + "/WysiwygPlugin/attachments";
30
var request = (tinyMCE.isIE) ?
31
new ActiveXObject("Microsoft.XMLHTTP") :
33
request.open("POST", url, true);
34
request.setRequestHeader(
35
"Content-type", "application/x-www-form-urlencoded");
37
var path = FoswikiTiny.getFoswikiVar("WEB") + '.'
38
+ FoswikiTiny.getFoswikiVar("TOPIC");
39
var params = "nocache=" + encodeURIComponent((new Date()).getTime())
40
+ "&topic=" + encodeURIComponent(path);
42
request.setRequestHeader("Content-length", params.length);
43
/* Banjaxes NTLM - see http://foswiki.org/Tasks/Item5859 for analysis
44
request.setRequestHeader("Connection", "close"); */
45
request.onreadystatechange = function() {
46
attachmentListCallback(request);
49
// Write the correct action into the form in attach.htm
50
var el = document.getElementById('upload_form');
51
el.action = scripturl + "/rest" + suffix +
52
"/WysiwygPlugin/upload";
53
el = document.getElementById('upload_form_topic');
57
// Callback to handle an attachment list
58
function attachmentListCallback(request) {
59
if (request.readyState == 4) {
61
if (request.status == 200) {
62
var atts = request.responseText;
65
var select = document.getElementById("attachments_select");
66
for (var i = 0; i < atts.length; i++) {
67
select.options[i] = new Option(atts[i].name, atts[i].name);
71
alert("There was a problem retrieving the attachments list: "
72
+ request.statusText);
77
// Insert a link to the selected attachment in the text
78
function insertLink() {
79
var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id'));
80
var select = document.getElementById("attachments_select");
81
var filename = select.value;
82
var url = FoswikiTiny.getFoswikiVar("ATTACHURL") + '/' + filename;
83
var tmp = filename.lastIndexOf(".");
85
tmp = filename.substring(tmp + 1, filename.length).toLowerCase();
88
if (tmp == "jpg" || tmp == "gif" || tmp == "jpeg" ||
89
tmp == "png" || tmp == "bmp") {
90
html = "<img src='" + url + "' alt='" + filename + "'>";
92
html = "<a href='" + url + "'>" + filename + "</a>";
94
tinyMCEPopup.execCommand('mceBeginUndoLevel');
95
tinyMCE.execCommand('mceInsertContent', false, html);
96
tinyMCE.triggerNodeChange();
97
tinyMCEPopup.execCommand('mceEndUndoLevel');