/* From http://blog.stevenlevithan.com/archives/faster-trim-javascript */ function trim (str) { var str = str.replace(/^\s\s*/, ''), ws = /\s/, i = str.length; while (ws.test(str.charAt(--i))); return str.slice(0, i + 1); } /* Właściwa część helpera */ /* * Function urlencode and http_build_query from phpjs; * More info: http://phpjs.org/pages/license */ var url = { encode: function (str) { str = (str+'').toString(); // Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current // PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following. return encodeURIComponent(str) .replace(/!/g, '%21') .replace(/'/g, '%27') .replace(/\(/g, '%28') .replace(/\)/g, '%29') .replace(/\*/g, '%2A') .replace(/%20/g, '+'); }, http_build_query: function (formdata, numeric_prefix, arg_separator) { var value, key, tmp = []; var _http_build_query_helper = function (key, val, arg_separator) { var k, tmp = []; if (val === true) { val = "1"; } else if (val === false) { val = "0"; } if (val !== null && typeof(val) === "object") { for (k in val) { if (val[k] !== null) { tmp.push(_http_build_query_helper(key + "[" + k + "]", val[k], arg_separator)); } } return tmp.join(arg_separator); } else if (typeof(val) !== "function") { return url.encode(key) + "=" + url.encode(val); } else { throw new Error('There was an error processing for http_build_query().'); } }; if (!arg_separator) { arg_separator = "&"; } for (key in formdata) { value = formdata[key]; if (numeric_prefix && !isNaN(key)) { key = String(numeric_prefix) + key; } tmp.push(_http_build_query_helper(key, value, arg_separator)); } return tmp.join(arg_separator); }, base: function() { return "https://firmymiesne.pl/"; }, indexFile : function() { return ""; }, site: function(uri) { return url.base() + url.indexFile() + '/' + trim(uri); }, query: function(params) { var query = url.http_build_query(params, '', '&'); return (query === '') ? '' : '?' + query; }, getQueryParam : function(name) { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp(regexS); var results = regex.exec(window.location.href); if(results == null) return ""; else return decodeURIComponent(results[1].replace(/\+/g, " ")); }, file: function(name) { return url.base() + name; }, segment: function(index, separator) { if (!separator) separator = '/'; var segments = window.location.href.substr( url.base().length, window.location.href.length ).split(separator); return segments[index + 1]; } };