Skip to content

Instantly share code, notes, and snippets.

View celsofabri's full-sized avatar
👾
The truth is dubious

Celso Fabri Junior celsofabri

👾
The truth is dubious
View GitHub Profile
@celsofabri
celsofabri / mobile-detect.js
Created September 14, 2015 18:08
Identifica dispositivo mobile
$(function(){
function device_detect() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)){
alert('Seu dispositivo mobile foi detectado');
@celsofabri
celsofabri / return-string.php
Created February 24, 2015 19:20
Returns hum summary for any rope word / Retorna um resumo de qualquer string por palavra
/**
* Retorna um resumo de qualquer string por palavra
* @param string $string A string que será cortada
* @param int $max O número máximo de palavras
* @return string A string cortada
* By Cezinha <3
*/
function resumo($string, $max, $final = '...') {
$string = explode(' ', trim($string));
@celsofabri
celsofabri / words_limit.php
Created January 26, 2015 16:03
Excerpt or Content Word Limit in WordPress / Resumo ou Conteúdo com limite de palavras WordPress
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
@celsofabri
celsofabri / add-remove-class.js
Created December 16, 2014 19:47
Add and Remove Class with Javascript / Adicionar e Remover Classe com Javascript
var variavel = document.querySelector('.title-main');
variavel.addEventListener('click', function() {
if(variavel.classList.contains('classe')) {
this.classList.remove('classe');
}
else {
this.classList.add('classe');
@celsofabri
celsofabri / page-slug-body-class.php
Created December 15, 2014 12:21
Page Slug Body Class / Slug da página como classe
<?php
// Page Slug Body Class
function add_slug_body_class( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
return $classes;
}
@celsofabri
celsofabri / scroll_top.js
Created December 15, 2014 12:17
Scroll Top / Voltar ao Topo
// Voltar ao Topo
$('.vr').on('click', function () {
$('body, html').animate({
scrollTop: 0
});
return false;
@celsofabri
celsofabri / menu_scrolling.js
Last active August 29, 2015 14:11
Menu Scrolling
// Menu Scrolling
$('.menu-list').find('li a').on('click', function () {
var self = $(this),
parent = self.parent(),
index = parent.index();
$('body, html').animate({
scrollTop: $('.section-block').eq(index).offset().top
});
@celsofabri
celsofabri / change_url-hash-scroll.js
Created December 5, 2014 13:48
Change URL Hash on Scroll / Mudar URL Hash ao deslizar
// Change URL Hash on Scroll =======================================
$(document).bind('scroll',function(e){
$('.section-block').each(function(){
if ( $(this).offset().top < window.pageYOffset + 10 && $(this).offset().top + $(this).height() > window.pageYOffset + 10) {
window.location.hash = $(this).attr('id');
}
});
});
@celsofabri
celsofabri / refresh_url-hash.js
Created December 5, 2014 13:47
Refresh Page without URL Hash / Atualizar Página sem URL Hash
// Refresh Page without URL Hash =======================================
var loc = window.location.href,
index = loc.indexOf('#');
if (index > 5000) {
window.location = loc.substring(0, index);
}
@celsofabri
celsofabri / ng-tasks.html
Created December 4, 2014 13:06
Add tasks with Angular JS / Adicionando tarefas com Angular JS
<html ng-app="NgApp">
<head>
<title>Add tasks with Angular JS / Adicionando tarefas com Angular JS</title>
</head>
<body>
<div ng-controller="TasksController">