diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-07-13 15:41:58 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-07-13 15:41:58 +0200 |
commit | ad42e3bdd3a412dbfbc3173a522f1dfb1b75b614 (patch) | |
tree | c3476566cf385080e6e3041c1bb8d9bb3dad575c /static/script.js | |
parent | lol gensym. (diff) | |
parent | Change event creation to only work for long events. (diff) | |
download | calp-ad42e3bdd3a412dbfbc3173a522f1dfb1b75b614.tar.gz calp-ad42e3bdd3a412dbfbc3173a522f1dfb1b75b614.tar.xz |
Merge long event creation as comments.
Diffstat (limited to 'static/script.js')
-rw-r--r-- | static/script.js | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/static/script.js b/static/script.js index 27831f35..d9f85aa6 100644 --- a/static/script.js +++ b/static/script.js @@ -60,6 +60,7 @@ class EventCreator { NOT on its children */ that.down_on_event = false; if (! e.target.classList.contains("events")) return; + // if (! e.target.classList.contains("longevents")) return; that.down_on_event = true; that.event_start.x = e.clientX; @@ -85,11 +86,6 @@ class EventCreator { /* only on left click */ if (e.buttons != 1) return; - /* [0, 1) -- where are we in the container */ - /* Ronud to force steps of quarters */ - let time = round_time(24 * (e.offsetY / this.clientHeight), - .25) - let event = that.event @@ -97,6 +93,15 @@ class EventCreator { .firstChild.cloneNode(true); bind_properties(event); + /* [0, 1) -- where are we in the container */ + /* Ronud to force steps of quarters */ + let time = round_time(24 * (e.offsetY / this.clientHeight), + .25); + /* + time = round_time((e.offsetX / this.clientWidth), + 1/(7*(24/8))); + */ + event.style.top = time * 100/24 + "%"; event.dataset.time1 = time; event.dataset.time2 = time; @@ -134,6 +139,26 @@ class EventCreator { that.event.properties.dtend = decimal_time_to_date(Math.max(Number(time1), Number(time2)), date); + + + /* + time2 = event.dataset.time2 = + round_time((e.offsetX / event.parentElement.clientWidth), + 1/(7*(24/8))); + // round_time(24 * (e.offsetX / event.parentElement.clientWidth), + // .25); + time1 = Number(event.dataset.time1); + + // let date = new Date(event.dataset.date) + let d1 = new Date(start_time.getTime() + (end_time-start_time) * Math.min(time1,time2)); + let d2 = new Date(start_time.getTime() + (end_time-start_time) * Math.max(time1,time2)); + event.properties.dtstart = d1; + // decimal_time_to_date(Math.min(Number(time1), Number(time2)), + // date); + event.properties.dtend = d2; + // decimal_time_to_date(Math.max(Number(time1), Number(time2)), + // date); + */ } } @@ -157,7 +182,6 @@ class EventCreator { } } - } async function remove_event (element) { @@ -374,7 +398,11 @@ window.onload = function () { el.parentElement.removeAttribute("href"); /* Bind all vcomponent properties into javascript. */ - bind_properties(el); + if (el.closest(".longevents")) { + bind_properties(el, true); + } else { + bind_properties(el); + } } @@ -466,7 +494,7 @@ Object.prototype.format = function () { return this; } /* any number of argument Date.prototype.format = function (str) { return format_date (this, str); } -function bind_properties (el) { +function bind_properties (el, wide_event=true) { el.properties = {} let children = el.getElementsByTagName("properties")[0].children; @@ -512,12 +540,21 @@ function bind_properties (el) { if (el.properties.dtstart) { el.properties.dtstart = new Date(el.properties.dtstart); el.properties["_slot_dtstart"].push( - [el.style, (s, v) => s.top = date_to_percent(v) + "%"]); + [el.style, + wide_event + ? (s, v) => s.left = 100 * (v - start_time)/(end_time - start_time) + "%" + : (s, v) => s.top = date_to_percent(v) + "%"]); } if (el.properties.dtend) { el.properties.dtend = new Date(el.properties.dtend); el.properties["_slot_dtend"].push( - [el.style, (s, v) => s.bottom = (100 - date_to_percent(v)) + "%"]); + [el.style, + wide_event + // TODO right and bottom only works if used from the start. However, + // events from the backend instead use top/left and width/height. + // Normalize so all use the same, or find a way to convert between. + ? (s, v) => s.right = 100*(1 - (v-start_time)/(end_time-start_time)) + "%" + : (s, v) => s.bottom = (100 - date_to_percent(v)) + "%"]); } } |