header.js.tpl 13 KB

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