header.js.tpl 14 KB

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