Best JavaScript code snippet using playwright-internal
layout_editor.js
Source:layout_editor.js
1function init_layout_editor() {2 document.getElementsByTagName('body')[0].style.backgroundColor = document.getElementById('bodybgcol').value;3 var mods = getElementsByClassName(document, '*', 'module');4 for(var i = 0; i < mods.length; i++)5 mods[i].style.borderColor = document.getElementById('modulecol').value;6 for(var i = 0; i < mods.length; i++) {7 var h1s = mods[i].getElementsByTagName('h1');8 for(var j = 0; j < h1s.length; j++) {9 var stylevalue = "background-color: " + document.getElementById('moduleh1bgcol').value + ";";10 if(document.getElementById("moduleh1col").value.length > 0)11 stylevalue += " color: " + document.getElementById("moduleh1col").value + ";"12 h1s[j].setAttribute("style", stylevalue);13 }14 }15 var mod = document.getElementById('header');16 var h1s = mod.getElementsByTagName('h1');17 for(var j = 0; j < h1s.length; j++) {18 var stylevalue = "color: " + document.getElementById('headerh1col').value + ";"19 h1s[j].setAttribute("style", stylevalue);20 }21 var h2s = mod.getElementsByTagName('h2');22 for(var j = 0; j < h2s.length; j++) {23 var stylevalue = "color: " + document.getElementById('headerh2col').value + ";"24 h2s[j].setAttribute("style", stylevalue);25 }26 var mod = document.getElementById('container');27 var stylevalue = "background-color: " + document.getElementById('containercol').value + ";"28 mod.setAttribute("style", stylevalue);29 var mod = document.getElementById('col_d');30 var stylevalue = "background-color: " + document.getElementById('colbcol').value + ";"31 mod.setAttribute("style", stylevalue);32}3334function pickColor(color) {35 var colorObjId = window.ColorPicker_targetInput.id;36 window.ColorPicker_targetInput.value = color;37 switch(colorObjId) {38 case 'bodybgcol':39 document.getElementsByTagName('body')[0].style.backgroundColor = color;40 break;41 case 'modulecol':42 var mods = getElementsByClassName(document, '*', 'module');43 for(var i = 0; i < mods.length; i++)44 mods[i].style.borderColor = color;45 break;46 case 'moduleh1bgcol':47 var mods = getElementsByClassName(document, '*', 'module');48 for(var i = 0; i < mods.length; i++) {49 var h1s = mods[i].getElementsByTagName('h1');50 for(var j = 0; j < h1s.length; j++) {51 var stylevalue = "background-color: " + color + ";";52 if(document.getElementById("moduleh1col").value.length > 0)53 stylevalue += " color: " + document.getElementById("moduleh1col").value + ";"54 if(document.getElementById("moduleh1font").selectedIndex > 0)55 stylevalue += " font-family: " + document.getElementById("moduleh1font").options[document.getElementById("moduleh1font").selectedIndex].value + ";"56 h1s[j].setAttribute("style", stylevalue);57 }58 }59 break;60 case 'moduleh1col':61 var mods = getElementsByClassName(document, '*', 'module');62 for(var i = 0; i < mods.length; i++) {63 var h1s = mods[i].getElementsByTagName('h1');64 for(var j = 0; j < h1s.length; j++) {65 var stylevalue = "color: " + color + ";"66 if(document.getElementById("moduleh1bgcol").value.length > 0)67 stylevalue += " background-color: " + document.getElementById("moduleh1bgcol").value + ";"68 if(document.getElementById("moduleh1font").selectedIndex > 0)69 stylevalue += " font-family: " + document.getElementById("moduleh1font").options[document.getElementById("moduleh1font").selectedIndex].value + ";"70 h1s[j].setAttribute("style", stylevalue);71 }72 }73 break;74 case 'headerh1col':75 var mod = document.getElementById('header');76 var h1s = mod.getElementsByTagName('h1');77 for(var j = 0; j < h1s.length; j++) {78 var stylevalue = "color: " + color + ";"79 if(document.getElementById("headerh1font").selectedIndex > 0)80 stylevalue += " font-family: " + document.getElementById("headerh1font").options[document.getElementById("headerh1font").selectedIndex].value + ";"81 if(document.getElementById("headerh1vis").selectedIndex > 0)82 stylevalue += " visibility: " + document.getElementById("headerh1vis").options[document.getElementById("headerh1vis").selectedIndex].value + ";"83 h1s[j].setAttribute("style", stylevalue);84 }85 break;86 case 'headerh2col':87 var mod = document.getElementById('header');88 var h2s = mod.getElementsByTagName('h2');89 for(var j = 0; j < h2s.length; j++) {90 var stylevalue = "color: " + color + ";"91 if(document.getElementById("headerh2font").selectedIndex > 0)92 stylevalue += " font-family: " + document.getElementById("headerh2font").options[document.getElementById("headerh2font").selectedIndex].value + ";"93 if(document.getElementById("headerh2vis").selectedIndex > 0)94 stylevalue += " visibility: " + document.getElementById("headerh2vis").options[document.getElementById("headerh2vis").selectedIndex].value + ";"95 h2s[j].setAttribute("style", stylevalue);96 }97 break;98 case 'containercol':99 var mod = document.getElementById('container');100 var stylevalue = "background-color: " + color + ";"101 mod.setAttribute("style", stylevalue);102 break;103 case 'colbcol':104 var mod = document.getElementById('col_b');105 var stylevalue = "background-color: " + color + ";"106 mod.setAttribute("style", stylevalue);107 break;108 }109}110111function getElementsByClassName(oElm, strTagName, strClassName) {112 var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);113 var arrReturnElements = new Array();114 strClassName = strClassName.replace(/\-/g, "\\-");115 var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");116 var oElement;117 for(var i=0; i<arrElements.length; i++){118 oElement = arrElements[i]; 119 if(oRegExp.test(oElement.className)){120 arrReturnElements.push(oElement);121 } 122 }123 return (arrReturnElements);124}125126function chBodyFont() {127 document.getElementsByTagName('body')[0].style.fontFamily = document.getElementById("bodyfont").options[document.getElementById("bodyfont").selectedIndex].value;128}129130function chBodyBgRepeat() {131 document.getElementsByTagName('body')[0].style.backgroundRepeat = document.getElementById("bodybgepeat").options[document.getElementById("bodybgepeat").selectedIndex].value;132}133134function chBodyBgRepeat() {135 document.getElementsByTagName('body')[0].style.backgroundImage = document.getElementById("bodybgimage").value;136}137138function chModuleH1Font() {139 var mods = getElementsByClassName(document, '*', 'module');140 for(var i = 0; i < mods.length; i++) {141 var h1s = mods[i].getElementsByTagName('h1');142 for(var j = 0; j < h1s.length; j++) {143 var stylevalue = "font-family: " + document.getElementById("moduleh1font").options[document.getElementById("moduleh1font").selectedIndex].value + ";"144 if(document.getElementById("moduleh1bgcol").value.length > 0)145 stylevalue += " background-color: " + document.getElementById("moduleh1bgcol").value + ";"146 if(document.getElementById("moduleh1col").value.length > 0)147 stylevalue += " color: " + document.getElementById("moduleh1col").value + ";"148 h1s[j].setAttribute("style", stylevalue);149 }150 }151}152153function chHeaderH1Font() {154 var mod = document.getElementById('header');155 var h1s = mod.getElementsByTagName('h1');156 for(var j = 0; j < h1s.length; j++) {157 var stylevalue = "font-family: " + document.getElementById("headerh1font").options[document.getElementById("headerh1font").selectedIndex].value + ";"158 if(document.getElementById("headerh1col").value.length > 0)159 stylevalue += " color: " + document.getElementById("headerh1col").value + ";"160 if(document.getElementById("headerh1vis").selectedIndex > 0)161 stylevalue += " visibility: " + document.getElementById("headerh1vis").options[document.getElementById("headerh1vis").selectedIndex].value + ";"162 h1s[j].setAttribute("style", stylevalue);163 }164}165166function chHeaderH1Visibility() {167 var mod = document.getElementById('header');168 var h1s = mod.getElementsByTagName('h1');169 for(var j = 0; j < h1s.length; j++) {170 var stylevalue = "visibility: " + document.getElementById("headerh1vis").options[document.getElementById("headerh1vis").selectedIndex].value + ";"171 if(document.getElementById("headerh1col").value.length > 0)172 stylevalue += " color: " + document.getElementById("headerh1col").value + ";"173 if(document.getElementById("headerh1font").selectedIndex > 0)174 stylevalue += " font-family: " + document.getElementById("headerh1font").options[document.getElementById("headerh1font").selectedIndex].value + ";"175 h1s[j].setAttribute("style", stylevalue);176 }177}178179function chHeaderH2Font() {180 var mod = document.getElementById('header');181 var h2s = mod.getElementsByTagName('h2');182 for(var j = 0; j < h2s.length; j++) {183 var stylevalue = "font-family: " + document.getElementById("headerh2font").options[document.getElementById("headerh2font").selectedIndex].value + ";"184 if(document.getElementById("headerh2col").value.length > 0)185 stylevalue += " color: " + document.getElementById("headerh2col").value + ";"186 if(document.getElementById("headerh2vis").selectedIndex > 0)187 stylevalue += " visibility: " + document.getElementById("headerh2vis").options[document.getElementById("headerh2vis").selectedIndex].value + ";"188 h2s[j].setAttribute("style", stylevalue);189 }190}191192function chHeaderH2Visibility() {193 var mod = document.getElementById('header');194 var h2s = mod.getElementsByTagName('h2');195 for(var j = 0; j < h2s.length; j++) {196 var stylevalue = "visibility: " + document.getElementById("headerh2vis").options[document.getElementById("headerh2vis").selectedIndex].value + ";"197 if(document.getElementById("headerh2col").value.length > 0)198 stylevalue += " color: " + document.getElementById("headerh2col").value + ";"199 if(document.getElementById("headerh2font").selectedIndex > 0)200 stylevalue += " font-family: " + document.getElementById("headerh2font").options[document.getElementById("headerh2font").selectedIndex].value + ";"201 h2s[j].setAttribute("style", stylevalue);202 }203}204205function chBodyShad() {206 document.getElementById('body_shadow').style.visibility = document.getElementById("bodyshad").options[document.getElementById("bodyshad").selectedIndex].value;207}208209function getCSS() {210 var ncss = '#container {\n'211 + '\tbackground-color: ' + document.getElementById("containercol").value + ';\n'212 + '}\n'213 + '#col_b {\n'214 + '\tbackground-color: ' + document.getElementById("colbcol").value + ';\n'215 + '}\n'216 + 'body {\n'217 + '\tbackground-color: ' + document.getElementById("bodybgcol").value + ';\n'218 + '\tfont-family: ' + document.getElementById("bodyfont").options[document.getElementById("bodyfont").selectedIndex].value + ';\n'219 + '\tbackground-image: none;\n'220 + '\tbackground-repeat: ' + document.getElementById("bodybgrepeat").options[document.getElementById("bodybgrepeat").selectedIndex].value + ';\n'221 + '}\n'222 + '.module {\n'223 + '\tborder-color: ' + document.getElementById("modulecol").value + ';\n'224 + '}\n'225 + '.module h1{\n'226 + '\tbackground-color: ' + document.getElementById("moduleh1bgcol").value + ';\n'227 + '\tcolor: ' + document.getElementById("moduleh1col").value + ';\n'228 + '}\n'229 + '#header h1 {\n'230 + '\tfont-family: ' + document.getElementById("headerh1font").options[document.getElementById("headerh1font").selectedIndex].value + ';\n'231 + '\tcolor: ' + document.getElementById("headerh1col").value + ';\n'232 + '\tvisibility: ' + document.getElementById("headerh1vis").options[document.getElementById("headerh1vis").selectedIndex].value + ';\n'233 + '}\n'234 + '\n'235 + '#header h2 {\n'236 + '\tfont-family: ' + document.getElementById("headerh2font").options[document.getElementById("headerh2font").selectedIndex].value + ';\n'237 + '\tcolor: ' + document.getElementById("headerh2col").value + ';\n'238 + '\tvisibility: ' + document.getElementById("headerh2vis").options[document.getElementById("headerh2vis").selectedIndex].value + ';\n'239 + '}\n'240 + '#body_shadow {\n'241 + '\tvisibility: ' + document.getElementById("bodyshad").options[document.getElementById("bodyshad").selectedIndex].value + ';\n'242 + '}';243 document.getElementById("newcss").innerHTML = ncss;244// alert(ncss);
...
info.js
Source:info.js
...36exports.render = function (logger, config, rpad, styleHeading, styleValue, styleBad) {37 var data = this.data;38 if (!data) return;39 logger.log(styleHeading(__('Android SDK')) + '\n' +40 ' ' + rpad(__('Android Executable')) + ' = ' + styleValue(data.sdk && data.sdk.executables.android || __('not found')) + '\n' +41 ' ' + rpad(__('ADB Executable')) + ' = ' + styleValue(data.sdk && data.sdk.executables.adb || __('not found')) + '\n' +42 ' ' + rpad(__('SDK Path')) + ' = ' + styleValue(data.sdk && data.sdk.path || __('not found')) + '\n'43 );44 logger.log(styleHeading(__('Android NDK')) + '\n' +45 ' ' + rpad(__('NDK Path')) + ' = ' + styleValue(data.ndk && data.ndk.path || __('not found')) + '\n' +46 ' ' + rpad(__('NDK Version')) + ' = ' + styleValue(data.ndk && data.ndk.version || __('not found')) + '\n'47 );48 var androidPlatforms = '',49 androidAddons = '',50 apiLevelMap = {};51 if (data.targets && Object.keys(data.targets).length) {52 Object.keys(data.targets).forEach(function (targetId) {53 var target = data.targets[targetId],54 supported = (target.supported == 'maybe'55 ? (' (' + __('not supported by Titanium SDK %s, but may work', data.tisdk) + ')').yellow56 : target.supported57 ? ''58 : styleBad(' **' + __('Not supported by Titanium SDK %s', data.tisdk) + '**'));59 if (target.type == 'platform') {60 var m = target.name.match(/Android\s+(\d(?:\.\d(?:\.\d)?)?)/);61 if (m) {62 apiLevelMap[m[1]] = target['api-level'];63 }64 androidPlatforms += ' ' + (targetId + ') ' + target.id).cyan + '\n' +65 ' ' + rpad(' ' + __('Name')) + ' = ' + styleValue(target.name) + supported + '\n' +66 ' ' + rpad(' ' + __('API Level')) + ' = ' + styleValue(target['api-level']) + '\n' +67 ' ' + rpad(' ' + __('Revision')) + ' = ' + styleValue(target.revision) + '\n' +68 ' ' + rpad(' ' + __('Skins')) + ' = ' + styleValue(target.skins.join(', ')) + '\n' +69 ' ' + rpad(' ' + __('ABIs')) + ' = ' + styleValue(target.abis.join(', ')) + '\n' +70 ' ' + rpad(' ' + __('Path')) + ' = ' + styleValue(target.path) + '\n';71 } else if (target.type == 'add-on') {72 androidAddons += ' ' + (targetId + ') ' + target.id).cyan + '\n' +73 ' ' + rpad(' ' + __('Name')) + ' = ' + styleValue(target.name74 + ' (' + target['based-on'] ? __('Android %s (API level %s)', target['based-on']['android-version'], target['based-on']['api-level']) : __('unknown') + ')') + supported + '\n' +75 ' ' + rpad(' ' + __('Vendor')) + ' = ' + styleValue(target.vendor) + '\n' +76 ' ' + rpad(' ' + __('Revision')) + ' = ' + styleValue(target.revision) + '\n' +77 ' ' + rpad(' ' + __('Description')) + ' = ' + styleValue(target.description) + '\n' +78 ' ' + rpad(' ' + __('Skins')) + ' = ' + styleValue(target.skins.join(', ')) + '\n' +79 ' ' + rpad(' ' + __('ABIs')) + ' = ' + styleValue(target.abis.join(', ')) + '\n' +80 ' ' + rpad(' ' + __('Path')) + ' = ' + styleValue(target.path) + '\n';81 if (target.libraries && Object.keys(target.libraries).length) {82 Object.keys(target.libraries).map(function (lib, i) {83 androidAddons += ' ' + (i == 0 ? rpad(' ' + __('Libraries')) + ' = ' : rpad('') + ' ') +84 styleValue(lib + ': ' + target.libraries[lib].description + ' (' + target.libraries[lib].jar + ')') + '\n';85 });86 androidAddons += '\n';87 } else {88 androidAddons += ' ' + rpad(' ' + __('Libraries')) + ' = ' + styleValue(__('none')) + '\n';89 }90 }91 });92 }93 logger.log(styleHeading(__('Android Platforms')) + '\n' + (androidPlatforms ? androidPlatforms : ' ' + __('None').grey + '\n'));94 logger.log(styleHeading(__('Android Add-Ons')) + '\n' + (androidAddons ? androidAddons : ' ' + __('None').grey + '\n'));95 logger.log(styleHeading(__('Android Emulators')));96 if (data.emulators) {97 var emus = data.emulators.filter(function (e) { return e.type == 'avd'; });98 if (emus.length) {99 logger.log(emus.map(function (emu) {100 return ' ' + emu.name.cyan + '\n' +101 ' ' + rpad(' ' + __('Path')) + ' = ' + styleValue(emu.path) + '\n' +102 ' ' + rpad(' ' + __('SDK Version')) + ' = ' + styleValue(emu.target) + '\n' +103 ' ' + rpad(' ' + __('ABI')) + ' = ' + styleValue(emu.abi) + '\n' +104 ' ' + rpad(' ' + __('Skin')) + ' = ' + styleValue(emu.skin) + '\n' +105 ' ' + rpad(' ' + __('SD Card')) + ' = ' + styleValue(emu.sdcard || __('no sd card')) + '\n' +106 (emu['based-on']107 ? ' ' + rpad(' ' + __('Based On')) + ' = ' + styleValue(__('Android %s (API level %s)', emu['based-on']['android-version'], emu['based-on']['api-level'])) + '\n'108 : ''109 ) +110 ' ' + rpad(' ' + __('Google APIs')) + ' = ' + styleValue(emu.googleApis ? __('yes') : __('no'));111 }).join('\n') + '\n');112 } else {113 logger.log(' ' + __('None').grey + '\n');114 }115 } else {116 logger.log(' ' + __('None').grey + '\n');117 }118 logger.log(styleHeading(__('Genymotion Emulators')));119 if (data.emulators) {120 var emus = data.emulators.filter(function (e) { return e.type == 'genymotion'; });121 if (emus.length) {122 logger.log(emus.map(function (emu) {123 return ' ' + emu.name.cyan + '\n' +124 ' ' + rpad(' ' + __('SDK Version')) + ' = ' + styleValue(emu.target + (apiLevelMap[emu.target] ? ' (android-' + apiLevelMap[emu.target] + ')' : '')) + '\n' +125 ' ' + rpad(' ' + __('ABI')) + ' = ' + styleValue(emu.abi || __('unknown')) + '\n' +126 ' ' + rpad(' ' + __('Genymotion Version')) + ' = ' + styleValue(emu.genymotion || __('unknown')) + '\n' +127 ' ' + rpad(' ' + __('Display')) + ' = ' + styleValue(emu.display || __('unknown')) + '\n' +128 ' ' + rpad(' ' + __('DPI')) + ' = ' + styleValue(emu.dpi || __('unknown')) + '\n' +129 ' ' + rpad(' ' + __('OpenGL Acceleration')) + ' = ' + styleValue(emu.hardwareOpenGL ? __('yes') : __('no')) + '\n' +130 ' ' + rpad(' ' + __('Google APIs')) + ' = ' + styleValue(emu.googleApis === null ? __('unknown, emulator not running') : emu.googleApis ? __('yes') : __('no'));131 }).join('\n') + '\n');132 } else {133 logger.log(' ' + __('None').grey + '\n');134 }135 } else {136 logger.log(' ' + __('None').grey + '\n');137 }138 logger.log(styleHeading(__('Connected Android Devices')));139 if (data.devices && data.devices.length) {140 logger.log(data.devices.map(function (device) {141 var name = device.name,142 result = [143 ' ' + rpad(__('ID')) + ' = ' + styleValue(device.id),144 ' ' + rpad(__('State')) + ' = ' + styleValue(device.state)145 ];146 if (device.release) {147 result.push(' ' + rpad(__('SDK Version')) + ' = ' + styleValue(device.release + ' (android-' + device.sdk + ')'));148 }149 if (Array.isArray(device.abi)) {150 result.push(' ' + rpad(__('ABIs')) + ' = ' + styleValue(device.abi.join(', ')));151 }152 if (device.emulator) {153 switch (device.emulator.type) {154 case 'avd':155 name = 'Android Emulator: ' + device.emulator.name;156 result.push(' ' + rpad(__('Skin')) + ' = ' + styleValue(device.emulator.skin || __('unknown')));157 result.push(' ' + rpad(__('SD Card')) + ' = ' + styleValue(device.emulator.sdcard || __('unknown')));158 result.push(' ' + rpad(__('Google APIs')) + ' = ' + styleValue(device.emulator.googleApis ? __('yes') : __('no')));159 break;160 case 'genymotion':161 name = 'Genymotion Emulator: ' + device.emulator.name;162 result.push(' ' + rpad(__('Genymotion Version')) + ' = ' + styleValue(device.emulator.genymotion || __('unknown')));163 result.push(' ' + rpad(__('Display')) + ' = ' + styleValue(device.emulator.display || __('unknown')));164 result.push(' ' + rpad(__('DPI')) + ' = ' + styleValue(device.emulator.dpi || __('unknown')));165 result.push(' ' + rpad(__('OpenGL Acceleration')) + ' = ' + styleValue(device.emulator.hardwareOpenGL ? __('yes') : __('no')));166 result.push(' ' + rpad(__('Google APIs')) + ' = ' + styleValue(device.emulator.googleApis ? __('yes') : __('no')));167 break;168 }169 return name.cyan + '\n' + result.join('\n');170 } else {171 return name.cyan + '\n' + result.join('\n');172 }173 }).join('\n') + '\n');174 } else {175 logger.log(' ' + __('None').grey + '\n');176 }...
styleValue.js
Source:styleValue.js
1const StyleValue = require('../models/styleValue');2const { errorHandler } = require('../helpers/errorHandler');3exports.styleValueById = (req, res, next, id) => {4 StyleValue.findById(id, (error, styleValue) => {5 if (error || !styleValue) {6 return res.status(404).json({7 error: 'Style value not found',8 });9 }10 req.styleValue = styleValue;11 next();12 });13};14exports.createStyleValue = (req, res, next) => {15 const { name, styleId } = req.body;16 if (!name || !styleId)17 return res.status(400).json({18 error: 'All fields are required',19 });20 const styleValue = new StyleValue({ name, styleId });21 styleValue.save((error, styleValue) => {22 if (error || !styleValue) {23 return res.status(400).json({24 error: errorHandler(error),25 });26 }27 return res.json({28 success: 'Create style value successfully',29 styleValue,30 });31 });32};33exports.updateStyleValue = (req, res) => {34 const { name } = req.body;35 if (!name)36 return res.status(400).json({37 error: 'All fields are required',38 });39 StyleValue.findOneAndUpdate(40 { _id: req.styleValue._id },41 { $set: { name } },42 { new: true },43 )44 .exec()45 .then((styleValue) => {46 if (!styleValue) {47 return res.status(500).json({48 error: 'style value not found',49 });50 }51 return res.json({52 success: 'Update styleValue successfully',53 styleValue,54 });55 })56 .catch((error) => {57 return res.status(400).json({58 error: errorHandler(error),59 });60 });61};62exports.removeStyleValue = (req, res) => {63 StyleValue.findOneAndUpdate(64 { _id: req.styleValue._id },65 { $set: { isDeleted: true } },66 { new: true },67 )68 .exec()69 .then((styleValue) => {70 if (!styleValue) {71 return res.status(500).json({72 error: 'style value not found',73 });74 }75 return res.json({76 success: 'Remove styleValue successfully',77 styleValue,78 });79 })80 .catch((error) => {81 return res.status(400).json({82 error: errorHandler(error),83 });84 });85};86exports.restoreStyleValue = (req, res) => {87 StyleValue.findOneAndUpdate(88 { _id: req.styleValue._id },89 { $set: { isDeleted: false } },90 { new: true },91 )92 .exec()93 .then((styleValue) => {94 if (!styleValue) {95 return res.status(500).json({96 error: 'style value not found',97 });98 }99 return res.json({100 success: 'Restore style Value successfully',101 styleValue,102 });103 })104 .catch((error) => {105 return res.status(400).json({106 error: errorHandler(error),107 });108 });109};110exports.removeAllStyleValue = (req, res) => {111 StyleValue.updateMany(112 { styleId: req.style._id },113 { $set: { isDeleted: true } },114 )115 .exec()116 .then(() => {117 return res.json({118 success: 'Remove style & values successfully',119 style: req.style,120 });121 })122 .catch((error) => {123 return res.status(400).json({124 error: errorHandler(error),125 });126 });127};128exports.restoreAllStyleValue = (req, res) => {129 StyleValue.updateMany(130 { styleId: req.style._id },131 { $set: { isDeleted: false } },132 )133 .exec()134 .then(() => {135 return res.json({136 success: 'Restore style & values successfully',137 style: req.style,138 });139 })140 .catch((error) => {141 return res.status(400).json({142 error: errorHandler(error),143 });144 });145};146exports.listActiveStyleValuesByStyle = (req, res) => {147 StyleValue.find({ styleId: req.style._id, isDeleted: false })148 .populate('styleId')149 .sort({ name: '1', _id: 1 })150 .exec()151 .then((values) => {152 return res.json({153 success: 'Load list values of style successfully',154 styleValues: values,155 style: req.style,156 });157 })158 .catch((error) => {159 return res.status(500).json({160 error: 'Load list values of style failed',161 });162 });163};164exports.listStyleValuesByStyle = (req, res) => {165 StyleValue.find({ styleId: req.style._id })166 .populate('styleId')167 .sort({ name: '1', _id: 1 })168 .exec()169 .then((values) => {170 return res.json({171 success: 'Load list values of style successfully',172 styleValues: values,173 style: req.style,174 });175 })176 .catch((error) => {177 return res.status(500).json({178 error: 'Load list values of style failed',179 });180 });...
plugin.js
Source:plugin.js
1/**2 * plugin.js3 *4 * Released under LGPL License.5 * Copyright (c) 1999-2015 Ephox Corp. All rights reserved6 *7 * License: http://www.tinymce.com/license8 * Contributing: http://www.tinymce.com/contributing9 */10/*global tinymce:true */11tinymce.PluginManager.add('advlist', function(editor) {12 var olMenuItems, ulMenuItems, lastStyles = {};13 function buildMenuItems(listName, styleValues) {14 var items = [];15 tinymce.each(styleValues.split(/[ ,]/), function(styleValue) {16 items.push({17 text: styleValue.replace(/\-/g, ' ').replace(/\b\w/g, function(chr) {18 return chr.toUpperCase();19 }),20 data: styleValue == 'default' ? '' : styleValue21 });22 });23 return items;24 }25 olMenuItems = buildMenuItems('OL', editor.getParam(26 "advlist_number_styles",27 "default,lower-alpha,lower-greek,lower-roman,upper-alpha,upper-roman"28 ));29 ulMenuItems = buildMenuItems('UL', editor.getParam("advlist_bullet_styles", "default,circle,disc,square"));30 function applyListFormat(listName, styleValue) {31 editor.undoManager.transact(function() {32 var list, dom = editor.dom, sel = editor.selection;33 // Check for existing list element34 list = dom.getParent(sel.getNode(), 'ol,ul');35 // Switch/add list type if needed36 if (!list || list.nodeName != listName || styleValue === false) {37 var detail = {38 'list-style-type': styleValue ? styleValue : ''39 };40 editor.execCommand(listName == 'UL' ? 'InsertUnorderedList' : 'InsertOrderedList', false, detail);41 }42 // Set style43 styleValue = styleValue === false ? lastStyles[listName] : styleValue;44 lastStyles[listName] = styleValue;45 list = dom.getParent(sel.getNode(), 'ol,ul');46 if (list) {47 dom.setStyle(list, 'listStyleType', styleValue ? styleValue : null);48 list.removeAttribute('data-mce-style');49 }50 editor.focus();51 });52 }53 function updateSelection(e) {54 var listStyleType = editor.dom.getStyle(editor.dom.getParent(editor.selection.getNode(), 'ol,ul'), 'listStyleType') || '';55 e.control.items().each(function(ctrl) {56 ctrl.active(ctrl.settings.data === listStyleType);57 });58 }59 editor.addButton('numlist', {60 type: 'splitbutton',61 tooltip: 'Numbered list',62 menu: olMenuItems,63 onshow: updateSelection,64 onselect: function(e) {65 applyListFormat('OL', e.control.settings.data);66 },67 onclick: function() {68 applyListFormat('OL', false);69 }70 });71 editor.addButton('bullist', {72 type: 'splitbutton',73 tooltip: 'Bullet list',74 menu: ulMenuItems,75 onshow: updateSelection,76 onselect: function(e) {77 applyListFormat('UL', e.control.settings.data);78 },79 onclick: function() {80 applyListFormat('UL', false);81 }82 });...
style.js
Source:style.js
1ko.bindingHandlers['style'] = {2 'update': function (element, valueAccessor) {3 var value = ko.utils.unwrapObservable(valueAccessor() || {});4 ko.utils.objectForEach(value, function(styleName, styleValue) {5 styleValue = ko.utils.unwrapObservable(styleValue);6 if (styleValue === null || styleValue === undefined || styleValue === false) {7 // Empty string removes the value, whereas null/undefined have no effect8 styleValue = "";9 }10 if (jQueryInstance) {11 jQueryInstance(element)['css'](styleName, styleValue);12 } else if (/^--/.test(styleName)) {13 // Is styleName a custom CSS property?14 element.style.setProperty(styleName, styleValue);15 } else {16 styleName = styleName.replace(/-(\w)/g, function (all, letter) {17 return letter.toUpperCase();18 });19 var previousStyle = element.style[styleName];20 element.style[styleName] = styleValue;21 if (styleValue !== previousStyle && element.style[styleName] == previousStyle && !isNaN(styleValue)) {22 element.style[styleName] = styleValue + "px";23 }24 }25 });26 }...
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const value = await page.evaluateHandle(() => {6 const element = document.querySelector('#docs > div > div:nth-child(3) > div:nth-child(1) > div > div:nth-child(1) > div:nth-child(2) >
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const style = await page.evaluate(() => {6 const element = document.querySelector('input[type="text"]');7 return element.style;8 });9 const value = await style.getPropertyValue('font-size');10 console.log(value);11 await browser.close();12})();
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.click('[placeholder="Search"]');6 await page.fill('[placeholder="Search"]', 'Playwright');7 await page.click('text=Playwright');8 const styleValue = await page.$eval('h1', (el) => el.style.color);9 console.log(styleValue);10 await page.close();11 await browser.close();12})();
Using AI Code Generation
1const { firefox, webkit, chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const selector = '[aria-label="Search"]';6 const elementHandle = await page.$(selector);7 const style = await elementHandle.evaluateHandle((element) => {8 return window.getComputedStyle(element);9 });10 const colorValue = await style.evaluate((style) => style.color);11 console.log(colorValue);12 await browser.close();13})();14- The following code uses the page.evaluate() method to get the value of the CSS property color:15const { firefox, webkit, chromium } = require('playwright');16(async () => {17 const browser = await chromium.launch();18 const page = await browser.newPage();19 const selector = '[aria-label="Search"]';20 const colorValue = await page.evaluate((selector) => {21 const element = document.querySelector(selector);22 return window.getComputedStyle(element).color;23 }, selector);24 console.log(colorValue);25 await browser.close();26})();27- The page.evaluate() method takes a function as an argument. The function takes the selector as an argument and returns the value of
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const element = await page.$('input[type="text"]');6 const value = await element.evaluate(element => element.styleValue('font-size'));7 console.log(value);8 await browser.close();9})();10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch();13 const page = await browser.newPage();14 const element = await page.$('input[type="text"]');15 const value = await element.evaluate(element => element.styleMap('font-size'));16 console.log(value);17 await browser.close();18})();19const { chromium } = require('playwright');20(async () => {21 const browser = await chromium.launch();22 const page = await browser.newPage();23 const element = await page.$('input[type="text"]');24 const value = await element.evaluate(element => element.textContent);25 console.log(value);26 await browser.close();27})();28const { chromium } = require('playwright');29(async () => {30 const browser = await chromium.launch();31 const page = await browser.newPage();32 const element = await page.$('input[type="text"]');33 const value = await element.evaluate(element => element.title);
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!