Skip to content

Instantly share code, notes, and snippets.

View tux255's full-sized avatar

Andrii Haranin tux255

  • Kyiv
  • 16:03 (UTC -12:00)
View GitHub Profile
function setSameHeight(array){
var list = '',
max = '',
children = [];
for (i = 0; i < array.length; i++) {
doMagic(array[i])
}
function doMagic(string) {
function vCenter() {
var def = '.vcenter',
target = '',
targetHeight = '',
marg = '',
parentHeight = '';
var target = document.querySelectorAll(def);
for (var i = 0; i < target.length; i++) {
parentHeight = parseInt(
@tux255
tux255 / functions.php
Last active May 30, 2016 08:45
Adds "level-#" class to Wordpress menu.
<?php
add_filter('wp_nav_menu_objects' , 'my_menu_class');
function my_menu_class($menu) {
$level = 0;
$stack = array('0');
foreach($menu as $key => $item) {
while($item->menu_item_parent != array_pop($stack)) {
$level--;
}
$level++;
//DEEPNESS OF SCROLL
document.addEventListener("DOMContentLoaded", function(event) {
//DEEPNESS OF SCROLL
var switcher = [],
maxScroll = 0,
result = 0,
currentScroll = 0,
scrollPosition = 0;
var getPosition = function(){
@tux255
tux255 / wpcf7-w3tc-fix-ajax.php
Created October 4, 2016 11:46
Hack Contact Form 7 to avoid unwanted ajax calls
// Hack Contact Form 7 to avoid unwanted ajax calls
// see http://stackoverflow.com/questions/19632244/is-w3-total-cache-compatible-with-contact-form-7
add_action('wpcf7_enqueue_scripts', 'hack_cf7');
function hack_cf7() {
$_wpcf7 = array(
'loaderUrl' => wpcf7_ajax_loader(),
'sending' => __( 'Sending ...', 'contact-form-7' )
);
wp_localize_script( 'contact-form-7', '_wpcf7', $_wpcf7 );
}
@tux255
tux255 / OpenCart 2.x .ocmod.xml template
Last active December 13, 2016 13:43
OpenCart 2.x .ocmod.xml template
<?xml version="1.0" encoding="utf-8"?>
<modification>
<code>00001</code>
<name>Modification</name>
<version>1.0</version>
<author>Author Name</author>
<link>http://www.author.com</link>
<file path="catalog/controller/common/home.php">
<operation>
<search><![CDATA[
@tux255
tux255 / snippet.php
Created November 24, 2016 13:39
Wordpress snippet to filter Editor image adding
<?php
function html5_insert_image($html, $id, $caption, $title, $align, $url) {
$html5 = "<figure id='post-$id media-$id' class='align-$align'>";
$html5 .= "<img src='' data-src='$url' alt='$title' />";
if ($caption) {
$html5 .= "<figcaption>$caption</figcaption>";
}
$html5 .= "</figure>";
return $html5;
}
@tux255
tux255 / suicidal-filter.php
Created December 8, 2016 09:54 — forked from markjaquith/suicidal-filter.php
Version of `add_filter()` for WordPress that only runs once
<?php
/*
Use this just like `add_filter()`, and then run something that calls the filter (like
`new WP_Query`, maybe).
That's it. If the filter gets called again, your callback will not be.
This works around the common "filter sandwich" pattern where you have to remember to
call `remove_filter` again after your call.
@tux255
tux255 / Good Opencart config.php example
Created January 11, 2017 19:49
Good example of Opencart config.php
<?php
// HTTP
define('HTTP_SERVER', 'http://' . $_SERVER['HTTP_HOST'] . '/admin/');
define('HTTP_CATALOG', 'http://' . $_SERVER['HTTP_HOST'] . '/');
// HTTPS
define('HTTPS_SERVER', 'http://' . $_SERVER['HTTP_HOST'] . '/admin/');
define('HTTPS_CATALOG', 'http://' . $_SERVER['HTTP_HOST'] . '/');
@tux255
tux255 / serializeObject.js
Created February 7, 2017 09:01
Serialize form data to JSON prototype
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');