开发者

Silverstripe Userforms Prototype and jQuery conflicts

I'm having a nightmare with javascript at the moment which hopefully someone can help out with. I'm using the Userforms module, which I've also added my own jQuery code to such that the default value of a textfield disappears when clicked, and reappears if loses focus and is null.

I'm also trying to implement a slideshow on the same page. I can't use jQuery for this, due to compatibility issues with IE8 (don't you just hate Microsoft!). Using Prototype instead, I'm getting loads of random errors which I can only guess 开发者_StackOverfloware being caused by the fact that I'm including prototype.js twice, once for the slideshow at the top of the page, and once at the bottom of the page which is injected by userforms somehow. If I remove my include at the top, my slideshow produces a missing Prototype lib error.

I'm attempting to use jQuery.NoConflict to prevent problems with multiple hooking of the $ token, but I've just ended up with a mess of javascript errors and conflicts.

Is there any way to control how userforms uses/includes javascript includes (jQuery and prototype)?

Any help or advice would be much appreciated! Many Thanks


  • If you're using jQuery noConflict correctly, there shouldn't be any issues with Prototype.
  • Including Prototype twice calls for problems.
  • If your slideshow requires the JS to be included in the head (discouraged for performance reasons), you can force SilverStripe to load the JS in the head. Include the following in your init() function:

    Requirements::set_write_js_to_body(false);
    
  • If that doesn't solve your problem, do you require two different versions of Prototype? If so, I would either try to fix the problems or switch the slideshow plugin - there should be loads of alternatives. Including 3 JS libraries on your page sounds like a major overkill - think about load times...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜