Client side global functions

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
ppinto
User
Posts: 148

Client side global functions

Post by ppinto »

Can someone direct me to the documentation about the client side global functions, like ew.isMobile()?
I've searched the available docs but can't find it anywhere...
Thanks!


mobhar
User
Posts: 11905

Post by mobhar »

It is located in js/ew.js generated file, or your PHPMaker template file, around line 8976 to 8979.

  // Check if mobile
  function isMobile() {
    return ew.IS_MOBILE || !isMediumScreen();
  }

ppinto
User
Posts: 148

Post by ppinto »

Thanks for your reply, but I only mentioned isMobile() as an example.
My question is about documentation on the client side global functions of PHP Maker. Server side global functions are very well documented, but client side seems to be lacking in this matter...


mobhar
User
Posts: 11905

Post by mobhar »

Although there is no specific documentation regarding client side global functions, you may learn it from that file above.


sangnandar
User
Posts: 1031

Post by sangnandar »

Actually many server-side global functions are also undocumented. It's impossible to documenting them all.
To get all available server-side global functions that you can use in a page, try:

// Page Data Rendering event
public function pageDataRendering(&$header)
{
  // Example:
  //$header = "your header";

  // Get an array of all defined functions
  $functions = get_defined_functions();

  // internal (built-in PHP) functions
  $internalFunctions = $functions['internal'];

  // user-defined functions
  $userFunctions = $functions['user'];

  $header = "";
  foreach ($userFunctions as $function) {
    $header .= $function . "<br/>";
  }
}

For client-side global functions, try:

// Startup script
function isStandardObject(obj) {
  return obj instanceof Object || obj instanceof Array || obj instanceof Function || 
        obj instanceof Date || obj instanceof RegExp || obj instanceof Set || 
        obj instanceof Map || obj instanceof WeakSet || obj instanceof WeakMap || 
        obj instanceof Promise || obj instanceof Symbol;
}

function findFunctions(obj) {
  let functions = [];

  function recursiveSearch(obj) {
    for (const key in obj) {
      if (isStandardObject(obj)) {
        if (obj.hasOwnProperty(key)) {
          if (typeof obj[key] === 'function') {
            functions.push({ key, func: obj[key] });
          } else if (typeof obj[key] === 'object' && obj[key] !== null) {
            recursiveSearch(obj[key]);
          }
        }
      }
    }
  }

  recursiveSearch(obj);
  return functions;
}

const functions = findFunctions(ew);
console.log(functions);

For server-side, you have to "Find in Files" to locate the functions.
For client-side, you can expand the object and go to [[FunctionLocation]].


ppinto
User
Posts: 148

Post by ppinto »

Thanks for the code, sangnandar, that is very helpful!
I do agree that it's impossible to document all the functions, but my contention is that it would be very helpful if the most important client functions were, as are the most relevant server functions (more than 40 of those are documented, actually).


Post Reply