/*
* The Strangecode Codebase - a general application development framework for PHP
* For details visit the project site:
* Copyright © 2014 Strangecode, LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
// Codebase functions will be under the Strangecode namespace, unless they are added to the jQuery object for chaining.
var Strangecode = Strangecode || {};
/*
Emulates a sprintf function. Placeholders are {1}…{N}.
Some versions of this function were zero-indexed; this one is not.
---------------------------------------------------------------------
"{1} is dead, but {2} is alive! {1} {3}".format("ASP", "ASP.NET")
outputs
ASP is dead, but ASP.NET is alive! ASP {3}
---------------------------------------------------------------------
*
* @access public
* @param string multiple Strings to pass to the formatted string.
* @author http://stackoverflow.com/a/4673436/277303
* @version 1.0
* @since 30 May 2014 18:02:39
*/
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number-1] != 'undefined' ? args[number-1] : match;
});
};
}
/*
* Displays 'user at domain dot com' as 'user@domain.com'.
---------------------------------------------------------------------
user at domain dot com
Email me
---------------------------------------------------------------------
*
* @access public
* @version 2.0
* @since 30 Jun 2008 12:32:19
*/
jQuery.fn.nospam = function() {
return this.each(function(){
$(this).text($(this).text().replace(' at ', '@').replace(' dot ', '.'));
if (this.href) {
this.href = this.href.replace(' at ', '@').replace(' dot ', '.');
}
});
};
/*
* Encode html entities by specific mapping table.
* Decode HTML by proxying content via an in-memory div, setting its inner text which jQuery automatically encodes.
Then we pull the encoded contents back out. The div never exists on the page.
---------------------------------------------------------------------
$('input').val(Strangecode.htmlEncode(string));
---------------------------------------------------------------------
@access public
@version 2.0
@since 30 Jun 2013
*/
Strangecode.htmlEncode = function (str) {
var entityMap = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": ''',
'/': '/',
'`': '`'
};
return String(str).replace(/[&<>"'\/`]/g, function (s) {
return entityMap[s];
});
};
Strangecode.htmlDecode = function (str) {
return $('
').html(str).text();
};
/*
Returns a string with URL-unsafe characters removed.
---------------------------------------------------------------------
var urlslug = $('.url').val().slug();
---------------------------------------------------------------------
* @access public
* @version 1.0
* @since 30 Jun 2013
*/
$.fn.slug = function() {
str = this.text().trim().toLowerCase();
var from = 'áéíóúàèìòùäëïöüÁÉÍÓÚÀÈÌÒÙÄËÏÖÜâêîôûÂÊÎÔÛñçÇ@·/_,:;';
var to = 'aeiouaeiouaeiouAEIOUAEIOUAEIOUaeiouAEIOUncCa------';
for (var i=0, l=from.length; i (.1*.2)
0.020000000000000004
> (.1*.2).trim()
0.02
---------------------------------------------------------------------
* @access public
* @version 1.0
* @since 24 Nov 2015
*/
if (!Number.prototype.trim) {
Number.prototype.trim = function (precision) {
var precision = precision || 11;
return Math.round(this * Math.pow(10, precision)) / Math.pow(10, precision);
};
}
/*
Uppercase the first letter of string.
---------------------------------------------------------------------
> 'hello world'.trim()
Hello world
---------------------------------------------------------------------
* @access public
* @version 1.0
* @since 24 Nov 2015
*/
if (!String.prototype.ucfirst) {
String.prototype.ucfirst = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
};
}