2020-05-08 06:37:58 +02:00
|
|
|
import * as google_analytics from './google-analytics.js';
|
2017-08-01 07:21:44 +02:00
|
|
|
import blueslip from './../blueslip';
|
|
|
|
|
|
|
|
import { path_parts } from './landing-page';
|
|
|
|
|
|
|
|
|
|
|
|
// these constants are populated immediately with data from the DOM on page load
|
|
|
|
// name -> display name
|
2020-02-12 06:45:30 +01:00
|
|
|
const INTEGRATIONS = new Map();
|
2020-02-12 06:49:41 +01:00
|
|
|
const CATEGORIES = new Map();
|
2017-08-01 07:21:44 +02:00
|
|
|
|
|
|
|
function load_data() {
|
2020-07-02 01:45:54 +02:00
|
|
|
$('.integration-lozenge').toArray().forEach((integration) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const name = $(integration).data('name');
|
|
|
|
const display_name = $(integration).find('.integration-name').text().trim();
|
2017-08-01 07:21:44 +02:00
|
|
|
|
|
|
|
if (display_name && name) {
|
2020-02-12 06:45:30 +01:00
|
|
|
INTEGRATIONS.set(name, display_name);
|
2017-08-01 07:21:44 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$('.integration-category').toArray().forEach((category) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const name = $(category).data('category');
|
|
|
|
const display_name = $(category).text().trim();
|
2017-08-01 07:21:44 +02:00
|
|
|
|
|
|
|
if (display_name && name) {
|
2020-02-12 06:49:41 +01:00
|
|
|
CATEGORIES.set(name, display_name);
|
2017-08-01 07:21:44 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const INITIAL_STATE = {
|
2017-08-01 07:21:44 +02:00
|
|
|
category: 'all',
|
|
|
|
integration: null,
|
|
|
|
query: '',
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let state = Object.assign({}, INITIAL_STATE);
|
2017-08-01 07:21:44 +02:00
|
|
|
|
|
|
|
|
2017-08-09 02:33:53 +02:00
|
|
|
function adjust_font_sizing() {
|
2020-07-02 01:45:54 +02:00
|
|
|
$('.integration-lozenge').toArray().forEach((integration) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const $integration_name = $(integration).find('.integration-name');
|
|
|
|
const $integration_category = $(integration).find('.integration-category');
|
2017-08-09 02:33:53 +02:00
|
|
|
|
|
|
|
// if the text has wrapped to two lines, decrease font-size
|
|
|
|
if ($integration_name.height() > 30) {
|
|
|
|
$integration_name.css('font-size', '1em');
|
|
|
|
if ($integration_name.height() > 30) {
|
2018-05-06 21:43:17 +02:00
|
|
|
$integration_name.css('font-size', '.95em');
|
2017-08-09 02:33:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($integration_category.height() > 30) {
|
|
|
|
$integration_category.css('font-size', '.8em');
|
|
|
|
if ($integration_category.height() > 30) {
|
|
|
|
$integration_category.css('font-size', '.75em');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-01 07:21:44 +02:00
|
|
|
function update_path() {
|
2019-11-02 00:06:25 +01:00
|
|
|
let next_path;
|
2017-08-01 07:21:44 +02:00
|
|
|
if (state.integration) {
|
|
|
|
next_path = $('.integration-lozenge[data-name="' + state.integration + '"]')
|
|
|
|
.closest('a').attr('href');
|
|
|
|
} else if (state.category) {
|
|
|
|
next_path = $('.integration-category[data-category="' + state.category + '"]')
|
|
|
|
.closest('a').attr('href');
|
|
|
|
} else {
|
|
|
|
next_path = '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
window.history.pushState(state, '', next_path);
|
2020-05-08 06:37:58 +02:00
|
|
|
google_analytics.config({page_path: next_path});
|
2017-08-01 07:21:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function update_categories() {
|
|
|
|
$('.integration-lozenges').css('opacity', 0);
|
|
|
|
|
|
|
|
$('.integration-category').removeClass('selected');
|
|
|
|
$('[data-category="' + state.category + '"]').addClass('selected');
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const $dropdown_label = $('.integration-categories-dropdown .dropdown-category-label');
|
2017-08-01 07:21:44 +02:00
|
|
|
if (state.category === INITIAL_STATE.category) {
|
|
|
|
$dropdown_label.text(i18n.t('Filter by category'));
|
|
|
|
} else {
|
2020-02-12 06:49:41 +01:00
|
|
|
$dropdown_label.text(CATEGORIES.get(state.category));
|
2017-08-01 07:21:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$('.integration-lozenges').animate(
|
|
|
|
{ opacity: 1 },
|
2020-07-02 02:16:03 +02:00
|
|
|
{ duration: 400 },
|
2017-08-01 07:21:44 +02:00
|
|
|
);
|
2017-08-09 02:36:29 +02:00
|
|
|
|
|
|
|
adjust_font_sizing();
|
2017-08-01 07:21:44 +02:00
|
|
|
}
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
const update_integrations = _.debounce(() => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const max_scrollY = window.scrollY;
|
2017-08-01 07:21:44 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const integrations = $('.integration-lozenges').children().toArray();
|
2020-07-02 01:45:54 +02:00
|
|
|
integrations.forEach((integration) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const $integration = $(integration).find('.integration-lozenge');
|
|
|
|
const $integration_category = $integration.find('.integration-category');
|
2017-08-01 07:21:44 +02:00
|
|
|
|
|
|
|
if (state.category !== 'all') {
|
|
|
|
$integration_category.css('display', 'none');
|
|
|
|
$integration.addClass('without-category');
|
|
|
|
} else {
|
|
|
|
$integration_category.css('display', '');
|
|
|
|
$integration.removeClass('without-category');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$integration.hasClass('integration-create-your-own')) {
|
2020-02-12 06:45:30 +01:00
|
|
|
const display_name = INTEGRATIONS.get($integration.data('name'));
|
2019-11-02 00:06:25 +01:00
|
|
|
const display =
|
2018-06-25 17:34:11 +02:00
|
|
|
common.phrase_match(state.query, display_name) &&
|
2020-02-12 06:49:41 +01:00
|
|
|
($integration.data('categories').includes(CATEGORIES.get(state.category)) ||
|
2017-08-01 07:21:44 +02:00
|
|
|
state.category === 'all');
|
|
|
|
|
|
|
|
if (display) {
|
|
|
|
$integration.css('display', 'inline-block');
|
|
|
|
} else {
|
|
|
|
$integration.css('display', 'none');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.body.scrollTop = Math.min(window.scrollY, max_scrollY);
|
|
|
|
});
|
2017-08-09 02:36:29 +02:00
|
|
|
|
|
|
|
adjust_font_sizing();
|
2017-08-01 07:21:44 +02:00
|
|
|
}, 50);
|
|
|
|
|
|
|
|
function hide_catalog_show_integration() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const $lozenge_icon = $(".integration-lozenge.integration-" + state.integration).clone(false);
|
2017-08-01 07:21:44 +02:00
|
|
|
$lozenge_icon.removeClass('legacy');
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const categories = $('.integration-' + state.integration).data('categories')
|
2017-08-01 07:21:44 +02:00
|
|
|
.slice(1, -1)
|
|
|
|
.split(',')
|
2020-07-02 01:45:54 +02:00
|
|
|
.map((category) => category.trim().slice(1, -1));
|
2017-08-01 07:21:44 +02:00
|
|
|
|
|
|
|
function show_integration(doc) {
|
2020-02-12 06:45:30 +01:00
|
|
|
$('#integration-instructions-group .name').text(INTEGRATIONS.get(state.integration));
|
2017-08-01 07:21:44 +02:00
|
|
|
$('#integration-instructions-group .categories .integration-category').remove();
|
2020-07-02 01:45:54 +02:00
|
|
|
categories.forEach((category) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let link;
|
2020-02-12 06:49:41 +01:00
|
|
|
for (const [name, display_name] of CATEGORIES) {
|
|
|
|
if (display_name === category) {
|
2017-08-01 07:21:44 +02:00
|
|
|
link = name;
|
|
|
|
}
|
2020-02-12 06:49:41 +01:00
|
|
|
}
|
2019-11-02 00:06:25 +01:00
|
|
|
const category_el = $('<a></a>')
|
2017-08-01 07:21:44 +02:00
|
|
|
.attr('href', '/integrations/' + link)
|
|
|
|
.append('<h3 class="integration-category"></h3>');
|
|
|
|
category_el.find('.integration-category')
|
|
|
|
.attr('data-category', link)
|
|
|
|
.text(category);
|
|
|
|
$('#integration-instructions-group .categories').append(category_el);
|
|
|
|
});
|
|
|
|
$('#integration-instructions-group').css({
|
|
|
|
opacity: 0,
|
2019-06-07 12:10:36 +02:00
|
|
|
display: 'flex',
|
2017-08-01 07:21:44 +02:00
|
|
|
});
|
|
|
|
$('.integration-instructions').css('display', 'none');
|
|
|
|
$('#' + state.integration + '.integration-instructions .help-content').html(doc);
|
|
|
|
$('#integration-instruction-block .integration-lozenge').remove();
|
|
|
|
$("#integration-instruction-block")
|
|
|
|
.append($lozenge_icon)
|
2019-08-15 21:17:05 +02:00
|
|
|
.css('display', 'flex');
|
2017-08-01 07:21:44 +02:00
|
|
|
$('.integration-instructions#' + state.integration).css('display', 'block');
|
|
|
|
|
|
|
|
$("html, body").animate(
|
|
|
|
{ scrollTop: 0 },
|
2020-07-02 02:16:03 +02:00
|
|
|
{ duration: 200 },
|
2017-08-01 07:21:44 +02:00
|
|
|
);
|
|
|
|
$('#integration-instructions-group').animate(
|
|
|
|
{ opacity: 1 },
|
2020-07-02 02:16:03 +02:00
|
|
|
{ duration: 300 },
|
2017-08-01 07:21:44 +02:00
|
|
|
);
|
2017-08-09 02:36:29 +02:00
|
|
|
|
|
|
|
adjust_font_sizing();
|
2017-08-01 07:21:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function hide_catalog(doc) {
|
|
|
|
$(".integration-categories-dropdown").css('display', 'none');
|
|
|
|
$(".integrations .catalog").addClass('hide');
|
|
|
|
$(".extra, #integration-main-text, #integration-search").css("display", "none");
|
|
|
|
|
|
|
|
show_integration(doc);
|
2018-06-13 00:55:44 +02:00
|
|
|
$(".main").css("visibility", "visible");
|
2017-08-01 07:21:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$.get({
|
|
|
|
url: '/integrations/doc-html/' + state.integration,
|
|
|
|
dataType: 'html',
|
|
|
|
success: hide_catalog,
|
|
|
|
error: function (err) {
|
|
|
|
blueslip.error("Integration documentation for '" + state.integration + "' not found.", err);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function hide_integration_show_catalog() {
|
|
|
|
function show_catalog() {
|
|
|
|
$("html, body").animate(
|
|
|
|
{ scrollTop: 0 },
|
2020-07-02 02:16:03 +02:00
|
|
|
{ duration: 200 },
|
2017-08-01 07:21:44 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$(".integration-categories-dropdown").css('display', '');
|
|
|
|
$(".integrations .catalog").removeClass('hide');
|
|
|
|
$(".extra, #integration-main-text, #integration-search").css("display", "block");
|
2017-08-09 02:36:29 +02:00
|
|
|
adjust_font_sizing();
|
2017-08-01 07:21:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function hide_integration() {
|
|
|
|
$('#integration-instruction-block').css('display', 'none');
|
|
|
|
$('#integration-instructions-group').css('display', 'none');
|
|
|
|
$('.inner-content').css({ padding: '' });
|
|
|
|
$("#integration-instruction-block .integration-lozenge").remove();
|
|
|
|
show_catalog();
|
|
|
|
}
|
|
|
|
|
|
|
|
hide_integration();
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_state_from_path() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const result = Object.assign({}, INITIAL_STATE);
|
2017-08-01 07:21:44 +02:00
|
|
|
result.query = state.query;
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const parts = path_parts();
|
2020-02-12 06:45:30 +01:00
|
|
|
if (parts[1] === 'doc' && INTEGRATIONS.get(parts[2])) {
|
2017-08-01 07:21:44 +02:00
|
|
|
result.integration = parts[2];
|
2020-02-12 06:49:41 +01:00
|
|
|
} else if (CATEGORIES.has(parts[1])) {
|
2017-08-01 07:21:44 +02:00
|
|
|
result.category = parts[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function render(next_state) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const previous_state = Object.assign({}, state);
|
2017-08-01 07:21:44 +02:00
|
|
|
state = next_state;
|
|
|
|
|
2018-06-13 00:55:44 +02:00
|
|
|
if (previous_state.integration !== next_state.integration &&
|
|
|
|
next_state.integration !== null) {
|
|
|
|
hide_catalog_show_integration();
|
|
|
|
} else {
|
|
|
|
if (previous_state.integration !== next_state.integration) {
|
2017-08-01 07:21:44 +02:00
|
|
|
hide_integration_show_catalog();
|
|
|
|
}
|
|
|
|
|
2018-06-13 00:55:44 +02:00
|
|
|
if (previous_state.category !== next_state.category) {
|
|
|
|
update_categories();
|
|
|
|
update_integrations();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (previous_state.query !== next_state.query) {
|
|
|
|
update_integrations();
|
|
|
|
}
|
2017-08-01 07:21:44 +02:00
|
|
|
|
2018-06-13 00:55:44 +02:00
|
|
|
$(".main").css("visibility", "visible");
|
2017-08-01 07:21:44 +02:00
|
|
|
}
|
2018-06-13 00:55:44 +02:00
|
|
|
|
2017-08-01 07:21:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function dispatch(action, payload) {
|
|
|
|
switch (action) {
|
2018-05-07 01:38:14 +02:00
|
|
|
case 'CHANGE_CATEGORY':
|
|
|
|
render(Object.assign({}, state, {
|
|
|
|
category: payload.category,
|
|
|
|
}));
|
|
|
|
update_path();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'SHOW_INTEGRATION':
|
|
|
|
render(Object.assign({}, state, {
|
|
|
|
integration: payload.integration,
|
|
|
|
}));
|
|
|
|
update_path();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'HIDE_INTEGRATION':
|
|
|
|
render(Object.assign({}, state, {
|
|
|
|
integration: null,
|
|
|
|
}));
|
|
|
|
update_path();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'SHOW_CATEGORY':
|
|
|
|
render(Object.assign({}, state, {
|
|
|
|
integration: null,
|
|
|
|
category: payload.category,
|
|
|
|
}));
|
|
|
|
update_path();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'UPDATE_QUERY':
|
|
|
|
render(Object.assign({}, state, {
|
|
|
|
query: payload.query,
|
|
|
|
}));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'LOAD_PATH':
|
|
|
|
render(get_state_from_path());
|
2020-05-08 06:37:58 +02:00
|
|
|
google_analytics.config({page_path: window.location.pathname});
|
2018-05-07 01:38:14 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
blueslip.error('Invalid action dispatched on /integrations.');
|
|
|
|
break;
|
2017-08-01 07:21:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-05 19:51:52 +02:00
|
|
|
function toggle_categories_dropdown() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const $dropdown_list = $('.integration-categories-dropdown .dropdown-list');
|
2018-07-05 20:13:36 +02:00
|
|
|
$dropdown_list.slideToggle(250);
|
2018-07-05 19:51:52 +02:00
|
|
|
}
|
|
|
|
|
2017-08-01 07:21:44 +02:00
|
|
|
function integration_events() {
|
2020-07-02 01:45:54 +02:00
|
|
|
$('#integration-search input[type="text"]').keypress((e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const integrations = $('.integration-lozenges').children().toArray();
|
2017-08-01 07:21:44 +02:00
|
|
|
if (e.which === 13 && e.target.value !== '') {
|
2019-11-02 00:06:25 +01:00
|
|
|
for (let i = 0; i < integrations.length; i += 1) {
|
|
|
|
const integration = $(integrations[i]).find('.integration-lozenge');
|
2017-08-01 07:21:44 +02:00
|
|
|
|
|
|
|
if ($(integration).css('display') !== 'none') {
|
|
|
|
$(integration).closest('a')[0].click();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$('.integration-categories-dropdown .dropdown-toggle').click(() => {
|
2018-07-05 19:51:52 +02:00
|
|
|
toggle_categories_dropdown();
|
2017-08-01 07:21:44 +02:00
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$('.integration-instruction-block').on('click', 'a .integration-category', (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const category = $(e.target).data('category');
|
2017-08-01 07:21:44 +02:00
|
|
|
dispatch('SHOW_CATEGORY', { category: category });
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$('.integrations a .integration-category').on('click', (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const category = $(e.target).data('category');
|
2017-08-01 07:21:44 +02:00
|
|
|
dispatch('CHANGE_CATEGORY', { category: category });
|
2018-07-05 19:51:52 +02:00
|
|
|
toggle_categories_dropdown();
|
2017-08-01 07:21:44 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$('.integrations a .integration-lozenge').on('click', (e) => {
|
2017-08-01 07:21:44 +02:00
|
|
|
if (!$(e.target).closest('.integration-lozenge').hasClass('integration-create-your-own')) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const integration = $(e.target).closest('.integration-lozenge').data('name');
|
2017-08-01 07:21:44 +02:00
|
|
|
dispatch('SHOW_INTEGRATION', { integration: integration });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$('a#integration-list-link span, a#integration-list-link i').on('click', () => {
|
2017-08-01 07:21:44 +02:00
|
|
|
dispatch('HIDE_INTEGRATION');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2017-08-24 09:01:26 +02:00
|
|
|
// combine selector use for both focusing the integrations searchbar and adding
|
|
|
|
// the input event.
|
|
|
|
$(".integrations .searchbar input[type='text']")
|
|
|
|
.focus()
|
2020-07-02 01:45:54 +02:00
|
|
|
.on('input', (e) => {
|
2018-12-18 19:34:45 +01:00
|
|
|
dispatch('UPDATE_QUERY', { query: e.target.value.toLowerCase() });
|
2017-08-24 09:01:26 +02:00
|
|
|
});
|
2017-08-01 07:21:44 +02:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$(window).scroll(() => {
|
2017-08-01 07:21:44 +02:00
|
|
|
if (document.body.scrollTop > 330) {
|
|
|
|
$('.integration-categories-sidebar').addClass('sticky');
|
|
|
|
} else {
|
2018-05-06 21:43:17 +02:00
|
|
|
$('.integration-categories-sidebar').removeClass('sticky');
|
2017-08-01 07:21:44 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$(window).on('resize', () => {
|
2017-08-01 07:21:44 +02:00
|
|
|
adjust_font_sizing();
|
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$(window).on('popstate', () => {
|
2017-08-01 07:21:44 +02:00
|
|
|
if (window.location.pathname.startsWith('/integrations')) {
|
|
|
|
dispatch('LOAD_PATH');
|
|
|
|
} else {
|
|
|
|
window.location = window.location.href;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// init
|
2020-07-02 01:45:54 +02:00
|
|
|
$(() => {
|
2017-08-01 07:21:44 +02:00
|
|
|
integration_events();
|
|
|
|
load_data();
|
|
|
|
dispatch('LOAD_PATH');
|
|
|
|
});
|