Skip to content

Instantly share code, notes, and snippets.

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

Mario Blas Gil Cárdenes marioblas

🏠
Working from home
View GitHub Profile
@marioblas
marioblas / checkbox.js
Created February 12, 2014 23:24
jQuery - Know if all checkboxes are selected
/**
* Know if all checkboxes are selected.
* Note: You can add the same class for each checkbox instead of use :checkbox selector
*/
$(':checkbox').on('change', function() {
if ( $(':checkbox:checked').length == $(':checkbox').length ) {
// Do something
}
});
@marioblas
marioblas / vertical-align.css
Last active April 17, 2016 17:45
Twitter Bootstrap - Align vertically a column
/* Align vertically a column */
.v-align {
float: none;
display: inline-block;
vertical-align: middle;
}
@marioblas
marioblas / insert-reactive-content.js
Last active August 29, 2015 13:58
Meteor 0.8.0 (blaze) - Inserting some reactive Meteor UI content into an existing document
/**
* Inserting some reactive Meteor UI content into an existing document.
*
* UI.render instantiates a template and UI.insert adds it as a child of some element in the DOM.
* UI.renderWithData is like UI.render which also sets the data context.
*/
UI.insert(UI.render(Template.foo), document.body);
UI.insert(UI.renderWithData(Template.foo, {bar: "baz"}), document.body);
@marioblas
marioblas / add-attributes.js
Last active December 21, 2017 17:41
Underscore.js - Add attributes to each object of an array
/**
* Add attributes to each object of an array.
*
* @param {array} foo - Array of objects where we will add the attibutes
* @param {function} iterator
*/
_.each(foo, function(element, index) {
_.extend(element, {field1: index}, {field2: 'bar', field3: 'baz'});
});
@marioblas
marioblas / remove-replace-spaces.js
Last active August 29, 2015 13:59
Javascript - Remove or replace spaces from a string
/**
* Remove spaces from a string.
*
* Info: http://stackoverflow.com/questions/5963182/how-to-remove-spaces-from-a-string-using-javascript
*/
str = str.replace(/\s+/g, '');
/**
* In the first regex, each space character is being replaced, character by character, with the empty string.
* In the second regex, each contiguous string of space characters is being replaced with the empty string because of the +.
@marioblas
marioblas / list-fiendly.js
Last active August 29, 2015 14:00
Javascript - Hace mas amigable la lectura de una lista de elementos separados por punto
/**
* Hace mas amigable la lectura de una lista de elementos separados por punto
*
* Ejemplos:
*
* HTML.CSS.Javascript.Node.
* --> HTML, CSS, Javascript y Node.
*
* HTML.
* CSS.
@marioblas
marioblas / get-last-class.js
Last active April 12, 2016 09:16
jQuery - Get the last class of an element
/**
* Get the last class of an element
*/
var lastClass = $('.foo').attr('class').split(' ').pop();
@marioblas
marioblas / truncate_string.css
Created April 29, 2014 11:49
CSS - Truncate String with Ellipsis
/**
* Truncate String with Ellipsis.
*
* Source: http://css-tricks.com/snippets/css/truncate-string-with-ellipsis/
*/
.truncate {
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
@marioblas
marioblas / data-attibute.js
Last active August 29, 2015 14:00
jQuery - Write data-* attribute and get it
/**
* Write data-* attribute and get it.
*
* When you make a call to .data, jQuery looks for any data-* attributes, and adds it to the data collection.
* However, THIS ONLY HAPPENS ONCE. Subsequent calls to .data will not look at the element's data-* attributes.
*
* Source: http://stackoverflow.com/questions/12271362/writing-to-a-data-attribute-and-getting-it-with-jquery-data/12271393#12271393
* Related and very important: http://stackoverflow.com/questions/7261619/jquery-data-vs-attr#7262427
*/
$('.foo').attr('data-bar', 'baz');
@marioblas
marioblas / scroll-bottom.js
Created July 17, 2014 12:55
jQuery - Check if a user has scrolled to the bottom
/**
* Check if a user has scrolled to the bottom.
*
* Source: http://stackoverflow.com/questions/3898130/how-to-check-if-a-user-has-scrolled-to-the-bottom
*/
$(window).scroll(function() {
if( $(window).scrollTop() + $(window).height() == $(document).height() ) {
console.log("bottom!");
}
});