/* Wochentagsbestimmung fuer highcharts -> Sa. u So. highlighten */ var MICROSECONDS_PER_DAY = 24 * 60 * 60 * 1000 ; // Set some global Highcharts options Highcharts.setOptions({ lang: { months: [gettext('January'), gettext('February'), gettext('March'), gettext('April'), gettext('May'), gettext('June'), gettext('July'), gettext('August'), gettext('September'), gettext('October'), gettext('November'), gettext('December')], weekdays: [gettext('Sun'), gettext('Mon'), gettext('Tue'), gettext('Wed'), gettext('Thu'), gettext('Fri'), gettext('Sat')] } }); function get_weekend_plotbands (start_timestamp, end_timestamp) { var plotbands = []; var start = 0; var stop = 0; for (var ts = start_timestamp; ts <= end_timestamp; ts += MICROSECONDS_PER_DAY) { var day = new Date(ts); day.setHours(0); day.setMinutes(0); day.setSeconds(0); day.setMilliseconds(0); var week_day = day.getDay(); if (week_day == 6) { start = Date.parse(day) - MICROSECONDS_PER_DAY/2; stop = start + MICROSECONDS_PER_DAY*2; plotbands.push({'from': start, 'to': stop, 'color': '#f7f7f7'}); } if (week_day == 0) { if (Date.parse(day) <= stop) continue; stop = Date.parse(day) + MICROSECONDS_PER_DAY/2; start = stop - MICROSECONDS_PER_DAY*2; plotbands.push({'from': start, 'to': stop, 'color': '#f7f7f7'}); } } return plotbands; } function Trennzeichen(zahl) { zahl = '' + zahl; str_zahl = zahl.toString(zahl); str_zahl = str_zahl.replace(".",","); for (i=0; i < str_zahl.length; i++){ if(str_zahl.charAt(i) == ',') { return str_zahl; break; } } if (zahl.length > 3 ) { var mod = zahl.length % 3; var output = (mod > 0 ? (zahl.substring(0,mod)) : ''); for (i=0 ; i < Math.floor(zahl.length / 3); i++) { if ((mod == 0) && (i == 0)) { output += zahl.substring(mod+ 3 * i, mod + 3 * i + 3); } else { output+= '.' + zahl.substring(mod + 3 * i, mod + 3 * i + 3); } } return (output); } else return zahl; } function zahl_plus_k(zahl) { zahl = '' + zahl; if (zahl >= 1000) { ergebnis = zahl / 1000 + 'k'; return ergebnis; } else { return zahl; } } //////////////////////////////////////////////////////////////////////////////// function url_trunc(url, maxLen) { var defaultValue = 30; var lenUrl = url.length; var maxLen = (typeof maxLen == 'undefined') ? defaultValue : maxLen; if (url.charAt(0) == 'h' && lenUrl > maxLen) { var first = url.indexOf('://') + 3; var rest = url.slice(first, lenUrl); try { idx = rest.indexOf('/') + 1; } catch (ValueError) { idx = rest.length; } if (idx + first <= maxLen) { newUrl = url.slice(0, maxLen-3) + '...'; } else { newUrl = url.slice(0, first) + rest.slice(0, idx) + '...'; } return newUrl; } else if (url.charAt(0) == 'w' && lenUrl > maxLen) { var first = url.indexOf('.') + 1; var rest = url.slice(first, lenUrl); try { idx = url.indexOf('/') + 1; } catch (ValueError) { idx = lenUrl; } if (idx + first <= maxLen) { newUrl = url.slice(0, maxLen-3) + '...'; } else { newUrl = url.slice(0, first) + rest.slice(0,idx) + '...'; } return newUrl; } else { return url; } } //////////////////////////////////////////////////////////////////////////////// function renumber_list_items(list_node, id_prefix) { index_item = 0; $(".list-item").each(function(index, list_item) { if ($(".list-item-field", list_item).attr("id")==undefined || $(".list-item-field", list_item).attr("id").indexOf(id_prefix)!=-1){ $(".list-item-field", list_item).attr("id", "id_" + id_prefix + "_" + index_item); $(".list-item-field", list_item).attr("name", id_prefix + "_" + index_item); index_item++; } }); } /* Functions used by dynamic list editor **************************************/ function add_list_item(list_node, id_prefix) { // clone list item template and fix id and class attributes var $newField=list_node.children("#list-item-template").clone(true); $newField.removeAttr("id"); $newField.addClass("list-item"); $newField.find(".remove-button").hide(); // insert new field after last list item list_node.children("#list-item-template,.list-item").slice(-1).after($newField); renumber_list_items(list_node, id_prefix); // show all remove buttons, as there must be more than one now $newField.show("fast", function() { $(this).find("input.list-item-field").focus(); $(this).find(".remove-button").show("fast"); list_node.find(".remove-button").show(); }); return false; } function remove_list_item(list_item_node, id_prefix) { // hide 'remove' button if there is only one list item if (list_item_node.siblings(".list-item").size() <= 1) { list_item_node.siblings(".list-item").find(".remove-button").css("display", "none"); } list_item_node.find(".remove-button").hide(); list_node = list_item_node.closest(".list"); list_item_node.hide("fast", function() { list_item_node.remove(); renumber_list_items(list_node, id_prefix); }); return false; } /* Utility functions **********************************************************/ function update_navigation(url) { $('#nav2 a').removeClass('active'); $('#nav2 a[href^="' + url + '"]').addClass('active'); } function create_overlay_msg(text) { var overlay_el = document.createElement('div'); $(overlay_el) .attr('id', 'main-overlay') .width($('#main').width()) .height($('#main').height()) .css({backgroundColor:'white', opacity:0.8, position:'absolute', left:0, top:0, 'z-index': 999}) .prependTo($('#main')) .html(text); $('#main').css('position','relative'); return overlay_el; } function show_sidebar_help(input_id) { var input_el = $('#' + input_id); var help_el = null; if (input_id.substr(0, 'id_search_terms'.length) === 'id_search_terms') { help_el = $('#help-id_search_terms'); } else { help_el = $('#help-' + input_id); } help_el .css('top', input_el.position().top + input_el.height()/2 - help_el.outerHeight()/2) .show(); var image_el = $('#sidebar .help_arrow'); image_el .css('top', input_el.position().top + input_el.height()/2 - image_el.height()/2) .show(); } function hide_sidebar_help(input_id) { if (input_id.substr(0, 'id_search_terms'.length) === 'id_search_terms') { input_id = 'id_search_terms'; } $('#help-' + input_id).hide(); $('#sidebar .help_arrow').hide(); } // Extend jQuery jQuery.info_tooltip = {version: '0.0.1'}; $(function() { // Info tooltip function. Pops up an info tooltip if element is clicked. // Use like this: // $('.your-button-class').info_tooltip(); // $.fn.info_tooltip = function(options) { var opts = jQuery.extend(false, jQuery.info_tooltip.defaults, jQuery.info_tooltip.options, options); var width = opts['width']; var cls = opts['tooltip_class']; return this.each(function() { var content = $(this).attr('title'); if (content == '') { return; } // remove previous tooltips $('.tooltip', this).remove(); // append tooltip HTML $('
') .appendTo(this); // remove title attribute & add event handler $(this) .removeAttr('title') .click(function(e) { $('.tooltip').hide(); if ($(e.target).hasClass('tooltip-active')) { $(e.target).removeClass('tooltip-active'); } else { var left = 0; if ($(e.target).offset().left + $(e.target).outerWidth() + $('.tooltip', e.target).outerWidth() > $(document).width()) { left = $(e.target).offset().left - width; } else { left = $(e.target).offset().left + $(e.target).width(); } $('.tooltip', e.target) .css('left', left) .css('top', $(e.target).offset().top) .fadeIn(); $(e.target) .addClass('tooltip-active'); $(document).click(function(e) { $('').removeClass('tooltip-active'); $('.tooltip').fadeOut(); }) } e.stopPropagation(); }); }); }; $.info_tooltip.defaults = { width: 400, tooltip_class: 'tooltip', effect: '' }; $.info_tooltip.options = {}; }); // Live search $.live_search_form = {version: '0.0.1'}; $(function() { $.fn.live_search_form = function(options) { var opts = $.extend(false, $.live_search_form.defaults, $.live_search_form.options); opts = $.extend(false, opts, options); this.postings_list = opts['postings_list']; this.query = this.postings_list.query || ''; this.timestamp = 0; var obj = this; $('input.query', obj) .data('timeout', null) .val(obj.query) .keyup(function() { var query = $('input.query', obj).val(); if (query !== obj.query) { obj.query = query; $('.search_preloader', obj).show(); var now = new Date().getTime(); $(obj).data('timeout', setTimeout(function() { // make sure only the latest query is executed; abort // the other one if applicable if (obj.timestamp < now) { obj.timestamp = now; obj.postings_list.abort(); obj.postings_list.query = obj.query; obj.postings_list.update({callback: function() { if (obj.timestamp == now) { $('.search_preloader', obj).hide(); } }}); } }, 2000)); } }) .keydown(function(){ clearTimeout($(this).data('timeout')); }); } $.live_search_form.defaults = {}; $.live_search_form.options = {}; });