tawork 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +16 -0
  4. data/Gemfile +91 -0
  5. data/Gemfile.lock +295 -0
  6. data/MIT-LICENSE +20 -0
  7. data/Procfile +2 -0
  8. data/README.md +1 -0
  9. data/Rakefile +6 -0
  10. data/app/assets/images/.keep +0 -0
  11. data/app/assets/javascripts/application.js +31 -0
  12. data/app/assets/javascripts/backbone/models/.gitkeep +0 -0
  13. data/app/assets/javascripts/backbone/routers/.gitkeep +0 -0
  14. data/app/assets/javascripts/backbone/tawork.js.coffee +11 -0
  15. data/app/assets/javascripts/backbone/templates/.gitkeep +0 -0
  16. data/app/assets/javascripts/backbone/views/.gitkeep +0 -0
  17. data/app/assets/javascripts/backbone/views/page.js.coffee +75 -0
  18. data/app/assets/javascripts/backbone/views/ticket.js.coffee +110 -0
  19. data/app/assets/javascripts/backbone/views/tree_node_page.js.coffee +16 -0
  20. data/app/assets/javascripts/backbone/views/tree_node_ticket.js.coffee +14 -0
  21. data/app/assets/javascripts/wiki/pages.js.coffee +3 -0
  22. data/app/assets/stylesheets/application.css +22 -0
  23. data/app/assets/stylesheets/bootstrap_and_overrides.sass +208 -0
  24. data/app/assets/stylesheets/diff.css +14 -0
  25. data/app/assets/stylesheets/wiki/pages.css.scss +3 -0
  26. data/app/controllers/application_controller.rb +15 -0
  27. data/app/controllers/assignments_controller.rb +30 -0
  28. data/app/controllers/attachments_controller.rb +10 -0
  29. data/app/controllers/comments_controller.rb +24 -0
  30. data/app/controllers/concerns/.keep +0 -0
  31. data/app/controllers/home_controller.rb +7 -0
  32. data/app/controllers/projects_controller.rb +31 -0
  33. data/app/controllers/search_controller.rb +49 -0
  34. data/app/controllers/sink_controller.rb +10 -0
  35. data/app/controllers/tickets_controller.rb +147 -0
  36. data/app/controllers/users/omniauth_callbacks_controller.rb +23 -0
  37. data/app/controllers/wiki/pages_controller.rb +115 -0
  38. data/app/controllers/wiki/spaces_controller.rb +37 -0
  39. data/app/helpers/application_helper.rb +20 -0
  40. data/app/helpers/wiki/pages_helper.rb +2 -0
  41. data/app/inputs/fake_input.rb +6 -0
  42. data/app/mailers/.keep +0 -0
  43. data/app/models/.keep +0 -0
  44. data/app/models/assignment.rb +5 -0
  45. data/app/models/attachment.rb +54 -0
  46. data/app/models/bug.rb +2 -0
  47. data/app/models/comment.rb +6 -0
  48. data/app/models/concerns/.keep +0 -0
  49. data/app/models/page.rb +68 -0
  50. data/app/models/project.rb +2 -0
  51. data/app/models/space.rb +2 -0
  52. data/app/models/story.rb +29 -0
  53. data/app/models/story_detail.rb +3 -0
  54. data/app/models/task.rb +2 -0
  55. data/app/models/ticket.rb +127 -0
  56. data/app/models/user.rb +36 -0
  57. data/app/models/user_verifier.rb +2 -0
  58. data/app/views/comments/_comment.html.haml +6 -0
  59. data/app/views/comments/_form.html.haml +4 -0
  60. data/app/views/comments/create.js.coffee +7 -0
  61. data/app/views/devise/confirmations/new.html.erb +12 -0
  62. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  63. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  64. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  65. data/app/views/devise/passwords/edit.html.erb +16 -0
  66. data/app/views/devise/passwords/new.html.erb +12 -0
  67. data/app/views/devise/registrations/edit.html.erb +29 -0
  68. data/app/views/devise/registrations/new.html.erb +18 -0
  69. data/app/views/devise/sessions/new.html.erb +17 -0
  70. data/app/views/devise/shared/_links.erb +25 -0
  71. data/app/views/devise/unlocks/new.html.erb +12 -0
  72. data/app/views/home/index.html.haml +4 -0
  73. data/app/views/layouts/_activity_wrapper.html.haml +17 -0
  74. data/app/views/layouts/_nav_header.html.haml +26 -0
  75. data/app/views/layouts/_spaces.html.haml +34 -0
  76. data/app/views/layouts/application.html.haml +39 -0
  77. data/app/views/layouts/minimal.html.haml +22 -0
  78. data/app/views/projects/index.html.haml +16 -0
  79. data/app/views/projects/new.html.haml +6 -0
  80. data/app/views/public_activity/ticket/_assignment.html.haml +14 -0
  81. data/app/views/public_activity/ticket/_create_comment.html.haml +10 -0
  82. data/app/views/public_activity/ticket/_created.html.haml +3 -0
  83. data/app/views/public_activity/ticket/_reorder.html.haml +2 -0
  84. data/app/views/public_activity/ticket/_state_change.html.haml +2 -0
  85. data/app/views/public_activity/ticket/_update_details.html.haml +13 -0
  86. data/app/views/tickets/_activity.html.haml +3 -0
  87. data/app/views/tickets/_breadcrumb.html.haml +7 -0
  88. data/app/views/tickets/_bug_form.html.haml +1 -0
  89. data/app/views/tickets/_events_dropdown.html.haml +4 -0
  90. data/app/views/tickets/_form.html.haml +28 -0
  91. data/app/views/tickets/_project_form.html.haml +1 -0
  92. data/app/views/tickets/_story_form.html.haml +15 -0
  93. data/app/views/tickets/_task_form.html.haml +8 -0
  94. data/app/views/tickets/_tickets_listing.html.haml +5 -0
  95. data/app/views/tickets/_title_and_description.html.haml +8 -0
  96. data/app/views/tickets/_tree_node.html.haml +28 -0
  97. data/app/views/tickets/assignment.js.coffee +3 -0
  98. data/app/views/tickets/create.js.coffee +7 -0
  99. data/app/views/tickets/new.html.haml +1 -0
  100. data/app/views/tickets/show.html.haml +64 -0
  101. data/app/views/tickets/trigger_event.js.coffee +12 -0
  102. data/app/views/tickets/update.js.coffee +12 -0
  103. data/app/views/wiki/pages/_attachment.html.haml +5 -0
  104. data/app/views/wiki/pages/_attachments.html.haml +22 -0
  105. data/app/views/wiki/pages/_breadcrumb.html.haml +9 -0
  106. data/app/views/wiki/pages/_child_menu.html.haml +9 -0
  107. data/app/views/wiki/pages/_display.html.haml +138 -0
  108. data/app/views/wiki/pages/_page_header.html.haml +13 -0
  109. data/app/views/wiki/pages/_subpages_dropdown.html.haml +6 -0
  110. data/app/views/wiki/pages/_subtree.html.haml +7 -0
  111. data/app/views/wiki/pages/_tree_node.html.haml +21 -0
  112. data/app/views/wiki/pages/attach.js.coffee +2 -0
  113. data/app/views/wiki/pages/combined.html.haml +8 -0
  114. data/app/views/wiki/pages/create.js.coffee +5 -0
  115. data/app/views/wiki/pages/edit.html.haml +2 -0
  116. data/app/views/wiki/pages/history.html.haml +13 -0
  117. data/app/views/wiki/pages/index.html.haml +2 -0
  118. data/app/views/wiki/pages/new.html.haml +13 -0
  119. data/app/views/wiki/pages/show.html.haml +14 -0
  120. data/app/views/wiki/pages/update.html.haml +2 -0
  121. data/app/views/wiki/spaces/_page_list_item.html.haml +11 -0
  122. data/app/views/wiki/spaces/_space_list.html.haml +4 -0
  123. data/app/views/wiki/spaces/new.html.haml +5 -0
  124. data/app/views/wiki/spaces/space_list.html.haml +1 -0
  125. data/bin/bundle +3 -0
  126. data/bin/rails +4 -0
  127. data/bin/rake +4 -0
  128. data/config/application.rb +30 -0
  129. data/config/boot.rb +4 -0
  130. data/config/database.yml +39 -0
  131. data/config/environment.rb +5 -0
  132. data/config/environments/development.rb +35 -0
  133. data/config/environments/production.rb +80 -0
  134. data/config/environments/test.rb +36 -0
  135. data/config/initializers/backtrace_silencers.rb +7 -0
  136. data/config/initializers/config.rb +4 -0
  137. data/config/initializers/devise.rb +257 -0
  138. data/config/initializers/elasticsearch.rb +9 -0
  139. data/config/initializers/filter_parameter_logging.rb +4 -0
  140. data/config/initializers/gollum.rb +31 -0
  141. data/config/initializers/haml_gfm.rb +66 -0
  142. data/config/initializers/inflections.rb +16 -0
  143. data/config/initializers/mime_types.rb +5 -0
  144. data/config/initializers/secret_token.rb +12 -0
  145. data/config/initializers/session_store.rb +3 -0
  146. data/config/initializers/simple_form.rb +145 -0
  147. data/config/initializers/simple_form_bootstrap.rb +73 -0
  148. data/config/initializers/wrap_parameters.rb +14 -0
  149. data/config/locales/devise.en.yml +59 -0
  150. data/config/locales/en.yml +23 -0
  151. data/config/locales/simple_form.en.yml +26 -0
  152. data/config/routes.rb +101 -0
  153. data/config/tinymce.yml +10 -0
  154. data/config.ru +4 -0
  155. data/db/migrate/20131209041251_create_tickets.rb +13 -0
  156. data/db/migrate/20131210041050_devise_create_users.rb +42 -0
  157. data/db/migrate/20131210043014_add_username_to_users.rb +5 -0
  158. data/db/migrate/20131210045348_add_creator_to_ticket.rb +5 -0
  159. data/db/migrate/20131211034104_create_comments.rb +11 -0
  160. data/db/migrate/20131212073014_create_assignments.rb +12 -0
  161. data/db/migrate/20131215220825_add_position_to_ticket.rb +5 -0
  162. data/db/migrate/20131216044331_create_story_details.rb +12 -0
  163. data/db/migrate/20131218060557_create_activities.rb +23 -0
  164. data/db/migrate/20140109235844_create_pages.rb +14 -0
  165. data/db/migrate/20140112004346_create_attachments.rb +13 -0
  166. data/db/migrate/20140120030547_add_name_to_users.rb +5 -0
  167. data/db/schema.rb +125 -0
  168. data/db/seeds.rb +7 -0
  169. data/init.rb +1 -0
  170. data/lib/assets/.keep +0 -0
  171. data/lib/tasks/.keep +0 -0
  172. data/lib/tawork/engine.rb +13 -0
  173. data/lib/tawork/version.rb +3 -0
  174. data/lib/tawork.rb +4 -0
  175. data/lib/templates/haml/scaffold/_form.html.haml +10 -0
  176. data/lib/ticket_assignment.rb +25 -0
  177. data/log/.keep +0 -0
  178. data/public/401.html +57 -0
  179. data/public/404.html +58 -0
  180. data/public/422.html +58 -0
  181. data/public/500.html +57 -0
  182. data/public/favicon.ico +0 -0
  183. data/public/robots.txt +5 -0
  184. data/tags +279 -0
  185. data/tawork.gemspec +24 -0
  186. data/vendor/.DS_Store +0 -0
  187. data/vendor/assets/.DS_Store +0 -0
  188. data/vendor/assets/javascripts/.keep +0 -0
  189. data/vendor/assets/javascripts/bootstrap-tagsinput.js +503 -0
  190. data/vendor/assets/javascripts/bootstrap-tree.js +15 -0
  191. data/vendor/assets/javascripts/bootstrap-typeahead.js +335 -0
  192. data/vendor/assets/javascripts/hallo.js +2949 -0
  193. data/vendor/assets/javascripts/highlight.pack.js +1 -0
  194. data/vendor/assets/javascripts/jquery.autosize.js +250 -0
  195. data/vendor/assets/javascripts/jquery.mjs.nestedSortable.js +613 -0
  196. data/vendor/assets/javascripts/rangy-core.js +94 -0
  197. data/vendor/assets/javascripts/tinymce/mention/plugin.js +358 -0
  198. data/vendor/assets/stylesheets/.keep +0 -0
  199. data/vendor/assets/stylesheets/bootflat-extensions.css +356 -0
  200. data/vendor/assets/stylesheets/bootflat-square.css +69 -0
  201. data/vendor/assets/stylesheets/bootflat.css +1556 -0
  202. data/vendor/assets/stylesheets/bootstrap-tagsinput.css +45 -0
  203. data/vendor/assets/stylesheets/bootstrap-tree.sass +82 -0
  204. data/vendor/assets/stylesheets/highlight/arta.css +160 -0
  205. data/vendor/assets/stylesheets/highlight/ascetic.css +50 -0
  206. data/vendor/assets/stylesheets/highlight/brown_paper.css +105 -0
  207. data/vendor/assets/stylesheets/highlight/brown_papersq.png +0 -0
  208. data/vendor/assets/stylesheets/highlight/dark.css +105 -0
  209. data/vendor/assets/stylesheets/highlight/default.css +153 -0
  210. data/vendor/assets/stylesheets/highlight/docco.css +132 -0
  211. data/vendor/assets/stylesheets/highlight/far.css +113 -0
  212. data/vendor/assets/stylesheets/highlight/foundation.css +133 -0
  213. data/vendor/assets/stylesheets/highlight/github.css +130 -0
  214. data/vendor/assets/stylesheets/highlight/googlecode.css +146 -0
  215. data/vendor/assets/stylesheets/highlight/idea.css +122 -0
  216. data/vendor/assets/stylesheets/highlight/ir_black.css +105 -0
  217. data/vendor/assets/stylesheets/highlight/magula.css +123 -0
  218. data/vendor/assets/stylesheets/highlight/mono-blue.css +62 -0
  219. data/vendor/assets/stylesheets/highlight/monokai.css +127 -0
  220. data/vendor/assets/stylesheets/highlight/monokai_sublime.css +102 -0
  221. data/vendor/assets/stylesheets/highlight/obsidian.css +154 -0
  222. data/vendor/assets/stylesheets/highlight/pojoaque.css +105 -0
  223. data/vendor/assets/stylesheets/highlight/pojoaque.jpg +0 -0
  224. data/vendor/assets/stylesheets/highlight/railscasts.css +182 -0
  225. data/vendor/assets/stylesheets/highlight/rainbow.css +115 -0
  226. data/vendor/assets/stylesheets/highlight/school_book.css +113 -0
  227. data/vendor/assets/stylesheets/highlight/school_book.png +0 -0
  228. data/vendor/assets/stylesheets/highlight/solarized_dark.css +92 -0
  229. data/vendor/assets/stylesheets/highlight/solarized_light.css +92 -0
  230. data/vendor/assets/stylesheets/highlight/sunburst.css +160 -0
  231. data/vendor/assets/stylesheets/highlight/tomorrow-night-blue.css +52 -0
  232. data/vendor/assets/stylesheets/highlight/tomorrow-night-bright.css +51 -0
  233. data/vendor/assets/stylesheets/highlight/tomorrow-night-eighties.css +51 -0
  234. data/vendor/assets/stylesheets/highlight/tomorrow-night.css +52 -0
  235. data/vendor/assets/stylesheets/highlight/tomorrow.css +49 -0
  236. data/vendor/assets/stylesheets/highlight/vs.css +89 -0
  237. data/vendor/assets/stylesheets/highlight/xcode.css +157 -0
  238. data/vendor/assets/stylesheets/highlight/zenburn.css +117 -0
  239. metadata +299 -0
@@ -0,0 +1,613 @@
1
+ /*
2
+ * jQuery UI Nested Sortable
3
+ * v 2.0 / 29 oct 2012
4
+ * http://mjsarfatti.com/sandbox/nestedSortable
5
+ *
6
+ * Depends on:
7
+ * jquery.ui.sortable.js 1.10+
8
+ *
9
+ * Copyright (c) 2010-2013 Manuele J Sarfatti
10
+ * Licensed under the MIT License
11
+ * http://www.opensource.org/licenses/mit-license.php
12
+ */
13
+
14
+ (function($) {
15
+
16
+ function isOverAxis( x, reference, size ) {
17
+ return ( x > reference ) && ( x < ( reference + size ) );
18
+ }
19
+
20
+ $.widget("mjs.nestedSortable", $.extend({}, $.ui.sortable.prototype, {
21
+
22
+ options: {
23
+ doNotClear: false,
24
+ expandOnHover: 700,
25
+ isAllowed: function(placeholder, placeholderParent, originalItem) { return true; },
26
+ isTree: false,
27
+ listType: 'ol',
28
+ maxLevels: 0,
29
+ protectRoot: false,
30
+ rootID: null,
31
+ rtl: false,
32
+ startCollapsed: false,
33
+ tabSize: 20,
34
+
35
+ branchClass: 'mjs-nestedSortable-branch',
36
+ collapsedClass: 'mjs-nestedSortable-collapsed',
37
+ disableNestingClass: 'mjs-nestedSortable-no-nesting',
38
+ errorClass: 'mjs-nestedSortable-error',
39
+ expandedClass: 'mjs-nestedSortable-expanded',
40
+ hoveringClass: 'mjs-nestedSortable-hovering',
41
+ leafClass: 'mjs-nestedSortable-leaf'
42
+ },
43
+
44
+ _create: function() {
45
+ this.element.data('ui-sortable', this.element.data('mjs-nestedSortable'));
46
+
47
+ // mjs - prevent browser from freezing if the HTML is not correct
48
+ if (!this.element.is(this.options.listType))
49
+ throw new Error('nestedSortable: Please check that the listType option is set to your actual list type');
50
+
51
+ // mjs - force 'intersect' tolerance method if we have a tree with expanding/collapsing functionality
52
+ if (this.options.isTree && this.options.expandOnHover) {
53
+ this.options.tolerance = 'intersect';
54
+ }
55
+
56
+ $.ui.sortable.prototype._create.apply(this, arguments);
57
+
58
+ // mjs - prepare the tree by applying the right classes (the CSS is responsible for actual hide/show functionality)
59
+ if (this.options.isTree) {
60
+ var self = this;
61
+ $(this.items).each(function() {
62
+ var $li = this.item;
63
+ if ($li.children(self.options.listType).length) {
64
+ $li.addClass(self.options.branchClass);
65
+ // expand/collapse class only if they have children
66
+ if (self.options.startCollapsed) $li.addClass(self.options.collapsedClass);
67
+ else $li.addClass(self.options.expandedClass);
68
+ } else {
69
+ $li.addClass(self.options.leafClass);
70
+ }
71
+ })
72
+ }
73
+ },
74
+
75
+ _destroy: function() {
76
+ this.element
77
+ .removeData("mjs-nestedSortable")
78
+ .removeData("ui-sortable");
79
+ return $.ui.sortable.prototype._destroy.apply(this, arguments);
80
+ },
81
+
82
+ _mouseDrag: function(event) {
83
+ var i, item, itemElement, intersection,
84
+ o = this.options,
85
+ scrolled = false;
86
+
87
+ //Compute the helpers position
88
+ this.position = this._generatePosition(event);
89
+ this.positionAbs = this._convertPositionTo("absolute");
90
+
91
+ if (!this.lastPositionAbs) {
92
+ this.lastPositionAbs = this.positionAbs;
93
+ }
94
+
95
+ //Do scrolling
96
+ if(this.options.scroll) {
97
+ if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') {
98
+
99
+ if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) {
100
+ this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
101
+ } else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity) {
102
+ this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed;
103
+ }
104
+
105
+ if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) {
106
+ this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed;
107
+ } else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity) {
108
+ this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
109
+ }
110
+
111
+ } else {
112
+
113
+ if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) {
114
+ scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
115
+ } else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) {
116
+ scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
117
+ }
118
+
119
+ if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) {
120
+ scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
121
+ } else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) {
122
+ scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
123
+ }
124
+
125
+ }
126
+
127
+ if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
128
+ $.ui.ddmanager.prepareOffsets(this, event);
129
+ }
130
+
131
+ //Regenerate the absolute position used for position checks
132
+ this.positionAbs = this._convertPositionTo("absolute");
133
+
134
+ // mjs - find the top offset before rearrangement,
135
+ var previousTopOffset = this.placeholder.offset().top;
136
+
137
+ //Set the helper position
138
+ if(!this.options.axis || this.options.axis !== "y") {
139
+ this.helper[0].style.left = this.position.left+"px";
140
+ }
141
+ if(!this.options.axis || this.options.axis !== "x") {
142
+ this.helper[0].style.top = this.position.top+"px";
143
+ }
144
+
145
+ // mjs - check and reset hovering state at each cycle
146
+ this.hovering = this.hovering ? this.hovering : null;
147
+ this.mouseentered = this.mouseentered ? this.mouseentered : false;
148
+
149
+ // mjs - let's start caching some variables
150
+ var parentItem = (this.placeholder[0].parentNode.parentNode &&
151
+ $(this.placeholder[0].parentNode.parentNode).closest('.ui-sortable').length)
152
+ ? $(this.placeholder[0].parentNode.parentNode)
153
+ : null,
154
+ level = this._getLevel(this.placeholder),
155
+ childLevels = this._getChildLevels(this.helper);
156
+
157
+ var newList = document.createElement(o.listType);
158
+
159
+ //Rearrange
160
+ for (i = this.items.length - 1; i >= 0; i--) {
161
+
162
+ //Cache variables and intersection, continue if no intersection
163
+ item = this.items[i];
164
+ itemElement = item.item[0];
165
+ intersection = this._intersectsWithPointer(item);
166
+ if (!intersection) {
167
+ continue;
168
+ }
169
+
170
+ // Only put the placeholder inside the current Container, skip all
171
+ // items form other containers. This works because when moving
172
+ // an item from one container to another the
173
+ // currentContainer is switched before the placeholder is moved.
174
+ //
175
+ // Without this moving items in "sub-sortables" can cause the placeholder to jitter
176
+ // beetween the outer and inner container.
177
+ if (item.instance !== this.currentContainer) {
178
+ continue;
179
+ }
180
+
181
+ // cannot intersect with itself
182
+ // no useless actions that have been done before
183
+ // no action if the item moved is the parent of the item checked
184
+ if (itemElement !== this.currentItem[0] &&
185
+ this.placeholder[intersection === 1 ? "next" : "prev"]()[0] !== itemElement &&
186
+ !$.contains(this.placeholder[0], itemElement) &&
187
+ (this.options.type === "semi-dynamic" ? !$.contains(this.element[0], itemElement) : true)
188
+ ) {
189
+
190
+ // mjs - we are intersecting an element: trigger the mouseenter event and store this state
191
+ if (!this.mouseentered) {
192
+ $(itemElement).mouseenter();
193
+ this.mouseentered = true;
194
+ }
195
+
196
+ // mjs - if the element has children and they are hidden, show them after a delay (CSS responsible)
197
+ if (o.isTree && $(itemElement).hasClass(o.collapsedClass) && o.expandOnHover) {
198
+ if (!this.hovering) {
199
+ $(itemElement).addClass(o.hoveringClass);
200
+ var self = this;
201
+ this.hovering = window.setTimeout(function() {
202
+ $(itemElement).removeClass(o.collapsedClass).addClass(o.expandedClass);
203
+ self.refreshPositions();
204
+ self._trigger("expand", event, self._uiHash());
205
+ }, o.expandOnHover);
206
+ }
207
+ }
208
+
209
+ this.direction = intersection == 1 ? "down" : "up";
210
+
211
+ // mjs - rearrange the elements and reset timeouts and hovering state
212
+ if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) {
213
+ $(itemElement).mouseleave();
214
+ this.mouseentered = false;
215
+ $(itemElement).removeClass(o.hoveringClass);
216
+ this.hovering && window.clearTimeout(this.hovering);
217
+ this.hovering = null;
218
+
219
+ // mjs - do not switch container if it's a root item and 'protectRoot' is true
220
+ // or if it's not a root item but we are trying to make it root
221
+ if (o.protectRoot
222
+ && ! (this.currentItem[0].parentNode == this.element[0] // it's a root item
223
+ && itemElement.parentNode != this.element[0]) // it's intersecting a non-root item
224
+ ) {
225
+ if (this.currentItem[0].parentNode != this.element[0]
226
+ && itemElement.parentNode == this.element[0]
227
+ ) {
228
+
229
+ if ( ! $(itemElement).children(o.listType).length) {
230
+ itemElement.appendChild(newList);
231
+ o.isTree && $(itemElement).removeClass(o.leafClass).addClass(o.branchClass + ' ' + o.expandedClass);
232
+ }
233
+
234
+ var a = this.direction === "down" ? $(itemElement).prev().children(o.listType) : $(itemElement).children(o.listType);
235
+ if (a[0] !== undefined) {
236
+ this._rearrange(event, null, a);
237
+ }
238
+
239
+ } else {
240
+ this._rearrange(event, item);
241
+ }
242
+ } else if ( ! o.protectRoot) {
243
+ this._rearrange(event, item);
244
+ }
245
+ } else {
246
+ break;
247
+ }
248
+
249
+ // Clear emtpy ul's/ol's
250
+ this._clearEmpty(itemElement);
251
+
252
+ this._trigger("change", event, this._uiHash());
253
+ break;
254
+ }
255
+ }
256
+
257
+ // mjs - to find the previous sibling in the list, keep backtracking until we hit a valid list item.
258
+ var previousItem = this.placeholder[0].previousSibling ? $(this.placeholder[0].previousSibling) : null;
259
+ if (previousItem != null) {
260
+ while (previousItem[0].nodeName.toLowerCase() != 'li' || previousItem[0] == this.currentItem[0] || previousItem[0] == this.helper[0]) {
261
+ if (previousItem[0].previousSibling) {
262
+ previousItem = $(previousItem[0].previousSibling);
263
+ } else {
264
+ previousItem = null;
265
+ break;
266
+ }
267
+ }
268
+ }
269
+
270
+ // mjs - to find the next sibling in the list, keep stepping forward until we hit a valid list item.
271
+ var nextItem = this.placeholder[0].nextSibling ? $(this.placeholder[0].nextSibling) : null;
272
+ if (nextItem != null) {
273
+ while (nextItem[0].nodeName.toLowerCase() != 'li' || nextItem[0] == this.currentItem[0] || nextItem[0] == this.helper[0]) {
274
+ if (nextItem[0].nextSibling) {
275
+ nextItem = $(nextItem[0].nextSibling);
276
+ } else {
277
+ nextItem = null;
278
+ break;
279
+ }
280
+ }
281
+ }
282
+
283
+ this.beyondMaxLevels = 0;
284
+
285
+ // mjs - if the item is moved to the left, send it one level up but only if it's at the bottom of the list
286
+ if (parentItem != null
287
+ && nextItem == null
288
+ && ! (o.protectRoot && parentItem[0].parentNode == this.element[0])
289
+ &&
290
+ (o.rtl && (this.positionAbs.left + this.helper.outerWidth() > parentItem.offset().left + parentItem.outerWidth())
291
+ || ! o.rtl && (this.positionAbs.left < parentItem.offset().left))
292
+ ) {
293
+
294
+ parentItem.after(this.placeholder[0]);
295
+ if (o.isTree && parentItem.children(o.listItem).children('li:visible:not(.ui-sortable-helper)').length < 1) {
296
+ parentItem.removeClass(this.options.branchClass + ' ' + this.options.expandedClass)
297
+ .addClass(this.options.leafClass);
298
+ }
299
+ this._clearEmpty(parentItem[0]);
300
+ this._trigger("change", event, this._uiHash());
301
+ }
302
+ // mjs - if the item is below a sibling and is moved to the right, make it a child of that sibling
303
+ else if (previousItem != null
304
+ && ! previousItem.hasClass(o.disableNestingClass)
305
+ &&
306
+ (previousItem.children(o.listType).length && previousItem.children(o.listType).is(':visible')
307
+ || ! previousItem.children(o.listType).length)
308
+ && ! (o.protectRoot && this.currentItem[0].parentNode == this.element[0])
309
+ &&
310
+ (o.rtl && (this.positionAbs.left + this.helper.outerWidth() < previousItem.offset().left + previousItem.outerWidth() - o.tabSize)
311
+ || ! o.rtl && (this.positionAbs.left > previousItem.offset().left + o.tabSize))
312
+ ) {
313
+
314
+ this._isAllowed(previousItem, level, level+childLevels+1);
315
+
316
+ if (!previousItem.children(o.listType).length) {
317
+ previousItem[0].appendChild(newList);
318
+ o.isTree && previousItem.removeClass(o.leafClass).addClass(o.branchClass + ' ' + o.expandedClass);
319
+ }
320
+
321
+ // mjs - if this item is being moved from the top, add it to the top of the list.
322
+ if (previousTopOffset && (previousTopOffset <= previousItem.offset().top)) {
323
+ previousItem.children(o.listType).prepend(this.placeholder);
324
+ }
325
+ // mjs - otherwise, add it to the bottom of the list.
326
+ else {
327
+ previousItem.children(o.listType)[0].appendChild(this.placeholder[0]);
328
+ }
329
+
330
+ this._trigger("change", event, this._uiHash());
331
+ }
332
+ else {
333
+ this._isAllowed(parentItem, level, level+childLevels);
334
+ }
335
+
336
+ //Post events to containers
337
+ this._contactContainers(event);
338
+
339
+ //Interconnect with droppables
340
+ if($.ui.ddmanager) {
341
+ $.ui.ddmanager.drag(this, event);
342
+ }
343
+
344
+ //Call callbacks
345
+ this._trigger('sort', event, this._uiHash());
346
+
347
+ this.lastPositionAbs = this.positionAbs;
348
+ return false;
349
+
350
+ },
351
+
352
+ _mouseStop: function(event, noPropagation) {
353
+
354
+ // mjs - if the item is in a position not allowed, send it back
355
+ if (this.beyondMaxLevels) {
356
+
357
+ this.placeholder.removeClass(this.options.errorClass);
358
+
359
+ if (this.domPosition.prev) {
360
+ $(this.domPosition.prev).after(this.placeholder);
361
+ } else {
362
+ $(this.domPosition.parent).prepend(this.placeholder);
363
+ }
364
+
365
+ this._trigger("revert", event, this._uiHash());
366
+
367
+ }
368
+
369
+
370
+ // mjs - clear the hovering timeout, just to be sure
371
+ $('.'+this.options.hoveringClass).mouseleave().removeClass(this.options.hoveringClass);
372
+ this.mouseentered = false;
373
+ this.hovering && window.clearTimeout(this.hovering);
374
+ this.hovering = null;
375
+
376
+ $.ui.sortable.prototype._mouseStop.apply(this, arguments);
377
+
378
+ },
379
+
380
+ // mjs - this function is slightly modified to make it easier to hover over a collapsed element and have it expand
381
+ _intersectsWithSides: function(item) {
382
+
383
+ var half = this.options.isTree ? .8 : .5;
384
+
385
+ var isOverBottomHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height*half), item.height),
386
+ isOverTopHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top - (item.height*half), item.height),
387
+ isOverRightHalf = isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
388
+ verticalDirection = this._getDragVerticalDirection(),
389
+ horizontalDirection = this._getDragHorizontalDirection();
390
+
391
+ if (this.floating && horizontalDirection) {
392
+ return ((horizontalDirection == "right" && isOverRightHalf) || (horizontalDirection == "left" && !isOverRightHalf));
393
+ } else {
394
+ return verticalDirection && ((verticalDirection == "down" && isOverBottomHalf) || (verticalDirection == "up" && isOverTopHalf));
395
+ }
396
+
397
+ },
398
+
399
+ _contactContainers: function(event) {
400
+
401
+ if (this.options.protectRoot && this.currentItem[0].parentNode == this.element[0] ) {
402
+ return;
403
+ }
404
+
405
+ $.ui.sortable.prototype._contactContainers.apply(this, arguments);
406
+
407
+ },
408
+
409
+ _clear: function(event, noPropagation) {
410
+
411
+ $.ui.sortable.prototype._clear.apply(this, arguments);
412
+
413
+ // mjs - clean last empty ul/ol
414
+ for (var i = this.items.length - 1; i >= 0; i--) {
415
+ var item = this.items[i].item[0];
416
+ this._clearEmpty(item);
417
+ }
418
+
419
+ },
420
+
421
+ serialize: function(options) {
422
+
423
+ var o = $.extend({}, this.options, options),
424
+ items = this._getItemsAsjQuery(o && o.connected),
425
+ str = [];
426
+
427
+ $(items).each(function() {
428
+ var res = ($(o.item || this).attr(o.attribute || 'id') || '')
429
+ .match(o.expression || (/(.+)[-=_](.+)/)),
430
+ pid = ($(o.item || this).parent(o.listType)
431
+ .parent(o.items)
432
+ .attr(o.attribute || 'id') || '')
433
+ .match(o.expression || (/(.+)[-=_](.+)/));
434
+
435
+ if (res) {
436
+ str.push(((o.key || res[1]) + '[' + (o.key && o.expression ? res[1] : res[2]) + ']')
437
+ + '='
438
+ + (pid ? (o.key && o.expression ? pid[1] : pid[2]) : o.rootID));
439
+ }
440
+ });
441
+
442
+ if(!str.length && o.key) {
443
+ str.push(o.key + '=');
444
+ }
445
+
446
+ return str.join('&');
447
+
448
+ },
449
+
450
+ toHierarchy: function(options) {
451
+
452
+ var o = $.extend({}, this.options, options),
453
+ sDepth = o.startDepthCount || 0,
454
+ ret = [];
455
+
456
+ $(this.element).children(o.items).each(function () {
457
+ var level = _recursiveItems(this);
458
+ ret.push(level);
459
+ });
460
+
461
+ return ret;
462
+
463
+ function _recursiveItems(item) {
464
+ var id = ($(item).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
465
+ if (id) {
466
+ var currentItem = {"id" : id[2]};
467
+ if ($(item).children(o.listType).children(o.items).length > 0) {
468
+ currentItem.children = [];
469
+ $(item).children(o.listType).children(o.items).each(function() {
470
+ var level = _recursiveItems(this);
471
+ currentItem.children.push(level);
472
+ });
473
+ }
474
+ return currentItem;
475
+ }
476
+ }
477
+ },
478
+
479
+ toArray: function(options) {
480
+
481
+ var o = $.extend({}, this.options, options),
482
+ sDepth = o.startDepthCount || 0,
483
+ ret = [],
484
+ left = 1;
485
+
486
+ if (!o.excludeRoot) {
487
+ ret.push({
488
+ "item_id": o.rootID,
489
+ "parent_id": null,
490
+ "depth": sDepth,
491
+ "left": left,
492
+ "right": ($(o.items, this.element).length + 1) * 2
493
+ });
494
+ left++
495
+ }
496
+
497
+ $(this.element).children(o.items).each(function () {
498
+ left = _recursiveArray(this, sDepth + 1, left);
499
+ });
500
+
501
+ ret = ret.sort(function(a,b){ return (a.left - b.left); });
502
+
503
+ return ret;
504
+
505
+ function _recursiveArray(item, depth, left) {
506
+
507
+ var right = left + 1,
508
+ id,
509
+ pid;
510
+
511
+ if ($(item).children(o.listType).children(o.items).length > 0) {
512
+ depth ++;
513
+ $(item).children(o.listType).children(o.items).each(function () {
514
+ right = _recursiveArray($(this), depth, right);
515
+ });
516
+ depth --;
517
+ }
518
+
519
+ id = ($(item).attr(o.attribute || 'id')).match(o.expression || (/(.+)[-=_](.+)/));
520
+
521
+ if (depth === sDepth + 1) {
522
+ pid = o.rootID;
523
+ } else {
524
+ var parentItem = ($(item).parent(o.listType)
525
+ .parent(o.items)
526
+ .attr(o.attribute || 'id'))
527
+ .match(o.expression || (/(.+)[-=_](.+)/));
528
+ pid = parentItem[2];
529
+ }
530
+
531
+ if (id) {
532
+ ret.push({"item_id": id[2], "parent_id": pid, "depth": depth, "left": left, "right": right});
533
+ }
534
+
535
+ left = right + 1;
536
+ return left;
537
+ }
538
+
539
+ },
540
+
541
+ _clearEmpty: function(item) {
542
+ var o = this.options;
543
+
544
+ var emptyList = $(item).children(o.listType);
545
+
546
+ if (emptyList.length && !emptyList.children().length && !o.doNotClear) {
547
+ o.isTree && $(item).removeClass(o.branchClass + ' ' + o.expandedClass).addClass(o.leafClass);
548
+ emptyList.remove();
549
+ } else if (o.isTree && emptyList.length && emptyList.children().length && emptyList.is(':visible')) {
550
+ $(item).removeClass(o.leafClass).addClass(o.branchClass + ' ' + o.expandedClass);
551
+ } else if (o.isTree && emptyList.length && emptyList.children().length && !emptyList.is(':visible')) {
552
+ $(item).removeClass(o.leafClass).addClass(o.branchClass + ' ' + o.collapsedClass);
553
+ }
554
+
555
+ },
556
+
557
+ _getLevel: function(item) {
558
+
559
+ var level = 1;
560
+
561
+ if (this.options.listType) {
562
+ var list = item.closest(this.options.listType);
563
+ while (list && list.length > 0 &&
564
+ !list.is('.ui-sortable')) {
565
+ level++;
566
+ list = list.parent().closest(this.options.listType);
567
+ }
568
+ }
569
+
570
+ return level;
571
+ },
572
+
573
+ _getChildLevels: function(parent, depth) {
574
+ var self = this,
575
+ o = this.options,
576
+ result = 0;
577
+ depth = depth || 0;
578
+
579
+ $(parent).children(o.listType).children(o.items).each(function (index, child) {
580
+ result = Math.max(self._getChildLevels(child, depth + 1), result);
581
+ });
582
+
583
+ return depth ? result + 1 : result;
584
+ },
585
+
586
+ _isAllowed: function(parentItem, level, levels) {
587
+ var o = this.options,
588
+ maxLevels = this.placeholder.closest('.ui-sortable').nestedSortable('option', 'maxLevels'); // this takes into account the maxLevels set to the recipient list
589
+
590
+ // mjs - is the root protected?
591
+ // mjs - are we nesting too deep?
592
+ if ( ! o.isAllowed(this.placeholder, parentItem, this.currentItem)) {
593
+ this.placeholder.addClass(o.errorClass);
594
+ if (maxLevels < levels && maxLevels != 0) {
595
+ this.beyondMaxLevels = levels - maxLevels;
596
+ } else {
597
+ this.beyondMaxLevels = 1;
598
+ }
599
+ } else {
600
+ if (maxLevels < levels && maxLevels != 0) {
601
+ this.placeholder.addClass(o.errorClass);
602
+ this.beyondMaxLevels = levels - maxLevels;
603
+ } else {
604
+ this.placeholder.removeClass(o.errorClass);
605
+ this.beyondMaxLevels = 0;
606
+ }
607
+ }
608
+ }
609
+
610
+ }));
611
+
612
+ $.mjs.nestedSortable.prototype.options = $.extend({}, $.ui.sortable.prototype.options, $.mjs.nestedSortable.prototype.options);
613
+ })(jQuery);