Skip to content

Instantly share code, notes, and snippets.

View fael's full-sized avatar

Rafael Santos Sá fael

  • OLX
  • Lisbon, Portugal
View GitHub Profile
@fael
fael / gist:1284764
Created October 13, 2011 16:50
Exemplo de um Revealing Module Pattern
var revealingModulePattern = function() {
var privateVar = 1;
function privateFunction() {
alert('private');
};
var publicVar = 2;
function publicFunction() {
@fael
fael / gist:1250715
Created September 29, 2011 13:20
Exemplo de Plugin em jQuery
jQuery.fn.extend({
reset : function() {
return jQuery(this).filter('form').each(function() {
return this.reset();
}).end();
}
});
$('form').bind('submit', function(e) {
@fael
fael / gist:1234907
Created September 22, 2011 14:29
Drap And Drop Method
//copiei do http://petelepage.com/presentations/2011/gdd-br/webapps/helpers/dnd-lib.js
function habilitarDragAndDrop(id, thumbsId) {
var el_ = document.getElementById(id);
var thumbnails_ = document.getElementById(thumbsId);
this.dragenter = function(e) {
e.stopPropagation();
e.preventDefault();
el_.classList.add('dropHere');
@fael
fael / gist:1217901
Created September 14, 2011 21:51
Load Firebug Lite when sequence "d e b u g" is typed
var hasFirebugLite = false;
runFirebug = function () {
if (!hasFirebugLite) {
$.getScript('https://getfirebug.com/firebug-lite.js', function () {
hasFirebugLite = true;
});
}
}
@fael
fael / gist:1212446
Created September 12, 2011 21:10
Javascript Easter Egg - Konami Code
var kkeys = [],
konami = "38,38,40,40,37,39,37,39,66,65";
easterEgg = function (e) {
kkeys.push(e.keyCode);
if (kkeys.toString().indexOf(konami) == 0) {
var ee = $('<div id="ee">TROLOLOL</div>');
ee.css({
@fael
fael / gist:1212439
Created September 12, 2011 21:09
Prevent event propagation
kill = function (e) {
if (!e) e = window.event;
(e.stopPropagation) ? e.stopPropagation() : e.cancelBubble = true;
(e.preventDefault) ? e.preventDefault() : e.returnValue = false;
return false;
}
@fael
fael / gist:1212432
Created September 12, 2011 21:07
Force scroll when jQuery Dialog is open
function enableScrollbar(event, ui) {
window.setTimeout(function() {
$(document)
.unbind('mousedown.dialog-overlay')
.unbind('mouseup.dialog-overlay');
}, 100);
}
//when calling a dialog, override the open method
$(...).dialog({
@fael
fael / gist:1212424
Created September 12, 2011 21:04
URL Encode/Decode
$.extend({
URLEncode: function (c) {
var o = '';
var x = 0;
c = c.toString();
var r = /(^[a-zA-Z0-9_.]*)/;
while (x < c.length) {
var m = r.exec(c.substr(x));
if (m != null && m.length > 1 && m[1] != '') {
o += m[1];
@fael
fael / gist:1212422
Created September 12, 2011 21:04
Get and format tweets
getTweets = function(alvo, usuario, qtdMensagens){
var o = {}
o.qtdMensagens = qtdMensagens;
o.caixaTwitter = $("#" + alvo);
o.caixaTwitter.append("<li><a href='#'>carregando tweets...</a></li>");
$.jTwitter(usuario, o.qtdMensagens, function(data){
@fael
fael / gist:1212419
Created September 12, 2011 21:03
Some Array Functions
in_array = function(needle, haystack, argStrict) {
// Checks if the given value exists in the array
var found = false,
key, strict = !! argStrict;
for (key in haystack) {
if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
found = true;
break;
}