~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to wiki/htdocs/applets/moinFCKplugins/moinattachment/fck_attachment.js

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
Import upstream version 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * FCKeditor - The text editor for internet
 
3
 * Copyright (C) 2003-2004 Frederico Caldeira Knabben
 
4
 * 
 
5
 * Licensed under the terms of the GNU Lesser General Public License:
 
6
 *   http://www.opensource.org/licenses/lgpl-license.php
 
7
 * 
 
8
 * For further information visit:
 
9
 *   http://www.fckeditor.net/
 
10
 * 
 
11
 * File Name: fck_attachment.js
 
12
 *  Scripts related to the Attachment dialog window.
 
13
 * 
 
14
 * Version:  2.0
 
15
 * Modified: 2005-03-12 15:16:39
 
16
 * 
 
17
 * File Authors:
 
18
 *   Frederico Caldeira Knabben (fredck@fckeditor.net)
 
19
 */
 
20
 
 
21
var oEditor  = window.parent.InnerDialogLoaded();
 
22
var FCK   = oEditor.FCK;
 
23
var FCKLang  = oEditor.FCKLang;
 
24
var FCKConfig = oEditor.FCKConfig;
 
25
 
 
26
//#### Dialog Tabs
 
27
 
 
28
// Set the dialog tabs.
 
29
window.parent.AddTab('Info', FCKLang.DlgLnkInfoTab);
 
30
 
 
31
// Function called when a dialog tag is selected.
 
32
function OnDialogTabChange(tabCode)
 
33
{
 
34
 ShowE('divInfo'  , (tabCode == 'Info'));
 
35
}
 
36
 
 
37
//#### Regular Expressions library.
 
38
var oRegex = new Object();
 
39
 
 
40
oRegex.UriProtocol = new RegExp('');
 
41
oRegex.UriProtocol.compile('^(((http|https|ftp|news):\/\/)|mailto:)', 'gi');
 
42
 
 
43
oRegex.UrlOnChangeProtocol = new RegExp('');
 
44
oRegex.UrlOnChangeProtocol.compile('^(http|https|ftp|news)://(?=.)', 'gi');
 
45
 
 
46
oRegex.UrlOnChangeTestOther = new RegExp('');
 
47
oRegex.UrlOnChangeTestOther.compile('^(javascript:|#|/)', 'gi');
 
48
 
 
49
oRegex.ReserveTarget = new RegExp('');
 
50
oRegex.ReserveTarget.compile('^_(blank|self|top|parent)$', 'i');
 
51
 
 
52
//#### Parser Functions
 
53
 
 
54
var oParser = new Object();
 
55
 
 
56
//#### Initialization Code
 
57
 
 
58
// oLink: The actual selected link in the editor.
 
59
var oLink = FCK.Selection.MoveToAncestorNode('A');
 
60
if (oLink)
 
61
 FCK.Selection.SelectNode(oLink);
 
62
 
 
63
window.onload = function()
 
64
{
 
65
 // Translate the dialog box texts.
 
66
 oEditor.FCKLanguageManager.TranslatePage(document);
 
67
 
 
68
 // Load the selected link information (if any).
 
69
 LoadSelection();
 
70
 
 
71
 // Show the initial dialog content.
 
72
 GetE('divInfo').style.display = '';
 
73
 
 
74
 // Activate the "OK" button.
 
75
 window.parent.SetOkButton(true);
 
76
}
 
77
 
 
78
function LoadSelection()
 
79
{
 
80
 if (!oLink) return;
 
81
 
 
82
 if (oLink.getAttribute('title') && 
 
83
          oLink.getAttribute('title').startsWith('attachment:'))
 
84
 {
 
85
  GetE('txtAttachmentname').value = decodeUrl(
 
86
     oLink.getAttribute('title').remove(0, 'attachment:'.length));
 
87
 }
 
88
 
 
89
}
 
90
 
 
91
//#### Link type selection.
 
92
function SetLinkType(linkType)
 
93
{
 
94
 ShowE('divLinkTypeAttachment' , (linkType == 'attachment'));
 
95
}
 
96
 
 
97
//#### Called when user selects Wikipage.
 
98
function OnChangePagename(pagename)
 
99
{
 
100
  GetE("txtPagename").value = pagename;
 
101
}
 
102
 
 
103
//#### Called while the user types the URL.
 
104
function OnUrlChange()
 
105
{
 
106
 var sUrl = GetE('txtUrl').value;
 
107
 var sProtocol = oRegex.UrlOnChangeProtocol.exec(sUrl);
 
108
 
 
109
 if (sProtocol)
 
110
 {
 
111
  sUrl = sUrl.substr(sProtocol[0].length);
 
112
  GetE('txtUrl').value = sUrl;
 
113
 }
 
114
 else if (oRegex.UrlOnChangeTestOther.test(sUrl))
 
115
 {
 
116
  GetE('cmbLinkProtocol').value = '';
 
117
 }
 
118
}
 
119
 
 
120
//#### The OK button was hit.
 
121
function Ok()
 
122
{
 
123
 var sUri;
 
124
 var sText = '';
 
125
 
 
126
   sUri = GetE('txtAttachmentname').value;
 
127
   if (sUri.length == 0)
 
128
   {
 
129
    alert(FCKLang.DlnLnkMsgNoUrl);
 
130
    return false;
 
131
   }
 
132
   sText = sUri;
 
133
   sUri = encodeUrl(sUri);
 
134
 
 
135
 if (oLink) // Modifying an existent link.
 
136
  oLink.href = sUri;
 
137
 else   // Creating a new link.
 
138
 {
 
139
  oLink = oEditor.FCK.CreateLink(sUri);
 
140
  if (! oLink)
 
141
  {
 
142
    oLink = oEditor.FCK.CreateElement('A');
 
143
    oLink.href = sUri;
 
144
    oLink.appendChild(oEditor.FCK.EditorDocument.createTextNode(sText)); 
 
145
  }
 
146
 }
 
147
 
 
148
  SetAttribute(oLink, 'title', 'attachment:' + sUri);
 
149
 
 
150
 return true;
 
151
}
 
152
 
 
153
function SetUrl(url)
 
154
{
 
155
 document.getElementById('txtUrl').value = url;
 
156
 OnUrlChange();
 
157
}
 
158