• Hi, we found an issue on pages that reference the same (combination of) citations more than once. This is what we found in our research:

    ISSUE

    1. List of citations is somehow duplicate in <span class="ZP_ITEM_KEY">. This causes multiple runs over same citation refs because intext_citations collection now contains duplicate number of references (as it uses .ZP_ITEM_KEY as source).
    2. The duplicate run is fine if there’s no more than 1 of same citation (or combination of citations) inside the text.
    3. However, if there’s more than 1 citation (of combination of citations), then intextGroupTracker code comes into play (from zotpress.shortcode.intext.js). This piece of code relies on index increase for every loop iteration to lookup intext_citation_params. As ZP_ITEM_KEY contains duplicate list and we have no proper checks in the lookup of intext_citation_params, the script tries to lookup at an index that does not exist. This causes a crash in zotpress.shortcode.intext(.min).js with message like can't access property "replace", jQuery(...).attr(...) is undefined

    FIX (my suggestion):
    Make code for intext_citation_params more resilient for incorrect index (basically for any unexpected list input from ZP_ITEM_KEY). Adjust in zotpress.shortcode.intext.js:

    OLD (line 353):

    // OLD (line 353)
    var intext_citation_params = JSON.parse( jQuery("."+intext_citation_id+":eq("+intext_group_index+")", $postRef ).attr("rel").replace( /'/g, '"') );

    NEW (line 353+):

    var $intext_citation = jQuery("."+intext_citation_id+":eq("+intext_group_index+")", $postRef );
    if ($intext_citation.length === 0 || $intext_citation.attr("rel") === undefined) {
    	console.warn('zp: no valid intext citation ref found at index', intext_citation_id, intext_group_index);
    	return;
    }
    var intext_citation_params = JSON.parse($intext_citation.attr("rel").replace( /'/g, '"') );
    

    TODO (idea)
    Find out maybe why ZP_ITEM_KEY element may contain duplicate list (we have not researched this). Having duplicate list in here may cause other issues as well?

    It would be nice if you could add this fix to the a new release of the plugin. It would help us a great deal. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Katie

    (@kseaborn)

    Can you provide an example? I’m not sure what you mean by duplicates. I’m testing with duplicates and it’s working for me. Here’s a copy-paste:

    <span class="ZP_ITEM_KEY" style="display: none;">{1573921:CZR96TX9};{1573921:9CMKY66V};{1573921:GN25WBKX};{1573921:ZFMCNWUH},{1573921:PWIMX9GU};{1573921:CZR96TX9},{1573921:PWIMX9GU}</span>

    Katie, the issue is not really solved. At the end of the the page the settings icon keeps rotating. I have made an example on our website showing the problem. The example’s html text is:

    This is a text with mutitple citations of the
    same library-item. [zotpressInText item=”{2358552:IK9TE6TJ}”]
    and again [zotpressInText item=”{2358552:IK9TE6TJ}”].

    References:

    [zotpressInTextBib style=”apa” sortby=”author” sort=”ASC”]

    Could you check if this code works correctly as a page on your site?

    Thanks, and kind regards,

    Bert van Zanten

    Thread Starter Maarten vZ

    (@mvzwp202310)

    Hi Katie, sorry for the late response.

    With duplicates I mean also a duplicate list inside de ZP_ITEM_KEY; it’s having all the references in the text twice. So if the text has 2 shortcode refs in the message, the ZP_ITEM_KEY somehow gets that duplicated to 4. (Then the script crashes looking for 3rd and 4th reference).

    The message example Bert gives above:

    This is a text with mutitple citations of thesame library-item. [zotpressInText item="{2358552:IK9TE6TJ}"]
    and again [zotpressInText item="{2358552:IK9TE6TJ}"].
    
    References:[zotpressInTextBib style="apa" sortby="author" sort="ASC"]

    Results in an ZP_ITEM_KEY in our case:

    <span class="ZP_ITEM_KEY" style="display: none;">{2358552:IK9TE6TJ};{2358552:IK9TE6TJ};{2358552:IK9TE6TJ};{2358552:IK9TE6TJ}</span>

    Then zotpress.shortcode.intext.js crashes because it’s looking for reference 3 and 4. My suggested fix works around that.

    Is there maybe something wrong with the config that makes it fill up ZP_ITEM_KEY twice?

    • This reply was modified 11 months, 1 week ago by Maarten vZ.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Issue multiple references in text to same citations + FIX’ is closed to new replies.