Skip to content

Instantly share code, notes, and snippets.

@lutzissler
lutzissler / function.tidy_office_html.php
Created July 31, 2012 07:32
Tidy HTML inserted by copy/pasting from Microsoft office (PHP)
// Regexps courtesy of 1st class media
// http://www.1stclassmedia.co.uk/developers/clean-ms-word-formatting.php
function tidy_office_html($str) {
$replacements = array(
'/<!--.*?-->/s' => '',
'/<o:p>\s*<\/o:p>/s' => '',
'/<o:p>.*?<\/o:p>/s' => "&nbsp;",
'/\s*mso-[^:]+:[^;"]+;?/i' => '',
'/\s*MARGIN: 0cm 0cm 0pt\s*;/i' => '',
'/\s*MARGIN: 0cm 0cm 0pt\s*"/i' => '',
@lutzissler
lutzissler / jquery.wrapgroups.js
Last active October 12, 2015 18:58
Wrap groups of matched elements (jQuery)
(function ($) {
// From http://forloop.co.uk/blog/wrap-child-elements-in-groups-in-jquery
// Modified to work much simpler
$.fn.wrapGroups = function(options) {
options = $.extend({
groupSize : false,
groupCount: false,
wrapper : '<div>'
}, options || {});
var elems = $(this),
@lutzissler
lutzissler / jquery.flash.js
Created June 3, 2013 09:58
Flash/blink elements by fading in/out. Use it with care!
$.fn.flash = function (options) {
options = $.extend({
animation: 200,
off: 0,
on: 1000
}, options || {});
var elems = $(this),
f = function () {
elems
.animate({opacity: 0}, options.animation)
@lutzissler
lutzissler / close_all_files.sublime-keymap
Created June 3, 2013 11:33
Sublime Text 2 key binding for "File > Close All Files", bound to Ctrl+Cmd+W.
[
{ "keys": ["super+ctrl+w"], "command": "close_all", "args": {} }
]
@lutzissler
lutzissler / jquery.fittext.js
Last active December 18, 2015 16:59
Shorten text to fit into a container.
(function ($) {
$.fn.fitText = function(options) {
var els = $(this),
options = $.extend({
ellipsis : "..."
}, options || {});
els.each(function () {
var el = $(this),
h = el.height(),
@lutzissler
lutzissler / jquery.findAndSelf.js
Created August 6, 2013 07:30
Filter() and find() combined.
// From http://forum.jquery.com/topic/jquery-jquery-way-for-filtering-self-all-children
$.fn.findAndSelf = function(selector) {
return this.find(selector).andSelf().filter(selector);
}
@lutzissler
lutzissler / func.listify.php
Created August 7, 2013 09:26
Smarty function to convert a list of arguments into a delimited output. Usage: {", "|listify:"Item 1":"Item 2":"Item 3"}
function listify($delimiter) {
return implode($delimiter, array_filter(array_slice(func_get_args(), 1)));
}
@lutzissler
lutzissler / func.curl_file_get_contents.php
Created August 8, 2013 16:05
file_get_contents() replacement if HTTP fopen wrappers are not working.
// Grabbed from http://de3.php.net/manual/de/function.file-get-contents.php
function curl_file_get_contents($URL) {
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, str_replace(' ', '%20', $URL));
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
@lutzissler
lutzissler / jquery.layoutchanged.css
Created September 13, 2013 10:26
Watch responsive layout changes with the help of an additional element in the body and an appropriate color setting.
@media screen and (min-width: ...) {
// Adjust the breakpoint identifier so that jQuery knows about it
#bp {
color: rgb(1, 1, 1);
}
}
@media screen and (min-width: ...) {
// Adjust the breakpoint identifier so that jQuery knows about it
#bp {
$.fn.reduce = function(fnReduce, initialValue) {
var values = this,
previousValue = initialValue;
values.each(function(index, currentValue) {
previousValue = fnReduce.call(currentValue, previousValue, currentValue, index, values);
});
return previousValue;
};