drupal_add_js() has no protection against adding duplicate inline JavaScript. Attached patch ensures the same js is only added once.

CommentFileSizeAuthor
jail.diff707 bytescatch

Comments

catch’s picture

Title: Avoid adding duplicate inline js. » Ensure that jail effects for different formatters work when applied to the same page
Status: Needs review » Needs work

This works, but there's a related problem that the formatter and js only really works for having one formatter displayed on a page, so it needs fixing to target a bit more specifically.

rerooting’s picture

I'd say that it's very important to tackle the issue of the repeat scripts.

I was able to use a tactic similar to this to force ONLY this function to load in the footer:

(function ($) {$(".lazy").jail({placeholder : "/sites/all/modules/jail/white.gif", effect : "fadeIn"});})(jQuery);

In this case, it didn't repeat this function over and over again. When I did this, it resolved a lot of the issues that people have been bringing up - no flickering, works well across browsers, etc. ( I still can't get it to work with infinite scroll but that will just require a callback property). See for yourself! http://dev.sportswriters2.gotpantheon.com/ (only works on the front page)

I'd say that using a different css selector for different formatter instances, and a different function (for different effects, options, etc.) and as well ensuring that there is no duplicate instances of this jquery function will go a long way for this module!