PageSourceSearch

https://ta-tum.com/js/Planlector.js?v=4

js ta-tum.com collected 2026-09-24 11:31:18 UTC 67,743 bytes, 2,126 lines download raw bytes

1/**
2 * Discover Manager
3 */
4var mDiscover = null,
5  mLanding = null,
6  mLogin = null,
7  mRegister = null,
8  mFooter = null,
9  mCom = null,
10  mStudentHome = null,
11  mParentHome = null,
12  mTeacherHome = null,
13  mSchoolAdminHome = null,
14  mEditorHtml = null,
15  mToast = null,
16  CoreData = null,
17  mAnalytics = null,
18  mUnboarding = null,
19  mTooltip = null,
20  mDatetime = null,
21  mCromoSelector = null,
22  mCromoViewer = null,
23  mAvatar = null,
24  mPolpRegister = null,
25  mAvatarProject = null,
26  mGoogleDrive = null,
27  userLang = null,
28  newSessionUser = null,
29  sso_token = null,
30  sso_email = null,
31  countryCode = null,
32  callbackSubscriptionSuccess = null;
33
34var soundClick = new Howl({
35  src: ["audio/mouseclick.mp3"],
36});
37
38var exeView = ""; //new implementation 15/07
39var isEnableGlobalEduca = false;
40
41// Document READY
42$(document).ready(function () {
43  // load lang-file if is necessary
44  userLang = getBrowserLang();
45  if ($.cookie("planlector-user-lang")) {
46    if (
47      $.cookie("planlector-user-lang") !== null &&
48      $.cookie("planlector-user-lang") &&
49      $.cookie("planlector-user-lang") !== "null"
50    ) {
51      userLang = String($.cookie("planlector-user-lang")).toLowerCase();
52      console.log("Lang definido por preferencia de usuario: " + userLang);
53    }
54  }
55
56  // GET view of exercise
57  $.get("execore/views/exercise.html", function (data) {
58    exeView = data;
59  });
60
61  switch (userLang) {
62    case "ca":
63      $("body").addClass("lang-ca");
64      $.ajax({
65        url: "lang/lang.cat.js",
66        dataType: "script",
67        success: startPlatform,
68      });
69      break;
70    case "eu":
71      $("body").addClass("lang-eu");
72      $.ajax({
73        url: "lang/lang.eus.js",
74        dataType: "script",
75        success: startPlatform,
76      });
77      break;
78    case "va":
79      $("body").addClass("lang-va");
80      $.ajax({
81        url: "lang/lang.val.js",
82        dataType: "script",
83        success: startPlatform,
84      });
85      break;
86    case "gl":
87      $("body").addClass("lang-gl");
88      $.ajax({
89        url: "lang/lang.glg.js",
90        dataType: "script",
91        success: startPlatform,
92      });
93      break;
94    case "ar":
95      $("body").addClass("lang-ar");
96      $.ajax({
97        url: "lang/lang.arg.js",
98        dataType: "script",
99        success: startPlatform,
100      });
101      break;
102    case "mx":
103      $("body").addClass("lang-mx");
104      $.ajax({
105        url: "lang/lang.mex.js",
106        dataType: "script",
107        success: startPlatform,
108      });
109      break;
110    case "en":
111      $("body").addClass("lang-en");
112      $.ajax({
113        url: "lang/lang.eng.js",
114        dataType: "script",
115        success: startPlatform,
116      });
117      break;
118    default:
119      $.ajax({
120        url: "lang/lang.spa.js",
121        dataType: "script",
122        success: startPlatform,
123      });
124      break;
125  }
126
127  // contact iframe url
128  let contactUrl = "";
129  switch (userLang) {
130    case "eu":
131      contactUrl = "https://formdynamics.edelvives.es/eu/ta-tum-info?utm_campaign=Ta-tum";
132      break;
133    case "va":
134      contactUrl = "https://formdynamics.edelvives.es/vc/ta-tum-info?utm_campaign=Ta-tum";
135      break;
136    case "ca":
137      contactUrl = "https://formdynamics.edelvives.es/ca/ta-tum-info?utm_campaign=Ta-tum";
138      break;
139    case "gl":
140      contactUrl = "https://formdynamics.edelvives.es/gl/ta-tum-info?utm_campaign=Ta-tum";
141      break;
142    case "ar":
143    case "mx":
144      contactUrl = "https://formdynamics.edelvives.es/es/ta-tum-info?utm_campaign=Ta-tum";
145      break;
146  }
147  if (contactUrl !== "") {
148    console.log("contactFormUrl: " + contactUrl);
149    $("#iframe_tatum_contact_form").attr("src", contactUrl);
150  }
151
152  function startPlatform() {
153    $("body").trigger("onStartPlatform");
154
155    mDiscover = new Discover($("body"));
156    mToast = new Toast($("body > .d-toasts"));
157    mModal = new Modal("");
158    mTooltip = new Tooltip($("body"));
159    mCromoSelector = new CromoSelector($("body > .cromo-selector"));
160    mCromoViewer = new CromoViewer();
161
162    mDiscover.hideLoading();
163  }
164
165  getCountryCode();
166
167  if (config && config.ORACULO_CDN) {
168    $.getScript(config.ORACULO_CDN, function (data, textStatus, jqxhr) {
169      console.log("Oráculo CDN Load was performed.");
170      if (
171        config.hasOwnProperty("ORACULO_APP_ID") &&
172        config.hasOwnProperty("ORACULO_APP_NAME") &&
173        config.hasOwnProperty("ORACULO_SHARED_KEY")
174      ) {
175        setConfiguration({
176          id: config.ORACULO_APP_ID,
177          name: config.ORACULO_APP_NAME,
178          sharedKey: config.ORACULO_SHARED_KEY,
179        });
180      }
181    });
182  }
183
184});
185
186function enableSysNotify() {
187  if (mCom.getSocket() !== null) {
188    onSocketConnect();
189  } else {
190    $("body").off("ON_SOCKET_CONNECT", onSocketConnect);
191    $("body").on("ON_SOCKET_CONNECT", onSocketConnect);
192  }
193}
194
195function onSocketConnect() {
196  $("body").off("ON_SOCKET_CONNECT", onSocketConnect);
197  var socket = mCom.getSocket();
198  if (socket !== null) {
199    console.log("listening channel: 'sys-notify'");
200    socket.on("sys-notify", function (event) {
201      console.log("sys-notify incomming");
202      console.log(event);
203    });
204  } else {
205    console.log("socket is null");
206  }
207}
208
209var Discover = function (sco) {
210  var scope = sco;
211  var session_id = null;
212  var user = null;
213  var parallax = null;
214  var ModalConfirm = null;
215  var ModalCookieConfirm = null;
216  var ModalInfo = null;
217  var ModalAviso = null;
218  var url_quiosco = config.url_quiosco;
219  var on_exercise_select_callback = null;
220  var core_exercise_loaded = false;
221  var core_exercise_ready = false;
222  var ModalSuscribe = null;
223  var ModalSubscribe = null;
224  var ModalClassroomCode = null;
225  var ModalChangePassword = null;
226  var callbackChangePasswordSuccess = null;
227  mAnalytics = new Analytics();
228  mAnalytics.init();
229
230  /**
231   * Hide all modules and show one
232   * @param {String} module class name
233   * @returns {undefined}
234   */
235  function showModule(module) {
236    console.log("showModule('" + module + "')");
237    if (mUnboarding !== null) mUnboarding.hide();
238
239    scope.find("main .d-module").hide();
240    scope.find("main .d-module." + module).show();
241    switch (module) {
242      default:
243        hideFooter();
244        break;
245    }
246  }
247
248  // setUser
249  function setUser(_u) {
250    user = _u;
251    if (user.roles.length === 1) {
252      user.role = user.roles[0];
253    }
254    setSession(user.session_guid);
255    setCookie();
256    mCom.sConnect();
257
258	if(config && config.hasOwnProperty("ENABLE_FEAT_GLOBALEDUCA") && config['ENABLE_FEAT_GLOBALEDUCA']){
259      if(user && user.role === "teacher"){
260        isEnableGlobalEduca = true;
261      }
262    }
263	
264    setTimeout(function () {
265      mUnboarding = new Unboarding($("body > .unboarding"));
266    }, 200);
267  }
268  function changeSessionTo(username, password) {
269    if (isAdmin()) {
270      newSessionUser = { username: username, password: password };
271      $.cookie("aux-planlector-user", JSON.stringify(user), {
272        expires: 7,
273        path: "/",
274      });
275      closeSession();
276    }
277  }
278  function updUserProfile(data) {
279    for (var key in data) {
280      if (data.hasOwnProperty(key)) {
281        user[key] = data[key];
282        //console.log("update profile value '" + key + "' = " + data[key]);
283      }
284    }
285    setCookie();
286    switch (user.role) {
287      case "student":
288        mStudentHome.refreshUserData();
289        break;
290      case "teacher":
291        mTeacherHome.refreshUserData();
292        break;
293      case "parent":
294        mParentHome.refreshUserData();
295        break;
296    }
297    $("body").trigger("on_update_user");
298  }
299
300  function getSession() {
301    return session_id;
302  }
303  function setSession(s) {
304    session_id = s;
305  }
306  function getUser() {
307    return user;
308  }
309  function isAdmin() {
310    if (user.hasOwnProperty("is_admin")) {
311      return user.is_admin;
312    }
313    return false;
314  }
315  function isSuperAdmin() {
316    if (user.hasOwnProperty("is_superadmin")) {
317      return user.is_superadmin;
318    }
319    return false;
320  }
321  function isSchoolAdmin() {
322    if (user.hasOwnProperty("is_school_admin")) {
323      return user.is_school_admin;
324    }
325    return false;
326  }
327  function haveSuperAdminSession() {
328    var haveSession = false;
329    if ($.cookie("aux-planlector-user")) {
330      if ($.cookie("aux-planlector-user") !== "") {
331        haveSession = true;
332      }
333    }
334    return haveSession;
335  }
336  function setRole(role) {
337    user.role = role;
338    setCookie();
339  }
340  function getRole() {
341    return user.role;
342  }
343  function setTitlePageDefault() {
344    document.title = lang.html_title_without_session;
345  }
346  function setTitlePageByRole() {
347    if (mDiscover.getUser()) {
348      //console.log("setTitlePageByRole(): " + mDiscover.getUser().role);
349      document.title = lang["html_title_" + mDiscover.getUser().role];
350    }
351  }
352
353  function reloadSession() {
354    mCom.ajax(
355      "reload-session",
356      "GET",
357      "",
358      function (data, status) {
359        mDiscover.setUser(data);
360      },
361      function (err, status, msg) {
362        //callback(err, status);
363        //mToast.toast("No se pudo refrescar sesión", 3000);
364        console.log(err);
365      }
366    );
367  }
368
369  function closeSession() {
370    mCom.ajax(
371      "logout",
372      "GET",
373      "",
374      function (data, status) {
375        user = null;
376        session_id = null;
377        cleanCookie();
378        mCom.sDisconnect();
379        core_exercise_ready = false; // force init again
380        console.log("closeSession successful");
381        console.log(newSessionUser);
382        if (newSessionUser !== null) {
383          routie("login");
384        } else {
385          if ($.cookie("aux-planlector-user")) {
386            if ($.cookie("aux-planlector-user") !== "") {
387              $.cookie("planlector-user", $.cookie("aux-planlector-user"), {
388                expires: 7,
389                path: "/",
390              });
391              $.cookie("planlector-user-lang", null, { expires: 7, path: "/" });
392              $.cookie("aux-planlector-user", "", { expires: 7, path: "/" });
393              tryRecoverSession();
394              routie("teacher/admin/schools");
395              try {
396                mTeacherHome.refreshUserData();
397                mTeacherHome.refreshClassrooms();
398                mTeacherHome.refreshTeacherMenuRules();
399              } catch (e) {
400                console.log(e);
401              }
402            }
403          } else {
404            routie("/");
405          }
406        }
407      },
408      function (err, status, msg) {
409        //callback(err, status);
410        mToast.toast("No se pudo cerrar sesión", 3000);
411      }
412    );
413    try {
414      makeLogout();
415    } catch (e) {
416      console.log(e);
417    }
418  }
419
420  function showParallax() {
421    $("body").addClass("parallax-login-register");
422    $(".paralax-container-login").show();
423    if (parallax === null) {
424      parallax = new Parallax($("#scene_paralax")[0]);
425    }
426    parallax.enable();
427  }
428
429  function hideParallax() {
430    $("body").removeClass("parallax-login-register");
431    $(".paralax-container-login").hide();
432    if (parallax !== null) parallax.disable();
433  }
434
435  function showFooter() {
436    console.log("showFooter()");
437    hideFooter();
438    $("body > div.page-footer").show();
439  }
440
441  function showFooterProject() {
442    hideFooter();
443    $("body > div.project-footer").show();
444  }
445
446  function hideFooter() {
447    console.log("hideFooter()");
448    $("body > div.footer").hide();
449  }
450
451  function headerMode(modes) {
452    $("body main .m-home").removeClass(
453      "header-retracted header-fixed header-sticky header-hidden header-only-back"
454    );
455    $("body main .m-home").addClass(modes);
456    doFooterSticky();
457
458    if (modes === "header-sticky") {
459      $(window).trigger("scroll"); // forzamos a recalcular posiciones
460      $("body").removeClass("showing-modal");
461    }
462    //$(window).scrollTop(0);
463  }
464
465  function doFooterSticky() {
466    //console.log("doFooterSticky()");
467    if ($("main .m-home:visible").length > 0) {
468      if ($(window).height() > $("main > .m-home").height()) {
469        var min_height =
470          $(window).height() -
471          ($("body > .page-footer").is(":visible")
472            ? $("body > .page-footer").height()
473            : 0) -
474          $(".header .d-header").height();
475        if (min_height < 550) min_height = 550;
476        //console.log("doFooterSticky() min_height: " + min_height);
477        $("main .m-home .d-home-content").css("min-height", min_height + "px");
478        //$("main .m-home").css("min-height", min_height + "px");
479      }
480    }
481  }
482
483  function redeem() {
484    mDiscover.showLoading();
485    const code = $('#modal-container .modal.d-modal-subscribe .d-input-code').text();
486    mCom.ajax(
487      "license/redeem",
488      "POST",
489      { code: code },
490      function (data) {
491        console.log(data);
492        if (callbackSubscriptionSuccess) {
493          callbackSubscriptionSuccess();
494        }
495        mToast.toast(lang.popup_redeem_license_success || "Licencia añadida correctamente");
496        mDiscover.hideLoading();
497      },
498      function (err, data, st) {
499        console.log(err, data, st);
500        if (err.responseJSON && err.responseJSON.error) {
501          switch (err.responseJSON.error) {
502            case 'REDEEM_01':
503              mToast.toast(lang.popup_redeem_license_error1 || "El código no es válido");
504              break;
505            case 'REDEEM_02':
506              mToast.toast(lang.popup_redeem_license_error2 || "La licencia ha expirado");
507              break;
508            case 'REDEEM_03':
509              mToast.toast(lang.popup_redeem_license_error3 || "La licencia no tiene usos disponibles");
510              break;
511            case 'REDEEM_04':
512              mToast.toast(lang.popup_redeem_license_error4 || "Ya tienes vinculada la licencia");
513              break;
514            case 'REDEEM_05':
515              mToast.toast(lang.popup_redeem_license_error5 || "La licencia está inactiva");
516              break;
517            case 'REDEEM_06':
518              mToast.toast(lang.popup_redeem_license_error6 || "La licencia no aplica a tu rol de usuario");
519              break;
520          }
521        } else {
522          mToast.toast("Problemas al intentar activar código");
523        }
524        mDiscover.hideLoading();
525      }
526    );
527  }
528
529  function tryChangePassword() {
530    console.log("tryChangePassword()");
531    const currentPassword = getModalChangePassword().find('.d-input-code1').text();
532    const newPassword = getModalChangePassword().find('.d-input-code2').text();
533    if (newPassword.length < 5) {
534      mToast.toast(lang.popup_change_password_min_length || "La contraseña debe tener al menos 5 caracteres");
535      return;
536    }
537    console.log(currentPassword, newPassword);
538    mDiscover.showLoading();
539    mCom.ajax(
540      "profile/change-password",
541      "PUT",
542      { passCurrent: currentPassword, passNew: newPassword, passNewConfirm: newPassword },
543      function (data) {
544        console.log(data);
545        if (callbackChangePasswordSuccess) {
546          callbackChangePasswordSuccess();
547        }
548        mToast.toast(lang.popup_change_password_success || "Contraseña cambiada correctamente");
549        mDiscover.hideLoading();
550        getModalChangePassword().find('.d-input-code1').html('********');
551        getModalChangePassword().find('.d-input-code2').html('********');
552        ModalChangePassword.hide();
553      },
554      function (err, data, st) {
555        console.log(err, data, st);
556        mToast.toast(lang.popup_change_password_error || "Problemas al cambiar la contraseña");
557        mDiscover.hideLoading();
558      }
559    );
560  }
561  // Constructor
562  function init() {
563    console.log("mDiscover:init()");
564
565    // Modules of Discover (standard)
566    mLogin = new Login($("main .m-login"));
567    mLanding = new Landing($("main .m-landing"));
568    mRegister = new Register($("main .m-register"));
569    mFooter = new Footer($("body>footer"));
570    mCom = new module_com();
571
572    mDatetime = new DatetimeSelector($("body > .date-time-selector"));
573    mAvatar = new AvatarSelector($("body > .avatar-selector"));
574    mPolpRegister = new PolpRegister($("body > .polp-register"));
575    mAvatarProject = new AvatarProjectSelector(
576      $("body > .avatar-project-selector")
577    );
578    mGoogleDrive = new GoogleDrive();
579
580    ModalConfirm = new Modal($("#modal-confirm"));
581    ModalCookieConfirm = new Modal($("#modal-cookie-confirm"));
582    ModalInfo = new Modal($("#modal-info"));
583    ModalAviso = new Modal($("#modal-aviso"));
584
585    $("#modal-confirm .cancel-generic-popup").html(lang.confirm_cancel);
586    $("#modal-confirm .acept-generic-popup").html(lang.confirm_accept);
587
588    // Modal Suscribe
589    $("#modal-container .modal.d-modal-suscribe").remove();
590    $("#modal-container").append(getHtmlModalSuscribe());
591    ModalSuscribe = new Modal(getModalSuscribe());
592    getModalSuscribe()
593      .find(".d-close")
594      .click(function () {
595        ModalSuscribe.hide();
596      });
597
598    // Modal Subscribe
599    $("#modal-container .modal.d-modal-subscribe").remove();
600    $("#modal-container").append(getHtmlModalSubscribe());
601    $("#modal-container").append(getHtmlModalClassroomCode());
602    $("#modal-container").append(getHtmlModalChangePassword());
603    $("#modal-container .d-modal-subscribe .d-submit").click(redeem);
604    ModalSubscribe = new Modal(getModalSubscribe());
605    ModalClassroomCode = new Modal(getModalClassroomCode());
606    $('#modal-container .modal.d-modal-subscribe .d-input-code').html('');
607    getModalSubscribe()
608      .find(".d-close")
609      .click(function () {
610        ModalSubscribe.hide();
611      });
612
613    // Modal Change Password
614    $("#modal-container .modal.d-modal-change-password").remove();
615    $("#modal-container").append(getHtmlModalChangePassword());
616    ModalChangePassword = new Modal(getModalChangePassword());
617    getModalChangePassword()
618      .find(".d-close")
619      .click(function () {
620        ModalChangePassword.hide();
621      });
622
623    getModalChangePassword().find('.d-submit').click(tryChangePassword);
624      
625      
626    getModalClassroomCode()
627      .find(".d-close")
628      .click(function () {
629        ModalClassroomCode.hide();
630      });
631    getModalClassroomCode()
632      .find(".ico-copy")
633      .click(function () {
634        mToast.toast(lang.popup_classroom_code_copied || "Código copiado");
635        navigator.clipboard.writeText(
636          $('#modal-container .modal.d-modal-classroom-code .d-input-code').text()
637        );
638      });
639
640    $(window).bind("offline", function (e) {
641      if (!mCom.isOnline() || !window.navigator.onLine) {
642        mToast.toast(lang.connection_problem, 6000);
643      }
644    });
645
646    // window resize event
647    $(window).resize(doFooterSticky);
648
649    // window scroll event
650    $(window).scroll(function () {
651      if ($("main .m-home:visible").length > 0) {
652        if ($("main .m-home").hasClass("header-sticky")) {
653          //console.log($(window).scrollTop() + " height: " + $("main .m-home .header .image-top").height() );
654          if (
655            $(window).scrollTop() >
656            $("main .m-home .header .image-top").height()
657          ) {
658            $("main .m-home .header .d-header-tile").addClass("sticky");
659          } else {
660            $("main .m-home .header .d-header-tile").removeClass("sticky");
661          }
662        }
663
664        // footer sticky
665        doFooterSticky();
666      }
667    });
668
669    setTimeout(doFooterSticky, 500);
670
671    function showCookieMessage() {
672      return true;
673
674      // COOKIE MSGBOX
675      setTimeout(function () {
676        $(".cookie#cookie").fadeIn("slow");
677        var t = setTimeout(function () {
678          $(".cookie#cookie").fadeOut("slow");
679        }, 4000);
680        $(".cookie#cookie").click(function () {
681          clearInterval(t);
682          $(".cookie#cookie").fadeOut("slow");
683        });
684      }, 2000);
685      $(".cookie#cookie a").click(function () {
686        $(".cookie#cookie").fadeOut("slow");
687        mDiscover.showAviso("punto4");
688      });
689      // END COOKIE MSGBOX
690    }
691
692    // close exercise editor
693    $("#exercise-editor-container .d-close-btn").click(function () {
694      mDiscover.hideExerciseEditor();
695    });
696
697    // set políticas y cookies
698    $("#modal-aviso #tyc").html(lang.footer_aviso_legal_cookies);
699    // set políticas de privacidad
700    $("#modal-aviso #pp").html(lang.footer_privacy_policies);
701    // cookie minipopup
702    $(".cookie#cookie li p").html(lang.footer_cookie_minipopup);
703
704    var IsShowCookieMessage = false;
705    // Routes of Discover
706    routie({
707      "": function () {
708        // default
709        routie("welcome");
710        setTitlePageDefault();
711        destroyModules();
712      },
713      resume: function () {
714        // resume
715        if($.cookie("resume-url") && $.cookie("resume-url") !== null && $.cookie("resume-url") !== window.location.href){
716          window.location.href = $.cookie("resume-url");
717        }else{
718          routie("welcome");
719        }
720      },
721      welcome: function () {
722        // mLanding
723        setTitlePageDefault();
724        showModule("m-landing");
725        mLanding.show();
726        destroyModules();
727        hideParallax();
728        mAnalytics.send("pageview", {
729          page: "welcome",
730          title: "Landing",
731        });
732        if (!IsShowCookieMessage) {
733          IsShowCookieMessage = true;
734          showCookieMessage();
735        }
736      },
737      "welcome/subscribe": function () {
738        // mLanding
739        setTitlePageDefault();
740        showModule("m-landing");
741        mLanding.show();
742        setTimeout(function () {
743          mDiscover.showSuscribe();
744        }, 300);
745        destroyModules();
746        hideParallax();
747        mAnalytics.send("pageview", {
748          page: "welcome subscribe",
749          title: "Landing - subscribe",
750        });
751        if (!IsShowCookieMessage) {
752          IsShowCookieMessage = true;
753          showCookieMessage();
754        }
755      },
756      "welcome/contact": function () {
757        // mLanding
758        showModule("m-landing");
759        mLanding.show("welcome/contact");
760        destroyModules();
761        hideParallax();
762        mAnalytics.send("pageview", {
763          page: "welcome",
764          title: "Landing",
765        });
766      },
767      "login/:Error": function (error) {
768        // mLogin with error
769        showModule("m-login");
770        mLogin.show(error);
771        mAnalytics.send("pageview", {
772          page: "login/error",
773          title: "Error when try init session",
774        });
775      },
776      login: function () {
777        // mLogin;
778        showParallax();
779        showModule("m-login");
780        mLogin.show();
781        destroyModules();
782        mAnalytics.send("pageview", {
783          page: "login",
784          title: "Login",
785        });
786      },
787      "register-sso": function () {
788        // mRegister
789        console.log("ROUTIE :: register sso");
790        showParallax();
791        showModule("m-register");
792        mRegister.show("sso");
793        mAnalytics.send("pageview", {
794          page: "register",
795          title: "Register",
796        });
797      },
798      register: function () {
799        // mRegister
800        //return routie("");
801        console.log("ROUTIE :: register");
802        showParallax();
803        showModule("m-register");
804        mRegister.show("");
805        mAnalytics.send("pageview", {
806          page: "register",
807          title: "Register",
808        });
809      },
810      "register/:step": function (step) {
811        // mRegister
812        tryRecoverSession();
813        showParallax();
814        showModule("m-register");
815        mRegister.show(step);
816        mAnalytics.send("pageview", {
817          page: "retister/" + step,
818          title: "Register step: " + step,
819        });
820      },
821      home: function () {
822        // mHome
823        showModule("m-home");
824        headerMode("header-retracted header-fixed");
825        mAnalytics.send("pageview", {
826          page: "home",
827          title: "Home",
828        });
829      },
830      "student/home": function () {
831        checkSessionAndRole(["student"], function () {
832          showModule("m-home");
833          headerMode("header-retracted header-fixed");
834          if (mStudentHome === null) {
835            mStudentHome = new StudentHome($("main .m-home"));
836            setTimeout(mDiscover.showVideoFinish, 500);
837          }
838          mStudentHome.show();
839
840          mAnalytics.send("pageview", {
841            page: "student/home",
842            title: "Home Student",
843          });
844        });
845      },
846      "student/work": function () {
847        checkSessionAndRole(["student"], function () {
848          showModule("m-home");
849          headerMode("header-retracted header-fixed");
850          if (mStudentHome === null)
851            mStudentHome = new StudentHome($("main .m-home"));
852
853          mStudentHome.show("work");
854
855          mAnalytics.send("pageview", {
856            page: "student/work",
857            title: "Student - Work",
858          });
859        });
860      },
861      "student/help/*": function () {
862        checkSessionAndRole(["student"], function () {
863          showModule("m-home");
864          headerMode("header-retracted header-fixed");
865          if (mStudentHome === null)
866            mStudentHome = new StudentHome($("main .m-home"));
867
868          mStudentHome.show("help");
869
870          mAnalytics.send("pageview", {
871            page: "student/help",
872            title: "Student - Help",
873          });
874        });
875      },
876      "teacher/help/:section": function (section) {
877        checkSessionAndRole(["teacher"], function () {
878          showModule("m-home");
879          headerMode("header-retracted header-fixed");
880          if (mTeacherHome === null)
881            mTeacherHome = new TeacherHome($("main .m-home"));
882
883          mTeacherHome.show("help", section);
884
885          mAnalytics.send("pageview", {
886            page: "teacher/help",
887            title: "Teacher - Help",
888          });
889        });
890      },
891      "student/profile/:section": function (section) {
892        checkSessionAndRole(["student"], function () {
893          console.log("ROUTIE :: student/profile/section(" + section + ")");
894          showModule("m-home");
895          headerMode("header-sticky");
896          if (mStudentHome === null)
897            mStudentHome = new StudentHome($("main .m-home"));
898
899          mStudentHome.show("profile", section);
900          mAnalytics.send("pageview", {
901            page: "student/profile/" + section,
902            title: "Student - Classroom profile - " + section,
903          });
904        });
905      },
906      "student/notifications": function (section) {
907        checkSessionAndRole(["student"], function () {
908          showModule("m-home");
909          headerMode("header-retracted header-fixed");
910          if (mStudentHome === null)
911            mStudentHome = new StudentHome($("main .m-home"));
912
913          mStudentHome.show("notifications");
914          mAnalytics.send("pageview", {
915            page: "student/notifications",
916            title: "Student - Notifications",
917          });
918        });
919      },
920      "student/pdi/:classroom_guid": function (classroom_guid) {
921        checkSessionAndRole(["student"], function () {
922          showModule("m-home");
923          headerMode("header-hidden");
924          if (mStudentHome === null)
925            mStudentHome = new StudentHome($("main .m-home"));
926
927          mStudentHome.setClassroomGuid(classroom_guid);
928          mStudentHome.show("pdi");
929          mAnalytics.send("pageview", {
930            page: "student/pdi",
931            title: "Student - Pdi",
932          });
933        });
934      },
935      "student/classroom/:classroom_guid/:section": function (
936        classroom_guid,
937        section
938      ) {
939        checkSessionAndRole(["student"], function () {
940          showModule("m-home");
941          headerMode("header-sticky");
942          if (mStudentHome === null)
943            mStudentHome = new StudentHome($("main .m-home"));
944
945          mStudentHome.setClassroomGuid(classroom_guid);
946          mStudentHome.setClassroomSection(section);
947          mStudentHome.show("classroom");
948          mAnalytics.send("pageview", {
949            page: "student/classroom/" + classroom_guid,
950            title: "Student - Classroom projects",
951          });
952        });
953      },
954      "student/classroom/:classroom_guid/:project_guid/:classroom_project_guid/:section":
955        function (
956          classroom_guid,
957          project_guid,
958          classroom_project_guid,
959          section
960        ) {
961          checkSessionAndRole(["student"], function () {
962            showModule("m-home");
963            headerMode("header-sticky");
964            if (mStudentHome === null)
965              mStudentHome = new StudentHome($("main .m-home"));
966
967            mStudentHome.setClassroomGuid(classroom_guid);
968            mStudentHome.setProjectGuid(project_guid);
969            mStudentHome.setClassroomProjectGuid(classroom_project_guid);
970            mStudentHome.setProjectSection(section);
971            mStudentHome.show("classroom/project/classroom_project/section");
972            mAnalytics.send("pageview", {
973              page:
974                "student/classroom/" +
975                classroom_guid +
976                "/" +
977                project_guid +
978                "/" +
979                classroom_project_guid +
980                "/" +
981                section,
982              title: "Student - Classroom project - " + section,
983            });
984          });
985        },
986      "student/classroom/:classroom_guid/:project_guid/:classroom_project_guid/post/:post_guid":
987        function (
988          classroom_guid,
989          project_guid,
990          classroom_project_guid,
991          post_guid
992        ) {
993          checkSessionAndRole(["student"], function () {
994            showModule("m-home");
995            headerMode("header-retracted header-fixed");
996            $("body").removeClass("showing-modal");
997            var first_load = false;
998            if (mStudentHome === null) {
999              mStudentHome = new StudentHome($("main .m-home"));
1000              first_load = true;
1001            }
1002
1003            mStudentHome.setClassroomGuid(classroom_guid);
1004            mStudentHome.setProjectGuid(project_guid);
1005            mStudentHome.setClassroomProjectGuid(classroom_project_guid);
1006            mStudentHome.setCurrentPostGuid(post_guid);
1007            mStudentHome.show("classroom/project/classroom_project/post");
1008            if (first_load) {
1009              mStudentHome.refreshCurrentClassroom();
1010            }
1011            mAnalytics.send("pageview", {
1012              page:
1013                "student/classroom/" +
1014                classroom_guid +
1015                "/" +
1016                project_guid +
1017                "/" +
1018                classroom_project_guid +
1019                "/post/" +
1020                post_guid,
1021              title: "Student - Classroom project - Post guid " + post_guid,
1022            });
1023          });
1024        },
1025      "parent/home": function () {
1026        checkSessionAndRole(["parent"], function () {
1027          showModule("m-home");
1028          headerMode("header-retracted header-fixed");
1029          if (mParentHome === null)
1030            mParentHome = new ParentHome($("main .m-home"));
1031
1032          mParentHome.show();
1033          mAnalytics.send("pageview", {
1034            page: "parent/home",
1035            title: "Parent - Home",
1036          });
1037        });
1038      },
1039      "teacher/home/classroom/:section": function (section) {
1040        checkSessionAndRole(["teacher"], function () {
1041          showModule("m-home");
1042          headerMode("header-retracted header-fixed");
1043          $("body").removeClass("showing-modal");
1044          if (mTeacherHome === null)
1045            mTeacherHome = new TeacherHome($("main .m-home"));
1046
1047          mTeacherHome.show("", section);
1048          mAnalytics.send("pageview", {
1049            page: "teacher/home",
1050            title: "Teacher - Home",
1051          });
1052        });
1053      },
1054      "teacher/home": function () {
1055        checkSessionAndRole(["teacher"], function () {
1056          showModule("m-home");
1057          headerMode("header-retracted header-fixed");
1058          $("body").removeClass("showing-modal");
1059          if (mTeacherHome === null) {
1060            mTeacherHome = new TeacherHome($("main .m-home"));
1061            setTimeout(mDiscover.showVideoFinish, 500);
1062          }
1063          mTeacherHome.show("");
1064          mAnalytics.send("pageview", {
1065            page: "teacher/home",
1066            title: "Teacher - Home",
1067          });
1068        });
1069      },
1070      "teacher/licenses": function () {
1071        checkSessionAndRole(["teacher"], function () {
1072          showModule("m-home");
1073          headerMode("header-retracted header-fixed");
1074          $("body").removeClass("showing-modal");
1075          if (mTeacherHome === null)
1076            mTeacherHome = new TeacherHome($("main .m-home"));
1077
1078          mTeacherHome.show("licenses");
1079          mAnalytics.send("pageview", {
1080            page: "teacher/licenses",
1081            title: "Teacher - Admin - Licenses",
1082          });
1083        });
1084      },
1085      "teacher/batch-licenses": function () {
1086        checkSessionAndRole(["teacher"], function () {
1087          showModule("m-home");
1088          headerMode("header-retracted header-fixed");
1089          $("body").removeClass("showing-modal");
1090          if (mTeacherHome === null)
1091            mTeacherHome = new TeacherHome($("main .m-home"));
1092
1093          mTeacherHome.show("batch-licenses");
1094          mAnalytics.send("pageview", {
1095            page: "teacher/batch-licenses",
1096            title: "Teacher - Admin - Batch Licenses",
1097          });
1098        });
1099      },
1100      "teacher/admin/schools": function () {
1101        checkSessionAndRole(["teacher"], function () {
1102          showModule("m-home");
1103          headerMode("header-retracted header-fixed");
1104          $("body").removeClass("showing-modal");
1105          if (mTeacherHome === null)
1106            mTeacherHome = new TeacherHome($("main .m-home"));
1107
1108          mTeacherHome.show("admin-schools");
1109          mAnalytics.send("pageview", {
1110            page: "teacher/admin/schools",
1111            title: "Teacher - Admin - Schools",
1112          });
1113        });
1114      },
1115      "teacher/admin/users": function () {
1116        checkSessionAndRole(["teacher"], function () {
1117          showModule("m-home");
1118          headerMode("header-retracted header-fixed");
1119          $("body").removeClass("showing-modal");
1120          if (mTeacherHome === null)
1121            mTeacherHome = new TeacherHome($("main .m-home"));
1122
1123          mTeacherHome.show("admin-users");
1124          mAnalytics.send("pageview", {
1125            page: "teacher/admin/users",
1126            title: "Teacher - Admin - Users",
1127          });
1128        });
1129      },
1130      "teacher/admin/codes": function () {
1131        checkSessionAndRole(["teacher"], function () {
1132          showModule("m-home");
1133          headerMode("header-retracted header-fixed");
1134          $("body").removeClass("showing-modal");
1135          if (mTeacherHome === null)
1136            mTeacherHome = new TeacherHome($("main .m-home"));
1137
1138          mTeacherHome.show("admin-codes");
1139          mAnalytics.send("pageview", {
1140            page: "teacher/admin/codes",
1141            title: "Teacher - Admin - Codes",
1142          });
1143        });
1144      },
1145      "teacher/admin/requested-projects": function () {
1146        checkSessionAndRole(["teacher"], function () {
1147          showModule("m-home");
1148          headerMode("header-retracted header-fixed");
1149          $("body").removeClass("showing-modal");
1150          if (mTeacherHome === null)
1151            mTeacherHome = new TeacherHome($("main .m-home"));
1152
1153          mTeacherHome.show("admin-requested-projects");
1154          mAnalytics.send("pageview", {
1155            page: "teacher/admin/requested-projects",
1156            title: "Teacher - Admin - Requested projects",
1157          });
1158        });
1159      },
1160      "editor/projects": function () {
1161        checkSessionAndRole(["teacher"], function () {
1162          if (!mDiscover.isAdmin()) {
1163            routie("");
1164          }
1165
1166          showModule("m-home");
1167          headerMode("header-retracted header-fixed");
1168          $("body").removeClass("showing-modal");
1169          if (mTeacherHome === null)
1170            mTeacherHome = new TeacherHome($("main .m-home"));
1171
1172          mTeacherHome.show("admin-projects");
1173          mAnalytics.send("pageview", {
1174            page: "teacher/admin/schools",
1175            title: "Teacher - Admin - Schools",
1176          });
1177        });
1178      },
1179      "teacher/library-projects": function () {
1180        checkSessionAndRole(["teacher"], function () {
1181          showModule("m-home");
1182          headerMode("header-retracted header-fixed");
1183          $("body").removeClass("showing-modal");
1184          if (mTeacherHome === null)
1185            mTeacherHome = new TeacherHome($("main .m-home"));
1186
1187          mTeacherHome.show("library-projects");
1188          mAnalytics.send("pageview", {
1189            page: "teacher/library-projects",
1190            title: "Teacher - Library projects",
1191          });
1192        });
1193      },
1194      "teacher/profile/:section": function (section) {
1195        checkSessionAndRole(["teacher"], function () {
1196          showModule("m-home");
1197          //headerMode("header-retracted header-fixed");
1198          headerMode("header-sticky");
1199          if (mTeacherHome === null)
1200            mTeacherHome = new TeacherHome($("main .m-home"));
1201
1202          mTeacherHome.show("profile", section);
1203          mAnalytics.send("pageview", {
1204            page: "teacher/profile/" + section,
1205            title: "Teacher - Classroom profile - " + section,
1206          });
1207        });
1208      },
1209      "teacher/school/:section": function (section) {
1210        checkSessionAndRole(["teacher"], function () {
1211          showModule("m-home");
1212          //headerMode("header-retracted header-fixed");
1213          headerMode("header-sticky");
1214          if (mTeacherHome === null)
1215            mTeacherHome = new TeacherHome($("main .m-home"));
1216
1217          mTeacherHome.show("school", section);
1218          mAnalytics.send("pageview", {
1219            page: "teacher/school/" + section,
1220            title: "Teacher - School - " + section,
1221          });
1222        });
1223      },
1224      "teacher/classroom/:classroom_guid": function (classroom_guid) {
1225        checkSessionAndRole(["teacher"], function () {
1226          routie("teacher/classroom/" + classroom_guid + "/projects");
1227        });
1228      },
1229      "teacher/classroom/:classroom_guid/:section": function (
1230        classroom_guid,
1231        section
1232      ) {
1233        checkSessionAndRole(["teacher"], function () {
1234          showModule("m-home");
1235          headerMode("header-sticky");
1236
1237          if (mTeacherHome === null)
1238            mTeacherHome = new TeacherHome($("main .m-home"));
1239
1240          mTeacherHome.setClassroomGuid(classroom_guid);
1241          mTeacherHome.setClassroomSection(section);
1242          mTeacherHome.show("classroom");
1243          mAnalytics.send("pageview", {
1244            page: "teacher/classroom/" + classroom_guid,
1245            title: "Teacher - Classroom projects",
1246          });
1247        });
1248      },
1249      "teacher/classroom/:classroom_guid/book-students/:book_guid": function (
1250        classroom_guid,
1251        book_guid
1252      ) {
1253        checkSessionAndRole(["teacher"], function () {
1254          showModule("m-home");
1255          headerMode("header-sticky");
1256
1257          if (mTeacherHome === null)
1258            mTeacherHome = new TeacherHome($("main .m-home"));
1259
1260          mTeacherHome.setClassroomGuid(classroom_guid);
1261          mTeacherHome.setClassroomSection("book-students");
1262          mTeacherHome.setClassroomBookGuid(book_guid);
1263          mTeacherHome.show("classroom");
1264          mAnalytics.send("pageview", {
1265            page: "teacher/classroom/" + classroom_guid,
1266            title: "Teacher - Classroom projects",
1267          });
1268        });
1269      },
1270      "teacher/classroom/:classroom_guid/:project_guid/:classroom_project_guid/:section":
1271        function (
1272          classroom_guid,
1273          project_guid,
1274          classroom_project_guid,
1275          section
1276        ) {
1277          checkSessionAndRole(["teacher"], function () {
1278            showModule("m-home");
1279            headerMode("header-sticky");
1280            var first_load = false;
1281            if (mTeacherHome === null) {
1282              mTeacherHome = new TeacherHome($("main .m-home"));
1283              first_load = true;
1284            }
1285
1286            mTeacherHome.setClassroomGuid(classroom_guid);
1287            mTeacherHome.setProjectGuid(project_guid);
1288            mTeacherHome.setClassroomProjectGuid(classroom_project_guid);
1289            mTeacherHome.setProjectSection(section);
1290            mTeacherHome.show("classroom/project/classroom_project/section");
1291            if (first_load) {
1292              mTeacherHome.refreshCurrentClassroom();
1293            }
1294            mAnalytics.send("pageview", {
1295              page:
1296                "teacher/classroom/" +
1297                classroom_guid +
1298                "/" +
1299                project_guid +
1300                "/" +
1301                classroom_project_guid +
1302                "/" +
1303                section,
1304              title: "Teacher - Classroom project - " + section,
1305            });
1306          });
1307        },
1308      "teacher/classroom/:classroom_guid/:project_guid/:classroom_project_guid/post/*":
1309        function (
1310          classroom_guid,
1311          project_guid,
1312          classroom_project_guid,
1313          params
1314        ) {
1315          checkSessionAndRole(["teacher"], function () {
1316            var params_ar = params.split("/");
1317            var post_guid = params_ar.length > 0 ? params_ar[0] : params;
1318            var student_guid = params_ar.length > 1 ? params_ar[1] : null;
1319            //console.log("post_guid: " + post_guid);
1320            //console.log("student_guid: " + student_guid);
1321            showModule("m-home");
1322            headerMode("header-retracted header-fixed");
1323            $("body").removeClass("showing-modal");
1324            var first_load = false;
1325            if (mTeacherHome === null) {
1326              mTeacherHome = new TeacherHome($("main .m-home"));
1327              first_load = true;
1328            }
1329
1330            mTeacherHome.setClassroomGuid(classroom_guid);
1331            mTeacherHome.setProjectGuid(project_guid);
1332            mTeacherHome.setClassroomProjectGuid(classroom_project_guid);
1333            mTeacherHome.setCurrentPostGuid(post_guid);
1334            mTeacherHome.setCurrentStudentGuid(student_guid);
1335            mTeacherHome.show("classroom/project/classroom_project/post");
1336            if (first_load) {
1337              mTeacherHome.refreshCurrentClassroom();
1338            }
1339            mAnalytics.send("pageview", {
1340              page:
1341                "teacher/classroom/" +
1342                classroom_guid +
1343                "/" +
1344                project_guid +
1345                "/" +
1346                classroom_project_guid +
1347                "/post/" +
1348                post_guid,
1349              title: "Teacher - Classroom project - Post guid " + post_guid,
1350            });
1351          });
1352        },
1353      "teacher/work": function () {
1354        checkSessionAndRole(["teacher"], function () {
1355          showModule("m-home");
1356          headerMode("header-retracted header-fixed");
1357          if (mTeacherHome === null)
1358            mTeacherHome = new TeacherHome($("main .m-home"));
1359
1360          mTeacherHome.show("work");
1361          mAnalytics.send("pageview", {
1362            page: "teacher/work",
1363            title: "Teacher - Work",
1364          });
1365        });
1366      },
1367      "teacher/insights/:classroom_guid": function (classroomGuid) {
1368        checkSessionAndRole(["teacher"], function () {
1369          showModule("m-home");
1370          headerMode("header-retracted header-fixed");
1371          if (mTeacherHome === null)
1372            mTeacherHome = new TeacherHome($("main .m-home"));
1373
1374          mTeacherHome.show("insights", classroomGuid);
1375          mAnalytics.send("pageview", {
1376            page: "teacher/insights",
1377            title: "Teacher - Insights",
1378          });
1379        });
1380      },
1381      "teacher/notifications": function () {
1382        checkSessionAndRole(["teacher"], function () {
1383          showModule("m-home");
1384          headerMode("header-retracted header-fixed");
1385          if (mTeacherHome === null)
1386            mTeacherHome = new TeacherHome($("main .m-home"));
1387
1388          mTeacherHome.show("notifications");
1389          mAnalytics.send("pageview", {
1390            page: "teacher/notifications",
1391            title: "Teacher - Notifications",
1392          });
1393        });
1394      },
1395      "teacher/pdi/:classroom_guid": function (classroom_guid) {
1396        checkSessionAndRole(["teacher"], function () {
1397          showModule("m-home");
1398          headerMode("header-hidden");
1399          if (mTeacherHome === null)
1400            mTeacherHome = new TeacherHome($("main .m-home"));
1401
1402          mTeacherHome.setClassroomGuid(classroom_guid);
1403          mTeacherHome.show("pdi");
1404          mAnalytics.send("pageview", {
1405            page: "teacher/pdi",
1406            title: "Teacher - Notifications",
1407          });
1408        });
1409      },
1410      "teacher/admin-class": function () {
1411        checkSessionAndRole(["teacher"], function () {
1412          showModule("m-home");
1413          headerMode("header-retracted header-fixed");
1414          if (mTeacherHome === null)
1415            mTeacherHome = new TeacherHome($("main .m-home"));
1416
1417          mTeacherHome.show("admin-class");
1418          mAnalytics.send("pageview", {
1419            page: "teacher/admin-class",
1420            title: "Teacher - Create classroom",
1421          });
1422        });
1423      },
1424      "teacher/admin-class/:classroom_guid": function (classroom_guid) {
1425        checkSessionAndRole(["teacher"], function () {
1426          showModule("m-home");
1427          headerMode("header-retracted header-fixed");
1428          if (mTeacherHome === null)
1429            mTeacherHome = new TeacherHome($("main .m-home"));
1430
1431          mTeacherHome.getAddClassModule().editClassroomGUID(classroom_guid);
1432          mTeacherHome.show("admin-class");
1433          mAnalytics.send("pageview", {
1434            page: "teacher/admin-class/" + classroom_guid,
1435            title: "Teacher - Edit classroom",
1436          });
1437        });
1438      },
1439      "school-admin/home": function () {
1440        checkSessionAndRole(["school-admin"], function () {
1441          showModule("m-home");
1442          headerMode("header-retracted header-fixed");
1443          if (mSchoolAdminHome === null)
1444            mSchoolAdminHome = new SchoolAdminHome($("main .m-home"));
1445
1446          mSchoolAdminHome.show();
1447          mAnalytics.send("pageview", {
1448            page: "school-admin/home",
1449            title: "School admin - Home",
1450          });
1451        });
1452      },
1453    });
1454    // Set Class in Body for Device
1455    if (
1456      (navigator.userAgent.match(/iPad|iPod/i) &&
1457        navigator.userAgent.match(/Mobile/i)) ||
1458      (navigator.userAgent.match(/Android/i) &&
1459        navigator.userAgent.match(/Tablet/i))
1460    ) {
1461      // TABLET
1462      //$('body').addClass('device-tablet');
1463      $("body").addClass("device-mobile");
1464      $("body").addClass("device-tablet-mobile");
1465    } else if (
1466      navigator.userAgent.match(
1467        /Android|BlackBerry|Tablet|Mobile|iPhone|Opera Mini|IEMobile/i
1468      )
1469    ) {
1470      // MOBILE
1471      $("body").addClass("device-mobile");
1472      $("body").addClass("device-tablet-mobile");
1473    } else {
1474      // PC
1475      $("body").addClass("device-pc");
1476    }
1477
1478    // Css Mobile Embed
1479    $("head link[rel='stylesheet']")
1480      .last()
1481      .after(
1482        '<link rel="stylesheet" href="css/planlector-mobile.css?t=' +
1483        new Date().getTime() +
1484        '" />'
1485      );
1486    $("head link[rel='stylesheet']")
1487      .last()
1488      .after(
1489        '<link rel="stylesheet" href="css/planlector-tablet-mobile.css?t=' +
1490        new Date().getTime() +
1491        '" />'
1492      );
1493  }
1494
1495  function destroyModules() {
1496    if (mStudentHome !== null) {
1497      mStudentHome.destroy(function () {
1498        mStudentHome = null;
1499      });
1500    }
1501    if (mParentHome !== null) {
1502      mParentHome.destroy(function () {
1503        mParentHome = null;
1504      });
1505    }
1506    if (mTeacherHome !== null) {
1507      mTeacherHome.destroy(function () {
1508        mTeacherHome = null;
1509      });
1510    }
1511    if (mSchoolAdminHome !== null) {
1512      mSchoolAdminHome.destroy(function () {
1513        mSchoolAdminHome = null;
1514      });
1515    }
1516    if (mGoogleDrive !== null) mGoogleDrive.destroy();
1517  }
1518
1519  function tryRecoverSession() {
1520    console.log("tryRecoverSession()");
1521    // posible recarga de página, miremos la cookie
1522    if (
1523      $.cookie("planlector-user") &&
1524      $.cookie("planlector-user") !== null &&
1525      $.cookie("planlector-user") !== "null"
1526    ) {
1527      console.log("Parsing session from cookie");
1528      setUser(jQuery.parseJSON($.cookie("planlector-user")));
1529    }
1530  }
1531
1532  /**
1533   * Verifica si el usuario tiene el rol adecuado para acceder al módulo
1534   * llama al callback cuando se recupera la sesión desde cookie
1535   */
1536  function checkSessionAndRole(roles_ar, callback) {
1537    hideParallax();
1538    if (session_id === null) {
1539      // SIN session
1540      // posible recarga de página, miremos la cookie
1541      if (
1542        $.cookie("planlector-user") &&
1543        $.cookie("planlector-user") !== null &&
1544        $.cookie("planlector-user") !== "null"
1545      ) {
1546        //console.log("datos de la cookie: ");
1547        //console.log($.cookie('planlector-user'));
1548        setUser(jQuery.parseJSON($.cookie("planlector-user")));
1549
1550        // tiempo para que escriba la cookie
1551        setTimeout(function () {
1552          // CON sesión, check permiso
1553          checkRole(roles_ar, getRole(), callback);
1554          setTitlePageByRole();
1555
1556          if (getRole() === "teacher" || getRole() === "student") {
1557            loadCoreExercise();
1558          }
1559        }, 200);
1560      } else {
1561        // no hay cookie
1562        routie("login");
1563      }
1564    } else {
1565      // CON sesión, check permiso
1566      checkRole(roles_ar, getRole(), callback);
1567    }
1568  }
1569  function checkRole(admited_roles_ar, user_role, callback) {
1570    if ($.inArray(user_role, admited_roles_ar) >= 0) {
1571      // el rol de sesión es admitido por el módulo
1572      // siga...
1573      callback();
1574    } else {
1575      // go to home role
1576      var role = getRole();
1577      console.log("CHECK-ROLE: '" + role + "'");
1578      if (role && role !== "undefined" && role !== undefined) {
1579        routie(role + "/home");
1580      } else {
1581        routie("");
1582      }
1583    }
1584  }
1585  function refreshCoreToken() {
1586    console.log("refreshCoreToken()");
1587    core_exercise_ready = false;
1588    initCore();
1589  }
1590
1591  function initCore() {
1592    if (!core_exercise_ready && core_exercise_loaded) {
1593      var role_int = getRole() === "teacher" ? 1 : 2;
1594      try {
1595        CORE.init(
1596          {
1597            appId: "0c4e3042796e38b6baf971a13bea8f6c",
1598            version: "v1.0",
1599            eRef: "77DSDD33YHU",
1600            email: getUser().username,
1601            name: String(getUser().name).split("#").join(""),
1602            lastname: String(getUser().lastname).split("#").join(""),
1603            rol: role_int,
1604            lang: userLang,
1605          },
1606          function (result) {
1607            // console.log(JSON.stringify(result));
1608            CoreData = result;
1609            core_exercise_ready = true;
1610            $(document).trigger("on_core_exercise_ready");
1611            if (CoreData.hasOwnProperty("expire")) {
1612              var expire = parseInt(CoreData.expire);
1613              if (!isNaN(expire)) {
1614                setTimeout(refreshCoreToken, (expire - 5) * 1000);
1615              }
1616            }
1617          },
1618          function (err) {
1619            console.log(err);
1620          }
1621        );
1622      } catch (e) {
1623        loadCoreExercise();
1624      }
1625    }
1626  }
1627  function loadCoreExercise() {
1628    // console.log("loadCoreExercise() core_exercise_loaded: " + core_exercise_loaded + " core_exercise_ready: " + core_exercise_ready);
1629    if (!core_exercise_loaded) {
1630      core_exercise_loaded = true;
1631      window.coreAsyncInit = function () {
1632        // console.log("window.coreAsyncInit()");
1633        initCore();
1634      };
1635      (function (d, s, id) {
1636        var js,
1637          fjs = d.getElementsByTagName(s)[0];
1638        if (d.getElementById(id)) {
1639          return;
1640        }
1641        js = d.createElement(s);
1642        js.id = id;
1643        js.src = config.assessment_url;
1644        fjs.parentNode.insertBefore(js, fjs);
1645      })(document, "script", "core");
1646    } else {
1647      if (!core_exercise_ready && typeof CORE !== "undefined") {
1648        // console.log("CORE already loaded");
1649        initCore();
1650      }
1651    }
1652  }
1653
1654  function setCookie() {
1655    // data a cookie por si recarga la página
1656    $.cookie("planlector-user", JSON.stringify(user), {
1657      expires: 7,
1658      path: "/",
1659    });
1660    if (getRole() === "teacher" || getRole() === "student") {
1661      loadCoreExercise();
1662    }
1663  }
1664
1665  function cleanCookie() {
1666    $.cookie("planlector-user", null, { path: "/" });
1667  }
1668  function openConfirm(title, content, callback) {
1669    ModalConfirm.confirm(title, content, callback);
1670  }
1671
1672  function openCookieConfirm() {
1673    $("#modal-cookie-confirm .acept-generic-popup").html(lang.cookie_dialog_ok || 'ok')
1674    $("#modal-cookie-confirm .cancel-generic-popup").html(lang.cookie_dialog_cancel || 'nok');
1675
1676    ModalCookieConfirm.confirm(lang.cookie_dialog_title || 'title', lang.cookie_dialog_message || 'message', function (accept) {
1677      if (accept) {
1678        Cookiebot.renew();
1679      }
1680    });
1681    $("#modal-cookie-confirm p a").attr('href', 'javascript:void(0)');
1682    $("#modal-cookie-confirm p a").click(function () {
1683      mDiscover.showAviso('cookies');
1684      ModalCookieConfirm.hide();
1685    });
1686  }
1687  function showAviso(anchor) {
1688    ModalAviso.showFixed();
1689
1690    $("#modal-aviso").show();
1691    $("#politica_privacidad").hide();
1692    $("#aviso_legal").hide();
1693    $("#politica_cookies").hide();
1694
1695    if (anchor) {
1696      $(".modal-content").scrollTop();
1697
1698      if (anchor === "privacy") {
1699        // Abrir página Política de privacidad
1700        $("#politica_privacidad").show();
1701      } else if (anchor === "legal") {
1702        // Abrir página Aviso legal
1703        //$("#aviso_legal").show();
1704        $("#politica_cookies").show();
1705        $(".modal-content").scrollTop(0);
1706      } else if (anchor === "cookies") {
1707        // Abrir página Política de cookies
1708        $("#politica_cookies").show();
1709        _gotoCookies();
1710      } else if (anchor === "cookies_config") {
1711        // Abrir página Política de cookies
1712        $("#politica_cookies").show();
1713        _gotoCookies();
1714      }
1715    }
1716    function _gotoCookies() {
1717      $(".modal-content").scrollTop(0);
1718      $(".modal-content").animate(
1719        {
1720          scrollTop: $(".modal-content a[name='punto4']").position().top - 50,
1721        },
1722        500
1723      );
1724    }
1725  }
1726  function checkYoutubeCookie(next) {
1727    function _next() {
1728      if (next) next();
1729    }
1730
1731    // for try locally
1732    // return openCookieConfirm(); // fail
1733    // return next(); // success
1734
1735    try {
1736      const domain = window.location.hostname;
1737      if (domain !== 'ta-tum.com') {
1738        return _next();
1739      }
1740      if (Cookiebot.consent.marketing) {
1741        return _next();
1742      }
1743      openCookieConfirm();
1744    } catch (e) {
1745      console.log(e);
1746      _next();
1747    }
1748  }
1749
1750  function openInfo(title, content, callback) {
1751    ModalInfo.info(title, content, callback);
1752  }
1753
1754  function showLoading() {
1755    if ($("body").find("#cometa_loading").length <= 0) {
1756      $("body").append(
1757        "<div id='cometa_loading'> <img src='css/img/loading_gears_2.gif' /> </div>"
1758      );
1759    }
1760    $("#cometa_loading").fadeIn();
1761  }
1762
1763  function hideLoading() {
1764    $("body")
1765      .find("#cometa_loading")
1766      .fadeOut(function () {
1767        $("#cometa_loading").remove();
1768      });
1769  }
1770  function setLoadingProgress(_p) {
1771    if ($("#cometa_loading").length > 0) {
1772      if ($("#cometa_loading .d-progress").length <= 0) {
1773        $("#cometa_loading").append('<div class="d-progress">' + _p + "</div>");
1774      } else {
1775        $("#cometa_loading .d-progress").html(_p);
1776      }
1777    }
1778  }
1779  // helpers
1780  function getModalSuscribe() {
1781    return $("#modal-container .modal.d-modal-suscribe");
1782  }
1783  function getHtmlModalSuscribe() {
1784    return (
1785      '  <div class="modal d-modal-suscribe">' +
1786      '  <div class="modal-content wrap-dialog-popup">' +
1787      '       <div class="d-close btn btn-bitmap"></div>' +
1788      '       <a href="https://www.edelvives.com/es/info/donde-encontrarnos" target="_blank">&nbsp;</a>' +
1789      '       <div class="d-modal-content">' +
1790      "       </div>" +
1791      "  </div>" +
1792      " </div>"
1793    );
1794  }
1795  function getModalSubscribe() {
1796    return $("#modal-container .modal.d-modal-subscribe");
1797  }
1798  function getModalChangePassword() {
1799    return $("#modal-container .modal.d-modal-change-password");
1800  }
1801  function getModalClassroomCode() {
1802    return $("#modal-container .modal.d-modal-classroom-code");
1803  }
1804  function getHtmlModalSubscribe() {
1805    return (`
1806      <div class="modal d-modal-subscribe">
1807        <div class="modal-content wrap-dialog-popup">
1808             <div class="d-close btn btn-bitmap"></div>
1809             <div class="d-modal-content">
1810                <div class="d-license-active">   
1811                <div class="d-title">
1812                  ${lang.popup_redeem_license_title || "Activar licencia"}
1813                </div>
1814                <div class="d-title-code">
1815                  ${lang.popup_redeem_license_message || "Introduce el código de licencia personal"}
1816                </div>
1817                <div class="d-input-code single-line" contenteditable="true" spellcheck="false" placeholder="${lang.popup_redeem_license_placeholder || "Escribe aquí..."}"></div>
1818                <div class="bg-input-code"></div>
1819                <div class="d-submit btn brown">
1820                ${lang.popup_redeem_license_submit || "Enviar"}
1821                </div></div>
1822             </div>
1823        </div>
1824       </div>`
1825    );
1826  }
1827  function getHtmlModalChangePassword() {
1828    return (`
1829      <div class="modal d-modal-change-password">
1830        <div class="modal-content wrap-dialog-popup">
1831             <div class="d-close btn btn-bitmap"></div>
1832             <div class="d-modal-content">
1833                <div class="d-license-active">   
1834                <div class="d-title">
1835                  ${lang.popup_change_password_title || "Cambiar contraseña"}
1836                </div>
1837                <div class="d-title-code1">
1838                  ${lang.popup_change_password_current_password || "Contraseña actual"}
1839                </div>
1840                <div class="d-input-code1" contenteditable="true" spellcheck="false" placeholder="${lang.popup_change_password_current_password_placeholder || "********"}"></div>
1841                <div class="bg-input-code1"></div>
1842                <div class="d-title-code2">
1843                  ${lang.popup_change_password_new_password || "Nueva contraseña"}
1844                </div>
1845                <div class="d-input-code2" contenteditable="true" spellcheck="false" placeholder="${lang.popup_change_password_new_password_placeholder || "********"}"></div>
1846                <div class="bg-input-code2"></div>
1847                <div class="d-submit btn brown">
1848                ${lang.popup_change_password_submit || "Cambiar contraseña"}
1849                </div>
1850
1851             </div>
1852        </div>
1853       </div>`
1854    );
1855  }
1856  function getHtmlModalClassroomCode() {
1857    return (`
1858      <div class="modal d-modal-classroom-code">
1859        <div class="modal-content wrap-dialog-popup">
1860             <div class="d-close btn btn-bitmap"></div>
1861             <div class="d-modal-content">
1862                <div class="d-license-active">   
1863                <div class="d-title">
1864                  ${lang.popup_classroom_code_title || "Código de clase"}
1865                </div>
1866                <div class="d-title-code">
1867                  ${lang.popup_classroom_code_message || "Envía este código a tus estudiantes para que se unan a la clase"}
1868                </div>
1869                <div class="d-input-code"></div>
1870                <div class="ico-copy btn btn-bitmap"></div>
1871                <div class="classroom-name"></div>
1872                <div class="education-level"></div>
1873
1874             </div>
1875        </div>
1876       </div>`
1877    );
1878  }
1879
1880  // public methods
1881  this.reloadSession = reloadSession;
1882  this.getSession = getSession;
1883  this.setSession = setSession;
1884  this.setUser = setUser;
1885  this.updUserProfile = updUserProfile;
1886  this.getUser = getUser;
1887  this.isAdmin = isAdmin;
1888  this.isSuperAdmin = isSuperAdmin;
1889  this.isSchoolAdmin = isSchoolAdmin;
1890  this.haveSuperAdminSession = haveSuperAdminSession;
1891  this.setRole = setRole;
1892  this.changeSessionTo = changeSessionTo;
1893  this.getRole = getRole;
1894  this.closeSession = closeSession;
1895  this.openConfirm = openConfirm;
1896  this.openCookieConfirm = openCookieConfirm;
1897  this.checkYoutubeCookie = checkYoutubeCookie;
1898  this.showAviso = showAviso;
1899  this.openInfo = openInfo;
1900  this.showLoading = showLoading;
1901  this.hideLoading = hideLoading;
1902  this.setLoadingProgress = setLoadingProgress;
1903  //this.showFooter = showFooter;
1904  //this.showFooterProject = showFooterProject;
1905  this.setTitlePageByRole = setTitlePageByRole;
1906  this.refreshFooterSticky = doFooterSticky;
1907  this.refreshCoreToken = refreshCoreToken;
1908  this.getUrlQuiosco = function () {
1909    return url_quiosco;
1910  };
1911  this.hideExerciseEditor = function () {
1912    console.log("showExerciseEditor()");
1913    $("#exercise-editor-container").hide();
1914    $("#exercise-editor-container iframe").attr("src", "");
1915    $("body").removeClass("showing-modal");
1916  };
1917  this.isCoreExerciseReady = function () {
1918    return core_exercise_ready;
1919  };
1920  this.showExerciseEditor = function (
1921    exercise_guid,
1922    callback,
1923    arrayExercisesNames
1924  ) {
1925    $("#exercise-editor-container .d-close-btn").hide();
1926    if (!core_exercise_ready) {
1927      mToast.toast("Exercise CORE not ready", 3000);
1928      return;
1929    }
1930    on_exercise_select_callback = callback;
1931    //var param_exercise_guid = (exercise_guid !== null) ? ('/?itemId=' + exercise_guid) : '';
1932    var param_exercise_guid = exercise_guid !== null ? "/" + exercise_guid : "";
1933    //var param_exercise_guid = '';
1934    console.log("showExerciseEditor()");
1935
1936    //$("#exercise-editor-container iframe").attr("src", CoreData.editor_url + CoreData.token + '/' + CoreData.email + '/' + CoreData.project + param_exercise_guid);
1937
1938    if (arrayExercisesNames && Array.isArray(arrayExercisesNames)) {
1939      $("#exercise-editor-container iframe").attr(
1940        "src",
1941        CoreData.editor_url.replace("foreign", "quiz") +
1942        CoreData.token +
1943        "/" +
1944        arrayExercisesNames.toString()
1945      );
1946    } else {
1947      $("#exercise-editor-container iframe").attr(
1948        "src",
1949        CoreData.editor_url +
1950        CoreData.token +
1951        "/" +
1952        CoreData.email +
1953        "/" +
1954        CoreData.project +
1955        param_exercise_guid
1956      );
1957    }
1958    $("#exercise-editor-container").show();
1959    $("body").addClass("showing-modal");
1960  };
1961
1962  this.showVideo = function (url) {
1963    if (matchYoutubeUrl(url)) {
1964      this.checkYoutubeCookie(_showVideo);
1965    } else {
1966      _showVideo();
1967    }
1968    function _showVideo() {
1969      $("#exercise-editor-container .d-close-btn").show();
1970      $("#exercise-editor-container .d-close-btn").html(lang.exit);
1971      $("#exercise-editor-container iframe").attr("src", url);
1972      $("#exercise-editor-container").show();
1973      $("body").addClass("showing-modal");
1974    }
1975  };
1976  // exercise editor selection event
1977  window.addEventListener(
1978    "message",
1979    function (event) {
1980      //console.log(event.data);
1981      if (event.data.itemId) {
1982        console.log("on exercise select, id: " + event.data.itemId);
1983        if (typeof on_exercise_select_callback === "function") {
1984          on_exercise_select_callback(event.data);
1985        }
1986        mDiscover.hideExerciseEditor();
1987      } else if (event.data.height) {
1988        console.log("on exercise height");
1989        console.log(event.data);
1990        $(window).trigger("on_exercise_height", event.data);
1991      } else if (event.data.evaluation_finished) {
1992        $(window).trigger("evaluation_finished", event.data);
1993        //console.log(event.data);
1994      }
1995      if (event.data.exit) {
1996        mDiscover.hideExerciseEditor();
1997      }
1998    },
1999    false
2000  );
2001
2002  this.showAviso = function (anchor) {
2003    console.log(anchor);
2004    ModalAviso.showFixed();
2005    if (anchor == "pp") {
2006      $("#modal-aviso #tyc").hide();
2007      $("#modal-aviso #pp").show();
2008      $("#modal-aviso #pp").scrollTop(0);
2009    } else {
2010      $("#modal-aviso #tyc").show();
2011      $("#modal-aviso #pp").hide();
2012      if (anchor) {
2013        var $element = $("#modal-aviso #tyc a[name='" + anchor + "']");
2014        var offset1 = $element.position().top; // - $("#modal-aviso #tyc").offset().top;
2015        var offset2 = $element.offset().top; // - $("#modal-aviso #tyc").offset().top;
2016        console.log(anchor + ": " + offset1 + " - " + offset2);
2017        $("#modal-aviso #tyc").animate(
2018          {
2019            scrollTop: offset1,
2020          },
2021          1000
2022        );
2023      }
2024      $("#modal-aviso #tyc").scrollTop(0);
2025    }
2026  };
2027  this.showSuscribe = function () {
2028    //console.log("mDiscover.showSuscribe()");
2029    ModalSuscribe.show();
2030  };
2031  this.showSubscribe = function (cb) {
2032    callbackSubscriptionSuccess = cb;
2033    $('#modal-container .modal.d-modal-subscribe .d-input-code').html('');
2034    ModalSubscribe.show();
2035  };
2036  this.hideSubscribe = function () {
2037    ModalSubscribe.hide();
2038  };
2039  this.showChangePassword = function (cb) {
2040    callbackChangePasswordSuccess = cb;
2041    $('#modal-container .modal.d-modal-change-password .d-input-code1').html('********');
2042    $('#modal-container .modal.d-modal-change-password .d-input-code2').html('********');
2043    ModalChangePassword.show();
2044  };
2045  this.hideChangePassword = function () {
2046    ModalChangePassword.hide();
2047  };
2048  this.showClassroomCode = function (code, classroomName, educationLevel) {
2049    $('#modal-container .modal.d-modal-classroom-code .d-input-code').html(code);
2050    $('#modal-container .modal.d-modal-classroom-code .classroom-name').html(classroomName);
2051    $('#modal-container .modal.d-modal-classroom-code .education-level').html(educationLevel);
2052    ModalClassroomCode.show();
2053  };
2054  this.hideClassroomCode = function () {
2055    ModalClassroomCode.hide();
2056  };
2057  this.headerMode = headerMode;
2058  this.refreshGameData = function (callback) {
2059    if (getUser().role === "student") {
2060      mCom.ajax(
2061        "profile/student/game",
2062        "GET",
2063        "",
2064        function (data) {
2065          //console.log("refreshGameData ajax return");
2066          //console.log(data);
2067          updUserProfile(data);
2068          if (isFunction(callback)) callback(false);
2069        },
2070        function (err, status, msg) {
2071          if (isFunction(callback)) callback(err);
2072        }
2073      );
2074    } else {
2075      if (isFunction(callback))
2076        callback({ status: "fail", info: "Current user isn't student" });
2077    }
2078  };
2079  var is_video_finis_viewed = false;
2080  var is_video_finis_active = false;
2081  this.showVideoFinish = function () {
2082    if (!is_video_finis_viewed && is_video_finis_active) {
2083      is_video_finis_viewed = true;
2084
2085      switch (userLang) {
2086        case "eu":
2087          mDiscover.showVideo(
2088            "https://www.youtube.com/embed/iQKJmsVaAwM?rel=0"
2089          );
2090          break;
2091        case "va":
2092        case "ca":
2093          mDiscover.showVideo(
2094            "https://www.youtube.com/embed/o3E4MPu5n0Y?rel=0"
2095          );
2096          break;
2097        default:
2098          mDiscover.showVideo(
2099            "https://www.youtube.com/embed/uJl3ENZVYXU?rel=0"
2100          );
2101          break;
2102      }
2103    }
2104  };
2105
2106  this.openLPD = function (token) {
2107    if (token && token != "") {
2108      var informedUserLang = userLang;
2109      switch (userLang) {
2110        case "ar":
2111        case "mx":
2112          informedUserLang = "es";
2113          break;
2114      }
2115
2116      window.lpd.openAuthLPD({
2117        token: token,
2118        lang: informedUserLang,
2119        border: false,
2120        theme: "tatum",
2121        endpoint: config.edelvivesSso,
2122      });
2123    }
2124  };
2125  init();
2126};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.