On Mon, Sep 15, 2008 at 8:45 AM, Laura Dunn <laura...@gmail.com> wrote:
>
> I am sure that the answer to this question is somewhere in this wiki
> but I have searched and searched to no avail. I am wanting to alter
> the display of the bubble basically. I have save the sources.js file
> and load that up in my html file and have played a little bit with it
> so I know that it is actually loading it.
> My next step is that I want to format the date displayed so that it
> never includes the time. I like the remainder of the date format
> (Day, DD MMM YYYY).
`fillInfoBubble` calls `fillTime` which in turn use the labeller to return
the date as a string. So I think one way to go is to define a custom
labeller and override the `labelPrecise()` method. For example :
bandInfo = Timeline.createBandInfo({ ... your data ...});
bandInfo.labeller = new MyLabeller();
where `MyLabeller` could be defined like :
MyLabeller = function() {
Timeline.GregorianDateLabeller.apply(this, arguments);
}
MyLabeller.labelPrecise = function(date) {
return "your custom formatted date";
}
Never tested this, so it might not work or have some side-effects
on other printed dates.
Cheers,
Adrien.
I've done something similar - see
http://naa.gov.au/collection/explore/federation/constitution-timeline.aspx
I created a new fillTime function (see below) and just inserted in the
page to overwrite the existing one. It calls another function to
insert en dashes between dates.
Hope this helps.
Cheers, Tim
Timeline.DefaultEventSource.Event.prototype.fillTime = function(elmt,
labeller) {
var startDate = this._start;
var endDate = this._end;
var startString = startDate.getDate() + " " +
month[startDate.getMonth()] + " " + startDate.getFullYear();
var endString = endDate.getDate() + " " +
month[endDate.getMonth()]
+ " " + endDate.getFullYear();
if (this._instant) {
if (this.isImprecise()) {
elmt.appendChild(elmt.ownerDocument.createTextNode(startString + " " +
entity('–') + " " + endString));
} else {
elmt.appendChild(elmt.ownerDocument.createTextNode(startString));
}
} else {
if (this.isImprecise()) {
elmt.appendChild(elmt.ownerDocument.createTextNode(
this.getProperty("start") + " ~ " +
this.getProperty("latestStart")));
elmt.appendChild(elmt.ownerDocument.createElement("br"));
elmt.appendChild(elmt.ownerDocument.createTextNode(
this.getProperty("earliestEnd") + " ~ " +
this.getProperty("end")));
} else {
elmt.appendChild(elmt.ownerDocument.createTextNode(startString + " " +
entity('–') + " " + endString));
}
}
};
function entity(str, mode) {
str = (str) ? str : "";
mode = (mode) ? mode : "string";
var e = document.createElement("div");
e.innerHTML = str;
if (mode == "numeric") {
return "&#" + e.innerHTML.charCodeAt(0) + ";";
}
else if (mode == "utf16") {
var un = e.innerHTML.charCodeAt(0).toString(16);
while (un.length < 4) un = "0" + un;
return "\\u" + un;
}
else return e.innerHTML;
}
--
Tim Sherratt (t...@discontents.com.au)
http://www.discontents.com.au