Thr*_*igh 3 jquery conflict magento prototypejs
我正在尝试将使用jQuery 的svg编辑 - 编辑器集成到Magento中.问题是Magento使用Prototype,因此我正在使用该jQuery.noConflict();方法.一切都很好,直到我通过函数调用编辑器然后Firebug抛出以下错误:
$ .extend不是函数
if(config) {
$.extend(curConfig, config);
}
Run Code Online (Sandbox Code Playgroud)
$ .isArray不是一个函数
} else if($.isArray(key)) {
Run Code Online (Sandbox Code Playgroud)
错误发生在svgcanvas.js的第59行和第121 行.我希望有更多使用jquery和prototype的经验可以帮助我解决这个问题.
尝试将你的函数放入
(function( $ ){
})( jQuery );
Run Code Online (Sandbox Code Playgroud)
所以它看起来像
(function( $ ){
jQuery.fn.attr = function(key, value) {
var len = this.length;
if(!len) return this;
for(var i=0; i<len; i++) {
var elem = this[i];
// set/get SVG attribute
if(elem.namespaceURI === svgns) {
// Setting attribute
if(value !== undefined) {
elem.setAttribute(key, value);
} else if($.isArray(key)) {
// Getting attributes from array
var j = key.length, obj = {};
while(j--) {
var aname = key[j];
var attr = elem.getAttribute(aname);
// This returns a number when appropriate
if(attr || attr === "0") {
attr = isNaN(attr)?attr:attr-0;
}
obj[aname] = attr;
}
return obj;
} else if(typeof key === "object") {
// Setting attributes form object
for(var v in key) {
elem.setAttribute(v, key[v]);
}
// Getting attribute
} else {
var attr = elem.getAttribute(key);
if(attr || attr === "0") {
attr = isNaN(attr)?attr:attr-0;
}
return attr;
}
} else {
return proxied.apply(this, arguments);
}
}
return this;
};
})( jQuery );
Run Code Online (Sandbox Code Playgroud)