diff --git a/.eslintrc.js b/.eslintrc.js index eb02c6b..db0f1fe 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,18 +3,18 @@ module.exports = { env: { browser: true, commonjs: true, - es6: true + es6: true, }, extends: 'eslint:recommended', parserOptions: { - sourceType: 'module' + sourceType: 'module', }, globals: { VERSION: true, - ENV: true + ENV: true, }, rules: { quotes: ['error', 'single'], - 'prefer-const': 2 - } + 'prefer-const': 2, + }, } diff --git a/.eustia.js b/.eustia.js index bd619d3..9596b2b 100644 --- a/.eustia.js +++ b/.eustia.js @@ -5,13 +5,13 @@ module.exports = { ignore: 'src/**/stringify.js', output: 'src/lib/util.js', exclude: ['createCfg'], - format: 'es' + format: 'es', }, test: { library: ['node_modules/eustia-module'], files: ['test/*.js', 'test/*.html'], exclude: ['js'], namespace: 'util', - output: 'test/util.js' - } + output: 'test/util.js', + }, } diff --git a/.travis.yml b/.travis.yml index db4dab4..03a8f7d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ addons: sauce_connect: true before_script: - npm install -g codecov + - npm install -g @liriliri/lsla script: - npm run ci after_script: diff --git a/build/webpack.base.js b/build/webpack.base.js index f2d787b..8ecc7f5 100644 --- a/build/webpack.base.js +++ b/build/webpack.base.js @@ -17,33 +17,33 @@ const postcssLoader = { plugins: [ prefixer({ prefix: '_', - ignore: [/luna-object-viewer/, /luna-notification/] + ignore: [/luna-object-viewer/, /luna-notification/], }), autoprefixer, - clean() - ] - } + clean(), + ], + }, } const cssMinifierLoader = { loader: path.resolve(__dirname, './loaders/css-minifier-loader'), - options: {} + options: {}, } module.exports = { entry: './src/index', resolve: { - symlinks: false + symlinks: false, }, devServer: { contentBase: './test', - port: 3000 + port: 3000, }, output: { path: path.resolve(__dirname, '../dist'), publicPath: '/assets/', library: 'eruda', - libraryTarget: 'umd' + libraryTarget: 'umd', }, module: { rules: [ @@ -57,20 +57,25 @@ module.exports = { presets: ['@babel/preset-env'], plugins: [ '@babel/plugin-transform-runtime', - '@babel/plugin-proposal-class-properties' - ] - } + '@babel/plugin-proposal-class-properties', + ], + }, }, - 'eslint-loader' - ] + 'eslint-loader', + ], }, { test: /\.scss$/, - loaders: [cssMinifierLoader, 'css-loader', postcssLoader, 'sass-loader'] + loaders: [ + cssMinifierLoader, + 'css-loader', + postcssLoader, + 'sass-loader', + ], }, { test: /\.css$/, - loaders: [cssMinifierLoader, 'css-loader', postcssLoader] + loaders: [cssMinifierLoader, 'css-loader', postcssLoader], }, // https://github.com/wycats/handlebars.js/issues/1134 { @@ -81,7 +86,7 @@ module.exports = { __dirname, './loaders/handlebars-minifier-loader.js' ), - options: {} + options: {}, }, { loader: nodeModDir + 'handlebars-loader/index.js', @@ -89,24 +94,24 @@ module.exports = { runtime: srcDir + 'lib/handlebars.js', knownHelpers: ['class', 'repeat', 'concat'], precompileOptions: { - knownHelpersOnly: true - } - } + knownHelpersOnly: true, + }, + }, }, { loader: 'html-minifier-loader', options: { - ignoreCustomFragments: [/\{\{\{[^}]+\}\}\}/, /\{\{[^}]+\}\}/] - } - } - ] - } - ] + ignoreCustomFragments: [/\{\{\{[^}]+\}\}\}/, /\{\{[^}]+\}\}/], + }, + }, + ], + }, + ], }, plugins: [ new webpack.BannerPlugin(banner), new webpack.DefinePlugin({ - VERSION: '"' + pkg.version + '"' - }) - ] + VERSION: '"' + pkg.version + '"', + }), + ], } diff --git a/build/webpack.dev.js b/build/webpack.dev.js index 7afbbe1..be8ae03 100644 --- a/build/webpack.dev.js +++ b/build/webpack.dev.js @@ -7,8 +7,8 @@ exports.output.filename = 'eruda.js' exports.devtool = 'source-map' exports.plugins = exports.plugins.concat([ new webpack.DefinePlugin({ - ENV: '"development"' - }) + ENV: '"development"', + }), ]) module.exports = exports diff --git a/build/webpack.release.js b/build/webpack.release.js index fd2839b..987fe32 100644 --- a/build/webpack.release.js +++ b/build/webpack.release.js @@ -7,8 +7,8 @@ exports.output.filename = 'eruda.js' exports.devtool = 'source-map' exports.plugins = exports.plugins.concat([ new webpack.DefinePlugin({ - ENV: '"production"' - }) + ENV: '"production"', + }), ]) module.exports = exports diff --git a/karma.conf.js b/karma.conf.js index 49a89c8..d985f78 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -6,11 +6,11 @@ webpackCfg.module.rules.push({ loader: 'istanbul-instrumenter-loader', enforce: 'post', options: { - esModules: true - } + esModules: true, + }, }) -module.exports = function(config) { +module.exports = function (config) { config.set({ basePath: '', frameworks: ['jquery-1.8.3'], @@ -30,7 +30,7 @@ module.exports = function(config) { 'test/snippets.js', 'test/sources.js', 'test/settings.js', - 'test/eruda.js' + 'test/eruda.js', ], plugins: [ 'karma-jasmine', @@ -38,17 +38,17 @@ module.exports = function(config) { 'karma-chrome-launcher', 'karma-webpack', 'karma-sourcemap-loader', - 'karma-coverage-istanbul-reporter' + 'karma-coverage-istanbul-reporter', ], webpackServer: { - noInfo: true + noInfo: true, }, preprocessors: { - 'src/index.js': ['webpack', 'sourcemap'] + 'src/index.js': ['webpack', 'sourcemap'], }, webpack: webpackCfg, coverageIstanbulReporter: { - reports: ['html', 'lcovonly', 'text', 'text-summary'] + reports: ['html', 'lcovonly', 'text', 'text-summary'], }, reporters: ['progress', 'coverage-istanbul'], port: 9876, @@ -56,6 +56,6 @@ module.exports = function(config) { logLevel: config.LOG_INFO, browsers: ['ChromeHeadless'], singleRun: true, - concurrency: Infinity + concurrency: Infinity, }) } diff --git a/package.json b/package.json index f66a8b9..e39812e 100644 --- a/package.json +++ b/package.json @@ -5,14 +5,14 @@ "main": "eruda.js", "scripts": { "ci": "npm run lint && npm run test && npm run build", - "build": "webpack --config build/webpack.release.js && node build/build && shx cp README.md dist", + "build": "webpack --config build/webpack.release.js && node build/build && lsla shx cp README.md dist", "build:analyser": "webpack --config build/webpack.analyser.js", "dev": "webpack-dev-server --config build/webpack.dev.js --host 0.0.0.0", "test": "karma start", - "format": "lsla prettier *.js eustia/*.js src/**/*.{js,scss,css} script/*.js build/*.js test/*.{js,html} --write", + "format": "lsla prettier *.js src/**/*.{js,scss,css} build/*.js test/*.{js,html} --write", "lint": "eslint src/**/*.js", "lint:fix": "npm run lint -- --fix", - "setup": "shx mkdir -p test/lib && shx cp node_modules/jasmine-core/lib/jasmine-core/{jasmine.css,jasmine.js,jasmine-html.js,boot.js} test/lib && shx cp node_modules/jasmine-jquery/lib/jasmine-jquery.js test/lib && shx cp node_modules/jquery/dist/jquery.js test/lib", + "setup": "lsla shx mkdir -p test/lib && lsla shx cp node_modules/jasmine-core/lib/jasmine-core/{jasmine.css,jasmine.js,jasmine-html.js,boot.js} test/lib && lsla shx cp node_modules/jasmine-jquery/lib/jasmine-jquery.js test/lib && lsla shx cp node_modules/jquery/dist/jquery.js test/lib", "genIcon": "lsla genIcon --input src/style/icon --output src/style/icon.css --name eruda-icon && prettier src/**/*.css --write", "genUtilDoc": "eustia doc src/lib/util.js -f md -o doc/UTIL_API.md -t \"Eruda Util Documentation\"" }, @@ -70,8 +70,6 @@ "postcss-loader": "^3.0.0", "postcss-prefixer": "^2.1.2", "sass-loader": "^8.0.2", - "shx": "^0.3.2", - "webfonts-generator": "^0.4.0", "webpack": "^4.41.6", "webpack-bundle-analyzer": "^3.6.0", "webpack-cli": "^3.3.11", diff --git a/prettier.config.js b/prettier.config.js index cbed5f6..7b56719 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -2,5 +2,4 @@ module.exports = { singleQuote: true, tabWidth: 2, semi: false, - endOfLine: 'lf' } diff --git a/src/Console/Console.js b/src/Console/Console.js index 099b84b..5e8457f 100644 --- a/src/Console/Console.js +++ b/src/Console/Console.js @@ -10,7 +10,7 @@ import { upperFirst, isHidden, lowerCase, - isNull + isNull, } from '../lib/util' import evalCss from '../lib/evalCss' import emitter from '../lib/emitter' @@ -49,7 +49,7 @@ export default class Console extends Tool { const origConsole = (this._origConsole = {}) const winConsole = window.console - CONSOLE_METHOD.forEach(name => { + CONSOLE_METHOD.forEach((name) => { let origin = (origConsole[name] = noop) if (winConsole[name]) { origin = origConsole[name] = winConsole[name].bind(winConsole) @@ -70,7 +70,7 @@ export default class Console extends Tool { if (!this._origConsole) return this CONSOLE_METHOD.forEach( - name => (window.console[name] = this._origConsole[name]) + (name) => (window.console[name] = this._origConsole[name]) ) delete this._origConsole @@ -104,7 +104,7 @@ export default class Console extends Tool { if (isHidden(this._$el.get(0))) return this._logger.renderViewport() } - _handleErr = err => { + _handleErr = (err) => { this._logger.error(err) } _enableJsExecution(enabled) { @@ -121,7 +121,7 @@ export default class Console extends Tool { } } _registerListener() { - this._scaleListener = scale => (this._scale = scale) + this._scaleListener = (scale) => (this._scale = scale) emitter.on(emitter.SCALE, this._scaleListener) } @@ -144,15 +144,15 @@ export default class Console extends Tool { _$inputContainer, _$input, _$inputBtns, - _$searchKeyword: $el.find('.eruda-search-keyword') + _$searchKeyword: $el.find('.eruda-search-keyword'), }) } _initLogger() { const $filter = this._$control.find('.eruda-filter') const logger = (this._logger = new Logger(this._$logs)) - logger.on('filter', filter => - $filter.each(function() { + logger.on('filter', (filter) => + $filter.each(function () { const $this = $(this) const isMatch = $this.data('filter') === filter @@ -165,7 +165,7 @@ export default class Console extends Tool { const methods = ['filter', 'html'].concat(CONSOLE_METHOD) methods.forEach( - name => + (name) => (this[name] = (...args) => { logger[name](...args) this.emit(name, ...args) @@ -186,7 +186,7 @@ export default class Console extends Tool { $control .on('click', '.eruda-clear-console', () => logger.silentClear()) - .on('click', '.eruda-filter', function() { + .on('click', '.eruda-filter', function () { $searchKeyword.text('') logger.filter($(this).data('filter')) }) @@ -208,16 +208,13 @@ export default class Console extends Tool { if (jsInput === '') return logger.input(jsInput) - $input - .val('') - .get(0) - .blur() + $input.val('').get(0).blur() this._hideInput() }) $input.on('focusin', () => this._showInput()) - logger.on('insert', log => { + logger.on('insert', (log) => { const autoShow = log.type === 'error' && config.get('displayIfErr') if (autoShow) container.showTool('console').show() @@ -266,7 +263,7 @@ export default class Console extends Tool { displayGetterVal: true, lazyEvaluation: true, displayIfErr: false, - maxLogNum: 'infinite' + maxLogNum: 'infinite', })) let maxLogNum = cfg.get('maxLogNum') @@ -325,7 +322,7 @@ export default class Console extends Tool { '125', '100', '50', - '10' + '10', ]) .separator() } @@ -348,5 +345,5 @@ const CONSOLE_METHOD = [ 'debug', 'group', 'groupCollapsed', - 'groupEnd' + 'groupEnd', ] diff --git a/src/Console/Log.js b/src/Console/Log.js index 18b3cbb..515d0c2 100644 --- a/src/Console/Log.js +++ b/src/Console/Log.js @@ -33,7 +33,7 @@ import { Emitter, stringifyAll, nextTick, - linkify + linkify, } from '../lib/util' import evalCss from '../lib/evalCss' @@ -48,7 +48,7 @@ export default class Log extends Emitter { group = {}, targetGroup = {}, headers, - ignoreFilter = false + ignoreFilter = false, }) { super() @@ -129,10 +129,7 @@ export default class Log extends Emitter { const $container = $el.find('.eruda-time-container') if (this.time) { - $container - .find('span') - .eq(0) - .text(time) + $container.find('span').eq(0).text(time) this.time = time } @@ -170,7 +167,7 @@ export default class Log extends Emitter { extractObj(cb = noop) { const { args, type } = this - const setSrc = result => { + const setSrc = (result) => { this.src = result cb() } @@ -213,7 +210,7 @@ export default class Log extends Emitter { } const objViewer = new LunaObjectViewer($json.get(0), { unenumerable: Log.showUnenumerable, - accessGetter: Log.showGetterVal + accessGetter: Log.showGetterVal, }) objViewer.set(args) objViewer.on('change', () => this.updateSize(false)) @@ -311,7 +308,7 @@ export default class Log extends Emitter { // Only linkify for simple types if (type !== 'error' && !this.args) { - msg = linkify(msg, url => { + msg = linkify(msg, (url) => { return `${url}` }) } @@ -323,12 +320,12 @@ export default class Log extends Emitter { } } -const getAbstract = wrap(origGetAbstract, function(fn, obj) { +const getAbstract = wrap(origGetAbstract, function (fn, obj) { return ( '' + fn(obj, { getterVal: Log.showGetterVal, - unenumerable: false + unenumerable: false, }) + '' ) @@ -347,7 +344,7 @@ function formatTable(args) { if (!isObj(table)) return formatMsg(args) - each(table, val => { + each(table, (val) => { if (isPrimitive(val)) { columns.push(Value) } else if (isObj(val)) { @@ -356,19 +353,19 @@ function formatTable(args) { }) columns = unique(columns) columns.sort() - if (filter) columns = columns.filter(val => contain(filter, val)) + if (filter) columns = columns.filter((val) => contain(filter, val)) if (columns.length > 20) columns = columns.slice(0, 20) if (isEmpty(columns)) return formatMsg(args) ret += '' columns.forEach( - val => (ret += ``) + (val) => (ret += ``) ) ret += '' each(table, (obj, idx) => { ret += `` - columns.forEach(column => { + columns.forEach((column) => { if (isObj(obj)) { ret += column === Value @@ -402,7 +399,7 @@ function formatErr(err) { let lines = err.stack ? err.stack.split('\n') : [] const msg = `${err.message || lines[0]}
` - lines = lines.filter(val => !regErudaJs.test(val)).map(val => escape(val)) + lines = lines.filter((val) => !regErudaJs.test(val)).map((val) => escape(val)) const stack = `
${lines .slice(1) @@ -412,7 +409,7 @@ function formatErr(err) { msg + stack.replace( regJsUrl, - match => `${match}` + (match) => `${match}` ) ) } @@ -424,7 +421,7 @@ function formatJs(code) { number: `color:${curTheme.numberColor}`, operator: `color:${curTheme.operatorColor}`, comment: `color:${curTheme.commentColor}`, - string: `color:${curTheme.stringColor}` + string: `color:${curTheme.stringColor}`, }) } @@ -455,7 +452,7 @@ function formatMsg(args, { htmlForEl = true } = {}) { return args.join(' ') + '
' } -const formatDir = args => formatMsg(args, { htmlForEl: false }) +const formatDir = (args) => formatMsg(args, { htmlForEl: false }) function substituteStr(args) { const str = escape(args[0]) @@ -521,7 +518,7 @@ function correctStyle(val) { val = lowerCase(val) const rules = val.split(';') const style = {} - each(rules, rule => { + each(rules, (rule) => { if (!contain(rule, ':')) return const [name, val] = rule.split(':') style[trim(name)] = trim(val) @@ -558,17 +555,17 @@ function formatEl(val) { } const tpl = require('./Log.hbs') -const render = data => tpl(data) +const render = (data) => tpl(data) function extractObj(obj, options = {}, cb) { defaults(options, { accessGetter: Log.showGetterVal, unenumerable: Log.showUnenumerable, symbol: Log.showUnenumerable, - timeout: 1000 + timeout: 1000, }) - stringify(obj, options, result => cb(JSON.parse(result))) + stringify(obj, options, (result) => cb(JSON.parse(result))) } function stringify(obj, options, cb) { diff --git a/src/Console/Logger.js b/src/Console/Logger.js index 853d63c..0dfd125 100644 --- a/src/Console/Logger.js +++ b/src/Console/Logger.js @@ -24,7 +24,7 @@ import { xpath, isHidden, lowerCase, - dateFormat + dateFormat, } from '../lib/util' import evalCss from '../lib/evalCss' @@ -75,7 +75,7 @@ export default class Logger extends Emitter { this._minSpeedTolerance = 800 } - this.renderViewport = throttle(options => { + this.renderViewport = throttle((options) => { this._renderViewport(options) }, 16) @@ -97,13 +97,13 @@ export default class Logger extends Emitter { clear: () => { this.clear() }, - dir: value => { + dir: (value) => { this.dir(value) }, table: (data, columns) => { this.table(data, columns) }, - keys + keys, } this._bindEvent() @@ -221,7 +221,7 @@ export default class Logger extends Emitter { return this.insert('log', [ '%cConsole was cleared', - 'color:#808080;font-style:italic;' + 'color:#808080;font-style:italic;', ]) } silentClear() { @@ -258,14 +258,14 @@ export default class Logger extends Emitter { return this.insert({ type: 'group', args, - ignoreFilter: true + ignoreFilter: true, }) } groupCollapsed(...args) { return this.insert({ type: 'groupCollapsed', args, - ignoreFilter: true + ignoreFilter: true, }) } groupEnd() { @@ -275,7 +275,7 @@ export default class Logger extends Emitter { this.insert({ type: 'input', args: [jsCode], - ignoreFilter: true + ignoreFilter: true, }) try { @@ -284,7 +284,7 @@ export default class Logger extends Emitter { this.insert({ type: 'error', ignoreFilter: true, - args: [e] + args: [e], }) } @@ -294,7 +294,7 @@ export default class Logger extends Emitter { return this.insert({ type: 'output', args: [val], - ignoreFilter: true + ignoreFilter: true, }) } html(...args) { @@ -319,7 +319,7 @@ export default class Logger extends Emitter { if (this._displayHeader) { headers = { time: getCurTime(), - from: getFrom() + from: getFrom(), } } @@ -350,7 +350,7 @@ export default class Logger extends Emitter { } extend(options, { id: ++id, - headers + headers, }) if (options.type === 'group' || options.type === 'groupCollapsed') { @@ -358,7 +358,7 @@ export default class Logger extends Emitter { id: uniqId('group'), collapsed: false, parent: groupStack.peek(), - indentLevel: groupStack.size + 1 + indentLevel: groupStack.size + 1, } if (options.type === 'groupCollapsed') group.collapsed = true options.targetGroup = group @@ -613,22 +613,16 @@ export default class Logger extends Emitter { const $el = this._$el $el - .on('click', '.eruda-log-container', function() { + .on('click', '.eruda-log-container', function () { this.log.click(self) }) - .on('click', '.eruda-icon-caret-down', function() { - const $el = $(this) - .parent() - .parent() - .parent() + .on('click', '.eruda-icon-caret-down', function () { + const $el = $(this).parent().parent().parent() self._collapseGroup($el.get(0).log) }) - .on('click', '.eruda-icon-caret-right', function() { - const $el = $(this) - .parent() - .parent() - .parent() + .on('click', '.eruda-icon-caret-right', function () { + const $el = $(this).parent().parent().parent() self._openGroup($el.get(0).log) }) @@ -687,7 +681,7 @@ export default class Logger extends Emitter { this.renderViewport({ topTolerance: topTolerance * 2, - bottomTolerance: bottomTolerance * 2 + bottomTolerance: bottomTolerance * 2, }) }) } diff --git a/src/DevTools/DevTools.js b/src/DevTools/DevTools.js index ddf2023..cb25cff 100644 --- a/src/DevTools/DevTools.js +++ b/src/DevTools/DevTools.js @@ -13,7 +13,7 @@ import { $, throttle, isDarkMode, - extend + extend, } from '../lib/util' import evalCss from '../lib/evalCss' import LunaNotification from 'luna-notification' @@ -26,7 +26,7 @@ export default class DevTools extends Emitter { { transparency: 1, displaySize: 80, - theme: isDarkMode() ? 'Dark' : 'Light' + theme: isDarkMode() ? 'Dark' : 'Light', }, defaults ) @@ -114,7 +114,7 @@ export default class DevTools extends Emitter { return this } removeAll() { - each(this._tools, tool => this.remove(tool.name)) + each(this._tools, (tool) => this.remove(tool.name)) return this } @@ -134,7 +134,7 @@ export default class DevTools extends Emitter { let lastTool = {} - each(tools, tool => { + each(tools, (tool) => { if (tool.active) { lastTool = tool tool.active = false @@ -175,12 +175,12 @@ export default class DevTools extends Emitter { .range(cfg, 'transparency', 'Transparency', { min: 0.2, max: 1, - step: 0.01 + step: 0.01, }) .range(cfg, 'displaySize', 'Display Size', { min: 40, max: 100, - step: 1 + step: 1, }) .separator() } @@ -214,19 +214,19 @@ export default class DevTools extends Emitter { } _initNavBar() { this._navBar = new NavBar(this._$el.find('.eruda-nav-bar-container')) - this._navBar.on('showTool', name => this.showTool(name)) + this._navBar.on('showTool', (name) => this.showTool(name)) } _initNotification() { this._notification = new LunaNotification(this._$el.get(0), { position: { x: 'center', - y: 'top' - } + y: 'top', + }, }) } _bindEvent() { const $navBar = this._$el.find('.eruda-nav-bar') - const startListener = e => { + const startListener = (e) => { e = e.origEvent this._resizeTimer = setTimeout(() => { e.preventDefault() @@ -238,10 +238,10 @@ export default class DevTools extends Emitter { }, 1000) } const setDisplaySize = throttle( - size => this.config.set('displaySize', size), + (size) => this.config.set('displaySize', size), 50 ) - const moveListener = e => { + const moveListener = (e) => { if (!this._isResizing) { return clearTimeout(this._resizeTimer) } @@ -265,14 +265,14 @@ export default class DevTools extends Emitter { this._isResizing = false $navBar.css('filter', 'brightness(1)') } - const getClientY = e => { + const getClientY = (e) => { if (e.clientY) return e.clientY if (e.touches) return e.touches[0].clientY return 0 } - $navBar.on('contextmenu', e => e.preventDefault()) + $navBar.on('contextmenu', (e) => e.preventDefault()) const $root = $(document.documentElement) if (isMobile()) { $navBar.on('touchstart', startListener).on('touchmove', moveListener) diff --git a/src/DevTools/NavBar.js b/src/DevTools/NavBar.js index dcd2914..6fc1500 100644 --- a/src/DevTools/NavBar.js +++ b/src/DevTools/NavBar.js @@ -28,7 +28,7 @@ export default class NavBar extends Emitter { } remove(name) { this._len-- - this._$el.find('.eruda-nav-bar-item').each(function() { + this._$el.find('.eruda-nav-bar-item').each(function () { const $this = $(this) if ($this.text().toLowerCase() === name.toLowerCase()) $this.remove() }) @@ -37,7 +37,7 @@ export default class NavBar extends Emitter { activateTool(name) { const self = this - this._$el.find('.eruda-nav-bar-item').each(function() { + this._$el.find('.eruda-nav-bar-item').each(function () { const $this = $(this) if ($this.text() === name) { @@ -84,14 +84,14 @@ export default class NavBar extends Emitter { $bottomBar.css({ width: li.offsetWidth, - left: li.offsetLeft - $el.get(0).scrollLeft + left: li.offsetLeft - $el.get(0).scrollLeft, }) } _bindEvent() { const self = this this._$el - .on('click', '.eruda-nav-bar-item', function() { + .on('click', '.eruda-nav-bar-item', function () { self.emit('showTool', $(this).text()) }) .on('scroll', () => this.resetBottomBar()) diff --git a/src/DevTools/Tool.js b/src/DevTools/Tool.js index d37b35c..40683e6 100644 --- a/src/DevTools/Tool.js +++ b/src/DevTools/Tool.js @@ -16,5 +16,5 @@ export default Class({ }, destroy() { this._$el.remove() - } + }, }) diff --git a/src/Elements/CssStore.js b/src/Elements/CssStore.js index 5133eae..5f801c4 100644 --- a/src/Elements/CssStore.js +++ b/src/Elements/CssStore.js @@ -16,7 +16,7 @@ function formatStyle(style) { const elProto = Element.prototype -let matchesSel = function() { +let matchesSel = function () { return false } @@ -38,7 +38,7 @@ export default class CssStore { getMatchedCSSRules() { const ret = [] - each(document.styleSheets, styleSheet => { + each(document.styleSheets, (styleSheet) => { try { // Started with version 64, Chrome does not allow cross origin script to access this property. if (!styleSheet.cssRules) return @@ -46,7 +46,7 @@ export default class CssStore { return } - each(styleSheet.cssRules, cssRule => { + each(styleSheet.cssRules, (cssRule) => { let matchesEl = false // Mobile safari will throw DOM Exception 12 error, need to try catch it. @@ -59,7 +59,7 @@ export default class CssStore { ret.push({ selectorText: cssRule.selectorText, - style: formatStyle(cssRule.style) + style: formatStyle(cssRule.style), }) }) }) @@ -90,7 +90,7 @@ function sortStyleKeys(style) { if (lenA < lenB) return -1 return 0 - } + }, }) } diff --git a/src/Elements/Elements.js b/src/Elements/Elements.js index c5dd1f7..32d404a 100644 --- a/src/Elements/Elements.js +++ b/src/Elements/Elements.js @@ -27,7 +27,7 @@ import { isNull, trim, lowerCase, - pick + pick, } from '../lib/util' import { isErudaEl } from '../lib/extraUtil' import evalCss from '../lib/evalCss' @@ -97,12 +97,12 @@ export default class Elements extends Tool { const origAddEvent = (this._origAddEvent = winEventProto.addEventListener) const origRmEvent = (this._origRmEvent = winEventProto.removeEventListener) - winEventProto.addEventListener = function(type, listener, useCapture) { + winEventProto.addEventListener = function (type, listener, useCapture) { addEvent(this, type, listener, useCapture) origAddEvent.apply(this, arguments) } - winEventProto.removeEventListener = function(type, listener, useCapture) { + winEventProto.removeEventListener = function (type, listener, useCapture) { rmEvent(this, type, listener, useCapture) origRmEvent.apply(this, arguments) } @@ -144,7 +144,7 @@ export default class Elements extends Tool { const select = this._select this._$el - .on('click', '.eruda-child', function() { + .on('click', '.eruda-child', function () { const idx = $(this).data('idx') const curEl = self._curEl const el = curEl.childNodes[idx] @@ -176,7 +176,7 @@ export default class Elements extends Tool { !isElExist(el) ? self._render() : self.set(el) }) - .on('click', '.eruda-listener-content', function() { + .on('click', '.eruda-listener-content', function () { const text = $(this).text() const sources = container.get('sources') @@ -193,7 +193,7 @@ export default class Elements extends Tool { container.showTool('sources') } }) - .on('click', '.eruda-parent', function() { + .on('click', '.eruda-parent', function () { let idx = $(this).data('idx') const curEl = self._curEl let el = curEl.parentNode @@ -224,7 +224,7 @@ export default class Elements extends Tool { .on('click', '.eruda-select', () => this._toggleSelect()) .on('click', '.eruda-reset', () => this.set(this._htmlEl)) - select.on('select', target => this.set(target)) + select.on('select', (target) => this.set(target)) } _toggleAllComputedStyle() { this._rmDefComputedStyle = !this._rmDefComputedStyle @@ -235,7 +235,7 @@ export default class Elements extends Tool { this._observer.observe(this._htmlEl, { attributes: true, childList: true, - subtree: true + subtree: true, }) } _disableObserver() { @@ -301,14 +301,14 @@ export default class Elements extends Tool { function getBoxModelValue(type) { let keys = ['top', 'left', 'right', 'bottom'] - if (type !== 'position') keys = map(keys, key => `${type}-${key}`) - if (type === 'border') keys = map(keys, key => `${key}-width`) + if (type !== 'position') keys = map(keys, (key) => `${type}-${key}`) + if (type === 'border') keys = map(keys, (key) => `${key}-width`) return { top: boxModelValue(computedStyle[keys[0]], type), left: boxModelValue(computedStyle[keys[1]], type), right: boxModelValue(computedStyle[keys[2]], type), - bottom: boxModelValue(computedStyle[keys[3]], type) + bottom: boxModelValue(computedStyle[keys[3]], type), } } @@ -318,8 +318,8 @@ export default class Elements extends Tool { padding: getBoxModelValue('padding'), content: { width: boxModelValue(computedStyle['width']), - height: boxModelValue(computedStyle['height']) - } + height: boxModelValue(computedStyle['height']), + }, } if (computedStyle['position'] !== 'static') { @@ -329,7 +329,7 @@ export default class Elements extends Tool { const styles = cssStore.getMatchedCSSRules() styles.unshift(getInlineStyle(el.style)) - styles.forEach(style => processStyleRules(style.style)) + styles.forEach((style) => processStyleRules(style.style)) ret.styles = styles if (this._rmDefComputedStyle) { @@ -373,8 +373,8 @@ export default class Elements extends Tool { } } _initObserver() { - this._observer = new MutationObserver(mutations => { - each(mutations, mutation => this._handleMutation(mutation)) + this._observer = new MutationObserver((mutations) => { + each(mutations, (mutation) => this._handleMutation(mutation)) }) } _handleMutation(mutation) { @@ -418,7 +418,7 @@ export default class Elements extends Tool { _initCfg() { const cfg = (this.config = Settings.createCfg('elements', { overrideEventTarget: true, - observeElement: true + observeElement: true, })) if (cfg.get('overrideEventTarget')) this.overrideEventTarget() @@ -466,7 +466,7 @@ function processStyleRule(val) { .replace(regCssUrl, (match, url) => `url("${wrapLink(url)}")`) } -const isElExist = val => isEl(val) && val.parentNode +const isElExist = (val) => isEl(val) && val.parentNode function formatElName(data, { noAttr = false } = {}) { const { id, className, attributes } = data @@ -477,7 +477,7 @@ function formatElName(data, { noAttr = false } = {}) { if (isStr(className)) { let classes = '' - each(className.split(/\s+/g), val => { + each(className.split(/\s+/g), (val) => { if (val.trim() === '') return classes += `.${val}` }) @@ -485,7 +485,7 @@ function formatElName(data, { noAttr = false } = {}) { } if (!noAttr) { - each(attributes, attr => { + each(attributes, (attr) => { const name = attr.name if (name === 'id' || name === 'class' || name === 'style') return ret += ` ${name}="${attr.value}"` @@ -495,8 +495,8 @@ function formatElName(data, { noAttr = false } = {}) { return ret } -const formatAttr = attributes => - map(attributes, attr => { +const formatAttr = (attributes) => + map(attributes, (attr) => { let { value } = attr const { name } = attr value = escape(value) @@ -522,7 +522,7 @@ function formatChildNodes(nodes) { ret.push({ text: val, isCmt: nodeType === 8, - idx: i + idx: i, }) continue } @@ -537,7 +537,7 @@ function formatChildNodes(nodes) { ret.push({ text: formatElName(child), isEl: true, - idx: i + idx: i, }) } } @@ -553,7 +553,7 @@ function getParents(el) { while (parent && parent.nodeType === 1) { ret.push({ text: formatElName(parent, { noAttr: true }), - idx: i++ + idx: i++, }) parent = parent.parentNode @@ -565,7 +565,7 @@ function getParents(el) { function getInlineStyle(style) { const ret = { selectorText: 'element.style', - style: {} + style: {}, } for (let i = 0, len = style.length; i < len; i++) { @@ -581,7 +581,7 @@ function rmDefComputedStyle(computedStyle, styles) { const ret = {} let keepStyles = ['display', 'width', 'height'] - each(styles, style => { + each(styles, (style) => { keepStyles = keepStyles.concat(keys(style.style)) }) keepStyles = unique(keepStyles) @@ -597,7 +597,8 @@ function rmDefComputedStyle(computedStyle, styles) { const NO_STYLE_TAG = ['script', 'style', 'meta', 'title', 'link', 'head'] -const needNoStyle = tagName => NO_STYLE_TAG.indexOf(tagName.toLowerCase()) > -1 +const needNoStyle = (tagName) => + NO_STYLE_TAG.indexOf(tagName.toLowerCase()) > -1 function addEvent(el, type, listener, useCapture = false) { if (!isEl(el) || !isFn(listener) || !isBool(useCapture)) return @@ -608,7 +609,7 @@ function addEvent(el, type, listener, useCapture = false) { events[type].push({ listener: listener, listenerStr: listener.toString(), - useCapture: useCapture + useCapture: useCapture, }) } @@ -636,7 +637,7 @@ const getWinEventProto = () => { return safeGet(window, 'EventTarget.prototype') || window.Node.prototype } -const wrapLink = link => `${link}` +const wrapLink = (link) => `${link}` function boxModelValue(val, type) { if (isNum(val)) return val diff --git a/src/Elements/Highlight.js b/src/Elements/Highlight.js index 4c05265..8f497f1 100644 --- a/src/Elements/Highlight.js +++ b/src/Elements/Highlight.js @@ -39,7 +39,7 @@ export default class Highlight { this._$el.css('visibility', 'visible') } - const getNumStyle = name => pxToNum(computedStyle.getPropertyValue(name)) + const getNumStyle = (name) => pxToNum(computedStyle.getPropertyValue(name)) const ml = getNumStyle('margin-left') const mr = getNumStyle('margin-right') @@ -72,7 +72,7 @@ export default class Highlight { borderTop: `${mt}px solid ${marginColor}`, borderLeft: `${ml}px solid ${marginColor}`, borderRight: `${mr}px solid ${marginColor}`, - borderBottom: `${mb}px solid ${marginColor}` + borderBottom: `${mb}px solid ${marginColor}`, }) this._$border.css({ @@ -83,7 +83,7 @@ export default class Highlight { borderTop: `${bt}px solid ${borderColor}`, borderLeft: `${bl}px solid ${borderColor}`, borderRight: `${br}px solid ${borderColor}`, - borderBottom: `${bb}px solid ${borderColor}` + borderBottom: `${bb}px solid ${borderColor}`, }) this._$padding.css({ @@ -94,7 +94,7 @@ export default class Highlight { borderTop: `${pt}px solid ${paddingColor}`, borderLeft: `${pl}px solid ${paddingColor}`, borderRight: `${pr}px solid ${paddingColor}`, - borderBottom: `${pb}px solid ${paddingColor}` + borderBottom: `${pb}px solid ${paddingColor}`, }) this._$content.css({ @@ -102,13 +102,13 @@ export default class Highlight { top: bt + pt, width: pw - pl - pr, height: ph - pt - pb, - background: contentColor + background: contentColor, }) this._$size .css({ top: -mt - (top - mt < 25 ? 0 : 25), - left: -ml + left: -ml, }) .html(`${formatElName(this._target)} | ${width} × ${height}`) } @@ -143,7 +143,7 @@ function formatElName(el) { let classes = '' if (isStr(className)) { - each(className.split(/\s+/g), val => { + each(className.split(/\s+/g), (val) => { if (trim(val) === '') return classes += `.${val}` diff --git a/src/Elements/Select.js b/src/Elements/Select.js index b0c06ef..bf3da91 100644 --- a/src/Elements/Select.js +++ b/src/Elements/Select.js @@ -7,21 +7,21 @@ export default class Select extends Emitter { const self = this - this._startListener = function(e) { + this._startListener = function (e) { if (isErudaEl(e.target)) return - self._timer = setTimeout(function() { + self._timer = setTimeout(function () { self.emit('select', e.target) }, 200) return false } - this._moveListener = function() { + this._moveListener = function () { clearTimeout(self._timer) } - this._clickListener = function(e) { + this._clickListener = function (e) { if (isErudaEl(e.target)) return e.preventDefault() diff --git a/src/EntryBtn/EntryBtn.js b/src/EntryBtn/EntryBtn.js index 95bab0a..268da34 100644 --- a/src/EntryBtn/EntryBtn.js +++ b/src/EntryBtn/EntryBtn.js @@ -29,7 +29,7 @@ export default class EntryBtn extends Emitter { this._$el.css({ left: pos.x, - top: pos.y + top: pos.y, }) this.config.set('pos', pos) @@ -91,7 +91,7 @@ export default class EntryBtn extends Emitter { if (cfg.get('rememberPos')) { cfg.set('pos', { x: pxToNum(this._$el.css('left')), - y: pxToNum(this._$el.css('top')) + y: pxToNum(this._$el.css('top')), }) } @@ -103,13 +103,13 @@ export default class EntryBtn extends Emitter { } _makeDraggable() { this._draggabilly = new Draggabilly(this._$el.get(0), { - containment: true + containment: true, }) } initCfg(settings) { const cfg = (this.config = Settings.createCfg('entry-button', { rememberPos: true, - pos: this._getDefPos() + pos: this._getDefPos(), })) settings @@ -123,7 +123,7 @@ export default class EntryBtn extends Emitter { return { x: window.innerWidth - minWidth, - y: window.innerHeight - minWidth + y: window.innerHeight - minWidth, } } } diff --git a/src/Info/Info.js b/src/Info/Info.js index 64ad953..603ab0d 100644 --- a/src/Info/Info.js +++ b/src/Info/Info.js @@ -27,7 +27,7 @@ export default class Info extends Tool { const infos = this._infos let isUpdate = false - each(infos, info => { + each(infos, (info) => { if (name !== info.name) return info.val = val @@ -49,7 +49,7 @@ export default class Info extends Tool { let result - each(infos, info => { + each(infos, (info) => { if (name === info.name) result = info.val }) @@ -74,7 +74,7 @@ export default class Info extends Tool { return this } _addDefInfo() { - each(defInfo, info => this.add(info.name, info.val)) + each(defInfo, (info) => this.add(info.name, info.val)) } _render() { const infos = [] diff --git a/src/Info/defInfo.js b/src/Info/defInfo.js index c259ab6..7b427f7 100644 --- a/src/Info/defInfo.js +++ b/src/Info/defInfo.js @@ -7,11 +7,11 @@ export default [ name: 'Location', val() { return escape(location.href) - } + }, }, { name: 'User Agent', - val: navigator.userAgent + val: navigator.userAgent, }, { name: 'Device', @@ -20,25 +20,25 @@ export default [ `
`, ``, ``, - '
(index)${val === Value ? 'Value' : toStr(val)}${val === Value ? 'Value' : toStr(val)}
${idx}
screen${screen.width} * ${screen.height}
viewport${window.innerWidth} * ${window.innerHeight}
pixel ratio${window.devicePixelRatio}
' - ].join('') + '', + ].join(''), }, { name: 'System', val: [ '', ``, - ``, - '
os${detectOs()}
browser${browser.name + - ' ' + - browser.version}
' - ].join('') + `browser${ + browser.name + ' ' + browser.version + }`, + '', + ].join(''), }, { name: 'About', val: 'Eruda v' + VERSION + - '' - } + '', + }, ] diff --git a/src/Network/Network.js b/src/Network/Network.js index 08ad922..2bac51e 100644 --- a/src/Network/Network.js +++ b/src/Network/Network.js @@ -36,12 +36,12 @@ export default class Network extends Tool { } requests() { const ret = [] - each(this._requests, request => { + each(this._requests, (request) => { ret.push(request) }) return ret } - _reqWillBeSent = params => { + _reqWillBeSent = (params) => { this._requests[params.requestId] = { name: getFileName(params.request.url), url: params.request.url, @@ -56,10 +56,10 @@ export default class Network extends Tool { resTxt: '', done: false, reqHeaders: params.request.headers || {}, - resHeaders: {} + resHeaders: {}, } } - _resReceivedExtraInfo = params => { + _resReceivedExtraInfo = (params) => { const target = this._requests[params.requestId] if (!target) { return @@ -76,7 +76,7 @@ export default class Network extends Tool { target.type = type target.subType = subType } - _resReceived = params => { + _resReceived = (params) => { const target = this._requests[params.requestId] if (!target) { return @@ -95,7 +95,7 @@ export default class Network extends Tool { this._render() } - _loadingFinished = params => { + _loadingFinished = (params) => { const target = this._requests[params.requestId] if (!target) { return @@ -108,7 +108,7 @@ export default class Network extends Tool { target.size = params.encodedDataLength target.done = true target.resTxt = chobitsu.domain('Network').getResponseBody({ - requestId: params.requestId + requestId: params.requestId, }).body this._render() @@ -120,7 +120,7 @@ export default class Network extends Tool { const self = this $el - .on('click', '.eruda-request', function() { + .on('click', '.eruda-request', function () { const id = $(this).data('id') const data = self._requests[id] @@ -221,6 +221,6 @@ function getType(contentType) { return { type: type[0], - subType: last(type) + subType: last(type), } } diff --git a/src/Resources/Resources.js b/src/Resources/Resources.js index 91ae38d..1a37ddf 100644 --- a/src/Resources/Resources.js +++ b/src/Resources/Resources.js @@ -18,7 +18,7 @@ import { lowerCase, contain, filter, - map + map, } from '../lib/util' import { isErudaEl } from '../lib/extraUtil' import evalCss from '../lib/evalCss' @@ -75,7 +75,7 @@ export default class Resources extends Tool { refreshScript() { let scriptData = [] - $('script').each(function() { + $('script').each(function () { const src = this.src if (src !== '') scriptData.push(src) @@ -90,7 +90,7 @@ export default class Resources extends Tool { refreshStylesheet() { let stylesheetData = [] - $('link').each(function() { + $('link').each(function () { if (this.rel !== 'stylesheet') return stylesheetData.push(this.href) @@ -105,7 +105,7 @@ export default class Resources extends Tool { refreshIframe() { let iframeData = [] - $('iframe').each(function() { + $('iframe').each(function () { const $this = $(this) const src = $this.attr('src') @@ -148,7 +148,7 @@ export default class Resources extends Tool { storeData.push({ key: key, - val: sliceStr(val, 200) + val: sliceStr(val, 200), }) }) @@ -158,7 +158,7 @@ export default class Resources extends Tool { const { cookies } = chobitsu.domain('Network').getCookies() const cookieData = map(cookies, ({ name, value }) => ({ key: name, - val: value + val: value, })) this._cookieData = cookieData @@ -172,13 +172,13 @@ export default class Resources extends Tool { window.webkitPerformance || window.performance) if (performance && performance.getEntries) { const entries = this._performance.getEntries() - entries.forEach(entry => { + entries.forEach((entry) => { if (entry.initiatorType === 'img' || isImg(entry.name)) { imageData.push(entry.name) } }) } else { - $('img').each(function() { + $('img').each(function () { const $this = $(this) const src = $this.attr('src') @@ -239,7 +239,7 @@ export default class Resources extends Tool { container.notify('Refreshed') this.refreshImage()._render() }) - .on('click', '.eruda-search', function() { + .on('click', '.eruda-search', function () { const $this = $(this) const type = $this.data('type') let filter = prompt('Filter') @@ -258,7 +258,7 @@ export default class Resources extends Tool { } self._render() }) - .on('click', '.eruda-delete-storage', function() { + .on('click', '.eruda-delete-storage', function () { const $this = $(this) const key = $this.data('key') const type = $this.data('type') @@ -271,20 +271,20 @@ export default class Resources extends Tool { self.refreshSessionStorage()._render() } }) - .on('click', '.eruda-delete-cookie', function() { + .on('click', '.eruda-delete-cookie', function () { const key = $(this).data('key') chobitsu.domain('Network').deleteCookies({ name: key }) self.refreshCookie()._render() }) - .on('click', '.eruda-clear-storage', function() { + .on('click', '.eruda-clear-storage', function () { const type = $(this).data('type') if (type === 'local') { - each(self._localStoreData, val => localStorage.removeItem(val.key)) + each(self._localStoreData, (val) => localStorage.removeItem(val.key)) self.refreshLocalStorage()._render() } else { - each(self._sessionStoreData, val => + each(self._sessionStoreData, (val) => sessionStorage.removeItem(val.key) ) self.refreshSessionStorage()._render() @@ -292,11 +292,11 @@ export default class Resources extends Tool { }) .on('click', '.eruda-clear-cookie', () => { chobitsu.domain('Storage').clearDataForOrigin({ - storageTypes: 'cookies' + storageTypes: 'cookies', }) this.refreshCookie()._render() }) - .on('click', '.eruda-storage-val', function() { + .on('click', '.eruda-storage-val', function () { const $this = $(this) const key = $this.data('key') const type = $this.data('type') @@ -312,7 +312,7 @@ export default class Resources extends Tool { showSources('raw', val) } }) - .on('click', '.eruda-img-link', function() { + .on('click', '.eruda-img-link', function () { const src = $(this).attr('src') showSources('img', src) @@ -335,7 +335,7 @@ export default class Resources extends Tool { } function linkFactory(type) { - return function(e) { + return function (e) { if (!container.get('sources')) return e.preventDefault() @@ -346,10 +346,10 @@ export default class Resources extends Tool { } else { ajax({ url, - success: data => { + success: (data) => { showSources(type, data) }, - dataType: 'raw' + dataType: 'raw', }) } } @@ -370,7 +370,7 @@ export default class Resources extends Tool { _initCfg() { const cfg = (this.config = Settings.createCfg('resources', { hideErudaSetting: true, - observeElement: true + observeElement: true, })) if (cfg.get('hideErudaSetting')) this._hideErudaSetting = true @@ -437,7 +437,7 @@ export default class Resources extends Tool { stylesheetState: getState('stylesheet', stylesheetData.length), iframeData: this._iframeData, imageData, - imageState: getState('image', imageData.length) + imageState: getState('image', imageData.length), }) ) } @@ -447,9 +447,9 @@ export default class Resources extends Tool { this._$el.html(html) } _initObserver() { - this._observer = new MutationObserver(mutations => { + this._observer = new MutationObserver((mutations) => { let needToRender = false - each(mutations, mutation => { + each(mutations, (mutation) => { if (this._handleMutation(mutation)) needToRender = true }) if (needToRender) this._render() @@ -458,7 +458,7 @@ export default class Resources extends Tool { _handleMutation(mutation) { if (isErudaEl(mutation.target)) return - const checkEl = el => { + const checkEl = (el) => { const tagName = getLowerCaseTagName(el) switch (tagName) { case 'script': @@ -493,7 +493,7 @@ export default class Resources extends Tool { this._observer.observe(document.documentElement, { attributes: true, childList: true, - subtree: true + subtree: true, }) } _disableObserver() { @@ -542,4 +542,4 @@ const sliceStr = (str, len) => const regImg = /\.(jpeg|jpg|gif|png)$/ -const isImg = url => regImg.test(url) +const isImg = (url) => regImg.test(url) diff --git a/src/Settings/Settings.js b/src/Settings/Settings.js index 50196cf..47f7e83 100644 --- a/src/Settings/Settings.js +++ b/src/Settings/Settings.js @@ -22,12 +22,12 @@ export default class Settings extends Tool { } remove(config, key) { if (isStr(config)) { - this._$el.find('.eruda-text').each(function() { + this._$el.find('.eruda-text').each(function () { const $this = $(this) if ($this.text() === config) $this.remove() }) } else { - this._settings = filter(this._settings, setting => { + this._settings = filter(this._settings, (setting) => { if (setting.config === config && setting.key === key) { this._$el.find('#' + setting.id).remove() return false @@ -60,7 +60,7 @@ export default class Settings extends Tool { desc, key, id, - val: config.get(key) + val: config.get(key), }) ) @@ -81,7 +81,7 @@ export default class Settings extends Tool { desc, colors, id, - val: config.get(key) + val: config.get(key), }) ) @@ -97,7 +97,7 @@ export default class Settings extends Tool { desc, selections, id, - val: config.get(key) + val: config.get(key), }) ) @@ -118,7 +118,7 @@ export default class Settings extends Tool { step, val, progress: progress(val, min, max), - id + id, }) ) @@ -157,7 +157,7 @@ export default class Settings extends Tool { _getSetting(id) { let ret - each(this._settings, setting => { + each(this._settings, (setting) => { if (setting.id === id) ret = setting }) @@ -167,7 +167,7 @@ export default class Settings extends Tool { const self = this this._$el - .on('click', '.eruda-checkbox', function() { + .on('click', '.eruda-checkbox', function () { const $input = $(this).find('input') const id = $input.data('id') const val = $input.get(0).checked @@ -175,16 +175,14 @@ export default class Settings extends Tool { const setting = self._getSetting(id) setting.config.set(setting.key, val) }) - .on('click', '.eruda-select .eruda-head', function() { - const $el = $(this) - .parent() - .find('ul') + .on('click', '.eruda-select .eruda-head', function () { + const $el = $(this).parent().find('ul') const isOpen = $el.hasClass('eruda-open') self._closeAll() isOpen ? $el.rmClass('eruda-open') : $el.addClass('eruda-open') }) - .on('click', '.eruda-select li', function() { + .on('click', '.eruda-select li', function () { const $this = $(this) const $ul = $this.parent() const val = $this.text() @@ -192,23 +190,18 @@ export default class Settings extends Tool { const setting = self._getSetting(id) $ul.rmClass('eruda-open') - $ul - .parent() - .find('.eruda-head span') - .text(val) + $ul.parent().find('.eruda-head span').text(val) setting.config.set(setting.key, val) }) - .on('click', '.eruda-range .eruda-head', function() { - const $el = $(this) - .parent() - .find('.eruda-input-container') + .on('click', '.eruda-range .eruda-head', function () { + const $el = $(this).parent().find('.eruda-input-container') const isOpen = $el.hasClass('eruda-open') self._closeAll() isOpen ? $el.rmClass('eruda-open') : $el.addClass('eruda-open') }) - .on('change', '.eruda-range input', function() { + .on('change', '.eruda-range input', function () { const $this = $(this) const $container = $this.parent() const id = $container.data('id') @@ -217,7 +210,7 @@ export default class Settings extends Tool { setting.config.set(setting.key, val) }) - .on('input', '.eruda-range input', function() { + .on('input', '.eruda-range input', function () { const $this = $(this) const $container = $this.parent() const id = $container.data('id') @@ -225,24 +218,19 @@ export default class Settings extends Tool { const setting = self._getSetting(id) const { min, max } = setting - $container - .parent() - .find('.eruda-head span') - .text(val) + $container.parent().find('.eruda-head span').text(val) $container .find('.eruda-range-track-progress') .css('width', progress(val, min, max) + '%') }) - .on('click', '.eruda-color .eruda-head', function() { - const $el = $(this) - .parent() - .find('ul') + .on('click', '.eruda-color .eruda-head', function () { + const $el = $(this).parent().find('ul') const isOpen = $el.hasClass('eruda-open') self._closeAll() isOpen ? $el.rmClass('eruda-open') : $el.addClass('eruda-open') }) - .on('click', '.eruda-color li', function() { + .on('click', '.eruda-color li', function () { const $this = $(this) const $ul = $this.parent() const val = $this.css('background-color') @@ -250,10 +238,7 @@ export default class Settings extends Tool { const setting = self._getSetting(id) $ul.rmClass('eruda-open') - $ul - .parent() - .find('.eruda-head span') - .css('background-color', val) + $ul.parent().find('.eruda-head span').css('background-color', val) setting.config.set(setting.key, val) }) diff --git a/src/Snippets/Snippets.js b/src/Snippets/Snippets.js index c138ed5..90f34a5 100644 --- a/src/Snippets/Snippets.js +++ b/src/Snippets/Snippets.js @@ -61,7 +61,7 @@ export default class Snippets extends Tool { _bindEvent() { const self = this - this._$el.on('click', '.eruda-run', function() { + this._$el.on('click', '.eruda-run', function () { const idx = $(this).data('idx') self._run(idx) @@ -71,14 +71,14 @@ export default class Snippets extends Tool { this._snippets[idx].fn.call(null) } _addDefSnippets() { - each(defSnippets, snippet => { + each(defSnippets, (snippet) => { this.add(snippet.name, snippet.fn, snippet.desc) }) } _render() { this._renderHtml( this._tpl({ - snippets: this._snippets + snippets: this._snippets, }) ) } diff --git a/src/Snippets/defSnippets.js b/src/Snippets/defSnippets.js index 0878551..471a658 100644 --- a/src/Snippets/defSnippets.js +++ b/src/Snippets/defSnippets.js @@ -10,7 +10,7 @@ import { $, upperFirst, loadJs, - trim + trim, } from '../lib/util' import { isErudaEl } from '../lib/extraUtil' import evalCss from '../lib/evalCss' @@ -32,7 +32,7 @@ export default [ document.head ) }, - desc: 'Add color borders to all elements' + desc: 'Add color borders to all elements', }, { name: 'Refresh Page', @@ -42,7 +42,7 @@ export default [ window.location.replace(url.toString()) }, - desc: 'Add timestamp to url and refresh' + desc: 'Add timestamp to url and refresh', }, { name: 'Search Text', @@ -53,7 +53,7 @@ export default [ search(keyword) }, - desc: 'Highlight given text on page' + desc: 'Highlight given text on page', }, { name: 'Edit Page', @@ -62,7 +62,7 @@ export default [ body.contentEditable = body.contentEditable !== 'true' }, - desc: 'Toggle body contentEditable' + desc: 'Toggle body contentEditable', }, { name: 'Fit Screen', @@ -93,77 +93,77 @@ export default [ window.scrollTo(0, documentHeight / 2 - viewportHeight / 2) } }, - desc: 'Scale down the whole page to fit screen' + desc: 'Scale down the whole page to fit screen', }, { name: 'Load Fps Plugin', fn() { loadPlugin('fps') }, - desc: 'Display page fps' + desc: 'Display page fps', }, { name: 'Load Features Plugin', fn() { loadPlugin('features') }, - desc: 'Browser feature detections' + desc: 'Browser feature detections', }, { name: 'Load Timing Plugin', fn() { loadPlugin('timing') }, - desc: 'Show performance and resource timing' + desc: 'Show performance and resource timing', }, { name: 'Load Memory Plugin', fn() { loadPlugin('memory') }, - desc: 'Display memory' + desc: 'Display memory', }, { name: 'Load Code Plugin', fn() { loadPlugin('code') }, - desc: 'Edit and run JavaScript' + desc: 'Edit and run JavaScript', }, { name: 'Load Benchmark Plugin', fn() { loadPlugin('benchmark') }, - desc: 'Run JavaScript benchmarks' + desc: 'Run JavaScript benchmarks', }, { name: 'Load Geolocation Plugin', fn() { loadPlugin('geolocation') }, - desc: 'Test geolocation' + desc: 'Test geolocation', }, { name: 'Load Dom Plugin', fn() { loadPlugin('dom') }, - desc: 'Navigate dom tree' + desc: 'Navigate dom tree', }, { name: 'Load Orientation Plugin', fn() { loadPlugin('orientation') }, - desc: 'Test orientation api' + desc: 'Test orientation api', }, { name: 'Load Touches Plugin', fn() { loadPlugin('touches') }, - desc: 'Visualize screen touches' + desc: 'Visualize screen touches', }, { name: 'Restore Settings', @@ -180,8 +180,8 @@ export default [ window.location.reload() }, - desc: 'Restore defaults and reload' - } + desc: 'Restore defaults and reload', + }, ] evalCss(require('./searchText.scss'), document.head) @@ -190,7 +190,7 @@ function search(text) { const root = document.body const regText = new RegExp(text, 'ig') - traverse(root, node => { + traverse(root, (node) => { const $node = $(node) if (!$node.hasClass('eruda-search-highlight-block')) return @@ -198,13 +198,13 @@ function search(text) { return document.createTextNode($node.text()) }) - traverse(root, node => { + traverse(root, (node) => { if (node.nodeType !== 3) return let val = node.nodeValue val = val.replace( regText, - match => `${match}` + (match) => `${match}` ) if (val === node.nodeValue) return @@ -239,7 +239,7 @@ function loadPlugin(name) { loadJs( `${protocol}//cdn.jsdelivr.net/npm/eruda-${name}@${pluginVersion[name]}`, - isLoaded => { + (isLoaded) => { if (!isLoaded || !window[globalName]) return logger.error('Fail to load plugin ' + name) @@ -259,5 +259,5 @@ const pluginVersion = { geolocation: '2.0.0', dom: '2.0.0', orientation: '2.0.0', - touches: '2.0.0' + touches: '2.0.0', } diff --git a/src/Sources/Sources.js b/src/Sources/Sources.js index 1a75631..b6c0bb8 100644 --- a/src/Sources/Sources.js +++ b/src/Sources/Sources.js @@ -39,20 +39,20 @@ export default class Sources extends Tool { const self = this - img.onload = function() { + img.onload = function () { self._isFetchingData = false self._data = { type: 'img', val: { width: this.width, height: this.height, - src: val - } + src: val, + }, } self._render() } - img.onerror = function() { + img.onerror = function () { self._isFetchingData = false } @@ -80,7 +80,7 @@ export default class Sources extends Tool { if (this._html) { this._data = { type: 'html', - val: this._html + val: this._html, } return this._render() @@ -91,13 +91,13 @@ export default class Sources extends Tool { ajax({ url: location.href, - success: data => (this._html = data), + success: (data) => (this._html = data), error: () => (this._html = 'Sorry, unable to fetch source code:('), complete: () => { this._isGettingHtml = false this._renderDef() }, - dataType: 'raw' + dataType: 'raw', }) } _bindEvent() { @@ -131,7 +131,7 @@ export default class Sources extends Tool { const cfg = (this.config = Settings.createCfg('sources', { showLineNum: true, formatCode: true, - indentSize: 4 + indentSize: 4, })) if (!cfg.get('showLineNum')) this._showLineNum = false @@ -210,7 +210,7 @@ export default class Sources extends Tool { number: `color:${curTheme.numberColor}`, operator: `color:${curTheme.operatorColor}`, comment: `color:${curTheme.commentColor}`, - string: `color:${curTheme.stringColor}` + string: `color:${curTheme.stringColor}`, }) } else { code = escape(code) @@ -222,7 +222,7 @@ export default class Sources extends Tool { return { idx: idx + 1, - val: line + val: line, } }) } @@ -230,7 +230,7 @@ export default class Sources extends Tool { this._renderHtml( this._codeTpl({ code, - showLineNum: len < MAX_LINE_NUM_LEN && this._showLineNum + showLineNum: len < MAX_LINE_NUM_LEN && this._showLineNum, }) ) } @@ -251,7 +251,7 @@ export default class Sources extends Tool { this._$el.find('.eruda-json').get(0), { unenumerable: true, - accessGetter: true + accessGetter: true, } ) objViewer.set(val) diff --git a/src/lib/cssMap.js b/src/lib/cssMap.js index 22f3f99..f5d84a9 100644 --- a/src/lib/cssMap.js +++ b/src/lib/cssMap.js @@ -51,5 +51,5 @@ module.exports = { 'will-change': 'wc', 'white-space': 'ws', '-webkit-overflow-scrolling': 'wos', - 'z-index': 'z' + 'z-index': 'z', } diff --git a/src/lib/evalCss.js b/src/lib/evalCss.js index 302dc61..fd07480 100644 --- a/src/lib/evalCss.js +++ b/src/lib/evalCss.js @@ -6,7 +6,7 @@ import { keys, kebabCase, defaults, - escapeRegExp + escapeRegExp, } from './util' import themes from './themes' import cssMap from './cssMap' @@ -16,7 +16,7 @@ let scale = 1 let curTheme = themes.Light -const exports = function(css, container) { +const exports = function (css, container) { css = toStr(css) for (let i = 0, len = styleList.length; i < len; i++) { @@ -36,12 +36,12 @@ const exports = function(css, container) { return style } -exports.setScale = function(s) { +exports.setScale = function (s) { scale = s resetStyles() } -exports.setTheme = function(theme) { +exports.setTheme = function (theme) { if (isStr(theme)) { curTheme = themes[theme] || themes.Light } else { @@ -55,19 +55,19 @@ exports.getCurTheme = () => curTheme exports.getThemes = () => themes -exports.clear = function() { +exports.clear = function () { each(styleList, ({ container, el }) => container.removeChild(el)) styleList = [] } -exports.remove = function(style) { - styleList = filter(styleList, s => s !== style) +exports.remove = function (style) { + styleList = filter(styleList, (s) => s !== style) style.container.removeChild(style.el) } function resetStyles() { - each(styleList, style => resetStyle(style)) + each(styleList, (style) => resetStyle(style)) } function resetStyle({ css, el }) { @@ -77,7 +77,7 @@ function resetStyle({ css, el }) { css = css.replace(new RegExp(escapeRegExp(`$${val}:`), 'g'), key + ':') }) const _keys = keys(themes.Light) - each(_keys, key => { + each(_keys, (key) => { css = css.replace( new RegExp(`var\\(--${kebabCase(key)}\\)`, 'g'), curTheme[key] diff --git a/src/lib/extraUtil.js b/src/lib/extraUtil.js index 07590b5..7531a6d 100644 --- a/src/lib/extraUtil.js +++ b/src/lib/extraUtil.js @@ -1,11 +1,11 @@ import beautify from 'js-beautify' import evalCss from './evalCss' -export default function(util) { +export default function (util) { Object.assign(util, { beautify, evalCss, - isErudaEl + isErudaEl, }) } diff --git a/src/lib/getAbstract.js b/src/lib/getAbstract.js index 98bebae..10656f5 100644 --- a/src/lib/getAbstract.js +++ b/src/lib/getAbstract.js @@ -8,7 +8,7 @@ import { each, getObjType, endWith, - isEmpty + isEmpty, } from './util' import evalCss from './evalCss' @@ -44,18 +44,18 @@ export default function getAbstract( const strWrapper = '' const boolWrapper = '' const specialWrapper = '' - const strEscape = str => + const strEscape = (str) => escape(str) .replace(/\\n/g, '↵') .replace(/\\f|\\r|\\t/g, '') .replace(/\\/g, '') const wrapperEnd = '' - const wrapKey = key => keyWrapper + strEscape(key) + wrapperEnd - const wrapNum = num => numWrapper + num + wrapperEnd - const wrapRegExp = str => strWrapper + str + wrapperEnd - const wrapBool = bool => boolWrapper + bool + wrapperEnd - const wrapNull = str => nullWrapper + str + wrapperEnd + const wrapKey = (key) => keyWrapper + strEscape(key) + wrapperEnd + const wrapNum = (num) => numWrapper + num + wrapperEnd + const wrapRegExp = (str) => strWrapper + str + wrapperEnd + const wrapBool = (bool) => boolWrapper + bool + wrapperEnd + const wrapNull = (str) => nullWrapper + str + wrapperEnd function wrapStr(str) { str = toStr(str) diff --git a/src/lib/handlebars.js b/src/lib/handlebars.js index 24566e9..272bbab 100644 --- a/src/lib/handlebars.js +++ b/src/lib/handlebars.js @@ -1,7 +1,7 @@ const handlebars = require('handlebars/runtime') // https://github.com/helpers/handlebars-helper-repeat -handlebars.registerHelper('repeat', function(count = 0, options) { +handlebars.registerHelper('repeat', function (count = 0, options) { if (count < 1) return options.inverse(this) const step = 1 @@ -17,7 +17,7 @@ handlebars.registerHelper('repeat', function(count = 0, options) { start, step, first: index === start, - last: index >= max - step + last: index >= max - step, } const blockParams = [index, data] str += options.fn(this, { data, blockParams }) @@ -27,15 +27,15 @@ handlebars.registerHelper('repeat', function(count = 0, options) { return str }) -handlebars.registerHelper('class', function(value) { +handlebars.registerHelper('class', function (value) { let classes = value.split(/\s+/) - classes = classes.map(c => `eruda-${c}`) + classes = classes.map((c) => `eruda-${c}`) return `class="${classes.join(' ')}"` }) -handlebars.registerHelper('concat', function() { +handlebars.registerHelper('concat', function () { let ret = '' for (let i = 0, len = arguments.length; i < len; i++) { diff --git a/src/lib/logger.js b/src/lib/logger.js index faa17a4..a501904 100644 --- a/src/lib/logger.js +++ b/src/lib/logger.js @@ -7,7 +7,7 @@ export default logger = new Logger( ENV === 'production' ? 'warn' : 'debug' ) -logger.formatter = function(type, argList) { +logger.formatter = function (type, argList) { argList.unshift(this.name) return argList diff --git a/src/lib/themes.js b/src/lib/themes.js index 7ae725b..99475b3 100644 --- a/src/lib/themes.js +++ b/src/lib/themes.js @@ -19,7 +19,7 @@ const keyMap = [ 'tagNameColor', 'functionColor', 'attributeNameColor', - 'commentColor' + 'commentColor', ] const keyMapLen = keyMap.length @@ -46,7 +46,7 @@ function createDarkTheme(theme) { consoleErrorForeground: '#ff8080', consoleErrorBorder: '#5c0000', light: '#ccc', - dark: '#aaa' + dark: '#aaa', }, theme ) @@ -64,7 +64,7 @@ function createLightTheme(theme) { consoleErrorForeground: '#f00', consoleErrorBorder: '#ffd6d6', light: '#fff', - dark: '#eee' + dark: '#eee', }, theme ) @@ -92,7 +92,7 @@ export default { functionColor: '#222', attributeNameColor: '#994500', commentColor: '#236e25', - cssProperty: '#c80000' + cssProperty: '#c80000', }), Dark: createDarkTheme({ darkerBackground: '#333', @@ -114,7 +114,7 @@ export default { tagNameColor: '#5db0d7', functionColor: '#d5d5d5', attributeNameColor: '#9bbbdc', - commentColor: '#747474' + commentColor: '#747474', }), 'Material Oceanic': createDarkTheme([ '#263238', @@ -135,7 +135,7 @@ export default { '#f07178', '#82aaff', '#ffcb6b', - '#546e7a' + '#546e7a', ]), 'Material Darker': createDarkTheme([ '#212121', @@ -156,7 +156,7 @@ export default { '#f07178', '#82aaff', '#ffcb6b', - '#616161' + '#616161', ]), 'Material Lighter': createLightTheme([ '#FAFAFA', @@ -177,7 +177,7 @@ export default { '#E53935', '#6182B8', '#F6A434', - '#AABFC9' + '#AABFC9', ]), 'Material Palenight': createDarkTheme([ '#292D3E', @@ -198,7 +198,7 @@ export default { '#f07178', '#82aaff', '#ffcb6b', - '#676E95' + '#676E95', ]), 'Material Deep Ocean': createDarkTheme([ '#0F111A', @@ -219,7 +219,7 @@ export default { '#f07178', '#82aaff', '#ffcb6b', - '#717CB4' + '#717CB4', ]), 'Monokai Pro': createDarkTheme([ '#2D2A2E', @@ -240,7 +240,7 @@ export default { '#FF6188', '#A9DC76', '#78DCE8', - '#727072' + '#727072', ]), Dracula: createDarkTheme([ '#282A36', @@ -261,7 +261,7 @@ export default { '#FF79C6', '#50FA78', '#50FA7B', - '#6272A4' + '#6272A4', ]), 'Arc Dark': createDarkTheme([ '#2f343f', @@ -282,7 +282,7 @@ export default { '#CF6A4C', '#7587A6', '#F9EE98', - '#747C84' + '#747C84', ]), 'Atom One Dark': createDarkTheme([ '#282C34', @@ -303,7 +303,7 @@ export default { '#F07178', '#61AEEF', '#E5C17C', - '#59626F' + '#59626F', ]), 'Atom One Light': createLightTheme([ '#FAFAFA', @@ -324,7 +324,7 @@ export default { '#E4564A', '#4078F2', '#C18401', - '#A0A1A7' + '#A0A1A7', ]), 'Solarized Dark': createDarkTheme([ '#002B36', @@ -345,7 +345,7 @@ export default { '#268BD2', '#B58900', '#B58900', - '#657B83' + '#657B83', ]), 'Solarized Light': createLightTheme([ '#fdf6e3', @@ -366,7 +366,7 @@ export default { '#268BD2', '#B58900', '#657B83', - '#93A1A1' + '#93A1A1', ]), Github: createLightTheme([ '#F7F8FA', @@ -387,7 +387,7 @@ export default { '#22863A', '#6F42C1', '#6F42C1', - '#6A737D' + '#6A737D', ]), 'Night Owl': createDarkTheme([ '#011627', @@ -408,7 +408,7 @@ export default { '#7fdbca', '#82AAFF', '#FAD430', - '#637777' + '#637777', ]), 'Light Owl': createLightTheme([ '#FAFAFA', @@ -429,6 +429,6 @@ export default { '#994cc3', '#4876d6', '#4876d6', - '#637777' - ]) + '#637777', + ]), } diff --git a/test/boot.js b/test/boot.js index 3199af0..4bb2f16 100644 --- a/test/boot.js +++ b/test/boot.js @@ -1,13 +1,13 @@ function boot(name, cb) { // Need a little delay to make sure width and height of webpack dev server iframe are initialized. - setTimeout(function() { + setTimeout(function () { let options = { useShadowDom: false, defaults: { displaySize: 50, transparency: 0.9, - theme: 'Monokai Pro' - } + theme: 'Monokai Pro', + }, } if (name) { options.tool = name === 'settings' ? [] : name @@ -24,10 +24,10 @@ function boot(name, cb) { if (name == null) return - loadJs('lib/boot', function() { - loadJs('lib/jasmine-jquery', function() { + loadJs('lib/boot', function () { + loadJs('lib/jasmine-jquery', function () { // This is needed to trigger jasmine initialization. - loadJs(name, function() { + loadJs(name, function () { window.onload() }) }) diff --git a/test/console.js b/test/console.js index 74966ea..6231e05 100644 --- a/test/console.js +++ b/test/console.js @@ -1,4 +1,4 @@ -describe('console', function() { +describe('console', function () { let tool = eruda.get('console') tool.config.set('asyncRender', false) let $tool = $('.eruda-console') @@ -12,54 +12,54 @@ describe('console', function() { return logger._displayLogs } - beforeEach(function() { + beforeEach(function () { eruda.show('console') logger.silentClear() }) - it('string', function() { + it('string', function () { let text = 'This is a log' tool.log(text) expect($(log(0))).toContainText(text) }) - it('clear', function() { + it('clear', function () { expect($tool.find('.eruda-logs li')).toHaveLength(0) }) - it('recognize url', function() { + it('recognize url', function () { tool.log('http://liriliri.github.io/eruda/?plugin=fps') expect($(log(0))).toContainHtml( 'http://liriliri.github.io/eruda/?plugin=fps' ) }) - it('basic object', function() { + it('basic object', function () { let obj = { a: 1 } tool.log(obj) expect($(log(0))).toContainText('Object { a: 1 }') }) - it('html', function() { + it('html', function () { tool.html('Blue') expect($(log(0))).toContainElement('span.color-blue') }) - it('timing', function() { + it('timing', function () { tool.time('eruda') tool.timeEnd('eruda') expect($(log(0))).toHaveText(/eruda: [.\d]+ms/) }) - it('error', function() { + it('error', function () { tool.error(new Error('error test')) expect($(log(0))).toContainElement('.eruda-stack') expect($(log(0))).toContainText('error test') }) - it('assert', function() { + it('assert', function () { tool.assert(true, 'assert') expect(logs()).toHaveLength(0) @@ -67,14 +67,14 @@ describe('console', function() { expect(logs()).toHaveLength(1) }) - it('count', function() { + it('count', function () { tool.count('test') tool.count('test') expect($(log(1))).toContainText('test: 2') }) - describe('substitution', function() { - it('number', function() { + describe('substitution', function () { + it('number', function () { tool.log('Eruda is %d', 1.2, 'year old') expect($(log(0))).toContainText('Eruda is 1 year old') logger.silentClear() @@ -87,12 +87,12 @@ describe('console', function() { expect($(log(0))).toContainText('1.2 year old') }) - it('string', function() { + it('string', function () { tool.log('My name is %s', 'eruda') expect($(log(0))).toContainText('My name is eruda') }) - it('object', function() { + it('object', function () { tool.log('Object is %O', { a: 1 }) expect($(log(0))).toContainText('Object is { a: 1 }') logger.silentClear() @@ -101,12 +101,12 @@ describe('console', function() { expect($(log(0))).toContainText('Dom is ') }) - it('style', function() { + it('style', function () { tool.log('%cblue%cgreen', 'color:blue', 'color:green') expect($(log(0))).toContainText('bluegreen') }) - it('Repeat log', function() { + it('Repeat log', function () { for (let i = 0; i < 10; i++) tool.log(1) let $log = $tool.find('.eruda-log-item') expect(logs()).toHaveLength(1) @@ -114,45 +114,45 @@ describe('console', function() { }) }) - describe('table', function() { - it('wrong args', function() { + describe('table', function () { + it('wrong args', function () { tool.table('test') expect($tool.find('.eruda-table')).not.toContainElement('table') }) - it('sort keys', function() { + it('sort keys', function () { tool.table([{ a: 1 }, { d: 2, a: 2 }, { c: 1 }]) expect($(log(0)).find('.eruda-table thead tr')).toContainHtml( '(index)acd' ) }) - it('basic', function() { + it('basic', function () { tool.table([{ test: 1 }, { test: 2, test2: 3 }]) expect($(log(0)).find('.eruda-table tbody tr')).toHaveLength(2) expect($(log(0)).find('.eruda-table thead th')).toHaveLength(3) }) - it('filter', function() { + it('filter', function () { tool.table([{ test: 1 }, { test: 2, test2: 3 }], 'test') expect($(log(0)).find('.eruda-table thead th')).toHaveLength(2) }) }) - describe('filter', function() { + describe('filter', function () { // Test case from https://github.com/liriliri/eruda/issues/14 - it('function', function() { - tool.filter(function(log) { + it('function', function () { + tool.filter(function (log) { return log.type !== 'error' }) let obj = {} Object.defineProperty(obj, 'a', { - get: function() { + get: function () { tool.error('deprecated') return 1 - } + }, }) tool.log(obj) expect(logs()).toHaveLength(1) @@ -160,13 +160,8 @@ describe('console', function() { tool.filter('all') }) - it('all info error warn log', function() { - tool - .log('log') - .info('info') - .error('error') - .warn('warn') - .debug('debug') + it('all info error warn log', function () { + tool.log('log').info('info').error('error').warn('warn').debug('debug') expect(logs()).toHaveLength(5) tool.filter('info') @@ -188,7 +183,7 @@ describe('console', function() { tool.filter('all') }) - it('regex', function() { + it('regex', function () { tool.log('test').log('test2') expect(logs()).toHaveLength(2) @@ -200,36 +195,36 @@ describe('console', function() { }) }) - describe('config', function() { + describe('config', function () { let config = tool.config - it('max number', function() { + it('max number', function () { config.set('maxLogNum', '10') for (let i = 0; i < 20; i++) tool.log(i) expect(logs()).toHaveLength(10) }) - it('override console', function() { + it('override console', function () { config.set('overrideConsole', true) console.log('test') expect($(log(0))).toContainText('test') }) - it('display extra info', function() { + it('display extra info', function () { config.set('displayExtraInfo', true) tool.log('test') expect($(log(0))).toContainElement('.eruda-header') }) }) - describe('ui', function() { - it('clear', function() { + describe('ui', function () { + it('clear', function () { tool.log('test') $('.eruda-clear-console').click() expect($tool.find('.eruda-logs li')).toHaveLength(0) }) - it('filter', function() { + it('filter', function () { tool.log('test') tool.warn('test') expect(logs()).toHaveLength(2) @@ -239,16 +234,16 @@ describe('console', function() { }) }) - describe('execute', function() { - it('js', function() { + describe('execute', function () { + it('js', function () { $tool.find('textarea').val('1+2') $('.eruda-execute').click() expect($(log(1))).toContainText('3') }) }) - describe('events', function() { - it('log', function() { + describe('events', function () { + it('log', function () { let sum = 0 function add(num) { sum += num diff --git a/test/elements.js b/test/elements.js index f658dac..5b77951 100644 --- a/test/elements.js +++ b/test/elements.js @@ -1,13 +1,13 @@ -describe('elements', function() { +describe('elements', function () { let tool = eruda.get('elements') let $tool = $('.eruda-elements') - beforeEach(function() { + beforeEach(function () { eruda.show('elements') }) - describe('api', function() { - it('set element', function() { + describe('api', function () { + it('set element', function () { tool.set(document.body) expect($tool.find('.eruda-parent')).toContainText('html') expect($tool.find('.eruda-breadcrumb')).toContainText('body') diff --git a/test/index.html b/test/index.html index 407412c..d68357b 100644 --- a/test/index.html +++ b/test/index.html @@ -47,10 +47,10 @@ diff --git a/test/info.js b/test/info.js index 4c7e347..f08e669 100644 --- a/test/info.js +++ b/test/info.js @@ -1,39 +1,39 @@ -describe('info', function() { +describe('info', function () { let tool = eruda.get('info') let $tool = $('.eruda-info') - describe('default', function() { - it('location', function() { + describe('default', function () { + it('location', function () { expect($tool.find('.eruda-content').eq(0)).toContainText(location.href) }) - it('user agent', function() { + it('user agent', function () { expect($tool.find('.eruda-content').eq(1)).toContainText( navigator.userAgent ) }) - it('device', function() { + it('device', function () { expect($tool.find('.eruda-content').eq(2)).toContainText( window.innerWidth ) }) - it('system', function() { + it('system', function () { expect($tool.find('.eruda-content').eq(3)).toContainText('os') }) - it('about', function() { + it('about', function () { expect($tool.find('.eruda-content').eq(4)).toHaveText(/Eruda v[\d.]+/) }) }) - it('clear', function() { + it('clear', function () { tool.clear() expect($tool.find('li')).toHaveLength(0) }) - it('add', function() { + it('add', function () { tool.add('test', 'eruda') expect($tool.find('.eruda-title')).toContainText('test') expect($tool.find('.eruda-content')).toContainText('eruda') @@ -42,13 +42,13 @@ describe('info', function() { expect($tool.find('.eruda-content')).toContainText('update') }) - it('get', function() { + it('get', function () { expect(tool.get()).toEqual([{ name: 'test', val: 'update' }]) expect(tool.get('test')).toBe('update') expect(tool.get('test2')).not.toBeDefined() }) - it('remove', function() { + it('remove', function () { tool.remove('test') expect($tool.find('li')).toHaveLength(0) }) diff --git a/test/init.js b/test/init.js index 168ef39..e827b51 100644 --- a/test/init.js +++ b/test/init.js @@ -1,3 +1,3 @@ eruda.init({ - useShadowDom: false + useShadowDom: false, }) diff --git a/test/manual.html b/test/manual.html index bef4bc7..29d2dd3 100644 --- a/test/manual.html +++ b/test/manual.html @@ -57,76 +57,76 @@ function addClickEvent(id, listener) { document.getElementById(id).addEventListener( 'click', - function(e) { + function (e) { e.preventDefault() listener() }, false ) } - addClickEvent('issue17', function() { - let B = function() {} - let A = function() { + addClickEvent('issue17', function () { + let B = function () {} + let A = function () { this._data = 'eruda' } A.prototype = Object.create(B.prototype) Object.defineProperty(A.prototype, 'data', { - get: function() { + get: function () { return this._data - } + }, }) let a = new A() console.log(a) }) - addClickEvent('plugin', function() { + addClickEvent('plugin', function () { eruda.add({ name: 'test' }) - eruda.add(function(eruda) { + eruda.add(function (eruda) { return { name: 'test2', - init: function($el) { + init: function ($el) { this._$el = $el this._$el.html('This is the new plugin') - } + }, } }) let Tool = eruda.Tool eruda.add( new (Tool.extend({ name: 'test3', - init: function($el) { + init: function ($el) { this.callSuper(Tool, 'init', arguments) this._$el.html('This is another new plugin') - } + }, }))() ) }) - addClickEvent('issue29', function() { - new Promise(function(resolve, reject) { + addClickEvent('issue29', function () { + new Promise(function (resolve, reject) { resolve() - }).then(function(res) { + }).then(function (res) { let a = res.a }) }) - addClickEvent('issue31', function() { - addEventListener('resize', function() {}) + addClickEvent('issue31', function () { + addEventListener('resize', function () {}) }) - addClickEvent('issue33', function() { + addClickEvent('issue33', function () { util.evalCss(':root {--test: 10px;}') }) - addClickEvent('trigger-error', function() { + addClickEvent('trigger-error', function () { triggerError() }) - addClickEvent('big-array', function() { + addClickEvent('big-array', function () { let arr = [] for (let i = 0; i < 10000; i++) { arr.push(i) } console.log(arr) }) - addClickEvent('override-style', function() { + addClickEvent('override-style', function () { util.evalCss('.eruda-nav-bar {background: red !important;}') }) - addClickEvent('stringify-timing', function() { + addClickEvent('stringify-timing', function () { console.time('stringify window') eruda.util.stringifyAll(window) console.timeEnd('stringify window') diff --git a/test/network.js b/test/network.js index a2f9de6..af97e23 100644 --- a/test/network.js +++ b/test/network.js @@ -1,12 +1,12 @@ -describe('network', function() { - beforeEach(function() { +describe('network', function () { + beforeEach(function () { eruda.show('network') }) - describe('request', function() { - it('xhr', function(done) { + describe('request', function () { + it('xhr', function (done) { $('.eruda-clear-xhr').click() - util.ajax.get(window.location.toString(), function() { + util.ajax.get(window.location.toString(), function () { expect($('.eruda-requests li')).toHaveLength(1) done() }) diff --git a/test/resources.js b/test/resources.js index c749135..55b129a 100644 --- a/test/resources.js +++ b/test/resources.js @@ -1,46 +1,46 @@ -describe('resources', function() { +describe('resources', function () { let $tool = $('.eruda-resources') - beforeEach(function() { + beforeEach(function () { eruda.show('resources') }) - describe('localStorage', function() { - it('show', function() { + describe('localStorage', function () { + it('show', function () { localStorage.clear() localStorage.setItem('testKey', 'testVal') $tool.find('.eruda-refresh-local-storage').click() expect($tool.find('.eruda-local-storage')).toContainText('testKey') }) - it('clear', function() { + it('clear', function () { $tool.find('.eruda-clear-storage[data-type="local"]').click() expect($tool.find('.eruda-local-storage')).toContainText('Empty') }) }) - describe('sessionStorage', function() { - it('show', function() { + describe('sessionStorage', function () { + it('show', function () { sessionStorage.clear() sessionStorage.setItem('testKey', 'testVal') $tool.find('.eruda-refresh-session-storage').click() expect($tool.find('.eruda-session-storage')).toContainText('testKey') }) - it('clear', function() { + it('clear', function () { $tool.find('.eruda-clear-storage[data-type="session"]').click() expect($tool.find('.eruda-session-storage')).toContainText('Empty') }) }) - describe('cookie', function() { - it('show', function() { + describe('cookie', function () { + it('show', function () { util.cookie.set('testKey', 'testVal') $tool.find('.eruda-refresh-cookie').click() expect($tool.find('.eruda-cookie')).toContainText('testKey') }) - it('clear', function() { + it('clear', function () { $tool.find('.eruda-clear-cookie').click() expect($tool.find('.eruda-cookie')).toContainText('Empty') }) diff --git a/test/settings.js b/test/settings.js index a643581..68183d4 100644 --- a/test/settings.js +++ b/test/settings.js @@ -1,4 +1,4 @@ -describe('settings', function() { +describe('settings', function () { let tool = eruda.get('settings') let $tool = $('.eruda-settings') @@ -7,14 +7,14 @@ describe('settings', function() { testSwitch: false, testSelect: '1', testRange: 1, - testColor: '#fff' + testColor: '#fff', }) - beforeEach(function() { + beforeEach(function () { tool.clear() }) - it('switch', function() { + it('switch', function () { let text = 'Test Switch' tool.switch(cfg, 'testSwitch', text) @@ -23,12 +23,12 @@ describe('settings', function() { expect(cfg.get('testSwitch')).toBe(true) }) - it('separator', function() { + it('separator', function () { tool.separator() expect($tool.find('.eruda-separator').length).toEqual(1) }) - it('select', function() { + it('select', function () { let text = 'Test Select' tool.select(cfg, 'testSelect', text, ['1', '2', '3']) @@ -37,13 +37,10 @@ describe('settings', function() { expect($el.find('.eruda-head')).toContainText(text) expect($el.find('.eruda-val')).toContainText('1') $el.find('.eruda-head').click() - $el - .find('ul li') - .eq(1) - .click() + $el.find('ul li').eq(1).click() expect(cfg.get('testSelect')).toBe('2') }) - it('range', function() { + it('range', function () { let text = 'Test Range' tool.range(cfg, 'testRange', text, { min: 0, max: 1, step: 0.1 }) @@ -53,7 +50,7 @@ describe('settings', function() { $el.find('.eruda-head').click() }) - it('color', function() { + it('color', function () { let text = 'Test Color' tool.color(cfg, 'testColor', text, ['#000', '#fff']) @@ -61,14 +58,11 @@ describe('settings', function() { expect($el.find('.eruda-head')).toContainText(text) expect($el.find('ul li').length).toEqual(2) $el.find('.eruda-head').click() - $el - .find('ul li') - .eq(0) - .click() + $el.find('ul li').eq(0).click() expect(cfg.get('testColor')).toBe('rgb(0, 0, 0)') }) - it('remove', function() { + it('remove', function () { let text = 'Test Switch' tool.switch(cfg, 'testSwitch', text) expect($tool.find('.eruda-switch')).toContainText(text) diff --git a/test/snippets.js b/test/snippets.js index da226d9..b73b9e9 100644 --- a/test/snippets.js +++ b/test/snippets.js @@ -1,9 +1,9 @@ -describe('snippets', function() { +describe('snippets', function () { let tool = eruda.get('snippets') let $tool = $('.eruda-snippets') - describe('default', function() { - it('border all', function() { + describe('default', function () { + it('border all', function () { expect($tool.find('.eruda-name').eq(0)).toContainText('Border All') let $body = $('body') @@ -15,15 +15,15 @@ describe('snippets', function() { expect($body).toHaveCss({ outlineWidth: '0px' }) }) - it('refresh page', function() { + it('refresh page', function () { expect($tool.find('.eruda-name').eq(1)).toContainText('Refresh Page') }) - it('search text', function() { + it('search text', function () { expect($tool.find('.eruda-name').eq(2)).toContainText('Search Text') }) - it('edit page', function() { + it('edit page', function () { expect($tool.find('.eruda-name').eq(3)).toContainText('Edit Page') let $body = $('body') @@ -36,15 +36,15 @@ describe('snippets', function() { }) }) - it('clear', function() { + it('clear', function () { tool.clear() expect($tool.find('.eruda-name')).toHaveLength(0) }) - it('add', function() { + it('add', function () { tool.add( 'Test', - function() { + function () { console.log('eruda') }, 'This is the description' @@ -55,7 +55,7 @@ describe('snippets', function() { ) }) - it('remove', function() { + it('remove', function () { tool.remove('Test') expect($tool.find('.eruda-name')).toHaveLength(0) }) diff --git a/test/sources.js b/test/sources.js index f3dc85f..f55ea08 100644 --- a/test/sources.js +++ b/test/sources.js @@ -1,13 +1,13 @@ -describe('sources', function() { +describe('sources', function () { let tool = eruda.get('sources') let $tool = $('.eruda-sources') - beforeEach(function() { + beforeEach(function () { eruda.show('sources') }) - describe('js', function() { - it('highlight', function() { + describe('js', function () { + it('highlight', function () { tool.set('js', '/* test */') expect($tool.find('.eruda-content')).toContainHtml('/* test */') })