OpenPlatform / 03. Client-side library
Updated: 19. May 2018
Author: Peter Širka

03. Client-side library

Professional Support Chat with contributors

OpenPlatform offers a small client-side library called openplatform.js. The application can obtain user/meta-data from OpenPlatform and it supports another features for OpenPlatform manipulation.

Initialization

The code below describes OpenPlatform initialization in your web application:

<script src="https://cdn.totaljs.com/openplatform.min.js"></script>
<script>

    OPENPLATFORM.init(function(err, response, redirectTimeout) {

        if (err) {
            document.body.innerHTML = '401: Unauthorized';
            return;
        }

       // response === meta-data

        OPENPLATFORM.minimize();
        OPENPLATFORM.notify('Hello world!');
    });

</script>

Methods

  • OPENPLATFORM.init(callback(err, response, redirectTimeout)) - initializes OpenPlatform
  • OPENPLATFORM.loading(visible) - toggles preloading (animation)
  • OPENPLATFORM.meta(callback(err, response)) - reads meta data again
  • OPENPLATFORM.play(url) - plays a sound
  • OPENPLATFORM.stop(url) - stops a playing sound
  • OPENPLATFORM.maximize() - maximizes this application in OpenPlatform
  • OPENPLATFORM.minimize() - minimizes this application in OpenPlatform
  • OPENPLATFORM.restart() - restarts this application
  • OPENPLATFORM.open(idapp, [data]) - opens another application
  • OPENPLATFORM.close() - closes/kills this running application
  • OPENPLATFORM.notify([type], body, [url]) - sends a push notification
  • OPENPLATFORM.confirm(msg, buttons, callback(err, result)) shows a confirm message
  • OPENPLATFORM.message(msg, [type]) - shows a message box, types: success (default) and warning
// OPENPLATFORM.notify([type], body, [url]);
// "type" {Number} 0 - info, 1 - success, 2 - error
// "body" {String}
// "url" {String} can be relative

// Examples:
OPENPLATFORM.notify(0, 'Info');
OPENPLATFORM.notify(1, 'Success', '/orders/101210/');
OPENPLATFORM.notify(2, 'Error/Warning', '/reports/');

OPENPLATFORM.confirm('Are you sure you want to remove selected order?', ['Yes', 'Cancel'], function(err, button) {
   console.log(button.index); 
});

Events

OPENPLATFORM.on('maximize', function() {
   // App is maximized
});

OPENPLATFORM.on('minimize', function() {
   // App is minimized
});

OPENPLATFORM.on('close', function() {
   // App is closed
});