/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */ /* Please note that this file should only contain common Javascript code used on many ILIAS screens. Please do not add any code that is only useful for single components here. See http://www.ilias.de/docu/goto_docu_pg_38968_42.html for the JS guidelines */ // console dummy object if (!window.console) { (function() { var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; window.console = {}; for (var i = 0; i < names.length; ++i) window.console[names[i]] = function(data) {} })(); } // global il namespace, additional objects usually should be added to this one if (typeof il === 'undefined') { il = {} } // utility functions il.Util = { addOnLoad: function(func) { $().ready(function() { try { func(); } catch (err) { console.error(err); } }); /* if (!document.getElementById | !document.getElementsByTagName) return; var oldonload=window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } }*/ }, addOnUnload: function (func) { if (!document.getElementById | !document.getElementsByTagName) return; var oldonunload = window.onunload; if (typeof window.onunload != 'function') { window.onunload = func; } else { window.onunload = function() { oldonunload(); func(); } } }, /** * Checks/unchecks checkboxes * * @param string parent name or id * @param string the checkbox name (or the first characters of the name, if unique) * @param boolean whether to check or to uncheck the element * @return boolean always true */ setChecked: function(parent_el, checkbox_name, do_check){ var name_sel = ''; if (checkbox_name != '') { name_sel = '[name^="' + checkbox_name + '"]'; } if(do_check) { $("#" + parent_el).find("input:checkbox" + name_sel).not(":disabled").prop('checked', true); $('[name="' + parent_el + '"]').find("input:checkbox" + name_sel).not(":disabled").prop('checked', true); } else { $("#" + parent_el).find("input:checkbox" + name_sel).not(":disabled").prop('checked', false); $('[name="' + parent_el + '"]').find("input:checkbox" + name_sel).not(":disabled").prop('checked', false); } return true; }, submitOnEnter: function(ev, form) { if (typeof ev != 'undefined' && typeof ev.keyCode != 'undefined') { if (ev.keyCode == 13) { form.submit(); return false; } } return true; }, // ajax related functions ajaxReplace: function(url, el_id) { console.log(url); this.sendAjaxGetRequestToUrl (url, {}, {el_id: el_id, inner: false}, this.ajaxReplaceSuccess) }, ajaxReplaceInner: function(url, el_id) { this.sendAjaxGetRequestToUrl (url, {}, {el_id: el_id, inner: true}, this.ajaxReplaceSuccess) }, ajaxReplaceSuccess: function(o) { // perform page modification if(o.responseText !== undefined) { if (o.argument.inner) { $('#' + o.argument.el_id).html(o.responseText); } else { $('#' + o.argument.el_id).replaceWith(o.responseText); } il.UICore.initDropDowns('#' + o.argument.el_id); } }, sendAjaxGetRequestToUrl: function(url, par, args, succ_cb) { var cb = { success: succ_cb, failure: this.handleAjaxFailure, argument: args }; for (k in par) { url = url + "&" + k + "=" + par[k]; } var request = YAHOO.util.Connect.asyncRequest('GET', url, cb); }, sendAjaxPostRequestToUrl: function(url, data, succ_cb) { $.post(url, data, succ_cb); }, // FailureHandler handleAjaxFailure: function(o) { console.log("il.Util.handleAjaxFailure: Ajax Error:"); console.log(o); }, // Screen reader related functions // Set focus for screen reader per element id setScreenReaderFocus: function(id) { var obj = document.getElementById(id); if (obj) { obj.focus(); self.location.hash = id; } }, // Set standard screen reader focus setStdScreenReaderFocus: function() { var obj = document.getElementById("il_message_focus"); if (obj) { obj.focus(); self.location.hash = 'il_message_focus'; } else { obj = document.getElementById("il_lm_head"); if (obj && self.location.hash == '') { obj.focus(); self.location.hash = 'il_lm_head'; } else { obj = document.getElementById("il_mhead_t_focus"); if (obj && self.location.hash == '') { obj.focus(); self.location.hash = 'il_mhead_t_focus'; } } } }, /** * Get region information (coordinates + size) for an element */ getRegion: function (el) { var w = $(el).outerWidth(), h = $(el).outerHeight(), o = $(el).offset(); return {top: o.top, right: o.left + w,bottom: o.top + h, left: o.left, height: h, width: w, y: o.top, x: o.left}; }, /** * Get region information (coordinates + size) for viewport */ getViewportRegion: function () { var w = $(window).width(), h = $(window).height(), t = $(window).scrollTop(), l = $(window).scrollLeft(); return {top: t, right: l + w,bottom: t + h, left: l, height: h, width: w, y: t, x: l}; }, /** * Fix position */ fixPosition: function (el) { var r = il.Util.getRegion(el), vp = il.Util.getViewportRegion(); // we only fix absolute positioned items if ($(el).css("position") != "absolute") { return; } if (vp.right - 15 < r.right) { il.Util.setX(el, r.x - (r.right - vp.right + 20)); } r = il.Util.getRegion(el); if (r.left < 0) { $(el).removeClass("pull-right"); il.Util.setX(el, 0); } }, /** * Set x */ setX: function (el, x) { $(el).offset({left: x}); }, setY: function (el, y) { $(el).offset({top: y}); }, /** * Checks whether coordinations are within an elements region */ coordsInElement: function (x, y, el) { var w = $(el).outerWidth(), h = $(el).outerHeight(), o = $(el).offset(); if (x >= o.left && x <= o.left + w && y >= o.top && y <= o.top + h) { return true; } return false; }, /** * print current window, thanks to anoack for the mathjax fix (see bug #) */ print: function () { if (typeof(window.print) != 'undefined') { if (typeof MathJax != "undefined" && typeof MathJax.Hub != "undefined") { MathJax.Hub.Queue( ["Delay",MathJax.Callback,700], window.print ); } else { window.print(); } } }, // see http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript escapeRegExp: function (string) { return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); }, // see http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript replaceAll: function (string, find, replace) { return string.replace(new RegExp(il.Util.escapeRegExp(find), 'g'), replace); } } // ILIAS Object related functions il.Object = { url_redraw_ah: "", url_redraw_li: "", url_rating: "", setRedrawAHUrl: function(url) { this.url_redraw_ah = url; }, getRedrawAHUrl: function() { return this.url_redraw_ah; }, redrawActionHeader: function() { var ah = document.getElementById("il_head_action"); if (this.url_redraw_ah && ah !== null) { il.Util.ajaxReplaceInner(this.url_redraw_ah, "il_head_action"); } }, setRedrawListItemUrl: function(url) { this.url_redraw_li = url; }, getRedrawListItemUrl: function() { return this.url_redraw_li; }, redrawListItem: function(ref_id) { if (this.url_redraw_li) { var url = this.url_redraw_li; $('div[id^=lg_div_' + ref_id + '_pref_]').each(function() { var id = $(this).attr('id'); var parent = id.split("_").pop(); il.Util.ajaxReplace(url + "&child_ref_id=" + ref_id + "&parent_ref_id=" + parent, id); }); } }, togglePreconditions: function(link, id, txt_show, txt_hide) { var li = document.getElementById("il_list_item_precondition_obl_" + id); if(li !== null) { if(li.style.display == "none") { li.style.display = ""; $(link).html("» "+txt_hide); } else { li.style.display = "none"; $(link).html("» "+txt_show); } } li = document.getElementById("il_list_item_precondition_opt_" + id); if(li !== null) { if(li.style.display == "none") { li.style.display = ""; $(link).html("» "+txt_hide); } else { li.style.display = "none"; $(link).html("» "+txt_show); } } }, setRatingUrl: function(url) { this.url_rating = url; }, saveRating: function(mark) { il.Util.sendAjaxGetRequestToUrl(this.url_rating + "&rating=" + mark, {}, {url_redraw: this.url_redraw_ah}, this.redrawAfterRating); }, redrawAfterRating: function(o) { var ah = document.getElementById("il_head_action"); if (ah !== null) { il.Util.ajaxReplaceInner(o.argument.url_redraw, "il_head_action"); } }, saveRatingFromListGUI: function(ref_id, hash, mark) { il.Util.sendAjaxGetRequestToUrl(this.url_rating + "&rating=" + mark + "&child_ref_id=" + ref_id + "&cadh= " + hash, {}, {url_redraw: this.url_redraw_li, ref_id: ref_id}, this.redrawAfterRatingFromListGUI); }, redrawAfterRatingFromListGUI: function(o) { $('div[id^=lg_div_' + o.argument.ref_id + '_pref_]').each(function() { var id = $(this).attr('id'); var parent = id.split("_").pop(); il.Util.ajaxReplace(o.argument.url_redraw + "&child_ref_id=" + o.argument.ref_id + "&parent_ref_id=" + parent, id); }); } } /* Main menu handling */ il.MainMenu = { removeLastVisitedItems: function (url) { $('.ilLVNavEnt').remove(); il.Util.sendAjaxGetRequestToUrl(url, {}, {}, this.dummyCallback); return false; }, dummyCallback: function () { } } /* UICore */ il.UICore = { // // Layout related // right_panel_wrapper: "", is_page_visible: true, /** * * @param {boolean} status */ setPageVisibilityStatus: function(status) { il.UICore.is_page_visible = status }, /** * * @returns {boolean} */ isPageVisible: function() { return il.UICore.is_page_visible; }, scrollToHash: function () { var h = self.location.hash; if (h != "") { h = h.substr(1); if ($("a[name='" + h + "']").length !== 0) { il.UICore.scrollToElement("a[name='" + h + "']"); } else if ($("#" + h).length !== 0) { il.UICore.scrollToElement("#" + h); } } }, // take care of initial layout scrollToElement: function (el) { // if we have an anchor, fix scrolling "behind" fixed top header var fixed_top_height = parseInt($("#mainspacekeeper").css("margin-top")) + parseInt($("#mainspacekeeper").css("padding-top")), vp_reg = il.Util.getViewportRegion(), el_reg = il.Util.getRegion(el); if (fixed_top_height > 0) { $('html, body').scrollTop(el_reg.top - fixed_top_height); } }, handleScrolling: function() { il.UICore.refreshLayout(); }, refreshLayout: function () { var el = document.getElementById("left_nav"), sm = document.getElementById("mainspacekeeper"), bc = document.getElementById("bot_center_area"), fc = document.getElementById("fixed_content"), ft = document.getElementById("ilFooter"), rtop = document.getElementById("right_top_area"), rbot = document.getElementById("right_bottom_area"), nb_reg, vp_reg, ft_reg, rtop_reg, rbot_reg, el_reg, bc_reg; vp_reg = il.Util.getViewportRegion(); $(".ilFrame").each(function() { var t = $(this); // console.log(t); var freg = il.Util.getRegion(this); if (freg.bottom < vp_reg.bottom) { t.height(t.height() + vp_reg.bottom - freg.bottom - 1); } //console.log(freg); //console.log(vp_reg); }); // fix fixed content if ($(fc).css("position") != "static") { if (fc && sm) { sm_reg = il.Util.getRegion(sm); fc_reg = il.Util.getRegion(fc); if (sm_reg.top < vp_reg.top) { $(fc).offset({top: vp_reg.top}); } else { $(fc).offset({top: sm_reg.top}); } } // fix left navigation area if (el && sm) { sm_reg = il.Util.getRegion(sm); nb_reg = il.Util.getRegion(el); vp_reg = il.Util.getViewportRegion(); if (sm_reg.top < vp_reg.top) { $(el).css("top", "0px"); $(fc).css("top", "0px"); } else { $(el).css("top", (sm_reg.top - vp_reg.top) + "px"); $(fc).css("top", (sm_reg.top - vp_reg.top) + "px"); } // bottom center area? if (bc) { bc_reg = il.Util.getRegion(bc); $(fc).css("bottom", bc_reg.height + "px"); } else { $(fc).css("bottom", "0px"); } } } if (el && bc) { el_reg = il.Util.getRegion(el); bc_reg = il.Util.getRegion(bc); if ($(el).is(':visible')) { il.Util.setX(bc, el_reg.right); } else if (sm) { sm_reg = il.Util.getRegion(sm); il.Util.setX(bc, sm_reg.left); // #0019851 } } if (bc && sm) { sm_reg = il.Util.getRegion(sm); bc_reg = il.Util.getRegion(bc); $(bc).css("width", parseInt(sm_reg.right - bc_reg.left) + "px"); } // footer vs. left nav if (ft && el) { ft_reg = il.Util.getRegion(ft); if (ft_reg.top < vp_reg.bottom) { $(el).css("bottom", (vp_reg.bottom - ft_reg.top) + "px"); } else { $(el).css("bottom", "0px"); } } // fit width of right top/bottom regions into mainspacekeeper area if (rtop && sm) { sm_reg = il.Util.getRegion(sm); rtop_reg = il.Util.getRegion(rtop); $(rtop).css("width", parseInt(sm_reg.right - rtop_reg.left) + "px"); } if (rbot && sm) { sm_reg = il.Util.getRegion(sm); rbot_reg = il.Util.getRegion(rbot); $(rbot).css("width", parseInt(sm_reg.right - rbot_reg.left) + "px"); } il.UICore.collapseTabs(false); }, collapseTabs: function (recheck) { var tabs = $('#ilTab.ilCollapsable'), tabsHeight, count, children, collapsed; if (tabs) { tabsHeight = tabs.innerHeight(); if (tabsHeight >= 50) { if (tabsHeight > 50) { $('#ilLastTab a').removeClass("ilNoDisplay"); } // as long as we have two lines... while (tabsHeight > 50) { children = tabs.children('li:not(:last-child)'); count = children.length; // ...put last child into collapsed drop down $(children[count-1]).prependTo('#ilTabDropDown'); tabsHeight = tabs.innerHeight(); } } else { // as long as we have one line... while (tabsHeight < 50 && ($('#ilTabDropDown').children('li').length>0)) { collapsed = $('#ilTabDropDown').children('li'); count = collapsed.length; $(collapsed[0]).insertBefore(tabs.children('li:last-child')); tabsHeight = tabs.innerHeight(); } if ($('#ilTabDropDown').children('li').length == 0) { $('#ilLastTab a').addClass("ilNoDisplay"); } if (tabsHeight>50 && !recheck) { // double chk height again il.UICore.collapseTabs(true); } } } }, initFixedDropDowns: function () { $('.ilMainMenu.ilTopFixed .dropdown').on('shown.bs.dropdown', function () { var el = $(this).children(".dropdown-menu")[0]; if (!el) { return; } var r = il.Util.getRegion(el), vp = il.Util.getViewportRegion(), newHeight; // make it smaller, if window height is not sufficient if (vp.bottom < r.bottom) { newHeight = r.height - r.bottom + vp.bottom; el.style.height = newHeight + "px"; $(el).css("overflow", "auto"); } }).on('hidden.bs.dropdown', function () { }); }, initLayoutDrag: function() { $('#bot_center_area_drag').mousedown(function(e){ e.preventDefault(); $('#drag_zmove').css("display","block"); $('#drag_zmove').mousemove(function(e){ var vp_reg = il.Util.getViewportRegion(); var drag_y = e.pageY; $('#bot_center_area').css("height", vp_reg.height - drag_y); il.UICore.refreshLayout(); }); }); $(document).mouseup(function(e){ $('#bot_center_area_drag').off('mousemove'); $('#drag_zmove').css("display","none"); $(document).off('mousemove'); }); }, initDropDowns: function (context) { // fix positions of drop-downs to viewport $(context + ' .dropdown-menu').parent().on('shown.bs.dropdown', function (e) { $(this).children(".dropdown-menu").each(function() { il.Util.fixPosition(this); }); }); }, showRightPanel: function () { this.right_panel = il.Modal.dialogue({ id: "il_right_panel", show: true, body: "
", buttons: { } }); return; /* var n = document.getElementById('ilRightPanel'); if (!n) { var b = $("body"); b.append("