Permalink
Browse files

wysihtml5 v0.2.0 - now library agnostic

  • Loading branch information...
Christopher Blum
Christopher Blum committed Jul 13, 2011
1 parent 64b67e3 commit 623afa8b624da0dcde8c88471e9b83126c938dbb
Showing with 10,554 additions and 8,329 deletions.
  1. +1 −1 LICENSE
  2. +53 −29 Makefile
  3. +20 −4 README.textile
  4. +82 −0 build/minify.js
  5. +4,224 −3,741 dist/{wysihtml5-0.1.0.js → wysihtml5-0.2.0.js}
  6. +242 −0 dist/wysihtml5-0.2.0.min.js
  7. +15 −12 examples/advanced.html
  8. +128 −2 examples/css/stylesheet.css
  9. +0 −1 examples/rules/spec.json
  10. +11 −19 examples/simple.html
  11. +139 −0 lib/base/base.js
  12. +0 −461 lib/rangy/rangy-cssclassapplier-wysihtml5.js
  13. +563 −0 parser_rules/advanced.js
  14. +32 −0 parser_rules/simple.js
  15. +7 −11 src/assert/html_equals.js
  16. +318 −0 src/browser.js
  17. +0 −267 src/browser_support.js
  18. +3 −4 src/commands.js
  19. +20 −23 src/commands/bold.js
  20. +54 −57 src/commands/createLink.js
  21. +15 −19 src/commands/fontSize.js
  22. +15 −20 src/commands/foreColor.js
  23. +95 −99 src/commands/formatBlock.js
  24. +42 −47 src/commands/formatInline.js
  25. +17 −21 src/commands/insertHTML.js
  26. +93 −100 src/commands/insertImage.js
  27. +20 −24 src/commands/insertLineBreak.js
  28. +55 −59 src/commands/insertOrderedList.js
  29. +56 −60 src/commands/insertUnorderedList.js
  30. +19 −23 src/commands/italic.js
  31. +14 −18 src/commands/justifyCenter.js
  32. +14 −18 src/commands/justifyLeft.js
  33. +14 −18 src/commands/justifyRight.js
  34. +14 −18 src/commands/underline.js
  35. +24 −23 src/{utils → dom}/auto_link.js
  36. +31 −0 src/dom/class.js
  37. +2 −2 src/{utils → dom}/contains.js
  38. +6 −6 src/{utils/convert_into_list.js → dom/convert_to_list.js}
  39. +11 −11 src/{utils → dom}/copy_attributes.js
  40. +73 −0 src/dom/copy_styles.js
  41. +26 −0 src/dom/delegate.js
  42. +5 −2 src/{utils/get_in_dom_element.js → dom/get_as_dom.js}
  43. +6 −6 src/{utils → dom}/get_parent_element.js
  44. +69 −0 src/dom/get_style.js
  45. +9 −9 src/{utils → dom}/has_element_with_class_name.js
  46. +3 −3 src/{utils → dom}/has_element_with_tag_name.js
  47. +15 −0 src/dom/insert.js
  48. +4 −16 src/{utils/insert_rules.js → dom/insert_css.js}
  49. +53 −0 src/dom/observe.js
  50. +28 −51 src/{utils/sanitize_html.js → dom/parse.js}
  51. +4 −4 src/{utils → dom}/remove_empty_text_nodes.js
  52. +3 −3 src/{utils → dom}/rename_element.js
  53. +2 −2 src/{utils/unwrap.js → dom/replace_with_child_nodes.js}
  54. +6 −6 src/{utils → dom}/resolve_list.js
  55. +258 −0 src/dom/sandbox.js
  56. +14 −0 src/dom/set_attributes.js
  57. +19 −0 src/dom/set_styles.js
  58. +42 −0 src/dom/simulate_placeholder.js
  59. +29 −0 src/dom/text_content.js
  60. +29 −68 src/editor.js
  61. +58 −0 src/lang/array.js
  62. +40 −0 src/lang/dispatcher.js
  63. +42 −0 src/lang/object.js
  64. +42 −0 src/lang/string.js
  65. +2 −2 src/quirks/clean_pasted_html.js
  66. +68 −63 src/quirks/ensure_proper_clearing.js
  67. +30 −0 src/quirks/get_correct_inner_html.js
  68. +20 −19 src/quirks/insert_line_break_on_return.js
  69. +6 −5 src/quirks/redraw.js
  70. +434 −0 src/selection/html_applier.js
  71. +450 −0 src/selection/selection.js
  72. +151 −130 src/toolbar/dialog.js
  73. +39 −32 src/toolbar/speech.js
  74. +229 −204 src/toolbar/toolbar.js
  75. +0 −16 src/utils/auto_focus.js
  76. +0 −451 src/utils/caret.js
  77. +0 −76 src/utils/copy_styles.js
  78. +0 −50 src/utils/get_style.js
  79. +0 −46 src/utils/observe.js
  80. +0 −240 src/utils/sandbox.js
  81. +0 −39 src/utils/simulate_placeholder.js
  82. +0 −102 src/utils/synchronizer.js
  83. +0 −25 src/utils/text_content.js
  84. +278 −256 src/views/composer.js
  85. +143 −142 src/views/composer.observe.js
  86. +170 −159 src/views/composer.style.js
  87. +97 −0 src/views/synchronizer.js
  88. +8 −11 src/views/textarea.js
  89. +14 −14 src/views/view.js
  90. +32 −6 src/wysihtml5.js
  91. +6 −6 test/assert/html_equals_test.js
  92. +25 −25 test/{browser_support_test.js → browser_test.js}
  93. +4 −4 test/{utils → dom}/auto_link_test.js
  94. +18 −0 test/dom/contains_test.js
  95. +86 −0 test/dom/convert_to_list_test.js
  96. +19 −17 test/{utils → dom}/copy_attributes_test.js
  97. +111 −0 test/dom/copy_styles_test.js
  98. +62 −0 test/dom/delegate_test.js
  99. +14 −11 test/{utils/get_in_dom_element_test.js → dom/get_as_dom_test.js}
  100. +37 −36 test/{utils → dom}/get_parent_element_test.js
  101. +8 −8 test/{utils → dom}/get_style_test.js
  102. +30 −0 test/dom/has_element_with_class_name_test.js
  103. +26 −0 test/dom/has_element_with_tag_name_test.js
  104. +56 −0 test/dom/insert_css_test.js
  105. +83 −0 test/dom/observe_test.js
  106. +35 −6 test/{utils/sanitize_html_test.js → dom/parse_test.js}
  107. +3 −3 test/{utils → dom}/rename_element_test.js
  108. +6 −15 test/{utils → dom}/resolve_list_test.js
  109. +65 −59 test/{utils → dom}/sandbox_test.js
  110. +15 −0 test/dom/set_attributes_test.js
  111. +19 −0 test/dom/set_styles_test.js
  112. +146 −257 test/editor_test.js
  113. +61 −0 test/incompatible_test.js
  114. +35 −21 test/index.html
  115. +22 −0 test/lang/array_test.js
  116. +22 −0 test/lang/object_test.js
  117. +19 −0 test/lang/string_test.js
  118. +1 −1 test/quirks/clean_pasted_html_test.js
  119. +0 −95 test/utils/convert_into_list_test.js
  120. +0 −110 test/utils/copy_styles_test.js
  121. +0 −27 test/utils/has_element_with_class_name_test.js
  122. +0 −23 test/utils/has_element_with_tag_name_test.js
  123. +0 −53 test/utils/insert_rules_test.js
  124. +0 −75 test/utils/observe_test.js
  125. +1 −1 version.txt
View
@@ -1,4 +1,4 @@
-Copyright (C) 2009 XING AG
+Copyright (C) 2011 XING AG
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version.
View
@@ -2,41 +2,51 @@ VERSION = $(shell cat version.txt)
JS_OUTPUT = "dist/wysihtml5-${VERSION}.js"
-JS_FILES = lib/rangy/rangy-core.js \
- lib/rangy/rangy-cssclassapplier-wysihtml5.js \
- src/wysihtml5.js \
- src/browser_support.js \
- src/utils/auto_focus.js \
- src/utils/auto_link.js \
- src/utils/caret.js \
- src/utils/contains.js \
- src/utils/convert_into_list.js \
- src/utils/copy_styles.js \
- src/utils/copy_attributes.js \
- src/utils/get_in_dom_element.js \
- src/utils/get_parent_element.js \
- src/utils/get_style.js \
- src/utils/has_element_with_tag_name.js \
- src/utils/has_element_with_class_name.js \
- src/utils/insert_rules.js \
- src/utils/observe.js \
- src/utils/resolve_list.js \
- src/utils/rename_element.js \
- src/utils/remove_empty_text_nodes.js \
- src/utils/sandbox.js \
- src/utils/sanitize_html.js \
- src/utils/simulate_placeholder.js \
- src/utils/synchronizer.js \
- src/utils/text_content.js \
- src/utils/unwrap.js \
+JS_FILES = src/wysihtml5.js \
+ lib/rangy/rangy-core.js \
+ lib/base/base.js \
+ src/browser.js \
+ src/lang/array.js \
+ src/lang/dispatcher.js \
+ src/lang/object.js \
+ src/lang/string.js \
+ src/dom/auto_link.js \
+ src/dom/class.js \
+ src/dom/contains.js \
+ src/dom/convert_to_list.js \
+ src/dom/copy_attributes.js \
+ src/dom/copy_styles.js \
+ src/dom/delegate.js \
+ src/dom/get_as_dom.js \
+ src/dom/get_parent_element.js \
+ src/dom/get_style.js \
+ src/dom/has_element_with_tag_name.js \
+ src/dom/has_element_with_class_name.js \
+ src/dom/insert.js \
+ src/dom/insert_css.js \
+ src/dom/observe.js \
+ src/dom/parse.js \
+ src/dom/remove_empty_text_nodes.js \
+ src/dom/rename_element.js \
+ src/dom/replace_with_child_nodes.js \
+ src/dom/resolve_list.js \
+ src/dom/sandbox.js \
+ src/dom/set_attributes.js \
+ src/dom/set_styles.js \
+ src/dom/simulate_placeholder.js \
+ src/dom/text_content.js \
src/quirks/clean_pasted_html.js \
src/quirks/ensure_proper_clearing.js \
+ src/quirks/get_correct_inner_html.js \
src/quirks/insert_line_break_on_return.js \
src/quirks/redraw.js \
+ src/selection/selection.js \
+ src/selection/html_applier.js \
src/views/view.js \
src/views/composer.js \
src/views/composer.style.js \
src/views/composer.observe.js \
+ src/views/synchronizer.js \
src/views/textarea.js \
src/toolbar/dialog.js \
src/toolbar/speech.js \
@@ -60,6 +70,20 @@ JS_FILES = lib/rangy/rangy-core.js \
src/commands/underline.js \
src/editor.js
-all:
+all: bundle minify
+
+bundle:
+ @@echo "Bundling..."
+ @@touch ${JS_OUTPUT}
@@rm ${JS_OUTPUT}
- @@cat ${JS_FILES} >> ${JS_OUTPUT}
+ @@cat ${JS_FILES} >> ${JS_OUTPUT}
+ @@cat ${JS_OUTPUT} | sed "s/@VERSION/${VERSION}/" > "${JS_OUTPUT}.tmp"
+ @@mv "${JS_OUTPUT}.tmp" ${JS_OUTPUT}
+
+minify:
+ @@echo "Minifying... (this requires node.js)"
+ @@node build/minify.js ${JS_OUTPUT}
+ @@echo "Done."
+
+unittest:
+ @@open test/index.html
View
@@ -1,8 +1,9 @@
-h1. wysihtml5 0.1.0
+h1. wysihtml5 0.2.0
wysihtml5 is an open source rich text editor based on HTML5 technology and the progressive-enhancement approach.
-It uses a sophisticated security concept and aims to generate fully valid HTML5 markup by preventing unmaintainable tag-soups and inline-styles.
-The editor is already in production use on "XING.com":https://www.xing.com - a social network with more than 10 million members.
+It uses a sophisticated security concept and aims to generate fully valid HTML5 markup by preventing unmaintainable tag soups and inline styles.
+The code is completely library agnostic: No jQuery, Prototype or similar is required.
+The editor is already in use on "XING.com":https://www.xing.com - a social network with more than 10 million members.
h2. Features:
@@ -15,6 +16,7 @@ h2. Features:
* Source code view for users with HTML skills
* Uses sandboxed iframes in order to prevent identity theft through XSS
* Editor inherits styles and attributes (placeholder, autofocus, ...) from original textarea (you only have to style one element)
+* Speech-input for Chrome 11+
h2. Browser Support
@@ -44,7 +46,7 @@ Following is a list of all configuration options with their corresponding defaul
// Object which includes parser rules (set this to examples/rules/spec.json or your own spec, otherwise only span tags are allowed!)
parserRules: null,
// Parser method to use when the user inserts content via copy & paste
- parser: wysihtml5.utils.sanitizeHTML || Prototype.K,
+ parser: wysihtml5.dom.parse || Prototype.K,
// Class name which should be set on the contentEditable element in the created sandbox iframe, can be styled via the 'stylesheets' option
composerClassName: "wysihtml5-editor",
// Class name to add to the body when the wysihtml5 editor is supported
@@ -113,6 +115,20 @@ copied to the hidden <code><textarea></code>)
behavior on the iframe's <code><body></code>
# Checks whether a toolbar is given and sets event listeners on it's link
+h2. How to build your own wysihtml5 files
+
+Clone and build the js file:
+<code>
+ git clone git://github.com/xing/wysihtml5.git
+ cd wysihtml5
+ make
+</code>
+
+Run the unit tests:
+<code>
+ make unittest
+</code>
+
h2. Research Material
Before starting this library we spent a lot of time investigating the different browsers and their behaviors.
View
@@ -0,0 +1,82 @@
+var script = process.argv[2],
+ http = require("http"),
+ queryString = require("querystring"),
+ fs = require("fs");
+
+if (!script) {
+ throw "No script url given";
+}
+
+function post(code, callback) {
+ // Build the post string from an object
+ var postData = queryString.stringify({
+ compilation_level: "SIMPLE_OPTIMIZATIONS",
+ output_format: "text",
+ output_info: "compiled_code",
+ warning_level: "QUIET",
+ js_code: code
+ });
+
+ // An object of options to indicate where to post to
+ var postOptions = {
+ host: "closure-compiler.appspot.com",
+ port: "80",
+ path: "/compile",
+ method: "POST",
+ headers: {
+ "Content-Type": "application/x-www-form-urlencoded",
+ "Content-Length": postData.length
+ }
+ };
+
+ // Set up the request
+ var request = http.request(postOptions, function(response) {
+ var responseText = [];
+ response.setEncoding("utf8");
+ response.on("data", function(data) {
+ responseText.push(data);
+ });
+ response.on("end", function() {
+ callback(responseText.join(""));
+ });
+ });
+
+ // Post the data
+ request.write(postData);
+ request.end();
+}
+
+function readFile(filePath, callback) {
+ // This is an async file read
+ fs.readFile(filePath, "utf-8", function (err, data) {
+ if (err) {
+ // If this were just a small part of the application, you would
+ // want to handle this differently, maybe throwing an exception
+ // for the caller to handle. Since the file is absolutely essential
+ // to the program's functionality, we're going to exit with a fatal
+ // error instead.
+ console.log("FATAL An error occurred trying to read in the file: " + err);
+ process.exit(-2);
+ }
+ // Make sure there's data before we post it
+ if (data) {
+ callback(data);
+ } else {
+ console.log("No data to post");
+ process.exit(-1);
+ }
+ });
+}
+
+function writeFile(filePath, data, callback) {
+ fs.writeFile(filePath, data, "utf-8", callback);
+}
+
+
+// Ok GO!
+readFile(script, function(code) {
+ post(code, function(code) {
+ var output = script.replace(/\.js/, ".min.js");
+ writeFile(output, code);
+ });
+});
Oops, something went wrong.

0 comments on commit 623afa8

Please sign in to comment.