NV / flying-focus

UI concept

Home Page:http://n12v.com/focus-transition/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

multiple instances on one page

notslang opened this issue · comments

If I have the flying focus chrome plugin installed and I visit a site that uses the flying focus script, 2 instances of flying focus run on the same page. This creates 2 separate elements (both with the id flying-focus) and they are both animated.

The fact that this happens doesn't actually break anything (they just overlap), and it's not really a performance concern since it's such a light plugin. Rather, it simply feels wrong to have 2 of them running at the same time, especially since both of the elements created have the same id.

So, flying-focus should check if the #flying-focus element has already been created, and exit if it has, to prevent multiple instances.

The extension used to check #flying-focus: flying-focus.jspp.js#L2. I removed when I implemented lazy initialization flying-focus.js#L32-L35, e.g. the flying-focus element gets created on first focus event. In this situation race conditions happen.

I haven’t seen any websites besides mine using the script so I don’t think it isn’t very important issue as for now.

JS is inherently single-threaded, so one of the instances is bound to create the element first, right? Eh, anyway, you're right - it isn't a big issue.

The problem is that flying-focus.js can be initialized either before or after the extension, depending on where script element is (head or end of the body).

exactly, so whichever happens first gets to continue running, the other
just stops. it doesn't matter whether the extension or script is the one
that is running, it's just whichever is first.

On Fri, Dec 27, 2013 at 5:13 PM, Nikita Vasilyev
notifications@github.comwrote:

The problem is that flying-focus.js can be initialized either before or
after the extension, depending on where script element is (head or end of
the body).


Reply to this email directly or view it on GitHubhttps://github.com//issues/7#issuecomment-31284514
.

CodeCombat is using it right now, and I see the issue. (I don't mind it at all; just adding an example of a site that uses it.)

@slang800, that would work. I don’t have much time to test but I’ll accept a pull request.

@nwinter nice, I’m a fan! I just listed it on newly created In the Wild wiki page.