diff --git a/sourcing/edl.py b/sourcing/edl.py index 7851eb4..669285a 100644 --- a/sourcing/edl.py +++ b/sourcing/edl.py @@ -42,21 +42,28 @@ def parse_edl(edl_text): return edl -def fulfil_edl_with_sources(edl_text, hide_all_transclusions=False): +def fulfil_edl_with_sources(edl_text, links=None, hide_all_transclusions=False): edl = parse_edl(edl_text) + return fulfil_edl_with_links(edl, + links=links, + hide_all_transclusions=hide_all_transclusions) + +def fulfil_edl_with_links(edl, links=None, hide_all_transclusions=False): spans = edl['spans'] hide_transclusions = set() two_facet_links = [] + if not links: + links = [parse_link(link['text']) for link in edl['links']] + link_num = 0 - for link in edl['links']: - link_detail = parse_link(link['text']) - if link_detail['type'] == 'HideTransclusions': - hide_transclusions.add(parse_sourcedoc_facet(link_detail['facets'][0])) - elif len(link_detail['facets']) == 2: - two_facet_links.append((link_num, [parse_span(span[0]) for span in link_detail['facets']])) + for link in links: + if link['type'] == 'HideTransclusions': + hide_transclusions.add(parse_sourcedoc_facet(link['facets'][0])) + elif len(link['facets']) == 2: + two_facet_links.append((link_num, [parse_span(span[0]) for span in link['facets']])) link_num += 1 source = [get_text(url) for url in get_urls(spans)] @@ -93,8 +100,7 @@ def fulfil_edl_with_sources(edl_text, hide_all_transclusions=False): break if link_end < start: continue - open_tag = ''.format(link_num) - link_span = (open_tag + + link_span = (f'' + escape(span_text[link_start:link_end]) + '') new_text += escape(span_text[pos:link_start]) + link_span diff --git a/sourcing/static/js/xanaflight.js b/sourcing/static/js/xanaflight.js index 0c19538..5072395 100644 --- a/sourcing/static/js/xanaflight.js +++ b/sourcing/static/js/xanaflight.js @@ -198,13 +198,15 @@ function new_document(doc) { var w = document.documentElement.clientWidth; var h = document.documentElement.clientHeight; - w = 1600; - - var ratio = (doc.index + 1) / (doc.doc_count + 1) - var r_index = doc.doc_count - doc.index - 1; - var x = (w * ratio - (r_index * (box_width / 2))); - var y = (h - box_height) / 2; - + if (doc.doctype == 'xanadoc') { + var ratio = (doc.index + 1) / (doc.doc_count + 1) + var r_index = doc.doc_count - doc.index - 1; + var x = (w * ratio - (r_index * (box_width / 2))); + var y = (h - box_height) / 2; + } else { + var x = Math.random() * (w - 400); + var y = Math.random() * (h - 400); + } update_location(element.get(0), x, y); $("#top").append(element); @@ -276,6 +278,23 @@ function fulfil(doc, index, doc_count) { link_bridge_count = doc.link_count; var svg_element = document.getElementById('svg'); + for(var i = 0; i < doc.span_count; i++) { + var p = document.createElementNS('http://www.w3.org/2000/svg', 'polygon'); + p.setAttribute('id', 'bridge' + i); + p.setAttribute('class', 'bridge'); + p.setAttribute('visibility', 'hidden'); + + p.addEventListener('mouseover', function(e) { + hover_bridge(this, true); + }); + + p.addEventListener('mouseout', function(e) { + hover_bridge(this, false); + }); + + svg_element.appendChild(p); + } + for(var i = 0; i < doc.link_count; i++) { var p = document.createElementNS('http://www.w3.org/2000/svg', 'polygon'); p.setAttribute('id', 'linkbridge' + i); @@ -293,6 +312,13 @@ function fulfil(doc, index, doc_count) { svg_element.appendChild(p); } + $.each(doc.source, function(key, doc) { + if (doc.text) { + doc.heading += " (source document)"; + doc.doctype = 'sourcedoc'; + new_document(doc); + } + }); new_document({'heading': 'xanadoc', 'text': doc.doc, 'doctype': 'xanadoc', @@ -301,6 +327,14 @@ function fulfil(doc, index, doc_count) { update(); + $('.transclusion').bind('mouseover', function(e) { + hover_bridge(this, true); + }); + + $('.transclusion').bind('mouseout', function(e) { + hover_bridge(this, false); + }); + $('.link').bind('mouseover', function(e) { hover_link_bridge(this, true); }); diff --git a/sourcing/view.py b/sourcing/view.py index a9f2f6e..9f326c7 100644 --- a/sourcing/view.py +++ b/sourcing/view.py @@ -6,10 +6,10 @@ from .forms import (LoginForm, SignupForm, AccountSettingsForm, UploadSourceDocForm, SourceDocForm, ItemForm, ForgotPasswordForm, PasswordForm) from .model import User, SourceDoc, Item, XanaDoc, XanaLink, Reference -from .parse import parse_xanapage_facet +from .parse import parse_xanapage_facet, parse_link from .url import get_url from .mail import send_mail -from .edl import fulfil_edl_with_sources, fulfil_edl, parse_edl +from .edl import fulfil_edl_with_sources, fulfil_edl, parse_edl, fulfil_edl_with_links from .span import Span from .edit import apply_edits from .database import session @@ -240,10 +240,19 @@ def fulfil_xanaflight(item): assert link['type'] == 'flight' facets = link['facets'] docs = [] + edl_list = [] + all_links = [] for facet in facets: xanapage = Item.from_external(parse_xanapage_facet(facet)) assert xanapage.type == 'xanadoc' - doc = fulfil_edl_with_sources(xanapage.text, hide_all_transclusions=True) + edl = parse_edl(xanapage.text) + edl_list.append((xanapage, edl)) + all_links += [parse_link(link['text']) for link in edl['links']] + + for xanapage, edl in edl_list: + doc = fulfil_edl_with_links(edl, + links=all_links, + hide_all_transclusions=True) doc['hashid'] = xanapage.hashid docs.append(doc) return render_template('view/xanaflight.html', item=item, docs=docs)