mirror of
https://gitverse.ru/kpa39l/yaru.nixg.ru.git
synced 2026-09-29 09:55:06 +00:00
138 lines
4.9 KiB
JavaScript
138 lines
4.9 KiB
JavaScript
/**
|
|
* Добавляет/удаляет виджет из каталога
|
|
*/
|
|
Friends.WidgetsCatalog = function(element, params) {
|
|
/** control container */
|
|
this.control = element;
|
|
this.params = params;
|
|
|
|
this.init();
|
|
}
|
|
|
|
Friends.WidgetsCatalog.prototype = {
|
|
init: function() {
|
|
// табы и соответствующие им картинки страниц с виджетами
|
|
var tab_my = y5.Dom.getDescendant(this.control, 'li', 'tab-my');
|
|
var widgets_my = y5.Dom.getDescendant(this.control, 'ul', 'b-widgets-catalog-my');
|
|
var tab_i = y5.Dom.getDescendant(this.control, 'li', 'tab-i');
|
|
var widgets_i = y5.Dom.getDescendant(this.control, 'ul', 'b-widgets-catalog-i');
|
|
|
|
var mode_whatsnew = function() {
|
|
y5.Classes.remove(tab_i, 'active');
|
|
y5.Classes.add(tab_my, 'active');
|
|
y5.Classes.add(widgets_i, 'i-hidden');
|
|
y5.Classes.remove(widgets_my, 'i-hidden');
|
|
}
|
|
|
|
var mode_profile = function() {
|
|
y5.Classes.remove(tab_my, 'active');
|
|
y5.Classes.add(tab_i, 'active');
|
|
y5.Classes.add(widgets_my, 'i-hidden');
|
|
y5.Classes.remove(widgets_i, 'i-hidden');
|
|
}
|
|
|
|
// переключение табов
|
|
y5.Events.observe('click', function() {
|
|
mode_whatsnew();
|
|
}, tab_my, true, this);
|
|
y5.Events.observe('click', function() {
|
|
mode_profile();
|
|
}, tab_i, true, this);
|
|
|
|
// виджеты
|
|
var widgets = y5.Dom.getDescendants(this.control, 'div', 'widget');
|
|
widgets.forEach(function(widget) {
|
|
this.initWidget(widget);
|
|
}, this);
|
|
|
|
var url = new y5.URL(document.location);
|
|
if (url.Query.tab == "whatsnew") {
|
|
mode_whatsnew();
|
|
}
|
|
},
|
|
|
|
initWidget: function(widget) {
|
|
// включить/выключить виджет
|
|
y5.Events.observe('click', function() {
|
|
this.addRemoveWidget(widget);
|
|
}, widget, true, this);
|
|
|
|
// контейнер виджета
|
|
var controlContainer = y5.Dom.getAncestor(widget, 'li', 'item');
|
|
// при наведении навешиваем подсветку
|
|
y5.Events.observe('mouseover', function(e, element) {
|
|
y5.Classes.add(element, 'hover');
|
|
}, controlContainer, true );
|
|
// при уведении мыши убираем подсветку
|
|
y5.Events.observe('mouseout', function(e, element) {
|
|
y5.Classes.remove(element, 'hover');
|
|
}, controlContainer, true);
|
|
},
|
|
|
|
addRemoveWidget: function(widget) {
|
|
var toShow, btnFromContainer, btnToContainer;
|
|
var params = widget.onclick();
|
|
|
|
// прогрессбар
|
|
var block_progress = y5.Dom.getDescendant(widget, 'li', 'progress');
|
|
|
|
if (y5.Classes.test(widget, 'active')) {
|
|
toShow = 'no';
|
|
btnFromContainer = y5.Dom.getDescendant(widget, 'li', 'status-remove');
|
|
btnToContainer = y5.Dom.getDescendant(widget, 'li', 'status-add');
|
|
} else {
|
|
toShow = 'yes';
|
|
btnFromContainer = y5.Dom.getDescendant(widget, 'li', 'status-add');
|
|
btnToContainer = y5.Dom.getDescendant(widget, 'li', 'status-remove');
|
|
}
|
|
|
|
y5.Classes.add(btnFromContainer, 'i-hidden');
|
|
// на время ajax-запроса показываем прогрессбар
|
|
y5.Classes.remove(block_progress, 'i-hidden');
|
|
|
|
var data = {
|
|
id: params.id,
|
|
show: params.id + '=' + toShow,
|
|
sk: this.params.sk
|
|
};
|
|
|
|
// функция на успех запроса
|
|
function responceOK(html, trace) {
|
|
// скрываем прогреесбар
|
|
y5.Classes.add(block_progress, 'i-hidden');
|
|
// показываем кнопку
|
|
if (html != 'Error') {
|
|
y5.Classes.remove(btnToContainer, 'i-hidden');
|
|
y5.Classes.toggle(widget, 'active');
|
|
} else {
|
|
y5.Classes.remove(btnFromContainer, 'i-hidden');
|
|
}
|
|
}
|
|
|
|
// функция на неудачу запроса
|
|
function responceError(trace) {
|
|
// скрываем прогреесбар
|
|
y5.Classes.add(block_progress, 'i-hidden');
|
|
// показываем прежнюю кнопку
|
|
y5.Classes.remove(btnFromContainer, 'i-hidden');
|
|
};
|
|
|
|
jQuery.ajax({
|
|
url: friendsURL('ajax/widgets_options_do_catalog'),
|
|
data: data,
|
|
dataType: 'json',
|
|
type: 'post',
|
|
success: function( response ){
|
|
responceOK( response.html);
|
|
},
|
|
error: responceError
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
y5.require (
|
|
['Ajax', 'AjaxObject', 'Dom', 'Events', 'Classes'],
|
|
function() {y5.loaded('{Friends}.WidgetsCatalog')}
|
|
);
|