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

« back to all changes in this revision

Viewing changes to MoinMoin/web/static/htdocs/applets/moinFCKplugins/moinimage/fck_image.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
 
/* FCKeditor - The text editor for internet
2
 
 * Copyright (C) 2003-2004 Frederico Caldeira Knabben
3
 
 * 
4
 
 * Licensed under the terms of the GNU Lesser General Public License:
5
 
 *   http://www.opensource.org/licenses/lgpl-license.php
6
 
 * 
7
 
 * For further information visit:
8
 
 *   http://www.fckeditor.net/
9
 
 * 
10
 
 * File Name: fck_image.js
11
 
 *  Scripts related to the Image dialog window
12
 
 * 
13
 
 * File Authors:
14
 
 *   Frederico Caldeira Knabben (fredck@fckeditor.net)
15
 
 *   Florian Festi
16
 
 */
17
 
 
18
 
var dialog      = window.parent ;
19
 
var oEditor  = window.parent.InnerDialogLoaded();
20
 
var FCK   = oEditor.FCK;
21
 
var FCKLang  = oEditor.FCKLang;
22
 
var FCKConfig = oEditor.FCKConfig;
23
 
 
24
 
var UriProtocol = new RegExp('');
25
 
UriProtocol.compile('^((http|https):\/\/|attachment:|drawing:|)', 'gi');
26
 
var UrlOnChangeProtocol = new RegExp('');
27
 
UrlOnChangeProtocol.compile('^(http|https)://(?=.)|attachment:|drawing:', 'gi');
28
 
 
29
 
var oImage = FCK.Selection.GetSelectedElement() ;
30
 
if ( oImage && oImage.tagName != 'IMG')
31
 
 oImage = null;
32
 
 
33
 
// Get the active link.
34
 
var oLink = dialog.Selection.GetSelection().MoveToAncestorNode( 'A' ) ;
35
 
if ( oLink )
36
 
        FCK.Selection.SelectNode( oLink ) ;
37
 
 
38
 
window.onload = function()
39
 
{
40
 
  // Load the selected element information (if any).
41
 
  LoadSelection();
42
 
 
43
 
  // Update UI
44
 
  OnProtocolChange();
45
 
 
46
 
  // Activate the "OK" button.
47
 
  window.parent.SetOkButton( true ) ;
48
 
 
49
 
  // select first text input element of dialog for usability
50
 
  SelectField('txtUrl');
51
 
}
52
 
 
53
 
function LoadSelection()
54
 
{
55
 
  if (!oImage) return ;
56
 
  var sUrl = GetAttribute(oImage, 'src', '');
57
 
  var sTitle = GetAttribute(oImage, 'title', '');
58
 
 
59
 
  if (sTitle) sUrl = sTitle;
60
 
 
61
 
  // Search for the protocol.
62
 
  var sProtocol = UriProtocol.exec(sUrl);
63
 
 
64
 
  if (sProtocol)
65
 
  {
66
 
    sProtocol = sProtocol[0].toLowerCase();
67
 
    GetE('cmbLinkProtocol').value = sProtocol;
68
 
 
69
 
    // Remove the protocol and get the remainig URL.
70
 
    sUrl = sUrl.replace(UriProtocol, '');
71
 
  }
72
 
 
73
 
  GetE('txtUrl').value = decodeUrl(sUrl);
74
 
 
75
 
  if (oLink) 
76
 
    GetE('chkLink').checked = 1;
77
 
  else
78
 
    GetE('chkLink').checked = 0;
79
 
}
80
 
 
81
 
function OnProtocolChange()
82
 
83
 
  var sProtocol = GetE('cmbLinkProtocol').value;
84
 
  ShowE('divChkLink', (sProtocol!='attachment:' && sProtocol!='drawing:'));
85
 
  // select first text input element of dialog for usability
86
 
  SelectField('txtUrl');
87
 
}
88
 
 
89
 
//#### Called while the user types the URL.
90
 
function OnUrlChange()
91
 
{
92
 
 var sUrl = GetE('txtUrl').value;
93
 
 var sProtocol = UrlOnChangeProtocol.exec(sUrl);
94
 
 
95
 
 if (sProtocol)
96
 
 {
97
 
  sUrl = sUrl.substr(sProtocol[0].length);
98
 
  GetE('txtUrl').value = sUrl;
99
 
  GetE('cmbLinkProtocol').value = sProtocol[0].toLowerCase();
100
 
 }
101
 
}
102
 
 
103
 
function getAttachUrl(sUrl)
104
 
{
105
 
  // XXX assumes attachments are not served directly!!!
106
 
  var iIdx = sUrl.lastIndexOf('/');
107
 
  var sPage = "";
108
 
  if (iIdx != -1)
109
 
  {
110
 
    sPage = sUrl.substring(0, iIdx);
111
 
    sUrl = sUrl.substring(iIdx+1, sUrl.length);
112
 
  } else
113
 
  {
114
 
    sPage = FCKConfig['WikiPage'];
115
 
  }
116
 
  return FCKConfig['WikiBasePath'] + sPage + 
117
 
          "?action=AttachFile&do=get&target=" + sUrl;
118
 
}
119
 
 
120
 
//#### The OK button was hit.
121
 
function Ok()
122
 
{
123
 
  if ( GetE('txtUrl').value.length == 0 )
124
 
  {
125
 
     window.parent.SetSelectedTab( 'Info' ) ;
126
 
     GetE('txtUrl').focus() ;
127
 
     alert( oEditor.FCKLang.DlgImgAlertUrl ) ;
128
 
     return false ;
129
 
  } 
130
 
 
131
 
  if (oImage==null)
132
 
  {
133
 
    oImage = FCK.CreateElement('IMG');
134
 
    oEditor.FCKSelection.SelectNode(oImage);
135
 
  }
136
 
 
137
 
  var sProtocol = GetE('cmbLinkProtocol').value;
138
 
  var sTitle = '';
139
 
  var sSrc = GetE('txtUrl').value;
140
 
 
141
 
  if (sProtocol!='drawing:')
142
 
  {
143
 
    // Check for valid image Url
144
 
    var sEnd = sSrc.substring(sSrc.length-4, sSrc.length).toLowerCase();
145
 
    if (!(sEnd==".gif" || sEnd=='.png' || sEnd=='.jpg' || sSrc.substring(sSrc.length-5, sSrc.length).toLowerCase()=='.jpeg'))
146
 
    {
147
 
      alert("Image Url must end with .gif, .png, .jpg or .jpeg"); //XXX i18n!
148
 
      return false;
149
 
    }
150
 
  }
151
 
 
152
 
  if (sProtocol=='attachment:' || sProtocol=='drawing:')
153
 
  {
154
 
    sTitle = sProtocol + encodeUrl(sSrc);
155
 
    if (sProtocol=='drawing:')
156
 
      sSrc = sSrc + '.png';
157
 
    sSrc = getAttachUrl(encodeUrl(sSrc));
158
 
  } else
159
 
  {
160
 
    sSrc = sProtocol + encodeUrl(sSrc);
161
 
    
162
 
    // Link image
163
 
    if (GetE('chkLink').checked)
164
 
    {
165
 
      if (!oLink) 
166
 
        oLink = oEditor.FCK.CreateLink(sSrc);
167
 
      else
168
 
        oLink.src = sSrc;
169
 
    } else
170
 
    {
171
 
      if (oLink) FCK.ExecuteNamedCommand('Unlink');
172
 
    }
173
 
  }
174
 
  oImage.src = sSrc;
175
 
  oImage.title = sTitle;
176
 
 
177
 
  return true;
178
 
}
179