[update] I solved this by inbuilt modx calendar and it’s associated javascript. I ditched this one. I am having a MySQL bug when ever a document is unpublished now. I’ll post that on another thread after I go through some more testing and research.
Hi there,
Are there any docs on the standards to allow the Ajax code to run without screwing up the quickedit menu? I’m sure this is breaking some ModX code rules and I’ve just started to create a snippet from the code here:
http://www.vbforums.com/showthread.php?t=397994
It is working in principle but I’ve got a little way to go before I can implement a publish and unpublish option within my newspublisher code.
I’ve made a chunk with the following HTML
<html>
<head>
<style>
#calenderSelect_one
{
background: #000000;
}
.calender_one td
{
width: 25px;
height: 25px;
background: #CFCFCF;
text-align: center;
}
.calender_one th
{
width: 25px;
height: 25px;
background: #B3B3B3;
}
#calenderSelect_two
{
background: #000000;
}
.calender_two td
{
width: 25px;
height: 25px;
background: #CFCFCF;
text-align: center;
}
.calender_two th
{
width: 25px;
height: 25px;
background: #B3B3B3;
}
</style>
</head>
<body>
<script>
function selectDate_one(day,month,year)
{
document.getElementById("calender_one").innerHTML = day + ' - ' + month + ' - ' + year + ' ' + '<a href="javascript:init_one();">Select a Date</a>';
}
</script>
<script src="dateselect.php?script=true&name=one"></script>
<script>
function selectDate_two(day,month,year)
{
document.getElementById("calender_two").innerHTML = day + ' - ' + month + ' - ' + year + ' ' + '<a href="javascript:init_two();">Select a Date</a>';
}
</script>
<script src="dateselect.php?script=true&name=two"></script>
</body>
</html>
And I’m working on the PHP / javascript here:
( and I know it’s the HTML is calling the .php file in the root atm, I’ll move that shortly but it’s functional and I’ve still to assign the function return vars back into the form.)
<?php
/****************************************************
Creator: John Tindell
Email: linal[_AT_]mindlessant.co.uk
Version: 1.1
Last-Update: 21st April 2006
****************************************************/
if(isset($_GET['script']))
{
?>
function createRequestObject_<?=$_GET['name']?>()
{
var request_o; //declare the variable to hold the object.
var browser = navigator.appName; //find the browser name
if(browser == "Microsoft Internet Explorer"){
/* Create the object using MSIE's method */
request_o = new ActiveXObject("Microsoft.XMLHTTP");
}else{
/* Create the object using other browser's method */
request_o = new XMLHttpRequest();
}
return request_o; //return the object
}
var http_<?=$_GET['name']?> = createRequestObject_<?=$_GET['name']?>();
/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleCalender_<?=$_GET['name']?>(){
/* Make sure that the transaction has finished. The XMLHttpRequest object
has a property called readyState with several states:
0: Uninitialized
1: Loading
2: Loaded
3: Interactive
4: Finished */
try
{
if(http_<?=$_GET['name']?>.readyState == 4){ //Finished loading the response
/* We have got the response from the server-side script,
let's see just what it was. using the responseText property of
the XMLHttpRequest object. */
var response = http_<?=$_GET['name']?>.responseText;
//alert(response);
//document.write(response);
document.getElementById("calenderSelect_<?=$_GET['name']?>").innerHTML = response;
}
}
catch(Exception)
{
}
}
/* Function called to get the product categories list */
function init_<?=$_GET['name']?>()
{
try
{
http_<?=$_GET['name']?>.open('get', 'dateselect.php?name=<?=$_GET['name']?>');
http_<?=$_GET['name']?>.onreadystatechange = handleCalender_<?=$_GET['name']?>;
http_<?=$_GET['name']?>.send(null);
showCalender_<?=$_GET['name']?>();
}
catch(Exception)
{
http_<?=$_GET['name']?> = createRequestObject_<?=$_GET['name']?>();
}
}
function getCalender_<?=$_GET['name']?>(month,year)
{
try
{
http_<?=$_GET['name']?>.open('get', 'dateselect.php?name=<?=$_GET['name']?>&month=' + month + '&year=' + year);
http_<?=$_GET['name']?>.onreadystatechange = handleCalender_<?=$_GET['name']?>;
http_<?=$_GET['name']?>.send(null);
}
catch(Exception)
{
http_<?=$_GET['name']?> = createRequestObject_<?=$_GET['name']?>();
getCalender_<?=$_GET['name']?>(month,year);
}
}
function showCalender_<?=$_GET['name']?>()
{
document.getElementById('calenderSelect_<?=$_GET['name']?>').style.display = 'block';
}
function hideCalender_<?=$_GET['name']?>()
{
document.getElementById('calenderSelect_<?=$_GET['name']?>').style.display = 'none';
}
document.write('<div id="calender_<?=$_GET['name']?>"><a href="javascript:init_<?=$_GET['name']?>();">Select a Date</a></div>');
document.write('<div style="display:none;position:absolute;" id="calenderSelect_<?=$_GET['name']?>"></div>');
<?
}
else
{
if(isset($_GET['month']))
{
$month = $_GET['month'];
}
else
{
$month = date("m");
}
if(isset($_GET['year']))
{
$year = $_GET['year'];
}
else
{
$year = date("Y");
}
$t = strtotime("j");
//die( date("j") );
$t = date("j");
$days = date("t",mktime(1,1,1,$month,$t,$year));
$currentMonth = date("M",mktime(1,1,1,$month,1,$year));
$m_prevMonth = $m_nextMonth = $month;
$iprevYear = $inextYear = $year;
if((($m_prevMonth + 1) % 12 ) == 2)
{
$m_prevMonth = 12;
$iprevYear--;
}
else
{
$m_prevMonth--;
}
if((($m_nextMonth + 1) % 12 ) == 1)
{
$m_nextMonth = 1;
$inextYear++;
}
else
{
$m_nextMonth++;
}
$prevMonth = date("M",mktime(1,1,1,$m_prevMonth,1,$year));
$nextMonth = date("M",mktime(1,1,1,$m_nextMonth,1,$year));
$iprevMonth = date("m",mktime(1,1,1,$m_prevMonth,1,$year));
$inextMonth = date("m",mktime(1,1,1,$m_nextMonth,1,$year));
$leep_prevYear = $year - 1;
$leep_nextYear = $year + 1;
?>
<table class="calender_<?=$_GET['name']?>">
<tr>
<th colspan="7">
<a href="javascript: getCalender_<?=$_GET['name']?>('<?=$month?>','<?=$leep_prevYear?>');"><?=$leep_prevYear?></a>
<?=$year?>
<a href="javascript: getCalender_<?=$_GET['name']?>('<?=$month?>','<?=$leep_nextYear?>');"><?=$leep_nextYear?></a>
<a href="javascript: hideCalender_<?=$_GET['name']?>();">Close</a>
</th>
</tr>
<tr>
<td colspan="7"><a href="javascript: getCalender_<?=$_GET['name']?>('<?=$iprevMonth?>','<?=$iprevYear?>');"><?=$prevMonth?></a> <?=$currentMonth?> <a href="javascript: getCalender_<?=$_GET['name']?>('<?=$inextMonth?>','<?=$inextYear?>');"><?=$nextMonth?></a></td>
</tr>
<th>mon</th><th>tue</th><th>wed</th><th>thurs</th><th>fri</th><th>sat</th><th>sun</th>
</tr><tr>
<?php
$firstRow = true;
$weekPos = 1;
for($i = 1; $i <= $days; $i++)
{
if($firstRow)
{
$temp = date("N",mktime(1,1,1,$month,$i,$year));
for($x = 1; $x < $temp;$x++)
{
?>
<td> </td>
<?
}
if( date("j") == $i)
{
?>
<td><b><a href="javascript:selectDate_<?=$_GET['name']?>(<?=$i?>,<?=$month?>,<?=$year?>);hideCalender_<?=$_GET['name']?>();"><?=$i?></a></b></td>
<?
}
else
{
?>
<td><a href="javascript:selectDate_<?=$_GET['name']?>(<?=$i?>,<?=$month?>,<?=$year?>);hideCalender_<?=$_GET['name']?>();"><?=$i?></a></td>
<?
}
$weekPos += $temp;
$firstRow = false;
}
else
{
if( date("j") == $i)
{
?>
<td><b><a href="javascript:selectDate_<?=$_GET['name']?>(<?=$i?>,<?=$month?>,<?=$year?>);hideCalender_<?=$_GET['name']?>();"><?=$i?></a></b></td>
<?
}
else
{
?>
<td><a href="javascript:selectDate_<?=$_GET['name']?>(<?=$i?>,<?=$month?>,<?=$year?>);hideCalender_<?=$_GET['name']?>();"><?=$i?></a></td>
<?
}
}
if( ($weekPos % 7) == 1)
{
?>
</tr><tr>
<?
}
$weekPos++;
}
while(($weekPos % 7) != 2)
{
?>
<td> </td>
<?
$weekPos++;
}
?>
</tr>
</table>
<?
}
?>