The current version of CS-Cart/Multi-Vendor uses jQuery. We provide all additional functionality as plugins.
Use the short notation ($) to summon all jQuery methods:
$.browser.msie;
$('#test').ourMethod();
Important
Don’t use the jQuery
variable to summon methods.
When you create plugins, use the jQuery coding style. Functions follow the standard PHP guidelines.
$(window).myFunc();
myVar = 123;
Format inline JavaScript as follows:
<script type="text/javascript">
...
</script>
Important
Try to keep inline JavaScript to a minimum. If you have to write logic in a template, then there is a problem with logic. Use inline JavaScript only to pass data from PHP to JavaScript.
Connect external scripts with the {script}
Smarty function
{script src="js/core.js"}
If you must load an external script with JavaScript, use ONLY the $.getScript
function—it is adjusted to track the loaded scripts and to work with namespaces and third-party libraries.
We store third-party JavaScript libraries in the js/lib directory. If we want to extend functionality, we write a wrapper like ceDialog
.
Use full notation with the reference to document
for the ready
event, that is summoned when the document is loaded.
Right:
$(document).ready(function() {
// do something
});
or
$(function() {
// do something
});
Wrong:
$(function()), $(window).ready()
Callbacks are used in AJAX requests and in many other places. If you want to pass a callback to the method of a particular object, use an anonymous function:
$.ceAjax('request', url, {callback: function() {
obj.method();
}});
Starting with CS-Cart 4.12.1, native async and defer scripts are supported.
The scripts are connected as follows:
{script src="js/tygh/bottom_panel.js" defer=true}
{script src="js/tygh/bottom_panel.js" async=true}
Questions & Feedback
Have any questions that weren't answered here? Need help with solving a problem in your online store? Want to report a bug in our software? Find out how to contact us.