Configuring Customizable Toolbars
The toolbar directive is HTML markup compiled by AngularJS using a template and bound to a controller.
A reusable toolbar directive was developed on top of the underlying Gateway Factory. The toolbar directive is HTML markup compiled by AngularJS using a template and bound to a controller. The toolbar directive makes it possible for toolbar actions to be configured from the interface exposed by the outer application's and the inner application's toolbar services. You can extend the SmartEdit toolbar service by declaring a toolbar and adding items to it.
In addition to the toolbars provided with SmartEdit by default, you can create your own toolbar and populate it with items and actions. You can do this using the toolbar service factory.
Declaring a Toolbar and Adding Items to It
In addition to the default toolsbars provided by SmartEdit, you can create your own toolbars by doing the following:
- Declaring a toolbar using the toolbar directive.
- Adding items to the toolbar.
- Adding items to the inner application.
Declaring a Toolbar Using the Toolbar Directive
The toolbar directive must appear in the HTML file at the position where you want the toolbar to appear in the page. You must specify a unique toolbar name, and, optionally, a CSS class name. You must add the following code to your page:
<toolbar data-css-class="someclass" data-image-root="someimageroot" data-toolbar-name="sometoolbarname"></toolbar>
The following code excerpt shows the script for a HTML page in which an AngularJS module has been set up with the toolbarModule as a dependency.
<div class="ySmartEditToolbars" style="position:absolute">
<div>
<toolbar data-css-class="ySmartEditTitleToolbar" data-image-root="imageRoot" data-toolbar-name="smartEditTitleToolbar"></toolbar>
</div>
<div>
<toolbar data-css-class="ySmartEditExperienceSelectorToolbar" data-image-root="imageRoot" data-toolbar-name="experienceSelectorToolbar"></toolbar>
</div>
</div>
<div ng-class="{'alert-overlay': true, 'ySEEmptyMessage': (!alerts || alerts.length == 0 ) }">
<alerts-box alerts="alerts" />
</div>
<div id="js_iFrameWrapper" class="iframeWrapper">
<iframe src="" hy-dropabpe-iframe></iframe>
</div>
With regards to the SmartEdit container, the toolbarModule contains the toolbar directive and the outer toolbar service factory. The toolbar service factory is injected into a controller in which an instance of the toolbar service associated to Toolbar1 (the same as in the HTML excerpt above) is fetched using the factory's getter method. The controller then pushes actions to the toolbar through the toolbar service.
Adding Items to a Toolbar
From the SmartEdit application and SmartEdit container, you must use the toolbar service factory to add items to the toolbar. To add an item to a toolbar, you must reference the toolbar service that handles the targeted toolbar (use smartEditTitleToolbar, experienceSelectorToolbar, and pageToolMenu as keys) and call the addItems method with an array of items. You can call any of the following three item types:
- ACTION: Consists of the i18nKey key to be translated and a callback function without arguments; this item can be used in the outer and inner toolbar services.
- HYBRID_ACTION: Consists of the i18nKey key to be translated, a callback function without arguments, and an include attribute that points to a HTML template location; this item can only be used in the outer toolbar service.
- TEMPLATE: Consists of an include attribute that points to a HTML template location; this item can only be used in the outer toolbar service.
Regardless of the order in which the items are executed, all TEMPLATE items will be pushed (DOM-wise) to the left of the toolbar and all ACTION and HYBRID_ACTION items will be grouped on the right-hand side within a div tag. You can control the CSS classes of this div tag using the toolbarService.addItemsStyling() API. You should execute this code within a run block of an AngularJS module.
The following code example shows how to add items to a toolbar. The toolbar can be in the outer or inner toolbar service.
angular.module('outerapp', ['toolbarModule'])
.controller('defaultController', function($rootScope, $scope, toolbarServiceFactory) {
var toolbarService = toolbarServiceFactory.getToolbarService('Toolbar1');
toolbarService.addItemsStyling('nav nav-pills group pull-right');
toolbarService.addItems([{
type:'TEMPLATE',
include:'path/to/my/template.html'
}, {
type:'ACTION',
i18nKey: 'toolbar.action.action1',
callback: function() {
$scope.message = 'Action 1 called';
},
icon:{
default:'path/to/my/icon.png'
}
}, {
type:'HYBRID_ACTION',
i18nKey: 'toolbar.action.action2',
callback: function() {
$scope.message = 'Action 2 called';
},
icon:{
default:'path/to/my/icon.png'
}
include:'path/to/my/template.html'
}]);
});
Adding Items to a Toolbar in the Inner Application
In the inner application, the SmartEdit application, another module is set up with the toolbarModule as a dependency. With regards to the SmartEdit application, the toolbarModule contains the inner toolbar service factory. The toolbar service factory is injected into a controller in which an instance of the toolbar service associated to Toolbar1 (the same as in the SmartEdit container and as shown in the HTML examples in the sections above) is fetched using the factory's getter method. The controller then pushes actions to the toolbar using the toolbar service. In the background, the toolbar service pushes actions to the SmartEdit container's toolbar service.
angular.module('innerapp', ['toolbarModule'])
.controller('defaultController', function($rootScope, $scope, toolbarServiceFactory) {
var toolbarService = toolbarServiceFactory.getToolbarService('Toolbar1');
toolbarService.addItemsStyling('nav nav-pills group pull-right');
toolbarService.addItems([{
type:'ACTION',
i18nKey: 'toolbar.action.action1',
callback: function() {
$scope.message = 'Action 1 called';
},
icon:{
default:'path/to/my/icon.png'
}
}]);
});