Skip to content

Commit f552b7b

Browse files
Merge branch 'canary' into dev
2 parents a1e87f3 + 3012229 commit f552b7b

File tree

3 files changed

+114
-65
lines changed

3 files changed

+114
-65
lines changed

lib/utils.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ Utils.empty = function(obj) {
7575
}
7676

7777
/**
78-
* Generates a unique blank node id
78+
* Generates a unique node id
7979
*/
80-
Utils.genBNID = function() {
80+
Utils.genBNID = function(base) {
81+
base = base || ""
8182
const r = Math.random()
8283
.toString(36)
8384
.substring(7)
8485
const d = new Date()
85-
const bnid = `_:${r}${d.getTime()}`
86+
const bnid = `doc:${base}${r}${d.getTime()}`
8687
return bnid
8788
}
8889

@@ -109,18 +110,16 @@ Utils.getShorthand = function(link) {
109110
Utils.compareIDs = function(ida, idb) {
110111
if (ida === idb) return true
111112
if (this.unshorten(ida) === idb) return true
113+
if (this.shorten(ida) === idb) return true
112114
if (this.unshorten(ida) === this.unshorten(idb)) return true
113-
const sha = this.getShorthand(ida)
114-
const shb = this.getShorthand(idb)
115-
if (sha && (sha === idb || sha === shb)) return true
116-
if (shb && shb === ida) return true
117115
return false
118116
}
119117

120118
/**
121119
* Shortens a URL to its compressed format - returns the full URL if not possible
122120
*/
123121
Utils.shorten = function(url, prefixes) {
122+
if(!url) return url
124123
prefixes = prefixes || Utils.standard_urls
125124
for (const pref in prefixes) {
126125
if (prefixes[pref] == url.substring(0, prefixes[pref].length)) {
@@ -134,6 +133,7 @@ Utils.shorten = function(url, prefixes) {
134133
* Expands a URL to its full URL format - returns the passed string if not possible to expand
135134
*/
136135
Utils.unshorten = function(url) {
136+
if(!url) return url
137137
if (this.validURL(url)) return url
138138
if (!url) return url
139139
const bits = url.split(':')
@@ -150,6 +150,7 @@ Utils.unshorten = function(url) {
150150
* Valid URLs are those that start with http:// or https://
151151
*/
152152
Utils.validURL = function(str) {
153+
if(str && typeof str != "string") str = "" + str
153154
if (str && (str.substring(0, 7) === 'http://' || str.substring(0, 8) === 'https://'))
154155
return true
155156
return false

lib/viewer/documentFrame.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ DocumentFrame.prototype.loadData = function(jsonld, cls, classframes){
9898
}
9999

100100
DocumentFrame.prototype.load = function(classframes, doc){
101-
this.document = new ObjectFrame(doc["@type"], doc, classframes)
101+
this.document = new ObjectFrame(doc["@type"], doc, classframes)
102102
}
103103

104104

@@ -116,7 +116,7 @@ DocumentFrame.prototype.loadSchemaFrames = function(classframes, cls){
116116
this.document.loadClassFrames(classframes);
117117
if(!this.document.subjid){
118118
this.document.newDoc = true;
119-
this.document.fillFromSchema("_:");
119+
this.document.fillFromSchema(FrameHelper.genBNID(FrameHelper.urlFragment(cls)+"_"));
120120
}
121121
}
122122
}
@@ -152,9 +152,9 @@ DocumentFrame.prototype.filterFrame = function(loadRenderer){
152152
* adds render and compare functions to object frames
153153
*/
154154
DocumentFrame.prototype.applyRules = function(doc, config, mymatch){
155-
doc = (doc ? doc : this.document);
155+
doc = doc || this.document;
156+
if(!doc) return
156157
config = (config ? config : this.config);
157-
var self = this;
158158
var onmatch = function(frame, rule){
159159
config.setFrameDisplayOptions(frame, rule);
160160
if(mymatch) mymatch(frame, rule);

0 commit comments

Comments
 (0)