我要求开发人员为我制作一个magento的便士拍卖脚本 请求的平均速度为450-500毫秒,这在云服务器和专用(低端)上很慢..但我测试了互联网上的其他脚本快速像100毫秒 是prototype.js慢吗?或者代码没有优化? 这里是剧本 请帮帮我,
function auctionTimer(dt,no,id)
{
//alert(no);
var end = new Date(dt);
var now_date= new Date(no);
// alert(now_date);
// alert(end);
var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour * 24;
flag_time = true;
timer = '';
setInterval(function(){showRemaining();},1000);
function showRemaining()
{
var date = no;
var now = new Date(date);
var de= now.getTime();
if ( flag_time ) {
timer = de;
}
var d = new Date(timer);
currentYear = d.getFullYear();
month = d.getMonth()+1;
var currentDate = d.getDate();
currentDate = currentDate < 10 ? '0'+currentDate : currentDate;
var hours = d.getHours();
var minutes = d.getMinutes();
var seconds = d.getSeconds();
// var ampm = hours >= 12 ? 'PM' : 'AM';
// hours = hours % 12;
// hours = hours ? hours : 12; // the hour ’0′ should be ’12′
minutes = minutes < 10 ? '0'+minutes : minutes;
seconds = seconds < 10 ? '0'+seconds : seconds;
var strTime = hours + ':' + minutes+ ':' + seconds; // + ' ' + ampm;
timer = timer + 1000;
var now_time = currentYear+'/' + month+'/' + currentDate + ' ' + strTime ;
// document.getElementById("demo1").innerHTML= currentMonth1+' ' + currentDate+' , ' + currentYear + ' ' + strTime ;
// document.getElementById("demo2").innerHTML= currentDate+':' +(month+1)+':' +currentYear + ' ' + strTime ;
// document.getElementById("demo3").innerHTML= strTime ;
// document.getElementById("demo4").innerHTML= current_day + ' , ' +currentMonth1+' ' + currentDate+' , ' + currentYear + ' ' + strTime ;
// alert(now_time);
var now = new Date(now_time);
// alert(now);
var distance = end - now;
if (distance < 0) {
if (distance>-3)
{
location.reload(true);
return;
};
clearInterval(timer);
document.getElementById('countdown_'+id).innerHTML = 'Sold';
document.getElementById('bid-box').hide();
document.getElementById('auction_watcher').hide();
toggleDisabled(document.getElementById('bid-box'));
toggleDisabled(document.getElementById('auction_watcher'));
document.getElementById('watcher_url').removeAttribute('href');
return;
}
var days = Math.floor(distance / _day);
var hours = Math.floor((distance % _day) / _hour);
var minutes = Math.floor((distance % _hour) / _minute);
var seconds = Math.floor((distance % _minute) / _second);
if (days <10)
{days = '0' + days;}
if (hours <10)
{hours = '0' + hours;}
if (minutes < 10)
{ minutes = '0' + minutes;}
if (seconds < 10)
{seconds = '0' + seconds; }
if(days==00)
{
dytext = '';
}
else if(days==1)
{
dytext = '<span class="countdown-text">'+ days +' Day </span>';
}
else
{
dytext = '<span class="countdown-text">'+ days +' Days </span>';
}
if(hours==00) {
hrtext='';
}
else {
hrtext = '<span class="countdown-text">'+ hours + '</span>'+ ":";
}
if(minutes==00)
{
mintext='';
}else {
mintext = '<span class="countdown-text">'+ minutes +'</span>'+ ":";
}
sectext = '<span class="countdown-text">'+ seconds +'</span>';
document.getElementById('countdown_'+id).innerHTML = dytext + hrtext + mintext + sectext;
flag_time = false;
}
//timer = setInterval(showRemaining, 1000);
}
function callme()
{
document.getElementById('countdown').innerHTML = "Time";
}
function price_condtion(min_price,max_price,id)
{ return;
min_price ="(Between" + '<span class="price">'+ "$" +min_price + '</span>' +" and ";
max_price = '<span class="price">'+ "$"+max_price + '</span>' + ")";
document.getElementById('price_condition_'+id).innerHTML = min_price + max_price;
}
function PlacepennyBid(url,id){
//var bid_type = $$('input:checked[type="radio"][name="bid_type"]').pluck('value');
//var is_valid_bidprice = checkBidPrice();
// if(is_valid_bidprice == false)
// return;
//var bid_price = $('bid_price').value;
var product_id = id;
$('auction_bid_button'+product_id).hide();
$('auction_bid_waitting'+product_id).show();
$('msg_error'+product_id).innerHTML = '';
$('msg_success'+product_id).innerHTML ='';
$('msg_error'+product_id).hide();
$('msg_success'+product_id).hide();
// $('is_bidding').value = '1';
var auctionId = $('auction_id').value;
new Ajax.Request(url,
{
method: 'post',
parameters: {auction_id:auctionId,product_id:product_id},
onSuccess: function(data) {
response = data.responseText.evalJSON(true);
if(response.iserror)
{
$('msg_error'+product_id).update(response.errors);
$('msg_error'+product_id).innerHTML;
//$('msg_error'+product_id).show();
jQuery('#msg_error'+product_id).show().delay(3000).fadeOut();
}else {
$('msg_success'+product_id).update(response.success);
$('msg_success'+product_id).innerHTML;
jQuery('#msg_success'+product_id).show().delay(3000).fadeOut();
//jQuery('#msg_success'+product_id).delay(5000).hide();
$('auction_bid_waitting'+product_id).hide();
$('auction_bid_button'+product_id).show();
$('totalbids').update(response.totalbid);
$('totalbids').innerHTML;
}
//autionBidComplete();
$('auction_bid_waitting'+product_id).hide();
$('auction_bid_button'+product_id).show();
},
onFailure: function(response){
// alert("URL NOT EXIXTS");
$('auction_bid_waitting'+product_id).hide();
$('auction_bid_button'+product_id).show();
}
});
//new Ajax.Updater('results_bid_after_'+auctionId,url,{method: 'get', onComplete:function(){autionBidComplete();} ,onFailure: ""});
}
function PlacepennyautoBid(url,id){
var product_id = id;
$('auction_bid_auto_button_start'+product_id).hide();
$('auction_bid_waitting'+product_id).show();
$('msg_error'+product_id).innerHTML = '';
$('msg_success'+product_id).innerHTML ='';
$('msg_error'+product_id).hide();
$('msg_success'+product_id).hide();
var auctionId = $('auction_id').value;
var auto_price = $('bid_auto_price').value;
var num_bid = $('bid_auto_number').value;
new Ajax.Request(url,
{
method: 'post',
parameters: {auction_id:auctionId,product_id:product_id,
auto_price:auto_price,num_bid:num_bid},
onSuccess: function(data) {
response = data.responseText.evalJSON(true);
if(response.iserror)
{
$('msg_error'+product_id).update(response.errors);
$('msg_error'+product_id).innerHTML;
$('msg_error'+product_id).show();
}else {
$('msg_success'+product_id).update(response.success);
$('msg_success'+product_id).innerHTML;
$('msg_success'+product_id).show();
//$('totalbids').update(response.totalbid);
//$('totalbids').innerHTML;
}
//autionBidComplete();
$('auction_bid_waitting'+product_id).hide();
//$('auction_bid_auto_button_start'+product_id).show();
},
onFailure: function(response){
$('auction_bid_waitting'+product_id).hide();
$('auction_bid_auto_button_start'+product_id).show();
}
});
}
function StoppennyautoBid(url,id){
var product_id = id;
var auctionId = $('auction_id').value;
new Ajax.Request(url,
{
method: 'post',
parameters: {auction_id:auctionId,product_id:product_id},
onSuccess: function(data) {
response = data.responseText.evalJSON(true);
var num_bid = $('bid_auto_number').setValue(15);
},
onFailure: function(response){
}
});
}
function checkBidPrice(){
var bid_price = document.getElementById('bid_price').value;
var bid_type = document.getElementById('auction_standard_bid').checked;
//alert(bid_type);
if(bid_type==true)
{
price = bid_price;
if(price==null)
{
alert("Enter Bid Price");
}
if(price != 0){
var min_next_price = document.getElementById('min_next_price').value;
var max_next_price = document.getElementById('max_next_price').value;
max_next_price = parseFloat(max_next_price);
min_next_price = parseFloat(min_next_price);
if(price < min_next_price)
{
alert("Your Bid Price Must Be Equal to or Greater Then "+min_next_price);
return false;
}
if(max_next_price != 0)
if(price > max_next_price)
{
alert("Your Bid Price Must Be Less Then "+max_next_price);
return false;
}
}
return true;
}
}
function placeBid(url){
var bid_type = $$('input:checked[type="radio"][name="bid_type"]').pluck('value');
var is_valid_bidprice = checkBidPrice();
if(is_valid_bidprice == false)
return;
var bid_price = $('bid_price').value;
var product_id = $('auction_product_id').value;
if(bid_price <= 0){
return;
}
if (url.indexOf('?') == -1)
url += '?bid_price=' + bid_price;
else
url += '&bid_price=' + bid_price;
url += '&product_id=' + product_id;
url += '&bid_type=' + bid_type;
$('auction_bid_button').hide();
$('auction_bid_waitting').show();
$('msg_error').innerHTML = '';
$('msg_success').innerHTML ='';
$('msg_error').hide();
$('msg_success').hide();
$('is_bidding').value = '1';
var auctionId = $('auction_id').value;
new Ajax.Updater('results_bid_after_'+auctionId,url,{method: 'get', onComplete:function(){autionBidComplete();} ,onFailure: ""});
}
function updateAuctionComplete(){
var auctionId;
if ($('result_auction_reset')!= null){
location.reload(true);
}
if($('result_auction_id') != null)
auctionId = $('result_auction_id').innerHTML;
if($('result_price_condition_'+auctionId)!=null)
$('price_condition_'+auctionId).innerHTML = $('result_price_condition_'+auctionId).innerHTML;
if($('notice_error')!=null){
$('msg_error').innerHTML = $('notice_error').value;
if($('notice_error').value != '')
$('msg_error').show();
else
$('msg_error').hide();
} else {
$('msg_error').innerHTML='';
$('msg_error').hide();
}
if($('notice_success')!=null){
$('msg_success').innerHTML = $('notice_success').value;
if($('notice_success').value != '')
$('msg_success').show();
else
$('msg_success').hide();
} else {
$('msg_success').innerHTML = '';
$('msg_success').hide();
}
if($('result_current_bid_id_'+auctionId)!=null)
$('current_bid_id_'+auctionId).value = $('result_current_bid_id_'+auctionId).innerHTML;
if($('result_auction_end_time_'+auctionId) != null)
$('auction_end_time_'+auctionId).value = $('result_auction_end_time_'+auctionId).innerHTML;
if($('result_auction_now_time_'+auctionId) != null)
$('auction_now_time_'+auctionId).value = $('result_auction_now_time_'+auctionId).innerHTML;
if($('result_auction_info_'+auctionId)!=null){
$('auction_info_'+auctionId).innerHTML = $('result_auction_info_'+auctionId).innerHTML;
$('result_auction_info_'+auctionId).innerHTML = '';
}
}
function autionBidComplete(){
$('auction_bid_button').show();
$('auction_bid_waitting').hide();
updateAuctionComplete();
updateauctioninfo();
$('is_bidding').value = '0';
}
function validNumeric(inputtext){
var text = inputtext.value;
if (isNaN(text)) {
alert('Bid in Wrong Format');
}
}
function updateauctioninfo()
{
var url = document.getElementById('updateurl').value;
var value = document.getElementById('auction_id').value;
new Ajax.Request(url,
{
method: 'post',
parameters: {auction_id:value },
onSuccess: function(data) {
response = data.responseText.evalJSON(true);
//var info = document.getElementById('auction_info');
$('auction_info').update(response.updated);
$('auction_info').innerHTML;
// info.innerHTML = update_auction_info;
},
onFailure: function(response){
alert("URL NOT EXIXTS");
}
});
}
function checkupdateauctioninfo(url)
{
if($('current_bidder_id')!=null)
{
var current_bidder_id = document.getElementById('current_bidder_id').value;
var value = document.getElementById('auction_id').value;
new Ajax.Request(url,
{
method: 'post',
parameters: {auction_id:value , bidder_id:current_bidder_id },
onSuccess: function(data) {
responses = data.responseText.evalJSON(true);
for (i = 0; i < responses.length; i++) {
response = responses[i];
document.getElementById('countdown_'+response.id).innerHTML = response.timer;
if(response.winner && !response.currentwinner)
{
$('auction_bid_button'+response.product).hide();
$('buy'+response.product).update(response.remplacementbutton);
$('buy'+response.product).innerHTML;
}
if(response.currentwinner)
{
$('auction_bid_button'+response.product).hide();
$('buy'+response.product).update(response.currentwinnerbuy);
$('buy'+response.product).innerHTML;
}
if(response.currenthigh && !response.currentwinner && !response.winner)
{ //alert(response.product);
$('auction_bid_button'+response.product).hide();
$('buy'+response.product).update(response.currenthightext);
$('buy'+response.product).innerHTML;
$('buy'+response.product).show();
}else if(!response.currenthigh && !response.currentwinner && !response.winner)
{
$('auction_bid_button'+response.product).show();
$('buy'+response.product).hide();
}
if(response.updated )
{
$('current_price').update(response.bid_price);
$('bidder').update(response.name);
$('current_price').innerHTML;
$('bidder').innerHTML;
}
// if(response.autobiddelete)
// {
// $('auction_bid_auto_button_stop'+response.product).hide();
// $('auction_bid_auto_button_start'+response.product).show();
// $('bid_auto_number').setValue(15);
// }
// if(response.autobid && response.currenthigh)
// {
// var num_bid = $('bid_auto_number').setValue(response.numbid);
// }
if(response.totalbid!=$('totalbids').innerHTML)
{
$('totalbids').update(response.totalbid);
$('totalbids').innerHTML;
}
if(response.totalautobid)
{ var num_bid = $('bid_auto_number').setValue(response.totalautobid);
$('auto-bid-notification').setValue(1);
}else {
if($('auto-bid-notification').value==1 && $('auction_bid_auto_button_stop'+response.product).visible()) {
$('auction_bid_auto_button_stop'+response.product).hide();
$('auction_bid_auto_button_start'+response.product).show();
$('bid_auto_number').setValue(15);
$('auto-bid-notification').setValue(0);
}
}
if(response.bidder)
{
$('current_bidder_id').setValue(response.bidder);
$('bidder').style.backgroundColor = "red";
htm='<tr class="row"><td>'+response.name+'</td><td>'+response.bid_price+'</td></tr>';
htmcheck='<td>'+response.name+'</td><td>'+response.bid_price+'</td>';
var count = document.getElementById("hisotry_item_list").getElementsByTagName("tr").length;
olderhtml=$('hisotry_item_list').innerHTML;
var table=document.getElementById("hisotry_item_list");
var updt=true;
var r=0;
var i=1;
while(row=table.rows[r++])
{
if(row.innerHTML==htmcheck){
var updt=false;
}
var i=i+1;
}
if(updt){
$('hisotry_item_list').update(htm+olderhtml);
$('hisotry_item_list').innerHTML;
if(i==9) {
$$('#hisotry_item_list tr').last('tr').remove();
}
}
// if(count==8) {
// $$('#hisotry_item_list tr').last('tr').remove();
// }
// olderhtml=$('hisotry_item_list').innerHTML;
// $('hisotry_item_list').update(htm+olderhtml);
}else {
$('bidder').style.backgroundColor='#fff';
}
//console.clear();
}
},
onFailure: function(response){
//alert("URL NOT EXIXTS");
//console.clear();
}
});
// var request = jQuery.ajax({
// url: url,
// method: "POST",
// data: { auction_id:value , bidder_id:current_bidder_id },
// dataType: "json"
// });
// request.done(function( msg ) {
// });
}
}
function checkupdateauctioninfolist(url)
{
var value = document.getElementById('auction_id').value;
//console.clear();
new Ajax.Request(url,
{
method: 'post',
parameters: {auction_id:value },
onCreate: function() {
//console.clear();
},
onSuccess: function(data) {
allresponses = data.responseText.evalJSON(true);
for (i = 0; i < allresponses.length; i++) {
response = allresponses[i];
document.getElementById('countdown_'+response.id).innerHTML = response.timer;
if(response.winner && !response.currentwinner)
{
$('auction_bid_button'+response.product).hide();
$('buy'+response.product).update(response.remplacementbutton);
$('buy'+response.product).innerHTML;
}
if(response.currentwinner)
{
$('auction_bid_button'+response.product).hide();
$('buy'+response.product).update(response.currentwinnerbuy);
$('buy'+response.product).innerHTML;
}
if(response.currenthigh && !response.currentwinner && !response.winner)
{ //alert(response.product);
$('auction_bid_button'+response.product).hide();
$('buy'+response.product).update(response.currenthightext);
$('buy'+response.product).innerHTML;
$('buy'+response.product).show();
}else if(!response.currenthigh && !response.currentwinner && !response.winner)
{
$('auction_bid_button'+response.product).show();
$('buy'+response.product).hide();
}
if(response.updated)
{
if(response.bid_price!=""){
$('current_price_'+response.id).update(response.bid_price);
$('current_price_'+response.id).innerHTML;
}
$('bidder_'+response.id).update(response.name);
$('bidder_'+response.id).innerHTML;
}
//console.clear();
} },
onFailure: function(response){
console.clear();
}
});
}
function toggleDisabled(el) {
try {
el.disabled = el.disabled ? false : true;
}
catch(E){
}
if (el.childNodes && el.childNodes.length > 0) {
for (var x = 0; x < el.childNodes.length; x++) {
toggleDisabled(el.childNodes[x]);
}
}
}
function auctionCompleteShow(id)
{
document.getElementById('countdown_'+id).innerHTML = 'Sold';
document.getElementById('bid-box').hide();
document.getElementById('auction_watcher').hide();
toggleDisabled(document.getElementById('bid-box'));
toggleDisabled(document.getElementById('auction_watcher'));
document.getElementById('watcher_url').removeAttribute('href');
}
function callthetimers(distance,id)
{
var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour * 24;
if (distance < 0) {
if (distance>-3)
{
location.reload(true);
return;
};
document.getElementById('countdown_'+id).innerHTML = 'Sold';
document.getElementById('bid-box').hide();
return;
}
var days = Math.floor(distance / _day);
var hours = Math.floor((distance % _day) / _hour);
var minutes = Math.floor((distance % _hour) / _minute);
var seconds = Math.floor((distance % _minute) / _second);
if (days <10)
{days = '0' + days;}
if (hours <10)
{hours = '0' + hours;}
if (minutes < 10)
{ minutes = '0' + minutes;}
if (seconds < 10)
{seconds = '0' + seconds; }
if(days==00)
{
dytext = '';
}
else if(days==1)
{
dytext = '<span class="countdown-text">'+ days +' Day </span>';
}
else
{
dytext = '<span class="countdown-text">'+ days +' Days </span>';
}
if(hours==00) {
hrtext='';
}
else {
hrtext = '<span class="countdown-text">'+ hours + '</span>'+ ":";
}
if(minutes==00)
{
mintext='';