3

为什么我需要升级
我需要禁用导航到某个日期之后的日期的功能,所以我正在考虑从 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,v 1.51)。这些帮助代码中有一些行,其中包含function showCalendar()which 调用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 的文档(我想使用的那个)说 -

  • 请注意,这是一个全新的产品。

  • 请注意,它与我们的旧日历项目不兼容。

我知道调用日历所需的最小值是 -

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 Started
找到了一个不太好的、未优化的解决方案,将其发布在答案中,但仍在寻找合适的解决方案。

4

1 回答 1

1

回答自己,但仍在寻找适当的解决方案。showCalendar()从 jscalendar 移动到 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;">&nbsp;</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 函数(此处为 showcalendar() 函数)内部启动弹出日历的正确方法。但是,在新 jscal2 日历的文档中,日历的启动仅支持绑定方法,而无法从内联 onclick 调用的函数内部执行相同操作。这是文档 - http://www.dynarch.com/projects/calendar/doc/(检查triggercont参数,其中之一是强制性的)。我应用了一些肮脏的修复来做同样的事情,因此不得不编写代码来做一些原本由插件自动完成的事情(例如,所选日期的显示=输入字段上的日期,日历的显示)。

于 2011-11-01T11:33:55.707 回答