Skip to content

Instantly share code, notes, and snippets.

View marciobarrios's full-sized avatar

Marcio Barrios marciobarrios

View GitHub Profile
@marciobarrios
marciobarrios / jquery_ajax_abort.js
Created March 24, 2009 17:04
Abortar petición AJAX en jQuery
var x = $.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
//kill the request
@marciobarrios
marciobarrios / jquery_ajaxify.js
Created March 27, 2009 05:10
Plugin básico para enviar formularios via ajax
(function() {
$.fn.ajaxify = function(options) {
$(this).submit(function(e) {
var form = $(this);
$.ajax({
type : form.attr('method'),
url : form.attr('action'),
data : form.serialize(),
error : options.error,
success : options.success,
@marciobarrios
marciobarrios / jquery_plugin.js
Created March 27, 2009 16:40
jQuery plugin development pattern
//closure
(function($) {
//permitimos acceso externo a las opciones por defecto
$.fn.pluginName.defaults = {
option1: "whatever",
option2: "",
option3: 9,
option4: true
}
@marciobarrios
marciobarrios / iphone_detector.js
Created May 7, 2009 00:40
para detectar navegador iPhone via javascript
if(navigator.userAgent.match(/iPhone/i)){
window.location = "/iphone/";
}
@marciobarrios
marciobarrios / jquery_debug.js
Created October 28, 2009 18:37
plugins para debugear en jquery
//para debugear con mensajes
$.log = function(message) {
if(window.console) {
console.debug(message);
} else {
alert(message);
}
};
//para hacer un alert del objeto
@marciobarrios
marciobarrios / jquery_autoclean.js
Created October 28, 2009 18:44
para autolimpiar inputs/textarea (podria hacer que con una clase se ejecutara automáticamente)
//plugin para aplicar en textarea/inputs para que cuando tenga el foco se elimine el contenido
$.fn.autoClean = function() {
return this.filter('input, textarea').each(function(){
var $this = $(this);
$this
.attr('default',$this.val())
.focus(function(){
if ( $this.attr('id') == 'terms' ) {
if ($this.val() == $this.attr('title') ) $this.val('');
} else {
@marciobarrios
marciobarrios / validate_mail.js
Created October 28, 2009 18:47
validar mail via js
//validacion de mail
function validarmail(email){
return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email));
}
@marciobarrios
marciobarrios / jquery_anchorslider.js
Created October 30, 2009 00:11
para ir a un anchor en la misma página con efecto de transición
/*******
*** Anchor Slider by Cedric Dugas ***
*** Http://www.position-absolute.com ***
Never have an anchor jumping your content, slide it.
Don't forget to put an id to your anchor !
You can use and modify this script for any project you want, but please leave this comment as credit.
@marciobarrios
marciobarrios / detect_types.js
Created November 17, 2009 11:35
detectar tipos de objetos
function isFunction(a) {
return typeof a == 'function';
}
function isNull(a) {
return typeof a == 'object' && !a;
}
function isNumber(a) {
return typeof a == 'number' && isFinite(a);
}
function isObject(a) {
@marciobarrios
marciobarrios / url_to_object.js
Created November 21, 2009 04:00
para transformar los parametros de una url en un objeto
/*
we have:
http://foo.com?nodeId=2&userId=3&sortOrder=name&sequence=asc
we want:
var params = {
nodeId : 2,
userId : 3,
sortOrder: name,
sequence: asc