Gl.notepad.createList = function (opt) { /* * @param * aid: article's aid * title: article's title * ct: article's creating time */ opt = opt || {}; var aid = opt.aid || $("#notepadSave").attr("data-aid"), title = opt.title || $("#notepadTitle").val(), ct = opt.ct ? (opt.ct >= 2147483647 ? parseInt(opt.ct) : opt.ct * 1000) : time.getTime().getTime(), // Check the create time format is in seconds or millisecond date = new Date(parseInt(ct)), currentAid = $("#notepadSave").attr("data-aid"), list; // List object which need to be created date = time.getForm(date); ct = helper.replaceTpl(_conf.timeTpl, date); list = $(helper.replaceTpl(listTpl, {aid: aid, title: title, ct: ct})); // Add active status when the article is the current one. if (aid == currentAid) { list.addClass("active"); $("#notepadList li").removeClass("active"); } $("#notepadList").prepend(list); return list; // Return the list object };
Gl.notepad.add = function (opt) { /* * @param * title: article's title * content: article's content */ opt = opt || {}; var that = this, date = createTime || time.getTime(), ct = helper.replaceTpl(_conf.timeTpl, time.getForm(new Date(date))), title = opt.title || "", content = opt.content || ""; createTime = date; // that.createList({title:"", ct: date.getTime()}); that.save(); $("#notepadList li").removeClass("active"); $("#notepadTitle").val(title); $("#notepadArticle").focus().val(content); // Focus on the textarea $("#notepadCreateTime").text(ct); // Reset save button $("#notepadSave").attr("data-aid", "").text(_conf.saveBtn); clearTimeout(t); that.inputStatus(); // Start to check input status that.inputTipSwitch(); };
formPrayData = function(dateStr){ var data = requestData[dateStr], dateArr = dateStr.split("-"), tmpData; curDate = uniform(Gl.serverNow); //console.log("curDate:"+curDate); curForm =time.getForm(curDate); curTime = curDate.getTime(); //get 6 pray time for(var i=0,td;td=data[i];i++){ curPrayTimeData = data[i].split(":"); prayTimeMsArr[i] = new Date(parseInt(dateArr[0]),parseInt(dateArr[1],10)-1,parseInt(dateArr[2],10)).setHours(curPrayTimeData[0],curPrayTimeData[1],0,curDate.getMilliseconds()); if(requestTomorrow){//是否请求明日数据 prayTimeMsArr[i] += 3600000*24; } timeGap[i] = prayTimeMsArr[i] - curTime; trParams[i] = {}; // 增加对时间补零操作 tmpTime = (curPrayTimeData[0].length > 1 ? curPrayTimeData[0] : "0" + curPrayTimeData[0]) + ":" + (curPrayTimeData[1].length > 1 ? curPrayTimeData[1] : "0" + curPrayTimeData[1]); if(conf.pray.prayClock.hourClock == "12"){ trParams[i].praytime = to12Hour(tmpTime,conf.pray.prayClock.localText); }else{ trParams[i].praytime = tmpTime; } } },
success: function (data) { data = $.parseJSON(data).data; if (data) { var date = new Date(data.ct >= 2147483647 ? parseInt(data.ct) : data.ct * 1000); // Check the create time format is in seconds or millisecond date = helper.replaceTpl(_conf.timeTpl, time.getForm(date)); $("#notepadTitle").val(data.title); $("#notepadArticle").focus().val(data.content); // Focus on the textarea $("#notepadCreateTime").text(date); // Bind article info with $.data listEle.data("data", {aid: aid, title: data.title, content: data.content, ct: date}); } else { $("#notepadTitle").val(""); $("#notepadArticle").focus().val(""); // Focus on the textarea $("#notepadCreateTime").text(""); // Bind article info with $.data listEle.data("data", {aid: aid, title: "", content: "", ct: ""}); } $("#notepadSave").attr("data-aid", aid); that.inputStatus(); // Check the input status that.inputTipSwitch(); }
VnLotteryBase.prototype._initDatePicker = function(){ var self = this; self._$datePicker.datepicker({ showOtherMonths: true, selectOtherMonths: true, showOn: "both", buttonText: "<i></i>", showAnim: "slideDown", showOptions: {direction: "down"}, dateFormat: self._conf.lottery.dateFormat, minDate: self._conf.lottery.minDate, maxDate: self._conf.lottery.maxDate, hideIfNoPrevNext: true }); $.datepicker.setDefaults(self._conf.datepicker);//localization //设置默认日期 if(time.getForm().hh >= parseInt(self._conf.lottery.changeHour,10)){ self._$datePicker.datepicker("setDate", "0");//超过设置的小时数,此时默认今日数据已经可用,取今日数据 }else{ self._$datePicker.datepicker("setDate", "-1");//否则取昨日数据 } };
success: function (data) { data = $.parseJSON(data).data; if (data) { list.attr("data-aid", data.aid); if (!$("#notepadSave").attr("data-aid") && $("p", $("#notepadList li").eq(0)).text() !== "") { $("#notepadSave").attr("data-aid", data.aid); } // Bind article info with $.data list.data("data", {aid: data.aid, title: title, content: content, ct: helper.replaceTpl(_conf.timeTpl, time.getForm(new Date(ct)))}); } }
Gl.notepad.save = function (opt) { /* * @param * aid: article's aid * title: article's title * content: article's content * ct: article's creating time * setSaved: if the value is true, set the Save button's text as SAVED */ opt = opt || {}; var that = this, aid = opt.aid || $("#notepadSave").attr("data-aid"), title = opt.title || $("#notepadTitle").val(), content = opt.content || $("#notepadArticle").val(), ct = opt.ct || time.getTime().getTime(); if (titleText !== title || articleText !== content) { isChange = true; // Check whether user has input anything } titleText = title; articleText = content; if (title === "" && content === "") { isChange = false; // It's illegal to save when the title and content are both empty } else if (title === "") { title = content.substr(0, 250); // If the title is blank, using content's substring as title } // Can save with changing if (isChange) { // Set saved text and reset it if (opt.setSaved) { $("#notepadSave").text(_conf.savedText); t = setTimeout(function () { $("#notepadSave").text(_conf.saveBtn); }, _conf.savedTimeout); } if (!aid || aid === "undefined") { // If the article's aid is not available, create it. ct = createTime ? createTime.getTime() : ct; createTime = ""; // reset create time // remove the first element while it's a new one if ($("#notepadList li").eq(0).attr("data-aid") === "" || $("#notepadList li").eq(0).attr("data-aid") === "undefined") { var list = $("#notepadList li").eq(0); $("p", list).text(title); } else { var list = that.createList({title: title, content: content, ct: ct}); } $("#notepadTitle").val(title); that.inputTipSwitch(); $.ajax({ url: "/cloudnote/create", data: { time: Math.floor(ct / 1000), // Set create time format in seconds in case of database overflow title: title, content: content }, type: "POST", success: function (data) { data = $.parseJSON(data).data; if (data) { list.attr("data-aid", data.aid); if (!$("#notepadSave").attr("data-aid") && $("p", $("#notepadList li").eq(0)).text() !== "") { $("#notepadSave").attr("data-aid", data.aid); } // Bind article info with $.data list.data("data", {aid: data.aid, title: title, content: content, ct: helper.replaceTpl(_conf.timeTpl, time.getForm(new Date(ct)))}); } } }); isChange = false; // Restore changing status } else { var save = function () { $.ajax({ url: "/cloudnote/save", data: { aid: aid, title: title, content: content }, type: "POST", success: function () { canSave = true; // saving process is end }, error: function () { canSave = true; // saving process is end } }); }; // If the article's aid is available, save it. var listEle = $("#notepadList li[data-aid='" + aid + "']"); $("p", listEle).text(title); $("#notepadTitle").val(title); that.inputTipSwitch(); // Check save list state if (canSave) { canSave = false; save(); } else { // Abandon the last saving process after timeout setTimeout(function () { canSave = true; save(); }, _conf.saveListTimeout); } isChange = false; // Restore changing status // Bind article info with $.data listEle.data("data", {aid: aid, title: title, content: content, ct: helper.replaceTpl(_conf.timeTpl, time.getForm(new Date(ct)))}); } } };
Gl.notepad.showContent = function (aid) { /* * @params * aid: the article's id which need to show */ var that = this, currentAid = $("#notepadSave").attr("data-aid"), listEle = $("#notepadList li[data-aid='" + aid + "']"); if (currentAid == aid) return; // Do not do anything while clicking the current article clearTimeout(t); // Reset save button $("#notepadSave").attr("data-aid", aid).text(_conf.saveBtn); if (listEle.data("data")) { // If the article has been bound with $.data, create with it var data = listEle.data("data"); $("#notepadTitle").val(data.title); $("#notepadArticle").focus().val(data.content); // Focus on the textarea $("#notepadCreateTime").text(data.ct); $("#notepadSave").attr("data-aid", aid); that.inputStatus(); // Check the input status that.inputTipSwitch(); } else if (!aid || aid === "undefined") { var ct = helper.replaceTpl(_conf.timeTpl, time.getForm(new Date(createTime))); // If the article has no aid, then add a new one. $("#notepadTitle").val(""); $("#notepadArticle").focus().val(""); // Focus on the textarea $("#notepadCreateTime").text(ct); // Reset save button $("#notepadSave").attr("data-aid", ""); that.inputStatus(); // Check the input status that.inputTipSwitch(); } else { $.ajax({ url: "/cloudnote/getcontent", data: { aid: aid }, type: "POST", success: function (data) { data = $.parseJSON(data).data; if (data) { var date = new Date(data.ct >= 2147483647 ? parseInt(data.ct) : data.ct * 1000); // Check the create time format is in seconds or millisecond date = helper.replaceTpl(_conf.timeTpl, time.getForm(date)); $("#notepadTitle").val(data.title); $("#notepadArticle").focus().val(data.content); // Focus on the textarea $("#notepadCreateTime").text(date); // Bind article info with $.data listEle.data("data", {aid: aid, title: data.title, content: data.content, ct: date}); } else { $("#notepadTitle").val(""); $("#notepadArticle").focus().val(""); // Focus on the textarea $("#notepadCreateTime").text(""); // Bind article info with $.data listEle.data("data", {aid: aid, title: "", content: "", ct: ""}); } $("#notepadSave").attr("data-aid", aid); that.inputStatus(); // Check the input status that.inputTipSwitch(); } }); } };
countDown = function(){ formPrayData(formDateParam(uniform(Gl.serverNow))); html = ""; var oldTimeGap, tmpTimeGap, nearestPray = -1; for(var i=0,td;td=prayNameList[i];i++){ if(timeGap[i] >= 0){//wait to start if(nearestPray == -1){ nearestPray = i; trParams[i].prayclass = "cur"; }else{ trParams[i].prayclass = ""; } /*hh = Math.floor(timeGap[i]/3600000); mm = Math.floor(timeGap[i]%3600000/60000); ss = Math.round(timeGap[i]%3600000%60000/1000);*/ tmpTimeGap = new Date(timeGap[i]); hh = tmpTimeGap.getUTCHours(); mm = tmpTimeGap.getUTCMinutes(); ss = tmpTimeGap.getUTCSeconds(); trParams[i].praycountdown = (hh<10?"0"+hh:hh)+":"+(mm<10?"0"+mm:mm)+":"+(ss<10?"0"+ss:ss); }else{//starting & started trParams[i].prayclass = "passed"; trParams[i].praycountdown = "--:--:--"; } oldTimeGap = timeGap[i]; trParams[i].prayname = td; html += helper.replaceTpl(trTpl,trParams[i]); //timeGap[i] -= 1000; } if(oldTimeGap <= -3600000 * conf.pray.prayClock.overtime || oldTimeGap > curPrayTimeData[0]*3600000+curPrayTimeData[1]*60000){//如果今日祷告已过去超过指定时间,就显示明日数据 requestTomorrow = 1; if(!loadTomorrow){ //formPrayData(formDateParam(new Date(curDate.getFullYear()+"-"+(curDate.getMonth()+1)+"-"+(curDate.getDate()+1))));a=new Date(curTime).setDate(curDate.getDate()+1) formPrayData(formDateParam(new Date(new Date(curTime).setDate(curDate.getDate()+1)))); loadTomorrow = 1; /*for(var i=0,td;td=prayNameList[i];i++){ timeGap[i] -= 1000; } curTime += 1000;*/ return; } }else{ requestTomorrow = 0; } curForm = time.getForm(new Date(curTime)); if(conf.pray.prayClock.hourClock == "12"){//12:15=>12:15PM;24:15=>12:15AM if(curForm.hh > 11 && curForm.hh < 24){ curForm.hourClock = "PM"; }else{ curForm.hourClock = "AM"; } if(curForm.hh > 12){ curForm.hh -= 12; } }else{ curForm.hourClock = ""; } curTimeContainer.html(helper.replaceTpl(timeTpl,curForm)); curDateContainer.html(helper.replaceTpl(dateTpl,curForm)); prayTimeTable.html(html); //curTime += 1000; },