|
3 | 3 | // |
4 | 4 | // This must load AFTER the rdflib.js and log-ext.js (or log.js). |
5 | 5 | // |
6 | | -import * as log from './log' |
7 | | -import { store } from './logic' |
8 | | -import * as ns from './ns' |
| 6 | +import * as log from '../log' |
| 7 | +import { store } from '../logic' |
| 8 | +import * as ns from '../ns' |
9 | 9 | import * as rdf from 'rdflib' // pull in first avoid cross-refs |
| 10 | +import { label } from './label' |
10 | 11 |
|
11 | 12 | const UI = { log, ns, rdf, store } |
12 | 13 |
|
@@ -366,8 +367,8 @@ function getEyeFocus (element, instantly, isBottom, myWindow) { |
366 | 367 | myWindow.scrollBy( |
367 | 368 | 0, |
368 | 369 | elementPosY + |
369 | | - element.clientHeight - |
370 | | - (myWindow.scrollY + myWindow.innerHeight) |
| 370 | + element.clientHeight - |
| 371 | + (myWindow.scrollY + myWindow.innerHeight) |
371 | 372 | ) |
372 | 373 | return |
373 | 374 | } |
@@ -495,112 +496,6 @@ function labelWithOntology (x, initialCap) { |
495 | 496 | return label(x, initialCap) |
496 | 497 | } |
497 | 498 |
|
498 | | -// This ubiquitous function returns the best label for a thing |
499 | | -// |
500 | | -// The hacks in this code make a major difference to the usability |
501 | | -// |
502 | | -// @returns string |
503 | | -// |
504 | | -function label (x, initialCap) { |
505 | | - // x is an object |
506 | | - function doCap (s) { |
507 | | - // s = s.toString() |
508 | | - if (initialCap) return s.slice(0, 1).toUpperCase() + s.slice(1) |
509 | | - return s |
510 | | - } |
511 | | - function cleanUp (s1) { |
512 | | - let s2 = '' |
513 | | - if (s1.slice(-1) === '/') s1 = s1.slice(0, -1) // chop trailing slash |
514 | | - for (let i = 0; i < s1.length; i++) { |
515 | | - if (s1[i] === '_' || s1[i] === '-') { |
516 | | - s2 += ' ' |
517 | | - continue |
518 | | - } |
519 | | - s2 += s1[i] |
520 | | - if ( |
521 | | - i + 1 < s1.length && |
522 | | - s1[i].toUpperCase() !== s1[i] && |
523 | | - s1[i + 1].toLowerCase() !== s1[i + 1] |
524 | | - ) { |
525 | | - s2 += ' ' |
526 | | - } |
527 | | - } |
528 | | - if (s2.slice(0, 4) === 'has ') s2 = s2.slice(4) |
529 | | - return doCap(s2) |
530 | | - } |
531 | | - |
532 | | - // Hard coded known label predicates |
533 | | - // @@ TBD: Add subproperties of rdfs:label |
534 | | - |
535 | | - const kb = UI.store |
536 | | - const lab1 = |
537 | | - kb.any(x, UI.ns.ui('label')) || // Prioritize ui:label |
538 | | - kb.any(x, UI.ns.link('message')) || |
539 | | - kb.any(x, UI.ns.vcard('fn')) || |
540 | | - kb.any(x, UI.ns.foaf('name')) || |
541 | | - kb.any(x, UI.ns.dct('title')) || |
542 | | - kb.any(x, UI.ns.dc('title')) || |
543 | | - kb.any(x, UI.ns.rss('title')) || |
544 | | - kb.any(x, UI.ns.contact('fullName')) || |
545 | | - kb.any(x, kb.sym('http://www.w3.org/2001/04/roadmap/org#name')) || |
546 | | - kb.any(x, UI.ns.cal('summary')) || |
547 | | - kb.any(x, UI.ns.foaf('nick')) || |
548 | | - kb.any(x, UI.ns.rdfs('label')) |
549 | | - |
550 | | - if (lab1) { |
551 | | - return doCap(lab1.value) |
552 | | - } |
553 | | - |
554 | | - // Default to label just generated from the URI |
555 | | - |
556 | | - if (x.termType === 'BlankNode') { |
557 | | - return '...' |
558 | | - } |
559 | | - if (x.termType === 'Collection') { |
560 | | - return '(' + x.elements.length + ')' |
561 | | - } |
562 | | - let s = x.uri |
563 | | - if (typeof s === 'undefined') return x.toString() // can't be a symbol |
564 | | - // s = decodeURI(s) // This can crash is random valid @ signs are presentation |
565 | | - // The idea was to clean up eg URIs encoded in query strings |
566 | | - // Also encoded character in what was filenames like @ [] {} |
567 | | - try { |
568 | | - s = s |
569 | | - .split('/') |
570 | | - .map(decodeURIComponent) |
571 | | - .join('/') // If it is properly encoded |
572 | | - } catch (e) { |
573 | | - // try individual decoding of ASCII code points |
574 | | - for (let i = s.length - 3; i > 0; i--) { |
575 | | - const hex = '0123456789abcefABCDEF' // The while upacks multiple layers of encoding |
576 | | - while ( |
577 | | - s[i] === '%' && |
578 | | - hex.indexOf(s[i + 1]) >= 0 && |
579 | | - hex.indexOf(s[i + 2]) >= 0 |
580 | | - ) { |
581 | | - s = |
582 | | - s.slice(0, i) + |
583 | | - String.fromCharCode(parseInt(s.slice(i + 1, i + 3), 16)) + |
584 | | - s.slice(i + 3) |
585 | | - } |
586 | | - } |
587 | | - } |
588 | | - if (s.slice(-5) === '#this') s = s.slice(0, -5) |
589 | | - else if (s.slice(-3) === '#me') s = s.slice(0, -3) |
590 | | - |
591 | | - const hash = s.indexOf('#') |
592 | | - if (hash >= 0) return cleanUp(s.slice(hash + 1)) |
593 | | - |
594 | | - if (s.slice(-9) === '/foaf.rdf') s = s.slice(0, -9) |
595 | | - else if (s.slice(-5) === '/foaf') s = s.slice(0, -5) |
596 | | - |
597 | | - // Eh? Why not do this? e.g. dc:title needs it only trim URIs, not rdfs:labels |
598 | | - const slash = s.lastIndexOf('/', s.length - 2) // (len-2) excludes trailing slash |
599 | | - if (slash >= 0 && slash < x.uri.length) return cleanUp(s.slice(slash + 1)) |
600 | | - |
601 | | - return doCap(decodeURIComponent(x.uri)) |
602 | | -} |
603 | | - |
604 | 499 | function escapeForXML (str) { |
605 | 500 | return str.replace(/&/g, '&').replace(/</g, '<') |
606 | 501 | } |
|
0 commit comments