Skip to content

Instantly share code, notes, and snippets.

Created March 10, 2017 15:59
Show Gist options
  • Save anonymous/ec138465bfaa7b117136060c51fca60d to your computer and use it in GitHub Desktop.
Save anonymous/ec138465bfaa7b117136060c51fca60d to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Mar 10, 2017.
    14 changes: 14 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    <section>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
    has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
    <p>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of <b>Lorem Ipsum</b>.</p>
    <a href="https://en.wikipedia.org/wiki/Lorem_ipsum">Lorem Ipsum Wikipedia Link</a>
    </section>
    <section>
    <p>This <span class="small-u">lorem ipsum</span> should not be hilighted.</p>
    </section>
    <ul>
    <li>A Lorem Ipsum List</li>
    <li>More Elements Here</li>
    </ul>
    <p class="notification"></p>
    7 changes: 7 additions & 0 deletions jquery-find-replace-plugin.markdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    jQuery Find Replace Plugin
    --------------------------


    A [Pen](http://codepen.io/Shokeen/pen/EPGWPM) by [Monty](http://codepen.io/Shokeen) on [CodePen](http://codepen.io/).

    [License](http://codepen.io/Shokeen/pen/EPGWPM/license).
    43 changes: 43 additions & 0 deletions script.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    (function($) {
    $.fn.findReplace = function(options) {

    var settings = $.extend({
    findText: null,
    replaceText: "",
    customClass: "",
    completeCallback: null
    }, options);
    return this.each(function() {
    var StringToFind = settings.findText;
    var regExpression = new RegExp(StringToFind, "g");
    var replacement = "<span class='" + settings.customClass + "'>" + settings.replaceText + "</span>";
    $(this).html(
    $(this).html().replace(regExpression, replacement)
    );

    if ($.isFunction(settings.completeCallback)) {
    settings.completeCallback.call(this);
    }
    });
    };
    }(jQuery));

    $("a").findReplace({
    findText: "Lorem Ipsum",
    replaceText: "I was replaced too!",
    customClass: "match-link",
    completeCallback: function() {
    $('.notification').text('Executed the plugin on all links').fadeOut(5000);
    }
    });

    $("section").findReplace({
    findText: "Lorem Ipsum",
    replaceText: "Ipsum Lorem",
    customClass: "match-section"
    });

    $("ul").findReplace({
    findText: "Lorem",
    replaceText: "Replaced"
    });
    1 change: 1 addition & 0 deletions scripts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    28 changes: 28 additions & 0 deletions style.css
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    body {
    font-family: 'Dosis';
    font-size: 1.3em;
    width: 600px;
    text-align: justify;
    line-height: 1.8em;
    }

    .match-section {
    background: #9F6;
    border-radius: 3px;
    padding: 2px;
    }

    .match-link {
    background: #F96;
    border-radius: 3px;
    padding: 2px;
    }

    .notification{
    border-radius: 3px;
    background: rgba(0,0,0,0.9);
    color: #fff;
    padding: 4px;
    position: fixed;
    bottom: 0;
    }
    1 change: 1 addition & 0 deletions styles
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <link href="https://fonts.googleapis.com/css?family=Dosis" rel="stylesheet" />