How to use HTML_TEMPLATE method in Best

Best JavaScript code snippet using best

ok-status-icon.js

Source:ok-status-icon.js Github

copy

Full Screen

1module.exports = {2 consumes: ["app", "$"],3 provides: ["ok-status-icon"],4 setup: function(options, imports, register) {5 var demo = false;6 var colorSwatch = {7 "red": "255, 0, 0",8 "orange": "255, 165, 0",9 "yellow": "255, 255, 0",10 "green": "50, 205, 50",11 "teal": "0, 128, 128",12 "blue": "0, 0, 255",13 "purple": "128, 0, 128",14 };15 //--------------------------------------------16 var $ = imports.$;17 var wait = ms => new Promise(resolve => setTimeout(resolve, ms));18 var html_template;19 var rainbowRunning = false;20 var pulseRunning = false;21 function setColor(color) {22 if (colorSwatch[color]) {23 color = "rgb(" + colorSwatch[color] + ")";24 }25 if (html_template) {26 if (color) {27 if(!isInserted())28 connection_pos(true);29 html_template.find(".ok-staus-color").30 css("filter", "drop-shadow(0 0 0.75rem " + color + ")");31 }32 else {33 html_template.find(".ok-staus-color").34 css("filter", "");35 }36 }37 }38 var rb_colorSwatch = [];39 for (var color in colorSwatch) {40 rb_colorSwatch.push(color);41 setColor[color] = (c => {42 return function(pulse) {43 setColor.off();44 if (pulse)45 doPulse(c);46 else47 setColor(c);48 };49 })(color);50 }51 setColor.rainbow = function() {52 var loopSwatch = [].concat(rb_colorSwatch, [].concat(rb_colorSwatch).reverse()); //cylon53 var ri;54 var pdone;55 connection_pos(function(){56 if(pdone) return;57 ri = setInterval(function() {58 loopSwatch.unshift(loopSwatch.pop());59 setColor(loopSwatch[0]);60 }, 250); 61 });62 rainbowRunning = function() {63 pdone = true;64 setColor(false);65 clearInterval(ri);66 rainbowRunning = false;67 };68 };69 setColor.off = function(disconnect) {70 if (rainbowRunning)71 rainbowRunning();72 if (pulseRunning)73 pulseRunning();74 setColor(false);75 if(disconnect) connection_pos();76 };77 function doPulse(color) {78 var c = colorSwatch[color];79 if (!c) c = color;80 var i = 0;81 var d;82 var ri;83 var pdone = false;84 connection_pos(function(){85 if(pdone) return;86 ri = setInterval(function() {87 if (i >= 1) d = 1;88 if (i <= 0) d = 0;89 if (d == 1)90 i -= 0.1;91 else92 i += 0.1;93 setColor("rgba(" + c + "," + i + ")");94 }, 50);95 });96 pulseRunning = function() {97 pdone = true;98 setColor(false);99 if(ri)100 clearInterval(ri);101 pulseRunning = false;102 };103 }104 var insertDist = "30";105 var _inserted = false;106 function isInserted() {107 return !!_inserted;108 }109 function connection_pos(inserted) {110 _inserted = !!inserted;111 if(!html_template) return;112 if (inserted) {113 html_template.animate({114 "margin-left": insertDist115 }, 250, function() {116 un_inserted_animation.inAnimation = false;117 if(typeof inserted == "function") inserted();118 });119 }120 else {121 html_template.animate({122 "margin-left": "-"+insertDist123 }, 250, function() {124 un_inserted_animation.inAnimation = false;125 });126 }127 un_inserted_animation.inAnimation = true;128 }129 var un_inserted_animation = {130 length_loop: 12,131 step: -1,132 inAnimation: false,133 interval: function() {134 if (un_inserted_animation.inAnimation) return;135 if (un_inserted_animation.step > un_inserted_animation.length_loop)136 un_inserted_animation.step = -1;137 un_inserted_animation.step++;138 if (!isInserted()) {139 if (un_inserted_animation.step == 8 || un_inserted_animation.step == 10) {140 html_template.animate({141 "margin-left": insertDist142 }, 250, function() {143 un_inserted_animation.inAnimation = false;144 });145 }146 else {147 html_template.animate({148 "margin-left": "-"+insertDist149 }, 250, function() {150 un_inserted_animation.inAnimation = false;151 });152 }153 un_inserted_animation.inAnimation = true;154 }155 else {156 un_inserted_animation.step = -1;157 }158 }159 };160 161 162 var TARGET_TO_REPLACE = '[src="ok-plugged4.png"]';163 var img_src = "ok-coverd-r-90.png";164 165 html_template = imports.$(require("./ok-status.template.html").default);166 html_template.css("visibility", "hidden");167 html_template.find("img").on("load", function() {168 169 html_template.css("display", "inline");170 html_template.css("position", "absolute");171 html_template.css("float", "left");172 html_template.css("z-index", "-1");173 html_template.css("top", "193px");174 175 var ttr = $(TARGET_TO_REPLACE);176 177 ttr.fadeOut(0, function(){178 ttr.attr("src", "ok-plugged5.png").on("load",function(){179 180 connection_pos(function(){181 182 ch.parent().prepend(html_template);//<-- add to DOM183 html_template.fadeOut(0);184 html_template.css("visibility", "");185 ttr.fadeIn(1000);186 html_template.fadeIn(1000,function(){187 setColor.off(true);188 setInterval(un_inserted_animation.interval, 500); 189 finishRegister();190 });191 });192 193 // setTimeout(function(){194 // html_template.fadeOut(0);195 // html_template.css("visibility", "");196 // html_template.fadeIn(1000,connection_pos);197 // },500);198 199 // setInterval(un_inserted_animation.interval, 500);200 //finishRegister();201 }); 202 });203 204 // connection_pos();205 });206 207 var ch = imports.$("body").find(TARGET_TO_REPLACE);208 if(ch[0]){209 html_template.find("img").attr("src", img_src);210 }else{211 html_template = false;212 finishRegister();213 } 214 215 216 217 218 function finishRegister(){219 register(null, {220 "ok-status-icon": {221 setColor: setColor,222 init: function() {223 imports.app.on("start", function() {224 // return;225 // setColor.off(true);// default state226 if(demo){227 setTimeout(async function() {228 setColor.rainbow();229 await wait(5000);230 setColor.green();//solid231 await wait(5000);232 setColor.yellow(true);//pulse233 await wait(5000);234 setColor.red();//solid235 await wait(5000);236 setColor.off(true);//disconnected and led off237 }, 10000);238 }else{239 240 /*241 LED Definitions242 Steady green light = Unlocked243 No light = Locked244 Single yellow flash = Button pressed for PIN entry245 3 red flashes = Wrong PIN246 Continuous red flashes = Exceeded PIN tries247 Continuous green flashes = Backup and restore is complete.248 Blue fade in and fade out = FIDO U2F request249 Blue blink on/off = FIDO2 request250 Purple fade in and fade out - Private key signing request (SSH or PGP)251 Turquoise fade in and fade out - Private key decryption request252 Red fade in and fade out - Device is in config mode253 Steady white light - Device is in bootloader mode, use the OnlyKey app to load firmware.254 */255 imports.app.on("ok-disconnected", function(){256 setColor.off(true);257 });258 imports.app.on("ok-connecting", function(){259 setColor.off(true);260 });261 imports.app.on("ok-connected", function(){262 setColor.green();263 });264 imports.app.on("ok-activity", function(){265 setColor.blue(true);266 });267 imports.app.on("ok-error", function(){268 setColor.red();269 });270 imports.app.on("ok-signing", function(){271 setColor.purple(true);272 });273 imports.app.on("ok-decrypting", function(){274 setColor.teal(true);275 });276 imports.app.on("ok-waiting", function(){277 setColor.yellow(true);278 });279 imports.app.on("ok-message", function(msg){280 imports.$("#header_messages").text(msg);281 });282 }283 });284 }285 }286 });287 }288 }...

Full Screen

Full Screen

dashboard.js

Source:dashboard.js Github

copy

Full Screen

1$(document).ready(function () {2 // to update orders and sales charts3 GraghQLAjax();4 // to update traffic and visit tables5 RESTAjax();6});7// Ajax functions to update chart and tables8function GraghQLAjax(params) {9 var query = JSON.stringify({10 query: `query {11 orders_month_report {12 month13 total14 }15 sales_month_report {16 month17 total_amount18 }19 }`20 });21 $.ajax({22 method: 'POST',23 url: '/graphql/',24 data: query,25 contentType: 'application/json',26 success: function (data) {27 var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];28 // sales chart29 var sales_chart_data = [];30 $.each(data.data.sales_month_report, function (index, obj) {31 sales_chart_data.push(obj.total_amount);32 });33 SalesChart(sales_chart_data, months);34 // orders chart35 var orders_chart_data = [];36 $.each(data.data.orders_month_report, function (index, obj) {37 orders_chart_data.push(obj.total);38 });39 OrderChart(orders_chart_data, months);40 },41 error: function () {42 alert('Error occurred');43 }44 });45}46function RESTAjax() {47 $.ajax({48 method: 'GET',49 url: '/api/v1/visits/',50 success: function (data) {51 var html_template = '';52 $.each(data.results, function (index, obj) {53 html_template += '<tr>';54 html_template += '<th scope="row">' + obj.page_name + '</th>';55 html_template += '<td>' + obj.visitors + '</td>';56 html_template += '<td>' + obj.unique_users + '</td>';57 if (obj.bounce_rate_type === 1)58 html_template += '<td><i class="fas fa-arrow-up text-success mr-3"></i>' + obj.bounce_rate + '%</td>';59 else60 html_template += '<td><i class="fas fa-arrow-down text-warning mr-3"></i>' + obj.bounce_rate + '%</td>';61 html_template += '</tr>';62 $('#visitsInfo').find('tbody').html(html_template);63 });64 },65 error: function () {66 alert('Error occurred');67 }68 });69 $.ajax({70 method: 'GET',71 url: '/api/v1/traffics/',72 success: function (data) {73 var html_template = '';74 $.each(data.results, function (index, obj) {75 var bg_gradient = obj.rate_type === 1 ? "bg-gradient-success" : "bg-gradient-danger";76 html_template += '<tr>';77 html_template += '<th scope="row">' + obj.referral + '</th>';78 html_template += '<td>' + obj.visitors + '</td>';79 html_template += '<td><div class="d-flex align-items-center"><span class="mr-2">' + obj.rate + '%</span>';80 html_template += '<div><div class="progress">';81 html_template += '<div class="progress-bar ' + bg_gradient + '" role="progressbar" ' +82 'aria-valuenow="' + obj.rate + '" aria-valuemin="0" aria-valuemax="100" ' +83 'style="width: ' + obj.rate + '%;"></div>';84 html_template += '</div></div>';85 html_template += '</div></td>';86 html_template += '</tr>';87 $('#trafficsInfo').find('tbody').html(html_template);88 });89 },90 error: function () {91 alert('Error occurred');92 }93 });94}95// charts function96function SalesChart(data, labels) {97 // Variables98 var $chart = $('#chartSales');99 var salesChart = new Chart($chart, {100 type: 'line',101 options: {102 scales: {103 yAxes: [{104 gridLines: {105 lineWidth: 1,106 color: Charts.colors.gray[900],107 zeroLineColor: Charts.colors.gray[900]108 },109 ticks: {110 callback: function (value) {111 if (!(value % 10)) {112 return '$' + value;113 }114 }115 }116 }]117 },118 tooltips: {119 callbacks: {120 label: function (item, data) {121 var label = data.datasets[item.datasetIndex].label || '';122 var yLabel = item.yLabel;123 var content = '';124 if (data.datasets.length > 1) {125 content += '<span class="popover-body-label mr-auto">' + label + '</span>';126 }127 content += '<span class="popover-body-value">$' + yLabel + '</span>';128 return content;129 }130 }131 }132 },133 data: {134 labels: labels,135 datasets: [{136 label: 'Performance',137 data: data138 }]139 }140 });141 // Save to jQuery object142 $chart.data('chart', salesChart);143}144function OrderChart(data, labels) {145 var $chart = $('#chartOrders');146 var ordersChart = new Chart($chart, {147 type: 'bar',148 options: {149 scales: {150 yAxes: [{151 gridLines: {152 lineWidth: 1,153 color: '#dfe2e6',154 zeroLineColor: '#dfe2e6'155 },156 ticks: {157 callback: function (value) {158 if (!(value % 10)) {159 //return '$' + value + 'k'160 return value161 }162 }163 }164 }]165 },166 tooltips: {167 callbacks: {168 label: function (item, data) {169 var label = data.datasets[item.datasetIndex].label || '';170 var yLabel = item.yLabel;171 var content = '';172 if (data.datasets.length > 1) {173 content += '<span class="popover-body-label mr-auto">' + label + '</span>';174 }175 content += '<span class="popover-body-value">' + yLabel + '</span>';176 return content;177 }178 }179 }180 },181 data: {182 labels: labels,183 datasets: [{184 label: 'Sales',185 data: data186 }]187 }188 });189 // Save to jQuery object190 $chart.data('chart', ordersChart);...

Full Screen

Full Screen

password-recovery.js

Source:password-recovery.js Github

copy

Full Screen

1const APIUtil = require("./../../APIUtil");2const sanitizer = require("./../../sanitizer");3const ServerException = require("./../../ServerException");4const SanctumUtil = require("./../../SanctumUtil");5const fs = require("fs");6const nodemailer = require("nodemailer");7const nuxt_config = require("../../../../../../nuxt.config");8const moment = require("moment");9module.exports = function(req, res, next){10 const username = sanitizer.cleanExtraSymbols(APIUtil.extract(req.body, "username"));11 SanctumUtil.post("/api/sanctum/system/initiate-password-recovery", {email: username}).then(async (password_recovery_attempt) => {12 let email_address = password_recovery_attempt.email_address;13 let link = req.headers.origin + "/password-reset?r=" + password_recovery_attempt.reference;14 let reset_link = req.headers.origin + "/login";15 let expiry_time = password_recovery_attempt.requested_time + password_recovery_attempt.ttl;16 expiry_time = moment.unix(expiry_time).format("D/M/YYYY HH:mm:ss");17 let html_template = fs.readFileSync(__dirname + "/../../../assets/html/forgot-password-template.html", "utf8") + "";18 html_template = html_template.replace(/\${primary_color}/g, nuxt_config.default.vuetify.theme.themes.light.primary);19 html_template = html_template.replace(/\${secondary_color}/g, nuxt_config.default.vuetify.theme.themes.light.secondary);20 html_template = html_template.replace(/\${accent_color}/g, nuxt_config.default.vuetify.theme.themes.light.accent);21 html_template = html_template.replace(/\${link}/g, link);22 html_template = html_template.replace(/\${reset_link}/g, reset_link);23 html_template = html_template.replace(/\${expiry_time}/g, expiry_time);24 const config = require("./../../../../../../server.config");25 if(config.email_server !== undefined) {26 try{27 let server = nodemailer.createTransport(config.email_server);28 server.sendMail({29 from: "System",30 to: email_address,31 subject: "Password Recovery",32 html: html_template33 });34 res.send({35 success: true36 });37 }catch (e){38 next(e);39 }40 }else{41 throw new ServerException(400, "unable_to_mail", "Unable to send recovery email");42 }43 }).catch(next);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestTemplate = require('best-template');2var template = new BestTemplate({3});4template.render({5}, function (err, html) {6 console.log(html);7});8var BestTemplate = require('best-template');9var template = new BestTemplate({10});11template.render({12}, function (err, html) {13 console.log(html);14});15var BestTemplate = require('best-template');16var template = new BestTemplate({17 template: 'Hello, {{name}}',18});19template.render({20}, function (err, html) {21 console.log(html);22});23var BestTemplate = require('best-template');24var template = new BestTemplate({25 template: 'Hello, #{name}',26});27template.render({28}, function (err, html) {29 console.log(html);30});31var BestTemplate = require('best-template');32var template = new BestTemplate({33 template: 'Hello, {{name}}',34});35template.render({36}, function (err, html) {37 console.log(html);38});39var BestTemplate = require('best-template');40var template = new BestTemplate({41 template: 'Hello, #{name}',42});43template.render({44}, function (err, html) {45 console.log(html);46});47var BestTemplate = require('best-template');48var template = new BestTemplate({49 template: 'Hello, {{

Full Screen

Using AI Code Generation

copy

Full Screen

1var bt = new BestTemplate();2bt.setTemplateMethod(BestTemplate.HTML_TEMPLATE);3bt.setTemplateFile("test.html");4bt.setTemplateData({ "name" : "John Doe" });5var result = bt.renderTemplate();6response.write(result);7setTemplateMethod(templateMethod)8setTemplateFile(templateFile)9setTemplateData(templateData)10renderTemplate()11bt.setTemplateFile("test.html");12bt.setTemplateData({ "name" : "John Doe" });

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var html = fs.readFileSync('index.html', 'utf8');3html = html.replace('{{name}}', 'Joe');4html = html.replace('{{value}}', 100);5console.log(html);6 <h1>{{name}}</h1>7 <p>{{value}}</p>8var fs = require('fs');9var html = fs.readFileSync('index.html', 'utf8');10html = html.replace('{{name}}', 'Joe');11html = html.replace('{{value}}', 100);12console.log(html);13 <h1>{{name}}</h1>14 <p>{{value}}</p>15var fs = require('fs');16var html = fs.readFileSync('index.html', 'utf8');17html = html.replace('{{name}}', 'Joe');18html = html.replace('{{value}}', 100);19console.log(html);20 <h1>{{name}}</h1>21 <p>{{value}}</p>22var fs = require('fs');23var html = fs.readFileSync('index.html', 'utf8');24html = html.replace('{{name}}', 'Joe');25html = html.replace('{{value}}', 100);26console.log(html);

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var HTML_TEMPLATE = fs.readFileSync('html_template.html', 'utf8');3 .replace('{{title}}', 'My Page')4 .replace('{{body}}', 'Hello World!');5console.log(html);6 <title>{{title}}</title>7 {{body}}8var fs = require('fs');9var HTML_TEMPLATE = fs.readFileSync('html_template.html', 'utf8');10 .replace('{{title}}', 'My Page')11 .replace('{{body}}', 'Hello World!');12console.log(html);13 <title>{{title}}</title>14 {{body}}15var fs = require('fs');16var HTML_TEMPLATE = fs.readFileSync('html_template.html', 'utf8');17 .replace('{{title}}', 'My Page')18 .replace('{{body}}', 'Hello World!');19console.log(html);20 <title>{{title}}</title>21 {{body}}

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 Best 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