header.js.tpl 14 KB

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