Last active
August 29, 2015 13:57
-
-
Save SergeyNarozhny/9736394 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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