Skip to content

Instantly share code, notes, and snippets.

@cdmz
cdmz / event on scroll mouse
Created December 30, 2015 12:57
event on scroll mouse
$('body').on('DOMMouseScroll mousewheel', function (event) {
var $elem = $(this);
event.preventDefault();
if (event.originalEvent.detail > 0 || event.originalEvent.wheelDelta < 0) {
console.log("pra baixo")
}else{
console.log("pra cima")
}
});
@cdmz
cdmz / create-li-a.js
Last active December 7, 2015 13:59
create li a javascript
function add_li_link(label,url,ul_class){
var ul = document.getElementsByClassName(ul_class)[0];
var ul = ul.getElementsByTagName("ul")[0];
var li = document.createElement("li");
var a = document.createElement("a");
a.href = url;
a.appendChild(document.createTextNode(label));
li.appendChild(a);
ul.appendChild(li);
}
@cdmz
cdmz / mobile-detect.php
Created November 16, 2015 17:35
mobile detect php
<?php
function detect_mobile(){
if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i',
$_SERVER['HTTP_USER_AGENT']))
return true;
else
return false;
}
@cdmz
cdmz / mutex.js
Created October 22, 2015 01:11 — forked from oivoodoo/mutex.js
mutex
var Mutex = function() {
this.queues = [];
this.locked = false;
};
Mutex.prototype = {
push: function(callback) {
var self = this;
this.queues.push(callback);
if (!this.locked) {
@cdmz
cdmz / images-display-retina.js
Created October 21, 2015 17:54
images display retina
<img src="http://www.site.com.br/nomedaimagem.png" class="hires">
if (window.devicePixelRatio >= 2) {
var images = $("img.hires");
// loop through the images and make them hi-res
for(var i = 0; i < images.length; i++) {
// create new image name
var imageType = images[i].src.substr(-4);
var imageName = images[i].src.substr(0, images[i].src.length - 4);
imageName += "@2x" + imageType;
//rename image
@cdmz
cdmz / search-post-like-title-wordpress.php
Created October 7, 2015 14:28
search post like title wordpress
<?php
add_filter( 'posts_where', 'like_title', 10, 2 );
function like_title( $where, &$wp_query ) {
global $wpdb;
if ( $title = $wp_query->get( 'title' ) ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( $wpdb->esc_like( $title ) ) . '%\'';
}
return $where;
}
$search_query = array(
@cdmz
cdmz / include-script-wordpress.php
Created October 6, 2015 19:41
include script wordpress
function theme_name_scripts() {
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/main.js', array(), '1.0.0', true );
wp_enqueue_style('main2' , get_template_directory_uri() ."/css/main2.css");
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
@cdmz
cdmz / sort_array_multidim.php
Created October 6, 2015 12:57 — forked from tufanbarisyildirim/sort_array_multidim.php
sort a multidimensional array by sql like order by clause
<?php
/**
* @name Mutlidimensional Array Sorter.
* @author Tufan Barış YILDIRIM
* @link http://www.tufanbarisyildirim.com
* @github http://github.com/tufanbarisyildirim
*
* This function can be used for sorting a multidimensional array by sql like order by clause
*
* @param mixed $array
@cdmz
cdmz / img.php
Last active October 6, 2015 18:52
input img wordpress SEO
<?php
/*
@author Cristiano de Mari
@param Int $ID
@param String $attachment
@param Array $args
@return <img />
*/
function img($ID = NULL, $thumb_size = 'post-thumbnail',$args = NULL ){
@cdmz
cdmz / Comments-for-create-plugin-wordpress.php
Created September 28, 2015 12:36
Comments for create plugin wordpress
/*
* Plugin Name: Nome do plugin
* Plugin URI: http://www.site.com.br/
* Description: Descrição do plugin
* Author: Autor
* Version: 1.0
* Author URI: http://www.autor-site.com.br/
* License:
*/