Skip to content

Instantly share code, notes, and snippets.

@Phoenix2k
Phoenix2k / gist:7980936
Created December 16, 2013 01:12
Convert RGB(A) values to #hexdecimal using jQuery.css()
// Convert RGB(A) values to #hexdecimal using jQuery.css()
// Original: http://jsfiddle.net/DCaQb/
// Note: This will not work on browsers which return 'color names' instead of rgb(a) values (i.e. IE8)
function rgba2hex( color_value ) {
if ( ! color_value ) return false;
var parts = color_value.toLowerCase().match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/),
length = color_value.indexOf('rgba') ? 3 : 2; // Fix for alpha values
delete(parts[0]);
for ( var i = 1; i <= length; i++ ) {
parts[i] = parseInt( parts[i] ).toString(16);
@Phoenix2k
Phoenix2k / svg.js
Last active February 12, 2017 10:16
Check for SVG support without Modernizr or jQuery
/**
* Check for SVG support (modified to support data-src attribute)
* Source: http://www.prosoxi.com/2013/04/24/svg-replace-using-modernizr/
*
* Usage (CSS):
* .svg .element { background-image: url('image.svg'); }
* .no-svg .element { background-image: url('image.png'); }
*
* Usage (HTML):
* <img src="image.svg" data-src="image.png" alt="" />
@Phoenix2k
Phoenix2k / admin.php
Last active June 27, 2023 17:40
WordPress Gists
<?php
/**
* Adds support for `admin.css` (with child-theme support)
*
* You can use this to style anything from edit buttons on the frontend
* to customizing your admin screen for logged in users
*
* @link http://codex.wordpress.org/Function_Reference/wp_enqueue_script
*/
add_action( 'admin_enqueue_scripts', 'theme_admin_styles' );
@Phoenix2k
Phoenix2k / update_debian.sh
Last active September 23, 2018 18:16
Update scripts
#!/bin/bash
bold=`tput bold`
normal=`tput sgr0`
clear
printf "Updating ${bold}Debian packages${normal}...\n";
sudo aptitude update && sudo aptitude full-upgrade
@Phoenix2k
Phoenix2k / header.php
Last active August 29, 2015 14:20
WordPress tags to enable styling languages via CSS
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
...
@Phoenix2k
Phoenix2k / functions.php
Last active December 10, 2016 22:39
WordPress: Method for passing localized strings via wp_localize_script() to an external .js file
<?php
/**
* Localize strings for JavaScripts
*
* @link https://codex.wordpress.org/Function_Reference/wp_localize_script
*/
// Enqueue the script which will use the localized strings
wp_enqueue_script( 'name-of-your-script', '/js/yourscript.js' );
// Define an array of data to be passed on to your JavaScript file
@Phoenix2k
Phoenix2k / footer.php
Last active September 5, 2019 16:03
WPML: Create transient menus with JS support
@Phoenix2k
Phoenix2k / location.js
Last active October 10, 2016 09:42
JavaScript: Obtain a user's location using Geolocation API
/**
* Obtain a user's location
*
* @see https://developers.google.com/web/fundamentals/native-hardware/user-location/obtain-location
* @return { object } Location data
*/
window.onload = function() {
var startPos;
var geoOptions = { enableHighAccuracy : true };
@Phoenix2k
Phoenix2k / distance_between.js
Last active February 27, 2023 19:07
JavaScript: Distance between two coordinates
/**
* Distance between two coordinates
*
* @author Salvador Dali
*
* @param { number } lat_1 - Latitude of first point
* @param { number } lon_1 - Longitude of first point
* @param { number } lat_2 - Latitude of second point
* @param { number } lon_2 - Longitude of second point
*
@Phoenix2k
Phoenix2k / override_link_attributes.php
Last active October 7, 2016 23:15
WordPress: Nav menu hacks