Skip to content

Instantly share code, notes, and snippets.

View uhtred's full-sized avatar

Daniel França uhtred

View GitHub Profile
@uhtred
uhtred / blocks-board.js
Last active August 29, 2015 14:06
JS: Blocks Board
define([], function() {
'use strict';
var optionsDefault = {
lines: 4,
cols: 4
};
function BlocksBoard(options) {
@uhtred
uhtred / viewport-change.js
Created September 22, 2014 17:10
JS: Detect Viewport Change
/*
Based on: http://css-tricks.com/media-query-change-detection-in-javascript-through-css-animations/
*/
define( [
/*'jquery', 'modernizr'*/
], function() {
@uhtred
uhtred / viewport-change.scss
Created September 22, 2014 17:12
CSS: Detect Viewport Change
/*
Based on: http://css-tricks.com/media-query-change-detection-in-javascript-through-css-animations/
*/
body {
@include animation-duration( 0.001s );
@media screen and (min-width: 48em) {
@uhtred
uhtred / fix-touches.js
Last active August 29, 2015 14:06
JS: Fix Touches
function fixTouches( e ) {
if(e.originalEvent.touches && e.originalEvent.touches.length) {
e.touches = e.originalEvent.touches;
} else if(e.originalEvent.changedTouches && e.originalEvent.changedTouches.length) {
e.touches = e.originalEvent.changedTouches;
}
}
// Solve jQuery touch events
@uhtred
uhtred / jQuery Mask Plugin São Paulo.js
Created October 8, 2014 22:30
JS: jQuery Mask Plugin São Paulo
var maskBehavior = function(val) {
return val.match(/^(\(?11\)? ?9(5[0-9]|6[0-9]|7[01234569]|8[0-9]|9[0-9])[0-9]{1})/g) ? '(00) 00000-0000' : '(00) 0000-00009';
},
options = {
onKeyPress: function(val, e, field, options) {
field.mask(maskBehavior.apply({}, arguments), options);
}
};
$('.phone').mask(maskBehavior, options);
@uhtred
uhtred / solution-chosen+valdiate.js
Created October 10, 2014 13:57
JS:Chosen + Validate Solution
//On validate:
ignore: function(index, element) {
return !!$(element).parents(':hidden').length;
}
//On chosen:
$('.chosen-select').chosen().change(function() {
$(this).trigger('click');
@uhtred
uhtred / validate-scope.js
Created October 16, 2014 17:29
JS: Validate Scope Using jQuery Validate
'validate--scope-dependence': {
required: function(element) {
var hasFilled = !!$(element).closest('.validate--scope')
.find('input, select, textarea')
.not( element )
.filter(function() {
return $(this).val().length > 0;
}).length;
@uhtred
uhtred / extend-jquery-validate-method.js
Created October 16, 2014 18:10
JS:Extend jQuery Validate Native Methods
$.validator.addMethod("cMaxlength", function(value, element, param) {
return $.validator.methods.maxlength.call(this, value, element, param[1]);
}, '{0}');
/*
USE
$.validator.addClassRules({
@uhtred
uhtred / disable-onkeyup-field.js
Created October 21, 2014 20:58
JS:jQuery Validate Tip To Disable Onkeyup Event In One Field.
jQuery.validator.setDefaults({
onkeyup: function(element) {
var _this = this,
$element = $(element),
element_id = $element.attr('id'),
classes = $element.attr('class') || '';
$.each(classes.split(' '), function() {
if (this in $.validator.classRuleSettings && $.validator.classRuleSettings[this].onkeyup !== false) {
$.validator.defaults.onkeyup.apply(_this, arguments);
@uhtred
uhtred / jquery-validate-only-one.js
Created October 31, 2014 21:49
JS: jQuery Validate Method Only One
$.validator.addMethod('onlyOne', function(value, element, params) {
var _this = this,
$element = $(element),
siblingsSelector = params[1],
scopeSelector = params[2],
repeated = false,
$repeat,
$elements = $element.closest(scopeSelector).find(siblingsSelector).not(element),
$elementsFirst = $elements.eq(0),