2012-11-07 00:09:38 +00:00
|
|
|
<!--
|
|
|
|
/**
|
2013-01-26 03:29:21 +00:00
|
|
|
* VisualEditor trigger demo
|
2012-11-07 00:09:38 +00:00
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
2013-02-19 23:37:34 +00:00
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
2012-11-07 00:09:38 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
-->
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
2013-01-26 03:29:21 +00:00
|
|
|
<title>VisualEditor Trigger Demo</title>
|
2012-11-07 00:09:38 +00:00
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
font-size: 1em;
|
|
|
|
font-family: sans-serif;
|
|
|
|
cursor: default;
|
|
|
|
}
|
|
|
|
ul {
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
list-style: none;
|
|
|
|
}
|
|
|
|
.flow li {
|
|
|
|
display: inline-block;
|
|
|
|
}
|
|
|
|
.stack li {
|
|
|
|
display: inline-block;
|
|
|
|
white-space: nowrap;
|
|
|
|
padding: 0.75em;
|
|
|
|
margin: 0.125em;
|
|
|
|
border: solid 1px #ccc;
|
|
|
|
background-color: #eee;
|
|
|
|
border-radius: 0.5em;
|
|
|
|
}
|
|
|
|
.key {
|
|
|
|
display: inline-block;
|
|
|
|
cursor: pointer;
|
|
|
|
color: #fff;
|
|
|
|
background-color: #555;
|
|
|
|
margin: 0.125em;
|
|
|
|
padding: 0.75em;
|
|
|
|
border-radius: 0.25em;
|
|
|
|
border: outset 2px #555;
|
|
|
|
-moz-user-select: none;
|
|
|
|
-webkit-user-select: none;
|
|
|
|
-ms-user-select: none;
|
|
|
|
user-select: none;
|
|
|
|
}
|
|
|
|
.alias {
|
|
|
|
color: #bbb;
|
|
|
|
}
|
|
|
|
.active {
|
|
|
|
border: inset 2px #444;
|
|
|
|
background-color: #333;
|
|
|
|
text-shadow: 0 0 0.5em #fff
|
|
|
|
}
|
|
|
|
table {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
td {
|
|
|
|
padding: 3em;
|
|
|
|
vertical-align: top;
|
|
|
|
}
|
|
|
|
h1 {
|
|
|
|
padding: 1.5em;
|
|
|
|
padding-bottom: 0;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
h2 {
|
|
|
|
font-weight: normal;
|
|
|
|
}
|
|
|
|
.title {
|
|
|
|
color: #777;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
2013-01-26 03:29:21 +00:00
|
|
|
<h1><span class="title">Key sequence: </span><span id="trigger"></span></h1>
|
2012-11-07 00:09:38 +00:00
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<h2 class="title">Modifiers</h2>
|
|
|
|
<ul id="modifiers" class="flow"></ul>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<h2 class="title">Primary</h2>
|
|
|
|
<ul id="primary" class="flow"></ul>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td colspan="2">
|
|
|
|
<h2 class="title">Aliases</h2>
|
|
|
|
<ul id="aliases" class="stack"></ul>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<script src="../../modules/jquery/jquery.js"></script>
|
2013-10-15 23:16:06 +00:00
|
|
|
<script src="../../modules/oojs/oojs.js"></script>
|
2013-07-29 23:27:43 +00:00
|
|
|
<script src="../../modules/unicodejs/unicodejs.js"></script>
|
|
|
|
<script src="../../modules/unicodejs/unicodejs.graphemebreak.js"></script>
|
|
|
|
<script src="../../modules/unicodejs/unicodejs.graphemebreakproperties.js"></script>
|
|
|
|
<script src="../../modules/unicodejs/unicodejs.textstring.js"></script>
|
|
|
|
<script src="../../modules/unicodejs/unicodejs.wordbreak.js"></script>
|
|
|
|
<script src="../../modules/unicodejs/unicodejs.wordbreakproperties.js"></script>
|
2012-11-07 00:09:38 +00:00
|
|
|
<script src="../../modules/ve/ve.js"></script>
|
2013-07-29 23:27:43 +00:00
|
|
|
<script src="../../modules/ve/ui/ve.ui.js"></script>
|
|
|
|
<script src="../../modules/ve/ui/ve.ui.Trigger.js"></script>
|
2012-11-07 00:09:38 +00:00
|
|
|
<script>
|
2013-01-26 03:29:21 +00:00
|
|
|
function setTrigger( trigger ) {
|
2012-11-07 00:09:38 +00:00
|
|
|
var i, len, key,
|
2013-01-26 03:29:21 +00:00
|
|
|
trigger = trigger.toString(),
|
2012-11-07 00:09:38 +00:00
|
|
|
parts = trigger.split( '+' );
|
2013-01-26 03:29:21 +00:00
|
|
|
$( '#trigger' ).text( trigger );
|
2012-11-07 00:09:38 +00:00
|
|
|
for ( i = 0, len = parts.length; i < len; i++ ) {
|
|
|
|
key = parts[i].replace( '\\', '\\\\' ).replace( '"', '\\"' );
|
|
|
|
$( '.key[rel="' + key + '"]' ).addClass( 'active' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialiation
|
|
|
|
|
|
|
|
var i, len, key,
|
|
|
|
$primary = $( '#primary' ),
|
|
|
|
$modifiers = $( '#modifiers' ),
|
|
|
|
$aliases = $( '#aliases' ),
|
2013-07-29 23:27:43 +00:00
|
|
|
primaryKeys = ve.ui.Trigger.static.primaryKeys,
|
|
|
|
modifierKeys = ve.ui.Trigger.static.modifierKeys,
|
|
|
|
keyAliases = ve.ui.Trigger.static.keyAliases;
|
2012-11-07 00:09:38 +00:00
|
|
|
|
|
|
|
for ( i = 0, len = modifierKeys.length; i < len; i++ ) {
|
|
|
|
$modifiers.append(
|
|
|
|
$( '<li>' ).append(
|
|
|
|
$( '<span class="key"></span>' )
|
|
|
|
.text( modifierKeys[i] )
|
|
|
|
.attr( 'rel', modifierKeys[i] )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
for ( i = 0, len = primaryKeys.length; i < len; i++ ) {
|
|
|
|
$primary.append(
|
|
|
|
$( '<li>' ).append(
|
|
|
|
$( '<span class="key"></span>' )
|
|
|
|
.text( primaryKeys[i] )
|
|
|
|
.attr( 'rel', primaryKeys[i] )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
for ( key in keyAliases ) {
|
|
|
|
$aliases.append(
|
|
|
|
$( '<li>' )
|
|
|
|
.append( $( '<span class="key alias"></span>' ).text( key ) )
|
|
|
|
.append( '⇢' )
|
|
|
|
.append( $( '<span class="key"></span>' ).text( keyAliases[key] ) )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Events
|
|
|
|
|
|
|
|
$( 'body' ).on( {
|
|
|
|
'keydown': function ( e ) {
|
|
|
|
$( '.active' ).removeClass( 'active' );
|
2013-07-29 23:27:43 +00:00
|
|
|
setTrigger( new ve.ui.Trigger( e ) );
|
2012-11-07 00:09:38 +00:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
$( '#primary .key, #modifiers .key' ).on( {
|
|
|
|
'mousedown': function( e ) {
|
|
|
|
var $target = $( e.target );
|
|
|
|
if ( e.which === 1 ) {
|
|
|
|
if ( $target.closest( '#primary' ).length ) {
|
|
|
|
$primary.find( '.active' ).removeClass( 'active' );
|
|
|
|
}
|
|
|
|
if ( !$target.hasClass( 'active' ) ) {
|
|
|
|
$target.addClass( 'active activating' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'mouseup': function( e ) {
|
|
|
|
var parts = [],
|
|
|
|
$target = $( e.target );
|
|
|
|
if ( e.which === 1 ) {
|
|
|
|
if ( $target.hasClass( 'active' ) && !$target.hasClass( 'activating' ) ) {
|
|
|
|
$target.removeClass( 'active' );
|
|
|
|
}
|
|
|
|
$target.removeClass( 'activating' );
|
|
|
|
$( '.active' ).each( function () {
|
|
|
|
parts.push( $(this).attr( 'rel' ) );
|
|
|
|
} );
|
2013-07-29 23:27:43 +00:00
|
|
|
setTrigger( new ve.ui.Trigger( parts.join( '+' ) ) );
|
2012-11-07 00:09:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|