Skip to content

Instantly share code, notes, and snippets.

@elclanrs
elclanrs / toCustomFile.js
Created July 5, 2012 03:57
toCustomFile
$.fn.toCustomFile = function () {
return this.each(function () {
var
$file = $(this), // The file input
// Necessary markup
$wrap = $('<div class="wrap">'),
$input = $('<input type="text" class="filename" />'),
@elclanrs
elclanrs / jquery.idealforms.min.js
Created July 29, 2012 10:17
jquery.idealforms.min.js
/*--------------------------------------------------------------------------
jq-idealforms 2.0
* Author: Cedric Ruiz
* License: GPL or MIT
* Demo: http://elclanrs.github.com/jq-idealforms/
*
--------------------------------------------------------------------------*/(function(e){"use strict";e.idealforms={};var t={getMaxWidth:function(t){var n=0;return t.each(function(){e(this).outerWidth()>n&&(n=e(this).outerWidth())}),n},getLessVar:function(t,n){var r=e('<p class="'+t+'"></p>').hide().appendTo("body").css(n);return e("."+t).remove(),/^\d+/.test(r)?parseInt(r,10):r},getKeys:function(e){var t=[];for(var n in e)t.push(n);return t},isFunction:function(e){return typeof e=="function"},isRegex:function(e){return e instanceof RegExp},getByNameOrId:function(t){if(e('[name="'+t+'"]').length)return e('[name="'+t+'"]');if(e('[name="'+t+'"]').length)return e("#"+t);e.error('The field "'+t+"\" doesn't exist.")},getIdealType:function(e){var t=e.attr("type")||e[0].tagName.toLowerCase();return/(text|password|em
@elclanrs
elclanrs / idealselect.js
Created August 6, 2012 22:40
jQuery select menu replacement
/**
* A custom <select> menu jQuery plugin
* @example `$('select').idealSelect()`
*/
$.fn.idealSelect = function () {
return this.each(function () {
var
function newDialog(id) {
var $div = $('<div id="#'+ id +'"/>').dialog({
open: function() {
$(this).append(
'<textarea class="content-area">Content</textarea>'+
'<textarea class="input-area">Input</textarea>'
)
},
title: id
});
@elclanrs
elclanrs / jquery.animateText.js
Created October 5, 2012 22:19
jquery.animateText
$.fn.animateText = function(delay, klass) {
var text = this.text();
var letters = text.split('');
return this.each(function(){
var $this = $(this);
$this.html(text.replace(/./g, '<span class="letter">$&</span>'));
$this.find('span.letter').each(function(i, el){
setTimeout(function(){ $(el).addClass(klass); }, delay * i);
@elclanrs
elclanrs / gist:3850588
Created October 8, 2012 03:31
IE Conditional comments
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
@elclanrs
elclanrs / refreshCss.js
Last active October 11, 2015 15:58
Auto-refresh CSS in browser
// Copy paste in browser console
// F5 to stop interval
setInterval(function () {
[].filter.call(document.querySelectorAll('link'), function(el) {
return !/google|lorempixel/.test(el.href);
}).forEach(function (el) {
var href = el.href,
date = '?' + new Date().getTime();
el.href = /\?/.test(href) ? href.replace(/\?.+/, date) : href + date;
});
function convertMonthToName( val ) {
var months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ];
return months[ val-1 ];
}
@elclanrs
elclanrs / sRegExpWithUnicode.js
Created October 15, 2012 08:13
Super Regex, interpolate variables in regular expressions with unicode
// Super RegExp
// @param regex A regular expression as literal or as string
// @param obj And object containing the values to replace inside the regex
// Usage: var regex = sRegExp( /Hello #{a}/, { a: 'World' } )
function sRegExp( regex, obj ) {
regex = regex.toString();
var newRegex = regex.replace(/(^\/|\/$|\/([igm]+)$)/g, '')
.replace( /#\{(\w+)\}/g, function( a,b ) { return obj[b]; });
var mods = regex.match( /\/([igm]+)$/ );
return new RegExp( newRegex, mods ? mods[1] : '' );
.sliced {
position: relative;
width: 640px;
height: 400px;
}
.tile { float: left; }