-
Notifications
You must be signed in to change notification settings - Fork 589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading spectrum via a script loader (e.g. yepnope) #41
Comments
That is surprising. Can you send a jsbin or jsfiddle example? I don't have any experience with yepnope, so I'll be interested to see how that loading happens. |
|
Thanks for the fast reply, here is a jsfiddle that demonstrates the error: http://jsfiddle.net/jZxNR/5/ I wonder if it has anything to do with the asynchronous nature of yepnope's loading? |
This is really weird, but I got it working by wrapping everything in |
But can you confirm that the new fiddle is working? |
Strange, I'm still getting the error in that fiddle (revision 6). Testing now on OS X, still in FireFox 16.0 |
Oh that is weird - for some reason the document ready call here https://github.com/bgrins/spectrum/blob/master/spectrum.js#L786 is firing before the rest of the script evaluates (when I move that to the bottom of the file the issue goes away). I guess because the document is ready when yepnope loads. I can move that call to the bottom of the file. Try this one: http://jsfiddle.net/jZxNR/7/ |
That seemed to do the trick! Will that change be making its way into master or should I use the yepnope branch? |
I'll merge it into master so it will work for everyone |
Can you confirm that it is working now on master on your original link: http://jsfiddle.net/jZxNR/5/? |
Yes, it is working on the original fiddle. Thanks so much for your work on this, best colorpicker component I've found and a huge plus that it doesn't use images and works easily as a shim/pollyfill. |
Thanks! |
Is it possible to merge this into master ? i got the same problem with requireJS. Thanks |
I thought this was working. The original fiddle has some broken CSS/JS links, but when I updated those it seemed to work: http://jsfiddle.net/bgrins/jZxNR/12/. Can you send a link with it failing on requireJS? |
maybe there is something i'm missing but trying to use spectrum with require js give 'tinycolor is not defined' |
Github changed their pages to not serve scripts, so I had to change the URL to |
it works with your link but the version of the libs are not the same. So i guess it is failing with the last one only. Not working version : v0.9.16 |
Most notable change is tinycolor that dont export his object globally : |
related to #113 and your last commit i guess |
wait, so |
it is not that In previous versions of tinycolor it was always exporting I dont know if you are up to or if there is a specific reason you did not do it but i guess i would suggest to treat tinycolor as a dependency and put it in a So non requirejs user would import jquery, tinycolor, spectrum in their html. For requirejs (and other AMD loader) to be able to use spectrum correctly you would also need to replace current anonymous function that wrap your plugin to something like that :
it is just a suggestion, and i understand it can be some work. I could make a fork to demonstrate how it could work if you want. Let me know. |
OK, I think I see. So for the spectrum version of tinycolor, we really need to just remove that whole if/else block and just set Would the problem be fixed by replacing this:
With this?
|
Yes replacing whole if/else block with only But each time you update tinycolor you will need to remember to make that change again. Again managing tinycolor as a dependency would be more bulletproof imo, but you are the maintainer :) Thanks for your plugin and implication. |
Yes, and that is a concern with implementing it this way. However, I don't want to split the development into multiple files because I think having it in a single file makes the usage instructions more simple. Can you think of any way to make the |
i guess you could keep the code as it is. I just found that it is sufficient to make tinycolor a global object in the requirejs callback. See http://jsfiddle.net/efMmB/17/ current code is working with requirejs used like that. |
@fadomire can you check now with https://raw.github.com/bgrins/spectrum/master/spectrum.js? I added a call to |
@bgrins i checked and it gives the same error as before. But did you checked my previous comment ? i found that assigning window.tinycolor in the requirejs callback makes it working as expected as shown here : |
Yes I saw the workaround, but I'd like for users to not have to have extra code :). Can you check https://raw.github.com/bgrins/spectrum/master/spectrum.js now and see if it is working after just forcing it to be set to window? I still feel like there should be a way to handle this outside of the tinycolor modifications, but I'm OK with manually copying this change over if there isn't - as it doesn't change that often. Could we directly call |
Your last version, where you changed tinycolor code and make it always But i think there is a misunderstanding about requirejs behavior. What happens is requirejs load spectrum lib, and in his load callback we pass tinycolor object returned by the following code :
the only extra code is to assign tinycolor to global scope in the load callback :
I'm not sure what you mean by "Could we directly call require after the initialization of tinycolor". IMO best options to fix this issue are : Overriding tinycolor default code just feel wrong. Sorry for the explanation if it was already clear :) |
Thanks for the explanation, I saw the extra require callback as an inconvenience to requirejs users, but it sounds like it may not be that big of a deal. What I meant by a workaround without extra HTTP calls / code, is that I wanted to do what you are doing, only inside the library so users wouldn't have to. So something like:
Two issues here:
|
I am trying to load spectrum via modernizr and yepnope. It loads spectrum.js correctly, but throws the error "tinycolor is not defined" on line 433. Is there a preferred way to load spectrum as a conditional polyfill. Testing in FireFox 16 Chromium Debian.
The text was updated successfully, but these errors were encountered: