Skip to content

Instantly share code, notes, and snippets.

@adriatic
Last active July 20, 2016 06:34
Show Gist options
  • Save adriatic/1d5ff9f9b881b192b1f57d382500fa3c to your computer and use it in GitHub Desktop.
Save adriatic/1d5ff9f9b881b192b1f57d382500fa3c to your computer and use it in GitHub Desktop.
Toolbar: events
<template>
<require from="./logger.js"></require>
<div id="example">
<div class="demo-section k-content wide">
<ak-toolbar k-on-click.delegate="click($event.detail)"
k-on-toggle.delegate="toggle($event.detail)"
k-on-overflow-open.delegate="overflowOpen($event.detail)"
k-on-overflow-close.delegate="overflowClose($event.detail)"
k-on-open.delegate="open($event.detail)"
k-on-close.delegate="close($event.detail)">
<ak-toolbar-item k-type="button" k-id="button1" k-text="Button 1" k-click.call="buttonClickHandler($event)"></ak-toolbar-item>
<ak-toolbar-item k-type="button" k-id="button2" k-text="Button 2" k-click.call="buttonClickHandler($event)"></ak-toolbar-item>
<ak-toolbar-item k-type="separator"></ak-toolbar-item>
<ak-toolbar-item k-type="button" k-id="toggle1" k-text="Toggle 1" k-togglable.bind="true" k-toggle.call="buttonToggleHandler($event)"></ak-toolbar-item>
<ak-toolbar-item k-type="button" k-id="toggle2" k-text="Toggle 2" k-togglable.bind="true" k-toggle.call="buttonToggleHandler($event)"></ak-toolbar-item>
<ak-toolbar-item k-type="separator"></ak-toolbar-item>
<ak-toolbar-item k-type="splitButton"
k-id="mainButton"
k-text="Split Button"
k-click.call="splitButtonClickHandler($event)"
k-menu-buttons.bind="[
{ text: 'Action 1', id: 'action1' },
{ text: 'Action 2', id: 'action2' },
{ text: 'Action 3', id: 'action3' }
]"></ak-toolbar-item>
<ak-toolbar-item k-type="separator"></ak-toolbar-item>
<ak-toolbar-item k-type="splitButton"
k-id="mainButton"
k-text="Split Button"
k-click.call="splitButtonClickHandler($event)"
k-menu-buttons.bind="[
{ text: 'Action 1', id: 'action1' },
{ text: 'Action 2', id: 'action2' },
{ text: 'Action 3', id: 'action3' }
]">
</ak-toolbar-item>
<ak-toolbar-item k-type="separator"></ak-toolbar-item>
<ak-toolbar-item k-type="buttonGroup">
<ak-toolbar-item-button k-text="Radio 1" k-id="radio1" k-togglable.bind="true" k-group="radio" k-toggle.call="buttonToggleHandler($event)"></ak-toolbar-item-button>
<ak-toolbar-item-button k-text="Radio 2" k-id="radio2" k-togglable.bind="true" k-group="radio" k-toggle.call="buttonToggleHandler($event)"></ak-toolbar-item-button>
<ak-toolbar-item-button k-text="Radio 3" k-id="radio3" k-togglable.bind="true" k-group="radio" k-toggle.call="buttonToggleHandler($event)"></ak-toolbar-item-button>
</ak-toolbar-item>
<ak-toolbar-item k-type="button" k-id="overflowButton" k-text="Overflow button" k-overflow="always"></ak-toolbar-item>
</ak-toolbar>
<div class="box">
<h4>Console log</h4>
<logger view-model.ref="logger"></logger>
</div>
</div>
</div>
</template>
export class Events {
buttonClickHandler(e) {
this.logger.log(e.target.text() + ' "click" event is fired.');
}
buttonToggleHandler(e) {
this.logger.log(e.target.text() + ' "toggle" event is fired.');
}
splitButtonClickHandler(e) {
this.logger.log('SplitButton event: ' + e.id + ' is clicked.');
}
click(e) {
this.logger.log('ToolBar "click" event is fired for element with id: ' + e.id);
}
toggle(e) {
if (e.group === 'radio') {
this.logger.log('Toolbar "toggle" event: ' + e.id + ' button is selected from group: ' + e.group);
} else {
this.logger.log('ToolBar "toggle" event: ' + e.id + ' button is changed');
}
}
overflowOpen(e) {
this.logger.log('Overflow container open');
}
overflowClose(e) {
this.logger.log('Overflow container close');
}
open(e) {
this.logger.log('SplitButton popup open');
}
close(e) {
this.logger.log('SplitButton popup close');
}
}
<!doctype html>
<html>
<head>
<title>Aurelia KendoUI bridge</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2016.1.226/styles/kendo.common.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2016.1.226/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2016.1.226/styles/kendo.default.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2016.1.226/styles/kendo.mobile.all.min.css">
<script src="https://kendo.cdn.telerik.com/2016.1.226/js/jszip.min.js"></script>
</head>
<body aurelia-app="main">
<h1>Loading...</h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.6/system.js"></script>
<script src="https://rawgit.com/aurelia-ui-toolkits/aurelia-kendoui-bundles/0.3.5/config2.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
<template>
<div class="console">
</div>
</template>
export class Logger {
attached() {
this.overrideStyles();
}
log(message, isError, container) {
let lastContainer = $('.console div:first', container);
let counter = lastContainer.find('.count').detach();
let lastMessage = lastContainer.text();
let count = 1 * (counter.text() || 1);
lastContainer.append(counter);
if (!lastContainer.length || message !== lastMessage) {
$('<div' + (isError ? ' class=\'error\'' : '') + '/>')
.css({
marginTop: -24,
backgroundColor: isError ? '#ffbbbb' : '#b2ebf2'
})
.html(message)
.prependTo($('.console', container))
.animate({ marginTop: 0 }, 300)
.animate({ backgroundColor: isError ? '#ffdddd' : '#ffffff' }, 800);
} else {
count++;
if (counter.length) {
counter.html(count);
} else {
lastContainer.html(lastMessage)
.append('<span class=\'count\'>' + count + '</span>');
}
}
}
error(message) {
this.log(message, true);
}
overrideStyles() {
jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i, attr) {
jQuery.fx.step[attr] = function(fx) {
if (!fx.state || typeof fx.end === typeof '') {
fx.start = getColor(fx.elem, attr);
fx.end = getRGB(fx.end);
}
fx.elem.style[attr] = ['rgb(', [
Math.max(Math.min(parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0], 10), 255), 0),
Math.max(Math.min(parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1], 10), 255), 0),
Math.max(Math.min(parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2], 10), 255), 0)
].join(','), ')'].join('');
};
});
}
}
// Color Conversion functions from highlightFade
// By Blair Mitchelmore
// http://jquery.offput.ca/highlightFade/
// Parse strings looking for color tuples [255,255,255]
function getRGB(color) {
let result;
// Check if we're already dealing with an array of colors
if (color && color.constructor === Array && color.length === 3) {
return color;
}
// Look for rgb(num,num,num)
result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color);
if (result) {
return [parseInt(result[1], 10), parseInt(result[2], 10), parseInt(result[3], 10)];
}
// Look for #a0b1c2
result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color);
if (result) {
return [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)];
}
// Otherwise, we're most likely dealing with a named color
return jQuery.trim(color).toLowerCase();
}
function getColor(elem, attr) {
let color;
do {
color = jQuery.css(elem, attr);
// Keep going until we find an element that has color, or we hit the body
if (color && color !== 'transparent' || jQuery.nodeName(elem, 'body')) {
break;
}
attr = 'backgroundColor';
elem = elem.parentNode;
} while (elem);
return getRGB(color);
}
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging()
.plugin('aurelia-kendoui-bridge', kendo => kendo.pro());
aurelia.start().then(a => a.setRoot());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment