Documentation

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.

<script async src="//demo.chevereto.com/sdk/pup.js" data-url="https://demo.chevereto.com/upload"></script>

Note: You need to edit src and data-url to match your Chevereto website.

PUP works on the DOM so it doesn't have any server-side dependencies and it can be installed on any website.

Customization

All plugin customizations are handled via data attributes that you must add to PUP base code. As an example, to use the red color palette the code should look like this:

<script async src="//demo.chevereto.com/sdk/pup.js" data-url="https://demo.chevereto.com/upload" data-palette="red"></script>

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.

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:

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:

<script async src="//demo.chevereto.com/sdk/pup.js" data-url="https://demo.chevereto.com/upload" data-html="<a %x title='%text' class='%bClass'>%iconSvg</a>"></script>

Custom CSS works exactly the same as custom HTML but it uses data-button-css and color palette placeholders (%1, %2, ..., %n). In this example, this is the custom CSS that we want to use:

li.%cClass .%bClass{background:%1;color:%2;text-indent:unset;border-radius:3px;position:relative}li.%cClass a.%bClass:hover{background:%3;color:%4;border-color:%5}.%cClass .%bClass svg{font-size:15px;width:1em;height:1em;-webkit-transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);transform:translate(-50%,-50%);position:absolute;left:50%;top:50%;fill:currentColor}

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

<script async src="//demo.chevereto.com/sdk/pup.js" data-url="https://demo.chevereto.com/upload" data-css="li.%cClass .%bClass{background:%1;color:%2;text-indent:unset;border-radius:3px;position:relative}li.%cClass a.%bClass:hover{background:%3;color:%4;border-color:%5}.%cClass .%bClass svg{font-size:15px;width:1em;height:1em;-webkit-transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);transform:translate(-50%,-50%);position:absolute;left:50%;top:50%;fill:currentColor};"></script>

Important: For both custom HTML and CSS make sure to don't break the syntax when using quotes.

Manual button binding

To manually bind a button, simply create your own button make sure to add data-chevereto-pup-trigger and data-target attributes. This is an example of a manually inserted button:

<div id="editor" contenteditable></div>
<button data-chevereto-pup-trigger data-target="#editor">Custom button</button>

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.