Skip to content

Instantly share code, notes, and snippets.

View Victa's full-sized avatar
🏠
Working from home

Victor Victa

🏠
Working from home
View GitHub Profile
@Victa
Victa / s.js
Created January 12, 2012 10:07
Textarea Auto Resize
/*
* Auto resizing textarea
* Usage: <textarea class="autoresize"></textarea>
*/
var textareaAutoResize = function textareaAutoResize(minHeight){
var txt = $('.autoresize'),
hiddenDiv = $(document.createElement('div')),
content = null,
mH = minHeight || 50;
txt.css({overflow:'hidden',minHeight:mH});
@Victa
Victa / gist:1599653
Created January 12, 2012 09:58
Saving contenteditable Content Changes as JSON with Ajax
document.addEventListener('keydown', function (event) {
var esc = event.which == 27,
nl = event.which == 13,
el = event.target,
input = el.nodeName != 'INPUT' && el.nodeName != 'TEXTAREA',
data = {};
if (input) {
if (esc) {
// restore state
@Victa
Victa / gist:1582288
Created January 9, 2012 10:04
Loading dot dot dot in CSS
body {
padding: 100px;
font-size: 62.5%;
}
.loading {
font: 16px Monaco; /* no fallback cuz spacing would probably be off... */
width: 6.1em; /* Was hoping 1 char = 1 em but didn't work out quite */
overflow: hidden;
@Victa
Victa / gist:1579658
Created January 8, 2012 20:56
addClass Function
var addClass = function addClass(_element, _classes) {
var classList, item, _i, _len;
classList = _element.classList;
for (_i = 0, _len = _classes.length; _i < _len; _i++) {
item = _classes[_i];
classList.add(item);
}
return _element;
};
@Victa
Victa / gist:1579626
Created January 8, 2012 20:45
Dom ready trick
(var domCheck = function(){
if(!document.body) return setTimeout(domCheck, 1);
//do moar here
})();
@Victa
Victa / gist:1569879
Created January 6, 2012 09:37
Async Script Loader with Callback
var Loader = function () { }
Loader.prototype = {
require: function (scripts, callback) {
this.loadCount = 0;
this.totalRequired = scripts.length;
this.callback = callback;
for (var i = 0; i < scripts.length; i++) {
this.writeScript(scripts[i]);
}
@Victa
Victa / flexgrid.scss
Created January 3, 2012 11:57
Compass: fluid/fixed grid generator
// ======================
// FlexGrid
// ======================
// Usage :
// nb of column, column width, column gutter, min-width, max-width, responsive, fluid/fixed
// @include flexGrid(12, 60, 20, 640px, 1024px, true)
@mixin flexGrid($grid-columns: 12, $grid-column-with:60, $grid-column-margin: 20,
@Victa
Victa / grid.css
Created January 2, 2012 21:21
Foundation CSS framework: fix webkit percent bug
/* Fix webkit percent bug */
@media screen and (-webkit-min-device-pixel-ratio:0) and (min-width: 767px){
.row>[class$="columns"]:last-of-type{
display: table-cell;
float: none;width: auto;
margin:0;
}
.row>[class$="columns"]:nth-last-of-type(2){
margin-right:4.4%;
@Victa
Victa / gist:1544160
Created December 31, 2011 14:36
Converting px to ems with LESS
/* Create variables [optional] */
@basefont: 14; // in pixels
@baseline: 20; // in pixels
/* Create a converter namespace [optional] */
#pxtoem {
/* Create convert mixin [required] */
.font-size( @target: @basefont, @context: @basefont ) {
font-size: (@target / @context) + 0em;
}
@Victa
Victa / gist:1540518
Created December 30, 2011 16:29
terminal: show/hide hidden files
# show/hide hidden files
hidden() {
if [ "$(defaults read com.apple.finder AppleShowAllFiles)" = 0 ]
then defaults write com.apple.finder AppleShowAllFiles 1
else defaults write com.apple.finder AppleShowAllFiles 0
fi
killall Finder
}