解决ecshop和ueditor,jquery的冲突…

本文介绍了解决ecShop系统中transport.js与jQuery之间的toJSONString方法冲突的方法,提供了两种解决方案,并详细说明了如何修改相关文件以确保系统兼容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

他们的问题主要在于ecshop的transport.js的toJSONString问题上,有两种方法可以解决
1,在调用ueditor的时候,删除Object.prototype.toJSONString 即delete(Object.prototype.toJSONString);
当使用transport.js里的文件后再重新加载transport或者删除之前赋值,使用后重新赋值回来,当然这里存在加载顺序关系
2,修改掉Obj.prototype.toJSONString,把使用prototype的obj换成function ,因为使用prototype更改了js的基础,所以在使用ueditor的时候,使js的基础发生错误,下面为一个转换成json的代码,从jquery复制出来的:

  1. function changeToJsonString(object) {
  2.     var type = typeof object;
  3.     if ('object' == type) {
  4.         if (Array == object.constructor) type = 'array';
  5.         else if (RegExp == object.constructor) type = 'regexp';
  6.         else type = 'object';
  7.     }
  8.     switch (type) {
  9.         case 'undefined':
  10.         case 'unknown':
  11.             return;
  12.             break;
  13.         case 'function':
  14.         case 'boolean':
  15.         case 'regexp':
  16.             return object.toString();
  17.             break;
  18.         case 'number':
  19.             return isFinite(object) ? object.toString() : 'null';
  20.             break;
  21.         case 'string':
  22.             return '"' + object.replace(/(\\|\")/g, "\\$1").replace(/\n|\r|\t/g, function() {
  23.                 var a = arguments[0];
  24.             return (a == '\n') ? '\\n': (a == '\r') ? '\\r': (a == '\t') ? '\\t': ""
  25.     }) + '"';
  26.     break;
  27.         case 'object':
  28.     if (object === null) return 'null';
  29.     var results = [];
  30.     for (var property in object) {
  31.         var value = changeToJsonString(object[property]);
  32.         if (value !== undefined) results.push(changeToJsonString(property) + ':' + value);
  33.     }
  34.     return '{' + results.join(',') + '}';
  35.     break;
  36.         case 'array':
  37.     var results = [];
  38.     for (var i = 0; i < object.length; i++) {
  39.         var value = changeToJsonString(object[i]);
  40.         if (value !== undefined) results.push(value);
  41.     }
  42.     return '[' + results.join(',') + ']';
  43.     break;
  44.     }
  45. }

接着把String.prototype.parseJSON也换成function,直接拿出来即可:

  1. function parseJson(value){
  2.             // Parsing happens in three stages. In the first stage, we run the text against
  3.             // a regular expression which looks for non-JSON characters. We are especially
  4.             // concerned with '()' and 'new' because they can cause invocation, and '='
  5.             // because it can cause mutation. But just to be safe, we will reject all
  6.             // unexpected characters.
  7.             try {
  8.                 if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.
  9.                         test(value)) {
  10.                     // In the second stage we use the eval function to compile the text into a
  11.                     // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
  12.                     // in JavaScript: it can begin a block or an object literal. We wrap the text
  13.                     // in parens to eliminate the ambiguity.
  14.                     var j = eval_r('(' + value + ')');
  15.                     // In the optional third stage, we recursively walk the new structure, passing
  16.                     // each name/value pair to a filter function for possible transformation.
  17.                     if (typeof filter === 'function') {
  18.                         function walk(k, v) {
  19.                             if (v && typeof v === 'object') {
  20.                                 for (var i in v) {
  21.                                     if (v.hasOwnProperty(i)) {
  22.                                         v[i] = walk(i, v[i]);
  23.                                     }
  24.                                 }
  25.                             }
  26.                             return filter(k, v);
  27.                         }
  28.                         j = walk('', j);
  29.                     }
  30.                     return j;
  31.                 }
  32.             } catch (e) {
  33.             // Fall through if the regexp test fails.
  34.             }
  35.             throw new SyntaxError("parseJSON");
  36. }
接着将object.toJSONString 换成changeToJsonString(object),object.parseJSON换成parseJson(object)即可
解决ecshop和jquery冲突,测试

增加一个时间函数

  1. function dateToJsonString() {
  2.         // Ultimately, this method will be equivalent to the date.toISOString method.
  3.         function f(n) {
  4.             // Format integers to have at least two digits.
  5.             return n < 10 ? '0' + n : n;
  6.         }
  7.         return '"' + this.getFullYear() + '-' +
  8.                 f(this.getMonth() + 1) + '-' +
  9.                 f(this.getDate()) + 'T' +
  10.                 f(this.getHours()) + ':' +
  11.                 f(this.getMinutes()) + ':' +
  12.                 f(this.getSeconds()) + '"';
  13.     };


解决ecshopjquery冲突问题

1,jquery.js文件中第一步将已存在的$赋值出来然后释放掉,再在最后重新赋值给$

 

2,修改transport.jstoJSONString方法

 

修改文件在同压缩目录下, 修改了toJSONStringparseJSON和一个时间函数

 

 

upload作为根目录

 

文件名

文件路径

修改量

具体修改操作

备注

前台文件

common.js

Js/

3

goods.toJSONString() => changeToJsonString(goods)

package_info.toJSONString() => changeToJsonString(package_info)

 

compare.js

Js/

1

this.data.toJSONString()  => dateToJsonString(); 

这里是记录当前时间,没有参数

compare.dwt

Themes/default

1

obj.toJSONString() => changeToJsonString(obj)

 

compare.dwt

Themes/default_old

1

obj.toJSONString() => changeToJsonString(obj)

 

flow.dwt

Themes/default_old

2

goods.toJSONString() => changeToJsonString(goods)

 

flow.dwt

Themes/default

2

goods.toJSONString() => changeToJsonString(goods)

 

comments_list.lbi

Themes/default

1

cmt.toJSONString() => changeToJsonString(cmt)

 

comments_list.lbi

Themes/default_old

1

cmt.toJSONString() => changeToJsonString(cmt)

 

brand.dwt

Themes/default_old

 

obj.toJSONString() =>changeToJsonString(obj)

 

后台文件

menu.htm

Admin/templates

1

this.SourceObject.toJSONString() => changeToJsonString(this.SourceObject)

 

topic_edit.htm

Admin/templates

1

myTopic.toJSONString() => changeToJsonString(myTopic)

 

template_setup.htm

Admin/templates

 

 

这里有几处存在toJSONString 暂时未知函数用处

wholesale_info.htm

Admin/templates

 

 

这里有几处存在toJSONString 暂时未知函数用处

selectzone.js

Admin/js

2

selOpt.toJSONString() => changeToJsonString(selOpt)

arr.toJSONString() => changeToJsonString(arr)

 

 

增加1.4.2jquery前后增加两项

$___ecshop_ = $ == null || $ == ‘undefined’ ? $ : null;

$ = $___ecshop_ ;

使用jquery时将$换成jQuery

,修改transport.js 测试结果

1,全功能使用uEditor不会出现 增加JS代码的问题

2,用户评论区可以正常判别验证码对错,可正常ajax提交评论内容

3,产品规格正常修改,ajax正常传输

4,后台商品分类,商品品牌,标签管理的移除,虚拟商品添加修改及编辑操作正常,缺货登记移除处理正常

5,调用ajax正常,scriptjson方式接受正常.

6,使用jquery插件zoominfo使用正常

 

 

 

2012/3/16


ecshop更换百度ueditor插件相关信息如下: ecshop版本:ecshop2.7.3 编码格式:UTF-8 ueditor版本:1.4.3 1、打开admin/includes/lib_main.php文件 (1)找到:(大约在306-323行左右) /** * 生成编辑器 * @param string input_name 输入框名称 * @param string input_value 输入框值 */ function create_html_editor($input_name, $input_value = '') { global $smarty; $editor = new FCKeditor($input_name); $editor->BasePath = '../includes/fckeditor/'; $editor->ToolbarSet = 'Normal'; $editor->Width = '100%'; $editor->Height = '320'; $editor->Value = $input_value; $FCKeditor = $editor->CreateHtml(); $smarty->assign('FCKeditor', $FCKeditor); } 将这段代码修改为: /** * 生成编辑器 * @param string input_name 输入框名称 * @param string input_value 输入框值 */ function create_html_editor($input_name, $input_value = '') { global $smarty; $editor = new FCKeditor($input_name); $editor->BasePath = '../includes/fckeditor/'; $editor->ToolbarSet = 'Normal'; $editor->Width = '100%'; $editor->Height = '320'; $editor->Value = $input_value; $FCKeditor = $editor->CreateHtml(); $smarty->assign('FCKeditor', $FCKeditor); } 将这段代码修改为: /** * 生成编辑器 * @param string input_name 输入框名称 * @param string input_value 输入框值 */ function create_html_editor($input_name, $input_value = '') { global $smarty; $kindeditor=" &lt;script id='editor' name='$input_name' type='text/plain' style='width:100%;height:500px;'&gt;$input_value&lt;/script&gt; &lt;script type='text/javascript' charset='utf-8' src='../includes/ueditor/ueditor.config.js'&gt;&lt;/script&gt; &lt;script type='text/javascript' charset='utf-8' src='../includes/ueditor/ueditor.all.min.js'&gt; &lt;/script&gt; &lt;script type='text/javascript' charset='utf-8' src='../includes/ueditor/lang/zh-cn/zh-cn.js'&gt;&lt;/script&gt; &lt;script&gt; var ue = UE.getEditor('editor'); UE.getEditor('editor').focus(); &lt;/script&gt; "; $smarty->assign('FCKeditor', $k
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值