Skip to content

Instantly share code, notes, and snippets.

View croxton's full-sized avatar
💭
Up to my elbows, as usual

Mark Croxton croxton

💭
Up to my elbows, as usual
View GitHub Profile
@croxton
croxton / stash_save_pref.md
Last active April 8, 2018 02:23
Saving user preferences with Stash + jQuery

Create a template such as site/save_preference with the following code - adjust the regex to suit your needs:

{exp:switchee variable="{segment_3}" parse="inward"}
	{!-- allow an alphanumeric name (and - or _) for the preference key only --}
	{case value="#^[a-zA-Z0-9-_]+$#"}
		{!-- allow a numeric value only --}
		{exp:stash:set name="{segment_3}" type="snippet" save="yes" scope="user" match="#^[0-9]+$#"}{segment_4}{/exp:stash:set}
	{/case}
{/exp:switchee}
@croxton
croxton / circle.svg
Last active September 10, 2024 05:57
Passing parameters to a SVG when used as an object, while still being able to use as an image.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@croxton
croxton / gist:7153533
Last active April 8, 2018 02:24
Spoofing the session
// Pretend to be a SuperAdmin.
// Don't really do this, setup a member group and account with the minimum permissions needed
$this->EE->session->userdata['group_id'] = 1;
$this->EE->session->userdata['member_id'] = 1;
$this->EE->session->userdata['can_delete_self_entries'] = 'y';
$this->EE->session->userdata['can_delete_all_entries'] = 'y';
@croxton
croxton / mod.my_module.php
Last active April 8, 2018 02:24
Loading a specific language file for a 3rd party add-on module
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class My_module {
protected $class_name;
function __construct()
{
$this->class_name = strtolower(__CLASS__);
@croxton
croxton / leaflet_custom_zoom_levels.js
Last active May 20, 2022 16:13
Leaflet custom zoom levels
/*
Most map tile providers use 256px square tiles so Leaflet's basic zoom algorithm looks like this:
256 * Math.pow(2, zoom);
If you're working with vector layers you can extend one of leaflet's default CRSs
and make it return tile sizes in smaller increments. This can be very helpful when using
fitBounds() with layer groups, so the zoomed group fits better within the map bounds:
E.g., extending L.CRS.EPSG3857 (the default CRS):
@croxton
croxton / entries_archive.md
Last active April 8, 2018 01:30
Sort a list of entries by year and then by month
	{exp:stash:set_list name="entries" parse_tags="yes"}
		{exp:channel:entries channel="my_channel" orderby="date" sort="desc" dynamic="no" limit="999"}
		    {stash:title}{title}{/stash:title}
		    {stash:date_day}{entry_date format="%d"}{/stash:date_day}
		    {stash:date_month}{entry_date format="%m"}{/stash:date_month}
		    {stash:date_year}{entry_date format="%Y"}{/stash:date_year}
		    {stash:date_sort}{entry_date format="%Y-%F"}{/stash:date_sort}
		    {stash:date_machine}{entry_date}{/stash:date_machine}
		{/exp:channel:entries}

{/exp:stash:set_list}

@croxton
croxton / Semantic responsive grids with CSS Crush.css
Last active April 8, 2018 01:29
Semantic resposive grids with CSS Crush
/* =============================================================================
Variables
========================================================================== */
@define {
grid-gutter: 30px;
small: min-width:36em;
medium: min-width:48em;
large: min-width:62.5em;
xlarge: min-width:75em;
@croxton
croxton / gist:5965737
Created July 10, 2013 12:04
jquery offset() problem
$('.scroll').click(function() {
var $target = $(this.hash);
if ($target.length && $target.html()!=undefined) {
var targetOffset = $target.offset().top;
$('html, body').animate({scrollTop: targetOffset}, 600);
}
return false;
@croxton
croxton / header--patch.php
Last active May 31, 2016 20:43
If your clients use IE, do them and yourself a favour and disable the compatibility button in the Control Panel by editing ./system/expressionengine/views/_shared/header.php Why? Because many popular fieldtypes break the publish screen with the compatibility button pressed.
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

##The problem:

When trying to cache a Stash embed or other post-processed Stash tag, ce_cache is caching only the placeholder for the post-processed tag.

http://devot-ee.com/add-ons/support/ce-cache/viewthread/9155

##Solution 1

Use process="start" or process="inline" instead, so the embed/tag is not post-processed: