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

Globalize jquery enhanced #623

Merged
merged 11 commits into from Mar 9, 2016
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
4 changes: 2 additions & 2 deletions js/core/base-runner.js
Expand Up @@ -70,8 +70,8 @@ if (window.console) {


define(
["jquery", "Promise"],
function ($) {
[],
function () {
return {
runAll: function (plugs) {
// publish messages for beginning of all and end of all
Expand Down
2 changes: 1 addition & 1 deletion js/core/best-practices.js
Expand Up @@ -5,7 +5,7 @@
// Best practices are marked up with span.practicelab.

define(
["text!core/css/bp.css", "jquery"],
["text!core/css/bp.css"],
function (css) {
return {
run: function (conf, doc, cb, msg) {
Expand Down
4 changes: 2 additions & 2 deletions js/core/biblio.js
Expand Up @@ -5,8 +5,8 @@
// - localBiblio: override or supplement the official biblio with your own.

define(
["jquery"],
function ($) {
[],
function () {
var getRefKeys = function (conf) {
var informs = conf.informativeReferences
, norms = conf.normativeReferences
Expand Down
2 changes: 1 addition & 1 deletion js/core/contrib.js
Expand Up @@ -6,7 +6,7 @@
// Spec editors get filtered out automatically.

define(
["github", "jquery"],
["github"],
function (github) {
return {
run: function (conf, doc, cb, msg) {
Expand Down
4 changes: 2 additions & 2 deletions js/core/data-include.js
Expand Up @@ -17,8 +17,8 @@
// entail performance issues.

define(
["core/utils", "jquery"],
function (utils, $) {
["core/utils"],
function (utils) {
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "w3c/data-include");
Expand Down
2 changes: 1 addition & 1 deletion js/core/data-transform.js
Expand Up @@ -14,7 +14,7 @@
// in the test suite, and therefore could easily break.

define(
["core/utils", "jquery"],
["core/utils"],
function (utils) {
return {
run: function (conf, doc, cb, msg) {
Expand Down
4 changes: 2 additions & 2 deletions js/core/default-root-attr.js
Expand Up @@ -7,8 +7,8 @@
// publishing.

define(
["jquery"],
function ($) {
[],
function () {
return {
run: function (config, doc, cb, msg) {
msg.pub("start", "core/default-root-attr");
Expand Down
4 changes: 2 additions & 2 deletions js/core/dfn.js
Expand Up @@ -2,8 +2,8 @@
// Module core/dfn
// Finds all <dfn> elements and populates conf.definitionMap to identify them.
define(
["jquery"],
function ($) {
[],
function () {
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "core/dfn");
Expand Down
4 changes: 2 additions & 2 deletions js/core/examples.js
Expand Up @@ -7,8 +7,8 @@
// be used by a containing shell to extract all examples.

define(
["text!core/css/examples.css", "text!core/css/examples-webspecs.css", "jquery"],
function (css, cssKraken, $) {
["text!core/css/examples.css", "text!core/css/examples-webspecs.css"],
function (css, cssKraken) {
var makeTitle = function (conf, $el, num, report) {
var txt = (num > 0) ? " " + num : ""
, $tit = $("<div class='example-title'><span>Example" + txt + "</span></div>");
Expand Down
4 changes: 2 additions & 2 deletions js/core/figures.js
Expand Up @@ -7,8 +7,8 @@
// to be found as well as normalise the titles of figures.

define(
["jquery"],
function ($) {
[],
function () {
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "core/figures");
Expand Down
4 changes: 2 additions & 2 deletions js/core/fix-headers.js
Expand Up @@ -5,8 +5,8 @@
// h2) with the knowledge that the proper depth level will be used

define(
["jquery"],
function ($) {
[],
function () {
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "core/fix-headers");
Expand Down
4 changes: 2 additions & 2 deletions js/core/highlight.js
Expand Up @@ -7,8 +7,8 @@
// the end of processing)

define(
["text!core/css/highlight.css", "google-code-prettify", "jquery"],
function (css, PR, $) {
["text!core/css/highlight.css", "google-code-prettify"],
function (css, PR) {
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "core/highlight");
Expand Down
4 changes: 2 additions & 2 deletions js/core/id-headers.js
Expand Up @@ -4,8 +4,8 @@
// This is currently in core though it comes from a W3C rule. It may move in the future.

define(
["jquery"],
function ($) {
[],
function () {
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "core/id-headers");
Expand Down
4 changes: 2 additions & 2 deletions js/core/include-config.js
Expand Up @@ -2,8 +2,8 @@
// Inject's the document's configuration into the head as JSON.

define(
["jquery"],
function ($) {
[],
function () {
'use strict';
return {
run: function (conf, doc, cb, msg) {
Expand Down
4 changes: 2 additions & 2 deletions js/core/inlines.js
Expand Up @@ -16,8 +16,8 @@
// the counter is not used.

define(
["jquery"],
function ($) {
[],
function () {
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "core/inlines");
Expand Down
4 changes: 2 additions & 2 deletions js/core/issues-notes.js
Expand Up @@ -12,8 +12,8 @@
// manually numbered, a link to the issue is created using issueBase and the issue number
"use strict";
define(
["text!core/css/issues-notes.css", "github", "jquery"],
function(css, github, $) {
["text!core/css/issues-notes.css", "github"],
function(css, github) {
return {
run: function(conf, doc, cb, msg) {
function onEnd() {
Expand Down
173 changes: 173 additions & 0 deletions js/core/jquery-enhanced.js
@@ -0,0 +1,173 @@
define(["jquery","core/utils"], function($, utils) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a straight copy and paste from core/utils (where this code used to live). This code does not require review.

// --- JQUERY EXTRAS -----------------------------------------------------------------------
// Applies to any jQuery object containing elements, changes their name to the one give, and
// return a jQuery object containing the new elements
$.fn.renameElement = function(name) {
var arr = [];
this.each(function() {
var $newEl = $(this.ownerDocument.createElement(name));
// I forget why this didn't work, maybe try again
// $newEl.attr($(this).attr());
for (var i = 0, n = this.attributes.length; i < n; i++) {
var at = this.attributes[i];
$newEl[0].setAttributeNS(at.namespaceURI, at.name, at.value);
}
$(this).contents().appendTo($newEl);
$(this).replaceWith($newEl);
arr.push($newEl[0]);
});
return $(arr);
};

// 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
// 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
// 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
// instead of an @lt (as per specprod mailing list discussion).
$.fn.getDfnTitles = function(args) {
var titles = [];
var theAttr = "";
var titleString = "";
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";
// prefer @data-lt for the list of title aliases
titleString = this.attr(theAttr).toLowerCase();
if (normalizedText !== "") {
//Regex: starts with the "normalizedText|"
var startsWith = new RegExp("^" + normalizedText + "\\|");
// Use the definition itself as first item, so to avoid
// having to declare the definition twice.
if (!startsWith.test(titleString)) {
titleString = normalizedText + "|" + titleString;
}
}
} else if (this.attr("title")) {
// allow @title for backward compatibility
titleString = this.attr("title");
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 && this.find(":first-child").attr("title")) {
titleString = this.find(":first-child").attr("title");
} else {
titleString = this.text();
}
// now we have a string of one or more titles
titleString = utils.norm(titleString).toLowerCase();
if (args && args.isDefinition === true) {
// if it came from an attribute, replace that with data-lt as per contract with Shepherd
if (theAttr) {
this.attr("data-lt", titleString);
this.removeAttr(theAttr);
}
// if there is no pre-defined type, assume it is a 'dfn'
if (!this.attr("dfn-type")) {
this.attr("data-dfn-type", "dfn");
} else {
this.attr("data-dfn-type", this.attr("dfn-type"));
this.removeAttr("dfn-type");
}
}
titleString.split('|').forEach(function(item) {
if (item != "") {
titles.push(item);
}
});
return titles;
};

// For any element (usually <a>), returns an array of targets that
// element might refer to, of the form
// {for_: 'interfacename', title: 'membername'}.
//
// For an element like:
// <p link-for="Int1"><a for="Int2">Int3.member</a></p>
// we'll return:
// * {for_: "int2", title: "int3.member"}
// * {for_: "int3", title: "member"}
// * {for_: "", title: "int3.member"}
$.fn.linkTargets = function() {
var elem = this;
var link_for = (elem.attr("for") || elem.attr("data-for") || elem.closest("[link-for]").attr("link-for") || elem.closest("[data-link-for]").attr("data-link-for") || "").toLowerCase();
var titles = elem.getDfnTitles();
var result = [];
$.each(titles, function() {
result.push({
for_: link_for,
title: this
});
var split = this.split('.');
if (split.length === 2) {
// If there are multiple '.'s, this won't match an
// Interface/member pair anyway.
result.push({
for_: split[0],
title: split[1]
});
}
result.push({
for_: "",
title: this
});
});
return result;
};


// Applied to an element, sets an ID for it (and returns it), using a specific prefix
// if provided, and a specific text if given.
$.fn.makeID = function(pfx, txt, noLC) {
if (this.attr("id")) return this.attr("id");
if (!txt) txt = this.attr("title") ? this.attr("title") : this.text();
txt = txt.replace(/^\s+/, "").replace(/\s+$/, "");
var id = noLC ? txt : txt.toLowerCase();
id = id.split(/[^\-.0-9a-z_]+/i).join("-").replace(/^-+/, "").replace(/-+$/, "");
if (/\.$/.test(id)) id += "x"; // trailing . doesn't play well with jQuery
if (id.length > 0 && /^[^a-z]/i.test(id)) id = "x" + id;
if (id.length === 0) id = "generatedID";
if (pfx) id = pfx + "-" + id;
var inc = 1,
doc = this[0].ownerDocument;
if ($("#" + id, doc).length) {
while ($("#" + id + "-" + inc, doc).length) inc++;
id += "-" + inc;
}
this.attr("id", id);
return id;
};

// Returns all the descendant text nodes of an element. Note that those nodes aren't
// returned as a jQuery array since I'm not sure if that would make too much sense.
$.fn.allTextNodes = function(exclusions) {
var textNodes = [],
excl = {};
for (var i = 0, n = exclusions.length; i < n; i++) excl[exclusions[i]] = true;

function getTextNodes(node) {
if (node.nodeType === 1 && excl[node.localName.toLowerCase()]) return;
if (node.nodeType === 3) textNodes.push(node);
else {
for (var i = 0, len = node.childNodes.length; i < len; ++i) getTextNodes(node.childNodes[i]);
}
}
getTextNodes(this[0]);
return textNodes;
};
window.$ = $;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@halindrome here be the magic!!!!! 🌟

return $;
});
4 changes: 2 additions & 2 deletions js/core/link-to-dfn.js
Expand Up @@ -2,8 +2,8 @@
// Module core/link-to-dfn
// Gives definitions in conf.definitionMap IDs and links <a> tags to the matching definitions.
define(
["jquery"],
function ($) {
[],
function () {
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "core/link-to-dfn");
Expand Down
4 changes: 2 additions & 2 deletions js/core/location-hash.js
Expand Up @@ -3,8 +3,8 @@
// Resets window.location.hash to jump to the right point in the document

define(
["jquery"],
function ($) {
[],
function () {
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "core/location-hash");
Expand Down
4 changes: 2 additions & 2 deletions js/core/markdown.js
Expand Up @@ -41,8 +41,8 @@
//

define(
['core/marked', "jquery"],
function (coreMarked, $) {
['core/marked'],
function (coreMarked) {
marked.setOptions({
gfm: false,
pedantic: false,
Expand Down
4 changes: 2 additions & 2 deletions js/core/rdfa.js
Expand Up @@ -5,8 +5,8 @@
// particular

define(
["jquery"],
function ($) {
[],
function () {
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "core/rdfa");
Expand Down
4 changes: 2 additions & 2 deletions js/core/requirements.js
Expand Up @@ -11,8 +11,8 @@
// and a class of "reqRef".

define(
["jquery"],
function ($) {
[],
function () {
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "core/requirements");
Expand Down