Skip to content

Instantly share code, notes, and snippets.

View chodorowicz's full-sized avatar

Jakub Chodorowicz chodorowicz

View GitHub Profile
@chodorowicz
chodorowicz / walker.php
Created February 21, 2017 20:00
remove li from wp_nav_menu, preserve classes, custom walker
<?php
// based on, fixed warnings http://www.designtoday.info/removing-li-menu-from-wordpress/
class Description_Walker extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
$classes = empty($item->classes) ? array () : (array) $item->classes;
$class_names = join(' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
!empty ( $class_names ) and $class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= "";
$attributes = '';
@chodorowicz
chodorowicz / get_term_level.php
Last active October 1, 2023 01:38
get depth level of current term on taxonomy archive page
<?php
// http://stackoverflow.com/questions/22307013/wordpress-get-current-level-of-taxonomy-in-an-archive-page
function get_tax_level($id, $tax) {
$ancestors = get_ancestors($id, $tax);
return count($ancestors) + 1;
}
$current_term_level = get_tax_level(get_queried_object()->term_id, get_queried_object()->taxonomy);
@chodorowicz
chodorowicz / config.js
Last active July 29, 2021 18:43
react-storybook samples
/**
* dynamically loading all stories with .stories.js extension
*/
import { configure } from '@kadira/storybook';
require('es6-promise').polyfill();
import 'babel-polyfill';
const stories = require.context('../app/js/components', true, /.stories.js$/);
function loadStories() {
@chodorowicz
chodorowicz / analytics-00.js
Last active April 16, 2021 13:48
TypeScript + Google Analytics = ❤️
function initAnalytics() {
(function(i,s,o,g,r,a,m) {i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function() {
(i[r].q=i[r].q ||[]).push(arguments);},i[r].l= 1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m);
})(window, document, "script", "//www.google-analytics.com/analytics.js", "ga");
ga("create", "UA-XXXXXXXX-X", "auto");
ga("send", "pageview");
}
@chodorowicz
chodorowicz / toggle.js
Last active February 15, 2021 21:23
lodash toggle array element
/**
* descructive
* https://github.com/lodash/lodash/issues/1677
*/
function toggle(collection, item) {
var idx = _.indexOf(collection, item);
if(idx !== -1) {
collection.splice(idx, 1);
} else {
collection.push(item);
@chodorowicz
chodorowicz / serialize.js
Created June 14, 2016 11:39
jQuery serialize form using serializeArray
function serializeForm($form) {
return $form.serializeArray().reduce( (result, input) => {
result[input.name] = input.value;
return result;
}, {}
);
}
@chodorowicz
chodorowicz / main.js
Created July 15, 2015 12:20
photoswipe disable zoom
{
zoomEl: false,
maxSpreadZoom: 1,
getDoubleTapZoom: function(isMouseClick, item) {
return item.initialZoomLevel;
}
pinchToClose: false
}
@chodorowicz
chodorowicz / browsersync.js
Last active September 1, 2018 14:27
BrowserSync custom host domain + snippet options
const browserSync = require('browser-sync').create();
const port = process.env.PORT || 8080;
const customDomain = environment.DEV_DOMAIN ? `${environment.DEV_DOMAIN}` : 'localhost';
browserSync.init('**/*.css', {
logPrefix: 'Showroom:',
proxy: `localhost:${port}`,
open: false,
host: customDomain,
port: 3000,
ghostMode: false, /* don't mirror interactions in other browsers */
@chodorowicz
chodorowicz / hoc.js
Last active July 18, 2018 16:26
React HOC example
/** base form */
import React, { Component } from 'react';
export default function(InnerComponent) {
class WrapperComponent extends Component {
render() {
return <InnerComponent {...this.props} />
}
}
}
@chodorowicz
chodorowicz / gulpfile.js
Last active November 22, 2017 10:41
simple gulpfile with stylus, browser sync,
// this method is currently broken
// better use vinyl-source-stream method
// http://fettblog.eu/gulp-browserify-multiple-bundles/
const gulp = require('gulp');
const browserify = require('browserify');
const transform = require('vinyl-transform');
const browserSync = require('browser-sync');
const reload = browserSync.reload;
const gutil = require('gulp-util');