【问题标题】:Unable to cleanly upgrade from old jscalendar to new jscal2 version无法从旧的 jscalendar 干净地升级到新的 jscal2 版本
【发布时间】:2011-12-14 05:01:02
【问题描述】:

为什么我需要升级
我需要具有禁用导航到某个日期之后的日期的功能,所以我正在考虑从 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)。这些帮助代码有几行,其中包含调用var cal = new Calendar()function showCalendar(),像这样 -

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.  
}

有什么想法吗?

谢谢

赏金活动开始
找到了一个不太好的、未优化的解决方案,将其发布在答案中,但仍在寻找合适的解决方案。

【问题讨论】:

    标签: javascript configuration jscalendar


    【解决方案1】:

    回答自己,但仍在寻找合适的解决方案。从 jscalendar 移动到 jsCal2 后,我编写了这段代码以继续使用 showCalendar() 函数 -

    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 参数,其中之一是强制性的)。 我应用了一些肮脏的修复来做同样的事情,因此不得不编写代码来做一些原本由插件自动完成的事情(例如,在输入字段上显示所选日期 = 日期,在日历显示上)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-03
      • 1970-01-01
      • 2018-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多