Skip to content

Instantly share code, notes, and snippets.

@thetrickster
Last active December 19, 2015 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thetrickster/6016066 to your computer and use it in GitHub Desktop.
Save thetrickster/6016066 to your computer and use it in GitHub Desktop.
Find and replace Gyrotonic trademark text in a website using jQuery

Gyrotonic® Trademark jQuery Plugin

Beta Version - Still a work in progress. Use at own risk.

Find and replace text node instances of Gyrotonic/Gyrokinesis in a web page and replace with the correct brand styles required by Gyrotonic Sales Group.

  • Download the script below and save it to your website

  • Reference the script in the or of your website after jQuery is already loaded

    <script src="/js/jquery.gyroTrademark.js"></script>

  • By default the script doesn't use inline CSS to style the text instances. So, you'll need to add the CSS below to your stylesheets already serving your website.

  • Call our javascript plugin after both the plugin script and jQuery are loaded. It's safe to put it just before your closing </body> tag:

<script>
        (function($){
          $(document).ready(function() {
            $("body").gyroTrademark();
          });
        })(jQuery);    
    </script>
  • If you *want to use inline styles over CSS just change where you call your plugin to:

    $("body").gyroTrademark({inlineStyles: true});

.gyro-trademark {
font-family: Times New Roman, Times, serif;
text-transform: uppercase;
font-weight: bold;
}
(function($) {
var GyroTrademark = function(element, options)
{
var elem = $(element);
var obj = this;
var data = elem.data();
var defaults = {
inlineStyles: false
,setFooter: false
};
var settings = $.extend(options, data || defaults);
this.setFooter = function() {
var copyright = "Gyrotonic, Gyrotonic Expansion System and Gyrokinesis are registered trademarks of Gyrotonic Sales Corp and are used with their permission.";
var original = $(settings.setFooter).text();
$(settings.setFooter).html(original+ " " +copyright);
};
this.init = function()
{
if (settings.setFooter) {
this.setFooter();
}
var useInlineStyles = settings.inlineStyles;
if (useInlineStyles) {
var preHTML = "<span style='font-family: Times New Roman, Times, serif; text-transform: uppercase;'>";
var postHTML = "</span>";
} else {
var preHTML = "<span class='gyro-trademark'>";
var postHTML = "</span>";
}
// Replace 'gyrotonic' or 'GYROTONIC'
elem.html(elem.html().replace(/gyrotonic(?!&reg;)(?! expansion)/gi, preHTML+"GYROTONIC&reg;"+postHTML));
// Replace 'gyrokinesis' or 'GYROKINESIS'
elem.html(elem.html().replace(/gyrokinesis(?!&reg;)/gi, preHTML+"GYROKINESIS&reg;"+postHTML));
elem.html(elem.html().replace(/gyrotonic expansion system(?!&reg;)/gi, preHTML+"GYROTONIC EXPANSION SYSTEM&reg;"+postHTML));
};
this.init();
};
$.fn.gyroTrademark = function(options)
{
return this.each(function()
{
var element = $(this);
// Return early if this element already has a plugin instance
if (element.data('gyroTrademark')) return;
// pass options to plugin constructor
var gyroTrademark = new GyroTrademark(this, options);
// Store plugin object in this element's data
element.data('gyroTrademark', gyroTrademark);
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment