|  | @@ -21,35 +21,123 @@ var _Dot = {
 | 
	
		
			
				|  |  |    type:'',
 | 
	
		
			
				|  |  |    text:'',
 | 
	
		
			
				|  |  |    summary:'',
 | 
	
		
			
				|  |  | +  active:true,
 | 
	
		
			
				|  |  |    opened:false,
 | 
	
		
			
				|  |  | -  classes:['dot'],
 | 
	
		
			
				|  |  | +  links:null,
 | 
	
		
			
				|  |  | +  parents:[],
 | 
	
		
			
				|  |  |    oninit: function(vn){
 | 
	
		
			
				|  |  |      this.id = vn.attrs.id;
 | 
	
		
			
				|  |  |      this.type = vn.attrs.type;
 | 
	
		
			
				|  |  |      this.text = markdown.render(vn.attrs.text);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // construct summary
 | 
	
		
			
				|  |  |      // TODO: summary needs more work (strip tags, markdown render)
 | 
	
		
			
				|  |  | -    this.summary = markdown.renderInline(vn.attrs.text.match('([^ ]*[ ]{0,1}){1,8}')[0]) + "…"
 | 
	
		
			
				|  |  | +    this.summary = vn.attrs.text.match('([^ ]*[ ]{0,1}){1,6}')[0];
 | 
	
		
			
				|  |  | +    this.summary = this.summary.trim().replace(/_([^_]+)$/g, "_$1_");
 | 
	
		
			
				|  |  | +    this.summary = this.summary.replace(/\[([^\]]+)$/g, "$1");
 | 
	
		
			
				|  |  | +    this.summary = markdown.renderInline(this.summary) + " …";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    if(typeof vn.attrs.active !== 'undefined')
 | 
	
		
			
				|  |  | +      this.active = vn.attrs.active;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // links
 | 
	
		
			
				|  |  | +    this.links = _dbs.data_strct[this.id];
 | 
	
		
			
				|  |  | +    // console.log(this.links);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // parents memorize where do we come from to avoid duplicates and looping nav
 | 
	
		
			
				|  |  | +    if(vn.attrs.parents){
 | 
	
		
			
				|  |  | +      this.parents = this.parents.concat(vn.attrs.parents);
 | 
	
		
			
				|  |  | +      // console.log('_Dot init '+this.id+' parents :',this.parents);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |    },
 | 
	
		
			
				|  |  | -  onbeforeupdate: function(vn){
 | 
	
		
			
				|  |  | -    if (this.opened){
 | 
	
		
			
				|  |  | -      this.classes.push('opened');
 | 
	
		
			
				|  |  | +  oncreate: function(vn){
 | 
	
		
			
				|  |  | +    if(this.active){
 | 
	
		
			
				|  |  | +      vn.dom.classList.remove('disabled');
 | 
	
		
			
				|  |  |      }else{
 | 
	
		
			
				|  |  | -      this.classes = ['dot'];
 | 
	
		
			
				|  |  | +      vn.dom.classList.add('disabled');
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  },
 | 
	
		
			
				|  |  | +  onbeforeupdate: function(vn){
 | 
	
		
			
				|  |  | +  },
 | 
	
		
			
				|  |  | +  onupdate: function(vn){
 | 
	
		
			
				|  |  | +    // console.log('_Dot : onupdate', vn);
 | 
	
		
			
				|  |  | +    if(this.active){
 | 
	
		
			
				|  |  | +      if (this.opened){
 | 
	
		
			
				|  |  | +        vn.dom.classList.add('opened');
 | 
	
		
			
				|  |  | +        if(this.links.to.length)
 | 
	
		
			
				|  |  | +          vn.dom.classList.add('to-links');
 | 
	
		
			
				|  |  | +      }else{
 | 
	
		
			
				|  |  | +        vn.dom.classList.remove('opened');
 | 
	
		
			
				|  |  | +        if(this.links.from.length)
 | 
	
		
			
				|  |  | +          vn.dom.classList.add('from-links');
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    },
 | 
	
		
			
				|  |  |    view: function(vn){
 | 
	
		
			
				|  |  | +    if (this.active && this.opened) {
 | 
	
		
			
				|  |  | +      // full view of dot with linked dots
 | 
	
		
			
				|  |  | +      console.log('_Dot view '+this.id+' parents :',this.parents);
 | 
	
		
			
				|  |  | +      var dot_content = [
 | 
	
		
			
				|  |  | +        // links to
 | 
	
		
			
				|  |  | +        this.links.to.length
 | 
	
		
			
				|  |  | +          ? m('aside', {'class':'links to'}, this.links.to.map(function(id){
 | 
	
		
			
				|  |  | +              // console.log(id);
 | 
	
		
			
				|  |  | +              return m(_Dot, {
 | 
	
		
			
				|  |  | +                "id":id,
 | 
	
		
			
				|  |  | +                'text':_dbs.data_byid[_dbs.lang][id].text,
 | 
	
		
			
				|  |  | +                'type':'',
 | 
	
		
			
				|  |  | +                // passe the memory of crossed dots plus the current one
 | 
	
		
			
				|  |  | +                'parents':vn.state.parents.concat([vn.state.id]),
 | 
	
		
			
				|  |  | +                // activate link only if not in parents (already went through it)
 | 
	
		
			
				|  |  | +                'active':vn.state.parents.indexOf(id) == -1 ? true:false
 | 
	
		
			
				|  |  | +              });
 | 
	
		
			
				|  |  | +            })
 | 
	
		
			
				|  |  | +          )
 | 
	
		
			
				|  |  | +          : null,
 | 
	
		
			
				|  |  | +        // id
 | 
	
		
			
				|  |  | +        m('span', {'class':'id'}, this.id), // this.type+' '+
 | 
	
		
			
				|  |  | +        // bullet
 | 
	
		
			
				|  |  | +        m('span', {'class':'bullet'}, m.trust('⚫')),
 | 
	
		
			
				|  |  | +        // full text
 | 
	
		
			
				|  |  | +        m('section', {'class':'text'}, m.trust(this.text)),
 | 
	
		
			
				|  |  | +        // links from
 | 
	
		
			
				|  |  | +        this.links.from.length
 | 
	
		
			
				|  |  | +          ? m('aside', {'class':'links from'}, this.links.from.map(function(id){
 | 
	
		
			
				|  |  | +              // retrun a dot
 | 
	
		
			
				|  |  | +              return m(_Dot, {
 | 
	
		
			
				|  |  | +                "id":id,
 | 
	
		
			
				|  |  | +                'text':_dbs.data_byid[_dbs.lang][id].text,
 | 
	
		
			
				|  |  | +                'type':'',
 | 
	
		
			
				|  |  | +                // passe the memory of crossed dots plus the current one
 | 
	
		
			
				|  |  | +                'parents':vn.state.parents.concat([vn.state.id]),
 | 
	
		
			
				|  |  | +                // activate link only if not in parents (already went through it)
 | 
	
		
			
				|  |  | +                'active':vn.state.parents.indexOf(id) == -1 ? true:false
 | 
	
		
			
				|  |  | +              });
 | 
	
		
			
				|  |  | +            })
 | 
	
		
			
				|  |  | +          )
 | 
	
		
			
				|  |  | +          : null
 | 
	
		
			
				|  |  | +      ];
 | 
	
		
			
				|  |  | +    }else{
 | 
	
		
			
				|  |  | +      // preview dot
 | 
	
		
			
				|  |  | +      var dot_content = [
 | 
	
		
			
				|  |  | +          m('span', {'class':'id'}, this.id), // this.type+' '+
 | 
	
		
			
				|  |  | +          m('span', {'class':'bullet'}, m.trust('•')),
 | 
	
		
			
				|  |  | +          m('p', {
 | 
	
		
			
				|  |  | +            'class':'summary',
 | 
	
		
			
				|  |  | +            onclick:function(e){
 | 
	
		
			
				|  |  | +              vn.state.opened = true;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +          }, m.trust(this.summary))
 | 
	
		
			
				|  |  | +      ];
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      return m('div',{
 | 
	
		
			
				|  |  |          'id':this.id,
 | 
	
		
			
				|  |  | -        'class':this.classes.join(' '),
 | 
	
		
			
				|  |  | -        onclick:function(e){
 | 
	
		
			
				|  |  | -          vn.state.opened = true;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        'class':'dot'
 | 
	
		
			
				|  |  |        },
 | 
	
		
			
				|  |  | -      [
 | 
	
		
			
				|  |  | -        m('span', {'class':'id'}, this.id), // this.type+' '+
 | 
	
		
			
				|  |  | -        m('span', {'class':'bullet'}, m.trust('⚫')),
 | 
	
		
			
				|  |  | -        m('p', {'class':'summary'}, m.trust(this.summary))
 | 
	
		
			
				|  |  | -    ]);
 | 
	
		
			
				|  |  | +      dot_content
 | 
	
		
			
				|  |  | +    );
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 |