Skip to content

Instantly share code, notes, and snippets.

View r4fx's full-sized avatar
👋

Rafał Brzeski r4fx

👋
View GitHub Profile
@r4fx
r4fx / $.extend.js
Last active August 29, 2015 14:03
JS $.extend
var defaults = {
radius: 25,
defaultradius: 0,
enableTilt: true,
tilt: 20,
random: true,
randomMax: 25,
colors: ['4AC7ED', 'FDC015', '9F78EC', 'F25C33']
};
@r4fx
r4fx / skiptofileform.js
Last active September 14, 2015 21:01
Scroll to uploaded file after upload in long form
$(function () {
var locationHashObjTop = false;
$('input[type="submit"]').on('click', function () {
var $locationHashObj = $(this).prev();
var locationHash = '#' + $(this).prev().attr('id');
locationHashObjTop = $locationHashObj.offset().top;
sessionStorage.setItem('fileHash', locationHash);
@r4fx
r4fx / getURLParameter.js
Created July 5, 2014 22:03
get URL parameter
/*
* get URL parameter
*/
function GetURLParameter(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
return sParameterName[1];
@r4fx
r4fx / pluginCheck.js
Last active October 13, 2017 08:49
check if plugin is ready
// Check if plugin is ready to call
function checkVendor(vendor, selector, options) {
if (!jQuery()[vendor]) {
console.log('ERROR: obsadź plugin: ' + vendor);
} else {
$(selector)[vendor](options);
}
}
// Example use
@r4fx
r4fx / custom-input-file
Last active August 29, 2015 14:07
Custom input file
$(function () {
$('_btnBrowse').click(function (e) {
e.preventDefault();
$('#inputUpload').click();
});
$('#inputUpload').change(function () {
var filename = $('input[type=file]').val().split('\\').pop();
var setContent = $('.inputFile').html(filename);
});
@r4fx
r4fx / locations.js
Created October 12, 2014 17:30
location, url, hash
location = {
host: "stackoverflow.com",
hostname: "stackoverflow.com",
href: "http://stackoverflow.com/questions/2300771/jquery-domain-get-url",
pathname: "/questions/2300771/jquery-domain-get-url",
port: "",
protocol: "http:"
}
location.host // would be the domain
@r4fx
r4fx / plugin-destroy.js
Last active August 29, 2015 14:07
plugin destroy
// jak przygotowac metode: http://jsfiddle.net/rafx/rtmtkqto/
// http://stackoverflow.com/questions/3502468/unbind-remove-kill-a-jquery-plugin
// przyklad na pluginie Stellar:
// http://stackoverflow.com/questions/12236631/can-stellar-js-readjust-element-offsets-on-window-resize
$(window).data('plugin_stellar').destroy();
$(window).data('plugin_stellar').init();
@r4fx
r4fx / hider.js
Last active August 29, 2015 14:15
Uniwersal hider
// Uniwersal hider
// ============================================================
function hider(targetToHide, trigger) {
$(document).on('mouseup', function (e) {
if (!targetToHide.is(e.target) // if the target of the click isn't the container...
&& targetToHide.has(e.target).length === 0 // ... nor a descendant of the container
&& !trigger.is(e.target)) // ... nor a trigger of the container
{
console.log(targetToHide);
targetToHide.add(trigger).removeClass('active');
@r4fx
r4fx / loadscript.js
Last active August 29, 2015 14:15
Script loader
function loadScript(url, callback) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
// Then bind the event to the callback function.
// There are several events for cross browser compatibility.
script.onreadystatechange = callback;
script.onload = callback;
@r4fx
r4fx / keys-pressed.js
Last active August 29, 2015 14:16
Events on keybord keys
var keys = {};
$(document).keydown(function (e) {
keys[e.which] = true;
showThemeSelector(e);
});
$(document).keyup(function (e) {
delete keys[e.which];