Skip to content

Instantly share code, notes, and snippets.

@codexico
codexico / main.js
Created February 19, 2013 20:02
solucao para o fade nos ies
$(function() {
if (jQuery.browser.msie)
$('img[src$=".png"]').each(function() { // must have quotes around .png
this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+this.src+",sizingMethod='scale')";
});
});
@codexico
codexico / pvt.fb.js
Created April 1, 2013 16:52
scrollTo animate Facebook
// http://stackoverflow.com/questions/7193425/how-do-you-animate-fb-canvas-scrollto
function scrollTo(y){
FB.Canvas.getPageInfo(function(pageInfo){
$({y: pageInfo.scrollTop}).animate(
{y: y},
{duration: 1000, step: function(offset){
FB.Canvas.scrollTo(0, offset);
}
});
@codexico
codexico / utils.js
Created April 4, 2013 15:59
getUrlParameter javascript
var getURLParameter = function (name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[undefined,""])[1].replace(/\+/g, '%20'))||null;
};
@codexico
codexico / stringWidth stringWordCrop
Created April 9, 2013 22:48
Crop string by width and word and append " ...".
// http://stackoverflow.com/questions/118241/calculate-text-width-with-javascript
function stringWidth(s, className) {
var c = className || "",
o = $('<div class="' + c + '">' + s + '</div>')
.css({'position': 'absolute', 'float': 'left', 'white-space': 'nowrap', 'visibility': 'hidden'})
.appendTo($('body')),
w = o.width();
o.remove();
<snippet>
<content><![CDATA[
console.log(${1:this});
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>log</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
<snippet>
<content><![CDATA[
console.log('${1:this} = ', ${1:snippet});
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>clog</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.js</scope>
</snippet>
@codexico
codexico / gist:8568280
Created January 22, 2014 22:02
char list to accept from user
function inputOnlyLetters () {
var re_letters= /^[ ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyzàáãÃÀÁéèÈÉíìÍÌïÏóòõÕÓÒúùÚÙüÜ]+$/gi;
var re_not_letters= /[^ ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyzàáãÃÀÁéèÈÉíìÍÌïÏóòõÕÓÒúùÚÙüÜ]/gi;
$('.not-number').on('keyup', function() {
var input = this;
// user needs some time to write chars that need two strokes, like ç => ' + c
window.setTimeout(function(){
@codexico
codexico / gist:8572143
Last active January 4, 2016 04:59
CSS pointer-events ============= CSS' pointer-events property effectively disable an element when the value is none but otherwise allow the element to function per usual when the value isn't none. Pointer-events even prevent JavaScript events from firing. Click on that element and any addEventListener callback you've placed on the element will n…
.disabled { pointer-events: none; }
emailRegex = /^[\w-]+(\.[\w-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,20})$/i;
@codexico
codexico / capitalize.js
Created February 28, 2019 23:27
function to capitalize text
// string.js
export const capitalize = (string = '') =>
(typeof string === 'string' && string.substring(1))
? string[0].toUpperCase() + string.substring(1).toLowerCase()
: '';
// string.test.js
import { capitalize } from './string';