Skip to content

Instantly share code, notes, and snippets.

View fengelz's full-sized avatar

Sune Fengel fengelz

View GitHub Profile
@fengelz
fengelz / functions.php
Created March 21, 2012 09:31
Get page depth in wordpress
function get_page_depth($post) {
$parent_id = $post->post_parent;
$depth = 0;
while ($parent_id > 0) {
$page = get_page($parent_id);
$parent_id = $page->post_parent;
$depth++;
}
return $depth;
@fengelz
fengelz / gist:6377400
Created August 29, 2013 12:24
Codeigniter htaccess file that remoces index.php and allows resources
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
AddDefaultCharset utf-8
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
@fengelz
fengelz / preventscroll.js
Created August 8, 2013 09:39
Enable/Disable scrolling temporarily when needed window.scrollStopper.disableScroll(); window.scrollStopper.enableScroll();
window.scrollStopper = (function () {
var obj = {}
obj.keys = [
37, 38, 39, 40
];
obj.preventDefault = function (e) {
e = e || window.event;
if (e.preventDefault) {
e.preventDefault();
}
@fengelz
fengelz / frontend.js
Created March 28, 2012 19:55
Wordpress ajax sign in
//Your frontend javascript
var data = {
action: 'sign_in',
username:"<username>",
pass:"<password>"
};
jQuery.post('/wordpress/wp-admin/admin-ajax.php', data,
function(response) {
alert("signed in successfully");
@fengelz
fengelz / functions.php
Created March 21, 2012 10:34
Redirect to first child in wordpress
/*if($post has condition) {
redirect_first_child($post->ID);
}*/
function redirect_first_child($post_id) {
$pagekids = get_pages("child_of=".$post_id."&sort_column=menu_order");
if ($pagekids) {
$firstchild = $pagekids[0];
wp_redirect(get_permalink($firstchild->ID));
exit;
@fengelz
fengelz / Email Validation
Created February 20, 2012 08:58
Javascript email validation. Validated with JSONLint.
var isEmail = function(a){return (/^[\w\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,6})$/i).test(a);};
@fengelz
fengelz / jsprinthtml.js
Created January 25, 2012 12:44
Javascript print html.
function printcontent(content)
{
var mywindow = window.open('', '', '');
mywindow.document.write('<html><title>Print</title><body>');
mywindow.document.write(content);
mywindow.document.write('</body></html>');
mywindow.document.close();
mywindow.print();
return true;
}
@fengelz
fengelz / gethashvalue.js
Created January 19, 2012 08:35
javascript get hash value
var hashval = location.hash.replace('#', '').substring(0, location.hash.indexOf('?')-1);
@fengelz
fengelz / hascanvas.js
Created December 5, 2011 15:06
Detect html canvas with javascript
function hasCanvas()
{
return !!document.createElement('canvas').getContext;
}
@fengelz
fengelz / umbraco404httpmodule.cs
Created November 3, 2011 08:06
404 Http module for umbraco.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using umbraco.BusinessLogic;
using umbraco.NodeFactory;
namespace Web.Modules
{