InputManJSでは、ツアーコンポーネントへのアクションに応じてさまざまなイベントが発生します。
ツアーコンポーネントで発生するイベントは、以下の通りです。
イベント名
説明
StepChanging
ステップが切り替わる直前に発生します。
StepChanged
ステップが切り替わった直後に発生します。
Closed
ツアーが終了したときに発生します。
import '@mescius/inputman/CSS/gc.inputman-js.css';
import { InputMan } from '@mescius/inputman';
InputMan.appearanceStyle = InputMan.AppearanceStyle.Modern;
const username = new InputMan.GcTextBox(document.getElementById('username'), {
watermarkDisplayNullText: '例)入力太郎',
exitOnEnterKey: InputMan.ExitKey.Both,
width: 250,
height: 32,
});
const mail = new InputMan.GcMask(document.getElementById('mail'), {
exitOnEnterKey: InputMan.ExitKey.Both,
width: 250,
height: 32,
});
const phone = new InputMan.GcMask(document.getElementById('phone'), {
formatPattern: '\\D{2,3}-\\D{2,3}-\\D{4}',
exitOnEnterKey: InputMan.ExitKey.Both,
width: 250,
height: 32,
});
const password1 = new InputMan.GcTextBox(document.getElementById('password1'), {
useSystemPasswordChar: true,
exitOnEnterKey: InputMan.ExitKey.Both,
width: 250,
height: 32,
});
const password2 = new InputMan.GcTextBox(document.getElementById('password2'), {
useSystemPasswordChar: true,
exitOnEnterKey: InputMan.ExitKey.Both,
width: 250,
height: 32,
});
const gctour = new InputMan.GcTour({
steps: [
{
title: 'アカウント登録フォームへようこそ',
description: '会員情報を入力し、送信してください。',
},
{
target: username,
title: 'お名前',
description: 'お名前を入力してください',
},
{
target: mail,
title: 'メールアドレス',
description: '正しいメールアドレス形式で入力してください',
},
{
target: phone,
title: '電話番号',
description: '正しい電話番号形式で入力してください',
},
{
target: password1,
title: 'パスワード',
description: 'パスワードを6文字以上に入力してください',
},
{
target: password2,
title: 'パスワードの確認',
description: 'パスワードと同じ内容を入力してください',
}
],
});
document.getElementById('start-tour').onclick = function () {
gctour.start(true);
};
setTimeout(() => {
gctour.start();
}, 1000);
// イベントハンドラ
gctour.addEventListener(InputMan.GcTourEvent.StepChanging, (s, e) => {
log(`StepChanging: oldIndex=${e.oldIndex}, newIndex=${e.newIndex}`);
});
gctour.addEventListener(InputMan.GcTourEvent.StepChanged, (s, e) => {
log(`StepChanged: oldIndex=${e.oldIndex}, newIndex=${e.newIndex}`);
});
gctour.addEventListener(InputMan.GcTourEvent.Closed, (s, e) => {
log(`TourClosed`);
});
// テキストボックスにログを出力
const log = (message) => {
const textarea = document.getElementById('log');
textarea.value += message + '\n';
textarea.scrollTop = textarea.scrollHeight;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>ツアーコンポーネント - イベント</title>
<!-- SystemJS -->
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
window.onload = function () {
System.import('./src/app');
}
</script>
</head>
<body>
<div class="container">
<button class="tour-start-btn" id="start-tour">入力ガイドを開始</button>
</div>
<div id="form1">
<div class="form-group">
<label for="username">名前</label>
<input id="username" />
</div>
<div class="form-group">
<label for="mail">メールアドレス</label>
<input id="mail" />
</div>
<div class="form-group">
<label>電話番号</label>
<input id="phone" />
</div>
<div class="form-group">
<label>パスワード</label>
<input id="password1" />
</div>
<div class="form-group">
<label>パスワードの確認</label>
<input id="password2" />
</div>
</div>
イベント<br>
<textarea id="log" rows="10" cols="60"></textarea>
</body>
</html>
.tour-start-btn {
background: #67c23a;
color: white;
padding: 8px 16px;
border: none;
border-radius: 4px;
cursor: pointer;
display: block;
margin: 30px auto 10px auto;
max-width: 250px;
font-size: 12px;
}
#form1 {
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
margin: 20px auto;
max-width: 500px;
width: 90%;
}
.form-group {
display: grid;
grid-template-columns: 150px 1fr;
align-items: center;
gap: 15px;
margin-bottom: 20px;
max-width: 400px;
margin-left: auto;
margin-right: auto;
}
.form-group label {
font-weight: 600;
color: #333;
font-size: 14px;
text-align: left;
padding-right: 10px;
}
.gcim_watermark_null {
color: lightgrey;
}
.tour-start-btn {
background: #67c23a;
color: white;
padding: 8px 16px;
border: none;
border-radius: 4px;
cursor: pointer;
display: block;
margin: 30px auto 10px auto;
max-width: 250px;
font-size: 12px;
}
#form1 {
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
margin: 20px auto;
max-width: 500px;
width: 90%;
}
.form-group {
display: grid;
grid-template-columns: 150px 1fr;
align-items: center;
gap: 15px;
margin-bottom: 20px;
max-width: 400px;
margin-left: auto;
margin-right: auto;
}
.form-group label {
font-weight: 600;
color: #333;
font-size: 14px;
text-align: left;
padding-right: 10px;
}
[gcim-control-appearance="modern"] .gcim_watermark_null {
color: lightgrey;
}
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: {
'@mescius/inputman': 'npm:@mescius/inputman/index.js',
'@mescius/inputman/CSS': 'npm:@mescius/inputman/CSS',
'@mescius/inputman.richtexteditor': 'npm:@mescius/inputman.richtexteditor/index.js',
"@mescius/inputman.richtexteditor/CSS": "npm:@mescius/inputman.richtexteditor/CSS",
'@mescius/inputman.richtexteditor/JS/plugins/advlist': 'npm:@mescius/inputman.richtexteditor/JS/plugins/advlist/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/all': 'npm:@mescius/inputman.richtexteditor/JS/plugins/all/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/autosave': 'npm:@mescius/inputman.richtexteditor/JS/plugins/autosave/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/charmap': 'npm:@mescius/inputman.richtexteditor/JS/plugins/charmap/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/directionality': 'npm:@mescius/inputman.richtexteditor/JS/plugins/directionality/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/emoticons': 'npm:@mescius/inputman.richtexteditor/JS/plugins/emoticons/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/fullscreen': 'npm:@mescius/inputman.richtexteditor/JS/plugins/fullscreen/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/htmlcode': 'npm:@mescius/inputman.richtexteditor/JS/plugins/htmlcode/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/image': 'npm:@mescius/inputman.richtexteditor/JS/plugins/image/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/link': 'npm:@mescius/inputman.richtexteditor/JS/plugins/link/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/lists': 'npm:@mescius/inputman.richtexteditor/JS/plugins/lists/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/media': 'npm:@mescius/inputman.richtexteditor/JS/plugins/media/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/pagebreak': 'npm:@mescius/inputman.richtexteditor/JS/plugins/pagebreak/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/preview': 'npm:@mescius/inputman.richtexteditor/JS/plugins/preview/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/save': 'npm:@mescius/inputman.richtexteditor/JS/plugins/save/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/searchreplace': 'npm:@mescius/inputman.richtexteditor/JS/plugins/searchreplace/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/table': 'npm:@mescius/inputman.richtexteditor/JS/plugins/table/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/template': 'npm:@mescius/inputman.richtexteditor/JS/plugins/template/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/wordcount': 'npm:@mescius/inputman.richtexteditor/JS/plugins/wordcount/plugin.js',
'@mescius/inputman.comment': 'npm:@mescius/inputman.comment/index.js',
'@mescius/inputman.comment/CSS': 'npm:@mescius/inputman.comment/CSS',
'@mescius/wijmo': 'npm:@mescius/wijmo/index.js',
'@mescius/wijmo.styles': 'npm:@mescius/wijmo.styles',
'@mescius/wijmo.cultures': 'npm:@mescius/wijmo.cultures',
'@mescius/wijmo.input': 'npm:@mescius/wijmo.input/index.js',
'@mescius/wijmo.grid': 'npm:@mescius/wijmo.grid/index.js',
'@mescius/wijmo.nav': 'npm:@mescius/wijmo.nav/index.js',
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-resources-ja': 'npm:@mescius/spread-sheets-resources-ja/index.js',
'@mescius/spread-sheets/styles': 'npm:@mescius/spread-sheets/styles',
'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'
},
}
});