With Méthode Swing it’s possible to add manipulation to a custom url.

Registration of a custom manipulation

To register a custom manipulation, use the following namespace

eidosmedia.webclient.extensions.manageCustomUrl

and its function

register( options )
Table 1. Method information

Method

register

Parameter

Required {object} options - An object containing more than one function that will be invoked to perform the custom manipulation.

Supported functions:

  • "handleUrl": Handle the custom url manipulation according to the area type

  • "getPreviewInfo": Handle the custom url to get preview info according to the area type

Returns

{undefined} undefined

The following is a very simple registration for a custom manipulation.

(function(){

    eidosmedia.webclient.extensions.manageCustomUrl.register({'handleUrl': function( data, ctx, callback ) {

            /**
             * Save the current url
             */
            var uri = data.uri;

            /**
             * Save the handle drop flag
             */
            var handleDrop = false;

            try {

                /**
                 * The area object it's useful to verify if the call come form the editor of the story
                 */
                var area = ctx.area;
                if (area.getType() == 'editor' && area.getName() == 'story') {

                    /**
                     * In our example we decide to handle only the url of eidosmedia site
                     * Change the if statement according to your needs
                     */
                    if (uri == 'https://www.eidosmedia.com/') {
                        var contentTitle = 'Eidosmedia link site';
                        handleDrop = true;

                        /**
                         * Prepare the xml to insert in the current active document context
                         */
                        var xml = '<a href="' + uri + '">' + contentTitle + '</a>';
                        ctx.activeDocument.insertXml(xml);
                    }
                }

                /**
                 * notify a callback, if specified, only if the drop has not been handled so Swing can manage
                 * the url in the standard way
                 */
                if (!handleDrop && callback) {
                    callback(data);
                }

            } catch (ex) {
                console.log("manageCustomUrl-handleUrl custom manipulation exception caught", ex);

                /**
                 * notify a callback, if specified, only if the drop has not been handled so Swing can manage
                 * the url in the standard way
                 */
                if (!handleDrop && callback) {
                    callback(data);
                }
            }
    }, 'getPreviewInfo': function( data, ctx ) {

        /**
         * Save the current url
         */
        var uri = data.uri;
        var currentXml = data.xml;
        var previewInfo;

        try {

            /**
             * The area object it's useful to verify if the call come form the editor of the story
             */
            var area = ctx.area;
            if (area.getType() == 'editor' && area.getName() == 'story') {

                /**
                 * In our example we decide to handle only the url of eidosmedia site
                 * Change the if statement according to your needs
                 */
                if (uri == 'https://www.eidosmedia.com/') {

                    var path = ''; // path of an image in the eomdb;
                    var customIcon = 'fa fa-exclamation-circle'; // the custom icon to use
                    previewInfo = {'path': path, 'icon': customIcon}
                }
            }

        } catch (ex) {
            console.log("manageCustomUrl-getPreviewInfo custom manipulation exception caught", ex);

        }

        return previewInfo;

    }});
})();
  • "handleUrl" Must have three parameters. The first one contains info about the url to handle. The second one is the context where the url has to be handle. The third one it’s a callback that must be invoked if the url doesn’t need custom manipulation, in this case Swing can proceed to handle the url in the standard way.

  • "getPreviewInfo" Must have TWO parameters. The first one contains info about the url to handle. The second one is the context where the url has to be handle. The method must return the preview info.

Wrap all the custom manipulation with a try…​catch block to allow Swing to handle the url if something goes wrong.