为什么我需要升级
我需要禁用导航到日期超过某个日期的功能,所以我考虑在我的项目中从jscalendar (http://www.dynarch.com/projects/calendar/old/)升级到jscal2 (http://www.dynarch.com/projects/calendar/)。但在新jscal2的主页和文档中,我们提到了以下几点-
问题
因此,我很困惑,是否可以在当前项目中进行更改最少的升级,如果可以的话,应该如何做到这一点。我已经在网站上发布了一条评论-- http://www.dynarch.com/projects/calendar/discussion/,等待一些回复。在此期间,我认为那些使用过该产品的人可能会有所帮助,所以这里是我的问题。
我的项目的现有代码使用jscalendar版本1.51 (我看到在calendar.js文件- calendar.js,v1.51中写了这一行)。这些帮助代码中有几行代码,其中包含调用function showCalendar()的var cal = new Calendar(),如下所示-
function setActiveStyleSheet()
function selected()
function closeHandler()
function showCalendar(){
...
//some lines of code
...
var cal = new Calendar(1, null, selected, closeHandler);
...
//some lines of code
...
}
....在这里查看相同的http://pastebin.com/QHAb0WdB
但是在我今天下载的新版本的演示中,我没有看到那个助手脚本。我尝试删除旧版本的所有js/css文件,包括新版本的文件,但只保留相同的jscalendar.js,但这会导致js错误-
_dynarch_popupCalendar is not defined
[Break On This Error] if (_dynarch_popupCalendar != null) { 我猜,我可以通过在新日历启动中添加onSelect参数来限制过去的日期,比如-
onSelect: function() {
var date = Calendar.intToDate(this.selection.get());
LEFT_CAL.args.min = date; // setting minimum date, so as to not allow browsing past this date
LEFT_CAL.redraw();
this.hide();
}但在修改助手脚本失败后,我没有尝试任何操作。
如果您对正确的升级过程有想法,请告诉我。我不知道我错过了什么。
我曾想过,它就像更改js的包含一样简单,并且可能是css文件,代码中不需要进行任何更改。我只需要设置更多的配置参数,以根据我的意愿禁用日期。
更新
让事情变得更简单!!
首先,更正一下,这不是升级,因为jscal2的文档(我想使用的文档)说-
注意:这是一个全新的product.
我知道调用日历的最低要求是-
Calendar.setup({
cont : "calendar-container" // a cont or a trigger
});所有参数都是可选的。但是,您应该为弹出日历提供一个cont (用于内联日历)或触发器,或者提供您自己的代码来显示弹出日历。我们以后再看看怎么做。
我想我需要写代码来显示弹出式日历,就像这样-
function showCalendar(){
...
//some lines of code
...
var cal = new Calendar();
...
//some code to display the calendar, based on the details already being passed to this function - which button was clicked, where to attach the calendar, etc.
...
}但是,我在文档中没有看到任何这样的代码。我试过用这个代码,但不起作用-
function trigger()
{
cal = new Calendar({
inputField: "startdate",
dateFormat: "%B %d, %Y",
bottomBar: false,
showTime:true
}
});
cal.redraw(); //blind try - does not work, but it does not give any errors. But I
don't see any other proper function to do this in the doc.
}伙计们有什么想法吗?
谢谢
Bounty启动
已经找到了一个不太好,没有优化的解决方案,张贴在回答,但仍在寻找一个适当的解决方案。
发布于 2011-11-01 11:33:55
回答我自己,但仍在寻找合适的解决办法。我编写这段代码是为了在从jscalendar转到jsCal2之后继续使用jsCal2函数-
var instance = null; //tracker of calendar instances
function showCalendar(id, format, showsTime, showsOtherMonths)
{
//some code here
//create a dummy holder so as to place the calendar inside, so that I can use the "cont" attribute. (Have to use either cont or trigger. )
if(instance!=null)
{
instance.hide();
instance = null;
$("table.DynarchCalendar-topCont").remove(); //I am having to kill the earlier calendar instance on every calendar display call, because otherwise multiple instances were getting created in DOM, causing confusion.
//get date in input field - since earlier instance is killed
}
if($("div#container").length == 0)
{
$('body').append('<div id="container" style="position: absolute;"> </div>');
}
cal = new Calendar({
cont: "container",
inputField: id,
dateFormat: format,
bottomBar: false,
min: minDateLimit,
showTime: showsTime,
weekNumbers: true,
selection : intDate,
onSelect: function() {
//set selected value into attached input field
var selectedDate = this.selection.get();
date = Calendar.intToDate(selectedDate);
date = Calendar.printDate(date, format);
$('#'+id).val(date);
this.hide();
},
onBlur: function() { //clicking outside hide calendar
this.hide();
}
});
cal.moveTo(intDate); //since new instance of calendar is being created everytime, need to move to the date
cal.popup(id,"Br");
instance = cal;
return false;
}我尝试了很多正确的方法,从内联的onclick函数(这里显示日历()函数)中启动一个弹出日历。但是,在新jscal2日历的文档中,日历的初始化只支持绑定方法,而无法在从内联单击调用的函数中执行相同的操作。这里是文档- http://www.dynarch.com/projects/calendar/doc/ (检查trigger和cont参数,其中之一是强制性的)。我应用了一些脏的补丁来做同样的事情,因此不得不编写代码来完成一些由插件自动完成的事情(例如,在输入字段中显示选定的日期=日期,在日历的显示上)。
https://stackoverflow.com/questions/7877344
复制相似问题