formol 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (226) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +147 -0
  3. data/Rakefile +29 -0
  4. data/app/assets/images/formol/read.png +0 -0
  5. data/app/assets/images/formol/unread.png +0 -0
  6. data/app/assets/javascripts/formol/admin/categories.js.coffee +55 -0
  7. data/app/assets/javascripts/formol/admin/forums.js +2 -0
  8. data/app/assets/javascripts/formol/application.js +9 -0
  9. data/app/assets/javascripts/formol/categories.js +2 -0
  10. data/app/assets/javascripts/formol/forums.js +2 -0
  11. data/app/assets/javascripts/formol/poll_votes.js +2 -0
  12. data/app/assets/javascripts/formol/posts.js.coffee +9 -0
  13. data/app/assets/javascripts/formol/preferences.js +2 -0
  14. data/app/assets/javascripts/formol/subscriptions.js.coffee +13 -0
  15. data/app/assets/javascripts/formol/topics.js.coffee +54 -0
  16. data/app/assets/javascripts/lib/jquery.prevent_double_submit.js.coffee +11 -0
  17. data/app/assets/javascripts/markitup/jquery.markitup.js +593 -0
  18. data/app/assets/javascripts/markitup/sets/markdown/set.js +53 -0
  19. data/app/assets/stylesheets/form_struct.css.scss +39 -0
  20. data/app/assets/stylesheets/formol/admin/categories.css.scss +30 -0
  21. data/app/assets/stylesheets/formol/admin/forums.css +4 -0
  22. data/app/assets/stylesheets/formol/categories.css.scss +3 -0
  23. data/app/assets/stylesheets/formol/development.css +4 -0
  24. data/app/assets/stylesheets/formol/forums.css.scss +3 -0
  25. data/app/assets/stylesheets/formol/mixins/after_clear.css.scss +7 -0
  26. data/app/assets/stylesheets/formol/partials/breadcrumb.css.scss +9 -0
  27. data/app/assets/stylesheets/formol/partials/categories/list.css.scss +101 -0
  28. data/app/assets/stylesheets/formol/partials/formol_lists.css.scss +6 -0
  29. data/app/assets/stylesheets/formol/partials/forums/list.css.scss +97 -0
  30. data/app/assets/stylesheets/formol/partials/polls/poll.css.scss +9 -0
  31. data/app/assets/stylesheets/formol/partials/posts/post.css.scss +116 -0
  32. data/app/assets/stylesheets/formol/posts.css.scss +8 -0
  33. data/app/assets/stylesheets/formol/topics.css.scss +42 -0
  34. data/app/assets/stylesheets/markitup/sets/markdown/images/block_code.png +0 -0
  35. data/app/assets/stylesheets/markitup/sets/markdown/images/bold.png +0 -0
  36. data/app/assets/stylesheets/markitup/sets/markdown/images/code.png +0 -0
  37. data/app/assets/stylesheets/markitup/sets/markdown/images/h1.png +0 -0
  38. data/app/assets/stylesheets/markitup/sets/markdown/images/h2.png +0 -0
  39. data/app/assets/stylesheets/markitup/sets/markdown/images/h3.png +0 -0
  40. data/app/assets/stylesheets/markitup/sets/markdown/images/h4.png +0 -0
  41. data/app/assets/stylesheets/markitup/sets/markdown/images/h5.png +0 -0
  42. data/app/assets/stylesheets/markitup/sets/markdown/images/h6.png +0 -0
  43. data/app/assets/stylesheets/markitup/sets/markdown/images/italic.png +0 -0
  44. data/app/assets/stylesheets/markitup/sets/markdown/images/link.png +0 -0
  45. data/app/assets/stylesheets/markitup/sets/markdown/images/list-bullet.png +0 -0
  46. data/app/assets/stylesheets/markitup/sets/markdown/images/list-numeric.png +0 -0
  47. data/app/assets/stylesheets/markitup/sets/markdown/images/picture.png +0 -0
  48. data/app/assets/stylesheets/markitup/sets/markdown/images/preview.png +0 -0
  49. data/app/assets/stylesheets/markitup/sets/markdown/images/quotes.png +0 -0
  50. data/app/assets/stylesheets/markitup/sets/markdown/style.css +57 -0
  51. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-container.png +0 -0
  52. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-bbcode.png +0 -0
  53. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-dotclear.png +0 -0
  54. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-html.png +0 -0
  55. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-json.png +0 -0
  56. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-markdown.png +0 -0
  57. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-textile.png +0 -0
  58. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-wiki.png +0 -0
  59. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor-xml.png +0 -0
  60. data/app/assets/stylesheets/markitup/skins/markitup/images/bg-editor.png +0 -0
  61. data/app/assets/stylesheets/markitup/skins/markitup/images/handle.png +0 -0
  62. data/app/assets/stylesheets/markitup/skins/markitup/images/menu.png +0 -0
  63. data/app/assets/stylesheets/markitup/skins/markitup/images/submenu.png +0 -0
  64. data/app/assets/stylesheets/markitup/skins/markitup/style.css +147 -0
  65. data/app/assets/stylesheets/markitup/skins/simple/images/handle.png +0 -0
  66. data/app/assets/stylesheets/markitup/skins/simple/images/menu.png +0 -0
  67. data/app/assets/stylesheets/markitup/skins/simple/images/submenu.png +0 -0
  68. data/app/assets/stylesheets/markitup/skins/simple/style.css +118 -0
  69. data/app/assets/stylesheets/pygments/autumn.css +58 -0
  70. data/app/assets/stylesheets/pygments/borland.css +46 -0
  71. data/app/assets/stylesheets/pygments/bw.css +34 -0
  72. data/app/assets/stylesheets/pygments/colorful.css +61 -0
  73. data/app/assets/stylesheets/pygments/default.css +62 -0
  74. data/app/assets/stylesheets/pygments/emacs.css +61 -0
  75. data/app/assets/stylesheets/pygments/friendly.css +61 -0
  76. data/app/assets/stylesheets/pygments/fruity.css +70 -0
  77. data/app/assets/stylesheets/pygments/manni.css +61 -0
  78. data/app/assets/stylesheets/pygments/murphy.css +61 -0
  79. data/app/assets/stylesheets/pygments/native.css +70 -0
  80. data/app/assets/stylesheets/pygments/pastie.css +60 -0
  81. data/app/assets/stylesheets/pygments/perldoc.css +58 -0
  82. data/app/assets/stylesheets/pygments/tango.css +69 -0
  83. data/app/assets/stylesheets/pygments/trac.css +59 -0
  84. data/app/assets/stylesheets/pygments/vim.css +70 -0
  85. data/app/assets/stylesheets/pygments/vs.css +33 -0
  86. data/app/controllers/formol/admin/admin_controller.rb +11 -0
  87. data/app/controllers/formol/admin/categories_controller.rb +60 -0
  88. data/app/controllers/formol/admin/forums_controller.rb +56 -0
  89. data/app/controllers/formol/application_controller.rb +47 -0
  90. data/app/controllers/formol/categories_controller.rb +21 -0
  91. data/app/controllers/formol/forums_controller.rb +19 -0
  92. data/app/controllers/formol/poll_votes_controller.rb +23 -0
  93. data/app/controllers/formol/posts_controller.rb +71 -0
  94. data/app/controllers/formol/preferences_controller.rb +32 -0
  95. data/app/controllers/formol/subscriptions_controller.rb +29 -0
  96. data/app/controllers/formol/topics_controller.rb +91 -0
  97. data/app/helpers/formol/admin/categories_helper.rb +4 -0
  98. data/app/helpers/formol/admin/forums_helper.rb +4 -0
  99. data/app/helpers/formol/application_helper.rb +35 -0
  100. data/app/helpers/formol/categories_helper.rb +15 -0
  101. data/app/helpers/formol/forums_helper.rb +19 -0
  102. data/app/helpers/formol/poll_votes_helper.rb +4 -0
  103. data/app/helpers/formol/posts_helper.rb +27 -0
  104. data/app/helpers/formol/preferences_helper.rb +4 -0
  105. data/app/helpers/formol/subscriptions_helper.rb +4 -0
  106. data/app/helpers/formol/topics_helper.rb +27 -0
  107. data/app/mailers/formol/subscription_mailer.rb +13 -0
  108. data/app/models/formol/category.rb +42 -0
  109. data/app/models/formol/forum.rb +77 -0
  110. data/app/models/formol/poll/option.rb +20 -0
  111. data/app/models/formol/poll/vote.rb +32 -0
  112. data/app/models/formol/poll.rb +107 -0
  113. data/app/models/formol/post.rb +162 -0
  114. data/app/models/formol/post_observer.rb +9 -0
  115. data/app/models/formol/topic/subscription.rb +16 -0
  116. data/app/models/formol/topic/track.rb +57 -0
  117. data/app/models/formol/topic.rb +185 -0
  118. data/app/models/formol/tracking.rb +45 -0
  119. data/app/models/formol/user_preference.rb +18 -0
  120. data/app/views/formol/admin/categories/_category.html.erb +9 -0
  121. data/app/views/formol/admin/categories/_form.html.erb +8 -0
  122. data/app/views/formol/admin/categories/edit.html.erb +3 -0
  123. data/app/views/formol/admin/categories/index.html.erb +3 -0
  124. data/app/views/formol/admin/categories/new.html.erb +3 -0
  125. data/app/views/formol/admin/forums/_form.html.erb +9 -0
  126. data/app/views/formol/admin/forums/_forum.html.erb +12 -0
  127. data/app/views/formol/admin/forums/edit.html.erb +3 -0
  128. data/app/views/formol/admin/forums/new.html.erb +3 -0
  129. data/app/views/formol/categories/_category.html.erb +5 -0
  130. data/app/views/formol/categories/index.html.erb +5 -0
  131. data/app/views/formol/categories/show.html.erb +3 -0
  132. data/app/views/formol/forums/_forum.html.erb +13 -0
  133. data/app/views/formol/forums/_list.html.erb +16 -0
  134. data/app/views/formol/forums/show.html.erb +18 -0
  135. data/app/views/formol/poll/options/_form.html.erb +1 -0
  136. data/app/views/formol/poll_votes/_form.html.erb +8 -0
  137. data/app/views/formol/polls/_form.html.erb +14 -0
  138. data/app/views/formol/polls/_poll.html.erb +24 -0
  139. data/app/views/formol/posts/_form.html.erb +7 -0
  140. data/app/views/formol/posts/_last_post.html.erb +9 -0
  141. data/app/views/formol/posts/_list.html.erb +3 -0
  142. data/app/views/formol/posts/_post.html.erb +47 -0
  143. data/app/views/formol/posts/edit.html.erb +10 -0
  144. data/app/views/formol/posts/new.html.erb +14 -0
  145. data/app/views/formol/preferences/show.html.erb +11 -0
  146. data/app/views/formol/subscription_mailer/topic_reply.en.html.erb +8 -0
  147. data/app/views/formol/subscription_mailer/topic_reply.fr.html.erb +8 -0
  148. data/app/views/formol/topics/_form.html.erb +20 -0
  149. data/app/views/formol/topics/_list.html.erb +16 -0
  150. data/app/views/formol/topics/_topic.html.erb +13 -0
  151. data/app/views/formol/topics/edit.html.erb +5 -0
  152. data/app/views/formol/topics/new.html.erb +5 -0
  153. data/app/views/formol/topics/show.html.erb +25 -0
  154. data/app/views/layouts/formol/mail.html.erb +9 -0
  155. data/config/locales/en.yml +3 -0
  156. data/config/locales/formol/views/forums/en.yml +13 -0
  157. data/config/locales/formol/views/forums/fr.yml +13 -0
  158. data/config/locales/formol/views/poll_votes/en.yml +5 -0
  159. data/config/locales/formol/views/polls/en.yml.yml +5 -0
  160. data/config/locales/formol/views/posts/en.yml +23 -0
  161. data/config/locales/formol/views/posts/fr.yml +20 -0
  162. data/config/locales/formol/views/topics/en.yml +23 -0
  163. data/config/locales/formol/views/topics/fr.yml +20 -0
  164. data/config/routes.rb +31 -0
  165. data/db/migrate/20111221101158_create_formol_categories.rb +7 -0
  166. data/db/migrate/20111221111417_create_formol_forums.rb +10 -0
  167. data/db/migrate/20111221121010_create_formol_topics.rb +9 -0
  168. data/db/migrate/20111221123515_create_formol_posts.rb +9 -0
  169. data/db/migrate/20111221151653_add_index_on_tables.rb +15 -0
  170. data/db/migrate/20120103163438_add_user_to_models.rb +13 -0
  171. data/db/migrate/20120104132631_add_counter_cache_to_models.rb +12 -0
  172. data/db/migrate/20120104163741_add_pinned_to_topics.rb +7 -0
  173. data/db/migrate/20120105133522_add_position_to_categories.rb +7 -0
  174. data/db/migrate/20120105190708_add_position_to_forums.rb +7 -0
  175. data/db/migrate/20120105212559_add_lock_to_topics.rb +7 -0
  176. data/db/migrate/20120106130944_add_first_post_and_last_post_to_topics.rb +8 -0
  177. data/db/migrate/20120106192951_change_forum_description_to_string.rb +9 -0
  178. data/db/migrate/20120107012517_add_last_post_to_forum.rb +7 -0
  179. data/db/migrate/20120107122921_add_missing_indexes.rb +12 -0
  180. data/db/migrate/20120107123654_add_default_on_forum_counters.rb +10 -0
  181. data/db/migrate/20120108114030_add_views_to_topics.rb +7 -0
  182. data/db/migrate/20120108131533_create_formol_topic_tracks.rb +13 -0
  183. data/db/migrate/20120109115141_create_formol_topic_subscriptions.rb +10 -0
  184. data/db/migrate/20120109220633_create_formol_user_preferences.rb +11 -0
  185. data/db/migrate/20120109223624_add_display_signature_to_posts.rb +7 -0
  186. data/db/migrate/20120109233054_add_display_signatures_and_avatars_to_user_preferences.rb +8 -0
  187. data/db/migrate/20120110152548_create_formol_polls.rb +14 -0
  188. data/db/migrate/20120110152618_create_formol_poll_options.rb +11 -0
  189. data/db/migrate/20120110152632_create_formol_poll_votes.rb +12 -0
  190. data/lib/formol/config.rb +12 -0
  191. data/lib/formol/controllers/auth.rb +9 -0
  192. data/lib/formol/controllers/nested/has_parent_category.rb +11 -0
  193. data/lib/formol/controllers/nested/has_parent_forum.rb +11 -0
  194. data/lib/formol/controllers/nested/has_parent_topic.rb +11 -0
  195. data/lib/formol/controllers.rb +5 -0
  196. data/lib/formol/engine.rb +18 -0
  197. data/lib/formol/formatters/redcarpet/formatter.rb +36 -0
  198. data/lib/formol/formatters/redcarpet/syntax_highlighter.rb +23 -0
  199. data/lib/formol/formatters.rb +2 -0
  200. data/lib/formol/generators/install/install_generator.rb +94 -0
  201. data/lib/formol/generators/install/templates/config/formol.yml +29 -0
  202. data/lib/formol/generators/install/templates/initializer/formol.rb.erb +21 -0
  203. data/lib/formol/generators/install/templates/lib/permissions/special_rights.rb +24 -0
  204. data/lib/formol/generators/install/templates/migrations/add_formol_profile_to_users.rb.erb +7 -0
  205. data/lib/formol/generators/install/templates/migrations/add_posts_count_to_user.rb.erb +7 -0
  206. data/lib/formol/generators.rb +1 -0
  207. data/lib/formol/integration/user.rb +76 -0
  208. data/lib/formol/integration.rb +1 -0
  209. data/lib/formol/permissions/controllers.rb +30 -0
  210. data/lib/formol/permissions/manager.rb +29 -0
  211. data/lib/formol/permissions/profile.rb +24 -0
  212. data/lib/formol/permissions/profiles.rb +44 -0
  213. data/lib/formol/permissions/user.rb +29 -0
  214. data/lib/formol/permissions.rb +5 -0
  215. data/lib/formol/rails/engine.rb +81 -0
  216. data/lib/formol/rails.rb +1 -0
  217. data/lib/formol/version.rb +10 -0
  218. data/lib/formol/view_helpers/assets_helper.rb +11 -0
  219. data/lib/formol/view_helpers/format_helper.rb +12 -0
  220. data/lib/formol/view_helpers.rb +2 -0
  221. data/lib/formol/will_paginate/list_link_renderer.rb +29 -0
  222. data/lib/formol/will_paginate.rb +1 -0
  223. data/lib/formol.rb +61 -0
  224. data/lib/formol_.rb +13 -0
  225. data/lib/tasks/formol_tasks.rake +0 -0
  226. metadata +348 -0
@@ -0,0 +1,593 @@
1
+ // ----------------------------------------------------------------------------
2
+ // markItUp! Universal MarkUp Engine, JQuery plugin
3
+ // v 1.1.x
4
+ // Dual licensed under the MIT and GPL licenses.
5
+ // ----------------------------------------------------------------------------
6
+ // Copyright (C) 2007-2011 Jay Salvat
7
+ // http://markitup.jaysalvat.com/
8
+ // ----------------------------------------------------------------------------
9
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ // of this software and associated documentation files (the "Software"), to deal
11
+ // in the Software without restriction, including without limitation the rights
12
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ // copies of the Software, and to permit persons to whom the Software is
14
+ // furnished to do so, subject to the following conditions:
15
+ //
16
+ // The above copyright notice and this permission notice shall be included in
17
+ // all copies or substantial portions of the Software.
18
+ //
19
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ // THE SOFTWARE.
26
+ // ----------------------------------------------------------------------------
27
+ (function($) {
28
+ $.fn.markItUp = function(settings, extraSettings) {
29
+ var options, ctrlKey, shiftKey, altKey;
30
+ ctrlKey = shiftKey = altKey = false;
31
+
32
+ options = { id: '',
33
+ nameSpace: '',
34
+ root: '',
35
+ previewInWindow: '', // 'width=800, height=600, resizable=yes, scrollbars=yes'
36
+ previewAutoRefresh: true,
37
+ previewPosition: 'after',
38
+ previewTemplatePath: '~/templates/preview.html',
39
+ previewParser: false,
40
+ previewParserPath: '',
41
+ previewParserVar: 'data',
42
+ resizeHandle: true,
43
+ beforeInsert: '',
44
+ afterInsert: '',
45
+ onEnter: {},
46
+ onShiftEnter: {},
47
+ onCtrlEnter: {},
48
+ onTab: {},
49
+ markupSet: [ { /* set */ } ]
50
+ };
51
+ $.extend(options, settings, extraSettings);
52
+
53
+ // compute markItUp! path
54
+ if (!options.root) {
55
+ $('script').each(function(a, tag) {
56
+ miuScript = $(tag).get(0).src.match(/(.*)jquery\.markitup(\.pack)?\.js$/);
57
+ if (miuScript !== null) {
58
+ options.root = miuScript[1];
59
+ }
60
+ });
61
+ }
62
+
63
+ return this.each(function() {
64
+ var $$, textarea, levels, scrollPosition, caretPosition, caretOffset,
65
+ clicked, hash, header, footer, previewWindow, template, iFrame, abort;
66
+ $$ = $(this);
67
+ textarea = this;
68
+ levels = [];
69
+ abort = false;
70
+ scrollPosition = caretPosition = 0;
71
+ caretOffset = -1;
72
+
73
+ options.previewParserPath = localize(options.previewParserPath);
74
+ options.previewTemplatePath = localize(options.previewTemplatePath);
75
+
76
+ // apply the computed path to ~/
77
+ function localize(data, inText) {
78
+ if (inText) {
79
+ return data.replace(/("|')~\//g, "$1"+options.root);
80
+ }
81
+ return data.replace(/^~\//, options.root);
82
+ }
83
+
84
+ // init and build editor
85
+ function init() {
86
+ id = ''; nameSpace = '';
87
+ if (options.id) {
88
+ id = 'id="'+options.id+'"';
89
+ } else if ($$.attr("id")) {
90
+ id = 'id="markItUp'+($$.attr("id").substr(0, 1).toUpperCase())+($$.attr("id").substr(1))+'"';
91
+
92
+ }
93
+ if (options.nameSpace) {
94
+ nameSpace = 'class="'+options.nameSpace+'"';
95
+ }
96
+ $$.wrap('<div '+nameSpace+'></div>');
97
+ $$.wrap('<div '+id+' class="markItUp"></div>');
98
+ $$.wrap('<div class="markItUpContainer"></div>');
99
+ $$.addClass("markItUpEditor");
100
+
101
+ // add the header before the textarea
102
+ header = $('<div class="markItUpHeader"></div>').insertBefore($$);
103
+ $(dropMenus(options.markupSet)).appendTo(header);
104
+
105
+ // add the footer after the textarea
106
+ footer = $('<div class="markItUpFooter"></div>').insertAfter($$);
107
+
108
+ // add the resize handle after textarea
109
+ if (options.resizeHandle === true && $.browser.safari !== true) {
110
+ resizeHandle = $('<div class="markItUpResizeHandle"></div>')
111
+ .insertAfter($$)
112
+ .bind("mousedown", function(e) {
113
+ var h = $$.height(), y = e.clientY, mouseMove, mouseUp;
114
+ mouseMove = function(e) {
115
+ $$.css("height", Math.max(20, e.clientY+h-y)+"px");
116
+ return false;
117
+ };
118
+ mouseUp = function(e) {
119
+ $("html").unbind("mousemove", mouseMove).unbind("mouseup", mouseUp);
120
+ return false;
121
+ };
122
+ $("html").bind("mousemove", mouseMove).bind("mouseup", mouseUp);
123
+ });
124
+ footer.append(resizeHandle);
125
+ }
126
+
127
+ // listen key events
128
+ $$.keydown(keyPressed).keyup(keyPressed);
129
+
130
+ // bind an event to catch external calls
131
+ $$.bind("insertion", function(e, settings) {
132
+ if (settings.target !== false) {
133
+ get();
134
+ }
135
+ if (textarea === $.markItUp.focused) {
136
+ markup(settings);
137
+ }
138
+ });
139
+
140
+ // remember the last focus
141
+ $$.focus(function() {
142
+ $.markItUp.focused = this;
143
+ });
144
+ }
145
+
146
+ // recursively build header with dropMenus from markupset
147
+ function dropMenus(markupSet) {
148
+ var ul = $('<ul></ul>'), i = 0;
149
+ $('li:hover > ul', ul).css('display', 'block');
150
+ $.each(markupSet, function() {
151
+ var button = this, t = '', title, li, j;
152
+ title = (button.key) ? (button.name||'')+' [Ctrl+'+button.key+']' : (button.name||'');
153
+ key = (button.key) ? 'accesskey="'+button.key+'"' : '';
154
+ if (button.separator) {
155
+ li = $('<li class="markItUpSeparator">'+(button.separator||'')+'</li>').appendTo(ul);
156
+ } else {
157
+ i++;
158
+ for (j = levels.length -1; j >= 0; j--) {
159
+ t += levels[j]+"-";
160
+ }
161
+ li = $('<li class="markItUpButton markItUpButton'+t+(i)+' '+(button.className||'')+'"><a href="" '+key+' title="'+title+'">'+(button.name||'')+'</a></li>')
162
+ .bind("contextmenu", function() { // prevent contextmenu on mac and allow ctrl+click
163
+ return false;
164
+ }).click(function() {
165
+ return false;
166
+ }).bind("focusin", function(){
167
+ $$.focus();
168
+ }).mouseup(function() {
169
+ if (button.call) {
170
+ eval(button.call)();
171
+ }
172
+ setTimeout(function() { markup(button) },1);
173
+ return false;
174
+ }).hover(function() {
175
+ $('> ul', this).show();
176
+ $(document).one('click', function() { // close dropmenu if click outside
177
+ $('ul ul', header).hide();
178
+ }
179
+ );
180
+ }, function() {
181
+ $('> ul', this).hide();
182
+ }
183
+ ).appendTo(ul);
184
+ if (button.dropMenu) {
185
+ levels.push(i);
186
+ $(li).addClass('markItUpDropMenu').append(dropMenus(button.dropMenu));
187
+ }
188
+ }
189
+ });
190
+ levels.pop();
191
+ return ul;
192
+ }
193
+
194
+ // markItUp! markups
195
+ function magicMarkups(string) {
196
+ if (string) {
197
+ string = string.toString();
198
+ string = string.replace(/\(\!\(([\s\S]*?)\)\!\)/g,
199
+ function(x, a) {
200
+ var b = a.split('|!|');
201
+ if (altKey === true) {
202
+ return (b[1] !== undefined) ? b[1] : b[0];
203
+ } else {
204
+ return (b[1] === undefined) ? "" : b[0];
205
+ }
206
+ }
207
+ );
208
+ // [![prompt]!], [![prompt:!:value]!]
209
+ string = string.replace(/\[\!\[([\s\S]*?)\]\!\]/g,
210
+ function(x, a) {
211
+ var b = a.split(':!:');
212
+ if (abort === true) {
213
+ return false;
214
+ }
215
+ value = prompt(b[0], (b[1]) ? b[1] : '');
216
+ if (value === null) {
217
+ abort = true;
218
+ }
219
+ return value;
220
+ }
221
+ );
222
+ return string;
223
+ }
224
+ return "";
225
+ }
226
+
227
+ // prepare action
228
+ function prepare(action) {
229
+ if ($.isFunction(action)) {
230
+ action = action(hash);
231
+ }
232
+ return magicMarkups(action);
233
+ }
234
+
235
+ // build block to insert
236
+ function build(string) {
237
+ var openWith = prepare(clicked.openWith);
238
+ var placeHolder = prepare(clicked.placeHolder);
239
+ var replaceWith = prepare(clicked.replaceWith);
240
+ var closeWith = prepare(clicked.closeWith);
241
+ var openBlockWith = prepare(clicked.openBlockWith);
242
+ var closeBlockWith = prepare(clicked.closeBlockWith);
243
+ var multiline = clicked.multiline;
244
+
245
+ if (replaceWith !== "") {
246
+ block = openWith + replaceWith + closeWith;
247
+ } else if (selection === '' && placeHolder !== '') {
248
+ block = openWith + placeHolder + closeWith;
249
+ } else {
250
+ string = string || selection;
251
+
252
+ var lines = selection.split(/\r?\n/), blocks = [];
253
+
254
+ for (var l=0; l < lines.length; l++) {
255
+ line = lines[l];
256
+ var trailingSpaces;
257
+ if (trailingSpaces = line.match(/ *$/)) {
258
+ blocks.push(openWith + line.replace(/ *$/g, '') + closeWith + trailingSpaces);
259
+ } else {
260
+ blocks.push(openWith + line + closeWith);
261
+ }
262
+ }
263
+
264
+ block = blocks.join("\n");
265
+ }
266
+
267
+ block = openBlockWith + block + closeBlockWith;
268
+
269
+ return { block:block,
270
+ openWith:openWith,
271
+ replaceWith:replaceWith,
272
+ placeHolder:placeHolder,
273
+ closeWith:closeWith
274
+ };
275
+ }
276
+
277
+ // define markup to insert
278
+ function markup(button) {
279
+ var len, j, n, i;
280
+ hash = clicked = button;
281
+ get();
282
+ $.extend(hash, { line:"",
283
+ root:options.root,
284
+ textarea:textarea,
285
+ selection:(selection||''),
286
+ caretPosition:caretPosition,
287
+ ctrlKey:ctrlKey,
288
+ shiftKey:shiftKey,
289
+ altKey:altKey
290
+ }
291
+ );
292
+ // callbacks before insertion
293
+ prepare(options.beforeInsert);
294
+ prepare(clicked.beforeInsert);
295
+ if ((ctrlKey === true && shiftKey === true) || button.multiline === true) {
296
+ prepare(clicked.beforeMultiInsert);
297
+ }
298
+ $.extend(hash, { line:1 });
299
+
300
+ if ((ctrlKey === true && shiftKey === true)) {
301
+ lines = selection.split(/\r?\n/);
302
+ for (j = 0, n = lines.length, i = 0; i < n; i++) {
303
+ if ($.trim(lines[i]) !== '') {
304
+ $.extend(hash, { line:++j, selection:lines[i] } );
305
+ lines[i] = build(lines[i]).block;
306
+ } else {
307
+ lines[i] = "";
308
+ }
309
+ }
310
+ string = { block:lines.join('\n')};
311
+ start = caretPosition;
312
+ len = string.block.length + (($.browser.opera) ? n-1 : 0);
313
+ } else if (ctrlKey === true) {
314
+ string = build(selection);
315
+ start = caretPosition + string.openWith.length;
316
+ len = string.block.length - string.openWith.length - string.closeWith.length;
317
+ len = len - (string.block.match(/ $/) ? 1 : 0);
318
+ len -= fixIeBug(string.block);
319
+ } else if (shiftKey === true) {
320
+ string = build(selection);
321
+ start = caretPosition;
322
+ len = string.block.length;
323
+ len -= fixIeBug(string.block);
324
+ } else {
325
+ string = build(selection);
326
+ start = caretPosition + string.block.length ;
327
+ len = 0;
328
+ start -= fixIeBug(string.block);
329
+ }
330
+ if ((selection === '' && string.replaceWith === '')) {
331
+ caretOffset += fixOperaBug(string.block);
332
+
333
+ start = caretPosition + string.openWith.length;
334
+ len = string.block.length - string.openWith.length - string.closeWith.length;
335
+
336
+ caretOffset = $$.val().substring(caretPosition, $$.val().length).length;
337
+ caretOffset -= fixOperaBug($$.val().substring(0, caretPosition));
338
+ }
339
+ $.extend(hash, { caretPosition:caretPosition, scrollPosition:scrollPosition } );
340
+
341
+ if (string.block !== selection && abort === false) {
342
+ insert(string.block);
343
+ set(start, len);
344
+ } else {
345
+ caretOffset = -1;
346
+ }
347
+ get();
348
+
349
+ $.extend(hash, { line:'', selection:selection });
350
+
351
+ // callbacks after insertion
352
+ if ((ctrlKey === true && shiftKey === true) || button.multiline === true) {
353
+ prepare(clicked.afterMultiInsert);
354
+ }
355
+ prepare(clicked.afterInsert);
356
+ prepare(options.afterInsert);
357
+
358
+ // refresh preview if opened
359
+ if (previewWindow && options.previewAutoRefresh) {
360
+ refreshPreview();
361
+ }
362
+
363
+ // reinit keyevent
364
+ shiftKey = altKey = ctrlKey = abort = false;
365
+ }
366
+
367
+ // Substract linefeed in Opera
368
+ function fixOperaBug(string) {
369
+ if ($.browser.opera) {
370
+ return string.length - string.replace(/\n*/g, '').length;
371
+ }
372
+ return 0;
373
+ }
374
+ // Substract linefeed in IE
375
+ function fixIeBug(string) {
376
+ if ($.browser.msie) {
377
+ return string.length - string.replace(/\r*/g, '').length;
378
+ }
379
+ return 0;
380
+ }
381
+
382
+ // add markup
383
+ function insert(block) {
384
+ if (document.selection) {
385
+ var newSelection = document.selection.createRange();
386
+ newSelection.text = block;
387
+ } else {
388
+ textarea.value = textarea.value.substring(0, caretPosition) + block + textarea.value.substring(caretPosition + selection.length, textarea.value.length);
389
+ }
390
+ }
391
+
392
+ // set a selection
393
+ function set(start, len) {
394
+ if (textarea.createTextRange){
395
+ // quick fix to make it work on Opera 9.5
396
+ if ($.browser.opera && $.browser.version >= 9.5 && len == 0) {
397
+ return false;
398
+ }
399
+ range = textarea.createTextRange();
400
+ range.collapse(true);
401
+ range.moveStart('character', start);
402
+ range.moveEnd('character', len);
403
+ range.select();
404
+ } else if (textarea.setSelectionRange ){
405
+ textarea.setSelectionRange(start, start + len);
406
+ }
407
+ textarea.scrollTop = scrollPosition;
408
+ textarea.focus();
409
+ }
410
+
411
+ // get the selection
412
+ function get() {
413
+ textarea.focus();
414
+
415
+ scrollPosition = textarea.scrollTop;
416
+ if (document.selection) {
417
+ selection = document.selection.createRange().text;
418
+ if ($.browser.msie) { // ie
419
+ var range = document.selection.createRange(), rangeCopy = range.duplicate();
420
+ rangeCopy.moveToElementText(textarea);
421
+ caretPosition = -1;
422
+ while(rangeCopy.inRange(range)) {
423
+ rangeCopy.moveStart('character');
424
+ caretPosition ++;
425
+ }
426
+ } else { // opera
427
+ caretPosition = textarea.selectionStart;
428
+ }
429
+ } else { // gecko & webkit
430
+ caretPosition = textarea.selectionStart;
431
+
432
+ selection = textarea.value.substring(caretPosition, textarea.selectionEnd);
433
+ }
434
+ return selection;
435
+ }
436
+
437
+ // open preview window
438
+ function preview() {
439
+ if (!previewWindow || previewWindow.closed) {
440
+ if (options.previewInWindow) {
441
+ previewWindow = window.open('', 'preview', options.previewInWindow);
442
+ $(window).unload(function() {
443
+ previewWindow.close();
444
+ });
445
+ } else {
446
+ iFrame = $('<iframe class="markItUpPreviewFrame"></iframe>');
447
+ if (options.previewPosition == 'after') {
448
+ iFrame.insertAfter(footer);
449
+ } else {
450
+ iFrame.insertBefore(header);
451
+ }
452
+ previewWindow = iFrame[iFrame.length - 1].contentWindow || frame[iFrame.length - 1];
453
+ }
454
+ } else if (altKey === true) {
455
+ if (iFrame) {
456
+ iFrame.remove();
457
+ } else {
458
+ previewWindow.close();
459
+ }
460
+ previewWindow = iFrame = false;
461
+ }
462
+ if (!options.previewAutoRefresh) {
463
+ refreshPreview();
464
+ }
465
+ if (options.previewInWindow) {
466
+ previewWindow.focus();
467
+ }
468
+ }
469
+
470
+ // refresh Preview window
471
+ function refreshPreview() {
472
+ renderPreview();
473
+ }
474
+
475
+ function renderPreview() {
476
+ var phtml;
477
+ if (options.previewParser && typeof options.previewParser === 'function') {
478
+ var data = options.previewParser( $$.val() );
479
+ writeInPreview( localize(data, 1) );
480
+ } else if (options.previewParserPath !== '') {
481
+ $.ajax({
482
+ type: 'POST',
483
+ dataType: 'text',
484
+ global: false,
485
+ url: options.previewParserPath,
486
+ data: options.previewParserVar+'='+encodeURIComponent($$.val()),
487
+ success: function(data) {
488
+ writeInPreview( localize(data, 1) );
489
+ }
490
+ });
491
+ } else {
492
+ if (!template) {
493
+ $.ajax({
494
+ url: options.previewTemplatePath,
495
+ dataType: 'text',
496
+ global: false,
497
+ success: function(data) {
498
+ writeInPreview( localize(data, 1).replace(/<!-- content -->/g, $$.val()) );
499
+ }
500
+ });
501
+ }
502
+ }
503
+ return false;
504
+ }
505
+
506
+ function writeInPreview(data) {
507
+ if (previewWindow.document) {
508
+ try {
509
+ sp = previewWindow.document.documentElement.scrollTop
510
+ } catch(e) {
511
+ sp = 0;
512
+ }
513
+ previewWindow.document.open();
514
+ previewWindow.document.write(data);
515
+ previewWindow.document.close();
516
+ previewWindow.document.documentElement.scrollTop = sp;
517
+ }
518
+ }
519
+
520
+ // set keys pressed
521
+ function keyPressed(e) {
522
+ shiftKey = e.shiftKey;
523
+ altKey = e.altKey;
524
+ ctrlKey = (!(e.altKey && e.ctrlKey)) ? (e.ctrlKey || e.metaKey) : false;
525
+
526
+ if (e.type === 'keydown') {
527
+ if (ctrlKey === true) {
528
+ li = $('a[accesskey="'+String.fromCharCode(e.keyCode)+'"]', header).parent('li');
529
+ if (li.length !== 0) {
530
+ ctrlKey = false;
531
+ setTimeout(function() {
532
+ li.triggerHandler('mouseup');
533
+ },1);
534
+ return false;
535
+ }
536
+ }
537
+ if (e.keyCode === 13 || e.keyCode === 10) { // Enter key
538
+ if (ctrlKey === true) { // Enter + Ctrl
539
+ ctrlKey = false;
540
+ markup(options.onCtrlEnter);
541
+ return options.onCtrlEnter.keepDefault;
542
+ } else if (shiftKey === true) { // Enter + Shift
543
+ shiftKey = false;
544
+ markup(options.onShiftEnter);
545
+ return options.onShiftEnter.keepDefault;
546
+ } else { // only Enter
547
+ markup(options.onEnter);
548
+ return options.onEnter.keepDefault;
549
+ }
550
+ }
551
+ if (e.keyCode === 9) { // Tab key
552
+ if (shiftKey == true || ctrlKey == true || altKey == true) {
553
+ return false;
554
+ }
555
+ if (caretOffset !== -1) {
556
+ get();
557
+ caretOffset = $$.val().length - caretOffset;
558
+ set(caretOffset, 0);
559
+ caretOffset = -1;
560
+ return false;
561
+ } else {
562
+ markup(options.onTab);
563
+ return options.onTab.keepDefault;
564
+ }
565
+ }
566
+ }
567
+ }
568
+
569
+ init();
570
+ });
571
+ };
572
+
573
+ $.fn.markItUpRemove = function() {
574
+ return this.each(function() {
575
+ var $$ = $(this).unbind().removeClass('markItUpEditor');
576
+ $$.parent('div').parent('div.markItUp').parent('div').replaceWith($$);
577
+ }
578
+ );
579
+ };
580
+
581
+ $.markItUp = function(settings) {
582
+ var options = { target:false };
583
+ $.extend(options, settings);
584
+ if (options.target) {
585
+ return $(options.target).each(function() {
586
+ $(this).focus();
587
+ $(this).trigger('insertion', [options]);
588
+ });
589
+ } else {
590
+ $('textarea').trigger('insertion', [options]);
591
+ }
592
+ };
593
+ })(jQuery);
@@ -0,0 +1,53 @@
1
+ // -------------------------------------------------------------------
2
+ // markItUp!
3
+ // -------------------------------------------------------------------
4
+ // Copyright (C) 2008 Jay Salvat
5
+ // http://markitup.jaysalvat.com/
6
+ // -------------------------------------------------------------------
7
+ // MarkDown tags example
8
+ // http://en.wikipedia.org/wiki/Markdown
9
+ // http://daringfireball.net/projects/markdown/
10
+ // -------------------------------------------------------------------
11
+ // Feel free to add more tags
12
+ // -------------------------------------------------------------------
13
+ mySettings = {
14
+ previewParserPath: '',
15
+ onShiftEnter: {keepDefault:false, openWith:'\n\n'},
16
+ markupSet: [
17
+ {name:'First Level Heading', key:'1', placeHolder:'Your title here...', openWith: '#' },
18
+ {name:'Second Level Heading', key:'2', placeHolder:'Your title here...', openWith: '##' },
19
+ {name:'Heading 3', key:'3', openWith:'### ', placeHolder:'Your title here...' },
20
+ {name:'Heading 4', key:'4', openWith:'#### ', placeHolder:'Your title here...' },
21
+ {name:'Heading 5', key:'5', openWith:'##### ', placeHolder:'Your title here...' },
22
+ {name:'Heading 6', key:'6', openWith:'###### ', placeHolder:'Your title here...' },
23
+ {separator:'---------------' },
24
+ {name:'Bold', key:'B', openWith:'**', closeWith:'**'},
25
+ {name:'Italic', key:'I', openWith:'_', closeWith:'_'},
26
+ {separator:'---------------' },
27
+ {name:'Bulleted List', openWith:'- ' },
28
+ {name:'Numeric List', openWith:function(markItUp) {
29
+ return markItUp.line+'. ';
30
+ }},
31
+ {separator:'---------------' },
32
+ {name:'Picture', key:'P', replaceWith:'![[![Alternative text]!]]([![Url:!:http://]!] "[![Title]!]")'},
33
+ {name:'Link', key:'L', openWith:'[', closeWith:']([![Url:!:http://]!] "[![Title]!]")', placeHolder:'Your text to link here...' },
34
+ {separator:'---------------'},
35
+ {name:'Quotes', openWith:'> '},
36
+ {name:'Code Block', openBlockWith:'```[![Language]!]\n', closeBlockWith:'\n```', multiline: false },
37
+ {name:'Code', openWith: '`', closeWith: '`' },
38
+ {separator:'---------------'},
39
+ {name:'Preview', call:'preview', className:"preview"}
40
+ ]
41
+ }
42
+
43
+ // mIu nameSpace to avoid conflict.
44
+ miu = {
45
+ markdownTitle: function(markItUp, char) {
46
+ heading = '';
47
+ n = $.trim(markItUp.selection||markItUp.placeHolder).length;
48
+ for(i = 0; i < n; i++) {
49
+ heading += char;
50
+ }
51
+ return '\n'+heading;
52
+ }
53
+ }
@@ -0,0 +1,39 @@
1
+ form {
2
+ width: 75%;
3
+ min-width: 700px;
4
+ margin: 0 auto;
5
+
6
+ ol, ul {
7
+ margin: 0;
8
+ }
9
+
10
+ fieldset.inputs {
11
+ padding: 1px;
12
+
13
+ > legend {
14
+ margin-left: 100px;
15
+ }
16
+
17
+ li.input:not(.boolean) {
18
+ > label {
19
+ display: inline-block;
20
+ width: 140px;
21
+ padding-right: 2px;
22
+ text-align: right;
23
+ vertical-align: top;
24
+
25
+ &:after {
26
+ content: ':';
27
+ }
28
+ }
29
+
30
+ > div {
31
+ display: inline-block;
32
+ }
33
+ }
34
+
35
+ li.input.boolean {
36
+ margin-left: 142px;
37
+ }
38
+ }
39
+ }