update JS code style to currently recommended conventions

ES5 support is still present to not introduce breaking changes (dropped
IE10 support) in minor updates.
This commit is contained in:
Stefan Kalscheuer 2019-08-28 11:10:39 +02:00
parent 2906d435d9
commit 0cab1a3580
3 changed files with 25 additions and 7 deletions

View File

@ -1,3 +1,23 @@
{ {
"extends": "eslint-config-wordpress" "env": {
"es6": false,
"browser": true
},
"globals": {
"sclivetickerAjax": "readonly"
},
"extends": [
"plugin:@wordpress/eslint-plugin/recommended",
"plugin:@wordpress/eslint-plugin/es5"
],
"overrides": [
{
"files": [
"*"
],
"rules": {
"no-var": "off"
}
}
]
} }

View File

@ -6,7 +6,7 @@
"license": "GPL-2.0+", "license": "GPL-2.0+",
"devDependencies": { "devDependencies": {
"eslint": "^6", "eslint": "^6",
"eslint-config-wordpress": "^2.0", "@wordpress/eslint-plugin": "^2.4",
"stylelint": "^10.1", "stylelint": "^10.1",
"stylelint-config-wordpress": "^14.0" "stylelint-config-wordpress": "^14.0"
} }

View File

@ -12,7 +12,6 @@ function scLiveticker() {
* @return {void} * @return {void}
*/ */
scLiveticker.init = function() { scLiveticker.init = function() {
// Opt out if AJAX pobject not present. // Opt out if AJAX pobject not present.
if ( 'undefined' === typeof sclivetickerAjax ) { if ( 'undefined' === typeof sclivetickerAjax ) {
return; return;
@ -31,7 +30,7 @@ scLiveticker.init = function() {
s: elem.getAttribute( 'data-sclt-ticker' ), s: elem.getAttribute( 'data-sclt-ticker' ),
l: elem.getAttribute( 'data-sclt-limit' ), l: elem.getAttribute( 'data-sclt-limit' ),
t: elem.getAttribute( 'data-sclt-last' ), t: elem.getAttribute( 'data-sclt-last' ),
e: elem e: elem,
}; };
} }
); );
@ -44,7 +43,7 @@ scLiveticker.init = function() {
w: elem.getAttribute( 'data-sclt-ticker' ), w: elem.getAttribute( 'data-sclt-ticker' ),
l: elem.getAttribute( 'data-sclt-limit' ), l: elem.getAttribute( 'data-sclt-limit' ),
t: elem.getAttribute( 'data-sclt-last' ), t: elem.getAttribute( 'data-sclt-last' ),
e: elem e: elem,
}; };
} }
); );
@ -61,7 +60,6 @@ scLiveticker.init = function() {
* @return {void} * @return {void}
*/ */
scLiveticker.update = function() { scLiveticker.update = function() {
// Extract ticker-slug, limit and timestamp of last poll. // Extract ticker-slug, limit and timestamp of last poll.
var updateReq = 'action=sclt_update-ticks&_ajax_nonce=' + scLiveticker.nonce; var updateReq = 'action=sclt_update-ticks&_ajax_nonce=' + scLiveticker.nonce;
var i, j; var i, j;
@ -112,6 +110,7 @@ scLiveticker.update = function() {
} }
setTimeout( scLiveticker.update, scLiveticker.pollInterval ); // Re-trigger update. setTimeout( scLiveticker.update, scLiveticker.pollInterval ); // Re-trigger update.
} catch ( e ) { } catch ( e ) {
// eslint-disable-next-line no-console
console.warn( 'Liveticker AJAX update failed, stopping automatic updates.' ); console.warn( 'Liveticker AJAX update failed, stopping automatic updates.' );
} }
} }
@ -131,7 +130,6 @@ scLiveticker.update = function() {
* @return {void} * @return {void}
*/ */
scLiveticker.updateHTML = function( t, u ) { scLiveticker.updateHTML = function( t, u ) {
// Prepend HTML of new ticks. // Prepend HTML of new ticks.
t.e.innerHTML = u.h + t.e.innerHTML; t.e.innerHTML = u.h + t.e.innerHTML;
t.e.setAttribute( 'data-sclt-last', u.t ); t.e.setAttribute( 'data-sclt-last', u.t );