Skip to content

Commit d3f0a8d

Browse files
committed
fix javascript when not on an ao page
1 parent 8c8f26e commit d3f0a8d

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

frontend/assets/getty_barcode.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
(function(exports) {
22
$(document).on("loadedrecordform.aspace", function(event, $pane) {
3-
const name = $('label[for=archival_object_component_id_]').parent().find('div').text() || document.location.hash.split('::')[1];
4-
const data = $('label[for=archival_object_ref_id_]').parent().find('.identifier-display').text();
5-
const text = document.location.hash.split('::')[1].split('_')[2];
3+
const loc_hash = document.location.hash.split('::');
4+
if (loc_hash.length > 1) {
5+
const name = $('label[for=archival_object_component_id_]').parent().find('div').text() || loc_hash[1];
6+
const data = $('label[for=archival_object_ref_id_]').parent().find('.identifier-display').text();
7+
const text = loc_hash[1].split('_')[2];
68

7-
if (data) {
8-
const url = AS.app_prefix('/plugins/getty_barcode?data=' + data + '&name=barcode_' + name + '&text=' + text);
9-
const bbut = '<a id="getty-barcode-button" class="btn btn-sm btn-default" href="' + url + '">Barcode</a>';
10-
$('.record-toolbar > .btn-toolbar > .btn-group').prepend(bbut);
9+
if (data) {
10+
const url = AS.app_prefix('/plugins/getty_barcode?data=' + data + '&name=barcode_' + name + '&text=' + text);
11+
const bbut = '<a id="getty-barcode-button" class="btn btn-sm btn-default" href="' + url + '">Barcode</a>';
12+
$('.record-toolbar > .btn-toolbar > .btn-group').prepend(bbut);
1113

12-
// show the barcode in the title area. disable for now. not sure if it's required
13-
// const bimg = '<div class="pull-right"><a href="' + url + '" title="Click to download"><img id="getty-barcode-image" style="height:50px;" src="' + url + '"/></a></div>';
14-
// $('.record-pane').prepend(bimg);
14+
// show the barcode in the title area. disable for now. not sure if it's required
15+
// const bimg = '<div class="pull-right"><a href="' + url + '" title="Click to download"><img id="getty-barcode-image" style="height:50px;" src="' + url + '"/></a></div>';
16+
// $('.record-pane').prepend(bimg);
17+
}
1518
}
1619
});
1720
}(window));

0 commit comments

Comments
 (0)