(函数($){/***progressbar对象。使用给定id初始化。必须插入到*之后通过progressBar.element访问DOM。**方法是执行HTTP请求以获取*进度条状态。“GET”或“POST”。**例如pb=新进度条('myProgressBar');*some_element.appendChild(pb.element);*/Drupal.progressBar=函数(id,updateCallback,method,errorCallbak){var pb=这个;this.id=id;this.method=方法||“GET”;this.updateCallback=更新回调;this.errorCallback=错误回拨;//WAI-ARIA设置ARIA-live=“polite”将在用户之后宣布更改//已完成当前活动,并且没有中断屏幕阅读器。this.element=$('
').attr('id',id);this.element.html('
' +'
' +'
 
');};/***设置进度条的百分比和状态消息。*/Drupal.progressBar.prototype.setProgress=函数(百分比,消息){if(百分比>=0&&百分比<=100){$('div.filled',this.element).css('width',percentage+'%');$('div.percentage',this.element).html(百分比+“%”);}$('div.message',this.element).html(消息);if(this.updateCallback){this.updateCallback(百分比,消息,this);}};/***开始通过Ajax监控进度。*/Drupal.progressBar.prototype.startMonitoring=函数(uri,延迟){this.delay=延迟;this.uri=uri;this.sendPing();};/***停止通过Ajax监视进度。*/Drupal.progressBar.prototype.stopMonitoring=函数(){clearTimeout(this.timer);//这允许从回调中停止监视。this.uri=空;};/***从服务器请求进度数据。*/Drupal.progressBar.prototype.sendPing=函数(){if(this.timer){clearTimeout(this.timer);}if(this.uri){var pb=这个;//在执行post请求时,需要非空数据。否则a//可能会导致HTTP 411或HTTP 406(带有Apache mod_security)错误。$.ajax(美元)({类型:this.method,url:this.uri,数据:“”,dataType:“json”,成功:功能(进度){//显示错误。if(进程状态==0){pb.displayError(进度.data);回报;}//更新显示。pb.setProgress(进度百分比,进度消息);//安排下一个计时器。pb.timer=设置超时(函数(){pb.sendPing();},pb.delay);},错误:函数(xmlhttp){pb.displayError(Drupal.ajaxError,xmlhttp,pb.uri);}});}};/***在页面上显示错误。*/Drupal.progressBar.prototype.displayError=函数(字符串){var错误=$('
').html(字符串);$(this.element).before(error).hide();if(this.errorCallback){this.errorCallback(this);}};})(jQuery);