changing spaces or slashes in padnames to underscores

This commit is contained in:
Wikinaut 2011-11-14 20:32:27 +01:00
parent 5ea8dd6b70
commit dc2aafa062

View file

@ -96,7 +96,10 @@
<input type="submit" value="OK">
</form>
</div>
<script>
<script>
// var pathName = "p/";
var pathName = "";
function randomPadName()
{
var chars = "23456789ABCDEFGHJKLMNPQRSTUWXYZabcdefghijkmnopqrstuwxyz";
@ -110,10 +113,14 @@
return randomstring;
}
function encodeSanitizedName( name ) {
return encodeURIComponent( name.replace( /[\/ ]/g, "_") );
}
function go2Name()
{
var padname = document.getElementById("padname").value;
padname.length > 0 ? window.location = /** "p/" + **/ padname : alert("Please enter a name")
padname.length > 0 ? window.location = pathName + encodeSanitizedName( padname ) : alert("Please enter a name")
}
function go2Random()
@ -121,14 +128,14 @@
var rnd = randomPadName();
var prefixedName = prompt( "You can prefix or modify your random pad name with some reasonable characters.\nSpecial characters will be removed or escaped.\n\n", "-"+rnd );
if ( prefixedName == "-" + rnd ) prefixedName = rnd;
var escPrefixedName = encodeURIComponent( prefixedName.replace( /\//, "" ) );
var escPrefixedName = encodeSanitizedName( prefixedName );
if ( prefixedName == null ) return;
if ( prefixedName == decodeURIComponent( escPrefixedName )
|| ( prefixedName != escPrefixedName
&& confirm( "You have used characters which are not allowed in Urls, and the padname will therefore be modified to "
+ decodeURIComponent( escPrefixedName )
+ ".\nDo you want to use this modifed name?" ) ) ) {
window.location = /** "p/" + **/ escPrefixedName;
window.location = pathName + escPrefixedName;
} else {
return;
}