Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for data-lt-noDefault attribute #481

Merged
merged 1 commit into from Aug 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 19 additions & 14 deletions js/core/utils.js
Expand Up @@ -30,13 +30,13 @@ define(
// For any element, returns an array of title strings that applies
// the algorithm used for determining the
// actual title of a <dfn> element (but can apply to other as well).
//
// if args.isDefinition is true, then the element is a definition, not a
//
// if args.isDefinition is true, then the element is a definition, not a
// reference to a definition. Any @title or @lt will be replaced with
// @data-lt to be consistent with Bikeshed / Shepherd.
//
// This method now *prefers* the data-lt attribute for the list of
// titles. That attribute is added by this method to dfn elements, so
// This method now *prefers* the data-lt attribute for the list of
// titles. That attribute is added by this method to dfn elements, so
// subsequent calls to this method will return the data-lt based list.
//
// This method will publish a warning if a title is used on a definition
Expand All @@ -45,7 +45,12 @@ define(
var titles = [];
var theAttr = "";
var titleString = "";
var normalizedText = utils.norm(this.text()).toLowerCase();
var normalizedText = "";
//data-lt-noDefault avoid using the text content of a definition
//in the definition list.
if (this.attr("data-lt-noDefault") === undefined){
normalizedText = utils.norm(this.text()).toLowerCase();
}
// allow @lt to be consistent with bikeshed
if (this.attr("data-lt") || this.attr("lt")) {
theAttr = this.attr("data-lt") ? "data-lt" : "lt";
Expand All @@ -67,8 +72,8 @@ define(
theAttr = "title";
respecEvents.pub("warn", "Using deprecated attribute @title for '" + this.text() + "': see http://w3.org/respec/guide.html#definitions-and-linking");
}
else if (this.contents().length == 1
&& this.children("abbr, acronym").length == 1
else if (this.contents().length == 1
&& this.children("abbr, acronym").length == 1
&& this.find(":first-child").attr("title")) {
titleString = this.find(":first-child").attr("title");
}
Expand Down Expand Up @@ -167,8 +172,8 @@ define(
getTextNodes(this[0]);
return textNodes;
};


var utils = {
// --- SET UP
run: function (conf, doc, cb, msg) {
Expand Down Expand Up @@ -216,7 +221,7 @@ define(
return str.replace(/^\s+/, "").replace(/\s+$/, "").split(/\s+/).join(" ");
}


// --- DATE HELPERS -------------------------------------------------------------------------------
// Takes a Date object and an optional separator and returns the year,month,day representation with
// the custom separator (defaulting to none) and proper 0-padding
Expand All @@ -230,7 +235,7 @@ define(
str = "" + str;
return (str.length == 1) ? "0" + str : str;
}

// takes a YYYY-MM-DD date and returns a Date object for it
, parseSimpleDate: function (str) {
return new Date(str.substr(0, 4), (str.substr(5, 2) - 1), str.substr(8, 2));
Expand All @@ -246,7 +251,7 @@ define(
// list of human names for months (in English)
, humanMonths: ["January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"]

// given either a Date object or a date in YYYY-MM-DD format, return a human-formatted
// date suitable for use in a W3C specification
, humanDate: function (date) {
Expand All @@ -260,8 +265,8 @@ define(
// return "" + date.getUTCFullYear() +'-'+ this.lead0(date.getUTCMonth() + 1)+'-' + this.lead0(date.getUTCDate()) +'T'+this.lead0(date.getUTCHours())+':'+this.lead0(date.getUTCMinutes()) +":"+this.lead0(date.getUTCSeconds())+'+0000';
return date.toISOString() ;
}


// --- STYLE HELPERS ------------------------------------------------------------------------------
// take a document and either a link or an array of links to CSS and appends a <link/> element
// to the head pointing to each
Expand Down
13 changes: 13 additions & 0 deletions tests/spec/core/utils-spec.js
Expand Up @@ -146,6 +146,19 @@ describe("Core - Utils", function () {
});
});

// $.getDfnTitles()
it("should not use the text content when data-lt-noDefault is present", function () {
runs(function () {
var $dfn = $("<dfn data-lt-noDefault data-lt='DFN|DFN2|DFN3'>FAIL</dfn>").appendTo($("body"));
var titles = $dfn.getDfnTitles( { isDefinition: true } );
expect(titles[0]).toEqual("dfn");
expect(titles[1]).toEqual("dfn2");
expect(titles[2]).toEqual("dfn3");
expect(titles[3]).toEqual(undefined);
$dfn.remove();
});
});

// $.getDfnTitles()
it("should find the data-lts", function () {
runs(function () {
Expand Down