Skip to content

Instantly share code, notes, and snippets.

View jorgepinon's full-sized avatar

Jorge Luis Piñon jorgepinon

View GitHub Profile
@jorgepinon
jorgepinon / getFirstSegment()
Last active August 29, 2015 14:15
returns the first segment of the current url
function getFirstSegment() {
var path = window.location.pathname;
seg1 = path.split("/")[1];
return seg1;
}
@jorgepinon
jorgepinon / ffmpeg web video
Last active August 29, 2015 14:12
basic ffmpeg web video command
ffmpeg -i input_file.mp4 -codec:v libx264 -profile:v high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=-1:480 -threads 0 -codec:a libfdk_aac -b:a 128k output_file.mp4
@jorgepinon
jorgepinon / preventDoubleSubmission.js
Last active August 29, 2015 14:10
block form double-submission
// jQuery plugin to prevent double submission of forms
jQuery.fn.preventDoubleSubmission = function() {
$(this).on('submit',function(e){
var $form = $(this);
if ($form.data('submitted') === true) {
// don't submit
e.preventDefault();
} else {
// set data attr to true for next time
@jorgepinon
jorgepinon / toggleOverlay()
Created February 26, 2014 17:02
simple utility for adding an overlay to help focus user on a page element
function toggleOverlay() {
if (document.getElementById('overlay') != null) {
console.log(true);
$('#overlay').fadeOut(300,function(){
$(this).remove()
});
} else {
var overlay = document.createElement('div');
overlay.id = 'overlay';
overlay.className = 'mfp-bg'; /* use existing styles */
@jorgepinon
jorgepinon / css unicode icons
Created February 26, 2014 15:53
Use escaped unicode for css pseudo-element content value
// usage: <span aria-hidden="true" class="u-icon--chevron--left"></span>
// →
.u-icon--arrow--right:before {
content: '\279E';
}
// ❯
.u-icon--chevron--right:before {
content: '\276F';
@jorgepinon
jorgepinon / drawer
Last active August 29, 2015 13:56
slideDown drawer module (html, scss, jquery)
// TODO: add keyboard listeners and aria attributes (expanded, haspopup)
/////////////////////////
////// HTML
///////////////
<div class="drawer trigger-drawer-open is-drawer-closed">
<div class="drawer-hd">
<span class="pull-left" data-target="drawer-bd"><span class="icon--arrow--closed"></span></span>
<h3 class="drawer-title">Drawer header indicates drawer-bd content</h3>
@jorgepinon
jorgepinon / JSON obj to Array
Created December 13, 2013 07:17
create an array of objects from a JSON object (useful for harpjs _data.json)
var dataJson = {},
dataArray = [];
// assuming a JSON structure like this:
dataJson = {
"key1": {
"prop1": "val1",
"prop2": "val2"
},
@jorgepinon
jorgepinon / fadeOut + remove
Last active December 26, 2015 02:29
jQuery fadeOut and remove plugin
$.fn.fadeOutAndRemove = function(speed){
$(this).fadeOut(speed,function(){
$(this).remove();
})
}
// use like $('div').fadeOutAndRemove(200);
@jorgepinon
jorgepinon / alert.js
Last active December 15, 2015 12:38
A tiny jquery plugin that adds a close link to an alert div
(function($){
$.fn.extend({
//pass the options variable to the function
alert: function(options) {
//Set the default values
var defaults = {
pull: 'right',
@jorgepinon
jorgepinon / nav-styles-responsive.html
Last active December 15, 2015 09:19
A CodePen by Jorge Luis Piñon. 3 .nav types, with togglers - .nav .nav--pills (extends .nav) .nav--stacked (extends .nav) For small screens a toggle link appears that expands an each navigation. TODO: method to alternate nav types repsonsively. For example, nav--stacked becomes nav--pills at a given breakpoint
<h2>3 Nav styles (with Toggling)</h2>
<ul>
<li>.nav (basic, horizontal list of links with padding for tap targets)</li>
<li>.nav-pills (extends nav, defined backgrounds, spaced)</li>
<li>.nav--stacked (extends nav, windowshade)</li>
</ul>
<p>For "major" navigation (like site-wide), the UL should be wrapped in a NAV element. Toggle links (".nav-link") should then be added as first child of NAV, sibling to UL.</p>
<p>Toggle links appear at small screen sizes.</p>