Created
September 15, 2015 19:24
-
-
Save MNBuyskih/13d466371bd11416c00d to your computer and use it in GitHub Desktop.
Example JS code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Класс для аналитики вебмастера | |
* @param {{ | |
* filterContainer: HTMLElement|String|jQuery | |
* tabsContainer: HTMLElement|String|jQuery | |
* dataUrl: String | |
* filtersUrl: String | |
* }} options Список параметров См. {@link AnalyticsAbstract.options}. | |
* @class | |
*/ | |
var SiteAnalytics = function (options) { | |
/** | |
* @type {{ | |
* filterContainer: HTMLElement|String|jQuery | |
* tabsContainer: HTMLElement|String|jQuery | |
* dataUrl: String | |
* filtersUrl: String | |
* }} | |
*/ | |
this.options = options; | |
var superListEvents = this.listEvents; | |
this.listEvents = function (list) { | |
superListEvents.call(this, list); | |
this.filter.on('getData', function (filter, data) { | |
var title = $('#source-list-title'), | |
clicksTitle = title.data('titleclicks'), | |
sourceTitle = title.data('titlesources'), | |
currentTableId = $(list.options.table).closest('table').attr('id'), | |
tableId = 'ad_sources_sites', | |
templateId = 'site-template'; | |
title.html(sourceTitle); | |
// Если выбран сайт - показываем список рекламных мест | |
if (+data['website']) { | |
tableId = 'ad_sources_adPlaces'; | |
templateId = 'adPlace-template'; | |
title.html(sourceTitle); | |
} | |
// Если выбрано рекламное место - показываем список кликов для этого места | |
if (+data.adPlace) { | |
tableId = 'ad_sources_clicks'; | |
templateId = 'click-template'; | |
// Заменяем заголовок списка | |
title.html(clicksTitle); | |
} | |
if (currentTableId !== tableId) { | |
list.options.table = $('.body', '#' + tableId); | |
list.options.template = $('#' + templateId); | |
// Прячем все таблицы, оставляем только нужную | |
$.each([$('#ad_sources_sites'), $('#ad_sources_adPlaces'), $('#ad_sources_clicks')], function () { | |
if ($(this).attr('id') !== tableId) { | |
$(this).hide().find('.body').html(''); | |
} else { | |
$(this).show(); | |
} | |
}); | |
} | |
}); | |
}; | |
this.init(); | |
this.loadFilters(); | |
}; | |
SiteAnalytics.prototype = AnalyticsAbstract.prototype; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment