admin管理员组文章数量:1406064
I have a problem as I'm conditionally including the Prototype-based Lightbox script for IE6 as it works better than the jQuery plugin.
Of course the two libraries conflict but the official solution is not really feasible for me as i would have to replace tons of $ with the alternative no-conflict syntax.
Is there any other solution for me, keeping in mind that in my case it would be easier to have Prototype work nicely with jQuery than the other way around?
I have a problem as I'm conditionally including the Prototype-based Lightbox script for IE6 as it works better than the jQuery plugin.
Of course the two libraries conflict but the official solution is not really feasible for me as i would have to replace tons of $ with the alternative no-conflict syntax.
Is there any other solution for me, keeping in mind that in my case it would be easier to have Prototype work nicely with jQuery than the other way around?
Share Improve this question edited Dec 29, 2011 at 15:32 Rob W 349k87 gold badges807 silver badges682 bronze badges asked Apr 26, 2010 at 15:52 LorenzoLorenzo 4,66811 gold badges47 silver badges54 bronze badges 1- 2 Any chance of taking the best parts of the script and creating a jquery plugin out of it? – James Westgate Commented Apr 26, 2010 at 16:15
3 Answers
Reset to default 5Not if you need to use Prototype code (your lightbox thing) in the same window as the jQuery code, your only option there is the one you don't want to use: jQuery.noConflict
.
If you could limit the lightbox thing to working in an iframe, you could only load Prototype in the iframe and not your main window. But my suspicion is that that would be overkill for what you're trying to do. :-)
The issue is that Prototype doesn't have a no-conflict option (and right now there's no active plan to provide one) and it's not easily wrapped in a scoping function to contain the symbols (since all you really care about is the global symbols, not the prototype extensions, which jQuery is okay with having around). That said, if you took the prototype.js file and bined it with your lightbox plug-in's file, wrapped the whole thing in a scoping function, and then went hunting for global symbol leaks, you could probably do it. It would be a non-trivial exercise, especially if you're not that familiar with Prototype. But if the iframe thing is overkill, this is probably nuking from orbit. :-)
You could try what I do when working on an application that's based on the Prototype library, but I want some jQuery functionality.
jQuery(document).ready(function($)
{
$("#BoxLabelRange").next('span').mouseenter(function()
{
$("#SearchInformation").slideDown();
})
})
See the parameter that I added to the document.ready, the dollar-sign? Within that function call you can use the jQuery "$" alias without any problems. Works for me. Good luck!
Have you considered taking a look at the jQuery plugin that you say doesn't work that well (I can find a couple, could be this one: http://leandrovieira./projects/jquery/lightbox/), and attempting to make it work better in IE6? If need be, check for IE6-specific fixes in the Prototype version.
I would consider this a better option than trying to get Prototype and jQuery to play nice together.
本文标签: javascriptjQuery Prototype conflictalternative solutionsStack Overflow
版权声明:本文标题:javascript - jQuery Prototype conflict, alternative solutions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744959418a2634561.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论