Skip to content

Commit

Permalink
updated manifesto
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Aug 22, 2018
1 parent 8bd5b63 commit eb39c3e
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 97 deletions.
156 changes: 83 additions & 73 deletions dist/@iiif/manifold.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ var Manifesto;
return new Manifesto.IIIFResourceType(Manifesto.Utils.normaliseType(this.getProperty('type')));
};
ManifestResource.prototype.getLabel = function () {
return Manifesto.TranslationCollection.parse(this.getProperty('label'), this.options.locale);
return Manifesto.LanguageMap.parse(this.getProperty('label'), this.options.locale);
};
ManifestResource.prototype.getMetadata = function () {
var _metadata = this.getProperty('metadata');
Expand Down Expand Up @@ -1155,16 +1155,17 @@ var Manifesto;
return _this;
}
IIIFResource.prototype.getAttribution = function () {
console.warn('getAttribution will be deprecated, use getRequiredStatement instead.');
var attribution = this.getProperty('attribution');
if (attribution) {
return Manifesto.TranslationCollection.parse(attribution, this.options.locale);
return Manifesto.LanguageMap.parse(attribution, this.options.locale);
}
return [];
};
IIIFResource.prototype.getDescription = function () {
var description = this.getProperty('description');
if (description) {
return Manifesto.TranslationCollection.parse(description, this.options.locale);
return Manifesto.LanguageMap.parse(description, this.options.locale);
}
return [];
};
Expand Down Expand Up @@ -1197,24 +1198,33 @@ var Manifesto;
IIIFResource.prototype.getLabel = function () {
var label = this.getProperty('label');
if (label) {
return Manifesto.TranslationCollection.parse(label, this.options.locale);
return Manifesto.LanguageMap.parse(label, this.options.locale);
}
return [];
};
IIIFResource.prototype.getDefaultLabel = function () {
return Manifesto.TranslationCollection.getValue(this.getLabel());
return Manifesto.LanguageMap.getValue(this.getLabel());
};
IIIFResource.prototype.getDefaultTree = function () {
this.defaultTree = new Manifesto.TreeNode('root');
this.defaultTree.data = this;
return this.defaultTree;
};
IIIFResource.prototype.getRequiredStatement = function () {
var requiredStatement = null;
var _requiredStatement = this.getProperty('requiredStatement');
if (!_requiredStatement)
return null;
var requiredStatement = new Manifesto.LabelValuePair(this.options.locale);
requiredStatement.parse(_requiredStatement);
if (_requiredStatement) {
requiredStatement = new Manifesto.LabelValuePair(this.options.locale);
requiredStatement.parse(_requiredStatement);
}
else {
// fall back to attribution (if it exists)
var attribution = this.getAttribution();
if (attribution) {
requiredStatement = new Manifesto.LabelValuePair(this.options.locale);
requiredStatement.value = attribution;
}
}
return requiredStatement;
};
IIIFResource.prototype.isCollection = function () {
Expand Down Expand Up @@ -1243,7 +1253,7 @@ var Manifesto;
id = that.__jsonld['@id'];
}
Manifesto.Utils.loadResource(id).then(function (data) {
that.parentLabel = Manifesto.TranslationCollection.getValue(that.getLabel(), options_1.locale);
that.parentLabel = Manifesto.LanguageMap.getValue(that.getLabel(), options_1.locale);
var parsed = Manifesto.Deserialiser.parse(data, options_1);
that = Object.assign(that, parsed);
that.index = options_1.index;
Expand Down Expand Up @@ -1590,7 +1600,7 @@ var Manifesto;
for (var i = 0; i < parentCollection.getManifests().length; i++) {
var manifest = parentCollection.getManifests()[i];
var tree = manifest.getDefaultTree();
tree.label = manifest.parentLabel || Manifesto.TranslationCollection.getValue(manifest.getLabel(), this.options.locale) || 'manifest ' + (i + 1);
tree.label = manifest.parentLabel || Manifesto.LanguageMap.getValue(manifest.getLabel(), this.options.locale) || 'manifest ' + (i + 1);
tree.navDate = manifest.getNavDate();
tree.data.id = manifest.id;
tree.data.type = Manifesto.Utils.normaliseType(Manifesto.TreeNodeType.MANIFEST.toString());
Expand All @@ -1603,7 +1613,7 @@ var Manifesto;
for (var i = 0; i < parentCollection.getCollections().length; i++) {
var collection = parentCollection.getCollections()[i];
var tree = collection.getDefaultTree();
tree.label = collection.parentLabel || Manifesto.TranslationCollection.getValue(collection.getLabel(), this.options.locale) || 'collection ' + (i + 1);
tree.label = collection.parentLabel || Manifesto.LanguageMap.getValue(collection.getLabel(), this.options.locale) || 'collection ' + (i + 1);
tree.navDate = collection.getNavDate();
tree.data.id = collection.id;
tree.data.type = Manifesto.Utils.normaliseType(Manifesto.TreeNodeType.COLLECTION.toString());
Expand Down Expand Up @@ -1747,7 +1757,7 @@ var Manifesto;
return false;
};
Range.prototype._parseTreeNode = function (node, range) {
node.label = Manifesto.TranslationCollection.getValue(range.getLabel(), this.options.locale);
node.label = Manifesto.LanguageMap.getValue(range.getLabel(), this.options.locale);
node.data = range;
node.data.type = Manifesto.Utils.normaliseType(Manifesto.TreeNodeType.RANGE.toString());
range.treeNode = node;
Expand Down Expand Up @@ -1881,7 +1891,7 @@ var Manifesto;
for (var i = 0; i < this.getTotalCanvases(); i++) {
var canvas = this.getCanvasByIndex(i);
// check if there's a literal match
if (Manifesto.TranslationCollection.getValue(canvas.getLabel(), this.options.locale) === label) {
if (Manifesto.LanguageMap.getValue(canvas.getLabel(), this.options.locale) === label) {
return i;
}
// check if there's a match for double-page spreads e.g. 100-101, 100_101, 100 101
Expand All @@ -1903,7 +1913,7 @@ var Manifesto;
Sequence.prototype.getLastCanvasLabel = function (alphanumeric) {
for (var i = this.getTotalCanvases() - 1; i >= 0; i--) {
var canvas = this.getCanvasByIndex(i);
var label = Manifesto.TranslationCollection.getValue(canvas.getLabel(), this.options.locale);
var label = Manifesto.LanguageMap.getValue(canvas.getLabel(), this.options.locale);
if (alphanumeric) {
var regExp = /^[a-zA-Z0-9]*$/;
if (regExp.test(label)) {
Expand Down Expand Up @@ -2307,7 +2317,7 @@ var Manifesto;
this.height = width;
}
this.uri = canvas.getCanonicalImageUri(width);
this.label = Manifesto.TranslationCollection.getValue(canvas.getLabel()); // todo: pass locale?
this.label = Manifesto.LanguageMap.getValue(canvas.getLabel()); // todo: pass locale?
}
return Thumb;
}());
Expand Down Expand Up @@ -3125,29 +3135,6 @@ var Manifesto;
Manifesto.Utils = Utils;
})(Manifesto || (Manifesto = {}));

var Manifesto;
(function (Manifesto) {
var Translation = /** @class */ (function () {
function Translation(value, locale) {
if (Array.isArray(value)) {
if (value.length === 1) {
this.value = value[0];
}
else {
// concatenate all of the values
this.value = value.join('<br/>');
}
}
else {
this.value = value;
}
this.locale = locale;
}
return Translation;
}());
Manifesto.Translation = Translation;
})(Manifesto || (Manifesto = {}));

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
Expand All @@ -3163,74 +3150,74 @@ var __extends = (this && this.__extends) || (function () {
})();
var Manifesto;
(function (Manifesto) {
var TranslationCollection = /** @class */ (function (_super) {
__extends(TranslationCollection, _super);
function TranslationCollection() {
var LanguageMap = /** @class */ (function (_super) {
__extends(LanguageMap, _super);
function LanguageMap() {
return _super !== null && _super.apply(this, arguments) || this;
}
TranslationCollection.parse = function (translation, defaultLocale) {
LanguageMap.parse = function (language, defaultLocale) {
var tc = [];
var t;
if (!translation) {
if (!language) {
return tc;
}
else if (Array.isArray(translation)) {
for (var i = 0; i < translation.length; i++) {
var value = translation[i];
else if (Array.isArray(language)) {
for (var i = 0; i < language.length; i++) {
var value = language[i];
if (typeof (value) === 'string') {
t = new Manifesto.Translation(value, defaultLocale);
t = new Manifesto.Language(value, defaultLocale);
}
else {
t = new Manifesto.Translation(value['@value'], value['@language'] || defaultLocale);
t = new Manifesto.Language(value['@value'], value['@language'] || defaultLocale);
}
tc.push(t);
}
}
else if (typeof (translation) === 'string') {
// if it's just a single string value, create one translation in the configured locale
t = new Manifesto.Translation(translation, defaultLocale);
else if (typeof (language) === 'string') {
// if it's just a single string value, create one language in the configured locale
t = new Manifesto.Language(language, defaultLocale);
tc.push(t);
return tc;
}
else {
// it's an object
if (translation['@value']) {
if (language['@value']) {
// presentation 2
t = new Manifesto.Translation(translation['@value'], translation['@language'] || defaultLocale);
t = new Manifesto.Language(language['@value'], language['@language'] || defaultLocale);
tc.push(t);
}
else {
// presentation 3
Object.keys(translation).forEach(function (key) {
Object.keys(language).forEach(function (key) {
// todo: support multiple values in array
if (translation[key].length) {
t = new Manifesto.Translation(translation[key], key);
if (language[key].length) {
t = new Manifesto.Language(language[key], key);
tc.push(t);
}
else {
throw new Error('Translation must have a value');
throw new Error('language must have a value');
}
});
}
}
return tc;
};
TranslationCollection.getValue = function (translationCollection, locale) {
if (translationCollection.length) {
LanguageMap.getValue = function (languageCollection, locale) {
if (languageCollection.length) {
if (locale) {
var translation = translationCollection.en().where(function (t) { return t.locale === locale || Manifesto.Utils.getInexactLocale(t.locale) === Manifesto.Utils.getInexactLocale(locale); }).first();
if (translation) {
return translation.value;
var language = languageCollection.en().where(function (t) { return t.locale === locale || Manifesto.Utils.getInexactLocale(t.locale) === Manifesto.Utils.getInexactLocale(locale); }).first();
if (language) {
return language.value;
}
}
// return the first valuel
return translationCollection[0].value;
return languageCollection[0].value;
}
return null;
};
return TranslationCollection;
return LanguageMap;
}(Array));
Manifesto.TranslationCollection = TranslationCollection;
Manifesto.LanguageMap = LanguageMap;
})(Manifesto || (Manifesto = {}));

var Manifesto;
Expand All @@ -3249,15 +3236,15 @@ global.manifesto = global.Manifesto = module.exports = {
AnnotationMotivation: new Manifesto.AnnotationMotivation(),
Behavior: new Manifesto.Behavior(),
IIIFResourceType: new Manifesto.IIIFResourceType(),
LabelValuePair: Manifesto.LabelValuePair,
LanguageMap: Manifesto.LanguageMap,
ManifestType: new Manifesto.ManifestType(),
MediaType: new Manifesto.MediaType(),
LabelValuePair: Manifesto.LabelValuePair,
RenderingFormat: new Manifesto.RenderingFormat(),
ResourceType: new Manifesto.ResourceType(),
ServiceProfile: new Manifesto.ServiceProfile(),
Size: Manifesto.Size,
Translation: Manifesto.Translation,
TranslationCollection: Manifesto.TranslationCollection,
Translation: Manifesto.Language,
TreeNode: Manifesto.TreeNode,
TreeNodeType: new Manifesto.TreeNodeType(),
Utils: Manifesto.Utils,
Expand Down Expand Up @@ -3509,13 +3496,13 @@ var Manifesto;
}
LabelValuePair.prototype.parse = function (resource) {
this.resource = resource;
this.label = Manifesto.TranslationCollection.parse(this.resource.label, this.defaultLocale);
this.value = Manifesto.TranslationCollection.parse(this.resource.value, this.defaultLocale);
this.label = Manifesto.LanguageMap.parse(this.resource.label, this.defaultLocale);
this.value = Manifesto.LanguageMap.parse(this.resource.value, this.defaultLocale);
};
// shortcuts to get/set values based on default locale
LabelValuePair.prototype.getLabel = function () {
if (this.label) {
return Manifesto.TranslationCollection.getValue(this.label, this.defaultLocale);
return Manifesto.LanguageMap.getValue(this.label, this.defaultLocale);
}
return null;
};
Expand All @@ -3534,7 +3521,7 @@ var Manifesto;
if (this.label.length && this.label[0].locale) {
locale = this.label[0].locale;
}
return Manifesto.TranslationCollection.getValue(this.value, locale);
return Manifesto.LanguageMap.getValue(this.value, locale);
}
return null;
};
Expand All @@ -3551,6 +3538,29 @@ var Manifesto;
Manifesto.LabelValuePair = LabelValuePair;
})(Manifesto || (Manifesto = {}));

var Manifesto;
(function (Manifesto) {
var Language = /** @class */ (function () {
function Language(value, locale) {
if (Array.isArray(value)) {
if (value.length === 1) {
this.value = value[0];
}
else {
// concatenate all of the values
this.value = value.join('<br/>');
}
}
else {
this.value = value;
}
this.locale = locale;
}
return Language;
}());
Manifesto.Language = Language;
})(Manifesto || (Manifesto = {}));

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
Expand Down
11 changes: 6 additions & 5 deletions dist/@iiif/manifold.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,10 @@ var Manifold;
return null;
};
Helper.prototype.getAttribution = function () {
console.warn('getAttribution will be deprecated, use getRequiredStatement instead.');
var attribution = this.manifest.getAttribution();
if (attribution) {
return Manifesto.TranslationCollection.getValue(attribution, this.options.locale);
return Manifesto.LanguageMap.getValue(attribution, this.options.locale);
}
return null;
};
Expand Down Expand Up @@ -535,7 +536,7 @@ var Manifold;
Helper.prototype.getDescription = function () {
var description = this.manifest.getDescription();
if (description) {
return Manifesto.TranslationCollection.getValue(description, this.options.locale);
return Manifesto.LanguageMap.getValue(description, this.options.locale);
}
return null;
};
Expand All @@ -545,7 +546,7 @@ var Manifold;
Helper.prototype.getLabel = function () {
var label = this.manifest.getLabel();
if (label) {
return Manifesto.TranslationCollection.getValue(label, this.options.locale);
return Manifesto.LanguageMap.getValue(label, this.options.locale);
}
return null;
};
Expand Down Expand Up @@ -578,14 +579,14 @@ var Manifold;
}
if (this.manifest.getDescription().length) {
var metadataItem = new Manifesto.LabelValuePair(this.options.locale);
metadataItem.label = [new Manifesto.Translation("description", this.options.locale)];
metadataItem.label = [new Manifesto.Language("description", this.options.locale)];
metadataItem.value = this.manifest.getDescription();
metadataItem.isRootLevel = true;
manifestGroup.addItem(metadataItem);
}
if (this.manifest.getAttribution().length) {
var metadataItem = new Manifesto.LabelValuePair(this.options.locale);
metadataItem.label = [new Manifesto.Translation("attribution", this.options.locale)];
metadataItem.label = [new Manifesto.Language("attribution", this.options.locale)];
metadataItem.value = this.manifest.getAttribution();
metadataItem.isRootLevel = true;
manifestGroup.addItem(metadataItem);
Expand Down
2 changes: 1 addition & 1 deletion dist/manifold.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @iiif/manifold v1.2.31 https:/iiif-commons/manifold#readme
// @iiif/manifold v1.2.32 https:/iiif-commons/manifold#readme
interface Window {
manifestCallback: any;
}
Expand Down
Loading

0 comments on commit eb39c3e

Please sign in to comment.