Skip to content

Instantly share code, notes, and snippets.

@kadavre
kadavre / wp_change_login_logo.php
Created November 11, 2013 11:02
If you are tired of seeing the same old default “log in” logo, then you can change that to display a logo of your choice. To change the logo, you need to create and copy the new custom logo.png image into the image file in your root folder then copy and paste the following code into your functions.php file.
// login page logo
function custom_login_logo() {
echo '<style type="text/css">h1 a { background: url('.get_bloginfo('template_directory').'/companylogo.png) 50% 50% no-repeat !important; }</style>';
}
add_action('login_head', 'custom_login_logo');
@kadavre
kadavre / maintaining_get_between_pages.php
Created December 6, 2013 10:25
Maintaining BET variables between pages with cakephp.
<?php
$this->paginator->options(array(
'url' => $this->request->query,
'convertKeys' => array_keys($this->request->query)
));
@kadavre
kadavre / ajax-promise.js
Created September 21, 2016 10:17
ajax jquery promise
function getAjaxPromise (url) {
return new Promise(function (resolve, reject) {
var xhttp = new XMLHttpRequest();
xhttp.open('GET', url, true);
xhttp.onload = function () {
if (xhttp.status == 200) {
resolve(JSON.parse(xhttp.response));
} else {
reject(xhttp.statusText);
}
(function() {
var results;
this.assert = function assert(value, desc) {
var li = document.createElement("li");
li.className = value ? "pass" : "fail";
li.appendChild(document.createTextNode(desc));
results.appendChild(li);
if (!value) {
li.parentNode.parentNode.className = "fail";
}
var equalizeHeights = function () {
$(".equalizer").each(function(ix, el) {
var heights = $(el).find('.eq-watch').map(function() {
return $(this).height();
}).get();
maxHeight = Math.max.apply(null, heights);
$(el).find('.eq-watch').height(maxHeight);
});
};
// with jQuery
$(document).ready(function(){ /* ... */ });
// shorter jQuery version
$(function(){ /* ... */ });
// without jQuery (doesn't work in older IEs)
document.addEventListener('DOMContentLoaded', function(){
// your code goes here
}, false);
// and here's the trick (works everywhere):
r(function(){
var route = {
_routes : {}, // The routes will be stored here
add : function(url, action){
this._routes[url] = action;
},
run : function(){
jQuery.each(this._routes, function(pattern){
if(location.href.match(pattern)){
// "this" points to the function to be executed
this();
// Old way
console.log($('#elem').length == 1 ? "exists!" : "doesn't exist!");
// The trick:
jQuery.fn.exists = function(){ return this.length > 0; }
console.log($('#elem').exists() ? "exists!" : "doesn't exist!");
// You want to parse this address into parts:
var url = 'http://tutorialzine.com/books/jquery-trickshots?trick=12#comments';
// The trick; create a new link with the url as its href:
var a = $('<a>',{ href: url });
console.log('Host name: ' + a.prop('hostname'));
console.log('Path: ' + a.prop('pathname'));
console.log('Query: ' + a.prop('search'));
console.log('Protocol: ' + a.prop('protocol'));
console.log('Hash: ' + a.prop('hash'));
$('p.descr').attr('unselectable', 'on')
.css('user-select', 'none')
.on('selectstart', false);