Change the plugin JS structure - refs #7279

1.9.x
Angel Fernando Quiroz Campos 11 years ago
parent c23b5493c7
commit 800699e5c6
  1. 53
      plugin/tour/views/script.tpl

@ -1,48 +1,56 @@
<script type="text/javascript">
var chamiloTour = (function() {
var intro = null;
var currentPageClass = '';
var $btnStart = null;
var setSteps = function (stepsData) {
var steps = new Array();
$.each(stepsData, function () {
var step = this;
if (step.element) {
if ($(step.element).length > 0) {
steps.push(step);
}
} else {
steps.push(step);
}
});
return steps;
};
return {
init: function(pageClass) {
currentPageClass = pageClass;
$.getJSON('{{ tour.web_path.steps_ajax }}', {
'page_class': pageClass
}, function(response) {
intro = introJs();
intro.setOptions({
steps: setSteps(response),
nextLabel: '{{ 'Next' | get_lang }}',
prevLabel: '{{ 'Prev' | get_lang }}',
skipLabel: '{{ 'Skip' | get_lang }}',
doneLabel: '{{ 'Done' | get_lang }}'
});
intro.oncomplete(function () {
$.post('{{ tour.web_path.save_ajax }}', {
page_class: currentPageClass
page_class: pageClass
}, function () {
$btnStart.remove();
});
});
},
showStartButton: function() {
$btnStart = $('<button>', {
class: 'btn btn-primary btn-large',
text: '{{ 'StartButtonText' | get_lang }}',
click: function(e) {
e.preventDefault();
var promise = chamiloTour.setSteps(currentPageClass);
$.when(promise).done(function (data) {
intro.start();
});
}
}).appendTo('#tour-button-cotainer');
},
setSteps: function() {
return $.getJSON('{{ tour.web_path.steps_ajax }}', {
'page_class': currentPageClass
}, function(response) {
intro.setOptions({
steps: response,
nextLabel: '{{ 'Next' | get_lang }}',
prevLabel: '{{ 'Prev' | get_lang }}',
skipLabel: '{{ 'Skip' | get_lang }}',
doneLabel: '{{ 'Done' | get_lang }}'
});
});
}
};
@ -67,7 +75,6 @@
$.getScript('{{ tour.web_path.intro_js }}', function() {
chamiloTour.init(page.pageClass);
chamiloTour.showStartButton(page.pageClass);
});
}
});

Loading…
Cancel
Save