Skip to content

Instantly share code, notes, and snippets.

View qborreda's full-sized avatar

Quique Borredá qborreda

View GitHub Profile
@qborreda
qborreda / mobile_detect.js
Created April 9, 2014 10:42
Mobile device detection
// Detecto si es un iPad o dispositivo con deteccion de movimiento
var isTouchable = ('ontouchstart' in window) || ('onmsgesturechange' in window);
var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
var isOrientationDevice = (window.DeviceOrientationEvent != null) && (typeof(window.DeviceOrientationEvent) === 'object');
@qborreda
qborreda / isOnScreen.js
Created July 17, 2014 08:07
jQuery isOnScreen function to check for an element in viewport
$.fn.isOnScreen = function() {
var win = $(window);
var viewport = {
top : win.scrollTop(),
left : win.scrollLeft()
};
viewport.right = viewport.left + win.width();
viewport.bottom = viewport.top + win.height();
@qborreda
qborreda / randomID.js
Created July 17, 2014 08:13
Random ID generator
var pass = Math.floor(Date.now() * Math.random()).toString(36);
@qborreda
qborreda / no.control.js
Last active August 29, 2015 14:04
Various javaScript methods to prevent user control and menus ..
// Disable Context Menu
document.oncontextmenu = function () {
return false
};
// Disable dragging of HTML elements
document.ondragstart = function () {
return false
};
@qborreda
qborreda / _percent.scss
Created August 5, 2014 08:01
Generate percentual progress classes
/**
* Function to generate percentual progress classes
* .p-1 1% -> p-100 100%
**/
$step: 1;
$loops: round(100 / $step);
$increment: 360 / $loops;
$half: round($loops / 2);
@for $i from 1 through $loops {
@qborreda
qborreda / getAgeFromBirthday.js
Created October 6, 2014 07:16
JavaScript getAgeFromBirthday
function getAgeFromBirthday() {
var month = document.getElementById('b-month').value;
var day = document.getElementById('b-day').value;
var year = document.getElementById('b-year').value;
var b_date = new Date(year, month, day);
if (b_date.getDate() != day || b_date.getMonth() != month || b_date.getFullYear() != year) {
alert('Please enter a valid date of birth');
@qborreda
qborreda / array.unique.js
Created October 10, 2014 07:27
JavaScript Unique function for Arrays
Array.prototype.unique = function() {
return this.filter(function (value, index, self) {
return self.indexOf(value) === index;
});
}
/*****/
var arr = ['a', 1, 'a', 2, '1']
arr.unique(); // => ['a', 1, 2, '1']
@qborreda
qborreda / isMobile.js
Created November 17, 2014 11:24
Detect mobile userAgents
var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
@qborreda
qborreda / _no-selectable.scss
Created November 20, 2014 09:57
Make any DOM element's content not selectable
@mixin no-selectable()
{
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@qborreda
qborreda / jquery.clog.js
Created November 20, 2014 12:34
Variante jQuery para sacar por consola el elemento dom actual y encadenar al objeto
jQuery.fn.clog = function(msg) {
var txt = msg ? msg : "";
if (console && typeof console.log != "undefined") {
console.log('%o ', this, txt);
}
return this;
}
/*
* use .clog() in the middle of your chain to make sure you have the
* proper object before you continue. it will log the current jquery