adding a resource (small hack, but works great)

adding a resource (small hack, but works great)

by Khaled Zamani -
Number of replies: 0
Hi everyone,

A small but useful functionality.

When linking to a file in (Add a resource) the name of the resource is automatically the filename. Of course you can change it to what ever you want, but if you give your files good names this helps a lot. This is tested and works with 1.9.3+ (Build: 20080730)

Things to do:

Edit ---> file\index.php
Change the javascript beginning at line 100 to

function cleantext(ptxt, pchar1, pchar2){
var atpos;
var myArray = ptxt.toLowerCase().split('');
for (i=0;i<myArray.length;i++)
{
atpos = ptxt.indexOf(pchar1);
if (myArray[i] == pchar1)
{
if (atpos > -1) {
ptxt = ptxt.substring(atpos+1, ptxt.length);
}
}
}


var atpos2 = ptxt.indexOf(pchar2);
if (atpos2 > -1){
ptxt = ptxt.substring(0, atpos2);
}
return ptxt;
}

function set_value(txt) {
opener.document.getElementById('<?php echo $chooseparts[0] ?>').value = txt;
vtxt1 = cleantext(txt, "/", ".");
opener.document.getElementById('name').value = vtxt1;
window.close();
}

This code works with any directory depth.
Example: when you link to a file from folder xxx/yyy/zzz/file.doc the name of the resource will be (file) without the name of the direcoties and extention.

MDL-17126
Average of ratings: -