Permalink
Browse files

Update and mostly fix the test editor

  • Loading branch information...
1 parent 086d814 commit a75175fc44edd6a818f137452e419cbf8c9ca314 @nhowell committed Sep 12, 2011
View
@@ -12,13 +12,13 @@ WYSIHAT_SRC_DIR = File.join(WYSIHAT_ROOT, 'src')
# Distribution
-file 'dist/jquery-1.6.3.min.js' => :sprockets do |t|
+file 'dist/jquery.js' => :sprockets do |t|
jquery_src_dir = "#{WYSIHAT_ROOT}/vendor/jquery"
env = Sprockets::Environment.new
env.prepend_path jquery_src_dir
FileUtils.mkdir_p File.dirname(t.name)
- File.open(t.name, 'w') {|f| f.write(env['jquery-1.6.3.min.js'].to_s) }
+ File.open(t.name, 'w') {|f| f.write(env['jquery-1.6.3.js'].to_s) }
end
file 'dist/jq-wysihat.js' => Dir['src/**/*'] + [:sprockets] do |t|
@@ -31,7 +31,7 @@ end
task :default => :dist
desc "Builds the distribution."
-task :dist => ['dist/jquery-1.6.3.min.js', 'dist/jq-wysihat.js']
+task :dist => ['dist/jquery.js', 'dist/jq-wysihat.js']
# Documentation
@@ -5,14 +5,14 @@
<link rel="stylesheet" href="editor.css" type="text/css" />
- <script type="text/javascript" src="../dist/jquery-1.6.3.min.js"></script>
+ <script type="text/javascript" src="../dist/jquery.js"></script>
<script type="text/javascript" src="../dist/jq-wysihat.js"></script>
<script type="text/javascript" charset="utf-8">
- $(document).ready(function() {
+ $(function() {
var editor = WysiHat.Editor.attach($('#content'));
var toolbar = new WysiHat.Toolbar(editor);
- toolbar.initialize(editor);
+ toolbar.initialize(editor);
toolbar.addButton({ name: 'bold', label: "Strong" });
@@ -37,10 +37,10 @@
<p>This examples shows how to add custom buttons and actions with the built-in toolbar class.</p>
<code><pre>
- $(document).ready(function() {
+ $(document).ready(function() {
var editor = WysiHat.Editor.attach($('#content'));
var toolbar = new WysiHat.Toolbar(editor);
- toolbar.initialize(editor);
+ toolbar.initialize(editor);
// The name will be used for the div class and the command to execute
// The label is the text you see for the button.
@@ -5,11 +5,11 @@
<link rel="stylesheet" href="editor.css" type="text/css" />
- <script type="text/javascript" src="../dist/jquery-1.6.3.min.js"></script>
+ <script type="text/javascript" src="../dist/jquery.js"></script>
<script type="text/javascript" src="../dist/jq-wysihat.js"></script>
<script type="text/javascript" charset="utf-8">
- $(document).ready(function() {
+ $(function() {
var editor = WysiHat.Editor.attach($("#content"));
var boldButton = $('.editor_toolbar .bold').first();
@@ -5,7 +5,7 @@
<link rel="stylesheet" href="editor.css" type="text/css" />
- <script type="text/javascript" src="../dist/jquery-1.6.3.min.js"></script>
+ <script type="text/javascript" src="../dist/jquery.js"></script>
<script type="text/javascript" src="../dist/jq-wysihat.js"></script>
<script type="text/javascript" charset="utf-8">
@@ -20,10 +20,10 @@
}
}
- $(document).ready(function() {
+ $(function() {
var editor = WysiHat.Editor.attach($('#content'));
var toolbar = new WysiHat.Toolbar(editor);
- toolbar.initialize(editor);
+ toolbar.initialize(editor);
toolbar.addButton({
label: "Link",
View
@@ -5,15 +5,15 @@
<link rel="stylesheet" href="editor.css" type="text/css" />
- <script type="text/javascript" src="../dist/jquery-1.6.3.min.js"></script>
+ <script type="text/javascript" src="../dist/jquery.js"></script>
<script type="text/javascript" src="../dist/jq-wysihat.js"></script>
<script type="text/javascript" charset="utf-8">
- $(document).ready(function() {
- var editor = WysiHat.Editor.attach($('#content'));
+ $(function() {
+ var editor = WysiHat.Editor.attach($('#content'));
var toolbar = new WysiHat.Toolbar(editor);
- toolbar.initialize(editor);
-
+ toolbar.initialize(editor);
+
toolbar.addButton({
label: "Ordered List",
handler: function(editor) { return editor.toggleOrderedList(); }
@@ -39,7 +39,7 @@
$(document).ready(function() {
var editor = WysiHat.Editor.attach('content');
var toolbar = new WysiHat.Toolbar(editor);
- toolbar.initialize(editor);
+ toolbar.initialize(editor);
toolbar.addButton({
label: "Ordered List",
View
@@ -5,7 +5,7 @@
<link rel="stylesheet" href="editor.css" type="text/css" />
- <script type="text/javascript" src="../dist/jquery-1.6.3.min.js"></script>
+ <script type="text/javascript" src="../dist/jquery.js"></script>
<script type="text/javascript" src="../dist/jq-wysihat.js"></script>
<script type="text/javascript" charset="utf-8">
View
@@ -1,22 +1,16 @@
//= require "./wysihat/header"
-//
//= require "./wysihat/editor"
//= require "./wysihat/features"
//= require "./wysihat/commands"
-//
//= require "./wysihat/dom/ierange"
//= require "./wysihat/dom/range"
//= require "./wysihat/dom/selection"
//= require "./wysihat/dom/bookmark"
-//
//= require "./wysihat/element/sanitize_contents"
-//
//= require "./wysihat/events/field_change"
//= require "./wysihat/events/frame_loaded"
//= require "./wysihat/events/selection_change"
-//
//= require "./wysihat/formatting"
-//
//= require "./wysihat/toolbar"
// Set wysihat as a jQuery plugin
View
@@ -9,23 +9,22 @@ WysiHat.Editor = {
*
* Creates a new editor for the textarea.
**/
- attach: function($textarea) {
- var $editArea;
+ attach: function(textarea) {
+ var id = textarea.attr('id') + '_editor';
+ var editArea = $('#' + id);
+ if (editArea.length) { return editArea; }
- var id = $textarea.attr('id') + '_editor';
- if ($editArea == $('#' + id)) { return $editArea; }
+ editArea = $('<div id="' + id + '" class="editor" contentEditable="true"></div>');
- $editArea = $('<div id="' + id + '" class="editor" contentEditable="true"></div>');
+ editArea.html(WysiHat.Formatting.getBrowserMarkupFrom(textarea.val()));
- $editArea.html(WysiHat.Formatting.getBrowserMarkupFrom($textarea.val()));
+ jQuery.extend(editArea, WysiHat.Commands);
- jQuery.extend($editArea, WysiHat.Commands);
-
- $textarea.before($editArea);
- $textarea.hide();
+ textarea.before(editArea);
+ textarea.hide();
// WysiHat.BrowserFeatures.run()
- return $editArea;
+ return editArea;
}
};
@@ -52,9 +52,9 @@
return element;
}
- function onFrameLoaded($element, callback) {
- $element.bind('frame:loaded', callback);
- $element.observeFrameContentLoaded();
+ function onFrameLoaded(element, callback) {
+ element.bind('frame:loaded', callback);
+ element.observeFrameContentLoaded();
}
jQuery.fn.observeFrameContentLoaded = observeFrameContentLoaded;
@@ -1,13 +1,13 @@
$(document).ready(function() {
- var $doc = $(document);
+ var doc = $(document);
if ('selection' in document && 'onselectionchange' in document) {
var selectionChangeHandler = function() {
var range = document.selection.createRange();
var element = range.parentElement();
$(element).trigger("selection:change");
}
- $doc.bind("selectionchange", selectionChangeHandler);
+ doc.bind("selectionchange", selectionChangeHandler);
} else {
var previousRange;
@@ -36,7 +36,7 @@ $(document).ready(function() {
}
};
- $doc.mouseup(selectionChangeHandler);
- $doc.keyup(selectionChangeHandler);
+ doc.mouseup(selectionChangeHandler);
+ doc.keyup(selectionChangeHandler);
}
});
View
@@ -69,7 +69,7 @@ WysiHat.Formatting = (function() {
// if it's a block-level element and the line buffer is full, flush it
if (isBlockElement(tagName)) {
if (isEmptyParagraph(node)) {
- accumulate($("<br />"));
+ accumulate($("<br />").get(0));
}
flush();
@@ -173,11 +173,11 @@ WysiHat.Formatting = (function() {
var element = node.cloneNode(false);
if (tagName == "span") {
- if ($(node).getStyle("fontWeight") == "bold") {
- element = $("<strong></strong>");
+ if ($(node).css('fontWeight') == "bold") {
+ element = $("<strong></strong>").get(0);
- } else if ($(node).getStyle("fontStyle") == "italic") {
- element = $("<em></em>");
+ } else if ($(node).css('fontStyle') == "italic") {
+ element = $("<em></em>").get(0);
}
}
@@ -208,9 +208,9 @@ WysiHat.Formatting = (function() {
function createLine() {
if (mode == ACCUMULATING_LINE) {
- return $("<div></div>");
+ return $("<div></div>").get(0);
} else if (mode == ACCUMULATING_LIST_ITEM) {
- return $("<li></li>");
+ return $("<li></li>").get(0);
}
}
@@ -220,7 +220,7 @@ WysiHat.Formatting = (function() {
return list;
}
- result = container = $("<div></div>");
+ result = container = $("<div></div>").get(0);
walk(element.childNodes);
flush();
return result.innerHTML;
View
@@ -45,8 +45,8 @@
}
</style>
- <script type="text/javascript" src="../dist/prototype.js"></script>
- <script type="text/javascript" src="../dist/wysihat.js"></script>
+ <script type="text/javascript" src="../dist/jquery.js"></script>
+ <script type="text/javascript" src="../dist/jq-wysihat.js"></script>
<script type="text/javascript" charset="utf-8">
var textarea, editor;
@@ -62,32 +62,33 @@
}
}
- document.observe("dom:loaded", function() {
- editor = $('note_body_editor');
- Object.extend(editor, WysiHat.Commands);
-
+ $(function() {
+ editor = WysiHat.Editor.attach($('#note_body'));
+ jQuery.extend(editor, WysiHat.Commands);
var toolbar = new WysiHat.Toolbar(editor);
- toolbar.addButtonSet(WysiHat.Toolbar.ButtonSets.Basic);
+ toolbar.initialize(editor);
+
+ toolbar.addButtonSet({buttons: WysiHat.Toolbar.ButtonSets.Basic});
toolbar.addButton({
label: "Link",
handler: function(editor) { return editor.promptLinkSelection(); }
});
- editor.observe("field:change", function(event) {
- $('note_body').setValue(WysiHat.Formatting.getApplicationMarkupFrom(editor));
- $('note_body_raw').setValue(event.element().innerHTML);
- });
+ setInterval(function() {
+ $('#note_body').val(WysiHat.Formatting.getApplicationMarkupFrom(editor.get(0)));
+ $('#note_body_raw').val(editor.html());
+ }, 250);
- editor.observe("paste", function(event) {
- (function() {
+ //editor.observe("paste", function(event) {
+ //(function() {
// window.getSelection().setBookmark();
// editor.innerHTML = editor.innerHTML;
// window.getSelection().moveToBookmark();
- }).defer();
- });
+ //}).defer();
+ //});
- $('note_body').show();
+ $('#note_body').show();
});
</script>
</head>
Oops, something went wrong.

0 comments on commit a75175f

Please sign in to comment.