Skip to content

Instantly share code, notes, and snippets.

@bruno-barros
bruno-barros / jQuery Boilerplate
Created October 29, 2012 03:22
JS: jQuery Boilerplate
;(function ( $, window, undefined ) {
// undefined is used here as the undefined global variable in ECMAScript 3 is
// mutable (ie. it can be changed by someone else). undefined isn't really being
// passed in so we can ensure the value of it is truly undefined. In ES5, undefined
// can no longer be modified.
// window and document are passed through as local variables rather than globals
// as this (slightly) quickens the resolution process and can be more efficiently
// minified (especially when both are regularly referenced in your plugin).
@bruno-barros
bruno-barros / JS replaceAll
Last active February 28, 2022 02:40
JS: replaceAll
/**
* substitui strings >> replaceAll(str, '.', ':');
* @param string : string utilizada
* @param token : termo buscado
* @param newtoken : termo irá substituir
*/
function replaceAll(string, token, newtoken) {
while (string.indexOf(token) != -1) {
string = string.replace(token, newtoken);
}
@bruno-barros
bruno-barros / functions.js
Created October 29, 2012 12:34
JS: popula cidades 'meucms'
/**
* POPULA COMBOBOX CIDADES
* @param UF : string do estado 'RJ'
* @param CIDID : ID da cidade
* @param obj_target : ID do select da cidade
* Ex: <input type="text" name="cep" id="cep" data-uf-id="uf" data-cidade-id="cidade" data-bairro-id="bairro" data-logradouro-id="logradouro" />
*/
function populaCidades(UF, CIDID, obj_target) {
myAj = $.ajax({
type: "POST",
@bruno-barros
bruno-barros / access another database from Wordpress
Created February 14, 2014 22:52
access another database from Wordpress
$newdb = new wpdb('root', '', 'sig001', 'localhost');
$l = $newdb->get_results("SELECT * FROM sig_contents WHERE content_type = 'sigsystem' ORDER BY title");
d($newdb->show_errors());
if($l){
foreach($l as $r){
d($r->title);
}
}
angular.module('myMdl', []).config(['$httpProvider', function($httpProvider) {
$httpProvider.responseInterceptors.push([
'$q', '$templateCache', 'activeProfile',
function($q, $templateCache, activeProfile) {
// Keep track which HTML templates have already been modified.
var modifiedTemplates = {};
// Tests if there are any keep/omit attributes.
var HAS_FLAGS_EXP = /data-(keep|omit)/;
@bruno-barros
bruno-barros / keep git repos synced
Last active August 29, 2015 14:10
keep git repos synced
# fork and clone
git clone <repo name>
# keep synk with remote origin
git remote add origin https://<repo name>
# fetch updates from upstream
git checkout master
git fetch upstream
git merge upstream/master
@bruno-barros
bruno-barros / wordpress-ajax.js
Created January 16, 2015 00:18
WordPress AJAX object
/**
* Ajax.send();
*
* Usage: Ajax.send('my-handler', {"data": "value"}, ajaxurl).then(function(response){ //... });
*
* Ajax handler to send messages to WordPress AJAX API
*/
(function ($, window, document, undefined) {
window.Ajax = (function () {
@bruno-barros
bruno-barros / WelAjaxForm
Last active December 12, 2015 02:57
jQuery plugin to send ajax request using library Ajax (https://gist.github.com/bruno-barros/98db76c8d777caa3c414)
/**
* WelAjaxForm
*
* Example:
* $('.news-signin').WelAjaxForm({
action: 'form_newsletter_signin', // string | false
fields: [
{'name' : {'selector': '#field_name_ft', validation: 'required'}},
{'email' : {'selector': '#field_email_ft', validation: 'required'}}
],
html {
font-size: calc(12px + 9 * ( (100vw - 420px) / 860));
}
@media screen and (max-width: 420px) {
html {
font-size: 12px;
}
}
@bruno-barros
bruno-barros / acf-map.php
Created October 13, 2015 03:46 — forked from nmyers/acf-map.php
ACF Static google map with link
<?php
$location = get_field('location');
if( !empty($location) ):
?>
<a href="http://www.google.com/maps/preview#!q=<?=urlencode( $location['address'] )?>">
<img src="http://maps.googleapis.com/maps/api/staticmap?center=<?php echo $location['lat']; ?>,<?php echo $location['lng']; ?>&zoom=15&format=png&sensor=false&size=397x297&maptype=roadmap&visual_refresh=true&style=visibility:off&style=feature:road|element:geometry|visibility:simplified&style=feature:landscape|element:geometry|visibility:simplified&style=element:labels|visibility:on&markers=color:red|<?php echo $location['lat']; ?>,<?php echo $location['lng']; ?>"/>
</a>
<?php endif; ?>