Skip to content

Instantly share code, notes, and snippets.

View farinspace's full-sized avatar
🙃
working ...

Dimas Begunoff farinspace

🙃
working ...
View GitHub Profile
@farinspace
farinspace / color_picker
Created September 27, 2014 15:32
Using a color picker with WPAlchemy
jQuery(function($){
var picker_config = {
onSubmit: function(hsb, hex, rgb, el) {
$(el).val(hex);
$(el).ColorPickerHide();
},
onBeforeShow: function () {
$(this).ColorPickerSetColor(this.value);
},
onChange: function (hsb, hex, rgb) {
@farinspace
farinspace / isPositionFixed
Created September 29, 2014 22:46
Javascript function to check if an element and/or its parents position is set to fixed
isPositionFixed = function (selector, traverseAncestors) {
var el = $(selector);
if (el.length) {
if (!traverseAncestors) {
return 'fixed' === el.css('position') ? true : false ;
}
var isFixed = false;
var els = el.add(el.parents());
els.each(function() {
if ('fixed' === $(this).css('position')) {
@farinspace
farinspace / SassMeister-input.scss
Created October 31, 2014 00:32
Generated by SassMeister.com.
// ----
// Sass (v3.4.6)
// Compass (v1.0.1)
// ----
@mixin size($size) {
$height: nth($size, 1);
$width: $height;
@if length($size) > 1 {
$height: nth($size, 2);
<?php
// src: http://www.sajithmr.me/php-time-ago-calculation/
function wpalchemy_time_ago($datefrom,$dateto=-1)
{
// Defaults and assume if 0 is passed in that
// its an error rather than the epoch
if($datefrom<=0) { return "A long time ago"; }
if($dateto==-1) { $dateto = time(); }
<?php
define('_TEMPLATEURL', WP_CONTENT_URL . '/themes/' . basename(TEMPLATEPATH));
include_once 'WPAlchemy/MetaBox.php';
if (is_admin()) wp_enqueue_style('custom_meta_css', _TEMPLATEURL . '/custom/meta.css');
$repeating_mb = new WPAlchemy_MetaBox(array
(
<div class="my_meta_control">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras orci lorem, bibendum in pharetra ac, luctus ut mauris.</p>
<p><a href="#" class="dodelete-docs button">Remove All</a></p>
<?php while($mb->have_fields_and_multi('docs')): ?>
<?php $mb->the_group_open(); ?>
<a href="#" class="dodelete button">Remove</a>
<?php $pages = get_pages(); ?>
<?php while( $mb->have_fields_and_multi( 'buttons' ) ) : ?>
<?php $mb->the_group_open(); ?>
<div class="button">
<a href="#" class="dodelete button">Remove</a>
<?php $mb->the_field('s_field'); ?>
<select name="<?php $mb->the_name(); ?>">
<option></option>
@farinspace
farinspace / repeating_fields.js
Created May 27, 2011 04:49
Repeating fields Javascript
// disable all fields in a template (so they do not get submitted)
$('.template').find('input, textarea, select, button').each(function()
{
$(this).attr('disabled', 'disabled');
});
function doRepeat(replace)
{
var container = $(this).closest('.container');
@farinspace
farinspace / repeating_fields_setup.html
Created May 27, 2011 04:59
Repeating fields Setup
<div class="container">
<div class="collection">
<div class="template" style="display:none;">
<input type="text" name="questions[%][question]" value="qq"/>
<input type="text" name="questions[%][type]" value="qt"/>