Created
December 8, 2015 23:33
-
-
Save rmcveigh/cb8e87ea34a47c6d65bf to your computer and use it in GitHub Desktop.
Checks for superscript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @file | |
* A JavaScript file for the theme. | |
* This file finds text with ®s that are dynamically add and wraps them in <sup> | |
* | |
*/ | |
// JavaScript should be made compatible with libraries other than jQuery by | |
// wrapping it with an "anonymous closure". See: | |
// - https://drupal.org/node/1446420 | |
// - http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth | |
(function ($, Drupal, window, document, undefined) { | |
'use strict'; | |
// To understand behaviors, see https://drupal.org/node/756722#behaviors | |
Drupal.behaviors.cardSuperscriptCheck = { | |
attach: function (context, settings) { // jshint ignore:line | |
// Wrap all ®s in superscript tags if they are not currently wrapped. | |
var regexp = /[\xAE]/; | |
$('body :not(script,sup)').contents().filter(function() { | |
return this.nodeType === 3 && (regexp.test(this.nodeValue)); | |
}).replaceWith(function() { | |
return this.nodeValue.replace(regexp, '<sup>$&</sup>'); | |
}); | |
} | |
}; | |
})(jQuery, Drupal, this, this.document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment