SGApps.IO modules · dialogs · notifications · menus · panels · grid editor

ApplicationPrototype Modules

The SGApps.IO UI module set for the application-prototype framework, written in-house -- modal dialogs (alert, confirm, prompt), toast notifications with ten screen positions, a context menu with sub-lists, collapsible side-by-side panels, an org-chart tree, a transform-based scroller element, a tiled grid layout editor, an iframe sandbox and a static routing pattern: about 3,600 lines of original JavaScript (plus 1,700 of CSS) with no third-party code inside, each module resolved by name through Application.require(). Plain ES5, no build step, no bundler.

Open the documentation →
The modules · Getting started · Playground · Repository

What is it?

Ten modules that give a page built with the application-prototype framework its everyday UI, plus one application pattern -- all original code developed by SGApps.IO, with the framework's own built-ins (extensions/prototype, uri-load, request, custom-elements, async) as the only dependencies. lib.js at the repository root registers the module names with Application.moduleRegister(); from then on App.require('elements/popup') downloads the module on first use, and every element and gadget factory returns an ApplicationPrototype instance with the same node(), on(), bind() surface.

3,600 lines of our own JavaScript

Scroller 643, Grid Panel 642, Popup 526, Routing 421, Context Menu 390, Notify 360, Crop Sections 287, Notify Service 121, Tree Node 87, Wrapper 86 -- counted with wc -l; a grep for require( shows they load only framework built-ins and each other.

Styled by their own stylesheets

Each module links its style.css through uri-load when it loads (1,700 lines of CSS in all: the notification layouts alone are 855). The dialogs, notifications and the menu use the class names of the SGApps RegalRoyal theme and take its look when it is on the page.

Custom elements without a polyfill

<sgapps-scroller> is registered through the framework's MutationObserver-based custom-elements module and lazy-loaded the first time the tag appears; options are plain attrb-* attributes.

One loader, one API

lib.js registers 10 names; factories return ApplicationPrototype instances with before / on / after hooks on every method, and every module has a playground page.

All modules

10 module names registered by lib.js, plus the routing pattern loaded by path -- each with a documentation page and a playground example (9 in all; the routing pattern needs component files of its own). Everything on this page is SGApps.IO module code: original software developed in-house, CC BY-NC-ND 4.0.

Elements: dialogs & notifications elements/

Popup SGApps.IO module

elements/popup · 526 JS + 189 CSS

alert(), confirm(), prompt() and bare popup() dialogs over a full-screen overlay: title, text, websymbols icon, any number of buttons with callbacks, light / dark / clean themes, outside-click handling, focus management.

Notify SGApps.IO module

elements/notify · 360 JS + 855 CSS

Toast notification manager: log / info / warn / error / debug rows with a message and detail lines, per-type auto-expiry, click callbacks, ten container positions; forwards alert / confirm / prompt to the Popup.

Notify Service SGApps.IO module

elements/notify-service · 121 JS

Ten Notify managers, one per position, attached to document.body on construction: position('top', 'right').warn(...) picks a corner; the service itself proxies the bottom-left manager.

Elements: menus & layout elements/

Context Menu SGApps.IO module

elements/context-menu · 390 JS + 101 CSS

A menu built from an options array -- text, icon, function or URL action, nested lists, a render hook, style classes, a draggable headbar -- shown at the mouse ('mouse-viewport' keeps it on screen) and hidden on the next click outside.

Crop Sections SGApps.IO module

elements/crop-sections · 287 JS + 310 CSS

Side-by-side panels that share the free width: fixed or fluid sections with a header and scrolling articles, collapsing into a 48 px vertical tab with a CSS 3D rotation; attach / detach, lookup by name.

Tree Node SGApps.IO module

elements/tree-node · 87 JS + 168 CSS

Org-chart style tree of <tree-node> elements: append(), remove(), parent(), parents(), childs(), siblings(); connectors drawn in pure CSS and highlighted on hover.

Custom elements custom-elements/

<sgapps-scroller> SGApps.IO module

custom-elements/scroller · 643 JS

A zero-size marker that turns an overflow: hidden box into a wheel- and drag-scrollable area by translating its siblings with a generated transform rule: limits, speeds, axis flags, synchronised boxes, a transform prefix and a bubbling sgapps-scroll event.

custom-elements/lib SGApps.IO module

custom-elements/lib · 12 JS

The registration helper: hands the tag → module map to the framework's custom-elements module so <sgapps-scroller> is downloaded the first time it appears in the page.

Gadgets gadgets/

Grid Panel SGApps.IO module

gadgets/grid-panel · 642 JS + 98 CSS

Tiled dashboard layout editor: click two cells (or double-click one) to place a block, a self-growing cell grid, blocks with a content container and geometry setters, settings() snapshot and restore of the whole layout.

Wrapper SGApps.IO module

gadgets/wrapper · 86 JS

Same-origin Blob-URL iframe sandbox: node(), container(), document(), window(), whenLoaded(), with header / code / base options for the generated document. Keeps a widget's globals and CSS out of your page.

Application patterns application-patterns/ · loaded by path, not in lib.js

Routing SGApps.IO module

application-patterns/routing · 421 JS

Static routing for single-page applications: routes (string patterns with :params, RegExps, matcher functions, a null fallback) name component modules and shared resource modules; load() resolves the URL, loads each resource once and renders the components in order with timed logs.

Live examples

A selection of the playground pages, embedded in preview mode. They load the framework from the SGApps CDN and the modules from this working copy (the folder above docs/) -- serve the repository root (npm start) and every example runs on your checkout; on a published docs-only site they fall back to the CDN copy of the modules. Each frame has an Edit in the playground button that opens the same page with its source in an editor.

Popup elements/popup

An alert(), a two-button dark-theme alert, a confirm(), a prompt() with validation and a custom popup(node) with its own footer. Docs · Open in the playground

Notify elements/notify

One manager in the bottom-right corner: log, info, warn, error rows, a sticky notification with detail lines and a click handler that updates it, and a position switch. Docs · Open in the playground

Context Menu elements/context-menu

Right-click the dashed area: a menu with a draggable headbar, actions that receive the context object, a nested Share list and a red Delete item decorated by its render hook. Docs · Open in the playground

Crop Sections elements/crop-sections

A fixed-width navigation panel and two fluid panels sharing the rest; collapse one with the arrow in its header, add and detach sections with the toolbar. Docs · Open in the playground

Tree Node elements/tree-node

An organisation chart built from data; click a node to read its path, siblings and children, append a child to it or remove it. Docs · Open in the playground

sgapps-scroller custom-elements/scroller

Three overflow: hidden boxes scrolled by wheel and drag: A and B are synchronised, C reverses the wheel axis; the buttons drive the API on A and a delegated sgapps-scroll listener prints the positions. Docs · Open in the playground

Grid Panel gadgets/grid-panel

Click a cell then another (or double-click) to add blocks, remove them with their x, change the cell size, and snapshot / restore the layout. Docs · Open in the playground

Getting started

  1. Clone the repository next to your site. There is nothing to install: the modules are plain files fetched by the framework's loader. The framework itself comes from your application-prototype checkout (or the SGApps CDN).
  2. Load ApplicationPrototype.js and ApplicationBuilder.js, register the framework modules, then the modules of this repository through lib.js.
  3. Require any module by name.
<script src="/application-prototype/ApplicationPrototype.js"></script>
<script src="/application-prototype/ApplicationBuilder.js"></script>
<script>
var App = new ApplicationBuilder({
    onready: function () {
        var App = this;
        App.modulePath('/application-prototype/constructors');
        App.require(['extensions/prototype', 'lib'], function (libs) {
            libs.lib();                                            // framework modules by name
            App.require('/application-prototype-modules/lib.js').then(function (loader) {
                loader();                                          // the 10 modules by name
                App.require('elements/notify-service').then(function (NotifyService) {
                    var notifications = NotifyService();
                    notifications.position('top', 'right').info('Ready', 'All modules registered');
                });
            });
        });
    }
});
</script>

The Getting Started page explains every step, how module names are resolved and how the modules load their stylesheets; each module page has a Use Cases section with copy-paste snippets.

npm start                     # this page + the docs at http://localhost:3000/ and /docs/
npm run docs-site-published   # serve docs/ alone, the layout of a published docs-only site
npm test                      # lint the documentation (links, sidebar, playground registry, this page, lib.js coverage)
sgapps.io