Skip to content

Instantly share code, notes, and snippets.

@SergeyNarozhny
Last active August 29, 2015 13:57
Show Gist options
  • Save SergeyNarozhny/9736394 to your computer and use it in GitHub Desktop.
Save SergeyNarozhny/9736394 to your computer and use it in GitHub Desktop.
function NewProto() {};
NewProto.prototype = {
pull: function(data) {
return $.ajax("ajax.php", {
data: data,
type: "POST",
context: this.el,
});
},
fill: function(params) {
if (arguments.length === 2 && typeof(params[1]) == "object") {
this.el = params[0];
this.data = params[1] || {};
}
}
};
var req = new NewProto();
$(".add2basketq").keyup(function(){
var val = $(this).val();
var el = $(this);
//var bid, bpid, start, limit, price ...;
req.fill([el, {val:val, pid:pid, bpid:bpid, ... }]);
if (Number(val) == 0) {
req.pull('&subaction=delete&id='+bpid+'&bpid='+bpid).
done(function(result) {
var output = JSON.parse(result);
var sum1 = output.total;
sum1 = sum1.toString().replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
if (req.query != undefined) {
//...
}
});
}
else if (parseInt(val) <= parseInt(limit)) {
req.pull('&action=ADD2BASKET&quantity='+val+'&id='+pid).done(function() { ... });
}
else {
req.pull('&action=ADD2BASKET&quantity='+limit+'&id='+pid).done(function() { ... });
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment