Commit 8ceb78a6f9a79e5ffec32a166805995c6f6d0a93

  • avatar
  • Jonne Itkonen <jonne.itkonen @j…u.fi> (Committer)
  • Mon Aug 26 14:32:47 EEST 2013
  • avatar
  • Jonne Itkonen <jonne.itkonen @j…u.fi> (Author)
  • Mon Aug 26 14:32:47 EEST 2013
lausekkeen arvon laskeminen toimii
taulukko.js
(16 / 9)
  
430430 var op = document.createElement('option');
431431 op.value = on;
432432 op.label = on;
433 op.fn = opers[op];
434 kohde.operator = opers[op];
433 op.fn = opers[on];
434
435435 sel.appendChild(op);
436436 }
437 sel.addEventListener('change', function () { kohde.aseta_oper(sel.value); }, false);
437438 divi.appendChild(sel);
438439 return divi;
439440}
473473 console.log("oid "+oid);
474474 event.target.style.background = "white";
475475 var olio = document.getElementById(oid);
476 event.target.olio.arg1 = olio.olio;
476 event.target.olio.aseta_arg1(olio.olio);
477477 return false;
478478 } else {
479479 event.preventDefault();
484484function Lauseke(divid) {
485485 this.divid = divid;
486486 this.arg1 = null;
487 this.operator = null;
487 this.operators = {'+': function (a,b) { return a+b; },
488 '-': function (a,b) { return a-b; },
489 '<': function (a,b) { return a<b; }};
490 this.operator = this.operators['+'];
488491 this.arg2 = null;
489492
490493 this.divi = luo_div(divid, {'className':'statement', 'draggable':true});
491494 this.divi_a1 = luo_div(divid+'-a1', {'className':'arg', 'draggable':false});
492 this.divi_op = luo_operaattorit(divid+'-op', this,
493 {'+': function (a,b) { return a+b; },
494 '-': function () { return this.arg1.arvo() * this.arg2.arvo(); },
495 '<': function () { return this.arg1.arvo() < this.arg2.arvo(); }});
495 this.divi_op = luo_operaattorit(divid+'-op', this, this.operators);
496496 this.divi_a2 = luo_div(divid+'-a2', {'className':'arg', 'draggable':false});
497497 this.divi_eq = luo_div(divid+'-eq', {'className':'equals-literal', 'draggable':false});
498498 this.divi_val = luo_div(divid+'-v', {'className':'arvo', 'draggable':true});
555555 event.target.innerHTML = event.dataTransfer.getData("Arvo");
556556 var oid = event.dataTransfer.getData("Oid");
557557 var olio = document.getElementById(oid);
558 event.target.olio.arg2 = olio.olio;
558 event.target.olio.aseta_arg2(olio.olio);
559559 event.preventDefault();
560560 return false;
561561 } else {
586586 this.divi_val.innerHTML = ""+(this.arvo()||'__');
587587};
588588
589Lauseke.prototype.aseta_oper = function (symboli) {
590 this.operator = this.operators[symboli];
591 this.divi_val.innerHTML = ""+(this.arvo()||'__');
592};
593
589594Lauseke.prototype.liitä = function (kooste) {
590595 var koosteolio = hae_olio(kooste);
591596 koosteolio.appendChild(this.divi);
607607 var lauseke = new Lauseke('lauseke'+d.getTime().toString(16));
608608 lauseke.liitä(diviin);
609609 event.preventDefault();
610
610611 return false;
611612 }
612613 return true;