diff --git a/js/core/requirements.js b/js/core/requirements.js new file mode 100644 index 0000000000..dd1cfe4519 --- /dev/null +++ b/js/core/requirements.js @@ -0,0 +1,57 @@ +// Module core/requirements +// This module does two things: +// +// 1. It finds and marks all requirements. These are elements with class "req". +// When a requirement is found, it is reported using the "req" event. This +// can be used by a containing shell to extract them. +// Requirements are automatically numbered. +// +// 2. It allows referencing requirements by their ID simply using an empty +// element with its href pointing to the requirement it should be referencing +// and a class of "reqRef". + +define( + [], + function () { + return { + run: function (conf, doc, cb, msg) { + msg.pub("start", "core/requirements"); + + $("*.req").each(function (i) { + i++; + var $req = $(this) + , title = "Req. " + i + ; + msg.pub("req", { + type: "req", + number: i, + content: $req.html(), + title: title + }); + $req.prepend("" + title + ": "); + }); + + $("a.reqRef").each(function () { + var $ref = $(this) + , href = $ref.attr("href") + , id + , $req + , txt + ; + if (!href) return; + id = href.substring(1); + $req = $("#" + id); + if ($req.length) { + txt = $req.find("> a").text(); + } else { + txt = "Req. not found '" + id + "'"; + } + $ref.text(txt); + }); + + msg.pub("end", "core/requirements"); + cb(); + } + }; + } +); \ No newline at end of file diff --git a/js/profile-w3c-common.js b/js/profile-w3c-common.js index 41a3f19ed7..fbf08fd004 100644 --- a/js/profile-w3c-common.js +++ b/js/profile-w3c-common.js @@ -15,6 +15,7 @@ define([ , "core/dfn" , "core/examples" , "core/issues-notes" + , "core/requirements" , "core/highlight" , "core/best-practices" , "core/figures"