Best JavaScript code snippet using best
ui.js
Source:ui.js
1/*global plupload */2/*global qiniu */3function FileProgress(file, targetID) {4 this.fileProgressID = file.id;5 this.file = file;6 this.opacity = 100;7 this.height = 0;8 this.fileProgressWrapper = $('#' + this.fileProgressID);9 if (!this.fileProgressWrapper.length) {10 // <div class="progress">11 // <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: 20%">12 // <span class="sr-only">20% Complete</span>13 // </div>14 // </div>15 this.fileProgressWrapper = $('<tr></tr>');16 var Wrappeer = this.fileProgressWrapper;17 Wrappeer.attr('id', this.fileProgressID).addClass('progressContainer');18 var progressText = $("<td/>");19 progressText.addClass('progressName').text(file.name);20 var fileSize = plupload.formatSize(file.size).toUpperCase();21 var progressSize = $("<td/>");22 progressSize.addClass("progressFileSize").text(fileSize);23 var progressBarTd = $("<td/>");24 var progressBarBox = $("<div/>");25 progressBarBox.addClass('info');26 var progressBarWrapper = $("<div/>");27 progressBarWrapper.addClass("progress progress-striped");28 var progressBar = $("<div/>");29 progressBar.addClass("progress-bar progress-bar-info")30 .attr('role', 'progressbar')31 .attr('aria-valuemax', 100)32 .attr('aria-valuenow', 0)33 .attr('aria-valuein', 0)34 .width('0%');35 var progressBarPercent = $('<span class=sr-only />');36 progressBarPercent.text(fileSize);37 var progressCancel = $('<a href=javascript:; />');38 progressCancel.show().addClass('progressCancel').text('Ã');39 progressBar.append(progressBarPercent);40 progressBarWrapper.append(progressBar);41 progressBarBox.append(progressBarWrapper);42 progressText.append(progressCancel);43 var progressBarStatus = $('<div class="status text-center"/>');44 progressBarBox.append(progressBarStatus);45 progressBarTd.append(progressBarBox);46 Wrappeer.append(progressText);47 Wrappeer.append(progressSize);48 Wrappeer.append(progressBarTd);49 $('#' + targetID).append(Wrappeer);50 } else {51 this.reset();52 }53 this.height = this.fileProgressWrapper.offset().top;54 this.setTimer(null);55}56FileProgress.prototype.setTimer = function(timer) {57 this.fileProgressWrapper.FP_TIMER = timer;58};59FileProgress.prototype.getTimer = function(timer) {60 return this.fileProgressWrapper.FP_TIMER || null;61};62FileProgress.prototype.reset = function() {63 this.fileProgressWrapper.attr('class', "progressContainer");64 this.fileProgressWrapper.find('td .progress .progress-bar-info').attr('aria-valuenow', 0).width('0%').find('span').text('');65 this.appear();66};67FileProgress.prototype.setChunkProgess = function(chunk_size) {68 var chunk_amount = Math.ceil(this.file.size / chunk_size);69 if (chunk_amount === 1) {70 return false;71 }72 var viewProgess = $('<button class="btn btn-default">æ¥çååä¸ä¼ è¿åº¦</button>');73 var progressBarChunkTr = $('<tr class="chunk-status-tr"><td colspan=3></td></tr>');74 var progressBarChunk = $('<div/>');75 for (var i = 1; i <= chunk_amount; i++) {76 var col = $('<div class="col-md-2"/>');77 var progressBarWrapper = $('<div class="progress progress-striped"></div');78 var progressBar = $("<div/>");79 progressBar.addClass("progress-bar progress-bar-info text-left")80 .attr('role', 'progressbar')81 .attr('aria-valuemax', 100)82 .attr('aria-valuenow', 0)83 .attr('aria-valuein', 0)84 .width('0%')85 .attr('id', this.file.id + '_' + i)86 .text('');87 var progressBarStatus = $('<span/>');88 progressBarStatus.addClass('chunk-status').text();89 progressBarWrapper.append(progressBar);90 progressBarWrapper.append(progressBarStatus);91 col.append(progressBarWrapper);92 progressBarChunk.append(col);93 }94 if(!this.fileProgressWrapper.find('td:eq(2) .btn-default').length){95 this.fileProgressWrapper.find('td>div').append(viewProgess);96 }97 progressBarChunkTr.hide().find('td').append(progressBarChunk);98 progressBarChunkTr.insertAfter(this.fileProgressWrapper);99};100FileProgress.prototype.setProgress = function(percentage, speed, chunk_size) {101 this.fileProgressWrapper.attr('class', "progressContainer green");102 var file = this.file;103 var uploaded = file.loaded;104 var size = plupload.formatSize(uploaded).toUpperCase();105 var formatSpeed = plupload.formatSize(speed).toUpperCase();106 var progressbar = this.fileProgressWrapper.find('td .progress').find('.progress-bar-info');107 if (this.fileProgressWrapper.find('.status').text() === 'åæ¶ä¸ä¼ '){108 return;109 }110 this.fileProgressWrapper.find('.status').text("å·²ä¸ä¼ : " + size + " ä¸ä¼ éåº¦ï¼ " + formatSpeed + "/s");111 percentage = parseInt(percentage, 10);112 if (file.status !== plupload.DONE && percentage === 100) {113 percentage = 99;114 }115 progressbar.attr('aria-valuenow', percentage).css('width', percentage + '%');116 if (chunk_size) {117 var chunk_amount = Math.ceil(file.size / chunk_size);118 if (chunk_amount === 1) {119 return false;120 }121 var current_uploading_chunk = Math.ceil(uploaded / chunk_size);122 var pre_chunk, text;123 for (var index = 0; index < current_uploading_chunk; index++) {124 pre_chunk = $('#' + file.id + "_" + index);125 pre_chunk.width('100%').removeClass().addClass('alert alert-success').attr('aria-valuenow', 100);126 text = "å" + index + "ä¸ä¼ è¿åº¦100%";127 pre_chunk.next().html(text);128 }129 var currentProgessBar = $('#' + file.id + "_" + current_uploading_chunk);130 var current_chunk_percent;131 if (current_uploading_chunk < chunk_amount) {132 if (uploaded % chunk_size) {133 current_chunk_percent = ((uploaded % chunk_size) / chunk_size * 100).toFixed(2);134 } else {135 current_chunk_percent = 100;136 currentProgessBar.removeClass().addClass('alert alert-success');137 }138 } else {139 var last_chunk_size = file.size - chunk_size * (chunk_amount - 1);140 var left_file_size = file.size - uploaded;141 if (left_file_size % last_chunk_size) {142 current_chunk_percent = ((uploaded % chunk_size) / last_chunk_size * 100).toFixed(2);143 } else {144 current_chunk_percent = 100;145 currentProgessBar.removeClass().addClass('alert alert-success');146 }147 }148 currentProgessBar.width(current_chunk_percent + '%');149 currentProgessBar.attr('aria-valuenow', current_chunk_percent);150 text = "å" + current_uploading_chunk + "ä¸ä¼ è¿åº¦" + current_chunk_percent + '%';151 currentProgessBar.next().html(text);152 }153 this.appear();154};155FileProgress.prototype.setComplete = function(up, info) {156 var td = this.fileProgressWrapper.find('td:eq(2)'),157 tdProgress = td.find('.progress');158 var res;159 var url;160 if(uploadConfig.saveType == "oss"){161 url = "oss";162 str = "<div class='success_text'>ä¸ä¼ æå</div>";163 }else{164 res = $.parseJSON(info);165 if (res.url) {166 url = res.url;167 str = "<div class='success_text'>ä¸ä¼ æå</div>";168 } else {169 var domain = up.getOption('domain');170 url = domain + encodeURI(res.key);171 var link = domain + res.key;172 str = "<div class='success_text'>ä¸ä¼ æå</div>";173 }174 }175 tdProgress.html(str).removeClass().next().next('.status').hide();176 this.fileProgressWrapper.find('td:eq(0) .progressCancel').hide();177 td.find('.status').hide();178 angular.element(document.querySelector('angular-filemanager > div')).scope().fileNavigator.refresh();179};180FileProgress.prototype.setError = function() {181 this.fileProgressWrapper.find('td:eq(2)').attr('class', 'text-warning');182 this.fileProgressWrapper.find('td:eq(2) .progress').css('width', 0).hide();183 this.fileProgressWrapper.find('button').hide();184 this.fileProgressWrapper.next('.chunk-status-tr').hide();185};186FileProgress.prototype.setCancelled = function(manual) {187 var progressContainer = 'progressContainer';188 if (!manual) {189 progressContainer += ' red';190 }191 this.fileProgressWrapper.attr('class', progressContainer);192 this.fileProgressWrapper.find('td .progress').remove();193 this.fileProgressWrapper.find('td:eq(2) .btn-default').hide();194 this.fileProgressWrapper.find('td:eq(0) .progressCancel').hide();195};196FileProgress.prototype.setStatus = function(status, isUploading) {197 if (!isUploading) {198 this.fileProgressWrapper.find('.status').text(status).attr('class', 'status text-left');199 }200};201// ç»å®åæ¶ä¸ä¼ äºä»¶202FileProgress.prototype.bindUploadCancel = function(up) {203 var self = this;204 if (up) {205 self.fileProgressWrapper.find('td:eq(0) .progressCancel').on('click', function(){206 self.setCancelled(false);207 self.setStatus("åæ¶ä¸ä¼ ");208 self.fileProgressWrapper.find('.status').css('left', '0');209 up.removeFile(self.file);210 });211 }212};213FileProgress.prototype.appear = function() {214 if (this.getTimer() !== null) {215 clearTimeout(this.getTimer());216 this.setTimer(null);217 }218 if (this.fileProgressWrapper[0].filters) {219 try {220 this.fileProgressWrapper[0].filters.item("DXImageTransform.Microsoft.Alpha").opacity = 100;221 } catch (e) {222 // If it is not set initially, the browser will throw an error. This will set it if it is not set yet.223 this.fileProgressWrapper.css('filter', "progid:DXImageTransform.Microsoft.Alpha(opacity=100)");224 }225 } else {226 this.fileProgressWrapper.css('opacity', 1);227 }228 this.fileProgressWrapper.css('height', '');229 this.height = this.fileProgressWrapper.offset().top;230 this.opacity = 100;231 this.fileProgressWrapper.show();...
handlers.js
Source:handlers.js
1/**2 * 3 * @version $Id: handlers.js 1 22:28 2010å¹´7æ20æ¥Z tianya $4 * @package DedeCMS.Administrator5 * @copyright Copyright (c) 2007 - 2010, DesDev, Inc.6 * @license http://help.dedecms.com/usersguide/license.html7 * @link http://www.dedecms.com8 */9//---äºä»¶å¥å¹¶------------------------------10function fileQueueError(file, errorCode, message){11 try {12 var imageName = "error.gif";13 var errorName = "";14 if (errorCode === SWFUpload.errorCode_QUEUE_LIMIT_EXCEEDED) {15 errorName = "ä½ æ·»å çæ件è¶
è¿äºéå¶ï¼";16 }17 if (errorName !== "") {18 alert(errorName);19 return;20 }21 switch (errorCode) {22 case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:23 imageName = "zerobyte.gif";24 break;25 case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:26 imageName = "toobig.gif";27 break;28 case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:29 case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:30 default:31 alert(message);32 break;33 }34 addImage("images/" + imageName, 0);35 } catch (ex) {36 this.debug(ex);37 }38}39function fileDialogComplete(numFilesSelected, numFilesQueued) {40 try {41 if (numFilesQueued > 0) {42 this.startUpload();43 }44 } catch (ex) {45 this.debug(ex);46 }47}48function uploadProgress(file, bytesLoaded) {49 try {50 var percent = Math.ceil((bytesLoaded / file.size) * 100);51 var progress = new FileProgress(file, this.customSettings.upload_target);52 progress.setProgress(percent);53 if (percent === 100) {54 progress.setStatus("å建缩ç¥å¾...");55 progress.toggleCancel(false, this);56 } else {57 progress.setStatus("ä¸ä¼ ä¸...");58 progress.toggleCancel(true, this);59 }60 } catch (ex) {61 this.debug(ex);62 }63}64function uploadSuccess(file, serverData) {65 try {66 var progress = new FileProgress(file, this.customSettings.upload_target);67 if (serverData.substring(0, 7) === "FILEID:") {68 addImage("swfupload.php?dopost=thumbnail&id=" + serverData.substring(7), serverData.substring(7));69 progress.setStatus("è·å缩ç¥å¾...");70 progress.toggleCancel(false);71 } else {72 addImage("images/error.gif", 0);73 progress.setStatus("æé误ï¼");74 progress.toggleCancel(false);75 alert(serverData);76 }77 } catch (ex) {78 this.debug(ex);79 }80}81function uploadComplete(file) {82 try {83 /* I want the next upload to continue automatically so I'll call startUpload here */84 if (this.getStats().files_queued > 0) {85 this.startUpload();86 } else {87 var progress = new FileProgress(file, this.customSettings.upload_target);88 progress.setComplete();89 progress.setStatus("ææå¾çä¸ä¼ å®æ...");90 progress.toggleCancel(false);91 }92 } catch (ex) {93 this.debug(ex);94 }95}96function uploadError(file, errorCode, message) {97 var imageName = "error.gif";98 var progress;99 try {100 switch (errorCode) {101 case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:102 try {103 progress = new FileProgress(file, this.customSettings.upload_target);104 progress.setCancelled();105 progress.setStatus("Cancelled");106 progress.toggleCancel(false);107 }108 catch (ex1) {109 this.debug(ex1);110 }111 break;112 case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:113 try {114 progress = new FileProgress(file, this.customSettings.upload_target);115 progress.setCancelled();116 progress.setStatus("Stopped");117 progress.toggleCancel(true);118 }119 catch (ex2) {120 this.debug(ex2);121 }122 case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:123 imageName = "uploadlimit.gif";124 break;125 default:126 alert(message);127 break;128 }129 addImage("images/" + imageName, 0);130 } catch (ex3) {131 this.debug(ex3);132 }133}134var albImg = 0;135function addImage(src, pid){136 var newImgDiv = document.createElement("div");137 var delstr = '';138 var iptwidth = 190;139 albImg++;140 if(pid != 0) {141 albImg = 'ok' + pid;142 delstr = '<a href="javascript:delAlbPic('+pid+')">[å é¤]</a>';143 } else {144 albImg = 'err' + albImg;145 }146 newImgDiv.className = 'albCt';147 newImgDiv.id = 'albCt'+albImg;148 document.getElementById("thumbnails").appendChild(newImgDiv);149 newImgDiv.innerHTML = '<img src="'+src+'" width="120" />'+delstr;150 if(typeof arctype != 'undefined' && arctype == 'article' )151 { 152 iptwidth = 100;153 if(pid != 0) {154 newImgDiv.innerHTML = '<img src="'+src+'" width="120" onClick="addtoEdit('+pid+')"/>'+delstr;155 }156 }157 newImgDiv.innerHTML += '<div style="margin-top:10px">注éï¼<input type="text" name="picinfo'+albImg+'" value="" style="width:'+iptwidth+'px;" /></div>';158}159/* ******************************************160 * FileProgress Object161 * Control object for displaying file info162 * ****************************************** */163function FileProgress(file, targetID) {164 this.fileProgressID = "divFileProgress";165 this.fileProgressWrapper = document.getElementById(this.fileProgressID);166 if (!this.fileProgressWrapper) {167 this.fileProgressWrapper = document.createElement("div");168 this.fileProgressWrapper.className = "progressWrapper";169 this.fileProgressWrapper.id = this.fileProgressID;170 this.fileProgressElement = document.createElement("div");171 this.fileProgressElement.className = "progressContainer";172 var progressCancel = document.createElement("a");173 progressCancel.className = "progressCancel";174 progressCancel.href = "#";175 progressCancel.style.visibility = "hidden";176 progressCancel.appendChild(document.createTextNode(" "));177 var progressText = document.createElement("div");178 progressText.className = "progressName";179 progressText.appendChild(document.createTextNode(file.name));180 var progressBar = document.createElement("div");181 progressBar.className = "progressBarInProgress";182 var progressStatus = document.createElement("div");183 progressStatus.className = "progressBarStatus";184 progressStatus.innerHTML = " ";185 this.fileProgressElement.appendChild(progressCancel);186 this.fileProgressElement.appendChild(progressText);187 this.fileProgressElement.appendChild(progressStatus);188 this.fileProgressElement.appendChild(progressBar);189 this.fileProgressWrapper.appendChild(this.fileProgressElement);190 document.getElementById(targetID).appendChild(this.fileProgressWrapper);191 } else {192 this.fileProgressElement = this.fileProgressWrapper.firstChild;193 this.fileProgressElement.childNodes[1].firstChild.nodeValue = file.name;194 }195 this.height = this.fileProgressWrapper.offsetHeight;196}197FileProgress.prototype.setProgress = function (percentage) {198 this.fileProgressElement.className = "progressContainer blue";199 this.fileProgressElement.childNodes[3].className = "progressBarInProgress";200 this.fileProgressElement.childNodes[3].style.width = percentage + "%";201};202FileProgress.prototype.setComplete = function () {203 this.fileProgressElement.className = "progressContainer green";204 this.fileProgressElement.childNodes[3].className = "progressBarComplete";205 this.fileProgressElement.childNodes[3].style.width = "";206};207FileProgress.prototype.setError = function () {208 this.fileProgressElement.className = "progressContainer red";209 this.fileProgressElement.childNodes[3].className = "progressBarError";210 this.fileProgressElement.childNodes[3].style.width = "";211};212FileProgress.prototype.setCancelled = function () {213 this.fileProgressElement.className = "progressContainer";214 this.fileProgressElement.childNodes[3].className = "progressBarError";215 this.fileProgressElement.childNodes[3].style.width = "";216};217FileProgress.prototype.setStatus = function (status) {218 this.fileProgressElement.childNodes[2].innerHTML = status;219};220FileProgress.prototype.toggleCancel = function (show, swfuploadInstance) {221 this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";222 if (swfuploadInstance) {223 var fileID = this.fileProgressID;224 this.fileProgressElement.childNodes[0].onclick = function () {225 swfuploadInstance.cancelUpload(fileID);226 return false;227 };228 }...
ProgressBar.js
Source:ProgressBar.js
1import React, { Component } from 'react';2import { Card, CardBody, CardHeader, Progress } from 'reactstrap';3class ProgressBar extends Component {4 render() {5 return (6 <div className="animated fadeIn">7 <Card>8 <CardHeader>9 <i className="fa fa-align-justify"></i><strong>Progress</strong>10 <div className="card-header-actions">11 <a href="https://reactstrap.github.io/components/progress/" rel="noreferrer noopener" target="_blank" className="card-header-action">12 <small className="text-muted">docs</small>13 </a>14 </div>15 </CardHeader>16 <CardBody>17 <div className="text-center">0%</div>18 <Progress />19 <div className="text-center">25%</div>20 <Progress value="25" />21 <div className="text-center">50%</div>22 <Progress value={50} />23 <div className="text-center">75%</div>24 <Progress value={75} />25 <div className="text-center">100%</div>26 <Progress value="100" />27 <div className="text-center">Multiple bars</div>28 <Progress multi>29 <Progress bar value="15" />30 <Progress bar color="success" value="30" />31 <Progress bar color="info" value="25" />32 <Progress bar color="warning" value="20" />33 <Progress bar color="danger" value="5" />34 </Progress>35 </CardBody>36 </Card>37 <Card>38 <CardHeader>39 <i className="fa fa-align-justify"></i><strong>Progress</strong>40 <small> color variants</small>41 </CardHeader>42 <CardBody>43 <Progress value={2 * 5} className="mb-3" />44 <Progress color="success" value="25" className="mb-3" />45 <Progress color="info" value={50} className="mb-3" />46 <Progress color="warning" value={75} className="mb-3" />47 <Progress color="danger" value="100" className="mb-3" />48 </CardBody>49 </Card>50 <Card>51 <CardHeader>52 <i className="fa fa-align-justify"></i><strong>Progress</strong>53 <small> labels</small>54 </CardHeader>55 <CardBody>56 <Progress value="25" className="mb-3">25%</Progress>57 <Progress value={50} className="mb-3">1/2</Progress>58 <Progress value={75} className="mb-3">You're almost there!</Progress>59 <Progress color="success" value="100" className="mb-3">You did it!</Progress>60 <Progress multi className="mb-3">61 <Progress bar value="15">Meh</Progress>62 <Progress bar color="success" value="30">Wow!</Progress>63 <Progress bar color="info" value="25">Cool</Progress>64 <Progress bar color="warning" value="20">20%</Progress>65 <Progress bar color="danger" value="5">!!</Progress>66 </Progress>67 </CardBody>68 </Card>69 <Card>70 <CardHeader>71 <i className="fa fa-align-justify"></i><strong>Progress</strong>72 <small> striped</small>73 </CardHeader>74 <CardBody>75 <Progress striped value={2 * 5} className="mb-3" />76 <Progress striped color="success" value="25" className="mb-3" />77 <Progress striped color="info" value={50} className="mb-3" />78 <Progress striped color="warning" value={75} className="mb-3" />79 <Progress striped color="danger" value="100" className="mb-3" />80 <Progress multi className="mb-3">81 <Progress striped bar value="10" />82 <Progress striped bar color="success" value="30" />83 <Progress striped bar color="warning" value="20" />84 <Progress striped bar color="danger" value="20" />85 </Progress>86 </CardBody>87 </Card>88 <Card>89 <CardHeader>90 <i className="fa fa-align-justify"></i><strong>Progress</strong>91 <small> animated</small>92 </CardHeader>93 <CardBody>94 <Progress animated value={2 * 5} className="mb-3" />95 <Progress animated color="success" value="25" className="mb-3" />96 <Progress animated color="info" value={50} className="mb-3" />97 <Progress animated color="warning" value={75} className="mb-3" />98 <Progress animated color="danger" value="100" className="mb-3" />99 <Progress multi>100 <Progress animated bar value="10" />101 <Progress animated bar color="success" value="30" />102 <Progress animated bar color="warning" value="20" />103 <Progress animated bar color="danger" value="20" />104 </Progress>105 </CardBody>106 </Card>107 <Card>108 <CardHeader>109 <i className="fa fa-align-justify"></i><strong>Progress</strong>110 <small> multiple bars / stacked</small>111 </CardHeader>112 <CardBody>113 <div className="text-center">Plain</div>114 <Progress multi>115 <Progress bar value="15" />116 <Progress bar color="success" value="20" />117 <Progress bar color="info" value="25" />118 <Progress bar color="warning" value="20" />119 <Progress bar color="danger" value="15" />120 </Progress>121 <div className="text-center">With Labels</div>122 <Progress multi>123 <Progress bar value="15">Meh</Progress>124 <Progress bar color="success" value="35">Wow!</Progress>125 <Progress bar color="warning" value="25">25%</Progress>126 <Progress bar color="danger" value="25">LOOK OUT!!</Progress>127 </Progress>128 <div className="text-center">Stripes and Animations</div>129 <Progress multi>130 <Progress bar striped value="15">Stripes</Progress>131 <Progress bar animated color="success" value="30">Animated Stripes</Progress>132 <Progress bar color="info" value="25">Plain</Progress>133 </Progress>134 </CardBody>135 </Card>136 <Card>137 <CardHeader>138 <i className="fa fa-align-justify"></i><strong>Progress</strong>139 <small> max value</small>140 </CardHeader>141 <CardBody>142 <div className="text-center">1 of 5</div>143 <Progress value="1" max="5" />144 <div className="text-center">50 of 135</div>145 <Progress value={50} max="135" />146 <div className="text-center">75 of 111</div>147 <Progress value={75} max={111} />148 <div className="text-center">463 of 500</div>149 <Progress value="463" max={500} />150 <div className="text-center">Various (40) of 55</div>151 <Progress multi>152 <Progress bar value="5" max={55}>5</Progress>153 <Progress bar color="success" value="15" max={55}>15</Progress>154 <Progress bar color="warning" value="10" max={55}>10</Progress>155 <Progress bar color="danger" value="10" max={55}>10</Progress>156 </Progress>157 </CardBody>158 </Card>159 </div>160 );161 }162}...
fileprogress.js
Source:fileprogress.js
1/*2 A simple class for displaying file information and progress3 Note: This is a demonstration only and not part of SWFUpload.4 Note: Some have had problems adapting this class in IE7. It may not be suitable for your application.5*/6function FileProgress(file, targetID) {7 this.fileProgressID = file.id;8 this.opacity = 100;9 this.height = 0;10 this.fileProgressWrapper = document.getElementById(this.fileProgressID);11 if (!this.fileProgressWrapper) {12 this.fileProgressWrapper = document.createElement("div");13 this.fileProgressWrapper.className = "progressWrapper";14 this.fileProgressWrapper.id = this.fileProgressID;15 this.fileProgressElement = document.createElement("div");16 this.fileProgressElement.className = "progressContainer";17 var progressCancel = document.createElement("a");18 progressCancel.className = "progressCancel";19 progressCancel.href = "#";20 progressCancel.style.visibility = "hidden";21 progressCancel.appendChild(document.createTextNode(" "));22 var progressText = document.createElement("div");23 progressText.className = "progressName";24 progressText.appendChild(document.createTextNode(file.name));25 var progressBar = document.createElement("div");26 progressBar.className = "progressBarInProgress";27 var progressStatus = document.createElement("div");28 progressStatus.className = "progressBarStatus";29 progressStatus.innerHTML = " ";30 this.fileProgressElement.appendChild(progressCancel);31 this.fileProgressElement.appendChild(progressText);32 this.fileProgressElement.appendChild(progressStatus);33 this.fileProgressElement.appendChild(progressBar);34 this.fileProgressWrapper.appendChild(this.fileProgressElement);35 document.getElementById(targetID).appendChild(this.fileProgressWrapper);36 } else {37 this.fileProgressElement = this.fileProgressWrapper.firstChild;38 this.reset();39 }40 this.height = this.fileProgressWrapper.offsetHeight;41 this.setTimer(null);42}43FileProgress.prototype.setTimer = function (timer) {44 this.fileProgressElement["FP_TIMER"] = timer;45};46FileProgress.prototype.getTimer = function (timer) {47 return this.fileProgressElement["FP_TIMER"] || null;48};49FileProgress.prototype.reset = function () {50 this.fileProgressElement.className = "progressContainer";51 this.fileProgressElement.childNodes[2].innerHTML = " ";52 this.fileProgressElement.childNodes[2].className = "progressBarStatus";53 this.fileProgressElement.childNodes[3].className = "progressBarInProgress";54 this.fileProgressElement.childNodes[3].style.width = "0%";55 this.appear();56};57FileProgress.prototype.setProgress = function (percentage) {58 this.fileProgressElement.className = "progressContainer green";59 this.fileProgressElement.childNodes[3].className = "progressBarInProgress";60 this.fileProgressElement.childNodes[3].style.width = percentage + "%";61 this.appear();62};63FileProgress.prototype.setComplete = function () {64 this.fileProgressElement.className = "progressContainer blue";65 this.fileProgressElement.childNodes[3].className = "progressBarComplete";66 this.fileProgressElement.childNodes[3].style.width = "";67};68FileProgress.prototype.setError = function () {69 this.fileProgressElement.className = "progressContainer red";70 this.fileProgressElement.childNodes[3].className = "progressBarError";71 this.fileProgressElement.childNodes[3].style.width = "";72 var oSelf = this;73 this.setTimer(setTimeout(function () {74 oSelf.disappear();75 }, 5000));76};77FileProgress.prototype.setCancelled = function () {78 this.fileProgressElement.className = "progressContainer";79 this.fileProgressElement.childNodes[3].className = "progressBarError";80 this.fileProgressElement.childNodes[3].style.width = "";81 var oSelf = this;82 this.setTimer(setTimeout(function () {83 oSelf.disappear();84 }, 2000));85};86FileProgress.prototype.setStatus = function (status) {87 this.fileProgressElement.childNodes[2].innerHTML = status;88};89FileProgress.prototype.toggleCancel = function (show, swfUploadInstance) {90 this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";91 if (swfUploadInstance) {92 var fileID = this.fileProgressID;93 this.fileProgressElement.childNodes[0].onclick = function () {94 swfUploadInstance.cancelUpload(fileID);95 return false;96 };97 }98};99FileProgress.prototype.appear = function () {100 if (this.getTimer() !== null) {101 clearTimeout(this.getTimer());102 this.setTimer(null);103 }104 if (this.fileProgressWrapper.filters) {105 try {106 this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 100;107 } catch (e) {108 this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";109 }110 } else {111 this.fileProgressWrapper.style.opacity = 1;112 }113 this.fileProgressWrapper.style.height = "";114 this.height = this.fileProgressWrapper.offsetHeight;115 this.opacity = 100;116 this.fileProgressWrapper.style.display = "";117};118FileProgress.prototype.disappear = function () {119 var reduceOpacityBy = 15;120 var reduceHeightBy = 4;121 var rate = 30; // 15 fps122 if (this.opacity > 0) {123 this.opacity -= reduceOpacityBy;124 if (this.opacity < 0) {125 this.opacity = 0;126 }127 if (this.fileProgressWrapper.filters) {128 try {129 this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = this.opacity;130 } catch (e) {131 this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + this.opacity + ")";132 }133 } else {134 this.fileProgressWrapper.style.opacity = this.opacity / 100;135 }136 }137 if (this.height > 0) {138 this.height -= reduceHeightBy;139 if (this.height < 0) {140 this.height = 0;141 }142 this.fileProgressWrapper.style.height = this.height + "px";143 }144 if (this.height > 0 || this.opacity > 0) {145 var oSelf = this;146 this.setTimer(setTimeout(function () {147 oSelf.disappear();148 }, rate));149 } else {150 this.fileProgressWrapper.style.display = "none";151 this.setTimer(null);152 }...
progress.spec.js
Source:progress.spec.js
1describe('progress events', function () {2 beforeEach(function () {3 jasmine.Ajax.install();4 });5 afterEach(function () {6 jasmine.Ajax.uninstall();7 });8 it('should add a download progress handler', function (done) {9 var progressSpy = jasmine.createSpy('progress');10 axios('/foo', { onDownloadProgress: progressSpy } );11 getAjaxRequest().then(function (request) {12 request.respondWith({13 status: 200,14 responseText: '{"foo": "bar"}'15 });16 expect(progressSpy).toHaveBeenCalled();17 done();18 });19 });20 it('should add a upload progress handler', function (done) {21 var progressSpy = jasmine.createSpy('progress');22 axios('/foo', { onUploadProgress: progressSpy } );23 getAjaxRequest().then(function (request) {24 // Jasmine AJAX doesn't trigger upload events. Waiting for upstream fix25 // expect(progressSpy).toHaveBeenCalled();26 done();27 });28 });29 it('should add both upload and download progress handlers', function (done) {30 var downloadProgressSpy = jasmine.createSpy('downloadProgress');31 var uploadProgressSpy = jasmine.createSpy('uploadProgress');32 axios('/foo', { onDownloadProgress: downloadProgressSpy, onUploadProgress: uploadProgressSpy });33 getAjaxRequest().then(function (request) {34 // expect(uploadProgressSpy).toHaveBeenCalled();35 expect(downloadProgressSpy).not.toHaveBeenCalled();36 request.respondWith({37 status: 200,38 responseText: '{"foo": "bar"}'39 });40 expect(downloadProgressSpy).toHaveBeenCalled();41 done();42 });43 });44 it('should add a download progress handler from instance config', function (done) {45 var progressSpy = jasmine.createSpy('progress');46 var instance = axios.create({47 onDownloadProgress: progressSpy,48 });49 instance.get('/foo');50 getAjaxRequest().then(function (request) {51 request.respondWith({52 status: 200,53 responseText: '{"foo": "bar"}'54 });55 expect(progressSpy).toHaveBeenCalled();56 done();57 });58 });59 it('should add a upload progress handler from instance config', function (done) {60 var progressSpy = jasmine.createSpy('progress');61 var instance = axios.create({62 onUploadProgress: progressSpy,63 });64 instance.get('/foo');65 getAjaxRequest().then(function (request) {66 // expect(progressSpy).toHaveBeenCalled();67 done();68 });69 });70 it('should add upload and download progress handlers from instance config', function (done) {71 var downloadProgressSpy = jasmine.createSpy('downloadProgress');72 var uploadProgressSpy = jasmine.createSpy('uploadProgress');73 var instance = axios.create({74 onDownloadProgress: downloadProgressSpy,75 onUploadProgress: uploadProgressSpy,76 });77 instance.get('/foo');78 getAjaxRequest().then(function (request) {79 // expect(uploadProgressSpy).toHaveBeenCalled();80 expect(downloadProgressSpy).not.toHaveBeenCalled();81 request.respondWith({82 status: 200,83 responseText: '{"foo": "bar"}'84 });85 expect(downloadProgressSpy).toHaveBeenCalled();86 done();87 });88 });...
Progressable.js
Source:Progressable.js
1/**2 * A Traversable mixin.3 * @private4 */5Ext.define('Ext.mixin.Progressable', {6 extend: 'Ext.mixin.Mixin',7 isProgressable: true,8 mixinConfig: {9 id: 'progressable'10 },11 config: {12 /**13 * @cfg {Number} minProgressInput14 * Minimum input value for this indicator15 */16 minProgressInput: 0,17 /**18 * @cfg {Number} maxProgressInput19 * Maximum input value for this indicator20 */21 maxProgressInput: 1,22 /**23 * @cfg {Number} minProgressOutput24 * Minimum output value for this indicator25 */26 minProgressOutput: 0,27 /**28 * @cfg {Number} maxProgressOutput29 * Maximum output value for this indicator30 */31 maxProgressOutput: 100,32 /**33 * @cfg {Boolean} dynamic34 *35 * When false this indicator will only receive progressStart and progressEnd commands, no progressUpdate commands will be sent.36 *37 */38 dynamic: true,39 /**40 * @cfg {String} state41 *42 * Current state of the progressIndicator. Should be used for switching progress states like download to upload.43 */44 state: null45 },46 // @private47 _progressActive: false,48 _progress: 0,49 _rawProgress: 0,50 onStartProgress: Ext.emptyFn,51 onUpdateProgress: Ext.emptyFn,52 onEndProgress: Ext.emptyFn,53 startProgress: function() {54 if (!this._progressActive) {55 this._progressActive = true;56 this.onStartProgress();57 this.updateProgress(this.getMinProgressInput());58 }59 },60 updateProgress: function(value, state) {61 if(state && state != this.getState()) this.setState(state);62 if(value > this.getMaxProgressInput()) value = this.getMaxProgressInput();63 if(value < this.getMinProgressInput()) value = this.getMinProgressInput();64 var mappedValue = this.mapValues(value, this.getMinProgressInput(), this.getMaxProgressInput(), this.getMinProgressOutput(), this.getMaxProgressOutput());65 this._progress = mappedValue;66 this._rawProgress = value;67 if(this.getDynamic()) {68 this.onUpdateProgress(mappedValue);69 }70 },71 endProgress: function() {72 if (this._progressActive) {73 this._progressActive = false;74 this.updateProgress(this.getMaxProgressInput());75 this.onEndProgress()76 }77 },78 mapValues: function(value, inputMin, inputMax, outputMin, outputMax) {79 return (value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin;80 },81 setProgress: function(value) {82 this.updateProgress(value);83 },84 getProgress: function() {85 return this._progress86 },87 getRawProgress: function() {88 return this._rawProgress;89 }...
u-easings.js
Source:u-easings.js
1u.easings = new function() {2 this["ease-in"] = function(progress) {3 return Math.pow((progress), 3);4 }5 this["linear"] = function(progress) {6 return progress;7 }8 this["ease-out"] = function(progress) {9 return 1 - Math.pow(1 - ((progress)), 3);10 }11 this["linear"] = function(progress) {12 return (progress);13 }14 this["ease-in-out-veryslow"] = function(progress) {15 if(progress > 0.5) {16 return 4*Math.pow((progress-1),3)+1;17 }18 return 4*Math.pow(progress,3); 19 }20 this["ease-in-out"] = function(progress) {21 if(progress > 0.5) {22 return 1 - Math.pow(1 - ((progress)), 2);23 }24 return Math.pow((progress), 2);25 }26 this["ease-out-slow"] = function(progress) {27 return 1 - Math.pow(1 - ((progress)), 2);28 }29 30 this["ease-in-slow"] = function(progress) {31 return Math.pow((progress), 2);32 }33 this["ease-in-veryslow"] = function(progress) {34 return Math.pow((progress), 1.5);35 }36 this["ease-in-fast"] = function(progress) {37 return Math.pow((progress), 4);38 }39 40 41 this["easeOutQuad"] = function (progress) {42 d = 1;43 b = 0;44 c = progress;45 t = progress;46 t /= d;47 return -c * t*(t-2) + b;48 };49 this["easeOutCubic"] = function (progress) {50 d = 1;51 b = 0;52 c = progress;53 t = progress;54 t /= d;55 t--;56 return c*(t*t*t + 1) + b;57 };58 this["easeOutQuint"] = function (progress) {59 d = 1;60 b = 0;61 c = progress;62 t = progress;63 t /= d;64 t--;65 return c*(t*t*t*t*t + 1) + b;66 };67 68 this["easeInOutSine"] = function (progress) {69 d = 1;70 b = 0;71 c = progress;72 t = progress;73 return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;74 };75 76 this["easeInOutElastic"] = function (progress) {77 d = 1;78 b = 0;79 c = progress;80 t = progress;81 var s=1.70158;var p=0;var a=c;82 if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);83 if (a < Math.abs(c)) { a=c; var s=p/4; }84 else var s = p/(2*Math.PI) * Math.asin (c/a);85 if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;86 return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;87 }88 89 this["easeOutBounce"] = function (progress) {90 d = 1;91 b = 0;92 c = progress;93 t = progress;94 if ((t/=d) < (1/2.75)) {95 return c*(7.5625*t*t) + b;96 } else if (t < (2/2.75)) {97 return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;98 } else if (t < (2.5/2.75)) {99 return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;100 } else {101 return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;102 }103 }104 this["easeInBack"] = function (progress) {105 var s = 1.70158;106 d = 1;107 b = 0;108 c = progress;109 t = progress;110 111 // if (s == undefined) s = 1.70158;112 return c*(t/=d)*t*((s+1)*t - s) + b;113 }...
Progress.stories.js
Source:Progress.stories.js
1import React from 'react'2import {storiesOf} from '@storybook/react'3import {Progress} from './'4storiesOf('Progress/', module).add('Progress empty', () => (5 <Progress width={'600px'} FOOBAR></Progress>6))7storiesOf('Progress/', module).add('Progress 0', () => (8 <Progress width={'600px'} FOOBAR>9 <Progress.Bar value={0} max={10} />10 </Progress>11))12storiesOf('Progress/', module).add('Progress full', () => (13 <Progress width={'600px'} FOOBAR>14 <Progress.Bar value={10} max={10} />15 </Progress>16))17storiesOf('Progress/', module).add('Progress Full success', () => (18 <Progress width={'600px'} FOOBAR>19 <Progress.Bar success value={10} max={10} />20 </Progress>21))22storiesOf('Progress/', module).add('Progress Full danger', () => (23 <Progress width={'600px'} FOOBAR>24 <Progress.Bar danger value={10} max={10} />25 </Progress>26))27storiesOf('Progress/', module).add('Progress mixed', () => (28 <Progress width={'600px'} FOOBAR>29 <Progress.Bar danger value={2.5} max={10} />30 <Progress.Bar success value={2.5} max={10} />31 <Progress.Bar value={2.5} max={10} />32 </Progress>...
Using AI Code Generation
1var BestFit = require('./BestFit.js');2var bestFit = new BestFit();3var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];4var progress = bestFit.progress(data, 10);5console.log(progress);6{ a: 0.9999999999999999,7 progress: 100 }8var BestFit = require('./BestFit.js');9var bestFit = new BestFit();10var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];11var progress = bestFit.progress(data, 100);12console.log(progress);13{ a: 0.9999999999999999,14 progress: 100 }15var BestFit = require('./BestFit.js');16var bestFit = new BestFit();17var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];18var progress = bestFit.progress(data, 1000);19console.log(progress);20{ a: 0.9999999999999999,21 progress: 100 }22var BestFit = require('./BestFit.js');23var bestFit = new BestFit();24var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];25var progress = bestFit.progress(data, 10000);26console.log(progress);27{ a: 0.9999999999999999,
Using AI Code Generation
1var BestTime = require('./bestTime');2var bestTime = new BestTime();3bestTime.start();4setTimeout(function() {5 bestTime.progress(50);6}, 1000);7setTimeout(function() {8 bestTime.progress(100);9}, 2000);10var BestTime = require('./bestTime');11var bestTime = new BestTime();12bestTime.start();13setTimeout(function() {14 bestTime.progress(50);15}, 1000);16setTimeout(function() {17 bestTime.progress(100);18}, 2000);19var BestTime = require('./bestTime');20var bestTime = new BestTime();21bestTime.start();22setTimeout(function() {23 bestTime.progress(50);24}, 1000);25setTimeout(function() {26 bestTime.progress(100);27}, 2000);28var BestTime = require('./bestTime');29var bestTime = new BestTime();30bestTime.start();31setTimeout(function() {32 bestTime.progress(50);33}, 1000);34setTimeout(function() {35 bestTime.progress(100);36}, 2000);37var BestTime = require('./bestTime');38var bestTime = new BestTime();39bestTime.start();40setTimeout(function() {41 bestTime.progress(50);42}, 1000);43setTimeout(function() {44 bestTime.progress(100);45}, 2000);46var BestTime = require('./bestTime');47var bestTime = new BestTime();48bestTime.start();49setTimeout(function() {50 bestTime.progress(50);51}, 1000);52setTimeout(function() {53 bestTime.progress(100);54}, 2000);55var BestTime = require('./bestTime');56var bestTime = new BestTime();57bestTime.start();58setTimeout(function() {59 bestTime.progress(50);60}, 1000);61setTimeout(function() {62 bestTime.progress(100);63}, 2000);64var BestTime = require('./best
Using AI Code Generation
1var BestTime = require('./besttime');2var bt = new BestTime();3bt.progress(1000);4bt.progress(2000);5bt.progress(3000);6bt.progress(4000);7bt.progress(5000);8bt.progress(6000);9bt.progress(7000);
Using AI Code Generation
1var bt = require('./BestTimeToBuyAndSellStock.js');2var myArray = [100, 180, 260, 310, 40, 535, 695];3console.log(bt.bestTimeToBuyAndSellStock(myArray));4console.log(bt.progress(myArray));5var bestTimeToBuyAndSellStock = function (stockPrices) {6 var maxProfit = 0;7 var minPrice = stockPrices[0];8 for (var i = 0; i < stockPrices.length; i++) {9 if (stockPrices[i] < minPrice) {10 minPrice = stockPrices[i];11 } else if (stockPrices[i] - minPrice > maxProfit) {12 maxProfit = stockPrices[i] - minPrice;13 }14 }15 return maxProfit;16};17var progress = function (stockPrices) {18 var maxProfit = 0;19 var minPrice = stockPrices[0];20 for (var i = 0; i < stockPrices.length; i++) {21 if (stockPrices[i] < minPrice) {22 minPrice = stockPrices[i];23 } else if (stockPrices[i] - minPrice > maxProfit) {24 maxProfit = stockPrices[i] - minPrice;25 }26 }27 return maxProfit;28};29module.exports.bestTimeToBuyAndSellStock = bestTimeToBuyAndSellStock;30module.exports.progress = progress;31console.log(bt.bestTimeToBuyAndSellStock(myArray));32at Object.<anonymous> (C:\Users\user\Desktop
Using AI Code Generation
1var bestFit = require('./bestFit.js');2var x = [1,2,3,4,5];3var y = [1,2,3,4,5];4var newBestFit = new bestFit(x,y);5console.log(newBestFit.progress());6var BestFit = function(x,y){7 this.x = x;8 this.y = y;9 this.progress = function(){10 return this.x;11 }12}13module.exports = BestFit;14I have a file called test4.js which is in the test directory. I have a file called bestFit.js which is in the bestFit directory. I am trying to use the progress method of the BestFit class in test4.js. I have tried using require('./bestFit.js') and require('./bestFit/bestFit.js') but neither of those work. What is the correct way to access the BestFit class in test4.js?15I have a file called test4.js which is in the test directory. I have a file called bestFit.js which is in the bestFit directory. I am trying to use the progress method of the BestFit class in test4.js. I have tried using require('./bestFit.js') and require('./bestFit/bestFit.js') but neither of those work. What is the correct way to access the BestFit class in test4.js?16I have a file called test4.js which is in the test directory. I have a file called bestFit.js which is in the bestFit directory. I am trying to use the progress method of the BestFit class in test4.js. I have tried using require('./bestFit.js') and require('./bestFit/bestFit.js') but neither of those work. What is the correct way to access the BestFit class in test4.js?
Using AI Code Generation
1var BestTime = require('./bestTime.js');2var bt = new BestTime();3bt.progress(1, 2);4bt.progress(2, 5);5bt.progress(3, 5);6bt.progress(4, 5);7bt.progress(5, 5);8bt.progress(6, 5);9bt.progress(7, 5);10bt.progress(8, 5);11bt.progress(9, 5);12bt.progress(10, 5);13bt.progress(11, 5);14bt.progress(12, 5);15bt.progress(13, 5);16bt.progress(14, 5);17bt.progress(15, 5);18bt.progress(16, 5);19bt.progress(17, 5);20bt.progress(18, 5);21bt.progress(19, 5);22bt.progress(20, 5);23bt.progress(21, 5);24bt.progress(22, 5);25bt.progress(23, 5);26bt.progress(24, 5);27bt.progress(25, 5);28bt.progress(26, 5);29bt.progress(27, 5);30bt.progress(28, 5);31bt.progress(29, 5);32bt.progress(30, 5);33bt.progress(31, 5);34bt.progress(32, 5);35bt.progress(33, 5);36bt.progress(34, 5);37bt.progress(35, 5);38bt.progress(36, 5);39bt.progress(37, 5);40bt.progress(38, 5);41bt.progress(39, 5);42bt.progress(40, 5);43bt.progress(41, 5);44bt.progress(42, 5);45bt.progress(43, 5);46bt.progress(44, 5);47bt.progress(45, 5);48bt.progress(46, 5);49bt.progress(47, 5);50bt.progress(48, 5);51bt.progress(49, 5);52bt.progress(50, 5);53bt.progress(51, 5);54bt.progress(52, 5);55bt.progress(53, 5);56bt.progress(54, 5);57bt.progress(55, 5);58bt.progress(56, 5);59bt.progress(57, 5);60bt.progress(58, 5);61bt.progress(59,
Using AI Code Generation
1var BestTime = require('./besttime.js');2var bt = new BestTime();3bt.start();4setTimeout(function() {5 console.log('Elapsed time: ' + bt.elapsed());6}, 5000);7function BestTime() {8 this.startTime = null;9 this.elapsedTime = null;10}11BestTime.prototype.start = function() {12 this.startTime = new Date();13};14BestTime.prototype.elapsed = function() {15 this.elapsedTime = new Date() - this.startTime;16 return this.elapsedTime;17};18module.exports = BestTime;19exports.myDateTime = function () {20 return Date();21};
Using AI Code Generation
1var BestTime = require('bestTime');2var bestTime = new BestTime();3var prices = [10, 8, 6, 4, 2];4console.log(bestTime.progress(prices));5var BestTime = require('bestTime');6var bestTime = new BestTime();7var prices = [2, 4, 6, 8, 10];8console.log(bestTime.progress(prices));9var BestTime = require('bestTime');10var bestTime = new BestTime();11var prices = [2, 10, 4, 6, 8];12console.log(bestTime.progress(prices));13var BestTime = require('bestTime');14var bestTime = new BestTime();15var prices = [2, 10, 4, 6, 8, 4, 6, 8, 10];16console.log(bestTime.progress(prices));17var BestTime = require('bestTime');18var bestTime = new BestTime();19var prices = [2, 10, 4, 6, 8, 4, 6, 8, 10, 2, 4, 6, 8, 10];20console.log(bestTime.progress(prices));
Using AI Code Generation
1var b = new BestFit();2b.progress = function (p) {3 console.log(p);4};5b.addRect(100, 100, 1);6b.addRect(50, 50, 2);7b.addRect(20, 20, 3);8b.addRect(30, 30, 4);9b.addRect(40, 40, 5);10b.fit();11console.log(b.getRects());12console.log(b.getArea());13console.log(b.getWidth());14console.log(b.getHeight());15console.log(b.getCount());16console.log(b.getRotations());
Using AI Code Generation
1var BestTime = {2 set: function(time, mode) {3 this.time = time;4 this.mode = mode;5 },6 get: function() {7 return this.time;8 },9 getMode: function() {10 return this.mode;11 },12 progress: function() {13 var time = this.time;14 var mode = this.mode;15 var timeStr = "";16 var hours = Math.floor(time / 3600);17 var minutes = Math.floor((time % 3600) / 60);18 var seconds = time % 60;19 if (hours) {20 timeStr += hours + ":";21 }22 if (minutes < 10 && hours) {23 timeStr += "0";24 }25 timeStr += minutes + ":";26 if (seconds < 10) {27 timeStr += "0";28 }29 timeStr += seconds;30 if (mode === "countdown") {31 timeStr += " left";32 } else {33 timeStr += " elapsed";34 }35 return timeStr;36 }37};38var Timer = {39 start: function(time, mode) {40 this.startTime = new Date().getTime();41 this.time = time;42 this.mode = mode;43 this.running = true;44 },45 stop: function() {46 this.running = false;47 },48 reset: function() {49 this.startTime = 0;50 this.time = 0;51 this.mode = "";52 this.running = false;53 },54 getTime: function() {55 return this.time;56 },57 getMode: function() {58 return this.mode;59 },60 isRunning: function() {61 return this.running;62 },63 progress: function() {64 if (this.running) {65 var time = 0;66 var now = new Date().getTime();67 if (this.mode === "countdown") {68 time = this.time - Math.floor((now - this.startTime) / 1000);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!