~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/pub/System/TinyMCEPlugin/tinymce/jscripts/tiny_mce/plugins/foswikibuttons/jscripts/attach_src.js

  • Committer: James Michael DuPont
  • Date: 2009-07-18 19:58:49 UTC
  • Revision ID: jamesmikedupont@gmail.com-20090718195849-vgbmaht2ys791uo2
added foswiki

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2007 Crawford Currie http://wikiring.com and Arthur Clemens
 
3
  All Rights Reserved.
 
4
 
 
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.
 
10
 
 
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.
 
14
 
 
15
  As per the GPL, removal of this notice is prohibited.
 
16
*/
 
17
function initAttachDialog() {
 
18
        tinyMCEPopup.resizeToInnerSize();
 
19
}
 
20
 
 
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";
 
29
 
 
30
    var request = (tinyMCE.isIE) ?
 
31
        new ActiveXObject("Microsoft.XMLHTTP") :
 
32
        new XMLHttpRequest();
 
33
    request.open("POST", url, true);
 
34
    request.setRequestHeader(
 
35
        "Content-type", "application/x-www-form-urlencoded");
 
36
 
 
37
    var path = FoswikiTiny.getFoswikiVar("WEB") + '.' 
 
38
        + FoswikiTiny.getFoswikiVar("TOPIC");
 
39
    var params = "nocache=" + encodeURIComponent((new Date()).getTime())
 
40
        + "&topic=" + encodeURIComponent(path);
 
41
    
 
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);
 
47
    };
 
48
    request.send(params);
 
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');
 
54
    el.value = path;
 
55
}
 
56
 
 
57
// Callback to handle an attachment list
 
58
function attachmentListCallback(request) {
 
59
    if (request.readyState == 4) {
 
60
        // only if "OK"
 
61
        if (request.status == 200) {
 
62
            var atts = request.responseText;
 
63
            if (atts != null) {
 
64
                atts = eval(atts);
 
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);
 
68
                }
 
69
            }
 
70
        } else {
 
71
            alert("There was a problem retrieving the attachments list: "
 
72
                  + request.statusText);
 
73
        }
 
74
    }
 
75
}
 
76
 
 
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(".");
 
84
    if (tmp >= 0)
 
85
        tmp = filename.substring(tmp + 1, filename.length).toLowerCase();
 
86
 
 
87
    var html;
 
88
    if (tmp == "jpg" || tmp == "gif" || tmp == "jpeg" ||
 
89
        tmp == "png" || tmp == "bmp") {
 
90
        html = "<img src='" + url + "' alt='" + filename + "'>";
 
91
    } else {
 
92
        html = "<a href='" + url + "'>" + filename + "</a>";
 
93
    }
 
94
    tinyMCEPopup.execCommand('mceBeginUndoLevel');
 
95
    tinyMCE.execCommand('mceInsertContent', false, html);
 
96
    tinyMCE.triggerNodeChange();
 
97
    tinyMCEPopup.execCommand('mceEndUndoLevel');
 
98
 
 
99
        tinyMCEPopup.close();
 
100
}
 
101