File "urlState.js"
Full path: E:/sites/Single15/tinmung2007/webroot/Tin VUI_BUON/Khan Tron/album/res/urlState.js
File size: 7.17 KiB (7340 bytes)
MIME-type:
Charset: utf-8
/* PUBLIC:
* getUrlArguments()
* function getUrl()
*/
/* === PUBLIC FUNCTION ===
* Use this function to read the URL.
* Returns the location defining part of the URL. I.e. the part before the '?'.
*/
function getUrl() {
//document.write('<p>getUrl()' + '</p>');
//document.write('===> ' + ", document.URL = " + document.URL + "<br>"); //URL is OK for Netscape, not for IE becuase IE does not give the part behind the '?'.
//document.write('===> ' + ", document.location = " + document.location + "<br>"); //Not a String object.
//document.write('===> ' + ", document.location.href = " + document.location.href + "<br>"); //String object. OK for both NS and IE. But it's is deprecated (replace by URL).
//docLoc = document.location.href; //Get the URL as a string.
//document.write('<p>===> </p>');
//document.write('===> ' + ', docLoc = ' + docLoc + '</p>');
questmarkPos = docLoc.indexOf('?');
//document.write('===> ' + ", questmarkPos = " + questmarkPos + "<br>");
if (questmarkPos > -1) {
//document.write('=== ===> questmarkPos > -1<br>');
return docLoc.substring(0, questmarkPos);
}
else {
//document.write('=== ===> questmarkPos = -1<br>');
return docLoc;
}
}
/* === PUBLIC FUNCTION ===
* Use this function to read the protocol.
* Returns the protocol part of the URL.
*/
function getProtocol() {
//document.write("getProtocol()" + "<br>");
return document.location.protocol;
}
/* === PUBLIC FUNCTION ===
* Use this function to read the protocol.
* Returns the protocol part of the URL.
*/
function getPathname() {
//document.write("getPathname()" + "<br>");
return document.location.pathname;
}
/* === PUBLIC FUNCTION ===
* Set to default of not present.
*/
function setDefaultUrlArgument(aKey, aValue) {
//document.write('<p>setDefaultUrlArgument(' + aKey + ', ' + aValue + '): theUrlArguments.get(aKey): ' + theUrlArguments.get(aKey) + '</p>');
theUrlArguments.insert(aKey, aValue);
}
/* === PUBLIC FUNCTION ===
*/
function setOwnAsReferrer() {
//document.write('<p>setOwnAsReferrer()</p>');
theUrlArguments.set("referrer", getUrl());
}
function setEntryReferrerAsReferrer() {
//document.write('<p>setEntryReferrerAsReferrer()</p>');
theUrlArguments.set("referrer", theReferrer);
}
function setClearReferrerAsReferrer() {
//document.write('<p>setClearReferrerAsReferrer()</p>');
theUrlArguments.set("referrer", "");
}
/* === PUBLIC FUNCTION ===
*/
function makeDestinationUrl(aSetReferrer, theUrl) {
if (aSetReferrer == 1) {
setOwnAsReferrer();
}
else if (aSetReferrer == 2) {
setEntryReferrerAsReferrer();
}
else if (aSetReferrer == 3) {
setClearReferrerAsReferrer();
}
return theUrl + theUrlArguments.toStringKeyValuePairs();
}
/* === PUBLIC FUNCTION ===
* Use this function to navigate.
*/
function insertLink(aSetReferrer, theUrl, theName) {
document.write('<a href="' + makeDestinationUrl(aSetReferrer, theUrl) + '">' + theName + '</a>');
//document.write(' ' + makeDestinationUrl(aSetReferrer, theUrl));
}
/* === PUBLIC FUNCTION ===
* Use this function to navigate.
*/
function insertActionLink(aSetReferrer) {
document.write('<form method="get" action="' + makeDestinationUrl(aSetReferrer, "") + '">');
//document.write('Form destination URL = [' + makeDestinationUrl(aSetReferrer, "") + ']');
}
/* === PUBLIC FUNCTION ===
* Use this function to navigate.
*/
function goToA(aSetReferrer, theUrl) {
document.location.href = makeDestinationUrl(aSetReferrer, theUrl);
}
/* === PUBLIC FUNCTION ===
*/
function getOwnLoc() {
return document.location.href;
}
/* === PUBLIC FUNCTION ===
*/
function getReferrerLoc() {
return theUrlArguments.get("referrer");
}
/* === PUBLIC FUNCTION ===
*/
function getEntryReferrerLoc() {
return theReferrer;
}
//////////////////////////////////////////////////////////
function numberOfUrlArguments() {
return theUrlArguments.getLength();
}
function makeFormFieldOptionHtml(aName, aValue) {
var tmpString = "";
var itsSelected = "";
if (theUrlArguments.get(aName) == aValue) {
itsSelected = "selected";
}
tmpStr = '<option value="' + aValue + '" ' + itsSelected + '>' + aValue + ' ';
//document.write('<option value="1"> V1<option value="2" selected>V2 <option value="3">V3');
return tmpStr;
}
function makeFormFieldRadioHtml(aName, aValue) {
var tmpString = "";
var itsChecked = "";
if (theUrlArguments.get(aName) == aValue) {
itsChecked = "checked";
}
tmpStr = '<input type="radio" name="' + aName + '" value="' + aValue + '" ' + itsChecked + '>';
return tmpStr;
}
function makeFormFieldHtml(aType, aName, aSize) {
var tmpString = "";
if (aType == "text") {
tmpStr = '<input type="text" name="' + aName + '" value="' + theUrlArguments.get(aName) + '" size="' + aSize + '">';
}
else if (aType == "checkbox") {
if (theUrlArguments.get(aName) != 'no') {
tmpStr = '<input type="checkbox" name="' + aName + '" value="' + theUrlArguments.get(aName) + '" checked>';
}
else {
tmpStr = '<input type="checkbox" name="' + aName + '" value="' + 'yes' + '">';
}
}
else if (aType == "hidden") {
tmpStr = '<input type="hidden" name="' + aName + '" value="' + theUrlArguments.get(aName) + '">';
}
else {
tmpStr = 'ERROR: makeFormFieldHtml: Unknown type.';
}
return tmpStr;
}
/* === PUBLIC FUNCTION ===
* Use this function to read the URL arguments into an array. Part behind the '?'.
*/
function getUrlArguments() {
//document.write("getUrlArguments()" + "<br>");
//document.write('===> ' + ", document.URL = " + document.URL + "<br>"); //URL is OK for Netscape, not for IE becuase IE does not give the part behind the '?'.
//document.write('===> ' + ", document.location = " + document.location + "<br>"); //Not a String object.
//document.write('===> ' + ", document.location.href = " + document.location.href + "<br>"); //String object. OK for both NS and IE. But it's is deprecated (replace by URL).
docLoc = document.location.href; //Get the URL as a string.
//document.write('===> ' + ", docLoc = " + docLoc + "<br>");
questmarkPos = docLoc.indexOf('?');
//document.write('===> ' + ", questmarkPos = " + questmarkPos + "<br>");
if (questmarkPos > -1) {
myString = docLoc.substring(questmarkPos + 1, docLoc.length);
//document.write('===> ' + myString + ", myString.length = " + myString.length + "<br>");
theUrlArguments.fromStringKeyValuePairs(myString);
}
//Extract special arguments.
theReferrer = getReferrerLoc();
//document.write('<p>=== === ===> The referrer: ' + theReferrer + "</p>");
}
/*
*Go to URL, with own set as referrer..
*/
function goTo(url) {
url = makeDestinationUrl(1, url);
document.location.href = url;
}
//////
//Storage for the URL arguments.
theUrlArguments = new MyArray();
//Keep the referrer at entry of the URL arguments set of pages.
//This is normally the address to go back to.
theReferrer = "";
docLoc = "";
//
getUrlArguments();
// ===