upadate
This commit is contained in:
1 parent
6909a25e1b
commit
7e30f7f278
20 files changed
+1250
-228
No files matched your search
@@ -0,0 +1,132 @@
|
||||
var Doc = (function(){
|
||||
var Document = function(baseURL){
|
||||
this.pages = [];
|
||||
this.baseURL = baseURL;
|
||||
}
|
||||
|
||||
Document.prototype.hasPage = function(index){
|
||||
return index >= 0 && index < this.pages.length;
|
||||
}
|
||||
|
||||
Document.prototype.getPageURL = function(pageNumber){
|
||||
var s = pageNumber <2 ? "" : "/" + pageNumber;
|
||||
return this.baseURL + s;
|
||||
}
|
||||
|
||||
Document.prototype.page = function(index){
|
||||
return index + 1;
|
||||
}
|
||||
|
||||
return Document;
|
||||
})();
|
||||
|
||||
(function(){
|
||||
const PAGES = [];
|
||||
var currentPageIndex = 0;
|
||||
var doc = new Doc(location.pathname.replace(/\/\d+$/, ""));
|
||||
$(document).ready(function(){
|
||||
try{
|
||||
var hrefPage = /\/(\d+)$/.exec(location.href)[1];
|
||||
currentPageIndex = parseInt(hrefPage) - 1;
|
||||
}catch(error){
|
||||
|
||||
}
|
||||
|
||||
$("#buttonNext").click(function(event){
|
||||
loadNext();
|
||||
});
|
||||
|
||||
$("#buttonPrev").click(function(event){
|
||||
loadPrevious();
|
||||
});
|
||||
|
||||
$("#page-container .pf").each(function(index, elem){
|
||||
var url = $(elem).data("page-url");
|
||||
doc.pages.push(url);
|
||||
});
|
||||
|
||||
$("#currentPage").attr("max", doc.pages.length);
|
||||
$("#totalPages").text(doc.pages.length);
|
||||
$("#currentPage").change(function(){
|
||||
var i = parseInt($(this).val()) - 1;
|
||||
if(i && doc.hasPage(i)){
|
||||
loadPage(i);
|
||||
}
|
||||
});
|
||||
|
||||
$("#page-container").html("");
|
||||
loadPage(currentPageIndex);
|
||||
|
||||
window.addEventListener("popstate", function(event){
|
||||
console.log("pops");
|
||||
console.log(event);
|
||||
var i = event.state;
|
||||
loadPage(i);
|
||||
});
|
||||
});
|
||||
|
||||
function loadNext(){
|
||||
var i = currentPageIndex + 1;
|
||||
if(doc.hasPage(i)){
|
||||
loadPage(i);
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function loadPrevious(){
|
||||
var i = currentPageIndex - 1;
|
||||
if(doc.hasPage(i)){
|
||||
loadPage(i);
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function loadPage(index){
|
||||
if(doc.hasPage(index)){
|
||||
var url = doc.pages[index];
|
||||
// $.ajax(
|
||||
// url,
|
||||
|
||||
// {
|
||||
// xhrFields: {
|
||||
// crossDomain: true,
|
||||
// withCredentials: true
|
||||
// },
|
||||
|
||||
// success: function(data, status){
|
||||
// currentPageIndex = index;
|
||||
// $("#currentPage").val(doc.page(currentPageIndex));
|
||||
// $("#page-container").html(data);
|
||||
|
||||
// var p = doc.page(currentPageIndex);
|
||||
// console.log("look at page ", p);
|
||||
// window.history.pushState(
|
||||
// currentPageIndex,
|
||||
// "State 2013 — " + p,
|
||||
// doc.getPageURL(p)
|
||||
// );
|
||||
// },
|
||||
|
||||
// error: function(xhr, aaa, error){
|
||||
// console.log(error);
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
$.get(url, function(data){
|
||||
currentPageIndex = index;
|
||||
$("#currentPage").val(doc.page(currentPageIndex));
|
||||
$("#page-container").html(data);
|
||||
|
||||
var p = doc.page(currentPageIndex);
|
||||
console.log("look at page ", p);
|
||||
window.history.pushState(
|
||||
currentPageIndex,
|
||||
"State 2013 — " + p,
|
||||
doc.getPageURL(p)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
+33
-14
@@ -11,11 +11,11 @@ $(document).ready(function(){
|
||||
|
||||
var now = new Date();
|
||||
var day = now.getDay();
|
||||
if(day < 7) selectDay(day);
|
||||
else deselectDays();
|
||||
// day = 3;
|
||||
if(day == 0) deselectDays();
|
||||
else selectDay(day);
|
||||
|
||||
var dates = getDates(day);
|
||||
// var dates = [45, 53, 53, 23, 53, 64];
|
||||
var dates = getDates(day);
|
||||
$(".schedule thead .date").each(function(index, elem){
|
||||
$(elem).text(dates[index]);
|
||||
});
|
||||
@@ -38,21 +38,40 @@ $(document).ready(function(){
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Generates list of numbers
|
||||
* @param {Number} start starting value
|
||||
* @param {Number} num amount of numbers in list
|
||||
* @param {Number} step difference value
|
||||
* @return {Array} list of numbers
|
||||
*/
|
||||
function range(start, num, step){
|
||||
var list= [];
|
||||
var val = start;
|
||||
for(var i = 0; i<num; i++){
|
||||
list.push(val);
|
||||
val += step;
|
||||
}
|
||||
return list;
|
||||
var list= [];
|
||||
var val = start;
|
||||
for(var i = 0; i<num; i++){
|
||||
list.push(val);
|
||||
val += step;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Monday date of current week
|
||||
* @param {[type]} d [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
function getMonday(d) {
|
||||
d = new Date(d);
|
||||
var day = d.getDay();
|
||||
var diff = d.getDate() - day + (day == 0 ? -6:1); // adjust when day is sunday
|
||||
return new Date(d.setDate(diff));
|
||||
}
|
||||
|
||||
function getDates(day){
|
||||
var dates = [];
|
||||
var prev = day - 1;
|
||||
var next = 6 - day;
|
||||
var dayMask = range(-1, 1, -1).concat([0]).concat(range(1, next, 1));
|
||||
var prev = day == 0 ? 0 : day - 1;
|
||||
var next = 6 - prev;
|
||||
var dayMask = range(-1, prev, -1).concat([0]).concat(range(1, next, 1));
|
||||
console.log("day mask", dayMask);
|
||||
dayMask.forEach(function(m){
|
||||
var time = Date.now() + (1000 * 60 * 60 * 24) * m;
|
||||
|
||||
Reference in new issue
Block a user