source: trunk/js/Utilities.js @ 496

Last change on this file since 496 was 496, checked in by anonymous, 10 years ago

Preparing for v2.2. This version will be less conservative towards backwards compatability. Users of codebase <= 2.1.8 or trunk installed before 07 Sept 2014 should use /tags/2.1.8, otherwise upgrade their implementation.

File size: 2.4 KB
Line 
1/*
2* The Strangecode Codebase - a general application development framework for PHP
3* For details visit the project site: <http://trac.strangecode.com/codebase/>
4* Copyright © 2014 Strangecode, LLC
5*
6* This program is free software: you can redistribute it and/or modify
7* it under the terms of the GNU General Public License as published by
8* the Free Software Foundation, either version 3 of the License, or
9* (at your option) any later version.
10*
11* This program is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14* GNU General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with this program.  If not, see <http://www.gnu.org/licenses/>.
18*/
19
20// All Codebase functions will be under the Strangecode namespace.
21var Strangecode = Strangecode || {};
22
23/*
24* Emulates a sprintf function.
25---------------------------------------------------------------------
26"{0} is dead, but {1} is alive! {0} {2}".format("ASP", "ASP.NET")
27
28outputs
29
30ASP is dead, but ASP.NET is alive! ASP {2}
31---------------------------------------------------------------------
32*
33* @access   public
34* @param    string multiple Strings to pass to the formatted string.
35* @author   http://stackoverflow.com/questions/610406/javascript-printf-string-format/4673436#4673436
36* @version  1.0
37* @since    30 May 2014 18:02:39
38*/
39if (!String.prototype.format) {
40    String.prototype.format = function() {
41        var args = arguments;
42        return this.replace(/{(\d+)}/g, function(match, number) {
43            return typeof args[number] != 'undefined' ? args[number] : match;
44        });
45    };
46}
47
48/*
49* Displays 'user at domain dot com' as 'user@domain.com'.
50---------------------------------------------------------------------
51<span class="sc-email">user at domain dot com</span>
52<a href="mailto:user at domain dot com" class="sc-email">Email me</a>
53<script>
54$('.sc-email').nospam();
55</script>
56---------------------------------------------------------------------
57*
58* @access   public
59* @version  2.0
60* @since    30 Jun 2008 12:32:19
61*/
62jQuery.fn.nospam = function() {
63    return this.each(function(){
64        $(this).text($(this).text().replace(' at ', '@').replace(' dot ', '.'));
65        if (this.href) {
66            this.href = this.href.replace(' at ', '@').replace(' dot ', '.');
67        }
68    });
69};
Note: See TracBrowser for help on using the repository browser.