main.js.tpl 21 KB

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