Unknown: mysqli::real_escape_string(): Passing null to parameter #1 ($string) of type string is deprecated in /home3/chicks64/theforestsecret.com.br/system/library/db/mysqli.php on line 45Warning: Cannot modify header information - headers already sent by (output started at /home3/chicks64/theforestsecret.com.br/system/framework.php:42) in /home3/chicks64/theforestsecret.com.br/catalog/controller/startup/session.php on line 25Unknown: Automatic conversion of false to array is deprecated in /home3/chicks64/theforestsecret.com.br/catalog/controller/startup/startup.php on line 95Warning: Cannot modify header information - headers already sent by (output started at /home3/chicks64/theforestsecret.com.br/system/framework.php:42) in /home3/chicks64/theforestsecret.com.br/catalog/controller/startup/startup.php on line 99Warning: Cannot modify header information - headers already sent by (output started at /home3/chicks64/theforestsecret.com.br/system/framework.php:42) in /home3/chicks64/theforestsecret.com.br/catalog/controller/startup/startup.php on line 157Warning: Cannot modify header information - headers already sent by (output started at /home3/chicks64/theforestsecret.com.br/system/framework.php:42) in /home3/chicks64/theforestsecret.com.br/catalog/controller/checkout/compraexpress.php on line 28//url da loja
var urlSSL = 'https://theforestsecret.com.br///';
//funcoes javascript
function aplicar_metodo_entrega_checkout(meio){
if(meio==''){
return false;
}
console.log('Meio de entrega: '+meio+'!');
var comentario = $('#comentario_pedido').val();
if (typeof comentario == 'undefined') {
var comentario = '';
}
$.ajax({
type: "POST",
url: urlSSL+"index.php?route=checkout/shipping_method/save",
data: {shipping_method:meio,comment:comentario},
dataType: 'JSON',
}).done(function( data ) {
if(typeof data.redirect !== 'undefined'){
location.href = data.redirect;
return false;
}else if(typeof data.error !== 'undefined'){
alerta_bootbox(data.error.warning);
desbloquear_tela_checkout();
return false;
}else{
//carrega o carrinho
carregar_carrinho_checkout();
//aplica novamente o metodo de pagamento se selecionado
var meio_pagamento = qual_metodo_pagamento_checkout();
if(meio_pagamento){
//tela de pagamento
carregar_pagamento_checkout(meio_pagamento);
}else{
//tela de produtos
$.ajax({
type: "GET",
url: urlSSL+"index.php?route=checkout/compraexpress/ver_itens_html",
dataType: 'html',
}).done(function( html ) {
var div = $('#tabela-produtos');
div.html(html);
});
}
}
});
}
function tipo_cliente_cliente(tipo,zona='todas'){
//remove os campos antes de adicionar novos
$('.custom-field').remove();
//pega o tipo de cliente selecionado
var $radios = $('input:radio[name=tipo_pessoa]');
if($radios.is(':checked') === false) {
$radios.filter('[value='+tipo+']').prop('checked', true);
}
//campos extras html cliente
if(zona=='todas' || zona=='cliente'){
$.ajax({
type: "POST",
url: urlSSL+"index.php?route=account/registroexpress/campos_extras_cliente",
dataType: 'html',
data: {grupo: tipo}
}).done(function( html ) {
$('#campos_extras_cliente').html(html);
});
}
//campos extras html endereco
if(zona=='todas' || zona=='endereco'){
var id_endereco = $('#endereco_inicial').val();
$.ajax({
type: "POST",
url: urlSSL+"index.php?route=account/registroexpress/campos_extras_endereco&endereco_id="+id_endereco,
dataType: 'html',
data: {grupo: tipo}
}).done(function( html ) {
$('#campos_extras_endereco').html(html);
});
}
}
function buscar_endereco_cadastro(){
var EstadosArray = [];
EstadosArray["AC"] = 440;
EstadosArray["AL"] = 441;
EstadosArray["AP"] = 442;
EstadosArray["AM"] = 443;
EstadosArray["BA"] = 444;
EstadosArray["CE"] = 445;
EstadosArray["DF"] = 446;
EstadosArray["ES"] = 447;
EstadosArray["GO"] = 448;
EstadosArray["MA"] = 449;
EstadosArray["MT"] = 450;
EstadosArray["MS"] = 451;
EstadosArray["MG"] = 452;
EstadosArray["PA"] = 453;
EstadosArray["PB"] = 454;
EstadosArray["PR"] = 455;
EstadosArray["PE"] = 456;
EstadosArray["PI"] = 457;
EstadosArray["RJ"] = 458;
EstadosArray["RN"] = 459;
EstadosArray["RS"] = 460;
EstadosArray["RO"] = 461;
EstadosArray["RR"] = 462;
EstadosArray["SC"] = 463;
EstadosArray["SP"] = 464;
EstadosArray["SE"] = 465;
EstadosArray["TO"] = 466;
var cep = $("#address input[name='cep']").val();
var s = (cep).replace(/\D/g,'');
var tam=(s).length;
if(tam==8){
$.getScript(urlSSL+"api_cep.php?formato=javascript&cep="+cep, function(){
if(resultadoCEP["resultado"] != 0){
console.log(resultadoCEP);
$("#address input[name='logradouro']").val(unescape(resultadoCEP["tipo_logradouro"]).toUpperCase()+""+unescape(resultadoCEP["logradouro"]));
$("#address input[name='bairro']").val(unescape(resultadoCEP["bairro"]));
$("#address input[name='cidade']").val(unescape(resultadoCEP["cidade"]));
$("#address select[name='uf']").val(EstadosArray[resultadoCEP["uf"]]).trigger('click');
$("#address span[name='cep_invalido']").addClass('invisible');
$("#address input[name='cep']").removeClass('campo_invalido');
}else{
$("#address input[name='cep']").addClass('campo_invalido');
$("#address span[name='cep_invalido']").removeClass('invisible');
}
});
}
}
function alerta_bootbox(alerta){
if (typeof bootbox.dialog !== "undefined") {
bootbox.dialog({
message: alerta,
title: "Ops",
});
}else{
alert(alerta);
}
}
function bloquear_tela_checkout(){
if (typeof $.blockUI !== "undefined") {
$.blockUI({ message: '
',css: { border: '0px solid #000', 'background-color': 'transparent', padding: '10px'}});
}
}
function desbloquear_tela_checkout(){
if (typeof $.blockUI !== "undefined") {
$.unblockUI();
$('.blockUI').remove();
}
}
function bloquearteladiv(div){
$('#'+div).block({message: '
'});
}
function sair_checkout_express(){
bootbox.confirm("Confirma sair da loja?", function(result) {
if(result==true){
$.ajax({
type: "POST",
url: urlSSL+"index.php?route=checkout/compraexpress/sair",
dataType: 'html',
}).done(function( html ) {
location.href = urlSSL+"index.php?route=account/logout";
});
}
});
return true;
}
function abrir_tela_checkout(url,titulo){
if($.pgwModal('isOpen')){
$.pgwModal('close');
}
$.pgwModal({
url: url,
title : titulo,
loadingContent: '

',
closable: true,
titleBar: true,
closeOnBackgroundClick: false,
maxWidth : 700
});
}
function carregar_checkout_express(){
$.ajax({
url: urlSSL+'index.php?route=checkout/compraexpress/checkout',
dataType: 'html',
success: function(html) {
$('#html-compraexpress').html(html);
desbloquear_tela_checkout();
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
}
function remover_carrinho(key){
$.ajax({
url: 'index.php?route=checkout/cart/remove',
type: 'post',
data: 'key=' + key,
dataType: 'json',
beforeSend: function() {
$('#cart > button').button('loading');
},
complete: function() {
$('#cart > button').button('reset');
},
success: function(json) {
setTimeout(function () {
$('#cart > button').html(' ' + json['total'] + '');
}, 100);
carregar_carrinho_checkout();
carregar_tela_produtos_checkout();
}
});
}
function remover_voucher(key){
$.ajax({
url: 'index.php?route=checkout/cart/remove',
type: 'post',
data: 'key=' + key,
dataType: 'json',
beforeSend: function() {
$('#cart > button').button('loading');
},
complete: function() {
$('#cart > button').button('reset');
},
success: function(json) {
setTimeout(function () {
$('#cart > button').html(' ' + json['total'] + '');
}, 100);
carregar_carrinho_checkout();
carregar_tela_produtos_checkout();
}
});
}
function carregar_tela_produtos_checkout(){
$.ajax({
type: "GET",
url: urlSSL+"index.php?route=checkout/compraexpress/ver_itens_html",
dataType: 'html',
}).done(function( html ) {
var div = $('#tabela-produtos');
div.html(html);
});
}
function carregar_endereco_cliente_json(endereco,tipo,zona){
$('#endereco_inicial').val(endereco);
$.ajax({
type: "GET",
url: urlSSL+"index.php?route=checkout/compraexpress/dados_endereco_json&id="+endereco,
dataType: 'JSON',
}).done(function( dados ) {
console.log(dados);
tipo_cliente_cliente(tipo,zona);
if(dados.id){
$('#idendereco_e').val(dados.id);
$('#nome_completo_e').val(dados.nome+' '+dados.sobrenome);
$('#cep_e').val(dados.cep);
$('#logradouro_e').val(dados.logradouro);
$('#bairro_e').val(dados.bairro);
$('#cidade_e').val(dados.cidade);
$('#uf_e').val(dados.uf);
$('#pais_e').val(dados.pais);
$('#acao_endereco').val('atualizar');
}else{
$('#endereco_inicial').val('');
$('#idendereco_e').val('');
$('#nome_completo_e').val('');
$('#cep_e').val('');
$('#logradouro_e').val('');
$('#bairro_e').val('');
$('#cidade_e').val('');
$('#uf_e').val('');
$('#acao_endereco').val('adicionar');
}
});
}
function carregarEstados(estado,ufe){
$.ajax({
type: "GET",
url: urlSSL+"index.php?route=account/registroexpress/estados",
data: {pais:estado},
dataType: 'json',
}).done(function( dados ) {
var estados = '';
$.each(dados, function(key,val) {
estados += '';
});
$('#'+ufe).html(estados);
});
}
function ativar_mostrar_endereco(tipo){
$('.lista_enderecos').hide();
$('#endereco-'+tipo).show();
$('.botoes_enderecos').removeClass('active');
$('.'+tipo).addClass('active');
}
function recupersenha(form){
var dados = $(form).serialize();
console.log(dados);
$.ajax({
type: "POST",
url: urlSSL+"index.php?route=checkout/compraexpress/atualizarsenhaemail",
dataType: 'json',
data: dados,
beforeSend: function() {
//bloquear_tela_checkout();
},
}).done(function( dados ) {
console.log(dados);
if(dados.erro==true){
$('#div-rec-msg').html(' '+dados.msg+'
');
}else{
$('#div-rec-msg').html(' '+dados.msg+'
');
setTimeout(function() {
$.pgwModal('close');
}, 1000);
}
});
return false;
}
function check_metodo_pagamento_checkout(){
var meio_pagamento = qual_metodo_pagamento_checkout();
if(meio_pagamento){
return true;
}else{
alerta_bootbox("Selecione primeiro uma forma de pagamento!");
return false;
}
}
function logincompraexpressaviso(form){
var dados = $(form).serialize();
console.log(dados);
if(!$(form).valid()){
return false;
}
$.ajax({
type: "POST",
url: urlSSL+"index.php?route=checkout/compraexpress/entrar",
dataType: 'html',
data: dados,
beforeSend: function() {
bloquear_tela_checkout();
},
}).done(function( html ) {
if(html==0){
$('#div-login-msg-aviso-modal').html(' E-mail ou senha inválida!
');
desbloquear_tela_checkout();
}else{
$.pgwModal('close');
carregar_checkout_express();
}
});
return false;
}
function aplicar_metodo_pagamento_checkout(meio){
//pega o metodo de entrega selecionado
var meio_entrega = qual_metodo_entrega_checkout();
//verifica se o produto tem um meio de entrega selecionado ou e digital
var produto_digital = $('input[name="produto_digital"]').val();
if(produto_digital=='false' && meio_entrega==false){
alerta_bootbox("Selecione primeiro o meio de entrega para poder selecionar a forma de pagamento!");
limpar_metodo_pagamento_checkout();
return false;
}
//bloqueia se vazio
if(meio==''){
return false;
}
//aplica e salva o metodo de pagamento
console.log('Metodo de pagamento: '+meio+'!');
var comentario = $('#comentario_pedido').val();
if (typeof comentario == 'undefined') {
var comentario = '';
}
$.ajax({
type: "POST",
url: urlSSL+"index.php?route=checkout/payment_method/save",
data: {payment_method:meio,agree:1,comment:comentario},
dataType: 'html',
}).done(function( html ) {
//salva e carrega
$('#meio_selecionado_express').val(meio);
carregar_pagamento_checkout(meio);
});
}
function carregar_pagamento_checkout(meio){
if(meio==''){
return false;
}
$(":radio[value="+meio+"]").prop('checked',true);
var idcliente = $('#cliente_id').val();
var clientehash = $('#cliente_hash').val();
bloquear_tela_checkout();
//carrega a tela de pagamento
$.ajax({
type: "GET",
url: urlSSL+"index.php?route=checkout/confirm",
data: {id:idcliente,hash:clientehash},
dataType: 'html',
}).done(function( html ) {
//div pagamento
var div = $('#html-detalhes-como-pagar');
div.html(html);
//desbloqueia a tela
desbloquear_tela_checkout();
carregar_carrinho_checkout();
});
}
function carregar_carrinho_checkout(){
$.ajax({
type: "GET",
url: urlSSL+"index.php?route=common/cart/info&express=true",
dataType: 'HTML',
}).done(function( html ) {
console.log('Carrinho topo atualizado!');
$('#cart-,#cart_block-').replaceWith(html);
});
}
function qual_metodo_pagamento_checkout(){
var selectedValue = false;
var radios = document.getElementsByName("meios_pagamento");
for(var i = 0; i < radios.length; i++) {
if(radios[i].checked) selectedValue = radios[i].value;
}
return selectedValue;
}
function limpar_metodo_pagamento_checkout(){
var radios = document.getElementsByName("meios_pagamento");
for(var i = 0; i < radios.length; i++) {
radios[i].checked = false;
}
return true;
}
function qual_metodo_entrega_checkout(){
var selectedValue = false;
var radios = document.getElementsByName("meios_entrega");
for(var i = 0; i < radios.length; i++) {
if(radios[i].checked) selectedValue = radios[i].value;
}
return selectedValue;
}
//detectar acoes do carrinho
$( document ).ajaxSuccess(function( event, xhr, settings ) {
if (typeof settings.url !== 'undefined' && typeof settings.data !== 'undefined') {
console.log(settings.url);
if(settings.url=='index.php?route=checkout/cart/remove' || settings.url=='checkout/cart/remove'){
carregar_tela_produtos_checkout();
}
}
});
//login facebook
//mascaras javascript pura
function mascara(o,f){
v_obj=o
v_fun=f
setTimeout("execmascara()",1)
}
function execmascara(){
if(v_fun=='telefone')
v_obj.value=telefone(v_obj.value);
if(v_fun=='soNumeros')
v_obj.value=soNumeros(v_obj.value);
if(v_fun=='cpf')
v_obj.value=cpf(v_obj.value);
if(v_fun=='cnpj')
v_obj.value=cnpj(v_obj.value);
if(v_fun=='cpfcnpj')
v_obj.value=cpfCnpj(v_obj.value);
if(v_fun=='cep')
v_obj.value=cep(v_obj.value);
}
function cpfCnpj(v){
v=v.replace(/\D/g,"")
if (v.length <= 11) {
v=v.replace(/(\d{3})(\d)/,"$1.$2")
v=v.replace(/(\d{3})(\d)/,"$1.$2")
v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2")
} else {
v=v.replace(/^(\d{2})(\d)/,"$1.$2")
v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3")
v=v.replace(/\.(\d{3})(\d)/,".$1/$2")
v=v.replace(/(\d{4})(\d)/,"$1-$2")
}
return v
}
function soNumeros(v){
return v.replace(/\D/g,"")
}
function telefone(v){
v=v.replace(/\D/g,"")
v=v.replace(/^(\d\d)(\d)/g,"($1)$2")
return v
}
function cpf(v){
v=v.substr(0,14);
v=v.replace(/\D/g,"")
v=v.replace(/(\d{3})(\d)/,"$1.$2")
v=v.replace(/(\d{3})(\d)/,"$1.$2")
v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2")
return v
}
function cnpj(v){
v=v.substr(0,18);
v=v.replace(/\D/g,"")
v=v.replace(/^(\d{2})(\d)/,"$1.$2")
v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3")
v=v.replace(/\.(\d{3})(\d)/,".$1/$2")
v=v.replace(/(\d{4})(\d)/,"$1-$2")
return v
}
function cep(v){
v=v.replace(/[^1234567890-]/g,"");
v=v.replace(/^(\d{5})(\d)/,"$1-$2")
return v
}
//javacripts utils
// String utils
//
// resources:
// -- mout, https://github.com/mout/mout/tree/master/src/string
/**
* "Safer" String.toLowerCase()
*/
function lowerCase(str) {
return str.toLowerCase();
}
/**
* "Safer" String.toUpperCase()
*/
function upperCase(str) {
return str.toUpperCase();
}
/**
* Convert string to camelCase text.
*/
function camelCase(str) {
str = replaceAccents(str);
str = removeNonWord(str)
.replace(/\-/g, " ") //convert all hyphens to spaces
.replace(/\s[a-z]/g, upperCase) //convert first char of each word to UPPERCASE
.replace(/\s+/g, "") //remove spaces
.replace(/^[A-Z]/g, lowerCase); //convert first char to lowercase
return str;
}
/**
* Add space between camelCase text.
*/
function unCamelCase(str) {
str = str.replace(/([a-z\xE0-\xFF])([A-Z\xC0\xDF])/g, "$1 $2");
str = str.toLowerCase(); //add space between camelCase text
return str;
}
/**
* UPPERCASE first char of each word.
*/
function properCase(str) {
return lowerCase(str).replace(/^\w|\s\w/g, upperCase);
}
/**
* camelCase + UPPERCASE first char
*/
function pascalCase(str) {
return camelCase(str).replace(/^[a-z]/, upperCase);
}
function normalizeLineBreaks(str, lineEnd) {
lineEnd = lineEnd || "n";
return str
.replace(/rn/g, lineEnd) // DOS
.replace(/r/g, lineEnd) // Mac
.replace(/n/g, lineEnd); // Unix
}
/**
* UPPERCASE first char of each sentence and lowercase other chars.
*/
function sentenceCase(str) {
// Replace first char of each sentence (new line or after '.\s+') to
// UPPERCASE
return lowerCase(str).replace(/(^\w)|\.\s+(\w)/gm, upperCase);
}
/**
* Convert to lower case, remove accents, remove non-word chars and
* replace spaces with the specified delimeter.
* Does not split camelCase text.
*/
function slugify(str, delimeter) {
if (delimeter == null) {
delimeter = "-";
}
str = replaceAccents(str);
str = removeNonWord(str);
str = trim(str) //should come after removeNonWord
.replace(/ +/g, delimeter) //replace spaces with delimeter
.toLowerCase();
return str;
}
/**
* Replaces spaces with hyphens, split camelCase text, remove non-word chars, remove accents and convert to lower case.
*/
function hyphenate(str) {
str = unCamelCase(str);
return slugify(str, "-");
}
/**
* Replaces hyphens with spaces. (only hyphens between word chars)
*/
function unhyphenate(str) {
return str.replace(/(\w)(-)(\w)/g, "$1 $3");
}
/**
* Replaces spaces with underscores, split camelCase text, remove
* non-word chars, remove accents and convert to lower case.
*/
function underscore(str) {
str = unCamelCase(str);
return slugify(str, "_");
}
/**
* Remove non-word chars.
*/
function removeNonWord(str) {
return str.replace(/[^0-9a-zA-Z\xC0-\xFF \-]/g, "");
}
/**
* Convert line-breaks from DOS/MAC to a single standard (UNIX by default)
*/
function normalizeLineBreaks(str, lineEnd) {
lineEnd = lineEnd || "\n";
return str
.replace(/\r\n/g, lineEnd) // DOS
.replace(/\r/g, lineEnd) // Mac
.replace(/\n/g, lineEnd); // Unix
}
/**
* Replaces all accented chars with regular ones
*/
function replaceAccents(str) {
// verifies if the String has accents and replace them
if (str.search(/[\xC0-\xFF]/g) > -1) {
str = str
.replace(/[\xC0-\xC5]/g, "A")
.replace(/[\xC6]/g, "AE")
.replace(/[\xC7]/g, "C")
.replace(/[\xC8-\xCB]/g, "E")
.replace(/[\xCC-\xCF]/g, "I")
.replace(/[\xD0]/g, "D")
.replace(/[\xD1]/g, "N")
.replace(/[\xD2-\xD6\xD8]/g, "O")
.replace(/[\xD9-\xDC]/g, "U")
.replace(/[\xDD]/g, "Y")
.replace(/[\xDE]/g, "P")
.replace(/[\xE0-\xE5]/g, "a")
.replace(/[\xE6]/g, "ae")
.replace(/[\xE7]/g, "c")
.replace(/[\xE8-\xEB]/g, "e")
.replace(/[\xEC-\xEF]/g, "i")
.replace(/[\xF1]/g, "n")
.replace(/[\xF2-\xF6\xF8]/g, "o")
.replace(/[\xF9-\xFC]/g, "u")
.replace(/[\xFE]/g, "p")
.replace(/[\xFD\xFF]/g, "y");
}
return str;
}
/**
* Searches for a given substring
*/
function contains(str, substring, fromIndex) {
return str.indexOf(substring, fromIndex) !== -1;
}
/**
* Truncate string at full words.
*/
function crop(str, maxChars, append) {
return truncate(str, maxChars, append, true);
}
/**
* Escape RegExp string chars.
*/
function escapeRegExp(str) {
var ESCAPE_CHARS = /[\\.+*?\^$\[\](){}\/'#]/g;
return str.replace(ESCAPE_CHARS, "\\$&");
}
/**
* Escapes a string for insertion into HTML.
*/
function escapeHtml(str) {
str = str
.replace(/&/g, "&")
.replace(//g, ">")
.replace(/'/g, "'")
.replace(/"/g, """);
return str;
}
/**
* Unescapes HTML special chars
*/
function unescapeHtml(str) {
str = str
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/'/g, "'")
.replace(/"/g, '"');
return str;
}
/**
* Escape string into unicode sequences
*/
function escapeUnicode(str, shouldEscapePrintable) {
return str.replace(/[\s\S]/g, function(ch) {
// skip printable ASCII chars if we should not escape them
if (!shouldEscapePrintable && /[\x20-\x7E]/.test(ch)) {
return ch;
}
// we use "000" and slice(-4) for brevity, need to pad zeros,
// unicode escape always have 4 chars after "\u"
return "\\u" + ("000" + ch.charCodeAt(0).toString(16)).slice(-4);
});
}
/**
* Remove HTML tags from string.
*/
function stripHtmlTags(str) {
return str.replace(/<[^>]*>/g, "");
}
/**
* Remove non-printable ASCII chars
*/
function removeNonASCII(str) {
// Matches non-printable ASCII chars -
// http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters
return str.replace(/[^\x20-\x7E]/g, "");
}
/**
* String interpolation
*/
function interpolate(template, replacements, syntax) {
var stache = /\{\{(\w+)\}\}/g; //mustache-like
var replaceFn = function(match, prop) {
return prop in replacements ? replacements[prop] : "";
};
return template.replace(syntax || stache, replaceFn);
}
/**
* Pad string with `char` if its' length is smaller than `minLen`
*/
function rpad(str, minLen, ch) {
ch = ch || " ";
return str.length < minLen ? str + repeat(ch, minLen - str.length) : str;
}
/**
* Pad string with `char` if its' length is smaller than `minLen`
*/
function lpad(str, minLen, ch) {
ch = ch || " ";
return str.length < minLen ? repeat(ch, minLen - str.length) + str : str;
}
/**
* Repeat string n times
*/
function repeat(str, n) {
return new Array(n + 1).join(str);
}
/**
* Limit number of chars.
*/
function truncate(str, maxChars, append, onlyFullWords) {
append = append || "...";
maxChars = onlyFullWords ? maxChars + 1 : maxChars;
str = trim(str);
if (str.length <= maxChars) {
return str;
}
str = str.substr(0, maxChars - append.length);
//crop at last space or remove trailing whitespace
str = onlyFullWords ? str.substr(0, str.lastIndexOf(" ")) : trim(str);
return str + append;
}
var WHITE_SPACES = [
" ",
"\n",
"\r",
"\t",
"\f",
"\v",
"\u00A0",
"\u1680",
"\u180E",
"\u2000",
"\u2001",
"\u2002",
"\u2003",
"\u2004",
"\u2005",
"\u2006",
"\u2007",
"\u2008",
"\u2009",
"\u200A",
"\u2028",
"\u2029",
"\u202F",
"\u205F",
"\u3000"
];
/**
* Remove chars from beginning of string.
*/
function ltrim(str, chars) {
chars = chars || WHITE_SPACES;
var start = 0,
len = str.length,
charLen = chars.length,
found = true,
i,
c;
while (found && start < len) {
found = false;
i = -1;
c = str.charAt(start);
while (++i < charLen) {
if (c === chars[i]) {
found = true;
start++;
break;
}
}
}
return start >= len ? "" : str.substr(start, len);
}
/**
* Remove chars from end of string.
*/
function rtrim(str, chars) {
chars = chars || WHITE_SPACES;
var end = str.length - 1,
charLen = chars.length,
found = true,
i,
c;
while (found && end >= 0) {
found = false;
i = -1;
c = str.charAt(end);
while (++i < charLen) {
if (c === chars[i]) {
found = true;
end--;
break;
}
}
}
return end >= 0 ? str.substring(0, end + 1) : "";
}
/**
* Remove white-spaces from beginning and end of string.
*/
function trim(str, chars) {
chars = chars || WHITE_SPACES;
return ltrim(rtrim(str, chars), chars);
}
/**
* Capture all capital letters following a word boundary (in case the
* input is in all caps)
*/
function abbreviate(str) {
return str.match(/\b([A-Z])/g).join("");
}