[Archivesspace_Users_Group] overriding javascript via plugin

Majewski, Steven Dennis (sdm7g) sdm7g at eservices.virginia.edu
Tue Apr 25 14:01:34 EDT 2017


Your screenshot was dropped from your email, so I don’t know exactly what you want, but you can monkey patch ResourceRenderer methods and change or decorate output with something like this in your plugins/local/frontend/views/layout_head_html.erb:


<meta name="controller" content="<%= controller.controller_name %>" />
<script type="text/javascript">
    var controller = $('html head meta[name="controller"]' ).attr('content');
    console.log( controller + " Controller");
</script>
<% if controller.controller_name == 'resources' %>
<script type="text/javascript" >
    $( function() {
        if (typeof(ResourceRenderer) != 'undefined') {
            var _build_container_summary = ResourceRenderer.prototype.build_container_summary; // stash old method
            ResourceRenderer.prototype.build_container_summary = function (node) {
                var summary = _build_container_summary.apply(this, [node]);  // call old method
                console.log(node);
                console.log(summary);
                return `[ ${summary} ]`;
            };
        }
    });
</script>
<% end %>

( Strip out all of the console.log debugging after you get it to do what you want. )


In a different use case, for adding IIIF image viewers for digital objects, what I want to modify is not available until the digital object file versions accordion is expanded, so I had to bind the bootstrap event to the body and delegate the event to the accordion element:

$('body').on( 'show.bs.collapse', '#digital_object_file_versions__accordion', 'data',  function ($x) {...} );



— Steve M.


On Apr 20, 2017, at 10:50 AM, Kevin Clair <Kevin.Clair at du.edu<mailto:Kevin.Clair at du.edu>> wrote:

Hello,

I’m wondering if anyone on the list has managed to write a plugin to override Javascript functions in the ArchivesSpace frontend. Here at Denver our preference is to display component IDs in the resource tree view instead of Top Container information (see attached screenshot). Currently we do this through our local plugins [1], but since it looks like v2.0.0 moves all of that functionality into the script at https://github.com/archivesspace/archivesspace/blob/master/frontend/app/assets/javascripts/tree_renderers.js.erb, I can’t figure out a way to customize the tree rendering to override the default behavior.

There will likely be local resistance to upgrading if we lose this display customization, so any help with this would be appreciated. thanks!  -k

[1] https://github.com/duspeccoll/plugins_local/blob/master/frontend/views/shared/_tree.html.erb

_______________________________________________
Archivesspace_Users_Group mailing list
Archivesspace_Users_Group at lyralists.lyrasis.org<mailto:Archivesspace_Users_Group at lyralists.lyrasis.org>
http://lyralists.lyrasis.org/mailman/listinfo/archivesspace_users_group

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lyralists.lyrasis.org/pipermail/archivesspace_users_group/attachments/20170425/590c502a/attachment.html>


More information about the Archivesspace_Users_Group mailing list