// Generated by CoffeeScript 1.10.0 (function() { var annotate; window.AnnotationView = Backbone.D3View.extend({ namespace: null, tagName: 'div', initialize: function() { this.d3el.attr({ "class": 'AnnotationView' }); return this.listenTo(this.model, 'change', this.render); }, render: function() { var data, insert, insertions, text; data = this.model.get('data'); insertions = {}; insert = function(ins) { if (insertions[ins.offset] == null) { insertions[ins.offset] = []; } return insertions[ins.offset].push(ins.content); }; data.marks.forEach(function(d) { var comment; comment = d.comment != null ? d.comment.content : ''; switch (d.type) { case 'gap': return insert({ offset: d.start, content: "[...]" }); case 'figure': return insert({ offset: d.start, content: "
Figure" + (comment ? ': ' + comment : '') + "
" }); case 'author_addition': insert({ offset: d.start, content: "" }); return insert({ offset: d.end, content: "" }); case 'editor_addition': return insert({ offset: d.start, content: "" + d.content + "" }); case 'break': return insert({ offset: d.start, content: "
" }); } }); text = annotate(data.plain_text + ' ', insertions); text = '
' + text + '
'; return this.d3el.html(text); } }); annotate = function(text, insertions) { var i; i = 0; return text.replace(/.|\n/g, function(character, index) { var to_be_inserted; to_be_inserted = ''; if (insertions[index] != null) { to_be_inserted += insertions[index].join(''); } if (character === '\n') { to_be_inserted += '
'; } to_be_inserted += character; return to_be_inserted; }); }; }).call(this);