cmsimple 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. data/.gitignore +31 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +16 -0
  4. data/Gemfile +20 -0
  5. data/Gemfile.ci +5 -0
  6. data/LICENSE +19 -0
  7. data/README.md +118 -0
  8. data/Rakefile +47 -0
  9. data/app/assets/javascripts/cmsimple.js +61 -0
  10. data/app/assets/javascripts/cmsimple/controllers/editor.coffee +102 -0
  11. data/app/assets/javascripts/cmsimple/lib/namespaces.coffee +3 -0
  12. data/app/assets/javascripts/cmsimple/lib/support.coffee +4 -0
  13. data/app/assets/javascripts/cmsimple/mercury/config.js +462 -0
  14. data/app/assets/javascripts/cmsimple/mercury/handlers.coffee +9 -0
  15. data/app/assets/javascripts/cmsimple/models/image.coffee +49 -0
  16. data/app/assets/javascripts/cmsimple/models/page.coffee +106 -0
  17. data/app/assets/javascripts/cmsimple/models/path.coffee +31 -0
  18. data/app/assets/javascripts/cmsimple/models/version.coffee +29 -0
  19. data/app/assets/javascripts/cmsimple/panels/images/index.coffee +2 -0
  20. data/app/assets/javascripts/cmsimple/panels/images/list.coffee +48 -0
  21. data/app/assets/javascripts/cmsimple/panels/images/panel.coffee +69 -0
  22. data/app/assets/javascripts/cmsimple/panels/images/selection.coffee +52 -0
  23. data/app/assets/javascripts/cmsimple/panels/page_metadata.coffee +42 -0
  24. data/app/assets/javascripts/cmsimple/panels/publish.coffee +32 -0
  25. data/app/assets/javascripts/cmsimple/panels/redirects/form.coffee +51 -0
  26. data/app/assets/javascripts/cmsimple/panels/redirects/index.coffee +2 -0
  27. data/app/assets/javascripts/cmsimple/panels/redirects/list.coffee +34 -0
  28. data/app/assets/javascripts/cmsimple/panels/redirects/panel.coffee +39 -0
  29. data/app/assets/javascripts/cmsimple/panels/sitemap/index.coffee +2 -0
  30. data/app/assets/javascripts/cmsimple/panels/sitemap/panel.coffee +40 -0
  31. data/app/assets/javascripts/cmsimple/panels/sitemap/sortable.coffee +55 -0
  32. data/app/assets/javascripts/cmsimple/panels/sitemap/tree.coffee +61 -0
  33. data/app/assets/javascripts/cmsimple/panels/versions/index.coffee +2 -0
  34. data/app/assets/javascripts/cmsimple/panels/versions/list.coffee +51 -0
  35. data/app/assets/javascripts/cmsimple/panels/versions/panel.coffee +53 -0
  36. data/app/assets/javascripts/cmsimple/views/image_library/_item.jst.hamlc +24 -0
  37. data/app/assets/javascripts/cmsimple/views/image_library/list.jst.hamlc +8 -0
  38. data/app/assets/javascripts/cmsimple/views/redirects/_path.jst.hamlc +6 -0
  39. data/app/assets/javascripts/cmsimple/views/redirects/list.jst.hamlc +19 -0
  40. data/app/assets/javascripts/cmsimple/views/sitemap/_page.jst.hamlc +9 -0
  41. data/app/assets/javascripts/cmsimple/views/sitemap/tree.jst.hamlc +5 -0
  42. data/app/assets/javascripts/cmsimple/views/versions/_item.jst.hamlc +6 -0
  43. data/app/assets/javascripts/cmsimple/views/versions/list.jst.hamlc +4 -0
  44. data/app/assets/stylesheets/cmsimple.css +15 -0
  45. data/app/assets/stylesheets/cmsimple/forms.css +10 -0
  46. data/app/assets/stylesheets/cmsimple/panels.css +399 -0
  47. data/app/assets/stylesheets/cmsimple/toolbar-images.css +27 -0
  48. data/app/assets/stylesheets/mercury_overrides.css +2 -0
  49. data/app/controllers/cmsimple/front_controller.rb +38 -0
  50. data/app/controllers/cmsimple/images_controller.rb +28 -0
  51. data/app/controllers/cmsimple/mercury_controller.rb +7 -0
  52. data/app/controllers/cmsimple/pages_controller.rb +89 -0
  53. data/app/controllers/cmsimple/paths_controller.rb +23 -0
  54. data/app/controllers/cmsimple/snippets_controller.rb +23 -0
  55. data/app/controllers/cmsimple/versions_controller.rb +17 -0
  56. data/app/helpers/cmsimple/regions_helper.rb +38 -0
  57. data/app/models/cmsimple/image.rb +19 -0
  58. data/app/models/cmsimple/page.rb +203 -0
  59. data/app/models/cmsimple/path.rb +63 -0
  60. data/app/models/cmsimple/region.rb +43 -0
  61. data/app/models/cmsimple/snippet.rb +64 -0
  62. data/app/models/cmsimple/version.rb +18 -0
  63. data/app/uploaders/image_attachment_uploader.rb +53 -0
  64. data/app/views/cmsimple/images/_form.html.haml +13 -0
  65. data/app/views/cmsimple/images/new.html.haml +5 -0
  66. data/app/views/cmsimple/pages/_form.html.haml +49 -0
  67. data/app/views/cmsimple/pages/_form_extras.html.haml +2 -0
  68. data/app/views/cmsimple/pages/edit.html.haml +3 -0
  69. data/app/views/cmsimple/pages/new.html.haml +3 -0
  70. data/app/views/cmsimple/pages/publish.html.haml +12 -0
  71. data/app/views/cmsimple/snippets/index.html.haml +5 -0
  72. data/app/views/cmsimple/templates/default.html.haml +4 -0
  73. data/app/views/layouts/editor.html.haml +12 -0
  74. data/app/views/layouts/panel.html.haml +9 -0
  75. data/cmsimple.gemspec +44 -0
  76. data/config.ru +4 -0
  77. data/config/application.rb +1 -0
  78. data/config/cucumber.yml +8 -0
  79. data/config/environment.rb +2 -0
  80. data/config/routes.rb +34 -0
  81. data/db/migrate/20120201221410_create_cmsimple_pages.rb +10 -0
  82. data/db/migrate/20120222185901_add_title_parent_id_and_position_to_pages.rb +10 -0
  83. data/db/migrate/20120229185214_add_slug_to_pages.rb +7 -0
  84. data/db/migrate/20120323200439_add_is_root_to_page.rb +5 -0
  85. data/db/migrate/20120328174339_add_meta_info_to_cmsimple_pages.rb +9 -0
  86. data/db/migrate/20120329172857_create_cmsimple_path.rb +11 -0
  87. data/db/migrate/20120407024752_create_cmsimple_images.rb +13 -0
  88. data/db/migrate/20120410041105_add_timestamps_to_cmsimple_pages.rb +7 -0
  89. data/db/migrate/20120425211937_add_published_at_to_cmsimple_pages.rb +6 -0
  90. data/db/migrate/20120430175047_create_cmsimple_versions.rb +13 -0
  91. data/db/migrate/20120831233927_rename_path_to_current_uri_on_paths.rb +5 -0
  92. data/features/create.feature +18 -0
  93. data/features/delete.feature +12 -0
  94. data/features/edit.feature +54 -0
  95. data/features/publishing.feature +31 -0
  96. data/features/redirects.feature +27 -0
  97. data/features/step_definitions/mercury_steps.rb +440 -0
  98. data/features/step_definitions/page_steps.rb +269 -0
  99. data/features/step_definitions/web_steps.rb +254 -0
  100. data/features/support/env.rb +77 -0
  101. data/features/support/mercury_content.rb +25 -0
  102. data/features/support/mercury_selectors.rb +148 -0
  103. data/features/support/paths.rb +16 -0
  104. data/features/support/selectors.rb +26 -0
  105. data/features/support/utils.rb +18 -0
  106. data/features/versioning.feature +27 -0
  107. data/features/visit.feature +7 -0
  108. data/lib/cmsimple.rb +22 -0
  109. data/lib/cmsimple/configuration.rb +65 -0
  110. data/lib/cmsimple/exts/to_bool.rb +25 -0
  111. data/lib/cmsimple/page_responder.rb +46 -0
  112. data/lib/cmsimple/rails.rb +5 -0
  113. data/lib/cmsimple/regions_proxy.rb +32 -0
  114. data/lib/cmsimple/template_resolver.rb +14 -0
  115. data/lib/cmsimple/template_responder.rb +12 -0
  116. data/lib/cmsimple/version.rb +3 -0
  117. data/lib/generators/cmsimple/install/install_generator.rb +46 -0
  118. data/lib/generators/cmsimple/install/templates/default.html.erb +10 -0
  119. data/lib/generators/cmsimple/install/templates/default.html.haml +6 -0
  120. data/lib/generators/cmsimple/install/templates/initializer.rb +22 -0
  121. data/lib/generators/cmsimple/snippet/snippet_generator.rb +56 -0
  122. data/lib/generators/cmsimple/snippet/templates/cell.rb +18 -0
  123. data/lib/generators/cmsimple/snippet/templates/display.html.erb +14 -0
  124. data/lib/generators/cmsimple/snippet/templates/display.html.haml +11 -0
  125. data/lib/generators/cmsimple/snippet/templates/options.html.erb +18 -0
  126. data/lib/generators/cmsimple/snippet/templates/options.html.haml +12 -0
  127. data/script/app +2 -0
  128. data/script/migrate +2 -0
  129. data/script/rails +8 -0
  130. data/spec/fixtures/rails.png +0 -0
  131. data/spec/helpers/regions_helper_spec.rb +62 -0
  132. data/spec/javascripts/controllers/editor_spec.coffee +57 -0
  133. data/spec/javascripts/models/image_geometry_spec.coffee +64 -0
  134. data/spec/javascripts/models/image_spec.coffee +4 -0
  135. data/spec/javascripts/models/page_spec.coffee +121 -0
  136. data/spec/javascripts/models/path_spec.coffee +39 -0
  137. data/spec/javascripts/models/version_spec.coffee +31 -0
  138. data/spec/javascripts/panels/images/selection_spec.coffee +104 -0
  139. data/spec/javascripts/panels/sitemap/panel_spec.coffee +10 -0
  140. data/spec/javascripts/panels/sitemap/sortable_spec.coffee +63 -0
  141. data/spec/javascripts/panels/sitemap/tree_spec.coffee +62 -0
  142. data/spec/javascripts/spec_helper.coffee +25 -0
  143. data/spec/javascripts/support/stubs.coffee +16 -0
  144. data/spec/lib/page_responder_spec.rb +58 -0
  145. data/spec/lib/regions_proxy_spec.rb +47 -0
  146. data/spec/models/image_spec.rb +46 -0
  147. data/spec/models/page_spec.rb +237 -0
  148. data/spec/models/path_spec.rb +71 -0
  149. data/spec/models/region_spec.rb +14 -0
  150. data/spec/models/snippet_spec.rb +57 -0
  151. data/spec/models/version_spec.rb +7 -0
  152. data/spec/rails_app/.gitignore +33 -0
  153. data/spec/rails_app/Rakefile +7 -0
  154. data/spec/rails_app/app/assets/images/rails.png +0 -0
  155. data/spec/rails_app/app/assets/javascripts/application.js +9 -0
  156. data/spec/rails_app/app/assets/stylesheets/application.css +7 -0
  157. data/spec/rails_app/app/cells/example/display.html.haml +2 -0
  158. data/spec/rails_app/app/cells/example/options.html.haml +15 -0
  159. data/spec/rails_app/app/cells/example_cell.rb +19 -0
  160. data/spec/rails_app/app/cells/image_example/display.html.haml +4 -0
  161. data/spec/rails_app/app/cells/image_example/options.html.haml +15 -0
  162. data/spec/rails_app/app/cells/image_example_cell.rb +18 -0
  163. data/spec/rails_app/app/controllers/application_controller.rb +3 -0
  164. data/spec/rails_app/app/helpers/application_helper.rb +2 -0
  165. data/spec/rails_app/app/mailers/.gitkeep +0 -0
  166. data/spec/rails_app/app/models/.gitkeep +0 -0
  167. data/spec/rails_app/app/views/cmsimple/_snippet_list.html.haml +8 -0
  168. data/spec/rails_app/app/views/cmsimple/templates/default.html.haml +19 -0
  169. data/spec/rails_app/app/views/cmsimple/templates/test.html.haml +2 -0
  170. data/spec/rails_app/app/views/layouts/application.html.haml +13 -0
  171. data/spec/rails_app/config.ru +4 -0
  172. data/spec/rails_app/config/application.rb +65 -0
  173. data/spec/rails_app/config/boot.rb +9 -0
  174. data/spec/rails_app/config/database.example.yml +22 -0
  175. data/spec/rails_app/config/database.travis.yml +8 -0
  176. data/spec/rails_app/config/environment.rb +5 -0
  177. data/spec/rails_app/config/environments/development.rb +30 -0
  178. data/spec/rails_app/config/environments/test.rb +39 -0
  179. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  180. data/spec/rails_app/config/initializers/cells.rb +1 -0
  181. data/spec/rails_app/config/initializers/cmsimple.rb +3 -0
  182. data/spec/rails_app/config/initializers/inflections.rb +10 -0
  183. data/spec/rails_app/config/initializers/mime_types.rb +5 -0
  184. data/spec/rails_app/config/initializers/secret_token.rb +7 -0
  185. data/spec/rails_app/config/initializers/session_store.rb +8 -0
  186. data/spec/rails_app/config/initializers/teabag.rb +58 -0
  187. data/spec/rails_app/config/initializers/wrap_parameters.rb +14 -0
  188. data/spec/rails_app/config/locales/en.yml +5 -0
  189. data/spec/rails_app/config/routes.rb +61 -0
  190. data/spec/rails_app/db/seeds.rb +11 -0
  191. data/spec/rails_app/lib/assets/.gitkeep +0 -0
  192. data/spec/rails_app/lib/tasks/.gitkeep +0 -0
  193. data/spec/rails_app/public/404.html +26 -0
  194. data/spec/rails_app/public/422.html +26 -0
  195. data/spec/rails_app/public/500.html +26 -0
  196. data/spec/rails_app/public/robots.txt +5 -0
  197. data/spec/rails_app/script/rails +6 -0
  198. data/spec/rails_app/vendor/assets/stylesheets/.gitkeep +0 -0
  199. data/spec/rails_app/vendor/plugins/.gitkeep +0 -0
  200. data/spec/spec_helper.rb +31 -0
  201. data/spec/support/active_model_lint_example.rb +14 -0
  202. data/spec/teabag_env.rb +28 -0
  203. data/vendor/assets/images/sitemap/has-changes.png +0 -0
  204. data/vendor/assets/images/sitemap/published.png +0 -0
  205. data/vendor/assets/images/sitemap/unpublished.png +0 -0
  206. data/vendor/assets/images/toolbar/metadata.png +0 -0
  207. data/vendor/assets/images/toolbar/publish.png +0 -0
  208. data/vendor/assets/images/toolbar/redirect.png +0 -0
  209. data/vendor/assets/images/toolbar/sitemap.png +0 -0
  210. data/vendor/assets/images/toolbar/snippets.png +0 -0
  211. data/vendor/assets/images/toolbar/unpublished.png +0 -0
  212. data/vendor/assets/images/tree-line-horizontal-last.png +0 -0
  213. data/vendor/assets/images/tree-line-horizontal.png +0 -0
  214. data/vendor/assets/images/tree-line-vertical.png +0 -0
  215. data/vendor/assets/javascripts/jquery-serializeObject.js +107 -0
  216. data/vendor/assets/javascripts/jquery.to-json.js +74 -0
  217. data/vendor/assets/javascripts/jquery.ui.nestedSortable-1.3.4.js +391 -0
  218. data/vendor/assets/javascripts/moment-1.6.2.js +918 -0
  219. data/vendor/assets/javascripts/underscore-1.3.1.js +31 -0
  220. data/vendor/assets/stylesheets/jasmine-modified.css +216 -0
  221. metadata +686 -0
@@ -0,0 +1,107 @@
1
+ !function($){
2
+ delete $.fn.serializeObject;
3
+ $.serializeObject = function(obj){
4
+ var o={},lookup=o,a = obj;
5
+ $.each(a,function(){
6
+ var named = this.name.replace(/\[([^\]]+)?\]/g,',$1').split(','),
7
+ cap = named.length - 1,
8
+ i = 0;
9
+ for(;i<cap;i++) {
10
+ // move down the tree - create objects or array if necessary
11
+ if(lookup.push){ // this is an array, add values instead of setting them
12
+ // push an object if this is an empty array or we are about to overwrite a value
13
+ if( !lookup[lookup.length -1] // this is an empty array
14
+ || lookup[lookup.length -1].constructor !== Object //current value is not a hash
15
+ || lookup[lookup.length -1][named[i+1]] !== undefined //current item is already set
16
+ ){
17
+ lookup.push({});
18
+ }
19
+ lookup = lookup[lookup.length -1];
20
+ } else {
21
+ lookup = lookup[named[i]] = lookup[named[i]] || (named[i+1]==""?[]:{});
22
+ }
23
+ }
24
+ if(lookup.push){
25
+ lookup.push(this.value);
26
+ }else{
27
+ lookup[named[cap]]=this.value;
28
+ }
29
+ lookup = o;
30
+ });
31
+ return o;
32
+ };
33
+
34
+ $.deserializeObject = function deserializeObject(json,arr,prefix){
35
+ var i,j,thisPrefix,objType;
36
+ arr = arr || [];
37
+ if(Object.prototype.toString.call(json) ==='[object Object]'){
38
+ for(i in json){
39
+ thisPrefix = prefix ? [prefix,'[',i,']'].join('') : i;
40
+ if(json.hasOwnProperty(i)){
41
+ objType = Object.prototype.toString.call(json[i])
42
+ if(objType === '[object Array]'){
43
+ for(j = 0,jsonLen = json[i].length;j<jsonLen;j++){
44
+ deserializeObject(json[i][j],arr,thisPrefix+'[]');
45
+ }
46
+ }else if(objType === '[object Object]'){
47
+ deserializeObject(json[i],arr,thisPrefix);
48
+ }else {
49
+ arr.push({
50
+ name : thisPrefix,
51
+ value : json[i]
52
+ });
53
+ }
54
+ }
55
+ }
56
+ } else {
57
+ arr.push({
58
+ name : prefix,
59
+ value : json
60
+ });
61
+ }
62
+ return arr;
63
+ }
64
+
65
+ var check = function(){
66
+ // older versions of jQuery do not have prop
67
+ var propExists = !!$.fn.prop;
68
+ return function(obj,checked){
69
+ if(propExists) obj.prop('checked',checked);
70
+ else obj.attr('checked', (checked ? 'checked' : null ));
71
+ };
72
+ }();
73
+
74
+ $.applySerializedArray = function(form,obj){
75
+ var $form = $(form).find('input,select,textarea'), el;
76
+ check($form.filter(':checked'),false)
77
+ for(var i = obj.length;i--;){
78
+ el = $form.filter("[name='"+obj[i].name+"']");
79
+ if(el.filter(':checkbox').length){
80
+ if(el.val() == obj[i].value) check(el.filter(':checkbox'),true);
81
+ }else if(el.filter(':radio').length){
82
+ check(el.filter("[value='"+obj[i].value+"']"),true)
83
+ } else {
84
+ el.val(obj[i].value);
85
+ }
86
+ }
87
+ };
88
+
89
+ $.applySerializedObject = function(form, obj){
90
+ $.applySerializedArray(form,$.deserializeObject(obj));
91
+ };
92
+
93
+ $.fn.serializeObject = $.fn.serializeObject || function(){
94
+ return $.serializeObject(this.serializeArray());
95
+ };
96
+
97
+ $.fn.applySerializedObject = function(obj){
98
+ $.applySerializedObject(this,obj);
99
+ return this;
100
+ };
101
+
102
+ $.fn.applySerializedArray = function(obj){
103
+ $.applySerializedArray(this,obj);
104
+ return this;
105
+ };
106
+
107
+ }(jQuery);
@@ -0,0 +1,74 @@
1
+ (function($){
2
+ $.fn.toJSON = function(options){
3
+
4
+ options = $.extend({}, options);
5
+
6
+ var self = this,
7
+ json = {},
8
+ push_counters = {},
9
+ patterns = {
10
+ "validate": /^[a-zA-Z][a-zA-Z0-9_]*(?:\[(?:\d*|[a-zA-Z0-9_]+)\])*$/,
11
+ "key": /[a-zA-Z0-9_]+|(?=\[\])/g,
12
+ "push": /^$/,
13
+ "fixed": /^\d+$/,
14
+ "named": /^[a-zA-Z0-9_]+$/
15
+ };
16
+
17
+
18
+ this.build = function(base, key, value){
19
+ base[key] = value;
20
+ return base;
21
+ };
22
+
23
+ this.push_counter = function(key, i){
24
+ if(push_counters[key] === undefined){
25
+ push_counters[key] = 0;
26
+ }
27
+ if(i === undefined){
28
+ return push_counters[key]++;
29
+ }
30
+ else if(i !== undefined && i > push_counters[key]){
31
+ return push_counters[key] = ++i;
32
+ }
33
+ };
34
+
35
+ $.each($(this).serializeArray(), function(){
36
+
37
+ // skip invalid keys
38
+ if(!patterns.validate.test(this.name)){
39
+ return;
40
+ }
41
+
42
+ var k,
43
+ keys = this.name.match(patterns.key),
44
+ merge = this.value,
45
+ reverse_key = this.name;
46
+
47
+ while((k = keys.pop()) !== undefined){
48
+
49
+ // adjust reverse_key
50
+ reverse_key = reverse_key.replace(new RegExp("\\[" + k + "\\]$"), '');
51
+
52
+ // push
53
+ if(k.match(patterns.push)){
54
+ merge = self.build([], self.push_counter(reverse_key), merge);
55
+ }
56
+
57
+ // fixed
58
+ else if(k.match(patterns.fixed)){
59
+ self.push_counter(reverse_key, k);
60
+ merge = self.build([], k, merge);
61
+ }
62
+
63
+ // named
64
+ else if(k.match(patterns.named)){
65
+ merge = self.build({}, k, merge);
66
+ }
67
+ }
68
+
69
+ json = $.extend(true, json, merge);
70
+ });
71
+
72
+ return json;
73
+ };
74
+ })(jQuery);
@@ -0,0 +1,391 @@
1
+ /*
2
+ * jQuery UI Nested Sortable
3
+ * v 1.3.4 / 28 apr 2011
4
+ * http://mjsarfatti.com/sandbox/nestedSortable
5
+ *
6
+ * Depends:
7
+ * jquery.ui.sortable.js 1.8+
8
+ *
9
+ * License CC BY-SA 3.0
10
+ * Copyright 2010-2011, Manuele J Sarfatti
11
+ */
12
+
13
+ (function($) {
14
+
15
+ $.widget("ui.nestedSortable", $.extend({}, $.ui.sortable.prototype, {
16
+
17
+ options: {
18
+ tabSize: 20,
19
+ disableNesting: 'ui-nestedSortable-no-nesting',
20
+ errorClass: 'ui-nestedSortable-error',
21
+ listType: 'ol',
22
+ maxLevels: 0,
23
+ revertOnError: 1
24
+ },
25
+
26
+ _create: function() {
27
+ this.element.data('sortable', this.element.data('nestedSortable'));
28
+ return $.ui.sortable.prototype._create.apply(this, arguments);
29
+ },
30
+
31
+ destroy: function() {
32
+ this.element
33
+ .removeData("nestedSortable")
34
+ .unbind(".nestedSortable");
35
+ return $.ui.sortable.prototype.destroy.apply(this, arguments);
36
+ },
37
+
38
+ _mouseDrag: function(event) {
39
+
40
+ //Compute the helpers position
41
+ this.position = this._generatePosition(event);
42
+ this.positionAbs = this._convertPositionTo("absolute");
43
+
44
+ if (!this.lastPositionAbs) {
45
+ this.lastPositionAbs = this.positionAbs;
46
+ }
47
+
48
+ //Do scrolling
49
+ if(this.options.scroll) {
50
+ var o = this.options, scrolled = false;
51
+ if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') {
52
+
53
+ if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
54
+ this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
55
+ else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity)
56
+ this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed;
57
+
58
+ if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity)
59
+ this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed;
60
+ else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity)
61
+ this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
62
+
63
+ } else {
64
+
65
+ if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
66
+ scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
67
+ else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
68
+ scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
69
+
70
+ if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
71
+ scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
72
+ else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
73
+ scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
74
+
75
+ }
76
+
77
+ if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
78
+ $.ui.ddmanager.prepareOffsets(this, event);
79
+ }
80
+
81
+ //Regenerate the absolute position used for position checks
82
+ this.positionAbs = this._convertPositionTo("absolute");
83
+
84
+ //Set the helper position
85
+ if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
86
+ if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
87
+
88
+ //Rearrange
89
+ for (var i = this.items.length - 1; i >= 0; i--) {
90
+
91
+ //Cache variables and intersection, continue if no intersection
92
+ var item = this.items[i], itemElement = item.item[0], intersection = this._intersectsWithPointer(item);
93
+ if (!intersection) continue;
94
+
95
+ if(itemElement != this.currentItem[0] //cannot intersect with itself
96
+ && this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before
97
+ && !$.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked
98
+ && (this.options.type == 'semi-dynamic' ? !$.contains(this.element[0], itemElement) : true)
99
+ //&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container
100
+ ) {
101
+
102
+ $(itemElement).mouseenter();
103
+
104
+ this.direction = intersection == 1 ? "down" : "up";
105
+
106
+ if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) {
107
+ $(itemElement).mouseleave();
108
+ this._rearrange(event, item);
109
+ } else {
110
+ break;
111
+ }
112
+
113
+ // Clear emtpy ul's/ol's
114
+ this._clearEmpty(itemElement);
115
+
116
+ this._trigger("change", event, this._uiHash());
117
+ break;
118
+ }
119
+ }
120
+
121
+ var parentItem = (this.placeholder[0].parentNode.parentNode
122
+ && $(this.placeholder[0].parentNode.parentNode).closest('.ui-sortable').length)
123
+ ? $(this.placeholder[0].parentNode.parentNode)
124
+ : null,
125
+ level = this._getLevel(this.placeholder),
126
+ childLevels = this._getChildLevels(this.helper),
127
+ previousItem = this.placeholder[0].previousSibling ? $(this.placeholder[0].previousSibling) : null;
128
+
129
+ if (previousItem != null) {
130
+ while (previousItem[0].nodeName.toLowerCase() != 'li' || previousItem[0] == this.currentItem[0]) {
131
+ if (previousItem[0].previousSibling) {
132
+ previousItem = $(previousItem[0].previousSibling);
133
+ } else {
134
+ previousItem = null;
135
+ break;
136
+ }
137
+ }
138
+ }
139
+
140
+ newList = document.createElement(o.listType);
141
+
142
+ this.beyondMaxLevels = 0;
143
+
144
+ // If the item is moved to the left, send it to its parent level
145
+ if (parentItem != null && this.positionAbs.left < parentItem.offset().left) {
146
+ parentItem.after(this.placeholder[0]);
147
+ this._clearEmpty(parentItem[0]);
148
+ this._trigger("change", event, this._uiHash());
149
+ }
150
+ // If the item is below another one and is moved to the right, make it a children of it
151
+ else if (previousItem != null && this.positionAbs.left > previousItem.offset().left + o.tabSize) {
152
+ this._isAllowed(previousItem, level+childLevels+1);
153
+ if (!previousItem.children(o.listType).length) {
154
+ previousItem[0].appendChild(newList);
155
+ }
156
+ previousItem.children(o.listType)[0].appendChild(this.placeholder[0]);
157
+ this._trigger("change", event, this._uiHash());
158
+ }
159
+ else {
160
+ this._isAllowed(parentItem, level+childLevels);
161
+ }
162
+
163
+ //Post events to containers
164
+ this._contactContainers(event);
165
+
166
+ //Interconnect with droppables
167
+ if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
168
+
169
+ //Call callbacks
170
+ this._trigger('sort', event, this._uiHash());
171
+
172
+ this.lastPositionAbs = this.positionAbs;
173
+ return false;
174
+
175
+ },
176
+
177
+ _mouseStop: function(event, noPropagation) {
178
+
179
+ // If the item is in a position not allowed, send it back
180
+ if (this.beyondMaxLevels) {
181
+
182
+ this.placeholder.removeClass(this.options.errorClass);
183
+
184
+ if (this.options.revertOnError) {
185
+ if (this.domPosition.prev) {
186
+ $(this.domPosition.prev).after(this.placeholder);
187
+ } else {
188
+ $(this.domPosition.parent).prepend(this.placeholder);
189
+ }
190
+ this._trigger("revert", event, this._uiHash());
191
+ } else {
192
+ var parent = this.placeholder.parent().closest(this.options.items);
193
+
194
+ for (var i = this.beyondMaxLevels - 1; i > 0; i--) {
195
+ parent = parent.parent().closest(this.options.items);
196
+ }
197
+
198
+ parent.after(this.placeholder);
199
+ this._trigger("change", event, this._uiHash());
200
+ }
201
+
202
+ }
203
+
204
+ // Clean last empty ul/ol
205
+ for (var i = this.items.length - 1; i >= 0; i--) {
206
+ var item = this.items[i].item[0];
207
+ this._clearEmpty(item);
208
+ }
209
+
210
+ $.ui.sortable.prototype._mouseStop.apply(this, arguments);
211
+
212
+ },
213
+
214
+ serialize: function(o) {
215
+
216
+ var items = this._getItemsAsjQuery(o && o.connected),
217
+ str = []; o = o || {};
218
+
219
+ $(items).each(function() {
220
+ var res = ($(o.item || this).attr(o.attribute || 'id') || '')
221
+ .match(o.expression || (/(.+)[-=_](.+)/)),
222
+ pid = ($(o.item || this).parent(o.listType)
223
+ .parent('li')
224
+ .attr(o.attribute || 'id') || '')
225
+ .match(o.expression || (/(.+)[-=_](.+)/));
226
+
227
+ if (res) {
228
+ str.push((o.key || res[1] + '[' + (o.key && o.expression ? res[1] : res[2]) + ']')
229
+ + '='
230
+ + (pid ? (o.key && o.expression ? pid[1] : pid[2]) : 'root'));
231
+ }
232
+ });
233
+
234
+ if(!str.length && o.key) {
235
+ str.push(o.key + '=');
236
+ }
237
+
238
+ return str.join('&');
239
+
240
+ },
241
+
242
+ toHierarchy: function(o) {
243
+
244
+ o = o || {};
245
+ var sDepth = o.startDepthCount || 0,
246
+ ret = [];
247
+
248
+ $(this.element).children('li').each(function () {
249
+ var level = _recursiveItems($(this));
250
+ ret.push(level);
251
+ });
252
+
253
+ return ret;
254
+
255
+ function _recursiveItems(li) {
256
+ var id = ($(li).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
257
+ if (id) {
258
+ var item = {"id" : id[2]};
259
+ if ($(li).children(o.listType).children('li').length > 0) {
260
+ item.children = [];
261
+ $(li).children(o.listType).children('li').each(function() {
262
+ var level = _recursiveItems($(this));
263
+ item.children.push(level);
264
+ });
265
+ }
266
+ return item;
267
+ }
268
+ }
269
+ },
270
+
271
+ toArray: function(o) {
272
+
273
+ o = o || {};
274
+ var sDepth = o.startDepthCount || 0,
275
+ ret = [],
276
+ left = 2;
277
+
278
+ ret.push({
279
+ "item_id": 'root',
280
+ "parent_id": 'none',
281
+ "depth": sDepth,
282
+ "left": '1',
283
+ "right": ($('li', this.element).length + 1) * 2
284
+ });
285
+
286
+ $(this.element).children('li').each(function () {
287
+ left = _recursiveArray(this, sDepth + 1, left);
288
+ });
289
+
290
+ ret = ret.sort(function(a,b){ return (a.left - b.left); });
291
+
292
+ return ret;
293
+
294
+ function _recursiveArray(item, depth, left) {
295
+
296
+ var right = left + 1,
297
+ id,
298
+ pid;
299
+
300
+ if ($(item).children(o.listType).children('li').length > 0) {
301
+ depth ++;
302
+ $(item).children(o.listType).children('li').each(function () {
303
+ right = _recursiveArray($(this), depth, right);
304
+ });
305
+ depth --;
306
+ }
307
+
308
+ id = ($(item).attr(o.attribute || 'id')).match(o.expression || (/(.+)[-=_](.+)/));
309
+
310
+ if (depth === sDepth + 1) {
311
+ pid = 'root';
312
+ } else {
313
+ var parentItem = ($(item).parent(o.listType)
314
+ .parent('li')
315
+ .attr(o.attribute || 'id'))
316
+ .match(o.expression || (/(.+)[-=_](.+)/));
317
+ pid = parentItem[2];
318
+ }
319
+
320
+ if (id) {
321
+ ret.push({"item_id": id[2], "parent_id": pid, "depth": depth, "left": left, "right": right});
322
+ }
323
+
324
+ left = right + 1;
325
+ return left;
326
+ }
327
+
328
+ },
329
+
330
+ _clearEmpty: function(item) {
331
+
332
+ var emptyList = $(item).children(this.options.listType);
333
+ if (emptyList.length && !emptyList.children().length) {
334
+ emptyList.remove();
335
+ }
336
+
337
+ },
338
+
339
+ _getLevel: function(item) {
340
+
341
+ var level = 1;
342
+
343
+ if (this.options.listType) {
344
+ var list = item.closest(this.options.listType);
345
+ while (!list.is('.ui-sortable')) {
346
+ level++;
347
+ list = list.parent().closest(this.options.listType);
348
+ }
349
+ }
350
+
351
+ return level;
352
+ },
353
+
354
+ _getChildLevels: function(parent, depth) {
355
+ var self = this,
356
+ o = this.options,
357
+ result = 0;
358
+ depth = depth || 0;
359
+
360
+ $(parent).children(o.listType).children(o.items).each(function (index, child) {
361
+ result = Math.max(self._getChildLevels(child, depth + 1), result);
362
+ });
363
+
364
+ return depth ? result + 1 : result;
365
+ },
366
+
367
+ _isAllowed: function(parentItem, levels) {
368
+ var o = this.options;
369
+ // Are we trying to nest under a no-nest or are we nesting too deep?
370
+ if (parentItem == null || !(parentItem.hasClass(o.disableNesting))) {
371
+ if (o.maxLevels < levels && o.maxLevels != 0) {
372
+ this.placeholder.addClass(o.errorClass);
373
+ this.beyondMaxLevels = levels - o.maxLevels;
374
+ } else {
375
+ this.placeholder.removeClass(o.errorClass);
376
+ this.beyondMaxLevels = 0;
377
+ }
378
+ } else {
379
+ this.placeholder.addClass(o.errorClass);
380
+ if (o.maxLevels < levels && o.maxLevels != 0) {
381
+ this.beyondMaxLevels = levels - o.maxLevels;
382
+ } else {
383
+ this.beyondMaxLevels = 1;
384
+ }
385
+ }
386
+ }
387
+
388
+ }));
389
+
390
+ $.ui.nestedSortable.prototype.options = $.extend({}, $.ui.sortable.prototype.options, $.ui.nestedSortable.prototype.options);
391
+ })(jQuery);