.. include:: /Includes.rst.txt .. _javascript-api: ========================= Extending the frontend UI ========================= For UI that needs to run in the browser - status badges, comment indicators, custom toolbar buttons - the extension exposes a small, stable facade on :code:`window.XimaFrontendEdit` and dispatches DOM :code:`CustomEvent`\ s at defined lifecycle points. Internal refactors of the underlying JavaScript do not change these method signatures or event :code:`detail` shapes - this is the one part of the frontend JavaScript covered by a semver guarantee. .. note:: Everything described here requires frontend editing to be active for the current backend user (see :ref:`Introduction `). When editing is disabled, :code:`xfe:ready` still fires once with an empty element map, but no elements are ever registered. Facade methods =============== ``getElementInfo(uid)`` ------------------------ Returns the resolved target element and payload for a content element uid, so consumers never have to re-do DOM resolution (anchor pattern, translation mapping). Returns :code:`null` if the uid was not rendered. .. code-block:: javascript const info = window.XimaFrontendEdit.getElementInfo(42); // { uid: 42, element: HTMLElement, payload: { element: {...}, menu: {...} } } ``notify({ title, message, severity })`` ------------------------------------------ Shows a toast notification using the extension's own notification manager. :code:`severity` is one of :code:`ok`, :code:`info`, :code:`warning`, :code:`error`. .. code-block:: javascript window.XimaFrontendEdit.notify({ title: 'Comment added', message: 'A new comment was posted on this element.', severity: 'info', }); ``registerToolbarItem(uid, buttonSpec)`` ------------------------------------------ Adds a button to a content element's hover toolbar, next to the built-in Edit/More actions buttons. :code:`buttonSpec`: - ``html`` - inner HTML of the button (e.g. an inline SVG icon) - ``label`` - accessible label, also used as the tooltip - ``href`` - renders an :code:`` instead of a :code:`