152 lines
4.3 KiB
JavaScript
152 lines
4.3 KiB
JavaScript
// now for the AJAX stuff .... first we need an XMLHTTP object
|
|
|
|
var http = false;
|
|
if (window.XMLHttpRequest) { // Mozilla, Safari,...
|
|
http = new XMLHttpRequest();
|
|
if (http.overrideMimeType) {
|
|
http.overrideMimeType('text/xml');
|
|
}
|
|
} else if (window.ActiveXObject) { // IE
|
|
try {
|
|
http = new ActiveXObject("Msxml2.XMLHTTP");
|
|
} catch (e) {
|
|
try {
|
|
http = new ActiveXObject("Microsoft.XMLHTTP");
|
|
} catch (e) {
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!http) {
|
|
alert('Cannot create an XMLHTTP instance');
|
|
}
|
|
|
|
|
|
function initContextMenu() {
|
|
// check whether user is logged into CMS and if so, create a DIV to display
|
|
// the link to the CMS mini-menu if the DIV doesn't already exist
|
|
if (loggedIntoCMS()) {
|
|
if (!document.getElementById('contextHeaderDiv')) {
|
|
// for menu toggling, put <a href='#' onclick='javascript:showOrHideMenu();'></a>
|
|
// around the <span>..</span> below and change the showOrHideMenu()
|
|
document.body.insertAdjacentHTML("afterBegin",
|
|
"<div id='contextDiv'> \
|
|
<div id='contextHeaderDiv'><span id='menuHeader'>CMS MENU</span><br>(Only shows for CMS users)</div> \
|
|
<div id='contextMenuDiv' style='display:none'></div> \
|
|
<div id='helpText' style='display:none'><br>This menu allows you to open any viewed static page, product & product category, article or article category in the CMS for your country. This menu is a beta-version, please report any issues.<br> <a href='javascript:toggleHelp()'><br><strong>Close Help</strong></a></div> \
|
|
<div id='helpLink' style='display:block' align='right'> <a href='javascript:toggleHelp()'><br><strong>Help</strong></a></div> \
|
|
</div>");
|
|
showOrHideMenu();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function toggleHelp() {
|
|
if (helpText.style.display=="none") {
|
|
helpText.style.display="block";
|
|
helpText.focus();
|
|
helpLink.style.display="none";
|
|
} else {
|
|
helpText.style.display="none";
|
|
helpLink.style.display="block";
|
|
}
|
|
}
|
|
|
|
|
|
function showOrHideMenu() {
|
|
var divToShow, getMenuContents;
|
|
|
|
divToShow = document.getElementById('contextMenuDiv');
|
|
|
|
// changed to remove possibility of menu toggling
|
|
// to put it back, uncommment below and add onclick handler back in initContextMenu function
|
|
// if (divToShow.style.display=="none") {
|
|
getMenuContents = menuHTML();
|
|
divToShow.style.display="block";
|
|
divToShow.focus();
|
|
// } else {
|
|
// divToShow.style.display="none";
|
|
// }
|
|
}
|
|
|
|
|
|
function menuHTML() {
|
|
// send request to Perl script, forwarding URL parameters, and await returned result
|
|
try {
|
|
http.open('GET','?ajaxModule=1&mode=getContextMenu&'+window.top.location.search.substring(1),true);
|
|
http.onreadystatechange = showContextMenu;
|
|
http.send(null);
|
|
} catch(e) {
|
|
alert('failed to do http open');
|
|
}
|
|
}
|
|
|
|
|
|
function showContextMenu() {
|
|
try {
|
|
if(http.readyState == 4){
|
|
if (http.status == 200){
|
|
var response = http.responseText;
|
|
document.getElementById('contextMenuDiv').innerHTML = response;
|
|
} else {
|
|
alert("There was a problem with the AJAX request, http status = "+http.status);
|
|
}
|
|
}
|
|
} catch(e) {
|
|
alert('showContextMenu never ready ');
|
|
}
|
|
}
|
|
|
|
|
|
function showInCMS(URL){
|
|
// called when context menu item is clicked, to open URL in content2 frame of CMS window
|
|
winHandle = window.open('','CMSWINDOW');
|
|
if(winHandle.content2) {
|
|
// CMS window is there, but ensure user is still logged in!!!
|
|
if (loggedIntoCMS()) {
|
|
winHandle.content2.location.href = URL;
|
|
} else {
|
|
alert("You are not logged into the CMS!!");
|
|
}
|
|
} else {
|
|
winHandle.close();
|
|
alert("CMS window is not open!!");
|
|
}
|
|
}
|
|
|
|
|
|
function loggedIntoCMS() {
|
|
if (document.cookie.indexOf("CookieUserToken") != -1) {
|
|
if (readCookie("CookieUserToken")) {
|
|
return 1;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
function readCookie(name) {
|
|
var nameEQ = name + "=";
|
|
var ca = document.cookie.split(';');
|
|
for(var i=0;i < ca.length;i++) {
|
|
var c = ca[i];
|
|
while (c.charAt(0)==' ') c = c.substring(1,c.length);
|
|
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
function changeCity() {
|
|
// keep this here for now as an example of how to encode the URL parameters properly
|
|
|
|
try {
|
|
http.open('GET', '?targetModule=users&mode=getDealers&dealerCity='+encodeURIComponent(document.getElementById('dealerCity').value),true);
|
|
http.onreadystatechange = showDealers;
|
|
http.send(null);
|
|
} catch(e) {
|
|
}
|
|
}
|
|
|