Skip to content

Commit

Permalink
added Utils.normaliseUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Aug 31, 2017
1 parent 163c724 commit 9193957
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 17 deletions.
15 changes: 11 additions & 4 deletions dist/client/manifesto.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,9 @@ var Manifesto;
Sequence.prototype.getCanvasById = function (id) {
for (var i = 0; i < this.getTotalCanvases(); i++) {
var canvas = this.getCanvasByIndex(i);
if (canvas.id === id) {
// normalise canvas id
var canvasId = Manifesto.Utils.normaliseUrl(canvas.id);
if (Manifesto.Utils.normaliseUrl(id) === canvasId) {
return canvas;
}
}
Expand Down Expand Up @@ -2167,10 +2169,15 @@ var Manifesto;
}
return type;
};
Utils.normaliseUrl = function (url) {
url = url.substr(url.indexOf('://'));
if (url.indexOf('#') !== -1) {
url = url.split('#')[0];
}
return url;
};
Utils.normalisedUrlsMatch = function (url1, url2) {
var url1norm = url1.substr(url1.indexOf('://'));
var url2norm = url1.substr(url1.indexOf('://'));
return url1norm === url2norm;
return Utils.normaliseUrl(url1) === Utils.normaliseUrl(url2);
};
Utils.isImageProfile = function (profile) {
if (Utils.normalisedUrlsMatch(profile.toString(), Manifesto.ServiceProfile.STANFORDIIIFIMAGECOMPLIANCE0.toString()) ||
Expand Down
15 changes: 11 additions & 4 deletions dist/client/manifesto.js
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,9 @@ var Manifesto;
Sequence.prototype.getCanvasById = function (id) {
for (var i = 0; i < this.getTotalCanvases(); i++) {
var canvas = this.getCanvasByIndex(i);
if (canvas.id === id) {
// normalise canvas id
var canvasId = Manifesto.Utils.normaliseUrl(canvas.id);
if (Manifesto.Utils.normaliseUrl(id) === canvasId) {
return canvas;
}
}
Expand Down Expand Up @@ -2094,10 +2096,15 @@ var Manifesto;
}
return type;
};
Utils.normaliseUrl = function (url) {
url = url.substr(url.indexOf('://'));
if (url.indexOf('#') !== -1) {
url = url.split('#')[0];
}
return url;
};
Utils.normalisedUrlsMatch = function (url1, url2) {
var url1norm = url1.substr(url1.indexOf('://'));
var url2norm = url1.substr(url1.indexOf('://'));
return url1norm === url2norm;
return Utils.normaliseUrl(url1) === Utils.normaliseUrl(url2);
};
Utils.isImageProfile = function (profile) {
if (Utils.normalisedUrlsMatch(profile.toString(), Manifesto.ServiceProfile.STANFORDIIIFIMAGECOMPLIANCE0.toString()) ||
Expand Down
1 change: 1 addition & 0 deletions dist/manifesto.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ declare namespace Manifesto {
static getLocalisedValue(resource: any, locale: string): string | null;
static generateTreeNodeIds(treeNode: ITreeNode, index?: number): void;
static normaliseType(type: string): string;
static normaliseUrl(url: string): string;
static normalisedUrlsMatch(url1: string, url2: string): boolean;
static isImageProfile(profile: Manifesto.ServiceProfile): boolean;
static isLevel0ImageProfile(profile: Manifesto.ServiceProfile): boolean;
Expand Down
15 changes: 11 additions & 4 deletions dist/server/manifesto.js
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,9 @@ var Manifesto;
Sequence.prototype.getCanvasById = function (id) {
for (var i = 0; i < this.getTotalCanvases(); i++) {
var canvas = this.getCanvasByIndex(i);
if (canvas.id === id) {
// normalise canvas id
var canvasId = Manifesto.Utils.normaliseUrl(canvas.id);
if (Manifesto.Utils.normaliseUrl(id) === canvasId) {
return canvas;
}
}
Expand Down Expand Up @@ -2166,10 +2168,15 @@ var Manifesto;
}
return type;
};
Utils.normaliseUrl = function (url) {
url = url.substr(url.indexOf('://'));
if (url.indexOf('#') !== -1) {
url = url.split('#')[0];
}
return url;
};
Utils.normalisedUrlsMatch = function (url1, url2) {
var url1norm = url1.substr(url1.indexOf('://'));
var url2norm = url1.substr(url1.indexOf('://'));
return url1norm === url2norm;
return Utils.normaliseUrl(url1) === Utils.normaliseUrl(url2);
};
Utils.isImageProfile = function (profile) {
if (Utils.normalisedUrlsMatch(profile.toString(), Manifesto.ServiceProfile.STANFORDIIIFIMAGECOMPLIANCE0.toString()) ||
Expand Down
5 changes: 4 additions & 1 deletion src/Sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ namespace Manifesto {
for (let i = 0; i < this.getTotalCanvases(); i++) {
const canvas = this.getCanvasByIndex(i);

if (canvas.id === id){
// normalise canvas id
const canvasId: string = Utils.normaliseUrl(canvas.id);

if (Utils.normaliseUrl(id) === canvasId){
return canvas;
}
}
Expand Down
15 changes: 11 additions & 4 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,18 @@ namespace Manifesto {
return type;
}

static normaliseUrl(url: string): string {
url = url.substr(url.indexOf('://'));

if (url.indexOf('#') !== -1) {
url = url.split('#')[0];
}

return url;
}

static normalisedUrlsMatch(url1: string, url2: string): boolean {
const url1norm: string = url1.substr(url1.indexOf('://'));
const url2norm: string = url1.substr(url1.indexOf('://'));

return url1norm === url2norm;
return Utils.normaliseUrl(url1) === Utils.normaliseUrl(url2);
}

static isImageProfile(profile: Manifesto.ServiceProfile): boolean {
Expand Down
1 change: 1 addition & 0 deletions test/lunchroommanners.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ describe('#hasRanges', function() {
var usingSoap = washingHands.members[0];
var canvasid = usingSoap.canvases[0];
expect(canvasid).to.equal("http://dlib.indiana.edu/iiif_av/lunchroom_manners/canvas/1#t=157,160");
// get sequence and use .getCanvasById trimming http/s and hash fragment
});
});

0 comments on commit 9193957

Please sign in to comment.