1
0
Fork 0
forked from 0x2620/oxjs

adding first Ox.Calendar demo

This commit is contained in:
rlx 2011-04-20 11:29:34 +00:00
commit 1c05a7945f
6 changed files with 620 additions and 15 deletions

View file

@ -9858,7 +9858,7 @@ requires
function initMap() {
var mapBounds;
updateFormElements()
updateFormElements();
self.elevationService = new google.maps.ElevationService();
self.geocoder = new google.maps.Geocoder();
@ -10760,16 +10760,17 @@ requires
};
/**
options
height image height (px)
places array of either names (''), points ([0, 0]),
or objects ({name, point, highlight})
type map type ('hybrid', 'roadmap', 'satellite', 'terrain')
width image width (px)
*/
Ox.MapImage = function(options, self) {
/**
options
height image height (px)
places array of either names (''), points ([0, 0]),
or objects ({name, point, highlight})
type map type ('hybrid', 'roadmap', 'satellite', 'terrain')
width image width (px)
*/
var self = self || {},
that = new Ox.Element('img', self)
.defaults({
@ -10827,6 +10828,426 @@ requires
};
Ox.Calendar = function(options, self) {
self = self || {};
var that = new Ox.Element({}, self)
.defaults({
date: new Date(),
dates: [],
height: 512,
range: [100, 5101],
width: 512,
zoom: 5
})
.options(options || {})
.addClass('OxCalendar')
.css({
width: self.options.width + 'px',
height: self.options.height + 'px'
});
self.overlayWidths = [Math.round(self.options.width / 16)];
self.overlayWidths = [
Math.floor((self.options.width - self.overlayWidths[0]) / 2),
self.overlayWidths[0],
Math.ceil((self.options.width - self.overlayWidths[0]) / 2),
];
self.units = [
{
id: 'century',
seconds: 36524 * 86400,
date: function(i) {
return new Date((i + 19) + '00');
},
name: function(i) {
return Ox.formatOrdinal(i + 20) + ' century';
},
value: function(date) {
return Math.floor(date.getFullYear() / 100) - 19;
}
},
{
id: 'decade',
seconds: 3652 * 86400,
date: function(i) {
return (i + 197) + '0'
},
name: function(i) {
return (i + 197) + '0s'
},
value: function(date) {
return Math.floor(date.getFullYear() / 10) - 197;
}
},
{
id: 'year',
seconds: 365 * 86400,
date: function(i) {
return (i + 1970) + '';
},
name: function(i) {
return (i + 1970) + '';
},
value: function(date) {
return date.getFullYear() - 1970;
}
},
{
id: 'month',
seconds: 28 * 86000,
date: function(i) {
return (Math.floor(i / 12) + 1970) + '-' + (Ox.mod(i, 12) + 1);
},
name: function(i) {
return Ox.SHORT_MONTHS[Ox.mod(i, 12)] + ' ' + Math.floor(i / 12 + 1970)
},
value: function(date) {
return (date.getFullYear() - 1970) * 12 + date.getMonth();
}
},
{
id: 'day',
seconds: 86400,
date: function(i) {
return i * 86400000;
},
name: function(i) {
return Ox.formatDate(new Date(i * 86400000), '%a, %b %e, %Y');
},
value: function(date) {
return Math.floor(date / 86400000);
}
},
{
id: 'hour',
seconds: 3600,
date: function(i) {
return i * 3600000;
},
name: function(i) {
return Ox.formatDate(new Date(i * 3600000), '%b %e, %H:00');
},
value: function(date) {
return Math.floor(date / 3600000);
}
},
{
id: 'minute',
seconds: 60,
date: function(i) {
return i * 60000;
},
name: function(i) {
return Ox.formatDate(new Date(i * 60000), '%b %e, %H:%M');
},
value: function(date) {
return Math.floor(date / 60000);
}
},
{
id: 'second',
seconds: 1,
date: function(i) {
return i * 1000;
},
name: function(i) {
return Ox.formatDate(new Date(i * 1000), '%H:%M:%S');
},
value: function(date) {
return Math.floor(date / 1000);
}
}
];
self.$container = new Ox.Element()
.addClass('OxCalendarContainer')
.css({
top: '24px',
bottom: '40px'
})
.bindEvent({
dragstart: dragstart,
drag: drag,
dragend: dragend
})
.appendTo(that);
self.$content = new Ox.Element()
.addClass('OxCalendarContent')
.appendTo(self.$container)
self.$scalebar = new Ox.Element()
.addClass('OxTimeline')
.css({
posision: 'absolute',
})
.appendTo(self.$content);
self.$scrollbar = new Ox.Element()
.addClass('OxTimeline')
.css({
posision: 'absolute',
bottom: '40px'
})
.appendTo(that);
self.$overlay = new Ox.Element()
.addClass('OxOverlay')
.css({
bottom: '40px'
})
.append(
$('<div>').css({
width: self.overlayWidths[0] + 'px'
})
)
.append(
$('<div>').css({
left: self.overlayWidths[0] + 'px',
width: self.overlayWidths[1] + 'px'
})
)
.append(
$('<div>').css({
left: (self.overlayWidths[0] + self.overlayWidths[1]) + 'px',
width: self.overlayWidths[2] + 'px'
})
)
.bindEvent({
dragstart: dragstartScrollbar,
drag: dragScrollbar,
dragend: dragendScrollbar
})
.appendTo(that);
self.$zoombar = new Ox.Bar({
size: 16
})
.css({
position: 'absolute',
bottom: 24 + 'px'
})
.appendTo(that);
self.$zoomInput = new Ox.Range({
arrows: true,
max: 28,
min: 0,
size: self.options.width,
thumbSize: 32,
thumbValue: true,
value: self.options.zoom
})
.bindEvent({
change: changeZoom
})
.appendTo(self.$zoombar);
sortDates();
renderTimelines();
renderDates();
function changeDate() {
}
function changeZoom(event, data) {
self.options.zoom = data.value;
$('.OxDate').remove();
renderTimelines();
renderDates();
}
function dragstart(event, e) {
if ($(e.target).is(':not(.OxLine > .OxDate)')) {
self.drag = {x: e.clientX};
}
}
function drag(event, e) {
if (self.drag) {
self.$content.css({
marginLeft: (e.clientX - self.drag.x) + 'px'
});
self.$scrollbar.css({
marginLeft: Math.round((e.clientX - self.drag.x) / 16) + 'px'
});
}
}
function dragend(event, e) {
if (self.drag) {
self.options.date = new Date(
+self.options.date + (self.drag.x - e.clientX) * getSecondsPerPixel() * 1000
);
dragafter();
}
}
function dragstartScrollbar(event, e) {
self.drag = {x: e.clientX};
}
function dragScrollbar(event, e) {
self.$content.css({
marginLeft: ((e.clientX - self.drag.x) * 16) + 'px'
});
self.$scrollbar.css({
marginLeft: (e.clientX - self.drag.x) + 'px'
});
}
function dragendScrollbar(event, e) {
self.options.date = new Date(
+self.options.date + (self.drag.x - e.clientX) * getSecondsPerPixel() * 1000 * 16
);
dragafter();
}
function dragafter() {
self.drag = null;
self.$content.css({
marginLeft: 0
});
self.$scrollbar.css({
marginLeft: 0
});
$('.OxDate').remove();
renderTimelines();
renderDates();
}
function getDateElement(date, zoom) {
var left = getPosition(date.start, zoom),
width = Math.max(getPosition(date.stop, zoom) - left, 1);
return new Ox.Element()
.addClass('OxDate')
.attr({
title: date.name
})
.css({
left: left + 'px',
width: width + 'px'
})
.html('&nbsp;' + date.name);
}
function getPixelsPerSecond(zoom) {
return Math.pow(2, (zoom || self.options.zoom) - 24);
}
function getSecondsPerPixel(zoom) {
return 1 / getPixelsPerSecond(zoom);
}
function getPosition(date, zoom) {
zoom = zoom || self.options.zoom
return Math.round(
self.options.width / 2 +
(date - self.options.date) / 1000 * getPixelsPerSecond(zoom)
);
}
function getTimelineElements(zoom) {
var $elements = [],
pixelsPerSecond = getPixelsPerSecond(zoom),
n, unit, value, width;
self.units = self.units.reverse();
Ox.forEach(self.units, function(v) {
width = v.seconds * pixelsPerSecond;
if (width >= 64) {
unit = Ox.getObjectById(self.units, v.id);
return false;
}
});
self.units = self.units.reverse();
n = Math.ceil(self.options.width * 1.5/* * 16*/ / width);
value = unit.value(self.options.date);
Ox.loop(-n, n + 1, function(i) {
$elements.push(
getDateElement({
name: unit.name(value + i)/* + unit.date(value + i) + '-' + unit.date(value + i + 1)*/,
start: new Date(unit.date(value + i)),
stop: new Date(unit.date(value + i + 1))
}, zoom)
.addClass(Ox.mod(value + i, 2) == 0 ? 'even' : 'odd')
);
});
return $elements;
}
function overlaps(date0, date1) {
return (
date0.start >= date1.start && date0.start < date1.stop
) || (
date1.start >= date0.start && date1.start < date0.stop
);
}
function renderDates() {
self.lineDates = [];
self.$lines = [];
self.options.dates.forEach(function(date, i) {
var line = self.$lines.length;
Ox.forEach(self.lineDates, function(dates, line_) {
var fits = true;
Ox.forEach(dates, function(date_) {
if (overlaps(date, date_)) {
Ox.print('over', date.name, date_.name)
fits = false;
return false;
}
});
if (fits) {
Ox.print(date.name, 'fits', line_)
line = line_;
return false;
}
});
Ox.print(date.name, line)
if (line == self.$lines.length) {
self.lineDates[line] = [];
self.$lines[line] = new Ox.Element()
.addClass('OxLine')
.css({
top: ((line + 1) * 16) + 'px'
});
}
self.lineDates[line].push(date);
self.$lines[line].append(getDateElement(date));
});
$('.OxLine').remove();
self.$lines.forEach(function($line) {
$line.appendTo(self.$content);
});
}
function renderTimelines() {
getTimelineElements(self.options.zoom).forEach(function($element) {
$element.appendTo(self.$scalebar.$element);
});
getTimelineElements(Math.max(self.options.zoom - 4, 0)).forEach(function($element) {
$element.appendTo(self.$scrollbar.$element);
});
}
function sortDates() {
self.options.dates.sort(function(a, b) {
return (b.stop - b.start) - (a.stop - a.start);
});
}
self.onChange = function(key, val) {
if (key == 'date') {
} else if (key == 'zoom') {
}
};
return that;
};
/*
============================================================================
Menus
@ -10836,6 +11257,7 @@ requires
/**
*/
Ox.MainMenu = function(options, self) {
var self = self || {},
that = new Ox.Bar({}, self)
.defaults({