diff --git a/apps/wiki/views.py b/apps/wiki/views.py index 5464ffe38..ebfe5b2de 100644 --- a/apps/wiki/views.py +++ b/apps/wiki/views.py @@ -37,10 +37,20 @@ from wiki.tasks import send_reviewed_notification, schedule_rebuild_kb log = logging.getLogger('k.wiki') +def _split_browser_slug(slug): + """Given something like fx35, split it into an alphabetic prefix and a + suffix, returning a 2-tuple like ('fx', '35').""" + right = slug.lstrip(ascii_letters) + left_len = len(slug) - len(right) + return slug[:left_len], slug[left_len:] + + OS_ABBR_JSON = json.dumps(dict([(o.slug, True) for o in OPERATING_SYSTEMS])) -BROWSER_ABBR_JSON = json.dumps(dict([(v.slug, v.show_in_ui) - for v in FIREFOX_VERSIONS])) +BROWSER_ABBR_JSON = json.dumps( + dict([(v.slug, {'product': _split_browser_slug(v.slug)[0], + 'maxFloatVersion': v.max_version}) + for v in FIREFOX_VERSIONS])) def _version_groups(versions): @@ -49,16 +59,9 @@ def _version_groups(versions): See test_version_groups for an example. """ - def split_slug(slug): - """Given something like fx35, split it into an alphabetic prefix and a - suffix, returning a 2-tuple like ('fx', '35').""" - right = slug.lstrip(ascii_letters) - left_len = len(slug) - len(right) - return slug[:left_len], slug[left_len:] - slug_groups = {} for v in versions: - left, right = split_slug(v.slug) + left, right = _split_browser_slug(v.slug) slug_groups.setdefault(left, []).append((v.max_version, right)) for g in slug_groups.itervalues(): g.sort() diff --git a/media/js/showfor.js b/media/js/showfor.js index a83ff08f1..e6ea4e72d 100644 --- a/media/js/showfor.js +++ b/media/js/showfor.js @@ -65,13 +65,38 @@ var ShowFor = { isSetManually; OSES = $osMenu.data('oses'); // {'mac': true, 'win': true, ...} - BROWSERS = $browserMenu.data('browsers'); // {'fx4': true, ...} + BROWSERS = $browserMenu.data('browsers'); // {'fx4': {product: 'fx', maxFloatVersion: 4.9999}, ...} VERSIONS = $browserMenu.data('version-groups'); // {'fx': [[3.4999, '3'], [3.9999, '35']], 'm': [[1.0999, '1'], [1.9999, '11']]} MISSING_MSG = gettext('[missing header]'); // Make the 'Table of Contents' header localizable. $('#toc > h2').text(gettext('Table of Contents')); + // Given a symbol like 'm4' or '=fx4', return something like + // {comparator: '>', product: 'm', version: 4.9999}. Even if there's no + // explicit comparator in the symbol, the comparator that's assumed + // will be made explicit in the returned object. If it's not a known + // product/version combo, return undefined. + function conditionFromSymbol(symbol) { + var slug, browser, comparator; + + // TODO: Put crappy special cases here. + + // Figure out comparator: + if (symbol.substring(0, 1) == '=') { + comparator = '='; + slug = symbol.substring(1); + } else { // If no leading =, assume >=. + comparator = '>='; + slug = symbol; + } + + browser = BROWSERS[slug]; + return {comparator: comparator, + product: browser.product, + version: browser.maxFloatVersion}; + } + function updateForsAndToc(calledOnLoad) { // Hide and show document sections accordingly: showAndHideFors($osMenu.val(), $browserMenu.val()); @@ -97,25 +122,64 @@ var ShowFor = { // Set the {for} nodes to the proper visibility for the given OS and // browser combination. // - // Hidden are {for}s that {list at least one OS but not the passed-in one} - // or that {list at least one browser but not the passed-in one}. Also, the - // entire condition can be inverted by prefixing it with "not ", as in {for - // not mac,linux}. + // Hidden are {for}s that {list at least one OS but not the passed-in + // one} or that {list at least one browser expression but none matching + // the passed-in one}. Also, the entire condition can be inverted by + // prefixing it with "not ", as in {for not mac,linux}. + // + // Takes a browser slug like "fx4" rather than a browser code and a + // raw floating-point version because it has to be able to take both + // detected browsers and slugs chosen explicitly from the