documentcloud / documentcloud-notes

Responsively embed DocumentCloud notes.

Home Page:https://documentcloud.github.io/documentcloud-notes/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Check for jQuery / Underscore before including

seanokey opened this issue · comments

Noticed an issue when trying to embed notes on our article pages – they work, but cause a cascade of errors to the rest of the page with anything else that requires jQuery.

We assign jQuery.noConflict to a different global var ($j) when we call it, but since jQuery is also delivered via note_embed.js it reassigns, breaking other functions called by the footer (or anything that runs after the embed script does).

Could the vendor scripts be checked and called as part of the asset loader rather than minified into note_embed.js to avoid reassigning to the default global vars? While less common, I imagine this would also be an issue for sites that already call Underscore, but reassign to a different global var.

Hey @seanokey, we're also calling noConflict with the intent to side step precisely this issue: https://github.com/documentcloud/documentcloud-notes/blob/master/src/js/note_embed.js#L13 so i'm hoping we haven't messed anything up there.

I dropped into check on a document posted on the CNN site but i'm not sure if what i'm seeing is what you're talking about: http://www.cnn.com/2016/06/28/us/orlando-pulse-police-logs/index.html

Do you have a sample page we could take a look at?

Best,

-Ted

Hi @knowtheory – right, the full document embeds work great. It's the note-specific embeds that are presenting an issue. Because of that, we don't have any live examples, but I'll work something up and message you a test link privately shortly.

Thanks!

-Sean

Oh! duh, sorry about that :) yes of course.

If you have a test page handy i'd love to take a look, otherwise i can put something together to simulate it.

This ended up being a really small but significant oversight on my part.

jQuery.noConflict() needs to be passed true so as not to step on other noConflict'd versions of jQuery.

Fixed in 6152599