Initial import
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
use app\models\Ts;
|
||||
use app\models\Articles;
|
||||
|
||||
$lg = Yii::$app->language;
|
||||
/**
|
||||
* @var $partner_id
|
||||
*/
|
||||
|
||||
?>
|
||||
<div class="content">
|
||||
<div class="filter-buttons top50">
|
||||
<button data-filter=""><?= Ts::get(5) ?></button>
|
||||
<button data-filter="art_table=news"><?= Ts::get(6) ?></button>
|
||||
<button data-filter="art_table=events"><?= Ts::get(7) ?></button>
|
||||
<button data-filter="art_table=campaigns"><?= Ts::get(8) ?></button>
|
||||
<button data-switch="order_title=title<?= $lg == 'en' ? '_en' : '' ?>"><?= Ts::get(9) ?></button>
|
||||
</div>
|
||||
<div class="top50"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="content-out" id="list-article"></div>
|
||||
<div class="content">
|
||||
<div id="pagination" class="filter-buttons flex-center top50"></div>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
let articleFilter = {}
|
||||
|
||||
<?php if(!empty($partner_id)):?>
|
||||
articleFilter['partner_id'] = 'partner_id=<?= $partner_id?>';
|
||||
<?php endif; ?>
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
if (window.location.search) {
|
||||
let serialize = atob(window.location.search.substr(1))
|
||||
try {
|
||||
articleFilter = JSON.parse(serialize)
|
||||
} catch (e) {
|
||||
console.log('Invalid query string');
|
||||
}
|
||||
}
|
||||
console.log(articleFilter);
|
||||
document.querySelector(`[data-filter="${articleFilter['art_table'] || ''}"]`).classList.add('active')
|
||||
let switcher = document.querySelector(`[data-switch="${articleFilter['switch_on'] || ''}"]`);
|
||||
if (switcher)
|
||||
switcher.classList.add('switch_on')
|
||||
filter();
|
||||
})
|
||||
|
||||
document.querySelectorAll('[data-filter]').forEach(button => {
|
||||
button.addEventListener('click', function () {
|
||||
const active = document.querySelector('[data-filter].active');
|
||||
active.classList.remove('active');
|
||||
button.classList.add('active');
|
||||
button.scrollIntoView()
|
||||
articleFilter['art_table'] = button.dataset.filter || null
|
||||
filter();
|
||||
})
|
||||
})
|
||||
|
||||
document.querySelectorAll('[data-switch]').forEach(button => {
|
||||
button.addEventListener('click', () => {
|
||||
if (!button.classList.contains('switch_on')) {
|
||||
button.classList.add('switch_on')
|
||||
articleFilter['switch_on'] = button.dataset.switch
|
||||
} else {
|
||||
button.classList.remove('switch_on')
|
||||
articleFilter['switch_on'] = null
|
||||
}
|
||||
filter()
|
||||
})
|
||||
})
|
||||
|
||||
function filter() {
|
||||
let serializeArray = [];
|
||||
Object.keys(articleFilter).forEach(key => {
|
||||
if (articleFilter[key])
|
||||
serializeArray.push(articleFilter[key])
|
||||
})
|
||||
let serialize = serializeArray.join('&')
|
||||
if (serialize)
|
||||
window.history.replaceState(null, null, `?${btoa(JSON.stringify(articleFilter))}`);
|
||||
contentRequest(`/<?= $lg ?>/remote/get-articles/?${serialize}`, '#list-article', '#pagination', page => {
|
||||
articleFilter['page'] = `page=${page}`;
|
||||
filter()
|
||||
})
|
||||
}
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user