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

时间:2016-02-09 06:34:38

标签: javascript jquery froala

当我们使用较旧的jQuery版本(1.4)和较新的版本(1.11)时,我们有两个不同的命名空间。 1.4使用标准$和1.11使用jQuery1111。

现在我正在尝试实现需要使用1.11版本的froala编辑器。我已将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)));

但这给了我错误a is not a function(但脚本似乎能够运行)。错误发生在上面脚本的第4行。

如果我将第4行的a(jQuery)更改为jQuery1111,它会运行且没有错误,但我不确定这些是否正确或稍后是否会导致错误。

这是将第三方组件实现到非默认jQuery名称空间的正确方法吗?

更新:脚本订单

内部<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>

内部<body />

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

1 个答案:

答案 0 :(得分:0)

您可以更改脚本包含的顺序以修复问题而无需修改第三方库

<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>
相关问题