Skip to content

Instantly share code, notes, and snippets.

View r4fx's full-sized avatar
👋

Rafał Brzeski r4fx

👋
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / $.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']
};