简体   繁体   English

更改第3方组件的jQuery名称空间

[英]Change jQuery namespace of a 3rd party component

As we using an older jQuery version (1.4) along with a newer one (1.11), we have 2 different namespaces for them. 当我们使用较旧的jQuery版本(1.4)和较新的jQuery版本(1.11)时,它们有2个不同的命名空间。 1.4 uses the standard $ and 1.11 uses jQuery1111. 1.4使用标准$,而1.11使用jQuery1111。

Now I'm trying to implement the froala editor, which need to use the 1.11 version. 现在,我正在尝试实现froala编辑器,该编辑器需要使用1.11版本。 I've changed the froala code to this to make that happen: 我已经将froala代码更改为此,以实现此目的:

(function (a) {
    "function" == typeof define && define.amd ? define(["jquery"], a) : "object" == typeof module && module.exports ? module.exports = function (b, c) {
        return void 0 === c && (c = "undefined" != typeof window ? require("jquery") : require("jquery")(b)), a(c), c
    } : a(jQuery)
}(function (a) {

...

}(window.jQuery1111)));

But this gives me the error a is not a function (but the script seems to be able to run). 但这给了我错误a is not a function (但是脚本似乎可以运行)。 The error is caught on the 4th line in the script above. 错误被捕获在上面脚本的第四行。

If I change a(jQuery) on the 4th line to jQuery1111 it runs with no errors, but Im not sure if thats correct or if it will result in a bug later on. 如果我将第4行a(jQuery)更改为jQuery1111则它运行时没有错误,但是我不确定那是否正确,否则以后是否会导致错误。

Is this the correct way of implementing a 3rd party component into a non default jQuery namespace? 这是将第3方组件实现到非默认jQuery名称空间中的正确方法吗?

Update: Script Order 更新:脚本顺序

Inside <head /> <head />

<script src="/js/jquery.js" type="text/javascript"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
    var jQuery1111 = jQuery.noConflict(true);
    window.jQuery1111 = window.jQuery1111 || jQuery1111;
</script>

Inside <body /> 内部<body />

<script type="text/javascript" src="/scripts/froala_editor.min.js"></script>

You could change the order of script include to fix the issue without modifying the 3rd party libraries 您可以更改脚本包含的顺序以解决此问题,而无需修改第三方库

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/froala-editor/2.1.0/js/froala_editor.min.js"></script>
<script type="text/javascript">
  var jQuery1111 = jQuery.noConflict(true);
  window.jQuery1111 = window.jQuery1111 || jQuery1111;
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM