main.js.tpl 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. var ajax_url = _p.web_ajax + 'chat.ajax.php';
  2. var online_button = '<img src="' + _p.web_img + 'statusonline.png">';
  3. var offline_button = '<img src="' + _p.web_img + 'statusoffline.png">';
  4. var connect_lang = '{{ "ChatConnected"|get_lang | escape('js')}}';
  5. var disconnect_lang = '{{ "ChatDisconnected"|get_lang | escape('js')}}';
  6. var chatLang = '{{ "GlobalChat"|get_lang | escape('js')}}';
  7. {% if 'hide_chat_video'|api_get_configuration_value %}
  8. var hide_chat_video = true;
  9. {% else %}
  10. var hide_chat_video = false;
  11. {% endif %}
  12. $(function() {
  13. addMainEvent(window, 'unload', courseLogout ,false);
  14. $("#open-view-list").click(function(){
  15. $("#student-list-work").fadeIn(300);
  16. });
  17. $("#closed-view-list").click(function(){
  18. $("#student-list-work").fadeOut(300);
  19. });
  20. checkBrand();
  21. var id;
  22. $(window).resize(function() {
  23. clearTimeout(id);
  24. id = setTimeout(doneResizing, 200);
  25. });
  26. // Removes the yellow input in Chrome
  27. if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {
  28. $(window).on("load", function () {
  29. $('input:-webkit-autofill').each(function(){
  30. var text = $(this).val();
  31. var name = $(this).attr('name');
  32. $(this).after(this.outerHTML).remove();
  33. $('input[name=' + name + ']').val(text);
  34. });
  35. });
  36. }
  37. $(".accordion_jquery").accordion({
  38. autoHeight: false,
  39. active: false, // all items closed by default
  40. collapsible: true,
  41. header: ".accordion-heading"
  42. });
  43. // Start modals
  44. // class='ajax' loads a page in a modal
  45. $('body').on('click', 'a.ajax', function(e) {
  46. e.preventDefault();
  47. var contentUrl = this.href,
  48. loadModalContent = $.get(contentUrl),
  49. self = $(this);
  50. $.when(loadModalContent).done(function(modalContent) {
  51. var modalDialog = $('#global-modal').find('.modal-dialog'),
  52. modalSize = self.data('size') || get_url_params(contentUrl, 'modal_size'),
  53. modalWidth = self.data('width') || get_url_params(contentUrl, 'width'),
  54. modalTitle = self.data('title') || ' ';
  55. modalDialog.removeClass('modal-lg modal-sm').css('width', '');
  56. if (modalSize && modalSize.length != 0) {
  57. switch (modalSize) {
  58. case 'lg':
  59. modalDialog.addClass('modal-lg');
  60. break;
  61. case 'sm':
  62. modalDialog.addClass('modal-sm');
  63. break;
  64. }
  65. } else if (modalWidth) {
  66. modalDialog.css('width', modalWidth + 'px');
  67. }
  68. $('#global-modal').find('.modal-title').text(modalTitle);
  69. $('#global-modal').find('.modal-body').html(modalContent);
  70. $('#global-modal').modal('show');
  71. });
  72. });
  73. // Expands an image modal
  74. $('a.expand-image').on('click', function(e) {
  75. e.preventDefault();
  76. var title = $(this).attr('title');
  77. var image = new Image();
  78. image.onload = function() {
  79. if (title) {
  80. $('#expand-image-modal').find('.modal-title').text(title);
  81. } else {
  82. $('#expand-image-modal').find('.modal-title').html('&nbsp;');
  83. }
  84. $('#expand-image-modal').find('.modal-body').html(image);
  85. $('#expand-image-modal').modal({
  86. show: true
  87. });
  88. };
  89. image.src = this.href;
  90. });
  91. // Delete modal
  92. $('#confirm-delete').on('show.bs.modal', function(e) {
  93. $(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
  94. var message = '{{ 'AreYouSureToDeleteJS' | get_lang | escape('js')}}: <strong>' + $(e.relatedTarget).data('item-title') + '</strong>';
  95. if ($(e.relatedTarget).data('item-question')) {
  96. message = $(e.relatedTarget).data('item-question');
  97. }
  98. $('.debug-url').html(message);
  99. });
  100. // End modals
  101. // old jquery.menu.js
  102. $('#navigation a').stop().animate({
  103. 'marginLeft':'50px'
  104. },1000);
  105. $('#navigation div').hover(
  106. function () {
  107. $('a',$(this)).stop().animate({
  108. 'marginLeft':'1px'
  109. },200);
  110. },
  111. function () {
  112. $('a',$(this)).stop().animate({
  113. 'marginLeft':'50px'
  114. },200);
  115. }
  116. );
  117. /* Make responsive image maps */
  118. $('map').imageMapResize();
  119. jQuery.fn.filterByText = function(textbox) {
  120. return this.each(function() {
  121. var select = this;
  122. var options = [];
  123. $(select).find('option').each(function() {
  124. options.push({value: $(this).val(), text: $(this).text()});
  125. });
  126. $(select).data('options', options);
  127. $(textbox).bind('change keyup', function() {
  128. var options = $(select).empty().data('options');
  129. var search = $.trim($(this).val());
  130. var regex = new RegExp(search,"gi");
  131. $.each(options, function(i) {
  132. var option = options[i];
  133. if(option.text.match(regex) !== null) {
  134. $(select).append(
  135. $('<option>').text(option.text).val(option.value)
  136. );
  137. }
  138. });
  139. });
  140. });
  141. };
  142. $(".black-shadow").mouseenter(function() {
  143. $(this).addClass('hovered-course');
  144. }).mouseleave(function() {
  145. $(this).removeClass('hovered-course');
  146. });
  147. $("[data-toggle=popover]").each(function(i, obj) {
  148. $(this).popover({
  149. html: true,
  150. content: function() {
  151. var id = $(this).attr('id')
  152. return $('#popover-content-' + id).html();
  153. }
  154. });
  155. });
  156. $('.scrollbar-inner').scrollbar();
  157. // Date time settings.
  158. moment.locale('{{ locale }}');
  159. $.datepicker.setDefaults($.datepicker.regional["{{ locale }}"]);
  160. $.datepicker.regional["local"] = $.datepicker.regional["{{ locale }}"];
  161. // Fix old calls of "inc/lib/mediaplayer/player.swf" and convert to <audio> tag, then rendered by media element js
  162. // see BT#13405
  163. $('embed').each( function () {
  164. var flashVars = $(this).attr('flashvars');
  165. if (flashVars && flashVars.indexOf("file") == -1) {
  166. var audioId = Math.floor( Math.random()*99999 );
  167. flashVars = flashVars.replace('&autostart=false', '');
  168. flashVars = flashVars.replace('&autostart=true', '');
  169. var audioDiv = '<audio id="'+audioId+'" controls="controls" style="width:400px;" width:"400px;" src="'+flashVars+'" ><source src="'+flashVars+'" type="audio/mp3" ></source></audio>';
  170. $(this).hide();
  171. $(this).after(audioDiv);
  172. }
  173. });
  174. // Chosen select
  175. $(".chzn-select").chosen({
  176. disable_search_threshold: 10,
  177. no_results_text: '{{ 'SearchNoResultsFound' | get_lang | escape('js') }}',
  178. placeholder_text_multiple: '{{ 'SelectSomeOptions' | get_lang | escape('js') }}',
  179. placeholder_text_single: '{{ 'SelectAnOption' | get_lang | escape('js') }}',
  180. width: "100%"
  181. });
  182. // Bootstrap tabs.
  183. $('.tab-wrapper a').click(function (e) {
  184. e.preventDefault();
  185. $(this).tab('show');
  186. //$('#tabs a:first').tab('show') // Select first tab
  187. });
  188. // Fixes bug when loading links inside a tab.
  189. $('.tab-wrapper .tab-pane a').unbind();
  190. /**
  191. * Advanced options
  192. * Usage
  193. * <a id="link" href="url">Advanced</a>
  194. * <div id="link_options">
  195. * hidden content :)
  196. * </div>
  197. * */
  198. $(".advanced_options").on("click", function (event) {
  199. event.preventDefault();
  200. var id = $(this).attr('id') + '_options';
  201. var button = $(this);
  202. $("#" + id).toggle();
  203. });
  204. /**
  205. * <a class="advanced_options_open" href="http://" rel="div_id">Open</a>
  206. * <a class="advanced_options_close" href="http://" rel="div_id">Close</a>
  207. * <div id="div_id">Div content</div>
  208. * */
  209. $(".advanced_options_open").on("click", function (event) {
  210. event.preventDefault();
  211. var id = $(this).attr('rel');
  212. $("#" + id).show();
  213. });
  214. $(".advanced_options_close").on("click", function (event) {
  215. event.preventDefault();
  216. var id = $(this).attr('rel');
  217. $("#" + id).hide();
  218. });
  219. // Adv multi-select search input.
  220. $('.select_class_filter').each( function () {
  221. var inputId = $(this).attr('id');
  222. inputId = inputId.replace('-filter', '');
  223. $("#" + inputId).filterByText($("#" + inputId + "-filter"));
  224. });
  225. // Mediaelement
  226. if ( {{ show_media_element }} == 1) {
  227. $('video:not(.skip), audio:not(.skip)').mediaelementplayer({
  228. pluginPath: _p.web + 'web/assets/mediaelement/build/',
  229. //renderers: ['html5', 'flash_video', 'native_flv'],
  230. features: ['{{ video_features }}'],
  231. success: function(mediaElement, originalNode, instance) {
  232. {{ quiz_markers_rolls_js }}
  233. },
  234. vrPath: _p.web + 'web/assets/vrview/build/vrview.js'
  235. });
  236. }
  237. // Table highlight.
  238. $("form .data_table input:checkbox").click(function () {
  239. if ($(this).is(":checked")) {
  240. $(this).parentsUntil("tr").parent().addClass("row_selected");
  241. } else {
  242. $(this).parentsUntil("tr").parent().removeClass("row_selected");
  243. }
  244. });
  245. /* For non HTML5 browsers */
  246. if ($("#formLogin".length > 1)) {
  247. $("input[name=login]").focus();
  248. }
  249. // Tool tip (in exercises)
  250. var tip_options = {
  251. placement: 'right'
  252. };
  253. $('.boot-tooltip').tooltip(tip_options);
  254. var more = '{{ 'SeeMore' | get_lang | escape('js') }}';
  255. var close = '{{ 'Close' | get_lang | escape('js') }}';
  256. $('.list-teachers').readmore({
  257. speed: 75,
  258. moreLink: '<a href="#">' + more + '</a>',
  259. lessLink: '<a href="#">' + close + '</a>',
  260. collapsedHeight: 35,
  261. blockCSS: 'display: block; width: 100%;'
  262. });
  263. $('.star-rating li a').on('click', function(event) {
  264. var id = $(this).parents('ul').attr('id');
  265. $('#vote_label2_' + id).html("{{'Loading'|get_lang| escape('js')}}");
  266. $.ajax({
  267. url: $(this).attr('data-link'),
  268. success: function(data) {
  269. $("#rating_wrapper_"+id).html(data);
  270. if (data == 'added') {
  271. //$('#vote_label2_' + id).html("{{'Saved'|get_lang | escape('js')}}");
  272. }
  273. if (data == 'updated') {
  274. //$('#vote_label2_' + id).html("{{'Saved'|get_lang| escape('js')}}");
  275. }
  276. }
  277. });
  278. });
  279. $("#notifications").load(_p.web_ajax + "online.ajax.php?a=get_users_online");
  280. $('video:not(.skip)').attr('preload', 'metadata');
  281. function socialLikes() {
  282. {% if 'social_enable_messages_feedback'|api_get_configuration_value %}
  283. $('body').on('click', '.social-like', function (e) {
  284. e.preventDefault();
  285. var $self = $(this),
  286. status = $self.data('status') || '',
  287. group = $self.data('group') || 0,
  288. message = $self.data('message') || 0;
  289. $.getJSON(
  290. '{{ _p.web_ajax }}social.ajax.php',
  291. {'a': 'like_message', 'group': group, 'id': message, 'status': status}
  292. ).then(function (response) {
  293. if (!response) {
  294. return;
  295. }
  296. var $count = $self.children('span'),
  297. currentCount = parseInt($count.text()) || 0;
  298. if ('like' === status) {
  299. var $dislike = $self.next(),
  300. $dislikeCount = $dislike.children('span'),
  301. dislikeCount = parseInt($dislikeCount.text()) || 0;
  302. $count.text(++currentCount);
  303. if ($dislike.is('.btn-danger')) {
  304. $dislikeCount.text(dislikeCount <= 0 ? 0 : --dislikeCount);
  305. $dislike.removeClass('btn-danger');
  306. }
  307. $self.addClass('btn-primary');
  308. } else if ('dislike' === status) {
  309. var $like = $self.prev(),
  310. $likeCount = $like.children('span'),
  311. likeCount = parseInt($likeCount.text()) || 0;
  312. $count.text(++currentCount);
  313. if ($like.is('.btn-primary')) {
  314. $likeCount.text(likeCount <= 0 ? 0 : --likeCount);
  315. $like.removeClass('btn-primary');
  316. }
  317. $self.addClass('btn-danger');
  318. }
  319. });
  320. });
  321. {% endif %}
  322. }
  323. socialLikes();
  324. });
  325. $(window).resize(function() {
  326. checkBrand();
  327. });
  328. $(document).scroll(function() {
  329. var valor = $('body').outerHeight() - 700;
  330. if ($(this).scrollTop() > 100) {
  331. $('.bottom_actions').addClass('bottom_actions_fixed');
  332. } else {
  333. $('.bottom_actions').removeClass('bottom_actions_fixed');
  334. }
  335. if ($(this).scrollTop() > valor) {
  336. $('.bottom_actions').removeClass('bottom_actions_fixed');
  337. } else {
  338. $('.bottom_actions').addClass('bottom_actions_fixed');
  339. }
  340. // Exercise warning fixed at the top
  341. var fixed = $("#exercise_clock_warning");
  342. if (fixed.length) {
  343. if (!fixed.attr('data-top')) {
  344. // If already fixed, then do nothing
  345. if (fixed.hasClass('subnav-fixed')) return;
  346. // Remember top position
  347. var offset = fixed.offset();
  348. fixed.attr('data-top', offset.top);
  349. fixed.css('width', '100%');
  350. }
  351. if (fixed.attr('data-top') - fixed.outerHeight() <= $(this).scrollTop()) {
  352. fixed.addClass('navbar-fixed-top');
  353. fixed.css('width', '100%');
  354. } else {
  355. fixed.removeClass('navbar-fixed-top');
  356. fixed.css('width', '100%');
  357. }
  358. }
  359. // Admin -> Settings toolbar.
  360. if ($('body').width() > 959) {
  361. if ($('.new_actions').length) {
  362. if (!$('.new_actions').attr('data-top')) {
  363. // If already fixed, then do nothing
  364. if ($('.new_actions').hasClass('new_actions-fixed')) return;
  365. // Remember top position
  366. var offset = $('.new_actions').offset();
  367. var more_top = 0;
  368. if ($('.subnav').hasClass('new_actions-fixed')) {
  369. more_top = 50;
  370. }
  371. $('.new_actions').attr('data-top', offset.top + more_top);
  372. }
  373. // Check if the height is enough before fixing the icons menu (or otherwise removing it)
  374. // Added a 30px offset otherwise sometimes the menu plays ping-pong when scrolling to
  375. // the bottom of the page on short pages.
  376. if ($('.new_actions').attr('data-top') - $('.new_actions').outerHeight() <= $(this).scrollTop() + 30) {
  377. $('.new_actions').addClass('new_actions-fixed');
  378. } else {
  379. $('.new_actions').removeClass('new_actions-fixed');
  380. }
  381. }
  382. }
  383. });
  384. function get_url_params(q, attribute) {
  385. var hash;
  386. if (q != undefined) {
  387. q = q.split('&');
  388. for(var i = 0; i < q.length; i++){
  389. hash = q[i].split('=');
  390. if (hash[0] == attribute) {
  391. return hash[1];
  392. }
  393. }
  394. }
  395. }
  396. function checkBrand() {
  397. if ($('.subnav').length) {
  398. if ($(window).width() >= 969) {
  399. $('.subnav .brand').hide();
  400. } else {
  401. $('.subnav .brand').show();
  402. }
  403. }
  404. }
  405. function setCheckbox(value, table_id) {
  406. checkboxes = $("#"+table_id+" input:checkbox");
  407. $.each(checkboxes, function(index, checkbox) {
  408. checkbox.checked = value;
  409. if (value) {
  410. $(checkbox).parentsUntil("tr").parent().addClass("row_selected");
  411. } else {
  412. $(checkbox).parentsUntil("tr").parent().removeClass("row_selected");
  413. }
  414. });
  415. return false;
  416. }
  417. function action_click(element, table_id) {
  418. d = $("#"+table_id);
  419. if (!confirm('{{ "ConfirmYourChoice"|get_lang | escape('js')}}')) {
  420. return false;
  421. } else {
  422. var action =$(element).attr("data-action");
  423. $('#'+table_id+' input[name="action"] ').attr("value", action);
  424. d.submit();
  425. return false;
  426. }
  427. }
  428. /**
  429. * Generic function to replace the deprecated jQuery toggle function
  430. * @param inId : id of block to hide / unhide
  431. * @param inIdTxt : id of the button
  432. * @param inTxtHide : text one of the button
  433. * @param inTxtUnhide : text two of the button
  434. * @todo : allow to detect if text is from a button or from a <a>
  435. */
  436. function hideUnhide(inId, inIdTxt, inTxtHide, inTxtUnhide) {
  437. if ($('#'+inId).css("display") == "none") {
  438. $('#'+inId).show(400);
  439. $('#'+inIdTxt).attr("value", inTxtUnhide);
  440. } else {
  441. $('#'+inId).hide(400);
  442. $('#'+inIdTxt).attr("value", inTxtHide);
  443. }
  444. }
  445. function expandColumnToogle(buttonSelector, col1Info, col2Info) {
  446. $(buttonSelector).on('click', function (e) {
  447. e.preventDefault();
  448. col1Info = $.extend({
  449. selector: '',
  450. width: 4
  451. }, col1Info);
  452. col2Info = $.extend({
  453. selector: '',
  454. width: 8
  455. }, col2Info);
  456. if (!col1Info.selector || !col2Info.selector) {
  457. return;
  458. }
  459. var col1 = $(col1Info.selector),
  460. col2 = $(col2Info.selector);
  461. $('#expand').toggleClass('hide');
  462. $('#contract').toggleClass('hide');
  463. if (col2.is('.col-md-' + col2Info.width)) {
  464. col2.removeClass('col-md-' + col2Info.width).addClass('col-md-12');
  465. col1.removeClass('col-md-' + col1Info.width).addClass('hide');
  466. return;
  467. }
  468. col2.removeClass('col-md-12').addClass('col-md-' + col2Info.width);
  469. col1.removeClass('hide').addClass('col-md-' + col1Info.width);
  470. });
  471. }
  472. // Load ckeditor plugins
  473. if (typeof CKEDITOR !== 'undefined') {
  474. // External plugins not part of the default Ckeditor package.
  475. var plugins = [
  476. 'asciimath',
  477. 'asciisvg',
  478. 'audio',
  479. 'ckeditor_wiris',
  480. 'dialogui',
  481. 'glossary',
  482. 'leaflet',
  483. 'mapping',
  484. 'maximize',
  485. 'mathjax',
  486. 'oembed',
  487. 'toolbar',
  488. 'toolbarswitch',
  489. 'video',
  490. 'wikilink',
  491. 'wordcount',
  492. 'youtube',
  493. 'flash',
  494. 'inserthtml',
  495. 'qmarkersrolls',
  496. 'image2_chamilo'
  497. ];
  498. plugins.forEach(function (plugin) {
  499. CKEDITOR.plugins.addExternal(
  500. plugin,
  501. _p.web_lib + '{{ 'javascript/ckeditor/plugins/' }}' + plugin + '/'
  502. );
  503. });
  504. /**
  505. * Function use to load templates in a div
  506. **/
  507. var showTemplates = function (ckeditorName) {
  508. var editorName = 'content';
  509. if (ckeditorName && ckeditorName.length > 0) {
  510. editorName = ckeditorName;
  511. }
  512. CKEDITOR.editorConfig(CKEDITOR.config);
  513. CKEDITOR.loadTemplates(CKEDITOR.config.templates_files, function (a) {
  514. var templatesConfig = CKEDITOR.getTemplates("default");
  515. var $templatesUL = $("<ul>");
  516. if (templatesConfig) {
  517. $.each(templatesConfig.templates, function () {
  518. var template = this;
  519. var $templateLi = $("<li>");
  520. var templateHTML = "<img src=\"" + templatesConfig.imagesPath + template.image + "\" ><div>";
  521. templateHTML += "<b>" + template.title + "</b>";
  522. if (template.description) {
  523. templateHTML += "<div class=description>" + template.description + "</div>";
  524. }
  525. templateHTML += "</div>";
  526. $("<a>", {
  527. href: "#",
  528. html: templateHTML,
  529. click: function (e) {
  530. e.preventDefault();
  531. if (CKEDITOR.instances[editorName]) {
  532. CKEDITOR.instances[editorName].setData(template.html, function () {
  533. this.checkDirty();
  534. });
  535. }
  536. }
  537. }).appendTo($templateLi);
  538. $templatesUL.append($templateLi);
  539. });
  540. }
  541. $templatesUL.appendTo("#frmModel");
  542. });
  543. };
  544. }
  545. function doneResizing() {
  546. var widthWindow = $(window).width();
  547. if ((widthWindow>=1024) && (widthWindow>=768)) {
  548. $("#profileCollapse").addClass("in");
  549. $("#courseCollapse").addClass("in");
  550. $("#skillsCollapse").addClass("in");
  551. $("#sn-sidebar-collapse").addClass("in");
  552. $("#user_image_block").removeClass("text-muted");
  553. } else {
  554. $("#profileCollapse").removeClass("in");
  555. $("#courseCollapse").removeClass("in");
  556. $("#skillsCollapse").removeClass("in");
  557. $("#sn-avatar-one").removeClass("in");
  558. $("#user_image_block").addClass("text-muted");
  559. }
  560. }
  561. function addMainEvent(elm, evType, fn, useCapture) {
  562. if (elm.addEventListener) {
  563. elm.addEventListener(evType, fn, useCapture);
  564. return true;
  565. } else if (elm.attachEvent) {
  566. elm.attachEvent('on' + evType, fn);
  567. } else {
  568. elm['on'+evType] = fn;
  569. }
  570. }
  571. function copyTextToClipBoard(elementId)
  572. {
  573. /* Get the text field */
  574. var copyText = document.getElementById(elementId);
  575. /* Select the text field */
  576. copyText.select();
  577. /* Copy the text inside the text field */
  578. document.execCommand("copy");
  579. }