Customising v-shaped editor buttons

Starting from version 4.6.1 it is possible to add your own custom functions to the v-shaped editor buttons. The following example adds a simple function that displays the object's ID:

{init_articles name="articles" buttons="edit,hide,custom_button"}

<script type="text/javascript" src="{$wwwroot}/js/jquery.js"></script>
<script type="text/javascript" src="{$wwwroot}/js/jquery.contextMenu.js"></script>
<script type="text/javascript">{literal}

    // define your custom button
    $.fn.contextMenu.addAction({name: 'custom_button', title: 'Custom action', bind: customAction});
   
    // function to be executed, when the menu item is clicked
    function customAction()
    {
        // get object info from the anchor
        var objectData = $(this).data('objectData');
       
        var attrs = objectData.anchor.getAttributes(/^scms_/);
       
        alert(attrs['scms_object_id']);
       
        // return false to stop click propagation
        return false;
    }
</script>{/literal}

{*** Article titles ***}
{foreach from=$articles item="article"}
{$article->buttons}{$article->title}<hr>
{foreachelse}
{$articles_newbutton}
{/foreach}

You can use the following CSS rule for defining icon to your action:

ul.context_plugin_dropdown li.context_plugin_item a.custom_button {
    background-image: url(url/to/icon.png);
}

Site development

About Saurus API / Creating page template tutorial / Creating content template tutorial / Applying custom design to page template checklist / Moderated comments / Stationary articles (header, footer etc) / First, last and n'th item in a foreach loop / Creating zebra tables (cycling values) / Site and Article editor CSS styles / How to set up website aliases / Customising v-shaped editor buttons / Using PHP in templates / Exchanging variables between templates and PHP / Profiles and Custom Assets / Site languages / Printer friendly pages / Enabling browser cache / Creating WAP pages / Configuring sitemap / Saurus 4.1 technical notes