Skip to content

Instantly share code, notes, and snippets.

View pbojinov's full-sized avatar

Petar Bojinov pbojinov

View GitHub Profile
@pbojinov
pbojinov / tokenizer.js
Last active December 16, 2015 15:09
Tokenizer
String.prototype.shuffle = function(size) {
var arr = this.split('');
for (var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x){};
arr = arr.join('');
return size ? arr.substr(0, Math.min(size, arr.length-1)) : arr;
};
var Tokenizer = {
seed: '1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm',
getToken: function(size) {
@pbojinov
pbojinov / noHover.js
Last active December 17, 2015 08:29
Disable Hover on Scroll based on Unnecessary Paints - http://www.html5rocks.com/en/tutorials/speed/unnecessary-paints/
// Used to track the enabling of hover effects
var enableTimer = 0;
/*
* Listen for a scroll and use that to remove
* the possibility of hover effects
*/
window.addEventListener('scroll', function() {
clearTimeout(enableTimer);
removeHoverClass();
//Able to load a JS file
$.loadJS = function (src) {
var s = document.createElement('script')
s.type = 'text/javascript'
s.async = true
s.src = src
var x = document.getElementsByTagName('script')[0]
x.parentNode.insertBefore(s, x)
}
@pbojinov
pbojinov / class.js
Last active December 17, 2015 22:59
Self executing function (class) with some exposed public function
/**
* If class Petar does not already exist, create a new instance of it
*/
window.Petar = window.Petar || {};
Petar.Music = function() {
var innerContent;
function init() {
@pbojinov
pbojinov / jquery.document.ready.js
Last active August 30, 2018 10:56
document ready extracted from jQuery source
/**
* Minified version
* 1.14KB (377 bytes gzipped)
*
* (function(){var documentIsReady=false;function documentReadyHandler(fn){if(!documentIsReady){documentIsReady=true;if(document.addEventListener)document.removeEventListener("DOMContentLoaded",function(){documentReadyHandler(fn)},false);else if(document.attachEvent)if(document.readyState=="complete")document.detachEvent("onreadystatechange",function(){documentReadyHandler(fn)});fn()}}function documentReady(fn){if(document.addEventListener){document.addEventListener("DOMContentLoaded",function(){documentReadyHandler(fn)},false);window.addEventListener("load",function(){documentReadyHandler(fn)},false)}else if(document.attachEvent){document.attachEvent("onreadystatechange",function(){documentReadyHandler(fn)});window.attachEvent("onload",function(){documentReadyHandler(fn)});var toplevel=false;try{toplevel=window.frameElement==null}catch(e){}if(document.documentElement.doScroll&&toplevel)doScrollCheck(function(){documentReadyHandler(fn)})}}function doSc
var html = (function () {/*
<!DOCTYPE html>
<html>
<body>
<h1>Hello, world!</h1>
</body>
</html>
*/}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1];
/**
* Declaration
*/
(function($) {
$.jPanelMenu = function(options) {
var jpm = {
options: $.extend({
'animated': true,
'duration': 500,
'direction': 'left'
@pbojinov
pbojinov / .htaccess
Created June 5, 2013 04:47
revent automatic directory listing
Options -Indexes
@pbojinov
pbojinov / consoleFix.js
Created June 21, 2013 21:05
Console fix for sad boy IE
/**
* For browsers like IE8 and below so we do not reek havok
*/
if (!('console' in window)) {
function nothing() {}
window.console = {
debug: nothing,
dir: nothing,
error: nothing,
group: nothing,
@pbojinov
pbojinov / toolbelt.js
Last active December 19, 2015 20:18
Extract useful Q.js functions from http://github.com/EGreg/Q.js/blob/master/Q.js
/**
* Add an event listener on an elemnent or array of elements
* @param element DOMNode
* @param eventName String
* @param eventHandler Function
*/
function addEventListener(element, eventName, eventHandler) {
if (typeOf(eventName) === 'array') {
for (var i=0, l=eventName.length; i<l; ++i) {