1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/grails-app/taglib/SimileTagLib.groovy Wed Mar 12 23:00:06 2008 -0500
1.3 @@ -0,0 +1,87 @@
1.4 +import org.codehaus.groovy.grails.plugins.PluginManagerHolder
1.5 +
1.6 +/**
1.7 + * A taglib to ease the loading of Simile libraries
1.8 + */
1.9 +class SimileTagLib {
1.10 + static namespace = 'simile'
1.11 +
1.12 + def ajax = { attrs ->
1.13 + out.println pluginJS(request?.contextPath, 'ajax/simile-ajax', attrs?.bundle);
1.14 + }
1.15 +
1.16 + def timeline = { attrs ->
1.17 + out.println pluginJS(request?.contextPath, 'timeline/timeline', attrs?.bundle);
1.18 + }
1.19 +
1.20 + def timelineExt = { attrs ->
1.21 + out.println pluginJS(request?.contextPath, "timeline/ext/${attrs?.name}/${attrs?.name}", attrs?.bundle);
1.22 + }
1.23 +
1.24 + def pluginJS(contextPath, lib, bundle) {
1.25 + def p = PluginManagerHolder?.pluginManager.getGrailsPlugin('simile')
1.26 + return "<script type='text/javascript' src='${contextPath}/plugins/${p.name}-${p.version}/js/${lib}-api.js?bundle=${bundle == 'true'}'></script>"
1.27 + }
1.28 +
1.29 + def renderTimeline = { attrs ->
1.30 + // get our timeline
1.31 + def timeline = attrs.timeline
1.32 +
1.33 + // figure out our unit type
1.34 + def unitType = Timeline.TYPE_UNITS[timeline.type]
1.35 + def eventSource = "0"
1.36 + if (unitType) { eventSource = "new SimileAjax.EventIndex(${unitType})" }
1.37 +
1.38 + def unitObject = ""
1.39 + switch (timeline.type) {
1.40 + case Timeline.DEPTH_TYPE: unitObject = ".Depth"; break;
1.41 + case Timeline.GEOCHRONO_TYPE: unitObject = ".Geochrono"; break;
1.42 + }
1.43 +
1.44 +
1.45 + out.println """\
1.46 + <script>
1.47 + var tl;
1.48 + function onLoad() {
1.49 + var eventSource = new Timeline.DefaultEventSource(${eventSource});
1.50 +
1.51 + var theme = Timeline.ClassicTheme.create();
1.52 + theme.event.bubble.width = 320;
1.53 + theme.event.bubble.height = 220;
1.54 + var bandInfos = [
1.55 + Timeline${unitObject}.createBandInfo({
1.56 + eventSource: eventSource,
1.57 + width: "80%",
1.58 + intervalUnit: Timeline.${timeline.detailUnit},
1.59 + intervalPixels: ${timeline.detailPixels}
1.60 + }),
1.61 + Timeline${unitObject}.createBandInfo({
1.62 + eventSource: eventSource,
1.63 + width: "20%",
1.64 + intervalUnit: Timeline.${timeline.overviewUnit},
1.65 + intervalPixels: ${timeline.overviewPixels},
1.66 + overview: true,
1.67 + convertToBaseUnit: true
1.68 + })
1.69 + ];
1.70 + bandInfos[1].syncWith = 0;
1.71 + bandInfos[1].highlight = true;
1.72 +
1.73 + tl = Timeline.create(document.getElementById("${attrs?.element}"), bandInfos, Timeline.HORIZONTAL${unitType == "" ? "" : ", " + unitType});
1.74 + tl.loadXML("${request?.contextPath}/timeline/eventsXML/${timeline.id}", function(xml, url) {
1.75 + eventSource.loadXML(xml, url);
1.76 + });
1.77 + }
1.78 + var resizeTimerID = null;
1.79 + function onResize() {
1.80 + if (resizeTimerID == null) {
1.81 + resizeTimerID = window.setTimeout(function() {
1.82 + resizeTimerID = null;
1.83 + tl.layout();
1.84 + }, 500);
1.85 + }
1.86 + }
1.87 + </script>
1.88 + """
1.89 + }
1.90 +}