Using different versions of jQuery and jQueryUI together

前端 未结 3 1015
心在旅途
心在旅途 2020-12-02 15:53

I am working on a project where their framework uses jQuery 1.3.2 and jQueryUI 1.7.2.

Upgrading the versions in the framework is not a possibility so i wanted to run

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 16:30

    AFAIK, there's no $.noConflict() equivalent for jQuery UI. You can, however, use a local copy of jQuery UI and wrap the whole JS using a similar trick to what you use for aliasing the different libraries:

    (function(jQuery) {
      // ... the jQuery UI lib code for jQuery 1.3.2
    })(j$132);
    

    This could be elegantly implemented using a server-side build script or a handler that serves the JS files but wraps the contents with the above code.

    Haven't tested this approach, so you may have to fiddle around with the function parameter (although I think it's safe to assume it uses jQuery to reference jQuery within the plugin code).

    The way you'd use this is declare both versions of jQuery:

      
    
    
    
    
    

    ... and then include your UI code, as I've specified above.

    And no, you can't do this while referencing the UI JS files from Google CDN.

    EDIT: The second code block in the question is actually a better solution than this answer, since it doesn't require wrapping the original UI code in a self-executing function and passing the specific version. Both approaches do result in exactly the same state on the page.

提交回复
热议问题