Skip to content

Instantly share code, notes, and snippets.

Drupal.settings.isTouchDevice = function() {
return "ontouchstart" in window;
}
if ( Drupal.settings.isTouchDevice() ) {
Drupal.behaviors.jQueryMobileSlideShowTouchAdvance = {
attach: function(context, settings) {
self = Drupal.behaviors.jQueryMobileSlideShowTouchAdvance;
jQuery.each(jQuery(".views_slideshow_cycle_main.viewsSlideshowCycle-processed"), function(idx, value) {
value.addEventListener("touchstart", self.handleTouchStart);
@sardbaba
sardbaba / WP-Widget_Language_Chooser
Created May 2, 2014 12:57
Wordpress - A textual language chooser widget compatible with qTranslate and qTranslate-slug
/**
* A textual language chooser widget compatible with qTranslate and qTranslate-slug
* Author: Mauro Mascia
* License: WTFPL (www.wtfpl.net)
*/
class Widget_Language_Chooser extends WP_Widget {
function __construct() {
parent::__construct(
'widget_language_chooser',
@sardbaba
sardbaba / jquery-outer.js
Last active August 29, 2015 14:01 — forked from tlync/jquery-outer.js
Setter for jQuery outerWidth/outerHeight, in a compact version
/** Get or set the current outer width/height for the first element in the set of matched elements. */
var origOuterWidth = $.fn.outerWidth;
$.fn.outerWidth = function(){
var value = arguments[0];
if (arguments.length === 0 || typeof value === 'boolean') { return origOuterWidth.apply(this, arguments); }
else if (typeof value !== 'number') { throw new Error('Invalid argument. The new outerWidth value must be an integer.'); }
var css = ['borderLeftWidth','borderRightWidth','paddingLeft','paddingRight'];
if (arguments[1] === true) { css.push('marginLeft'); css.push('marginRight'); }
var $el = $(this), exclude = 0, parse = parseFloat;
for (var i=0; i<css.length; i++) { exclude += parse($el.css(css[i])); }
@sardbaba
sardbaba / backup_all_dbs.sh
Created November 18, 2012 20:35
Backup All DB's and transfer to S3 with s3cmd + Rolling on the days of the weeks and on the weeks of the months + a montly backup (for paranoiac guys)
#!/bin/bash
BACKUP_DIR="~/db_backups"
DBUSER=""
DBPASSWORD=""
BUCKET="your-unique-bucket-name"
FROM='"Backups" <backups@localhost>'
TO='"Admin" <admin@localhost>'
SUBJECT='Backup Log'
@sardbaba
sardbaba / drupal-template.php
Last active October 13, 2015 10:27
Drupal | Omega | Transform the main menu into a select to be used into small screen sizes.
// see also https://gist.github.com/3201854
function mytheme_menu_tree__main_menu($variables) {
return '<select class="mobile-main-menu" onchange="location = this.options[this.selectedIndex].value;">'
. $variables['tree'] . '</select>';
}
function mytheme_menu_link__main_menu($variables) {
global $base_url;
$e = $variables['element'];
@sardbaba
sardbaba / functions.php
Last active October 24, 2015 14:21
Wordpress - Bulk change products status
/**
* Aggiungo una notice nella pagina dei prodotti con due bottoni:
* uno per nascondere (mettere in bozza), l'altro per pubblicare tutti i prodotti.
*/
add_action( "admin_notices", function() {
// Verifico che sia la pagina corretta
$screen = get_current_screen();
if ( 'edit-product' != $screen->id ) return;
$_wpnonce = wp_create_nonce('la_mia_stringa_di_sicurezza');
@sardbaba
sardbaba / functions.php
Last active December 4, 2015 17:59 — forked from kloon/functions.php
<?php
// Add a date range to a datepicker field, replace #date with the id of the date field.
add_filter( 'wp_footer' , 'woo_add_checkout_field_date_range_limit' );
function woo_add_checkout_field_date_range_limit() {
if ( is_checkout() ) {
$js = 'jQuery( "#date" ).datepicker({ minDate: -5, maxDate: "+1M +10D" });';
// Check if WC 2.1+
if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
wc_enqueue_js( $js );
} else {
@sardbaba
sardbaba / jquery.center.js
Created December 11, 2015 17:46
jQuery plugin for centering vertically and/or horizontally
(function( $ ) {
$.fn.vcenter = function () {
this.css("position","absolute");
this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + $(window).scrollTop()) + "px");
return this;
}
$.fn.hcenter = function () {
this.css("position","absolute");
this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + $(window).scrollLeft()) + "px");
return this;
@sardbaba
sardbaba / wordpress-function.php
Last active December 14, 2015 18:29
qtrans_generate_language_list() is a better version of the qtrans_generateLanguageSelectCode() function from qTranslate's Wordpress plugin, originally used to print the languages as an HTML select. This function receive an optional string for the separator that will be echoed and it is able to show your languages as spans followed by separators:…
/**
* Language list Code for non-Widget users
*
* @global array $q_config
* @param string $sep
*/
function qtrans_generate_language_list($sep = " | ") {
global $q_config;
$languages = qtrans_getSortedLanguages();
$num_langs = count($languages);
@sardbaba
sardbaba / wordpress-function.php
Last active December 17, 2015 08:09
Hide Standard Shipping option when free shipping is available
/**
* Hide Standard Shipping option when free shipping is available
*
* @param array $available_methods
*/
function sardbaba_hide_standard_shipping_when_free_is_available($available_methods) {
if (isset($available_methods['free_shipping']) AND isset($available_methods['flat_rate'])) {
// remove standard shipping option
unset($available_methods['flat_rate']);
}