/************************************ REVISION LOG ENTRY Revision By: Mihai Filimon ( mfl@exontrol.com ) Created on 06/13/2024 08:20:00 AM Comments: jshelp.js This code may be used in compiled form in any way you desire. This file may not be redistributed modified or unmodified without the authors written consent. ************************************/ /////////////////////////////////////////////////////////// (QP) (QueryParam) // // The QP namespace provides functions to update or query the URL parameters. // // The QP namespace includes definitions for the following methods: // // Split(url) {object}, splits the URL into location, params and hash parts, as an object of {a(ll),u(rl),h(ash),l(ocation),p(arams)} type // Add(url, param, value) {string}, adds(replaces) the parameter of the specified url and returns the new url(adds/replaces "param=value" or "param") // Del(url, param) {string}, removes the parameter of the specified url and returns the new url // Has(url, param) {string}, gets the value of the specified parameter within the giving url (returns null if no parameter is found) // /////////////////////////////////////////////////////////// /** * @description Creates the QP namespace */ QP = function() { /** * @description The split() method splits the URL into location, params and hash parts, as an object of {a(ll),u(rl),h(ash),l(ocation),p(arams)} type * @param {string} url A string expression that defines the URL to split * @returns {object} Returns an object of {a(ll),u(rl),h(ash),l(ocation),p(arams)} type as explained: * * a(ll) {string}, indicates the unsplited URL (as it was provided) * u(rl) {string}, specifies the URL without the # hash section (location + params) * h(ash) {string}, indicates empty string or the # hash section (includes the '#' character) * l(ocation) {string}, specifies the location of the URL (the string precceding the ? character, includes protocol, domain and path) * p(arams) {string}, specifies the query-parameters of the URL (the string after the ? character, includes '?' character) * */ function split(url) { var iHash = String(url || "").indexOf('#'), // {number} indicates the position of '#' character within the url (-1 if not found) u = ~iHash ? url.substr(0, iHash).trim() : url, // {string} specifies the URL without the # hash section (location + params) iParam = u.indexOf('?'); // {number} indicates the position of '?' character within the url (-1 if not found) return { a: url, // a(ll) {string}, indicates the unsplited URL (as it was provided) u: u, // u(rl) {string}, specifies the URL without the # hash section (location + params) h: ~iHash ? url.substr(iHash).trim() : "", // h(ash) {string}, indicates empty string or the # hash section (includes the '#' character) l: ~iParam ? u.substr(0, iParam).trim() : u, // l(ocation) {string}, specifies the location of the URL (the string precceding the ? character, includes protocol, domain and path) p: ~iParam ? u.substr(iParam).trim() : "", // p(arams) {string}, specifies the query-parameters of the URL (the string after the ? character, includes '?' character) } } /** * @description The getParamEx() method gets the regular-expression to search for the parameter * @param {string} param Specifies the name of the parameter to look for * @returns {object} Returns an object of RegExp type */ function getParamEx(param) { return new RegExp("[?&]" + param + "($|[&]|=[^&]*)", "i"); } /** * @description The add() method adds(replaces) the parameter of the specified url (adds/replaces "param=value" or "param") * @param {string} url Specifies an URL to change * @param {string} param Indicates the name of the parameter to add * @param {string} value Specifies the value of the parameter to add * @returns {string} Returns the new URL (includes the added parameter) */ function add(url, param, value) { var oURL = split(url), oParamEx = getParamEx(param = String(param || "").trim()), separator = oURL.u.indexOf('?') != -1 ? "&" : "?", oMatch = oURL.u.match(oParamEx); // builds the value as "param=value" or "param" if ( value = String(value || "").trim() ) value = "=" + value; value = param + value; // adds or replaces the parameter return (oMatch ? oURL.u.substr(0,oMatch.index + 1) + value + oURL.u.substr(oMatch.index + oMatch[0].length) : oURL.u + separator + value) + oURL.h } /** * @description The del() method removes the parameter of the specified url * @param {string} url Specifies an URL to change * @param {string} param Indicates the name of the parameter to delete * @returns {string} Returns the new URL (excludes the parameter) */ function del(url, param) { var oURL = split(url); url = oURL.u.replace(getParamEx(String(param || "").trim()), ''); if (url.slice(-1) == '?') url = url.slice(0, -1); // removes the last ? character if any if (url.indexOf('?') < 0) url = url.replace(/&/, '?'); // replace the first occurrence of & by ? if no ? is present return url + oURL.h; } /** * @description The has() method gets the value of the specified parameter within the giving url (returns undefined if no parameter is found) * @param {string} url Specifies an URL to query * @param {string} param Indicates the name of the parameter to request * @returns {string} Returns null (no parameter found), or a string expression that defines the value of the giving parameter (could be empty string) */ function has(url, param) { var oParam = split(url).u.match(getParamEx(param = String(param || "").trim())), // {array} returns the matches, as an Array object nEqual; // {number} specifies the position of the "=" character inside the match if ( oParam ) { oParam = oParam[0]; nEqual = oParam.indexOf("="); oParam = ~nEqual ? oParam.substr(nEqual + 1) : ""; } return oParam; } return { /** * @description The Split(url) method splits the URL into location, params and hash parts, as an object of {a(ll),u(rl),h(ash),l(ocation),p(arams)} type * @param {string} url A string expression that defines the URL to split * @returns {object} Returns an object of {a(ll),u(rl),h(ash),l(ocation),p(arams)} type as explained: * * a(ll) {string}, indicates the unsplited URL (as it was provided) * u(rl) {string}, specifies the URL without the # hash section (location + params) * h(ash) {string}, indicates empty string or the # hash section (includes the '#' character) * l(ocation) {string}, specifies the location of the URL (the string precceding the ? character, includes protocol, domain and path) * p(arams) {string}, specifies the query-parameters of the URL (the string after the ? character, includes '?' character) * * @example * * QP.Split("http://exontrol.com/rhelp.jsp?product=exgrid#bookmark") * * returns: * * { * a:'http://exontrol.com/rhelp.jsp?product=exgrid#bookmark' * h:'#bookmark' * l:'http://exontrol.com/rhelp.jsp' * p:'?product=exgrid' * u:'http://exontrol.com/rhelp.jsp?product=exgrid' * } */ Split: split, /** * @description The Add(url, param, value) method adds(replaces) the parameter of the specified url and returns the new url (adds/replaces "param=value" or "param") * @param {string} url Specifies an URL to change * @param {string} param Indicates the name of the parameter to add * @param {string} value Specifies the value of the parameter to add * @returns {string} Returns the new URL (includes the added parameter) * @example * * QP.Add("http://exontrol.com/rhelp.jsp?product=exgrid#bookmark","src","InsideZooms_default") * * returns: * * "http://exontrol.com/rhelp.jsp?product=exgrid&src=InsideZooms_default#bookmark" */ Add: add, /** * @description The Del(url, param) method removes the parameter of the specified url and returns the new url * @param {string} url Specifies an URL to change * @param {string} param Indicates the name of the parameter to add * @returns {string} Returns the new URL (excludes the parameter) * @example * * QP.Del("http://exontrol.com/rhelp.jsp?product=exgrid#bookmark","product") * * returns: * * "http://exontrol.com/rhelp.jsp#bookmark" */ Del: del, /** * @description The Has(url, param) method gets the value of the specified parameter within the giving url (returns null if no parameter is found) * @param {string} url Specifies an URL to query * @param {string} param Indicates the name of the parameter to request * @returns {string} Returns null (no parameter found), or a string expression that defines the value of the giving parameter (could be empty string) * @example * * QP.Has("http://exontrol.com/rhelp.jsp?product=exgrid#bookmark","product") * * returns: * * "exgrid" */ Has: has }; }(); var oDEF = { OPTS: "options", // {string} holds the 'options' string LIVEX: "live-sample", // {string} specifies the identifier of "live example" links MAIN: "main", // {string} specifies the identifier of the main section NAME: "name", // {string} specifies the identifier to a