source: trunk/plugins/ExtendedFileManager/assets/images.js @ 799

Last change on this file since 799 was 799, checked in by ray, 12 years ago

Ticket #908 Prompts broken in IE7: fixed for EFM & ImageManager?

  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 10.5 KB
Line 
1/**
2 * Functions for the image listing, used by images.php only
3 * Authors: Wei Zhuo, Afru, Krzysztof Kotowicz, Raimund Meyer
4 * Version: Updated on 08-01-2005 by Afru
5 * Version: Updated on 04-07-2006 by Krzysztof Kotowicz
6 * Version: Updated on 17-11-2006 by Raimund Meyer
7 * Package: ExtendedFileManager (EFM 1.1.3)
8 * http://www.afrusoft.com/htmlarea
9 */
10
11function i18n(str) {
12    return Xinha._lc(str, 'ExtendedFileManager');
13}
14
15function changeDir(newDir)
16{
17    showMessage('Loading');
18    var mode=window.top.document.getElementById('manager_mode').value;
19    var selection = window.top.document.getElementById('viewtype');
20    var viewtype = selection.options[selection.selectedIndex].value;
21    location.href = _backend_url + "__function=images&mode="+mode+"&dir="+newDir+"&viewtype="+viewtype;
22        document.cookie = "EFMStartDir" + mode + "="+newDir;
23}
24
25function newFolder(dir, newDir)
26{
27    var mode=window.top.document.getElementById('manager_mode').value;
28    var selection = window.top.document.getElementById('viewtype');
29    var viewtype = selection.options[selection.selectedIndex].value;
30    location.href = _backend_url + "__function=images&mode="+mode+"&dir="+dir+"&newDir="+newDir+"&viewtype="+viewtype;
31}
32
33function renameFile(oldPath) {
34 // strip directory and extension
35  var oldName=oldPath.replace(/.*%2F/,'').replace(/\..*$/,'');
36 
37  var rename = function (newName)
38  {
39    if(newName == '' || newName == null || newName == oldName)
40    {
41        alert(i18n('Cancelled rename.'));
42        return false;
43    }
44    var mode=window.top.document.getElementById('manager_mode').value;
45    var selection = window.top.document.getElementById('dirPath');
46    var dir = selection.options[selection.selectedIndex].value;
47    selection = window.top.document.getElementById('viewtype');
48    var viewtype = selection.options[selection.selectedIndex].value;
49    location.href = _backend_url + "__function=images&mode="+mode+"&dir="+dir+"&rename="+oldPath+"&renameTo="+newName+"&viewtype="+viewtype;
50  }
51 
52   // IE7 has crippled the prompt()
53  if ( Xinha.ie_version > 6 )
54  {
55    popupPrompt(i18n("Please enter new name for this file..."), oldName, rename, i18n("Rename"));
56  }
57  else
58  {
59    var newName = prompt(i18n('Please enter new name for this file...'), oldName);
60    rename(newName);
61  }
62}
63function renameDir(oldName)
64{
65  // strip directory and extension
66
67  function rename(newName)
68  {
69    if(newName == '' || newName == null || newName == oldName)
70    {
71      alert(i18n('Cancelled rename.'));
72      return false;
73    }
74    var mode=window.top.document.getElementById('manager_mode').value;
75    var selection = window.top.document.getElementById('dirPath');
76    var dir = selection.options[selection.selectedIndex].value;
77    selection = window.top.document.getElementById('viewtype');
78    var viewtype = selection.options[selection.selectedIndex].value;
79    location.href = _backend_url + "__function=images&mode="+mode+"&dir="+dir+"&rename="+oldName+"&renameTo="+newName+"&viewtype="+viewtype;
80  }
81 
82  // IE7 has crippled the prompt()
83  if ( Xinha.ie_version > 6 )
84  {
85    popupPrompt(i18n('Please enter new name for this folder...'), oldName, rename, i18n("Rename"));
86  }
87  else
88  {
89    var newName = prompt(i18n('Please enter new name for this folder...'), oldName);
90    rename(newName);
91  }
92}
93function copyFile(file,action)
94{
95        var selection = window.top.document.getElementById('dirPath');
96    var dir = selection.options[selection.selectedIndex].value;
97        window.top.pasteButton({'dir':dir,'file':file,'action':action+'File'});
98}
99function copyDir(dirToCopy,action)
100{
101        var selection = window.top.document.getElementById('dirPath');
102    var dir = selection.options[selection.selectedIndex].value;
103        window.top.pasteButton({'dir':dir,'file':dirToCopy,'action':action+'Dir'});
104}
105function paste(action)
106{
107    var mode=window.top.document.getElementById('manager_mode').value;
108    var selection = window.top.document.getElementById('dirPath');
109    var dir = selection.options[selection.selectedIndex].value;
110    selection = window.top.document.getElementById('viewtype');
111    var viewtype = selection.options[selection.selectedIndex].value;
112        location.href = _backend_url + "__function=images&mode="+mode+"&dir="+dir+"&paste="+action.action+"&srcdir="+action.dir+"&file="+action.file+"&viewtype="+viewtype;
113}
114//update the dir list in the parent window.
115function updateDir(newDir)
116{
117        var mode = window.top.document.getElementById('manager_mode').value;
118        document.cookie = "EFMStartDir" + mode + "="+newDir;
119   
120        var selection = window.top.document.getElementById('dirPath');
121    if(selection)
122    {
123        for(var i = 0; i < selection.length; i++)
124        {
125            var thisDir = selection.options[i].text;
126            if(thisDir == newDir)
127            {
128                selection.selectedIndex = i;
129                showMessage('Loading');
130                break;
131            }
132        }
133    }
134
135}
136
137function emptyProperties()
138{
139    toggleImageProperties(false);
140    var topDoc = window.top.document;
141    topDoc.getElementById('f_url').value = '';
142    topDoc.getElementById('f_alt').value = '';
143    topDoc.getElementById('f_title').value = '';
144    topDoc.getElementById('f_width').value = '';
145    topDoc.getElementById('f_margin').value = '';
146    topDoc.getElementById('f_height').value = '';
147    topDoc.getElementById('f_padding').value = '';
148    topDoc.getElementById('f_border').value = '';
149    topDoc.getElementById('f_borderColor').value = '';
150    topDoc.getElementById('f_backgroundColor').value = '';
151}
152
153function toggleImageProperties(val)
154{
155    var topDoc = window.top.document;
156    if(val==true)
157    {
158        topDoc.getElementById('f_width').value = '';
159        topDoc.getElementById('f_margin').value = '';
160        topDoc.getElementById('f_height').value = '';
161        topDoc.getElementById('f_padding').value = '';
162        topDoc.getElementById('f_border').value = '';
163        topDoc.getElementById('f_borderColor').value = '';
164        topDoc.getElementById('f_backgroundColor').value = '';
165    }
166    topDoc.getElementById('f_width').disabled = val;
167    topDoc.getElementById('f_margin').disabled = val;
168    topDoc.getElementById('f_height').disabled = val;
169    topDoc.getElementById('f_padding').disabled = val;
170    topDoc.getElementById('f_align').disabled = val;
171    topDoc.getElementById('f_border').disabled = val;
172    topDoc.getElementById('f_borderColor').value = '';
173    topDoc.getElementById('f_backgroundColor').value = '';
174    topDoc.getElementById('constrain_prop').disabled = val;
175}
176
177function selectImage(filename, alt, width, height)
178{
179    var topDoc = window.top.document;
180
181    if(topDoc.getElementById('manager_mode').value=="image")
182    {
183        var obj = topDoc.getElementById('f_url');  obj.value = filename;
184        obj = topDoc.getElementById('f_alt'); obj.value = alt;
185        obj = topDoc.getElementById('f_title'); obj.value = alt;
186
187        if(width==0 && height==0) toggleImageProperties(true);
188        else
189        {
190            toggleImageProperties(false);
191            var obj = topDoc.getElementById('f_width');  obj.value = width;
192            var obj = topDoc.getElementById('f_height'); obj.value = height;
193            var obj = topDoc.getElementById('orginal_width'); obj.value = width;
194            var obj = topDoc.getElementById('orginal_height'); obj.value = height;
195            update_selected();
196        }
197    }
198    else if (topDoc.getElementById('manager_mode').value=="link")
199    {
200        var obj = topDoc.getElementById('f_href');  obj.value = filename;
201        var obj = topDoc.getElementById('f_title'); obj.value = alt;
202    }
203
204    return false;
205}
206
207var _current_selected = null;
208
209function update_selected()
210{
211    var topDoc = window.top.document;
212    if(_current_selected)
213    {
214        _current_selected.className = _current_selected.className.replace(/(^| )active( |$)/, '$1$2');
215        _current_selected = null;
216    }
217    // Grab the current file, and highlight it if we have it
218    var c_file = topDoc.getElementById('f_url').value;
219    var selection = topDoc.getElementById('dirPath');
220    var currentDir = selection.options[selection.selectedIndex].text;
221    var dRe = new RegExp('^(' + currentDir.replace(/([\/\^$*+?.()|{}[\]])/g, '\\$1') + ')([^/]*)$');
222    if(dRe.test(c_file))
223    {
224        var holder = document.getElementById('holder_' + asc2hex(RegExp.$2));
225        if(holder)
226        {
227            _current_selected = holder;
228            holder.className += ' active';
229        }
230    }
231    showPreview(c_file);
232}
233
234function asc2hex(str)
235{
236    var hexstr = '';
237    for(var i = 0; i < str.length; i++)
238    {
239        var hex = (str.charCodeAt(i)).toString(16);
240        if(hex.length == 1) hex = '0' + hex;
241        hexstr += hex;
242    }
243    return hexstr;
244}
245
246function showMessage(newMessage)
247{
248    var topDoc = window.top.document;
249
250    var message = topDoc.getElementById('message');
251    var messages = topDoc.getElementById('messages');
252    if(message && messages)
253    {
254        if(message.firstChild)
255            message.removeChild(message.firstChild);
256
257        message.appendChild(topDoc.createTextNode(i18n(newMessage)));
258
259        messages.style.display = "block";
260    }
261}
262
263function updateDiskMesg(newMessage)
264{
265    var topDoc = window.top.document;
266
267    var diskmesg = topDoc.getElementById('diskmesg');
268    if(diskmesg)
269    {
270        if(diskmesg.firstChild)
271            diskmesg.removeChild(diskmesg.firstChild);
272
273        diskmesg.appendChild(topDoc.createTextNode(newMessage));
274
275    }
276}
277
278function addEvent(obj, evType, fn)
279{
280    if (obj.addEventListener) { obj.addEventListener(evType, fn, true); return true; }
281    else if (obj.attachEvent) {  var r = obj.attachEvent("on"+evType, fn);  return r;  }
282    else {  return false; }
283}
284
285function confirmDeleteFile(file)
286{
287    if(confirm(i18n('Delete file "$file=' + file +'$"?')))
288        return true;
289
290    return false;
291}
292
293function confirmDeleteDir(dir, count)
294{
295   /* if(count > 0)
296    {
297        alert(i18n("Folder is not empty. Please delete all Files and Subfolders inside."));
298        return false;
299    }*/
300
301    if(confirm(i18n('Delete folder "$dir=' + dir +'$"?')))
302        return true;
303
304    return false;
305}
306
307function showPreview(f_url)
308{
309    window.parent.document.getElementById('f_preview').src =
310    f_url ? window.parent._backend_url + '__function=thumbs&img=' + f_url :window.parent.opener._editor_url+'plugins/ExtendedFileManager/img/1x1_transparent.gif';
311}
312
313addEvent(window, 'load', init);
Note: See TracBrowser for help on using the repository browser.