Permalink
Browse files

Change the plugin's return value to work with multiple editors

Change the default css class to 'button' for toolbar buttons.
Update a few of the examples.
  • Loading branch information...
1 parent 1899d76 commit 21a14f35045101ac0a4f1b89269262ac8aefc4d5 @nhowell nhowell committed Sep 14, 2011
Showing with 57 additions and 52 deletions.
  1. +1 −1 examples/editor.css
  2. +28 −29 examples/link_selection.html
  3. +2 −0 examples/simple.html
  4. +13 −8 src/wysihat.js
  5. +5 −4 src/wysihat/toolbar.js
  6. +8 −10 test/editor.html
View
@@ -13,7 +13,7 @@
margin: 0;
}
-.editor_toolbar .toolbar_button {
+.editor_toolbar .button {
float: left;
margin: 2px 5px;
}
@@ -9,23 +9,23 @@
<script type="text/javascript" src="../dist/jq-wysihat.js"></script>
<script type="text/javascript" charset="utf-8">
- WysiHat.Commands.promptLinkSelection = function() {
- if (this.linkSelected()) {
- if (confirm("Remove link?"))
- this.unlinkSelection();
- } else {
- var value = prompt("Enter a URL", "http://www.google.com/");
- if (value)
- this.linkSelection(value);
+ $(function() {
+ var editor;
+
+ WysiHat.Commands.promptLinkSelection = function() {
+ if (this.linkSelected()) {
+ if (confirm("Remove link?"))
+ this.unlinkSelection();
+ } else {
+ var value = prompt("Enter a URL", "http://www.google.com/");
+ if (value)
+ this.linkSelection(value);
+ }
}
- }
- $(function() {
- var editor = WysiHat.Editor.attach($('#content'));
- var toolbar = new WysiHat.Toolbar(editor);
- toolbar.initialize(editor);
+ editor = $('#content').wysihat();
- toolbar.addButton({
+ editor.toolbar.addButton({
label: "Link",
handler: function(editor) { return editor.promptLinkSelection(); }
});
@@ -42,27 +42,26 @@
<p>This example shows you how to create a simple UI for linking and unlinking selections</p>
<code><pre>
- WysiHat.Commands.promptLinkSelection = function() {
- if (this.linkSelected()) {
- if (confirm("Remove link?"))
- this.unlinkSelection();
- } else {
- var value = prompt("Enter a URL", "http://www.google.com/");
- if (value)
- this.linkSelection(value);
+ $(function() {
+ var editor;
+
+ WysiHat.Commands.promptLinkSelection = function() {
+ if (this.linkSelected()) {
+ if (confirm("Remove link?"))
+ this.unlinkSelection();
+ } else {
+ var value = prompt("Enter a URL", "http://www.google.com/");
+ if (value)
+ this.linkSelection(value);
+ }
}
- }
- $(document).ready(function() {
- var editor = WysiHat.Editor.attach($('#content'));
- var toolbar = new WysiHat.Toolbar(editor);
- toolbar.initialize(editor);
+ editor = $('#content').wysihat();
- toolbar.addButton({
+ editor.toolbar.addButton({
label: "Link",
handler: function(editor) { return editor.promptLinkSelection(); }
});
-
});
</pre></code>
@@ -11,6 +11,8 @@
<script type="text/javascript" charset="utf-8">
$(function() {
$('#content').wysihat();
+
+ // Hide our error message if the editor loads fine
$('#error').hide();
});
</script>
View
@@ -14,16 +14,21 @@
//= require "./wysihat/toolbar"
// Set wysihat as a jQuery plugin
-$.fn.wysihat = function(options) {
- options = typeof(options) != 'undefined' ? options : [];
- options = WysiHat.Toolbar.ButtonSets.Standard.concat(options);
+$.fn.wysihat = function(buttons) {
+ buttons = typeof(buttons) == 'undefined' ? WysiHat.Toolbar.ButtonSets.Basic : buttons;
- return this.each(function() {
- var editor = WysiHat.Editor.attach($(this));
- var toolbar = new WysiHat.Toolbar(editor);
- toolbar.initialize(editor);
- toolbar.addButtonSet(options);
+ var result;
+
+ this.each(function() {
+ var $editor = WysiHat.Editor.attach($(this));
+ var toolbar = new WysiHat.Toolbar($editor);
+ toolbar.initialize($editor);
+ toolbar.addButtonSet(buttons);
+ $editor.toolbar = toolbar;
+ if (result) result.add($editor); else result = $editor;
});
+
+ return result;
};
})(jQuery);
@@ -253,8 +253,9 @@ WysiHat.Toolbar.ButtonSets.Basic = [
* The most common set of buttons that I will be using.
**/
WysiHat.Toolbar.ButtonSets.Standard = [
- { label: "Bold", cssClass: 'toolbar_button' },
- { label: "Italic", cssClass: 'toolbar_button' },
- { label: "Bullets", cssClass: 'toolbar_button', handler: function(editor) { return editor.toggleUnorderedList(); } },
- { label: "Numbers", cssClass: 'toolbar_button', handler: function(editor) { return editor.toggleOrderedList(); } }
+ { label: "Bold"},
+ { label: "Italic"},
+ { label: "Underline"},
+ { label: "Bullets", handler: function(editor) { return editor.toggleUnorderedList(); } },
+ { label: "Numbers", handler: function(editor) { return editor.toggleOrderedList(); } }
];
View
@@ -50,7 +50,7 @@
<script type="text/javascript" charset="utf-8">
$(function() {
- var textarea, editor;
+ var editor;
WysiHat.Commands.promptLinkSelection = function() {
if (this.linkSelected()) {
@@ -63,16 +63,14 @@
}
}
- editor = WysiHat.Editor.attach($('#note_body'));
- var toolbar = new WysiHat.Toolbar(editor);
- toolbar.initialize(editor);
-
- toolbar.addButtonSet(WysiHat.Toolbar.ButtonSets.Standard);
+ var buttons = WysiHat.Toolbar.ButtonSets.Standard.concat([
+ {
+ label: "Link",
+ handler: function(editor) { return editor.promptLinkSelection(); }
+ }
+ ]);
- toolbar.addButton({
- label: "Link",
- handler: function(editor) { return editor.promptLinkSelection(); }
- });
+ editor = $('#note_body').wysihat(buttons);
$('#note_body').show();

0 comments on commit 21a14f3

Please sign in to comment.