header.js.tpl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. <script src="{{ _p.web_css_theme }}js/jquery.checkradios.min.js"></script>
  2. <script>
  3. {% if constant('CHAMILO_LOAD_WYSIWYG') %}
  4. // External plugins not part of the default Ckeditor package.
  5. var plugins = [
  6. 'asciimath',
  7. 'asciisvg',
  8. 'audio',
  9. 'ckeditor_wiris',
  10. 'dialogui',
  11. 'glossary',
  12. 'leaflet',
  13. 'mapping',
  14. 'maximize',
  15. 'mathjax',
  16. 'oembed',
  17. 'toolbar',
  18. 'toolbarswitch',
  19. 'video',
  20. 'wikilink',
  21. 'wordcount',
  22. 'youtube',
  23. 'flash',
  24. 'inserthtml',
  25. 'image2_chamilo'
  26. ];
  27. plugins.forEach(function(plugin) {
  28. CKEDITOR.plugins.addExternal(plugin, '{{ _p.web_main ~ 'inc/lib/javascript/ckeditor/plugins/' }}' + plugin + '/');
  29. });
  30. /**
  31. * Function use to load templates in a div
  32. **/
  33. var showTemplates = function (ckeditorName) {
  34. var editorName = 'content';
  35. if (ckeditorName && ckeditorName.length > 0) {
  36. editorName = ckeditorName;
  37. }
  38. CKEDITOR.editorConfig(CKEDITOR.config);
  39. CKEDITOR.loadTemplates(CKEDITOR.config.templates_files, function (a) {
  40. var templatesConfig = CKEDITOR.getTemplates("default");
  41. var $templatesUL = $("<ul>");
  42. if (templatesConfig) {
  43. $.each(templatesConfig.templates, function () {
  44. var template = this;
  45. var $templateLi = $("<li>");
  46. var templateHTML = "<img src=\"" + templatesConfig.imagesPath + template.image + "\" ><div>";
  47. templateHTML += "<b>" + template.title + "</b>";
  48. if (template.description) {
  49. templateHTML += "<div class=description>" + template.description + "</div>";
  50. }
  51. templateHTML += "</div>";
  52. $("<a>", {
  53. href: "#",
  54. html: templateHTML,
  55. click: function (e) {
  56. e.preventDefault();
  57. if (CKEDITOR.instances[editorName]) {
  58. CKEDITOR.instances[editorName].setData(template.html, function () {
  59. this.checkDirty();
  60. });
  61. }
  62. }
  63. }).appendTo($templateLi);
  64. $templatesUL.append($templateLi);
  65. });
  66. }
  67. $templatesUL.appendTo("#frmModel");
  68. });
  69. };
  70. {% endif %}
  71. function doneResizing() {
  72. var widhtWindow = $(window).width();
  73. if ((widhtWindow>=1024) && (widhtWindow>=768)) {
  74. $("#profileCollapse").addClass("in");
  75. $("#courseCollapse").addClass("in");
  76. $("#skillsCollapse").addClass("in");
  77. $("#sn-sidebar-collapse").addClass("in");
  78. $("#user_image_block").removeClass("text-muted");
  79. } else {
  80. $("#profileCollapse").removeClass("in");
  81. $("#courseCollapse").removeClass("in");
  82. $("#skillsCollapse").removeClass("in");
  83. $("#sn-avatar-one").removeClass("in");
  84. $("#user_image_block").addClass("text-muted");
  85. }
  86. };
  87. $(document).ready(function() {
  88. $('.checkradios').checkradios();
  89. $("#open-view-list").click(function(){
  90. $("#student-list-work").fadeIn(300);
  91. });
  92. $("#closed-view-list").click(function(){
  93. $("#student-list-work").fadeOut(300);
  94. });
  95. check_brand();
  96. var id;
  97. $(window).resize(function() {
  98. clearTimeout(id);
  99. id = setTimeout(doneResizing, 200);
  100. });
  101. // Removes the yellow input in Chrome
  102. if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {
  103. $(window).load(function(){
  104. $('input:-webkit-autofill').each(function(){
  105. var text = $(this).val();
  106. var name = $(this).attr('name');
  107. $(this).after(this.outerHTML).remove();
  108. $('input[name=' + name + ']').val(text);
  109. });
  110. });
  111. }
  112. $(".accordion_jquery").accordion({
  113. autoHeight: false,
  114. active: false, // all items closed by default
  115. collapsible: true,
  116. header: ".accordion-heading"
  117. });
  118. // Global popup
  119. $('body').on('click', 'a.ajax', function(e) {
  120. e.preventDefault();
  121. var contentUrl = this.href,
  122. loadModalContent = $.get(contentUrl),
  123. self = $(this);
  124. $.when(loadModalContent).done(function(modalContent) {
  125. var modalDialog = $('#global-modal').find('.modal-dialog'),
  126. modalSize = self.data('size') || get_url_params(contentUrl, 'modal_size'),
  127. modalWidth = self.data('width') || get_url_params(contentUrl, 'width'),
  128. modalTitle = self.data('title') || ' ';
  129. modalDialog.removeClass('modal-lg modal-sm').css('width', '');
  130. if (modalSize) {
  131. switch (modalSize) {
  132. case 'lg':
  133. modalDialog.addClass('modal-lg');
  134. break;
  135. case 'sm':
  136. modalDialog.addClass('modal-sm');
  137. break;
  138. }
  139. } else if (modalWidth) {
  140. modalDialog.css('width', modalWidth + 'px');
  141. }
  142. $('#global-modal').find('.modal-title').text(modalTitle);
  143. $('#global-modal').find('.modal-body').html(modalContent);
  144. $('#global-modal').modal('show');
  145. });
  146. });
  147. $('a.expand-image').on('click', function(e) {
  148. e.preventDefault();
  149. var title = $(this).attr('title');
  150. var image = new Image();
  151. image.onload = function() {
  152. if (title) {
  153. $('#expand-image-modal').find('.modal-title').text(title);
  154. } else {
  155. $('#expand-image-modal').find('.modal-title').html('&nbsp;');
  156. }
  157. $('#expand-image-modal').find('.modal-body').html(image);
  158. $('#expand-image-modal').modal({
  159. show: true
  160. });
  161. };
  162. image.src = this.href;
  163. });
  164. // Global confirmation
  165. $('.popup-confirmation').on('click', function() {
  166. showConfirmationPopup(this);
  167. return false;
  168. });
  169. // old jquery.menu.js
  170. $('#navigation a').stop().animate({
  171. 'marginLeft':'50px'
  172. },1000);
  173. $('#navigation div').hover(
  174. function () {
  175. $('a',$(this)).stop().animate({
  176. 'marginLeft':'1px'
  177. },200);
  178. },
  179. function () {
  180. $('a',$(this)).stop().animate({
  181. 'marginLeft':'50px'
  182. },200);
  183. }
  184. );
  185. /* Make responsive image maps */
  186. $('map').imageMapResize();
  187. jQuery.fn.filterByText = function(textbox) {
  188. return this.each(function() {
  189. var select = this;
  190. var options = [];
  191. $(select).find('option').each(function() {
  192. options.push({value: $(this).val(), text: $(this).text()});
  193. });
  194. $(select).data('options', options);
  195. $(textbox).bind('change keyup', function() {
  196. var options = $(select).empty().data('options');
  197. var search = $.trim($(this).val());
  198. var regex = new RegExp(search,"gi");
  199. $.each(options, function(i) {
  200. var option = options[i];
  201. if(option.text.match(regex) !== null) {
  202. $(select).append(
  203. $('<option>').text(option.text).val(option.value)
  204. );
  205. }
  206. });
  207. });
  208. });
  209. };
  210. $(".black-shadow").mouseenter(function() {
  211. $(this).addClass('hovered-course');
  212. }).mouseleave(function() {
  213. $(this).removeClass('hovered-course');
  214. });
  215. });
  216. $(window).resize(function() {
  217. check_brand();
  218. });
  219. $(document).scroll(function() {
  220. var valor = $('body').outerHeight() - 700;
  221. if ($(this).scrollTop() > 100) {
  222. $('.bottom_actions').addClass('bottom_actions_fixed');
  223. } else {
  224. $('.bottom_actions').removeClass('bottom_actions_fixed');
  225. }
  226. if ($(this).scrollTop() > valor) {
  227. $('.bottom_actions').removeClass('bottom_actions_fixed');
  228. } else {
  229. $('.bottom_actions').addClass('bottom_actions_fixed');
  230. }
  231. //Exercise warning fixed at the top
  232. var fixed = $("#exercise_clock_warning");
  233. if (fixed.length) {
  234. if (!fixed.attr('data-top')) {
  235. // If already fixed, then do nothing
  236. if (fixed.hasClass('subnav-fixed')) return;
  237. // Remember top position
  238. var offset = fixed.offset();
  239. fixed.attr('data-top', offset.top);
  240. fixed.css('width', '100%');
  241. }
  242. if (fixed.attr('data-top') - fixed.outerHeight() <= $(this).scrollTop()) {
  243. fixed.addClass('navbar-fixed-top');
  244. fixed.css('width', '100%');
  245. } else {
  246. fixed.removeClass('navbar-fixed-top');
  247. fixed.css('width', '100%');
  248. }
  249. }
  250. // Admin -> Settings toolbar.
  251. if ($('body').width() > 959) {
  252. if ($('.new_actions').length) {
  253. if (!$('.new_actions').attr('data-top')) {
  254. // If already fixed, then do nothing
  255. if ($('.new_actions').hasClass('new_actions-fixed')) return;
  256. // Remember top position
  257. var offset = $('.new_actions').offset();
  258. var more_top = 0;
  259. if ($('.subnav').hasClass('new_actions-fixed')) {
  260. more_top = 50;
  261. }
  262. $('.new_actions').attr('data-top', offset.top + more_top);
  263. }
  264. // Check if the height is enough before fixing the icons menu (or otherwise removing it)
  265. // Added a 30px offset otherwise sometimes the menu plays ping-pong when scrolling to
  266. // the bottom of the page on short pages.
  267. if ($('.new_actions').attr('data-top') - $('.new_actions').outerHeight() <= $(this).scrollTop() + 30) {
  268. $('.new_actions').addClass('new_actions-fixed');
  269. } else {
  270. $('.new_actions').removeClass('new_actions-fixed');
  271. }
  272. }
  273. }
  274. });
  275. function get_url_params(q, attribute) {
  276. var vars;
  277. var hash;
  278. if (q != undefined) {
  279. q = q.split('&');
  280. for(var i = 0; i < q.length; i++){
  281. hash = q[i].split('=');
  282. if (hash[0] == attribute) {
  283. return hash[1];
  284. }
  285. }
  286. }
  287. }
  288. function check_brand() {
  289. if ($('.subnav').length) {
  290. if ($(window).width() >= 969) {
  291. $('.subnav .brand').hide();
  292. } else {
  293. $('.subnav .brand').show();
  294. }
  295. }
  296. }
  297. function showConfirmationPopup(obj, urlParam) {
  298. if (urlParam) {
  299. url = urlParam
  300. } else {
  301. url = obj.href;
  302. }
  303. var dialog = $("#dialog");
  304. if ($("#dialog").length == 0) {
  305. dialog = $('<div id="dialog" style="display:none">{{ "ConfirmYourChoice" | get_lang }} </div>').appendTo('body');
  306. }
  307. var width_value = 350;
  308. var height_value = 150;
  309. var resizable_value = true;
  310. var new_param = get_url_params(url, 'width');
  311. if (new_param) {
  312. width_value = new_param;
  313. }
  314. var new_param = get_url_params(url, 'height')
  315. if (new_param) {
  316. height_value = new_param;
  317. }
  318. var new_param = get_url_params(url, 'resizable');
  319. if (new_param) {
  320. resizable_value = new_param;
  321. }
  322. // Show dialog
  323. dialog.dialog({
  324. modal : true,
  325. width : width_value,
  326. height : height_value,
  327. resizable : resizable_value,
  328. buttons: [
  329. {
  330. text: '{{ 'Yes' | get_lang }}',
  331. click: function() {
  332. window.location = url;
  333. },
  334. icons:{
  335. primary:'ui-icon-locked'
  336. }
  337. },
  338. {
  339. text: '{{ 'No' | get_lang }}',
  340. click: function() { $(this).dialog("close"); },
  341. icons:{
  342. primary:'ui-icon-locked'
  343. }
  344. }
  345. ]
  346. });
  347. // prevent the browser to follow the link
  348. return false;
  349. }
  350. function setCheckbox(value, table_id) {
  351. checkboxes = $("#"+table_id+" input:checkbox");
  352. $.each(checkboxes, function(index, checkbox) {
  353. checkbox.checked = value;
  354. if (value) {
  355. $(checkbox).parentsUntil("tr").parent().addClass("row_selected");
  356. } else {
  357. $(checkbox).parentsUntil("tr").parent().removeClass("row_selected");
  358. }
  359. });
  360. return false;
  361. }
  362. function action_click(element, table_id) {
  363. d = $("#"+table_id);
  364. if (!confirm('{{ "ConfirmYourChoice"|get_lang }}')) {
  365. return false;
  366. } else {
  367. var action =$(element).attr("data-action");
  368. $('#'+table_id+' input[name="action"] ').attr("value", action);
  369. d.submit();
  370. return false;
  371. }
  372. }
  373. /**
  374. * Generic function to replace the deprecated jQuery toggle function
  375. * @param inId : id of block to hide / unhide
  376. * @param inIdTxt : id of the button
  377. * @param inTxtHide : text one of the button
  378. * @param inTxtUnhide : text two of the button
  379. * @todo : allow to detect if text is from a button or from a <a>
  380. */
  381. function hideUnhide(inId, inIdTxt, inTxtHide, inTxtUnhide)
  382. {
  383. if ($('#'+inId).css("display") == "none") {
  384. $('#'+inId).show(400);
  385. $('#'+inIdTxt).attr("value", inTxtUnhide);
  386. } else {
  387. $('#'+inId).hide(400);
  388. $('#'+inIdTxt).attr("value", inTxtHide);
  389. }
  390. }
  391. function expandColumnToogle(buttonSelector, col1Info, col2Info)
  392. {
  393. $(buttonSelector).on('click', function (e) {
  394. e.preventDefault();
  395. col1Info = $.extend({
  396. selector: '',
  397. width: 4
  398. }, col1Info);
  399. col2Info = $.extend({
  400. selector: '',
  401. width: 8
  402. }, col2Info);
  403. if (!col1Info.selector || !col2Info.selector) {
  404. return;
  405. }
  406. var col1 = $(col1Info.selector),
  407. col2 = $(col2Info.selector);
  408. $('#expand').toggleClass('hide');
  409. $('#contract').toggleClass('hide');
  410. if (col2.is('.col-md-' + col2Info.width)) {
  411. col2.removeClass('col-md-' + col2Info.width).addClass('col-md-12');
  412. col1.removeClass('col-md-' + col1Info.width).addClass('hide');
  413. return;
  414. }
  415. col2.removeClass('col-md-12').addClass('col-md-' + col2Info.width);
  416. col1.removeClass('hide').addClass('col-md-' + col1Info.width);
  417. });
  418. }
  419. </script>