Documentation - Upload plugin

Upload plugin

The popup upload plugin (PUP) is a small file that allows Chevereto based websites to provide external image uploading via a small JavaScript file. PUP is enabled by default in all Chevereto based websites since version 3.10.2 and when enabled, instructions will be available at /plugin in your website.

PUP binds user-editable content with an upload button that will trigger an image upload dialog and it will auto handle the codes needed for image insertion. End-users will experience a fluid and neat process without leaving the original website.

Supported devices

PUP should work in any modern web browser (HTML 5) regardless of the user device (that includes mobile devices). It has been tested and confirmed to work on Windows, Mac, Linux and Android (Chrome).

Installation

Basic installation is easy as copy the following code into any HTML section of the target website. You can add custom options right on this code.

This applies to all PUP options. The format is data-key where key is the target option key, in this case the palette option is being declared as the data-palette attribute value.

Options

This is the list of all the plugin key options available.

url

URL of the target Chevereto website.

palette

Named color palette of the button or a comma-separated list of colors (HEX, RGB, etc.). When using a comma-separated list of colors, the system will bind each color to a %n color index (starting at %1) that you can use with custom CSS. Supported list of palette names:
default,
clear,
turquoise,
green,
blue,
purple,
darkblue,
yellow,
orange,
red,
grey,
black.

Sibling CSS selector to use it as a reference to the DOM node where the button should be inserted. By default, the button will be placed relative to the editable content. When the sibling is defined, the plugin will search for that element and it will use it as the reference for button insertion. Value css-selector.

sibling-pos

Position, relative to the sibling, to place the button. Default after. Values before, after.

A boolean indicating if the plugin should fit the button to the target editor toolbar. Values 0 (disabled), 1 (enabled). When disabled, the plugin won't fit the button styling to the target editor (override valid only for supported vendors).

observe

CSS selector for elements that on click event will trigger sibling observation and then button insertion. Useful for dynamic editors that generate editor code on the fly. Value css-selector.

observe-cache

A boolean indicating if a matched observed element should be cached. Default 1. Values 0 (disabled), 1 (enabled). When enabled, it will stop observing the matched observed element click events. Always disable observe cache if the editor is dynamically generated and not stored as a DOM node.

Custom HTML and CSS

PUP support custom templates and it includes template placeholders. A template placeholder is a special string that PUP will convert into usable markup. This is the list of template placeholders available:

%x

PUP button observer (must be used to trigger button action)

%cClass

Container class name

%bClass

Button class name

%iClass

Icon class name

%iconSvg

Vector icon in the form of a ready-to-use SVG HTML tag

%text

Translated button text

For custom CSS, you can also use color palette placeholders in the form of %n where n is the color palette index so it binds %1, %2, ..., %n placeholders.

Custom HTML works by indicating the template string as an option attribute. In this example, this is the custom HTML that we want to use:

<a %x title='%text' class='%bClass'>%iconSvg</a>

To use this template, simply assign data-html right into the plugin code:

Manually inserted buttons get the same popup dialog functionality and binding. However, manually inserted buttons won't use any of the plugin options or templating.

Core features

This plugin has very neat functions and takes advantage of modern standards to provide its core functionality. These are some of the features shape the PUP core.

Native JavaScript

PUP is written in modern JavaScript standard and it doesn't require any external library or server module. The code is about 18KB and gzipped should be around just 6KB. The source is minified using Google Closure compiler but object names aren't touched so you can inspect the source and easily understand the code.

It works async so it doesn't matter where you place the insertion code and it won't render block the load of the target website at all.

Smart load and dynamic trigger observer

PUP is designed to observe the DOM until the target sibling element is available and soon as that happens, it will initiate its process and it will stop any additional DOM node observation. For dynamically generated editor boxes, PUP has a complimentary load option that observes the click event on a defined selector element. Any click on that element will trigger PUP's sibling observation and it will stop soon as the sibling gets found. This allows PUP to work in static or dynamic editor boxes.

Since some dynamic editor boxes will be generated just once and then stored as DOM nodes (XenForo) and others will be always re-parsed (Discourse, NodeBB), you can indicate if PUP should cache or not the observed triggered bindings. XenForo, Discourse and NodeBB vendors are configured to observe certain selectors just in case you want to learn how this works.

Closure

The source is all wrapped in a JavaScript closure meaning that the internal variables can't be tempered. This aims to avoid hijacking via browser console exploits or DOM manipulation. This closure also grants that all the variables handled by PUP won't conflict with any of the scripts running on the target website.

postMessage

PUP uses postMessage API to keep an active communication with the target Chevereto website. Options and embed codes are safely handled using this API which restricts the origin of the posted messagese and on top of that, PUP validates each message to ensure that there's no tempering on those either. PUP will only listen to messages from the target Chevereto website.

Multiple instances

PUP supports multiple unlimited instances. You can cast multiple buttons at the same time and all instance ids are referenced using the GUID algorithm.

Template cache

PUP will cache the button template so it won't unnecessarily re-process the template placeholders. This grants super fast performance even in multiple instances.