import 'bootstrap.css';
import '@mescius/wijmo.styles/wijmo.css';
import './styles.css';
//
import * as wjCore from '@mescius/wijmo';
import * as wjInput from '@mescius/wijmo.input';
import * as wjNav from '@mescius/wijmo.nav';
//
document.readyState === 'complete' ? init() : window.onload = init;
//
function init() {
// initialize editor element
let editor = document.querySelector('#editor');
execCommand('styleWithCSS', true);
//
if (localStorage.editorContent) {
editor.innerHTML = localStorage.editorContent;
}
//
// create ribbon
let ribbon = new wjNav.TabPanel('#ribbon');
//
// toggle ribbon content visibility on double-clicks, restore on clicks
document.querySelector('.wj-tabheaders').addEventListener('dblclick', e => {
if (!wjCore.hasClass(e.target, 'wj-tabheader')) {
wjCore.toggleClass(ribbon.hostElement, 'hide-content');
}
});
document.querySelector('.wj-tabheaders').addEventListener('click', e => {
if (wjCore.hasClass(e.target, 'wj-tabheader')) {
wjCore.toggleClass(ribbon.hostElement, 'hide-content', false);
}
});
//
// set up combos
let fontFace = new wjInput.ComboBox('#font-face', {
itemsSource: ['Arial', 'Courier New', 'Garamond', 'Tahoma', 'Times', 'Verdana', 'WingDings'],
textChanged: (sender) => execCommand('fontName', sender.text)
});
let fontSize = new wjInput.ComboBox('#font-size', {
itemsSource: ['Very Small', 'Smaller', 'Small', 'Medium', 'Large', 'Larger', 'Very Large'],
selectedIndex: 3,
textChanged: (sender) => execCommand('fontSize', sender.selectedIndex + 1)
});
//
// set up color pickers
let clrBack = createColorPicker(sender => execCommand('backColor', sender.value));
document.querySelector('#background').addEventListener('click', e => {
wjCore.showPopup(clrBack.hostElement, e.target, false, true, false);
clrBack.focus();
});
let clrFore = createColorPicker(sender => execCommand('foreColor', sender.value));
document.querySelector('#color').addEventListener('click', e => {
wjCore.showPopup(clrFore.hostElement, e.target, false, true, false);
clrFore.focus();
});
//
// add tooltips (based on aria-label attribute)
addTooltips(ribbon);
//
// execute commands
ribbon.hostElement.addEventListener('click', e => {
switch (e.target.id) {
// format group
case 'save':
localStorage.editorContent = editor.innerHTML;
alert('Document Saved to Local Storage.');
break;
case 'undo':
case 'redo':
case 'preview':
case 'removeFormat':
case 'cut':
case 'copy':
case 'paste':
case 'selectAll':
execCommand(e.target.id);
break;
//
// font group
case 'bold':
case 'italic':
case 'underline':
case 'strikethrough':
case 'subscript':
case 'superscript':
execCommand(e.target.id);
break;
//
case 'click-me':
alert('Wijmo Ribbon Sample');
}
});
//
// execute editor commands
function execCommand(cmd, parm) {
editor.focus();
document.execCommand(cmd, false, parm);
}
//
// save/restore editor selection on focus changes
let selection = null;
editor.addEventListener('keyup', () => selection = saveSelection());
editor.addEventListener('mouseup', () => selection = saveSelection());
editor.addEventListener('focus', () => restoreSelection(selection));
//
function saveSelection() {
let sel = window.getSelection();
return sel && sel.rangeCount ? sel.getRangeAt(0) : null;
}
//
function restoreSelection(range) {
if (range) {
let sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
}
}
//
// add tooltips based on the element's aria-label attribute
function addTooltips(ctl) {
let tt = new wjCore.Tooltip();
let els = ctl.hostElement.querySelectorAll('[aria-label]');
for (let i = 0; i < els.length; i++) {
tt.setTooltip(els[i], els[i].getAttribute('aria-label'));
}
}
//
// create an auto-hiding color picker control
function createColorPicker(valueChanged) {
// create color picker
let host = wjCore.createElement('<div class="wj-dropdown-panel"></div>');
let picker = new wjInput.ColorPicker(host, {
lostFocus: function (s) {
wjCore.hidePopup(s.hostElement);
}
});
//
// apply color and close picker on clicks
host.addEventListener('click', function () {
wjCore.hidePopup(host);
valueChanged(picker);
});
//
// done
return picker;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>MESCIUS Wijmo TabPanel Ribbon</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- SystemJS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.21.5/system.src.js" integrity="sha512-skZbMyvYdNoZfLmiGn5ii6KmklM82rYX2uWctBhzaXPxJgiv4XBwJnFGr5k8s+6tE1pcR1nuTKghozJHyzMcoA==" crossorigin="anonymous"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('./src/app');
</script>
</head>
<body>
<div class="container-fluid">
<div id="ribbon">
<!-- Format tab -->
<div>
<div>書式</div>
<div>
<div class="wj-group">
<div class="wj-content">
<div class="wj-column">
<button id="save" class="wj-btn wj-btn-large">
<i class="material-icons">save</i>
<br />
保存
</button>
</div>
<div class="wj-column">
<div class="wj-row">
<button id="undo" class="wj-btn" aria-label="元に戻す">
<i class="material-icons">undo</i>
</button>
<button id="redo" class="wj-btn" aria-label="繰り返し">
<i class="material-icons">redo</i>
</button>
<button id="preview" class="wj-btn" aria-label="プレビュー">
<i class="material-icons">pageview</i>
</button>
<button id="removeFormat" class="wj-btn" aria-label="書式を削除">
<i class="material-icons">format_clear</i>
</button>
</div>
<div class="wj-row">
<button id="cut" class="wj-btn" aria-label="切り取り">
<i class="material-icons">✂</i>
</button>
<button id="copy" class="wj-btn" aria-label="コピー">
<i class="material-icons"></i>
</button>
<button id="paste" class="wj-btn" aria-label="貼り付け">
<i class="material-icons"></i>
</button>
<button id="selectAll" class="wj-btn" aria-label="すべてを選択">
<i class="material-icons">select_all</i>
</button>
</div>
</div>
</div>
<div class="wj-header">アクション</div>
</div>
<div class="wj-group">
<div class="wj-content">
<div class="wj-row">
<div id="font-face" aria-label="フォント"></div>
<div id="font-size" aria-label="フォントサイズ"></div>
<button id="background" class="wj-btn" aria-label="背景色">
<i class="material-icons">format_color_fill</i>
</button>
<button id="color" class="wj-btn" aria-label="フォントの色">
<i class="material-icons">format_color_text</i>
</button>
</div>
<div class="wj-row">
<button id="bold" class="wj-btn" aria-label="太字">
<i class="material-icons">format_bold</i>
</button>
<button id="italic" class="wj-btn" aria-label="斜体">
<i class="material-icons">format_italic</i>
</button>
<button id="underline" class="wj-btn" aria-label="下線">
<i class="material-icons">format_underline</i>
</button>
<button id="strikethrough" class="wj-btn" aria-label="取り消し線">
<i class="material-icons">format_strikethrough</i>
</button>
<button id="subscript" class="wj-btn" aria-label="下付き">
<i class="material-icons">vertical_align_bottom</i>
</button>
<button id="superscript" class="wj-btn" aria-label="上付き">
<i class="material-icons">vertical_align_top</i>
</button>
</div>
</div>
<div class="wj-header">フォント</div>
</div>
</div>
</div>
<!-- Custom Tab -->
<div>
<div>カスタムタブ</div>
<div>
<div class="wj-group">
<div class="wj-content">
<div class="wj-column">
<button id="click-me" class="wj-btn wj-btn-large">
カスタムボタン
</button>
</div>
</div>
<div class="wj-header">カスタムグループ</div>
</div>
</div>
</div>
</div>
<div id="editor" contenteditable="true">
<b>Wijmoを選ぶ理由</b><br>Wijmoは業務アプリケーション開発での利用に最適化されています。導入による開発工数の削減効果はもちろんのこと、運用開始後の保守性にも優れたライブラリです。
</div>
</div>
</body>
</html>
@import url('https://fonts.googleapis.com/icon?family=Material+Icons');
.wj-tabpane {
white-space: nowrap; /* keep groups on a single line */
}
.wj-group {
display: inline-block;
border-right: 1px solid #eee;
padding: 3px 6px 0 3px;
}
.wj-group >.wj-header {
text-align: center;
background: transparent;
font-weight: normal;
font-size: 80%;
margin-top: 6px;
}
.wj-group >.wj-content {
border: none;
height: 5.5em;
overflow: visible;
}
.wj-group .wj-column {
display: inline-block;
vertical-align: top;
}
.wj-group .wj-row {
margin-bottom: 2px;
}
.wj-control .wj-group .wj-content .wj-btn {
font-weight: normal;
padding: 5px 12px;
}
.wj-group .wj-content .wj-btn.wj-btn-large {
padding: 2em 1.5em;
}
.wj-group .material-icons {
font-size: 110%;
padding-top: 2px;
pointer-events: none;
}
.wj-group .wj-dropdown {
width: 10em;
border: none;
background: #eee;
}
/* hide ribbon content */
.wj-tabpanel.hide-content .wj-tabpanes {
height: 0;
transition: height linear 400ms;
}
#editor {
height: 300px;
overflow: auto;
padding: 12px;
background: #ffe;
border: 1px solid #ccc;
}
body {
margin-bottom: 36pt;
}
(function (global) {
System.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true
},
meta: {
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'jszip': 'npm:jszip/dist/jszip.js',
'@mescius/wijmo': 'npm:@mescius/wijmo/index.js',
'@mescius/wijmo.input': 'npm:@mescius/wijmo.input/index.js',
'@mescius/wijmo.styles': 'npm:@mescius/wijmo.styles',
'@mescius/wijmo.cultures': 'npm:@mescius/wijmo.cultures',
'@mescius/wijmo.chart': 'npm:@mescius/wijmo.chart/index.js',
'@mescius/wijmo.chart.analytics': 'npm:@mescius/wijmo.chart.analytics/index.js',
'@mescius/wijmo.chart.animation': 'npm:@mescius/wijmo.chart.animation/index.js',
'@mescius/wijmo.chart.annotation': 'npm:@mescius/wijmo.chart.annotation/index.js',
'@mescius/wijmo.chart.finance': 'npm:@mescius/wijmo.chart.finance/index.js',
'@mescius/wijmo.chart.finance.analytics': 'npm:@mescius/wijmo.chart.finance.analytics/index.js',
'@mescius/wijmo.chart.hierarchical': 'npm:@mescius/wijmo.chart.hierarchical/index.js',
'@mescius/wijmo.chart.interaction': 'npm:@mescius/wijmo.chart.interaction/index.js',
'@mescius/wijmo.chart.radar': 'npm:@mescius/wijmo.chart.radar/index.js',
'@mescius/wijmo.chart.render': 'npm:@mescius/wijmo.chart.render/index.js',
'@mescius/wijmo.chart.webgl': 'npm:@mescius/wijmo.chart.webgl/index.js',
'@mescius/wijmo.chart.map': 'npm:@mescius/wijmo.chart.map/index.js',
'@mescius/wijmo.gauge': 'npm:@mescius/wijmo.gauge/index.js',
'@mescius/wijmo.grid': 'npm:@mescius/wijmo.grid/index.js',
'@mescius/wijmo.grid.detail': 'npm:@mescius/wijmo.grid.detail/index.js',
'@mescius/wijmo.grid.filter': 'npm:@mescius/wijmo.grid.filter/index.js',
'@mescius/wijmo.grid.search': 'npm:@mescius/wijmo.grid.search/index.js',
'@mescius/wijmo.grid.grouppanel': 'npm:@mescius/wijmo.grid.grouppanel/index.js',
'@mescius/wijmo.grid.multirow': 'npm:@mescius/wijmo.grid.multirow/index.js',
'@mescius/wijmo.grid.transposed': 'npm:@mescius/wijmo.grid.transposed/index.js',
'@mescius/wijmo.grid.transposedmultirow': 'npm:@mescius/wijmo.grid.transposedmultirow/index.js',
'@mescius/wijmo.grid.pdf': 'npm:@mescius/wijmo.grid.pdf/index.js',
'@mescius/wijmo.grid.sheet': 'npm:@mescius/wijmo.grid.sheet/index.js',
'@mescius/wijmo.grid.xlsx': 'npm:@mescius/wijmo.grid.xlsx/index.js',
'@mescius/wijmo.grid.selector': 'npm:@mescius/wijmo.grid.selector/index.js',
'@mescius/wijmo.grid.cellmaker': 'npm:@mescius/wijmo.grid.cellmaker/index.js',
'@mescius/wijmo.nav': 'npm:@mescius/wijmo.nav/index.js',
'@mescius/wijmo.odata': 'npm:@mescius/wijmo.odata/index.js',
'@mescius/wijmo.olap': 'npm:@mescius/wijmo.olap/index.js',
'@mescius/wijmo.rest': 'npm:@mescius/wijmo.rest/index.js',
'@mescius/wijmo.pdf': 'npm:@mescius/wijmo.pdf/index.js',
'@mescius/wijmo.pdf.security': 'npm:@mescius/wijmo.pdf.security/index.js',
'@mescius/wijmo.viewer': 'npm:@mescius/wijmo.viewer/index.js',
'@mescius/wijmo.xlsx': 'npm:@mescius/wijmo.xlsx/index.js',
'@mescius/wijmo.undo': 'npm:@mescius/wijmo.undo/index.js',
'@mescius/wijmo.interop.grid': 'npm:@mescius/wijmo.interop.grid/index.js',
'@mescius/wijmo.touch': 'npm:@mescius/wijmo.touch/index.js',
'@mescius/wijmo.cloud': 'npm:@mescius/wijmo.cloud/index.js',
'@mescius/wijmo.barcode': 'npm:@mescius/wijmo.barcode/index.js',
'@mescius/wijmo.barcode.common': 'npm:@mescius/wijmo.barcode.common/index.js',
'@mescius/wijmo.barcode.composite': 'npm:@mescius/wijmo.barcode.composite/index.js',
'@mescius/wijmo.barcode.specialized': 'npm:@mescius/wijmo.barcode.specialized/index.js',
'jszip': 'npm:jszip/dist/jszip.js',
'bootstrap.css': 'npm:bootstrap/dist/css/bootstrap.min.css',
'css': 'npm:systemjs-plugin-css/css.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'js'
},
"node_modules": {
defaultExtension: 'js'
},
}
});
})(this);