From edf32623c55fabe6a6c32e219867efbc8f23802a Mon Sep 17 00:00:00 2001 From: itpixelz Date: Wed, 8 Apr 2020 08:43:46 +0500 Subject: [PATCH 01/12] Rewrite admin/includes/js/admin.js without using jQuery. --- admin/includes/js/admin.js | 234 ++++++++++++++++++++----------------- 1 file changed, 124 insertions(+), 110 deletions(-) diff --git a/admin/includes/js/admin.js b/admin/includes/js/admin.js index 5e8b121..23a61a0 100644 --- a/admin/includes/js/admin.js +++ b/admin/includes/js/admin.js @@ -1,110 +1,124 @@ -( function( $ ) { - - 'use strict'; - - if ( typeof bogo === 'undefined' || bogo === null ) { - return; - } - - bogo.langName = function( locale ) { - return bogo.availableLanguages[ locale ] || ''; - }; - - $( function() { - $( 'body.options-general-php select#WPLANG' ).each( function() { - $( this ).find( 'option[selected="selected"]' ).removeAttr( 'selected' ); - var val = bogo.defaultLocale || 'en_US'; - val = ( 'en_US' == val ? '' : val ); - $( this ).find( 'option[value="' + val + '"]' ).first().attr( 'selected', 'selected' ); - } ); - } ); - - $( function() { - $( '#bogo-add-translation' ).click( function() { - if ( ! bogo.currentPost.postId ) { - return; - } - - var locale = $( '#bogo-translations-to-add' ).val(); - var rest_url = bogo.apiSettings.getRoute( - '/posts/' + bogo.currentPost.postId + '/translations/' + locale ); - $( '#bogo-add-translation' ).next( '.spinner' ) - .css( 'visibility', 'visible' ); - - $.ajax( { - type: 'POST', - url: rest_url, - beforeSend: function( xhr ) { - xhr.setRequestHeader( 'X-WP-Nonce', bogo.apiSettings.nonce ); - } - } ).done( function( response ) { - var post = response[ locale ]; - - if ( ! post ) { - return; - } - - var $added = $( '' ).attr( { - href: post.edit_link, - target: '_blank', - rel: 'noopener noreferrer' - } ).html( function() { - var output = post.title.rendered; - output += ' ' - + bogo.l10n.targetBlank + ''; - return output; - } ); - - $added = $( '
  • ' ).append( $added ).append( - ' [' + bogo.availableLanguages[ locale ] + ']' ); - $( '#bogo-translations' ).append( $added ); - - $( '#bogo-translations-to-add option[value="' + locale + '"]' ).detach(); - - if ( $( '#bogo-translations-to-add option' ).length < 1 ) { - $( '#bogo-add-translation-actions' ).detach(); - } - } ).always( function() { - $( '#bogo-add-translation' ).next( '.spinner' ).css( 'visibility', 'hidden' ); - } ); - } ); - } ); - - $( function() { - if ( 'bogo-texts' == bogo.pagenow ) { - $( window ).on( 'beforeunload', function( event ) { - var changed = false; - - $( '#bogo-terms-translation :text' ).each( function() { - if ( this.defaultValue != $( this ).val() ) { - changed = true; - } - } ); - - if ( changed ) { - event.returnValue = bogo.l10n.saveAlert; - return bogo.l10n.saveAlert; - } - } ); - - $( '#bogo-terms-translation' ).submit( function() { - $( window ).off( 'beforeunload' ); - } ); - - $( '#select-locale' ).change( function() { - location = 'admin.php?page=bogo-texts&locale=' + $( this ).val(); - } ); - } - } ); - - bogo.apiSettings.getRoute = function( path ) { - var url = bogo.apiSettings.root; - - url = url.replace( - bogo.apiSettings.namespace, - bogo.apiSettings.namespace + path ); - - return url; - }; - -} )( jQuery ); +function init_bogo_admin() { + + if ( typeof bogo === 'undefined' || bogo === null ) { + return; + } + + bogo.langName = function( locale ) { + return bogo.availableLanguages[ locale ] || ''; + }; + + bogo.apiSettings.getRoute = function( path ) { + + var url = bogo.apiSettings.root; + url = url.replace( bogo.apiSettings.namespace, bogo.apiSettings.namespace + path ); + + return url; + }; + + + var bogo_add_translation = document.getElementById( 'bogo-add-translation' ); + + if ( bogo_add_translation ) { + + bogo_add_translation.onclick = function() { + + if ( !bogo.currentPost.postId ) { + return; + } + + var locale = document.getElementById('bogo-translations-to-add').value; + var rest_url = bogo.apiSettings.getRoute( '/posts/' + bogo.currentPost.postId + '/translations/' + locale ); + var spinner_element = document.getElementById( 'bogo-add-translation' ).nextElementSibling; + + spinner_element.style.visibility = 'visible'; + + var httpRequest = new XMLHttpRequest(); + httpRequest.onreadystatechange = function( data ) { + + if ( httpRequest.readyState == XMLHttpRequest.DONE ) { // XMLHttpRequest.DONE == 4 + + if ( httpRequest.status == 200 ) { + + var response = JSON.parse( httpRequest.response ); + var post = response[locale]; + + if (!post) { + return; + } + + // The element into which appending will be done + var element = document.getElementById( 'bogo-translations' ); + + // The element to be appended + var child = document.createElement( 'LI' ); + var output = post.title.rendered; + output += ' ' + bogo.l10n.targetBlank + ''; + child.innerHTML = '' + output + ' [' + bogo.availableLanguages[locale] + ']'; + + // append + element.appendChild( child ); + + // remove appended option + document.querySelector( '#bogo-translations-to-add option[value="' + locale + '"]' ).remove(); + + var langs = document.getElementById( 'bogo-translations-to-add' ); + + if (!langs.options.length) { + document.getElementById( 'bogo-add-translation-actions' ).remove(); + } + } + + spinner_element.style.visibility = 'hidden'; + } + }; + + httpRequest.open( 'POST', rest_url ); + httpRequest.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' ); + httpRequest.setRequestHeader( 'X-WP-Nonce', bogo.apiSettings.nonce ); + httpRequest.send(); + + }; + } + + + + if ( 'bogo-texts' == bogo.pagenow ) { + + // window.addEventListener( "beforeunload", function( event ) { + window.onbeforeunload = function( event ) { + var changed = false; + + document.querySelectorAll( "#bogo-terms-translation input[type=text]" ).forEach( text => { + if ( text.defaultValue != text.value ) { + changed = true; + } + }); + + if ( changed ) { + event.returnValue = bogo.l10n.saveAlert; + return bogo.l10n.saveAlert; + } + }; + + + + document.getElementById('bogo-terms-translation').onsubmit = function(){ + window.onbeforeunload = function () {}; + }; + + + var select_local = document.getElementById('select-locale'); + select_local.addEventListener('change',function(){ + location = 'admin.php?page=bogo-texts&locale=' + select_local.value; + }); + + } + + + +} + + +// fire +init_bogo_admin(); From ddf5b569b9559ee2d11b0217ccf901f65076888b Mon Sep 17 00:00:00 2001 From: itpixelz Date: Wed, 8 Apr 2020 08:53:50 +0500 Subject: [PATCH 02/12] Formal code --- admin/includes/js/admin.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/admin/includes/js/admin.js b/admin/includes/js/admin.js index 23a61a0..c2ac956 100644 --- a/admin/includes/js/admin.js +++ b/admin/includes/js/admin.js @@ -15,7 +15,7 @@ function init_bogo_admin() { return url; }; - + var bogo_add_translation = document.getElementById( 'bogo-add-translation' ); @@ -103,22 +103,18 @@ function init_bogo_admin() { - document.getElementById('bogo-terms-translation').onsubmit = function(){ + document.getElementById( 'bogo-terms-translation' ).onsubmit = function(){ window.onbeforeunload = function () {}; }; - var select_local = document.getElementById('select-locale'); - select_local.addEventListener('change',function(){ + var select_local = document.getElementById( 'select-locale' ); + select_local.addEventListener( 'change',function(){ location = 'admin.php?page=bogo-texts&locale=' + select_local.value; }); } - - - } - // fire init_bogo_admin(); From 42a0b0bfc8ec8958cdb00c6911b621983b4725da Mon Sep 17 00:00:00 2001 From: itpixelz Date: Wed, 8 Apr 2020 09:06:07 +0500 Subject: [PATCH 03/12] Add space --- admin/includes/js/admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/includes/js/admin.js b/admin/includes/js/admin.js index c2ac956..0e0ef43 100644 --- a/admin/includes/js/admin.js +++ b/admin/includes/js/admin.js @@ -64,7 +64,7 @@ function init_bogo_admin() { var langs = document.getElementById( 'bogo-translations-to-add' ); - if (!langs.options.length) { + if ( !langs.options.length ) { document.getElementById( 'bogo-add-translation-actions' ).remove(); } } From 3e376f23a60bcc69bff8c90ae3ca907c3b2cc36f Mon Sep 17 00:00:00 2001 From: itpixelz Date: Wed, 8 Apr 2020 09:07:16 +0500 Subject: [PATCH 04/12] Add formating space --- admin/includes/js/admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/includes/js/admin.js b/admin/includes/js/admin.js index 0e0ef43..fe4f564 100644 --- a/admin/includes/js/admin.js +++ b/admin/includes/js/admin.js @@ -43,7 +43,7 @@ function init_bogo_admin() { var response = JSON.parse( httpRequest.response ); var post = response[locale]; - if (!post) { + if ( !post ) { return; } From aa4dd39d7c080dee5c4d014638f2c3a619215065 Mon Sep 17 00:00:00 2001 From: itpixelz Date: Wed, 8 Apr 2020 20:12:18 +0500 Subject: [PATCH 05/12] Remove unnecessary comment --- admin/includes/js/admin.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/admin/includes/js/admin.js b/admin/includes/js/admin.js index fe4f564..0e2d881 100644 --- a/admin/includes/js/admin.js +++ b/admin/includes/js/admin.js @@ -27,7 +27,7 @@ function init_bogo_admin() { return; } - var locale = document.getElementById('bogo-translations-to-add').value; + var locale = document.getElementById( 'bogo-translations-to-add' ).value; var rest_url = bogo.apiSettings.getRoute( '/posts/' + bogo.currentPost.postId + '/translations/' + locale ); var spinner_element = document.getElementById( 'bogo-add-translation' ).nextElementSibling; @@ -48,7 +48,7 @@ function init_bogo_admin() { } // The element into which appending will be done - var element = document.getElementById( 'bogo-translations' ); + var element = document.'bogo-translations-to-add'( 'bogo-translations' ); // The element to be appended var child = document.createElement( 'LI' ); @@ -85,7 +85,7 @@ function init_bogo_admin() { if ( 'bogo-texts' == bogo.pagenow ) { - // window.addEventListener( "beforeunload", function( event ) { + window.onbeforeunload = function( event ) { var changed = false; From 3b1b2f8d44a3c9727302ea747cda86d2ac016593 Mon Sep 17 00:00:00 2001 From: itpixelz Date: Wed, 8 Apr 2020 20:21:53 +0500 Subject: [PATCH 06/12] Remove extra spaces --- admin/includes/js/admin.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/admin/includes/js/admin.js b/admin/includes/js/admin.js index 0e2d881..a89dd86 100644 --- a/admin/includes/js/admin.js +++ b/admin/includes/js/admin.js @@ -9,14 +9,12 @@ function init_bogo_admin() { }; bogo.apiSettings.getRoute = function( path ) { - var url = bogo.apiSettings.root; url = url.replace( bogo.apiSettings.namespace, bogo.apiSettings.namespace + path ); return url; }; - var bogo_add_translation = document.getElementById( 'bogo-add-translation' ); if ( bogo_add_translation ) { @@ -48,7 +46,7 @@ function init_bogo_admin() { } // The element into which appending will be done - var element = document.'bogo-translations-to-add'( 'bogo-translations' ); + var element = document.getElementById( 'bogo-translations' ); // The element to be appended var child = document.createElement( 'LI' ); @@ -81,11 +79,8 @@ function init_bogo_admin() { }; } - - if ( 'bogo-texts' == bogo.pagenow ) { - window.onbeforeunload = function( event ) { var changed = false; @@ -101,13 +96,10 @@ function init_bogo_admin() { } }; - - document.getElementById( 'bogo-terms-translation' ).onsubmit = function(){ window.onbeforeunload = function () {}; }; - var select_local = document.getElementById( 'select-locale' ); select_local.addEventListener( 'change',function(){ location = 'admin.php?page=bogo-texts&locale=' + select_local.value; From d08e0c54d917edfc436b4cb81da23989619cad31 Mon Sep 17 00:00:00 2001 From: itpixelz Date: Sat, 9 May 2020 03:02:04 +0500 Subject: [PATCH 07/12] Enqueue minified Js file --- admin/admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/admin.php b/admin/admin.php index f10b134..ab2308d 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -36,7 +36,7 @@ function bogo_admin_enqueue_scripts( $hook_suffix ) { } wp_enqueue_script( 'bogo-admin', - plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ), + plugins_url( 'admin/includes/js/admin.min.js', BOGO_PLUGIN_BASENAME ), array( 'jquery' ), BOGO_VERSION, true ); From ac0b41ffcd689496a6cf0784d6fb79df7d6352a8 Mon Sep 17 00:00:00 2001 From: itpixelz Date: Sat, 9 May 2020 03:02:50 +0500 Subject: [PATCH 08/12] Use TypeScript file for development --- admin/includes/js/admin.js | 112 --------------------------------- admin/includes/ts/admin.ts | 123 +++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 112 deletions(-) delete mode 100644 admin/includes/js/admin.js create mode 100644 admin/includes/ts/admin.ts diff --git a/admin/includes/js/admin.js b/admin/includes/js/admin.js deleted file mode 100644 index a89dd86..0000000 --- a/admin/includes/js/admin.js +++ /dev/null @@ -1,112 +0,0 @@ -function init_bogo_admin() { - - if ( typeof bogo === 'undefined' || bogo === null ) { - return; - } - - bogo.langName = function( locale ) { - return bogo.availableLanguages[ locale ] || ''; - }; - - bogo.apiSettings.getRoute = function( path ) { - var url = bogo.apiSettings.root; - url = url.replace( bogo.apiSettings.namespace, bogo.apiSettings.namespace + path ); - - return url; - }; - - var bogo_add_translation = document.getElementById( 'bogo-add-translation' ); - - if ( bogo_add_translation ) { - - bogo_add_translation.onclick = function() { - - if ( !bogo.currentPost.postId ) { - return; - } - - var locale = document.getElementById( 'bogo-translations-to-add' ).value; - var rest_url = bogo.apiSettings.getRoute( '/posts/' + bogo.currentPost.postId + '/translations/' + locale ); - var spinner_element = document.getElementById( 'bogo-add-translation' ).nextElementSibling; - - spinner_element.style.visibility = 'visible'; - - var httpRequest = new XMLHttpRequest(); - httpRequest.onreadystatechange = function( data ) { - - if ( httpRequest.readyState == XMLHttpRequest.DONE ) { // XMLHttpRequest.DONE == 4 - - if ( httpRequest.status == 200 ) { - - var response = JSON.parse( httpRequest.response ); - var post = response[locale]; - - if ( !post ) { - return; - } - - // The element into which appending will be done - var element = document.getElementById( 'bogo-translations' ); - - // The element to be appended - var child = document.createElement( 'LI' ); - var output = post.title.rendered; - output += ' ' + bogo.l10n.targetBlank + ''; - child.innerHTML = '' + output + ' [' + bogo.availableLanguages[locale] + ']'; - - // append - element.appendChild( child ); - - // remove appended option - document.querySelector( '#bogo-translations-to-add option[value="' + locale + '"]' ).remove(); - - var langs = document.getElementById( 'bogo-translations-to-add' ); - - if ( !langs.options.length ) { - document.getElementById( 'bogo-add-translation-actions' ).remove(); - } - } - - spinner_element.style.visibility = 'hidden'; - } - }; - - httpRequest.open( 'POST', rest_url ); - httpRequest.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' ); - httpRequest.setRequestHeader( 'X-WP-Nonce', bogo.apiSettings.nonce ); - httpRequest.send(); - - }; - } - - if ( 'bogo-texts' == bogo.pagenow ) { - - window.onbeforeunload = function( event ) { - var changed = false; - - document.querySelectorAll( "#bogo-terms-translation input[type=text]" ).forEach( text => { - if ( text.defaultValue != text.value ) { - changed = true; - } - }); - - if ( changed ) { - event.returnValue = bogo.l10n.saveAlert; - return bogo.l10n.saveAlert; - } - }; - - document.getElementById( 'bogo-terms-translation' ).onsubmit = function(){ - window.onbeforeunload = function () {}; - }; - - var select_local = document.getElementById( 'select-locale' ); - select_local.addEventListener( 'change',function(){ - location = 'admin.php?page=bogo-texts&locale=' + select_local.value; - }); - - } -} - -// fire -init_bogo_admin(); diff --git a/admin/includes/ts/admin.ts b/admin/includes/ts/admin.ts new file mode 100644 index 0000000..093e352 --- /dev/null +++ b/admin/includes/ts/admin.ts @@ -0,0 +1,123 @@ +import apiFetch from '@wordpress/api-fetch'; + +interface bogoObject { + langName: any; + availableLanguages: any; + apiSettings: any; + currentPost: any; + l10n: any; + pagenow: any; +} + +declare var bogo: bogoObject; + +(function () { + + if (typeof bogo === 'undefined' || bogo === null) { + return; + } + + bogo.langName = function (locale: any) { + return bogo.availableLanguages[locale] || ''; + }; + + bogo.apiSettings.getRoute = function (path: any) { + let url = bogo.apiSettings.root; + url = url.replace(bogo.apiSettings.namespace, bogo.apiSettings.namespace + path); + + return url; + }; + + const bogo_add_translation = document.querySelector('#bogo-add-translation'); + + if (bogo_add_translation) { + + bogo_add_translation.addEventListener('click', function () { + + if (!bogo.currentPost.postId) { + return; + } + + const locale: any = (document.querySelector('#bogo-translations-to-add')).value; + const rest_url: any = bogo.apiSettings.getRoute('/posts/' + bogo.currentPost.postId + '/translations/' + locale); + const spinner_element: any = document.querySelector('#bogo-add-translation').nextElementSibling; + + spinner_element.style.visibility = 'visible'; + + const httpRequest = new XMLHttpRequest(); + httpRequest.onreadystatechange = function (data) { + + if (httpRequest.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4 + + if (httpRequest.status == 200) { + + const response = JSON.parse(httpRequest.response); + const post = response[locale]; + + if (!post) { + return; + } + + // The element into which appending will be done + const element = document.getElementById('bogo-translations'); + + // The element to be appended + let child = document.createElement('LI'); + let output = post.title.rendered; + output += ' ' + bogo.l10n.targetBlank + ''; + child.innerHTML = '' + output + ' [' + bogo.availableLanguages[locale] + ']'; + + // append + element.appendChild(child); + + // remove appended option + document.querySelector('#bogo-translations-to-add option[value="' + locale + '"]').remove(); + + const langs: any = document.querySelector('#bogo-translations-to-add'); + + if (!langs.options.length) { + document.querySelector('#bogo-add-translation-actions').remove(); + } + } + + spinner_element.style.visibility = 'hidden'; + } + } + + httpRequest.open('POST', rest_url); + httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + httpRequest.setRequestHeader('X-WP-Nonce', bogo.apiSettings.nonce); + httpRequest.send(); + + }); + } + + if ('bogo-texts' == bogo.pagenow) { + + window.onbeforeunload = function (event: any) { + let changed = false; + + document.querySelectorAll("#bogo-terms-translation input[type=text]").forEach((text: any) => { + if (text.defaultValue != text.value) { + changed = true; + } + }); + + if (changed) { + event.returnValue = bogo.l10n.saveAlert; + return bogo.l10n.saveAlert; + } + }; + + const bogo_terms = (document.querySelector('#bogo-terms-translation')); + bogo_terms.addEventListener('submit', function () { + window.onbeforeunload = function () { + }; + }); + + const select_local = (document.querySelector('#select-locale')); + select_local.addEventListener('change', function () { + window.location.href = 'admin.php?page=bogo-texts&locale=' + select_local.value; + }); + } +})(); From f8e9f78f59ce41c678a556959d85aab0a61143e7 Mon Sep 17 00:00:00 2001 From: itpixelz Date: Sat, 9 May 2020 03:03:46 +0500 Subject: [PATCH 09/12] Use gulp for TypeScript build --- gulpfile.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 gulpfile.js diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..319a34d --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,29 @@ +'use strict'; + +// Load plugins +const gulp = require('gulp'); +const rename = require('gulp-rename'); +const uglify = require('gulp-uglify'); +const ts = require('gulp-typescript'); + +// JS task +function js() { + return gulp.src([ + './admin/includes/ts/*.ts', + ]).pipe(ts({ + noImplicitAny: true, + })).pipe(uglify()).pipe(rename({ + suffix: '.min', + })).pipe(gulp.dest('./admin/includes/js')); +} + +// Watch files +function watchFiles() { + gulp.watch(['./admin/includes/ts/*'], js); +} + +// Define complex tasks +const build = gulp.series(gulp.parallel(js)); +const watch = gulp.series(build, gulp.parallel(watchFiles)); + +exports.watch = watch; From cd202d69ff3f7682f9d77f3a4f3edb60aa94a82d Mon Sep 17 00:00:00 2001 From: itpixelz Date: Sat, 9 May 2020 03:04:00 +0500 Subject: [PATCH 10/12] Use minified js file --- admin/includes/js/admin.min.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 admin/includes/js/admin.min.js diff --git a/admin/includes/js/admin.min.js b/admin/includes/js/admin.min.js new file mode 100644 index 0000000..4eb8e3f --- /dev/null +++ b/admin/includes/js/admin.min.js @@ -0,0 +1 @@ +"use strict";exports.__esModule=!0,function(){var e,t;"undefined"!=typeof bogo&&null!==bogo&&(bogo.langName=function(e){return bogo.availableLanguages[e]||""},bogo.apiSettings.getRoute=function(e){return bogo.apiSettings.root.replace(bogo.apiSettings.namespace,bogo.apiSettings.namespace+e)},(e=document.querySelector("#bogo-add-translation"))&&e.addEventListener("click",function(){var r,e,i,s;bogo.currentPost.postId&&(r=document.querySelector("#bogo-translations-to-add").value,e=bogo.apiSettings.getRoute("/posts/"+bogo.currentPost.postId+"/translations/"+r),(i=document.querySelector("#bogo-add-translation").nextElementSibling).style.visibility="visible",(s=new XMLHttpRequest).onreadystatechange=function(e){if(s.readyState==XMLHttpRequest.DONE){if(200==s.status){var t=JSON.parse(s.response)[r];if(!t)return;var o=document.getElementById("bogo-translations"),n=document.createElement("LI"),a=t.title.rendered;a+=' '+bogo.l10n.targetBlank+"",n.innerHTML=''+a+" ["+bogo.availableLanguages[r]+"]",o.appendChild(n),document.querySelector('#bogo-translations-to-add option[value="'+r+'"]').remove(),document.querySelector("#bogo-translations-to-add").options.length||document.querySelector("#bogo-add-translation-actions").remove()}i.style.visibility="hidden"}},s.open("POST",e),s.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),s.setRequestHeader("X-WP-Nonce",bogo.apiSettings.nonce),s.send())}),"bogo-texts"==bogo.pagenow&&(window.onbeforeunload=function(e){var t=!1;if(document.querySelectorAll("#bogo-terms-translation input[type=text]").forEach(function(e){e.defaultValue!=e.value&&(t=!0)}),t)return e.returnValue=bogo.l10n.saveAlert,bogo.l10n.saveAlert},document.querySelector("#bogo-terms-translation").addEventListener("submit",function(){window.onbeforeunload=function(){}}),(t=document.querySelector("#select-locale")).addEventListener("change",function(){window.location.href="admin.php?page=bogo-texts&locale="+t.value})))}(); \ No newline at end of file From 231239d217893f7dc5fe8dd6be439abc0a7a35b9 Mon Sep 17 00:00:00 2001 From: itpixelz Date: Sat, 9 May 2020 03:05:25 +0500 Subject: [PATCH 11/12] Add TypeScript and Gulp dependencies --- package.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b0f45fd..60c4c1e 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,15 @@ }, "homepage": "https://github.com/takayukister/bogo#readme", "devDependencies": { - "@wordpress/scripts": "6.1.0" + "@wordpress/scripts": "6.1.0", + "@types/jquery": "^3.3.38", + "gulp": "^4.0.2", + "gulp-rename": "1.4.0", + "gulp-uglify": "3.0.2" + }, + "dependencies": { + "@wordpress/api-fetch": "^3.14.0", + "gulp-typescript": "^6.0.0-alpha.1", + "typescript": "^3.8.3" } } From 3756bde6c0e6f715ebb1ffe16355583d7f3b714f Mon Sep 17 00:00:00 2001 From: itpixelz Date: Sat, 9 May 2020 03:14:04 +0500 Subject: [PATCH 12/12] Remove unnecessary import --- admin/includes/js/admin.min.js | 2 +- admin/includes/ts/admin.ts | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/admin/includes/js/admin.min.js b/admin/includes/js/admin.min.js index 4eb8e3f..4c2017f 100644 --- a/admin/includes/js/admin.min.js +++ b/admin/includes/js/admin.min.js @@ -1 +1 @@ -"use strict";exports.__esModule=!0,function(){var e,t;"undefined"!=typeof bogo&&null!==bogo&&(bogo.langName=function(e){return bogo.availableLanguages[e]||""},bogo.apiSettings.getRoute=function(e){return bogo.apiSettings.root.replace(bogo.apiSettings.namespace,bogo.apiSettings.namespace+e)},(e=document.querySelector("#bogo-add-translation"))&&e.addEventListener("click",function(){var r,e,i,s;bogo.currentPost.postId&&(r=document.querySelector("#bogo-translations-to-add").value,e=bogo.apiSettings.getRoute("/posts/"+bogo.currentPost.postId+"/translations/"+r),(i=document.querySelector("#bogo-add-translation").nextElementSibling).style.visibility="visible",(s=new XMLHttpRequest).onreadystatechange=function(e){if(s.readyState==XMLHttpRequest.DONE){if(200==s.status){var t=JSON.parse(s.response)[r];if(!t)return;var o=document.getElementById("bogo-translations"),n=document.createElement("LI"),a=t.title.rendered;a+=' '+bogo.l10n.targetBlank+"",n.innerHTML=''+a+" ["+bogo.availableLanguages[r]+"]",o.appendChild(n),document.querySelector('#bogo-translations-to-add option[value="'+r+'"]').remove(),document.querySelector("#bogo-translations-to-add").options.length||document.querySelector("#bogo-add-translation-actions").remove()}i.style.visibility="hidden"}},s.open("POST",e),s.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),s.setRequestHeader("X-WP-Nonce",bogo.apiSettings.nonce),s.send())}),"bogo-texts"==bogo.pagenow&&(window.onbeforeunload=function(e){var t=!1;if(document.querySelectorAll("#bogo-terms-translation input[type=text]").forEach(function(e){e.defaultValue!=e.value&&(t=!0)}),t)return e.returnValue=bogo.l10n.saveAlert,bogo.l10n.saveAlert},document.querySelector("#bogo-terms-translation").addEventListener("submit",function(){window.onbeforeunload=function(){}}),(t=document.querySelector("#select-locale")).addEventListener("change",function(){window.location.href="admin.php?page=bogo-texts&locale="+t.value})))}(); \ No newline at end of file +!function(){var e,t;"undefined"!=typeof bogo&&null!==bogo&&(bogo.langName=function(e){return bogo.availableLanguages[e]||""},bogo.apiSettings.getRoute=function(e){return bogo.apiSettings.root.replace(bogo.apiSettings.namespace,bogo.apiSettings.namespace+e)},(e=document.querySelector("#bogo-add-translation"))&&e.addEventListener("click",function(){var r,e,i,l;bogo.currentPost.postId&&(r=document.querySelector("#bogo-translations-to-add").value,e=bogo.apiSettings.getRoute("/posts/"+bogo.currentPost.postId+"/translations/"+r),(i=document.querySelector("#bogo-add-translation").nextElementSibling).style.visibility="visible",(l=new XMLHttpRequest).onreadystatechange=function(e){if(l.readyState==XMLHttpRequest.DONE){if(200==l.status){var t=JSON.parse(l.response)[r];if(!t)return;var o=document.getElementById("bogo-translations"),n=document.createElement("LI"),a=t.title.rendered;a+=' '+bogo.l10n.targetBlank+"",n.innerHTML=''+a+" ["+bogo.availableLanguages[r]+"]",o.appendChild(n),document.querySelector('#bogo-translations-to-add option[value="'+r+'"]').remove(),document.querySelector("#bogo-translations-to-add").options.length||document.querySelector("#bogo-add-translation-actions").remove()}i.style.visibility="hidden"}},l.open("POST",e),l.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),l.setRequestHeader("X-WP-Nonce",bogo.apiSettings.nonce),l.send())}),"bogo-texts"==bogo.pagenow&&(window.onbeforeunload=function(e){var t=!1;if(document.querySelectorAll("#bogo-terms-translation input[type=text]").forEach(function(e){e.defaultValue!=e.value&&(t=!0)}),t)return e.returnValue=bogo.l10n.saveAlert,bogo.l10n.saveAlert},document.querySelector("#bogo-terms-translation").addEventListener("submit",function(){window.onbeforeunload=function(){}}),(t=document.querySelector("#select-locale")).addEventListener("change",function(){window.location.href="admin.php?page=bogo-texts&locale="+t.value})))}(); \ No newline at end of file diff --git a/admin/includes/ts/admin.ts b/admin/includes/ts/admin.ts index 093e352..d1458a8 100644 --- a/admin/includes/ts/admin.ts +++ b/admin/includes/ts/admin.ts @@ -1,5 +1,3 @@ -import apiFetch from '@wordpress/api-fetch'; - interface bogoObject { langName: any; availableLanguages: any;