'container' => [
'singletons' => [
'fast-edit' => function () {
return new \frontend\services\editing\FastEdit();
},
'hide' => function () {
return new \frontend\services\editing\HideSubject();
}
],
],
Yii::$container->get($type)
function wrapLinks() {
let selector = document.querySelectorAll('.article-comment-text.fl'),
pattern = /(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z()]{1,6}\b([-a-zA-Z0-9()@:;%_\+.~#?&//=]*)/g,
imgPattern = /<img[^>]+src="?([^"\s]+)"?\s*(\/)?/g;
selector.forEach(element => {
let text = element.innerHTML;
let needless = [];
let urls = text.match(pattern);
let links = element.querySelectorAll('a[href]');
if (urls) {
while (src = imgPattern.exec(text)) {
needless.push(src[1]);
}
if (links.length) {
links.forEach(elem => {
needless.push(elem.href);
needless.push(elem.innerHTML);
});
}
urls = urls.filter(el => {
return needless.indexOf(el) < 0;
});
urls.forEach(elem => {
if (elem.match(/^https?\:\/\//i)) {
text = text.replace(elem, '<a href="$&" target="_blank">$&</a>');
} else {
text = text.replace(elem, '<a href="//$&" target="_blank">$&</a>');
}
});
}
element.innerHTML = text;
});
}
let searchRequest = null,
searchResult = document.querySelector('input[name="search"]');
searchResult.addEventListener('keyup', function(e) {
let cityName = $(this).val(),
searchInput = $(this),
formAction = $(this).parent().attr('action'),
formMethod = $(this).parent().attr('method'),
resultBox = $(this).parent().parent().find('.search-form-result'),
searchForm = $('.search-form-result-city');
if (searchForm.hasClass('selected-city') && (e.keyCode == 38 || e.keyCode == 40)) {
return false;
}
if (searchRequest !== null) {
searchRequest.abort();
}
searchRequest = new XMLHttpRequest();
searchRequest.open(formMethod, formAction + "?cityName=" + cityName, true);
searchRequest.onload = function() {
if (this.status >= 200 && this.status < 400) {
let data = this.response;
searchInput.addClass('active');
resultBox.find('.scrollbar-search-form-result').html(data);
resultBox.show();
if (e.keyCode === 13) {
let url = $.parseHTML(data)[1]['children'][0]['attributes'][0]['value'];
if (url) {
window.location = url;
return false;
}
}
if (!searchForm.hasClass('selected-city') && e.code == 'ArrowUp') {
let last = document.querySelector('.search-form-result-city:last-child');
last.className += ' selected-city';
}
if (!searchForm.hasClass('selected-city') && e.code == 'ArrowDown') {
let first = document.querySelector('.search-form-result-city:first-child');
first.className += ' selected-city';
}
} else {
resultBox.hide();
searchInput.removeClass('active');
}
}
searchRequest.send();
});
function addList(arr, thisClass) {
if (Array.isArray(arr) && arr.length) {
arr.forEach(function(value, index) {
$('.' + thisClass + '-check-class').each(function(){
if ($(this).val() == value) {
$(this).addClass("active-color");
$(this).parent().addClass("active");
}
});
})
}
}
<?php if (!empty($color_names)) { ?>
let arr = <?= json_encode($color_names); ?>,
thisClass = 'color';
addList(arr, thisClass);
<?php } ?>