How to use resetSrc method in wpt

Best JavaScript code snippet using wpt

PicturesUploader.js

Source:PicturesUploader.js Github

copy

Full Screen

1/*!2 * tanguage framework source code3 *4 * class form.PicturesUploader5 *6 * Date: 2017-04-067 */8;9tang.init().block([10 '$_/util/',11 '$_/dom/Elements',12 '$_/data/Uploader'13], function(pandora, root, imports, undefined) {14 var block = this,15 _ = pandora,16 $ = _.dom.$,17 declare = pandora.declareClass,18 doc = root.document,19 console = root.console,20 query = _.dom.sizzle || _.dom.selector;21 var values = {},22 builders = {23 image: function() {24 // console.log(this);25 this.changer = _.dom.create('input', this.Element, {26 className: 'pic-changer',27 type: 'file',28 value: ''29 });30 _.dom.create('i', this.Element, {31 className: 'pic-mask'32 });33 this.displayer = _.dom.create('img', this.Element, {34 className: 'pic-displayer'35 });36 this.displayer.src = this.playsrc;37 this.resetter = _.dom.create('i', this.Element, {38 className: 'pic-resetter',39 innerHTML: '重置或清除'40 });41 },42 video: function() {43 // console.log(this);44 this.changer = _.dom.create('input', this.Element, {45 className: 'pic-changer',46 type: 'file',47 value: ''48 });49 _.dom.create('i', this.Element, {50 className: 'pic-mask'51 });52 this.displayer = _.dom.create('video', this.Element, {53 className: 'pic-displayer',54 autoplay: 'autoplay',55 loop: 'loop',56 muted: 'muted'57 });58 _.dom.create('img', this.displayer, {59 className: 'pic-displayer'60 }).src = this.subtype === 'video16x9' ? _.dirname(block.url) + 'static/video16x9.jpg' : _.dirname(block.url) + 'static/video.jpg';61 this.displayer.src = this.playsrc;62 this.resetter = _.dom.create('i', this.Element, {63 className: 'pic-resetter',64 innerHTML: '重置或清除'65 });66 }67 },68 callbacks = {69 checkDone: function(files) {70 // console.log(this, files);71 _.data.Uploader.transfer.call(this, files[0], {72 url: this.caller.posturl,73 handlers: {74 before: callbacks.beforeUpload,75 after: callbacks.afterUpload,76 done: callbacks.uploadDone,77 fail: callbacks.uploadFail,78 progress: callbacks.onUploadProgress79 }80 });81 },82 checkFail: function(file, errtype) {83 // console.log(file, errtype);84 // return;85 switch (errtype) {86 case 0:87 alert('Format Error!');88 break;89 case 1:90 alert('Filesize OVER!');91 break;92 case 2:93 alert('No Legal File Selected!');94 break;95 };96 },97 uploadDone: function(response) {98 var caller = this.caller,99 src = caller.srcFinder(response.responseText);100 if (src) {101 if (caller.inputter) {102 caller.inputter.value = src;103 }104 caller.displayer.src = src;105 values[caller.uid] = src;106 } else {107 // console.log(response);108 alert('上传失败');109 }110 $(caller.bluemask).css({111 height: '0',112 top: '100%'113 });114 },115 uploadFail: function(response) {116 console.log(this);117 alert('服务器错误');118 // console.log(response);119 },120 beforeUpload: function(response) {121 // console.log(response);122 },123 afterUpload: function(response) {124 // console.log(response);125 },126 onUploadProgress: function(response) {127 var p, caller = this.caller;128 if (response.lengthComputable) {129 p = Math.round(response.loaded * 100 / response.total);130 $(caller.bluemask).css({131 height: p + '%',132 top: (100 - p) + '%'133 });134 };135 // console.log(p + '%', (100 - p) + '%');136 }137 },138 fileInputOnChange = function(caller) {139 if (caller.posturl) {140 if (caller.type === 'video') {141 var uploader = new _.data.Uploader(this.files, ['video/mp4', 'video/ogg', 'video/webm'], ['mp4', 'ogg', 'webv'], 1024 * 1024 * 20);142 } else {143 var uploader = new _.data.Uploader(this.files, ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png'], ['jpg', 'png', 'gif'], 1024 * 1024 * 20);144 }145 uploader.caller = caller;146 uploader.isOnlyFilter = false;147 // console.log('foo');148 uploader.checkType(callbacks.checkDone, callbacks.checkFail);149 } else {150 _.error('must have a post url.');151 }152 },153 reset = function() {154 if (this.inputter) {155 this.inputter.value = this.resetsrc;156 }157 this.displayer.src = this.resetsrc;158 values[this.uid] = this.resetsrc;159 };160 declare('form.PicturesUploader', {161 type: 'image',162 subtype: 'image',163 Element: null,164 inputter: null,165 changer: null,166 displayer: null,167 bluemask: null,168 resetter: null,169 resetsrc: null,170 playsrc: null,171 posturl: '',172 _init: function(elem, options) {173 this.Element = _.util.isStr(elem) ? _.dom.selector.byId(elem) : elem;174 // console.log(this.Element, elem);175 if (_.util.isEl(this.Element)) {176 _.dom.addClass(this.Element, 'actived');177 options = options || {};178 this.uid = new _.Identifier();179 this.type = options.type === 'video' ? 'video' : 'image';180 this.subtype = options.subtype || options.type;181 var inputs = $('.pic-src', this.Element);182 if (inputs.length) {183 this.inputter = inputs[0];184 values[this.uid] = this.playsrc = this.resetsrc = inputs.val() || '';185 inputs.hide();186 } else {187 values[this.uid] = '';188 this.playsrc = options.src || $(this.Element).data('defaultSrc') || null;189 this.resetsrc = options.resetsrc || this.playsrc || '';190 }191 if (!this.playsrc) {192 switch (this.subtype) {193 case 'photo2x3':194 case 'figure3x4':195 case 'banner':196 case 'banner100':197 var filename = this.subtype + '.jpg';198 break;199 case 'avatar':200 case 'avatar1x1':201 var filename = 'avatar.jpg';202 break;203 case 'figure':204 case 'figure4x3':205 var filename = 'figure.jpg';206 break;207 case 'video':208 case 'video4x3':209 var filename = 'video4x3.mp4';210 break;211 case 'video16x9':212 var filename = 'video16x9.mp4';213 break;214 default:215 var filename = 'photo.jpg';216 }217 this.playsrc = _.dirname(block.url) + 'static/' + filename;218 }219 var changers = $('.pic-changer', this.Element);220 if (changers.length) {221 this.changer = changers[0];222 if (this.type === 'image') {223 this.displayer = $('img.pic-displayer', this.Element).attr('src', this.playsrc).get(0);224 } else {225 }226 this.resetter = $('.pic-resetter', this.Element).get(0);227 } else {228 builders[this.type].call(this);229 }230 this.bluemask = $('.pic-bluemask', this.Element).get(0) || _.dom.create('i', this.Element, {231 className: 'pic-bluemask'232 });233 if (options.url) {234 this.posturl = options.url;235 }236 if (options.finder) {237 this.srcFinder = options.finder;238 }239 this.listenEvents();240 } else {241 // console.log(this.Element, elem);242 _.error('elem must be an Element Object.');243 }244 },245 srcFinder: function(responseText) {246 var response = _.data.decodeJSON(responseText) || {247 data: 500248 };249 if (response.data && response.data.successed && response.data.successed.myfile && response.data.successed.myfile.length) {250 return response.data.successed.myfile[0].url251 } else {252 return null;253 }254 },255 inForm: function(formElement) {256 return (formElement === this.Element) || _.dom.contain(formElement, this.Element);257 },258 resetValue: function() {259 if (this.resetter) {260 reset.call(this);261 }262 },263 getValue: function() {264 return values[this.uid];265 },266 listenEvents: function() {267 var that = this;268 if (this.posturl) {269 this.changer.onchange = function() {270 fileInputOnChange.call(this, that);271 }272 }273 if (this.resetter) {274 this.resetter.onclick = function() {275 reset.call(that);276 }277 };278 }279 });280 _.extend(_.form, true, {281 careatPicturesUploader: function(elem, options) {282 return new _.form.PicturesUploader(elem, options);283 },284 careatPicturesUploaders: function(selector, options) {285 var uploaders = [];286 _.each(query(selector), function(i, el) {287 uploaders.push(_.form.careatPicturesUploader(el, options));288 });289 return uploaders;290 }291 });...

Full Screen

Full Screen

jpng-auto.js

Source:jpng-auto.js Github

copy

Full Screen

...12 img.onerror = onerror;13 img.setAttribute('data-jpng', 'loading');14 }15}16function resetSrc(img, w, h){17 img.setAttribute('data-jpng-auto', 'false');18 if (img.src.indexOf('data:image/png;') === 0) return;19 ensureLoaded(img, (loadedImg, error) => {20 if (error || w === 0 || h === 0) img.setAttribute('data-jpng', 'error');21 else {22 let x = 0, y = h;23 const canvas = jpng.fromRect(img, x, y, w, h),24 dataURL = canvas.toDataURL('image/png');25 canvas.width = canvas.height = 0; // cleanup.26 img.src = dataURL;27 wait( () => { img.setAttribute('data-jpng', 'ready'); } );28 }29 });30}31function update(){32 const images = document.querySelectorAll('img[data-jpng-auto="true"]'),33 len = images.length;34 for (let i = 0, img = null; i < len; i++) {35 img = images[i];36 resetSrc(img, img.width|0, img.height|0);37 }38}39update();40document.addEventListener('readystatechange', update);41export default Object.defineProperties(jpng, {42 resetSrc: { value: resetSrc },43 update: { value: update }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.resetSrc(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org');12 if (err) {13 console.log(err);14 } else {15 console.log(data);16 }17});18var wpt = require('webpagetest');19var wpt = new WebPageTest('www.webpagetest.org');20}, function(err, data) {21 if (err) {22 console.log(err);23 } else {24 console.log(data);25 }26});27var wpt = require('webpagetest');28var wpt = new WebPageTest('www.webpagetest.org');29wpt.getLocations(function(err, data) {30 if (err) {31 console.log(err);32 } else {33 console.log(data);34 }35});36var wpt = require('webpagetest');37var wpt = new WebPageTest('www.webpagetest.org');38wpt.getTestResults('150812_6P_3f3c0e0d1e3e3d4f4c4c4d4e4d4d4e4', function(err, data) {39 if (err) {40 console.log(err);41 } else {42 console.log(data);43 }44});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log(JSON.stringify(data));7 }8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org');11 if (err) {12 console.log('Error: ' + err);13 } else {14 console.log(JSON.stringify(data));15 }16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org');19 if (err) {20 console.log('Error: ' + err);21 } else {22 console.log(JSON.stringify(data));23 }24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27wpt.getLocations(function(err, data) {28 if (err) {29 console.log('Error: ' + err);30 } else {31 console.log(JSON.stringify(data));32 }33});34var wpt = require('webpagetest');35var wpt = new WebPageTest('www.webpagetest.org');36wpt.getTesters(function(err, data) {37 if (err) {38 console.log('Error: ' + err);39 } else {40 console.log(JSON.stringify(data));41 }42});43var wpt = require('web

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org','A.6a7b8c9d0e1f2g3h4i5j6k7l8m9n0o1p2q3r4s5t6u7v8w9x0y1z2a3b4c5d6e7f8g9h0i1j2k3l4m5n6o7p8q9r0s1t2u3v4w5x6y7z8');3 if(err) {4 console.log(err);5 }6 else {7 console.log(data);8 }9});10var wpt = require('wpt');11var wpt = new WebPageTest('www.webpagetest.org','A.6a7b8c9d0e1f2g3h4i5j6k7l8m9n0o1p2q3r4s5t6u7v8w9x0y1z2a3b4c5d6e7f8g9h0i1j2k3l4m5n6o7p8q9r0s1t2u3v4w5x6y7z8');12 if(err) {13 console.log(err);14 }15 else {16 console.log(data);17 }18});19var wpt = require('wpt');20var wpt = new WebPageTest('www.webpagetest.org','A.6a7b8c9d0e1f2g3h4i5j6k7l8m9n0o1p2q3r4s5t6u7v8w9x0y1z

Full Screen

Using AI Code Generation

copy

Full Screen

1var WebPageTest = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.3e3f3f3e3f3e3f3e3f3e3f3e3f3e3f3e3');3wpt.resetSrc('www.webpagetest.org', function(err, data) {4 if (err) {5 console.log('Error: ' + err.message);6 } else {7 console.log('ResetSrc: ' + data);8 }9});10### `new WebPageTest([host], [key], [options])`

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.5c5e5a2d5c5e5a2d5c5e5a2d5c5e5a2d');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10var wpt = new WebPageTest('www.webpagetest.org', 'A.5c5e5a2d5c5e5a2d5c5e5a2d5c5e5a2d');11wpt.getLocations(function(err, data) {12 if (err) {13 console.log(err);14 } else {15 console.log(data);16 }17});18var wpt = require('wpt');19var wpt = new WebPageTest('www.webpagetest.org', 'A.5c5e5a2d5c5e5a2d5c5e5a2d5c5e5a2d');20wpt.getTesters(function(err, data) {21 if (err) {22 console.log(err);23 } else {24 console.log(data);25 }26});27var wpt = require('wpt');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt-api-wrapper');2var fs = require('fs');3var path = require('path');4var config = require('./config.json');5var url = config.url;6var key = config.key;7var location = config.location;8var wpt = new wpt(key);9var location = 'Dulles_MotoG4:Chrome.56';10wpt.runTest(url, {location: location, connectivity: '3G'}, function(err, data) {11 if (err) {12 console.log(err);13 } else {14 var data = JSON.parse(data);15 var testId = data.data.testId;16 var url = data.data.userUrl;17 var status = data.data.statusCode;18 var result = data.data.statusText;19 var runTestUrl = data.data.userUrl;20 console.log('Test ID: ' + testId);21 console.log('Status: ' + status);22 console.log('Result: ' + result);23 console.log('URL: ' + runTestUrl);24 wpt.getTestResults(testId, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 var data = JSON.parse(data);29 var result = data.data;30 var testId = result.testId;31 var url = result.url;32 var status = result.statusCode;33 var result = result.statusText;34 var runTestUrl = result.userUrl;35 var firstView = result.average.firstView;36 var repeatView = result.average.repeatView;37 var firstViewLoadTime = firstView.loadTime;38 var firstViewFullyLoaded = firstView.fullyLoaded;39 var firstViewBytesIn = firstView.bytesIn;40 var firstViewBytesOut = firstView.bytesOut;41 var firstViewRequests = firstView.requests;42 var firstViewRender = firstView.render;43 var firstViewSpeedIndex = firstView.SpeedIndex;44 var firstViewTTFB = firstView.TTFB;45 var firstViewDomElements = firstView.domElements;46 var firstViewDomContentLoadedEventStart = firstView.domContentLoadedEventStart;47 var firstViewDomContentLoadedEventEnd = firstView.domContentLoadedEventEnd;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = new WebPageTest('www.webpagetest.org');2 if (err) {3 console.log('Error: ' + err);4 } else {5 console.log(data);6 }7});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful