header.js.tpl 14 KB

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