Visitas guiadas - Cliente
. Visitas guiadas A API fornece métodos para iniciar e interromper tours guiados.
Esta API inclui métodos usados em Designer de Tour Guiado .
Tours guiados - applyListFilter(function filter_func)
Define uma função para recuperar resultados de tour filtrados quando GetAllTours() o método é chamado.
Assinaturas completas inclusões TOP.NOW.guided_tours.api precedendo o nome do método.
| Nome | Tipo | Descrição |
|---|---|---|
| filter_func | Função | Função de filtro que usa um único tour objeto do tours[] matriz retornada de GetAllTours() método. |
| Tipo | Descrição |
|---|---|
| Nenhum(a) |
O exemplo a seguir mostra o uso básico da API.
//create a filter function
var filtFunction = function(tour) {
//only return those tours whose name starts with 'my'
return tour.name.indexOf('my') === 0);
}
//apply the filter
top.NOW.guided_tours.api.applyListFilter (filtFunction);
//call the getAllTours method to observe the filtered tours
top.NOW.guided_tours.api.getAllTours (function(er, tours) {
if(!er) {
console.log('The filtered tours are: ');
console.log(tours);
}
});
O exemplo a seguir mostra como usar o. opções Campo no objeto de tour para adicionar JSON com identificadores de tour personalizados para leitura e filtragem de tours dentro do filter_func() função.
top.NOW.guided_tours.api.applyListFilter(function(tour) {
var options = (tour.options)? JSON.parse(tour.options): null;
return (options && options.my_param) ? (options.my_param == my_value) : false;
});
Visitas guiadas - endTour()
Interrompe um tour em reprodução no momento. Se nenhum tour estiver sendo reproduzido, este método será encerrado silenciosamente.
Assinaturas completas inclusões TOP.NOW.guided_tours.api precedendo o nome do método.
| Nome | Tipo | Descrição |
|---|---|---|
| Nenhum |
| Tipo | Descrição |
|---|---|
| Nulo |
//create a callback function to end the tour if it starts correctly
var cbFunction = function(err) {
if (err) {
console.log('Error Occurred');
}
else {
// tour has started so we can call endTour
top.NOW.guided_tours.api.endTour();
}
}
//calling the startTour method so that we can end the tour as soon as it starts
top.NOW.guided_tours.api.startTour('a297e04b732313007077edcc5ef6a780', 2, cbFunction);
Tours guiados - events.off(cadeia de caracteres event_name, function listener_function)
Remove um ouvinte de evento existente.
Assinaturas completas inclusões TOP.NOW.guided_tours.api precedendo o nome do método.
| Nome | Tipo | Descrição |
|---|---|---|
| event_name | Cadeia de caracteres | Nome do evento a ser removido do ouvinte. Nomes de evento válidos:
|
| ouvinte_function | Função | Opcional. Se fornecida, a função de ouvinte especificada será removida dos ouvintes de evento restantes anexados a esse evento. Se não for fornecida, todas as funções de ouvinte anexadas a esse evento serão removidas. |
| Tipo | Descrição |
|---|---|
| Nenhum |
//create a callback function to handle the result of the api call
var eventListenerTourStarted = function() {
console.log('The tour has started');
}
var eventListenerTourEnded = function() {
console.log('The tour has ended');
}
//attaching event listeners for tourStarted and tourEnded Events
top.NOW.guided_tours.events.on('tourStarted',eventListenerTourStarted);
top.NOW.guided_tours.events.on('tourEnded', eventListenerTourEnded);
…
//start a tour
top.NOW.guided_tours.api.startTour ('a297e04b732313007077edcc5ef6a780', 2, cbFunction);
//As soon as the tour starts the eventListenerTourStarted gets fired
…
top.NOW.guided_tours.api.endTour();
// eventListenerTourEnded gets fired
….
//removing the event listeners top.NOW.guided_tours.events.off('tourStarted',eventListenerTourStarted);
top.NOW.guided_tours.events.off('tourEnded', eventListenerTourEnded);
Tours guiados - events.on(cadeia de caracteres event_name, function listener_function)
Anexa um ouvinte de evento a um evento de tour guiado.
Assinaturas completas inclusões TOP.NOW.guided_tours.api precedendo o nome do método.
| Nome | Tipo | Descrição |
|---|---|---|
| event_name | Cadeia de caracteres | Nome do evento a ser anexado ao ouvinte. Nomes de evento válidos:
|
| ouvinte_function | Função | Ouvinte a ser adicionado. Nota: Limpe qualquer ouvinte de evento depois que ele resolver sua finalidade. |
| listener_function.obj | Objeto | Passado para ouvinte_function() por cada evento no seguinte formato:
Parâmetros JSON:
|
O exemplo a seguir mostra o uso básico da API.
//create a callback function to handle the result of the api call
var eventListenerTourStarted = function() {
console.log('The tour has started');
}
var eventListenerTourEnded = function() {
console.log('The tour has ended');
}
//attaching event listeners for tourStarted and tourEnded Events
top.NOW.guided_tours.events.on('tourStarted',eventListenerTourStarted);
top.NOW.guided_tours.events.on('tourEnded', eventListenerTourEnded);
…
//start a tour
top.NOW.guided_tours.api.startTour ('a297e04b732313007077edcc5ef6a780', 2, cbFunction);
//As soon as the tour starts the eventListenerTourStarted gets fired
…
top.NOW.guided_tours.api.endTour();
// eventListenerTourEnded gets fired
….
//removing the event listeners top.NOW.guided_tours.events.off('tourStarted',eventListenerTourStarted);
top.NOW.guided_tours.events.off('tourEnded', eventListenerTourEnded);
O exemplo a seguir mostra como usar o. ouvinte_function parâmetro com obj como argumento.
top.NOW.guided_tours.events.on("tourStarted", function (obj){console.log(obj);});
Tours guiados - getAllTours(function cb_function)
Obtém uma lista de tours na página atual da qual este método é chamado. Como este método é assíncrono, uma função de retorno de chamada deve ser passada para determinar o sucesso da operação e obter uma lista de tours.
Assinaturas completas inclusões TOP.NOW.guided_tours.api precedendo o nome do método.
| Nome | Tipo | Descrição |
|---|---|---|
| cb_function | Função | Função de retorno de chamada chamada por GetAllTours() após a tentativa de buscar todos os tours da página atual da qual GetAllTours() o método é chamado. |
| cb_function.err | Objeto | Aponta para o objeto de erro se ocorreu algum durante a operação:
Caso contrário, nulo. |
| cb_function.tours | Matriz | Lista de tours disponíveis para a página. Se não houver tours presentes na página,
|
| Tipo | Descrição |
|---|---|
| Nenhum |
//create a callback function to handle the result of the API call
var cbFunction = function(err, tours) {
if (err) {
console.log('Error Occurred');
}
else {
if(!tours) console.log('No tour present')
else {
tours.forEach(function(t) {
console.log(t);
});
}
}
}
//calling the getTours method
top.NOW.guided_tours.api.getAllTours(cbFunction);
Tours guiados - loadPlayer()
Carrega o player de tours guiados em uma página na qual o player de tours guiados não está presente por padrão.
NOW.guided_tours.api.loadPlayer()| Nome | Tipo | Descrição |
|---|---|---|
| Nenhum |
| Tipo | Descrição |
|---|---|
| Nenhum |
Tours guiados - startTour(cadeia de caracteres tour_id, number step_number, function cb_function)
Inicia um tour. Como esse método é assíncrono, você deve passar uma função de retorno de chamada para determinar o sucesso da operação.
Assinaturas completas inclusões TOP.NOW.guided_tours.api precedendo o nome do método.
| Nome | Tipo | Descrição |
|---|---|---|
| tour_id | Cadeia de caracteres | Sys ID do tour da tabela Tours guiados [sys_embedded_tour_guide]. |
| step_number | Número | Opcional. Etapa na qual iniciar o tour. Se não for fornecido (ou o número da etapa for 0), o tour começará do início. |
| cb_function | Função | Opcional. Função de retorno de chamada chamada por StartTour() método após a tentativa de iniciar o tour. |
| cb_function.err | Objeto | Aponta para o objeto de erro se ocorreu algum durante a operação:
Caso contrário, nulo. |
| Tipo | Descrição |
|---|---|
| Nenhum |
//create a callback function to handle the result of the API call
var cbFunction = function(err) {
if (err) {
console.log('Error Occurred');
}
else {
console.log('The tour with tourid=%s was successfully launched', tourId);
}
}
//calling the startTour method
top.NOW.guided_tours.api.startTour('a297e04b732313007077edcc5ef6a780', 2, cbFunction);