script.tpl 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. {% if tour.show_tour %}
  2. <script type="text/javascript">
  3. var chamiloTour = (function() {
  4. var intro = null;
  5. var $btnStart = null;
  6. var setSteps = function (stepsData) {
  7. var steps = new Array();
  8. $.each(stepsData, function () {
  9. var step = this;
  10. if (step.element) {
  11. if ($(step.element).length > 0) {
  12. steps.push(step);
  13. }
  14. } else {
  15. steps.push(step);
  16. }
  17. });
  18. return steps;
  19. };
  20. return {
  21. init: function(pageClass) {
  22. $.getJSON('{{ tour.web_path.steps_ajax }}', {
  23. 'page_class': pageClass
  24. }, function(response) {
  25. intro = introJs();
  26. intro.setOptions({
  27. steps: setSteps(response),
  28. nextLabel: '{{ 'Next' | get_lang }}',
  29. prevLabel: '{{ 'Prev' | get_lang }}',
  30. skipLabel: '{{ 'Skip' | get_lang }}',
  31. doneLabel: '{{ 'Done' | get_lang }}'
  32. });
  33. intro.oncomplete(function () {
  34. $.post('{{ tour.web_path.save_ajax }}', {
  35. page_class: pageClass
  36. }, function () {
  37. $btnStart.remove();
  38. });
  39. });
  40. $btnStart = $('<button>', {
  41. class: 'tour-warning',
  42. html: '<img src="{{ _p.web }}/plugin/tour/resources/tour-chamilo.png">{{ 'StartButtonText' | get_lang }}',
  43. click: function(e) {
  44. e.preventDefault();
  45. intro.start();
  46. }
  47. }).appendTo('#tour-button-container');
  48. });
  49. }
  50. };
  51. })();
  52. $(function () {
  53. var pages = {{ tour.pages }};
  54. $.each(pages, function(index, page) {
  55. var thereIsSelectedPage = $(page.pageClass).length > 0;
  56. if (thereIsSelectedPage && page.show) {
  57. $('<link>', {
  58. href: '{{ tour.web_path.intro_css }}',
  59. rel: 'stylesheet'
  60. }).appendTo('head');
  61. {% if tour.web_path.intro_theme_css is not null %}
  62. $('<link>', {
  63. href: '{{ tour.web_path.intro_theme_css }}',
  64. rel: 'stylesheet'
  65. }).appendTo('head');
  66. {% endif %}
  67. $.getScript('{{ tour.web_path.intro_js }}', function() {
  68. chamiloTour.init(page.pageClass);
  69. });
  70. }
  71. });
  72. });
  73. </script>
  74. <div id="tour-button-container"></div>
  75. {% endif %}