Created
August 29, 2012 09:29
-
-
Save evo42/3509018 to your computer and use it in GitHub Desktop.
Aloha/UI: using Aloha Editor commands API for your own toolbar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<link rel="stylesheet" href="http://aloha-editor.org/builds/development/latest/src/css/aloha.css" | |
type="text/css"> | |
<script src="http://aloha-editor.org/builds/development/latest/src/lib/aloha.js"></script> | |
</head> | |
<body> | |
<button id="bold">Bold</button> | |
<div class="edit">This is some content</div> | |
<script> | |
// Bind to Aloha Ready Event | |
Aloha.ready(function () { | |
var $ = jQuery = Aloha.jQuery; | |
$('.edit').aloha(); | |
var button = jQuery('#bold'); | |
button.attr('disabled', (Aloha.queryCommandSupported('bold') && Aloha.queryCommandEnabled('bold'))); | |
button.click(function () { | |
Aloha.execCommand('bold', false, ''); | |
updateBoldColor(); | |
}); | |
Aloha.bind('aloha-selection-changed', function () { | |
updateBoldColor(); | |
}); | |
function updateBoldColor() { | |
if (Aloha.queryCommandIndeterm('bold')) { | |
button.css('background-color', 'yellow'); | |
return; | |
} | |
button.css('background-color', Aloha.queryCommandState('bold') ? 'lightgreen' : 'orange'); | |
} | |
// update the color on startup | |
updateBoldColor(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment