moved messages to script variables
This commit is contained in:
parent
cc4951f515
commit
8604ed72a2
|
@ -1,6 +1,16 @@
|
|||
<?php
|
||||
|
||||
class FreshExtension_kagiSummarizer_Controller extends Minz_ActionController {
|
||||
public function kagiStringsAction() {
|
||||
$this->view->kagi_strings = json_encode(array(
|
||||
'loading_summary' => _t('ext.kagiSummarizer.ui.loading_summary'),
|
||||
'error' => _t('ext.kagiSummarizer.ui.error')
|
||||
));
|
||||
$this->view->_layout(false);
|
||||
$this->view->_path('kagiSummarizer/strings.js');
|
||||
header('Content-Type: application/javascript; charset=UTF-8');
|
||||
}
|
||||
|
||||
public function summarizeAction() {
|
||||
$this->view->_layout(false);
|
||||
|
||||
|
@ -34,14 +44,10 @@ class FreshExtension_kagiSummarizer_Controller extends Minz_ActionController {
|
|||
'Authorization: ' . $kagi_token
|
||||
));
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_HEADER, true);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
|
||||
$response_body = substr($response, $header_size);
|
||||
|
||||
echo json_encode(array(
|
||||
'response' => json_decode($response_body),
|
||||
'response' => json_decode($response),
|
||||
'status' => curl_getinfo($curl, CURLINFO_HTTP_CODE)
|
||||
));
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ class KagiSummarizerExtension extends Minz_Extension {
|
|||
$this->registerTranslates();
|
||||
$this->registerHook('entry_before_display', [$this, 'addSummarizeButton']);
|
||||
Minz_View::appendScript($this->getFileUrl('script.js', 'js'), false, false, false);
|
||||
Minz_View::appendScript(_url('kagiSummarizer', 'kagiStrings'), false, true, false);
|
||||
$this->registerViews();
|
||||
$this->registerController('kagiSummarizer');
|
||||
}
|
||||
|
||||
|
@ -30,7 +32,10 @@ class KagiSummarizerExtension extends Minz_Extension {
|
|||
'params' => array(
|
||||
'id' => $entry->id()
|
||||
)));
|
||||
$entry->_content('<p class="kagi-summary"><a data-loading="' . htmlspecialchars(_t('ext.kagiSummarizer.ui.loading_summary')) . '" data-error="' . htmlspecialchars(_t('ext.kagiSummarizer.ui.error')) . '" class="btn" href="' . $url .'">' . _t('ext.kagiSummarizer.ui.summarize_button') . '</a></p>' . $entry->content());
|
||||
$entry->_content(
|
||||
'<p class="kagi-summary"><a class="btn" href="' . $url .'">'
|
||||
. _t('ext.kagiSummarizer.ui.summarize_button') . '</a></p>'
|
||||
. $entry->content());
|
||||
return $entry;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,13 +21,11 @@ function configureSummarizeButtons() {
|
|||
|
||||
function summarizeButtonClick(button) {
|
||||
var url = button.href;
|
||||
var loadingMsg = button.dataset.loading;
|
||||
var errorMsg = button.dataset.error;
|
||||
var container = button.parentNode;
|
||||
|
||||
container.classList.add('alert');
|
||||
container.classList.add('alert-warn');
|
||||
container.innerHTML = loadingMsg;
|
||||
container.innerHTML = kagi_strings.loading_summary;
|
||||
|
||||
var request = new XMLHttpRequest();
|
||||
request.open('POST', url, true);
|
||||
|
@ -62,7 +60,7 @@ function summarizeButtonClick(button) {
|
|||
badAjax(this.status == 403);
|
||||
container.classList.remove('alert-warn');
|
||||
container.classList.add('alert-error');
|
||||
container.innerHTML = errorMsg;
|
||||
container.innerHTML = kagi_strings.error;
|
||||
}
|
||||
|
||||
request.setRequestHeader('Content-Type', 'application/json');
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
var kagi_strings = <?= htmlspecialchars_decode(urldecode($this->kagi_strings)) ?>
|
Loading…
Reference in New Issue