main.js.tpl 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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. });
  228. }
  229. // Table highlight.
  230. $("form .data_table input:checkbox").click(function () {
  231. if ($(this).is(":checked")) {
  232. $(this).parentsUntil("tr").parent().addClass("row_selected");
  233. } else {
  234. $(this).parentsUntil("tr").parent().removeClass("row_selected");
  235. }
  236. });
  237. /* For non HTML5 browsers */
  238. if ($("#formLogin".length > 1)) {
  239. $("input[name=login]").focus();
  240. }
  241. // Tool tip (in exercises)
  242. var tip_options = {
  243. placement: 'right'
  244. };
  245. $('.boot-tooltip').tooltip(tip_options);
  246. var more = '{{ 'SeeMore' | get_lang | escape('js') }}';
  247. var close = '{{ 'Close' | get_lang | escape('js') }}';
  248. $('.list-teachers').readmore({
  249. speed: 75,
  250. moreLink: '<a href="#">' + more + '</a>',
  251. lessLink: '<a href="#">' + close + '</a>',
  252. collapsedHeight: 35,
  253. blockCSS: 'display: block; width: 100%;'
  254. });
  255. $('.star-rating li a').on('click', function(event) {
  256. var id = $(this).parents('ul').attr('id');
  257. $('#vote_label2_' + id).html("{{'Loading'|get_lang}}");
  258. $.ajax({
  259. url: $(this).attr('data-link'),
  260. success: function(data) {
  261. $("#rating_wrapper_"+id).html(data);
  262. if (data == 'added') {
  263. //$('#vote_label2_' + id).html("{{'Saved'|get_lang}}");
  264. }
  265. if (data == 'updated') {
  266. //$('#vote_label2_' + id).html("{{'Saved'|get_lang}}");
  267. }
  268. }
  269. });
  270. });
  271. $("#notifications").load(_p.web_ajax + "online.ajax.php?a=get_users_online");
  272. });
  273. $(window).resize(function() {
  274. checkBrand();
  275. });
  276. $(document).scroll(function() {
  277. var valor = $('body').outerHeight() - 700;
  278. if ($(this).scrollTop() > 100) {
  279. $('.bottom_actions').addClass('bottom_actions_fixed');
  280. } else {
  281. $('.bottom_actions').removeClass('bottom_actions_fixed');
  282. }
  283. if ($(this).scrollTop() > valor) {
  284. $('.bottom_actions').removeClass('bottom_actions_fixed');
  285. } else {
  286. $('.bottom_actions').addClass('bottom_actions_fixed');
  287. }
  288. //Exercise warning fixed at the top
  289. var fixed = $("#exercise_clock_warning");
  290. if (fixed.length) {
  291. if (!fixed.attr('data-top')) {
  292. // If already fixed, then do nothing
  293. if (fixed.hasClass('subnav-fixed')) return;
  294. // Remember top position
  295. var offset = fixed.offset();
  296. fixed.attr('data-top', offset.top);
  297. fixed.css('width', '100%');
  298. }
  299. if (fixed.attr('data-top') - fixed.outerHeight() <= $(this).scrollTop()) {
  300. fixed.addClass('navbar-fixed-top');
  301. fixed.css('width', '100%');
  302. } else {
  303. fixed.removeClass('navbar-fixed-top');
  304. fixed.css('width', '100%');
  305. }
  306. }
  307. // Admin -> Settings toolbar.
  308. if ($('body').width() > 959) {
  309. if ($('.new_actions').length) {
  310. if (!$('.new_actions').attr('data-top')) {
  311. // If already fixed, then do nothing
  312. if ($('.new_actions').hasClass('new_actions-fixed')) return;
  313. // Remember top position
  314. var offset = $('.new_actions').offset();
  315. var more_top = 0;
  316. if ($('.subnav').hasClass('new_actions-fixed')) {
  317. more_top = 50;
  318. }
  319. $('.new_actions').attr('data-top', offset.top + more_top);
  320. }
  321. // Check if the height is enough before fixing the icons menu (or otherwise removing it)
  322. // Added a 30px offset otherwise sometimes the menu plays ping-pong when scrolling to
  323. // the bottom of the page on short pages.
  324. if ($('.new_actions').attr('data-top') - $('.new_actions').outerHeight() <= $(this).scrollTop() + 30) {
  325. $('.new_actions').addClass('new_actions-fixed');
  326. } else {
  327. $('.new_actions').removeClass('new_actions-fixed');
  328. }
  329. }
  330. }
  331. });
  332. function get_url_params(q, attribute) {
  333. var hash;
  334. if (q != undefined) {
  335. q = q.split('&');
  336. for(var i = 0; i < q.length; i++){
  337. hash = q[i].split('=');
  338. if (hash[0] == attribute) {
  339. return hash[1];
  340. }
  341. }
  342. }
  343. }
  344. function checkBrand() {
  345. if ($('.subnav').length) {
  346. if ($(window).width() >= 969) {
  347. $('.subnav .brand').hide();
  348. } else {
  349. $('.subnav .brand').show();
  350. }
  351. }
  352. }
  353. function setCheckbox(value, table_id) {
  354. checkboxes = $("#"+table_id+" input:checkbox");
  355. $.each(checkboxes, function(index, checkbox) {
  356. checkbox.checked = value;
  357. if (value) {
  358. $(checkbox).parentsUntil("tr").parent().addClass("row_selected");
  359. } else {
  360. $(checkbox).parentsUntil("tr").parent().removeClass("row_selected");
  361. }
  362. });
  363. return false;
  364. }
  365. function action_click(element, table_id) {
  366. d = $("#"+table_id);
  367. if (!confirm('{{ "ConfirmYourChoice"|get_lang }}')) {
  368. return false;
  369. } else {
  370. var action =$(element).attr("data-action");
  371. $('#'+table_id+' input[name="action"] ').attr("value", action);
  372. d.submit();
  373. return false;
  374. }
  375. }
  376. /**
  377. * Generic function to replace the deprecated jQuery toggle function
  378. * @param inId : id of block to hide / unhide
  379. * @param inIdTxt : id of the button
  380. * @param inTxtHide : text one of the button
  381. * @param inTxtUnhide : text two of the button
  382. * @todo : allow to detect if text is from a button or from a <a>
  383. */
  384. function hideUnhide(inId, inIdTxt, inTxtHide, inTxtUnhide) {
  385. if ($('#'+inId).css("display") == "none") {
  386. $('#'+inId).show(400);
  387. $('#'+inIdTxt).attr("value", inTxtUnhide);
  388. } else {
  389. $('#'+inId).hide(400);
  390. $('#'+inIdTxt).attr("value", inTxtHide);
  391. }
  392. }
  393. function expandColumnToogle(buttonSelector, col1Info, col2Info) {
  394. $(buttonSelector).on('click', function (e) {
  395. e.preventDefault();
  396. col1Info = $.extend({
  397. selector: '',
  398. width: 4
  399. }, col1Info);
  400. col2Info = $.extend({
  401. selector: '',
  402. width: 8
  403. }, col2Info);
  404. if (!col1Info.selector || !col2Info.selector) {
  405. return;
  406. }
  407. var col1 = $(col1Info.selector),
  408. col2 = $(col2Info.selector);
  409. $('#expand').toggleClass('hide');
  410. $('#contract').toggleClass('hide');
  411. if (col2.is('.col-md-' + col2Info.width)) {
  412. col2.removeClass('col-md-' + col2Info.width).addClass('col-md-12');
  413. col1.removeClass('col-md-' + col1Info.width).addClass('hide');
  414. return;
  415. }
  416. col2.removeClass('col-md-12').addClass('col-md-' + col2Info.width);
  417. col1.removeClass('hide').addClass('col-md-' + col1Info.width);
  418. });
  419. }
  420. // Load ckeditor plugins
  421. if (typeof CKEDITOR !== 'undefined') {
  422. // External plugins not part of the default Ckeditor package.
  423. var plugins = [
  424. 'asciimath',
  425. 'asciisvg',
  426. 'audio',
  427. 'ckeditor_wiris',
  428. 'dialogui',
  429. 'glossary',
  430. 'leaflet',
  431. 'mapping',
  432. 'maximize',
  433. 'mathjax',
  434. 'oembed',
  435. 'toolbar',
  436. 'toolbarswitch',
  437. 'video',
  438. 'wikilink',
  439. 'wordcount',
  440. 'youtube',
  441. 'flash',
  442. 'inserthtml',
  443. 'image2_chamilo'
  444. ];
  445. plugins.forEach(function (plugin) {
  446. CKEDITOR.plugins.addExternal(
  447. plugin,
  448. _p.web_lib + '{{ 'javascript/ckeditor/plugins/' }}' + plugin + '/'
  449. );
  450. });
  451. /**
  452. * Function use to load templates in a div
  453. **/
  454. var showTemplates = function (ckeditorName) {
  455. var editorName = 'content';
  456. if (ckeditorName && ckeditorName.length > 0) {
  457. editorName = ckeditorName;
  458. }
  459. CKEDITOR.editorConfig(CKEDITOR.config);
  460. CKEDITOR.loadTemplates(CKEDITOR.config.templates_files, function (a) {
  461. var templatesConfig = CKEDITOR.getTemplates("default");
  462. var $templatesUL = $("<ul>");
  463. if (templatesConfig) {
  464. $.each(templatesConfig.templates, function () {
  465. var template = this;
  466. var $templateLi = $("<li>");
  467. var templateHTML = "<img src=\"" + templatesConfig.imagesPath + template.image + "\" ><div>";
  468. templateHTML += "<b>" + template.title + "</b>";
  469. if (template.description) {
  470. templateHTML += "<div class=description>" + template.description + "</div>";
  471. }
  472. templateHTML += "</div>";
  473. $("<a>", {
  474. href: "#",
  475. html: templateHTML,
  476. click: function (e) {
  477. e.preventDefault();
  478. if (CKEDITOR.instances[editorName]) {
  479. CKEDITOR.instances[editorName].setData(template.html, function () {
  480. this.checkDirty();
  481. });
  482. }
  483. }
  484. }).appendTo($templateLi);
  485. $templatesUL.append($templateLi);
  486. });
  487. }
  488. $templatesUL.appendTo("#frmModel");
  489. });
  490. };
  491. }
  492. function doneResizing() {
  493. var widthWindow = $(window).width();
  494. if ((widthWindow>=1024) && (widthWindow>=768)) {
  495. $("#profileCollapse").addClass("in");
  496. $("#courseCollapse").addClass("in");
  497. $("#skillsCollapse").addClass("in");
  498. $("#sn-sidebar-collapse").addClass("in");
  499. $("#user_image_block").removeClass("text-muted");
  500. } else {
  501. $("#profileCollapse").removeClass("in");
  502. $("#courseCollapse").removeClass("in");
  503. $("#skillsCollapse").removeClass("in");
  504. $("#sn-avatar-one").removeClass("in");
  505. $("#user_image_block").addClass("text-muted");
  506. }
  507. }
  508. function addMainEvent(elm, evType, fn, useCapture) {
  509. if (elm.addEventListener) {
  510. elm.addEventListener(evType, fn, useCapture);
  511. return true;
  512. } else if (elm.attachEvent) {
  513. elm.attachEvent('on' + evType, fn);
  514. } else {
  515. elm['on'+evType] = fn;
  516. }
  517. }
  518. function copyTextToClipBoard(elementId)
  519. {
  520. /* Get the text field */
  521. var copyText = document.getElementById(elementId);
  522. /* Select the text field */
  523. copyText.select();
  524. /* Copy the text inside the text field */
  525. document.execCommand("copy");
  526. /* Alert the copied text */
  527. //alert('Copied');
  528. }