www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

ports.js (3525B)


      1 function MPorts(mBlocParent, estEntrée) {
      2     $.extend(this, {
      3         uid: singleton.uid(),
      4         // Propriétés
      5         entrée: estEntrée, /* entrée / sortie */
      6         // Parents
      7         bloc: mBlocParent,
      8         // Ajout
      9         ports: [],
     10         ajouterPort: function(p) {
     11             p.bloc = this;
     12             p.entrée = estEntrée;
     13             this.ports.push(p);
     14             faireCallbacks(this.cbAjoutPort, p);
     15             //faireCallbacks(this.cbModification, this);
     16         },
     17         cbAjoutPort: [],
     18         onAjoutPort: function(callback) {
     19             this.cbAjoutPort.push(callback);
     20         }
     21     });
     22 }
     23 
     24 function VPorts(vDéfinitionsParente, sens, mPorts) {
     25     $.extend(this,(
     26         $('#vue-ports-'+sens)
     27             .jqote({})
     28             .toDom()));
     29     
     30     this.vVerticalBar = this.find('.ports.vVerticalBar');
     31     this.vPorts = this.find('.ports.vPorts');
     32     
     33     var that = this;
     34     this.addVPort = function(vPort, mPorts) {
     35         new VPortInPorts(this, vPort, mPorts);
     36     };
     37     
     38     vDéfinitionsParente.setVPorts(this, sens);
     39     
     40     var ph0 = $('#vue-port-placeholder').jqote().appendTo(this.vPorts);
     41     this.ph0 = ph0;
     42     this.ph0.box = this.ph0.find('.port.placeholder.vBox');
     43     this.ph0.td = ph0.find('.port.placeholder.vTd');
     44     var a0 = ph0.box.stepAnimateClass('active', '');
     45     this.ph0.hide();
     46     var dragProxy = null;
     47     
     48     var showDistance = function (e) {
     49         // Glow when we get close
     50         var h0 = that.ph0.td.height() / 2;
     51         var dist0 = e.pageY - that.ph0.box.offY() + (that.ph0.box.height() / 2);
     52         var factor0 = Math.min(1, Math.abs(dist0 / h0));
     53         a0(Math.sqrt(factor0));
     54     };
     55     this.addClass('port-target');
     56     var dropstartFunc = function(e) {
     57         that.ph0.show();
     58         $('body').bind('mousemove', showDistance);
     59         showDistance(e);
     60     };
     61     var dropFunc = function(e) {
     62         e.dragTarget.droppedOn(mPorts, 0); // Position 0, car actuellement il n'y a rien.
     63     };
     64     var dropendFunc = function(e) {
     65         that.ph0.hide();
     66         $('body').unbind('mousemove', showDistance);
     67     };
     68 
     69     this.bindForDrops = function(bind) {
     70         if (bind) {
     71             this.bind('dropstart', dropstartFunc);
     72             this.bind('drop', dropFunc);
     73             this.bind('dropend', dropendFunc);
     74         } else {
     75             this.unbind('dropstart', dropstartFunc);
     76             this.unbind('drop', dropFunc);
     77             this.unbind('dropend', dropendFunc);
     78         }
     79     }
     80     this.bindForDrops(true);
     81 }
     82 
     83 function CPorts(mInstanceBloc, vDéfinitionsParente) {
     84     this.modèle= mInstanceBloc;
     85     this.mEntrée = mInstanceBloc.bloc.mPortsEntrée;
     86     this.mSortie = mInstanceBloc.bloc.mPortsSortie;
     87     this.vEntrée = new VPorts(vDéfinitionsParente, 'entrée', this.mEntrée);
     88     this.vSortie = new VPorts(vDéfinitionsParente, 'sortie', this.mSortie);
     89 
     90     var that = this;
     91     this.mEntrée.onAjoutPort(function(mPort) {
     92         console.log("Ajout de port d'entrée", mPort);
     93         that.modèle.bloc.monde.log.envoiMessage("Ajout de port d'entrée " + mPort);
     94         new CPort(mPort, that.vEntrée);
     95         window.setTimeout(function() {that.vEntrée.bindForDrops(false)}, 0);
     96     });
     97     this.mSortie.onAjoutPort(function(mPort) {
     98         console.log("Ajout de port de sortie", mPort);
     99         that.modèle.bloc.monde.log.envoiMessage("Ajout de port de sortie " + mPort);
    100         new CPort(mPort, that.vSortie);
    101         window.setTimeout(function() {that.vSortie.bindForDrops(false);}, 0);
    102     });
    103 }