首页 » 二次开发 » 阅读文章

ecshop中jQuery致命冲突解决方案

2010-07-20 16:49 15958 6 发表评论

主要就是Ecshop的AJAX传输类,transport.js中重写了object的对象原型,从而导致了与jq框架的冲突。
解决:
1. 删除[shan chu]transport.js中587行 – 636行中关于object.prototype.toJSONString的定义
2. 自定义一个方法用于object对象的json序列化
如下
function obj2str(o)
{
//开始
var r = [];
if(typeof o ==”string”) return “\””+o.replace(/([\’\”[url=file://\\])/g,]\\])/g,”\\$1″).replace(/(\n)/g,”\\n”).replace(/(\r)/g,”\\r”).replace(/(\t)/g,”\\t”)+”\[/url]””;
if(typeof o ==”undefined”) return “undefined”;
if(typeof o == “object”){
if(o===null) return “null”;
else if(!o.sort){
for(var i in o)
{
if(i!=”toJSONString”) //增加判断,清除对object原型的定义加入到json中
r.push(“\””+i+”\””+”:”+obj2str(o));
}
r=”{“+r.join()+”}”;
}else{
for(var i =0;i<o.length;i++)
r.push(obj2str(o))
r=”[“+r.join()+”]”
}
return r;
}
return o.toString();
//结束
}
3. 在模板页和js脚本中所有对于obj.toJSONString()的地方,一概替换为obj2str(obj)
4. 重写好后发现compare.js, 主要重写其中的定时器功能。 将以下代码替换到compare.js中
var Compare = new Object();
Compare = {
add : function(goodsId, goodsName, type)
{
var count = 0;
for (var k in this.data)
{
if (typeof(this.data[k]) == “function”)
continue;
if (this.data[k].t != type) {
alert(goods_type_different.replace(“%s”, goodsName));
return;
}
count++;
}
if (this.data[goodsId])
{
alert(exist.replace(“%s”,goodsName));
return;
}
else
{
this.data[goodsId] = {n:goodsName,t:type};
}
this.save();
this.init();
},
init : function(){
this.data = new Object();
var cookieValue = document.getCookie(“compareItems”);
if (cookieValue != null) {
this.data = cookieValue.parseJSON();
}
if (!this.compareBox)
{
this.compareBox = document.createElement(“DIV”);
var submitBtn = document.createElement(“INPUT”);
this.compareList = document.createElement(“UL”);
this.compareBox.id = “compareBox”;
this.compareBox.style.display = “none”;
this.compareBox.style.top = “200px”;
this.compareBox.align = “center”;
this.compareList.id = “compareList”;
submitBtn.type = “button”;
submitBtn.value = button_compare;
this.compareBox.appendChild(this.compareList);
this.compareBox.appendChild(submitBtn);
submitBtn.onclick = function() {
var cookieValue = document.getCookie(“compareItems”);
var obj = cookieValue.parseJSON();
var url = document.location.href;
url = url.substring(0,url.lastIndexOf(‘/’)+1) + “compare.php”;

var i = 0;
for(var k in obj)
{
if(typeof(obj[k])==”function”)
continue;
if(i==0)
url += “?goods[]=” + k;
else
url += “&goods[]=” + k;
i++;
}
if(i<2)
{
alert(compare_no_goods);
return ;
}
document.location.href = url;
}
document.body.appendChild(this.compareBox);
}
this.compareList.innerHTML = “”;
var self = this;
for (var key in this.data)
{
if(typeof(this.data[key]) == “function”)
continue;
var li = document.createElement(“LI”);
var span = document.createElement(“SPAN”);
span.style.overflow = “hidden”;
span.style.width = “100px”;
span.style.height = “20px”;
span.style.display = “block”;
span.innerHTML = this.data[key].n;
li.appendChild(span);
li.style.listStyle = “none”;
var delBtn = document.createElement(“IMG”);
delBtn.src = “themes/default/images/drop.gif”;
delBtn.className = key;
delBtn.onclick = function(){
document.getElementById(“compareList”).removeChild(this.parentNode);
delete self.data[this.className];
self.save();
self.init();
}
li.insertBefore(delBtn,li.childNodes[0]);
this.compareList.appendChild(li);
}
if (this.compareList.childNodes.length > 0)
{
this.compareBox.style.display = “”;
this.timer = window.setInterval(“flowdiv(‘compareBox’)”, 50);
}
else
{
this.compareBox.style.display = “none”;
window.clearInterval(this.timer);
this.timer = 0;
}
},
save : function()
{
var date = new Date();
date.setTime(date.getTime() + 99999999);
document.setCookie(“compareItems”, obj2str(this.data));
},
lastScrollY : 0
}

//用于定时器的自动滚动的层
lastScrollY=0;
function flowdiv(domid){
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
diffY = document.documentElement.scrollTop;
else if (document.body)
diffY = document.body.scrollTop
else
{/*Netscape stuff*/}
//alert(diffY);
percent=.1*(diffY-lastScrollY);
if(percent>0) percent=Math.ceil(percent);
else percent=Math.floor(percent);
document.getElementById(domid).style.top=parseInt(document.getElementById(domid).style.top)+percent+”px”;
lastScrollY=lastScrollY+percent;
//alert(lastScrollY);
}

本文地址:http://www.jwzzsw.com/archives/77.html

文章作者:思悟
版权所有 © 转载时请以链接形式注明作者和原始出处!

评论 共6条 (RSS 2.0) 发表评论

  1. 脸上毛孔粗怎么办说道:

    文章写的真不错,我要好好向你学习~~~~~~

  2. 代写代发论文说道:

    博客风格不错,欣赏!

  3. 淘宝网减肥药说道:

    您好 请问能交换个链接吗?

  4. 淘宝说道:

    过来看看你!

  5. 美白乳液说道:

    写的很好,记下慢慢学习中,谢谢楼主!!

  6. zendwang说道:

    写的很好,记下慢慢学习中,谢谢楼主!!

发表评论

联系我 Contact Me

回到页首