Resolve the conflict between ECShop and jQuery

ecshop puts the AJAX events and JSON parsing modules in common/transport.js. It can be said that it also has its own set of tools, which is actually normal.

 
But precisely, the object model is rewritten while encapsulating various methods of JSON, which conflicts with jQuery. As we all know, jQuery extends various JavaScript objects.
 
All of this is actually very easy to understand, and each has its own reasons. It is very natural, but the headache and helplessness become for us users. On the ECShop forum , many friends have also raised this question and put forward various methods. I tried some, but it was not good or even useless, so I had to do it myself.
 
Solutions probably shielded ecshop toJSONString extension method, instead of using other functions.
 
In order to take care of the side dishes, just write down the details.
 
 
One, modify the default js file
 
 
1. First copy a copy of transport.js and rename it to transport.org.js for back-end use
 
 
2. The number of toJSON function lines in transport.js is probably between 497-737 lines.
Code starting with if (! Object.prototype.toJSONString) {.
 
Modify 352 behavior:
 
 legalParams = “JSON=” + $.toJSON(params);
 
Modify 408 behavior:
 
result = $.evalJSON(result);
 
Block out the following code in global.js (lines 10-13):
 
Object.prototype.extend = function(object)
{
  return Object.extend.apply(this, [this, object]);
}
3. Modify line 44 of the index.js file to:
 
var res = $ .evalJSON (result);
 
 
4. Modify the common.js file
Change line 34 to:
 
Ajax.call(‘flow.php?step=add_to_cart’, ‘goods=’ + $.toJSON(goods), addToCartResponse, ‘POST’, ‘JSON’);
 
Change line 850 to:
 
Ajax.call(‘flow.php?step=add_package_to_cart’, ‘package_info=’ + $.toJSON(package_info), addPackageToCartResponse, ‘POST’, ‘JSON’);
 
Change line 1056 to:
 
Ajax.call(‘flow.php?step=add_to_cart’, ‘goods=’ + $.toJSON(goods), addToCartResponse, ‘POST’, ‘JSON’);
 
5. Modify the compare.js file
Change line 49 to:
 
 this.data = $ .evalJSON (cookieValue);
 
Change line 67 to:
 
 var obj = $ .evalJSON (cookieValue);
 
Change line 133 to:
 
 document.setCookie(“compareItems”, $.toJSON(this.data));
 
6. Modify the global.js file
Change the function name on line 16: function $e()
Both lines 114 and 126 are changed to: var element = $e(element);
 
 
Second, modify the background call part
 
 
 
7、
Modify the background header to introduce the transport.js path admin/templates/pageheader.htm, the 9th line is changed to: {insert_scripts files=”../js/transport.org.js,common.js”}
 
admin/templates/menu.htm
Change line 151 to {insert_scripts files="../js/global.js,../js/utils.js,../js/transport.org.js"}
 
 
 
  Third, modify the front-end template part
 
 
8. Modify the themes/default/library/page_header.lbi file and add the following code above {insert_scripts files='transport.js,utils.js'}
{insert_scripts files=’jquery.js,jquery.json.js’}
 
 
9、
library/comment_list.lbi
Line 188:
 
 Ajax.call(‘comment.php’, ‘cmt=’ + $.toJSON(cmt), commentResponse, ‘POST’, ‘JSON’);
 
 
10、compare.dwt
Line 20:
 
var obj = $.evalJSON(document.getCookie(“compareItems”));
 
Line 24:
 
document.setCookie(“compareItems”, $.toJSON(obj));
 
 
11、flow.dwt
Line 138:
 
Ajax.call(‘flow.php?step=add_to_cart’, ‘goods=’ + $.toJSON(goods), collect_to_flow_response, ‘POST’, ‘JSON’);
 
Line 199:
 
 Ajax.call(‘flow.php?step=add_to_cart’, ‘goods=’ + $.toJSON(goods), fittings_to_flow_response, ‘POST’, ‘JSON’);
 
 
12、
 
brand.dwt
brand_list.dwt
category.dwt
exchange_list.dwt
search.dwt
 
Such as:
{* Including script files*}
{insert_scripts files=’jquery.js,jquery.json.js’}
{insert_scripts files=’common.js,global.js,compare.js’}



Recently I got a template of the ecshop mall system. The home page called a slide of jquery, but it could not be displayed. I searched on the Internet and found that it was because the json definition of jquery and ecshop conflicted. This is too difficult, so how about How to resolve the conflict between ECShop and jQuery?

Partially call the jquery plugin

If you just add jQuery to the home page, it is recommended to use this method: introduce the jquery file and the following code before the body at the bottom of the home page template index.dwt.

<script type="text/javascript">
$(function() {
    window.__Object_toJSONString = Object.prototype.toJSONString;
    delete Object.prototype.toJSONString;
});
</script>

Site-wide jQuery compatible modification

1. Modify the file: /js/transport.js

Add code at the bottom of the file:

if (Object.prototype.toJSONString) {
    var oldToJSONString = Object.toJSONString;
    Object.prototype.toJSONString = function() {
        if (arguments.length & amp; gt; 0) {
            return false;
        } else {
            return oldToJSONString.apply(this, arguments);
        }
    }
}

2. Modify the file: /js/compare.js

this.timer = window.setInterval(this.relocation.bind(this), 50);

change into:

this.timer = window.setInterval(this.bind(this.relocation,this), 50);

Find the code:

lastScrollY: 0

Add code to the line above the code:

bind: function(obj1, obj2) {
    return function() {
        obj1.apply(obj2, arguments);
    }
}

3. In the following template files, find the code that embeds the global.js file, and delete the embedding global.js

brand.dwt
brand_list.dwt
category.dwt
exchange_list.dwt
search.dwt

4. Download the latest version of the jquery library file to the template directory

/themes/temlatename/images/js/jquery.1.5.2.js

If there is no corresponding directory in your template, just create a new directory and copy into the jquery file.

5. Modify the file:

/themes/temlatename/library/page_header.lbi

Add the code at the top:

<script src="images/js/jquery.1.5.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
    var $$ = jQuery.noConflict();
</script>

Note that calling the JQUERY object in the future will need two dollar signs $$, don't use a $, because a $ has a compatibility problem with the original function of ECSHOP with the same name.

Guess you like

Origin blog.csdn.net/jjiale/article/details/45893901