// taginfo.js // capitalize a string String.prototype.capitalize = function() { return this.substr(0, 1).toUpperCase() + this.substr(1); } // print a number as percent value with two digits after the decimal point Number.prototype.print_as_percent = function() { return (this * 100).toFixed(2) + '%'; }; /* ============================ */ var grids = {}; var current_grid = ''; /* ============================ */ function init_tipsy() { jQuery('*[tipsy]').each(function(index, obj) { obj = jQuery(obj); obj.tipsy({ opacity: 1, delayIn: 500, gravity: obj.attr('tipsy') }); }); } function resize_box() { var height = jQuery(window).height(); height -= jQuery('div#header').outerHeight(true); height -= jQuery('div.pre').outerHeight(true); height -= jQuery('.ui-tabs-nav').outerHeight(true); height -= jQuery('div#footer').outerHeight(true); var wrapper = jQuery('.resize,.ui-tabs-panel'); wrapper.outerHeight(height); } function resize_home() { var tagcloud = jQuery('#tagcloud'); tagcloud.empty(); tagcloud.height(0); resize_box(); var height = tagcloud.parent().innerHeight(); tagcloud.parent().children().each(function(index) { if (this.id != 'tagcloud') { height -= jQuery(this).outerHeight(true); } }); tagcloud.height(height - 20); var tags = tagcloud_data(); var cloud = ''; for (var i=0; i < tags.length; i++) { cloud += link(url_for_key(tags[i][0]), tags[i][0], { style: 'font-size: ' + tags[i][1] + 'px;' }) + ' '; } tagcloud.append(cloud); var tags = tagcloud.children().toArray().sort(function(a, b) { return parseInt(jQuery(a).css('font-size')) - parseInt(jQuery(b).css('font-size')); }); while (tagcloud.get(0).scrollHeight > tagcloud.height()) { jQuery(tags.shift()).remove(); } } function resize_grid() { if (grids[current_grid]) { var grid = grids[current_grid][0].grid; var oldrp = grid.getRp(); var rp = calculate_flexigrid_rp(jQuery(grids[current_grid][0]).parents('.resize,.ui-tabs-panel')); if (rp != oldrp) { grid.newRp(rp); grid.fixHeight(); } } } /* ============================ */ function hover_expand(text) { return '' + text + ''; } function empty(text) { return '' + text + ''; } function link(url, text, attrs) { if (attrs === undefined) { attrs = {} } attrs.href = url; var attributes = ''; for (a in attrs) { attributes += ' ' + a + '="' + attrs[a] + '"'; } return '' + text + ''; } function print_wiki_link(title, options) { if (title == '') { return ''; } if (options && options.edit) { path = 'w/index.php?action=edit&title=' + title; } else { path = 'wiki/' + title; } return link('http://wiki.openstreetmap.org/' + path, title, { target: '_blank', class: 'extlink' }); } function print_language(code, native_name, english_name) { return '' + code + ' ' + native_name; } function print_image(type) { type = type.replace(/s$/, ''); var name; if (type == 'all') { name = texts.misc.all; } else { name = texts.osm[type]; } return ''; } // print a number with thousand separator function print_with_ts(value) { if (value === null) { return '-'; } else { return value.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1 '); } } /* ============================ */ function print_key_or_tag_list(list) { return jQuery.map(list, function(tag, i) { if (tag.match(/=/)) { var el = tag.split('=', 2); return link_to_tag(el[0], el[1]); } else { return link_to_key(tag); } }).join(' • '); } function print_prevalent_value_list(key, list) { if (list.length == 0) { return empty(texts.misc.values_less_than_one_percent); } return jQuery.map(list, function(item, i) { return link_to_value_with_title(key, item.value, '(' + item.fraction.print_as_percent() + ')'); }).join(' • '); } function html_escape(text) { return text.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, '''); } function url_for_key(key) { var k = encodeURIComponent(key); if (key.match(/[=\/]/)) { return '/keys/?key=' + k; } else { return '/keys/' + k; } } function url_for_tag(key, value) { var k = encodeURIComponent(key), v = encodeURIComponent(value); if (key.match(/[=\/]/) || value.match(/[=\/]/)) { return '/tags/?key=' + k + '&value=' + v; } else { return '/tags/' + k + '=' + v; } } function link_to_value_with_title(key, value, extra) { var k = encodeURIComponent(key), v = encodeURIComponent(value), title = html_escape(value) + ' ' + extra, url = url_for_tag(key, value); return link(url, pp_value(value), { title: title, tipsy: 'e'}); } function print_value_with_percent(value, fraction) { var v1 = print_with_ts(value), v2 = fraction.print_as_percent(); return '