Skip to content

Instantly share code, notes, and snippets.

View gist:11078290
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
Wordpress - A textual language chooser widget compatible with qTranslate and qTranslate-slug
View WP-Widget_Language_Chooser
/**
* 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 Aug 29, 2015 — forked from tlync/jquery-outer.js
Setter for jQuery outerWidth/outerHeight, in a compact version
View jquery-outer.js
/** 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 Nov 18, 2012
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)
View backup_all_dbs.sh
#!/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 Oct 13, 2015
Drupal | Omega | Transform the main menu into a select to be used into small screen sizes.
View drupal-template.php
// 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 Oct 24, 2015
Wordpress - Bulk change products status
View functions.php
/**
* 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');
View 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 Dec 11, 2015
jQuery plugin for centering vertically and/or horizontally
View jquery.center.js
(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 Dec 14, 2015
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:…
View wordpress-function.php
/**
* 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 Dec 17, 2015
Hide Standard Shipping option when free shipping is available
View wordpress-function.php
/**
* 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']);
}
You can’t perform that action at this time.