Skip to content

Instantly share code, notes, and snippets.

View wernerkrauss's full-sized avatar

Werner Krauß wernerkrauss

View GitHub Profile
@svandragt
svandragt / DateRange.php
Created February 25, 2014 14:16
DateRange class: Quickly find overlaps with other date ranges
<?php
/**
* Class to make it easier to compare date ranges (where range is between start date and end date)
*/
class DateRange {
public $StartDate = null;
public $EndDate = null;
/**
@lozcalver
lozcalver / gist:5848538
Created June 24, 2013 08:20
'No alignment' option for images. Only tested on 3.0, though I imagine it would work on 3.1 fine. Apply with Object::add_extension('HtmlEditorField_Toolbar', 'HtmlEditorField_ToolbarExtension');
<?php
/**
* Add 'no alignment' option when inserting images through 'Insert Media' form
*/
class HtmlEditorField_ToolbarExtension extends Extension {
public function updateFieldsForImage(&$fields, $url, $file) {
$className = $fields->fieldByName('CSSClass');
$classes = $className->getSource();
$classes = array_merge(array('' => _t('HtmlEditorField.CSSCLASSNONE', 'No alignment.')), $classes);
@havvg
havvg / ajax-form.js
Created August 1, 2012 13:20
jQuery AJAX form submit with Twitter Bootstrap modal
jQuery(function($) {
$('form[data-async]').live('submit', function(event) {
var $form = $(this);
var $target = $($form.attr('data-target'));
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
@wilr
wilr / ResampleUpload.php
Created April 4, 2012 05:33
An extension for resampling SilverStripe images on upload.
<?php
/**
* An extension to SilverStripes inbuilt {@link Image} class to handle resizing
* large images on upload either through the backend interface or through upload
* forms.
*
* File is resized to a copy, then the original is deleted and the smaller image
* moved back.
*