spontaneous 0.2.0.beta5 → 0.2.0.beta6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +39 -0
  4. data/Gemfile +2 -0
  5. data/Readme.markdown +4 -4
  6. data/application/css/core.css.scss +144 -43
  7. data/application/css/definitions.css.scss +50 -16
  8. data/application/css/dialogue.css.scss +5 -2
  9. data/application/css/editing.css.scss +7 -7
  10. data/application/css/font.css.scss +1 -1
  11. data/application/css/meta.css.scss +6 -6
  12. data/application/css/popover.css.scss +6 -6
  13. data/application/css/top.css.scss +8 -1
  14. data/application/js/add_alias_dialogue.js +137 -36
  15. data/application/js/add_home_dialogue.js +10 -10
  16. data/application/js/ajax.js +26 -26
  17. data/application/js/authentication.js +2 -2
  18. data/application/js/box.js +21 -10
  19. data/application/js/box_container.js +13 -7
  20. data/application/js/compatibility.js +19 -17
  21. data/application/js/conflicted_field_dialogue.js +5 -5
  22. data/application/js/content.js +22 -16
  23. data/application/js/content_area.js +62 -33
  24. data/application/js/dialogue.js +16 -16
  25. data/application/js/dom.js +9 -10
  26. data/application/js/edit_panel.js +25 -20
  27. data/application/js/editing.js +21 -8
  28. data/application/js/entry.js +1 -1
  29. data/application/js/extensions.js +11 -11
  30. data/application/js/field/boolean.js +6 -6
  31. data/application/js/field/date.js +1 -1
  32. data/application/js/field/file.js +17 -17
  33. data/application/js/field/image.js +27 -27
  34. data/application/js/field/markdown.js +72 -71
  35. data/application/js/field/select.js +9 -9
  36. data/application/js/field/string.js +3 -3
  37. data/application/js/field/webvideo.js +2 -2
  38. data/application/js/field_preview.js +3 -0
  39. data/application/js/init.js +3 -2
  40. data/application/js/jquery-selection-position.js +13 -13
  41. data/application/js/location.js +17 -12
  42. data/application/js/login.js +2 -2
  43. data/application/js/meta_view/user_admin.js +101 -101
  44. data/application/js/metadata.js +1 -1
  45. data/application/js/page.js +2 -2
  46. data/application/js/page_browser.js +13 -13
  47. data/application/js/page_entry.js +1 -1
  48. data/application/js/panel/root_menu.js +10 -10
  49. data/application/js/popover.js +6 -5
  50. data/application/js/popover_view.js +5 -5
  51. data/application/js/preview.js +10 -4
  52. data/application/js/progress.js +6 -6
  53. data/application/js/properties.js +35 -6
  54. data/application/js/publish.js +43 -43
  55. data/application/js/require.js +14 -14
  56. data/application/js/services.js +3 -3
  57. data/application/js/sharded_upload.js +9 -8
  58. data/application/js/side_bar.js +5 -5
  59. data/application/js/state.js +2 -2
  60. data/application/js/status_bar.js +6 -6
  61. data/application/js/top_bar.js +97 -65
  62. data/application/js/types.js +9 -6
  63. data/application/js/upload.js +4 -4
  64. data/application/js/upload_manager.js +21 -21
  65. data/application/js/user.js +1 -1
  66. data/application/js/vendor/jquery.velocity.min.js +7 -0
  67. data/application/js/views.js +32 -8
  68. data/application/js/views/box_view.js +51 -31
  69. data/application/js/views/page_piece_view.js +17 -15
  70. data/application/js/views/page_view.js +54 -43
  71. data/application/js/views/piece_view.js +44 -37
  72. data/application/static/font/fontawesome-webfont-4f0022f25672c7f501c339cbf98d9117.ttf +0 -0
  73. data/application/views/index.erb +1 -0
  74. data/db/migrations/20130114120000_create_revision_tables.rb +2 -1
  75. data/db/migrations/20130813111009_increase_path_length.rb +11 -2
  76. data/db/migrations/20140506171823_add_index_to_target_id.rb +11 -0
  77. data/db/migrations/20140514090204_add_content_hash.rb +59 -0
  78. data/db/migrations/20140519150253_add_content_hash_timestamp.rb +20 -0
  79. data/lib/spontaneous.rb +0 -1
  80. data/lib/spontaneous/asset/environment.rb +77 -15
  81. data/lib/spontaneous/box.rb +21 -0
  82. data/lib/spontaneous/capistrano/deploy.rb +1 -1
  83. data/lib/spontaneous/capistrano/sync.rb +8 -7
  84. data/lib/spontaneous/change.rb +4 -2
  85. data/lib/spontaneous/cli/fields.rb +7 -3
  86. data/lib/spontaneous/cli/generate.rb +2 -0
  87. data/lib/spontaneous/cli/init.rb +24 -93
  88. data/lib/spontaneous/cli/init/db.rb +94 -0
  89. data/lib/spontaneous/cli/init/mysql.rb +17 -0
  90. data/lib/spontaneous/cli/init/postgresql.rb +33 -0
  91. data/lib/spontaneous/cli/init/sqlite.rb +14 -0
  92. data/lib/spontaneous/cli/site.rb +45 -20
  93. data/lib/spontaneous/collections/box_set.rb +3 -0
  94. data/lib/spontaneous/collections/entry_set.rb +43 -4
  95. data/lib/spontaneous/collections/field_set.rb +14 -2
  96. data/lib/spontaneous/data_mapper.rb +40 -7
  97. data/lib/spontaneous/data_mapper/content_model.rb +1 -1
  98. data/lib/spontaneous/data_mapper/content_model/associations.rb +63 -12
  99. data/lib/spontaneous/data_mapper/content_model/timestamps.rb +9 -14
  100. data/lib/spontaneous/data_mapper/content_table.rb +4 -2
  101. data/lib/spontaneous/data_mapper/dataset.rb +31 -2
  102. data/lib/spontaneous/data_mapper/scope.rb +37 -20
  103. data/lib/spontaneous/errors.rb +6 -0
  104. data/lib/spontaneous/facet.rb +20 -10
  105. data/lib/spontaneous/field/base.rb +8 -1
  106. data/lib/spontaneous/field/file.rb +28 -3
  107. data/lib/spontaneous/field/image.rb +2 -0
  108. data/lib/spontaneous/field/update.rb +6 -0
  109. data/lib/spontaneous/field/webvideo/vimeo.rb +6 -1
  110. data/lib/spontaneous/field/webvideo/vine.rb +1 -1
  111. data/lib/spontaneous/field/webvideo/youtube.rb +1 -1
  112. data/lib/spontaneous/generators/site.rb +6 -4
  113. data/lib/spontaneous/generators/site/.gitignore +1 -0
  114. data/lib/spontaneous/generators/site/Gemfile.tt +3 -3
  115. data/lib/spontaneous/generators/site/config/{indexes.rb.tt → initializers/indexes.rb.tt} +0 -0
  116. data/lib/spontaneous/generators/site/config/initializers/publishing.rb.tt +78 -0
  117. data/lib/spontaneous/generators/site/{config/database.yml.tt → db/mysql2.yml.tt} +7 -6
  118. data/lib/spontaneous/generators/site/db/postgres.yml.tt +25 -0
  119. data/lib/spontaneous/generators/site/db/sqlite3.yml.tt +18 -0
  120. data/lib/spontaneous/generators/site/public/humans.txt.tt +14 -0
  121. data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +51 -0
  122. data/lib/spontaneous/loader.rb +1 -1
  123. data/lib/spontaneous/logger.rb +1 -1
  124. data/lib/spontaneous/media/image/optimizer.rb +1 -1
  125. data/lib/spontaneous/media/image/processor.rb +11 -2
  126. data/lib/spontaneous/media/image/renderable.rb +2 -0
  127. data/lib/spontaneous/model.rb +3 -0
  128. data/lib/spontaneous/model/box/allowed_types.rb +17 -4
  129. data/lib/spontaneous/model/core.rb +36 -3
  130. data/lib/spontaneous/model/core/aliases.rb +5 -2
  131. data/lib/spontaneous/model/core/boxes.rb +6 -0
  132. data/lib/spontaneous/model/core/cascading_change.rb +38 -0
  133. data/lib/spontaneous/model/core/content_hash.rb +171 -0
  134. data/lib/spontaneous/model/core/entries.rb +0 -19
  135. data/lib/spontaneous/model/core/fields.rb +11 -0
  136. data/lib/spontaneous/model/core/modifications.rb +22 -21
  137. data/lib/spontaneous/model/core/render.rb +3 -0
  138. data/lib/spontaneous/model/core/serialisation.rb +18 -17
  139. data/lib/spontaneous/model/page.rb +35 -8
  140. data/lib/spontaneous/model/page/page_tree.rb +20 -8
  141. data/lib/spontaneous/model/page/paths.rb +79 -50
  142. data/lib/spontaneous/model/page/singleton.rb +71 -0
  143. data/lib/spontaneous/model/page/site_map.rb +2 -1
  144. data/lib/spontaneous/model/page/site_timestamps.rb +2 -2
  145. data/lib/spontaneous/model/piece.rb +10 -0
  146. data/lib/spontaneous/output/context.rb +13 -6
  147. data/lib/spontaneous/output/format.rb +30 -5
  148. data/lib/spontaneous/output/helpers/script_helper.rb +8 -0
  149. data/lib/spontaneous/output/helpers/stylesheet_helper.rb +7 -0
  150. data/lib/spontaneous/output/renderable.rb +16 -0
  151. data/lib/spontaneous/output/store.rb +1 -1
  152. data/lib/spontaneous/output/template/renderer.rb +2 -2
  153. data/lib/spontaneous/page_piece.rb +25 -1
  154. data/lib/spontaneous/prototypes/box_prototype.rb +13 -0
  155. data/lib/spontaneous/prototypes/field_prototype.rb +7 -4
  156. data/lib/spontaneous/publishing.rb +10 -5
  157. data/lib/spontaneous/publishing/immediate.rb +32 -349
  158. data/lib/spontaneous/publishing/pipeline.rb +43 -0
  159. data/lib/spontaneous/publishing/progress.rb +186 -0
  160. data/lib/spontaneous/publishing/publish.rb +107 -0
  161. data/lib/spontaneous/publishing/rerender.rb +17 -0
  162. data/lib/spontaneous/publishing/revision.rb +53 -18
  163. data/lib/spontaneous/publishing/simultaneous.rb +1 -1
  164. data/lib/spontaneous/publishing/steps.rb +154 -0
  165. data/lib/spontaneous/publishing/steps/activate_revision.rb +45 -0
  166. data/lib/spontaneous/publishing/steps/archive_old_revisions.rb +22 -0
  167. data/lib/spontaneous/publishing/steps/base_step.rb +49 -0
  168. data/lib/spontaneous/publishing/steps/copy_static_files.rb +74 -0
  169. data/lib/spontaneous/publishing/steps/create_revision_directory.rb +24 -0
  170. data/lib/spontaneous/publishing/steps/generate_rackup_file.rb +51 -0
  171. data/lib/spontaneous/publishing/steps/generate_search_indexes.rb +24 -0
  172. data/lib/spontaneous/publishing/steps/render_revision.rb +69 -0
  173. data/lib/spontaneous/publishing/steps/write_revision_file.rb +43 -0
  174. data/lib/spontaneous/rack/back.rb +3 -1
  175. data/lib/spontaneous/rack/back/alias.rb +9 -8
  176. data/lib/spontaneous/rack/front.rb +1 -1
  177. data/lib/spontaneous/rack/middleware.rb +7 -4
  178. data/lib/spontaneous/rack/middleware/transaction.rb +14 -0
  179. data/lib/spontaneous/rack/page_controller.rb +23 -8
  180. data/lib/spontaneous/revision.rb +5 -10
  181. data/lib/spontaneous/schema.rb +5 -0
  182. data/lib/spontaneous/server.rb +3 -1
  183. data/lib/spontaneous/site.rb +17 -10
  184. data/lib/spontaneous/site/publishing.rb +25 -3
  185. data/lib/spontaneous/site/state.rb +7 -3
  186. data/lib/spontaneous/tasks/database.rake +5 -10
  187. data/lib/spontaneous/utils/database/mysql_dumper.rb +5 -1
  188. data/lib/spontaneous/version.rb +1 -1
  189. data/spontaneous.gemspec +4 -3
  190. data/test/fixtures/example_application/config/initializers/initializer1.rb +1 -0
  191. data/test/fixtures/example_application/config/initializers/initializer2.rb +1 -0
  192. data/test/fixtures/example_application/config/initializers/publishing.rb +13 -0
  193. data/test/fixtures/search/config/{indexes.rb → initializers/indexes.rb} +0 -0
  194. data/test/fixtures/serialisation/root_hash.yaml.erb +10 -4
  195. data/test/functional/test_application.rb +10 -0
  196. data/test/functional/test_back.rb +23 -5
  197. data/test/functional/test_cli.rb +98 -34
  198. data/test/functional/test_front.rb +7 -3
  199. data/test/test_helper.rb +35 -28
  200. data/test/unit/test_alias.rb +20 -3
  201. data/test/unit/test_assets.rb +58 -30
  202. data/test/unit/test_changesets.rb +20 -12
  203. data/test/unit/test_content_hash.rb +496 -0
  204. data/test/unit/test_context.rb +28 -1
  205. data/test/unit/test_controllers.rb +96 -61
  206. data/test/unit/test_crypt.rb +1 -8
  207. data/test/unit/test_datamapper.rb +95 -19
  208. data/test/unit/test_features.rb +1 -4
  209. data/test/unit/test_fields.rb +61 -12
  210. data/test/unit/test_generators.rb +39 -2
  211. data/test/unit/test_images.rb +3 -1
  212. data/test/unit/test_modifications.rb +224 -219
  213. data/test/unit/test_output_store.rb +10 -0
  214. data/test/unit/{test_formats.rb → test_outputs.rb} +75 -6
  215. data/test/unit/test_page.rb +61 -15
  216. data/test/unit/test_plugins.rb +2 -42
  217. data/test/unit/test_publishing_pipeline.rb +1050 -0
  218. data/test/unit/test_render.rb +30 -0
  219. data/test/unit/test_revisions.rb +110 -2
  220. data/test/unit/test_schema.rb +4 -0
  221. data/test/unit/test_search.rb +1 -1
  222. data/test/unit/test_serialisation.rb +6 -1
  223. data/test/unit/test_singletons.rb +159 -0
  224. data/test/unit/test_site.rb +71 -44
  225. metadata +140 -86
  226. data/application/static/font/fontawesome-webfont-1c66a4738b40ef0f6b1abca0ba9a796d.ttf +0 -0
  227. data/test/unit/test_publishing.rb +0 -330
@@ -1,5 +1,5 @@
1
1
 
2
- Spontaneous.AddHomeDialogue = (function($, S) {
2
+ Spontaneous.AddHomeDialogue = (function($, S, window) {
3
3
  var dom = S.Dom, Dialogue = Spontaneous.Dialogue;
4
4
 
5
5
  var AddHomeDialogue = new JS.Class(Dialogue, {
@@ -7,14 +7,14 @@ Spontaneous.AddHomeDialogue = (function($, S) {
7
7
  this.types = types;
8
8
  },
9
9
  title: function() {
10
- return "Create site home page";
10
+ return 'Create site home page';
11
11
  },
12
12
  width: function() {
13
13
  return '50%';
14
14
  },
15
15
  buttons: function() {
16
16
  var btns = {};
17
- btns["Create"] = this.create_home.bind(this);
17
+ btns['Create'] = this.create_home.bind(this);
18
18
  return btns;
19
19
  },
20
20
 
@@ -27,7 +27,7 @@ Spontaneous.AddHomeDialogue = (function($, S) {
27
27
  }
28
28
  },
29
29
  home_created: function(data) {
30
- window.location.href = S.Ajax.namespace
30
+ window.location.href = S.Ajax.namespace;
31
31
  },
32
32
  select_type: function(type) {
33
33
  this.type = type;
@@ -35,25 +35,25 @@ Spontaneous.AddHomeDialogue = (function($, S) {
35
35
  body: function() {
36
36
  var editing = dom.div('#create-home-dialogue'), outer = dom.div(), instructions = dom.p('.instructions'),
37
37
  types = this.types, __dialogue = this;
38
- instructions.html("You don't have a home page. Please choose a type below and hit <span class=\"button\">Create</span> to add one")
38
+ instructions.html("You don't have a home page. Please choose a type below and hit <span class=\"button\">Create</span> to add one");
39
39
  $.each(types, function(i, type) {
40
40
  if (type.is_page()) {
41
41
  var d = dom.div('.type').text(type.title).click(function() {
42
42
  $('.type', outer).removeClass('selected');
43
43
  __dialogue.select_type(type);
44
- $(this).addClass('selected');;
44
+ $(this).addClass('selected');
45
45
  });
46
- outer.append(d)
46
+ outer.append(d);
47
47
  }
48
48
  });
49
- editing.append(instructions, outer)
49
+ editing.append(instructions, outer);
50
50
  return editing;
51
51
  },
52
52
  cancel_button: function() {
53
53
  return false;
54
- },
54
+ }
55
55
  });
56
56
  return AddHomeDialogue;
57
- })(jQuery, Spontaneous);
57
+ })(jQuery, Spontaneous, window);
58
58
 
59
59
 
@@ -1,7 +1,7 @@
1
1
  // console.log("Loading Ajax...");
2
2
 
3
3
  Spontaneous.Ajax = (function($, S) {
4
- "use strict";
4
+ 'use strict';
5
5
 
6
6
  $.ajaxSetup({
7
7
  'async': true,
@@ -19,18 +19,18 @@ Spontaneous.Ajax = (function($, S) {
19
19
  // wraps jQuery.ajax with a auth aware error catcher
20
20
  var __request = function(params) {
21
21
  // console.log("AJAX", params)
22
- var requestSuccessHandler = params["success"];
22
+ var requestSuccessHandler = params.success;
23
23
  var successHandler = function(data, textStatus, xhr) {
24
- if (textStatus === "success") {
24
+ if (textStatus === 'success') {
25
25
  if (params.ifModified) {
26
26
  requestCache[params.url] = data;
27
27
  }
28
- } else if (!data && (textStatus === "notmodified")) {
28
+ } else if (!data && (textStatus === 'notmodified')) {
29
29
  data = requestCache[params.url];
30
30
  }
31
- requestSuccessHandler(data, textStatus, xhr)
31
+ requestSuccessHandler(data, textStatus, xhr);
32
32
  };
33
- var requestErrorHandler = params["error"];
33
+ var requestErrorHandler = params.error;
34
34
  var errorHandler = function(xhr, textStatus, error_thrown) {
35
35
  if (xhr.status === 401) {
36
36
  S.Ajax.unauthorized();
@@ -38,15 +38,15 @@ Spontaneous.Ajax = (function($, S) {
38
38
  requestErrorHandler(xhr, textStatus, error_thrown);
39
39
  }
40
40
  };
41
- params['error'] = errorHandler;
42
- params['success'] = successHandler;
43
- params['beforeSend'] = function (request) {
41
+ params.error = errorHandler;
42
+ params.success = successHandler;
43
+ params.beforeSend = function(request) {
44
44
  __authenticate(request);
45
45
  };
46
46
  $.ajax(params);
47
47
  };
48
48
  return {
49
- namespace: "/@spontaneous",
49
+ namespace: '/@spontaneous',
50
50
  // returns a modified xmlhttprequest that adds csrf headers
51
51
  // after #open is called.
52
52
  authenticatedRequest: function(request) {
@@ -62,27 +62,27 @@ Spontaneous.Ajax = (function($, S) {
62
62
  __authenticate(request);
63
63
  },
64
64
  get: function(url, data, callback, options) {
65
- if (typeof data === "function") {
65
+ if (typeof data === 'function') {
66
66
  callback = data;
67
67
  data = {};
68
68
  }
69
- this.makeRequest("GET", url, data, callback, options)
69
+ this.makeRequest('GET', url, data, callback, options);
70
70
  },
71
71
  put: function(url, data, callback) {
72
- this.makeRequest("PUT", url, data, callback);
72
+ this.makeRequest('PUT', url, data, callback);
73
73
  },
74
74
  del: function(url, data, callback) {
75
- this.makeRequest("DELETE", url, data, callback);
75
+ this.makeRequest('DELETE', url, data, callback);
76
76
  },
77
77
  post: function(url, data, callback) {
78
- this.makeRequest("POST", url, data, callback);
78
+ this.makeRequest('POST', url, data, callback);
79
79
  },
80
80
  patch: function(url, data, callback) {
81
- this.makeRequest("PATCH", url, data, callback);
81
+ this.makeRequest('PATCH', url, data, callback);
82
82
  },
83
83
  makeRequest: function(method, url, data, callback, options) {
84
84
  var success = function(data, textStatus, xhr) {
85
- if (typeof callback === "function") {
85
+ if (typeof callback === 'function') {
86
86
  callback(data, textStatus, xhr);
87
87
  }
88
88
  };
@@ -91,7 +91,7 @@ Spontaneous.Ajax = (function($, S) {
91
91
  try {
92
92
  result = $.parseJSON(xhr.responseText);
93
93
  } catch (e) { }
94
- if (typeof callback === "function") {
94
+ if (typeof callback === 'function') {
95
95
  callback(result, textStatus, xhr);
96
96
  }
97
97
  };
@@ -106,12 +106,12 @@ Spontaneous.Ajax = (function($, S) {
106
106
  __request(ajaxOptions);
107
107
  },
108
108
  unauthorized: function() {
109
- window.location.href = "/";
109
+ window.location.href = '/';
110
110
  },
111
111
  test_field_versions: function(target, fields, success, failure) {
112
112
  var version_data = {}, modified = 0;
113
113
  for (var i = 0, ii = fields.length; i < ii; i++) {
114
- var field = fields[i], key = "[fields]["+field.schema_id()+"]";
114
+ var field = fields[i], key = '[fields]['+field.schema_id()+']';
115
115
  if (field.is_modified()) {
116
116
  version_data[key] = field.version();
117
117
  modified++;
@@ -138,26 +138,26 @@ Spontaneous.Ajax = (function($, S) {
138
138
  version: values[0],
139
139
  values: {
140
140
  server_original: values[1],
141
- local_edited: field.edited_value(),
142
- local_original: field.original_value()
141
+ local_edited: field.edited_value(),
142
+ local_original: field.original_value()
143
143
  }
144
144
  });
145
145
  }
146
146
  }
147
- failure(conflicted_fields)
147
+ failure(conflicted_fields);
148
148
  }
149
149
  }
150
150
  });
151
151
  },
152
152
  csrf_token: function() {
153
- return {'__token':csrfToken }
153
+ return {'__token':csrfToken };
154
154
  },
155
155
  request_url: function(url, needs_key) {
156
156
  var path = this.namespace + url;
157
157
  if (needs_key) {
158
- path += "?"+$.param(this.csrf_token())
158
+ path += '?'+$.param(this.csrf_token());
159
159
  }
160
- return path
160
+ return path;
161
161
  }
162
162
  };
163
163
  }(jQuery, Spontaneous));
@@ -4,7 +4,7 @@ Spontaneous.Auth = (function($, S) {
4
4
  return {
5
5
  Key: {
6
6
  key: function(site) {
7
- return site + '_api_key'
7
+ return site + '_api_key';
8
8
  },
9
9
  save: function(site, key) {
10
10
  localStorage.setItem(this.key(site), key);
@@ -14,7 +14,7 @@ Spontaneous.Auth = (function($, S) {
14
14
  },
15
15
  loadAutoLogin: function() {
16
16
  if (!this._autoLoginKey) {
17
- console.warn("Using auto login key for user", "'"+S.auto_login+"'");
17
+ console.warn('Using auto login key for user', "'"+S.auto_login+"'");
18
18
  this._autoLoginKey = S.user_key;
19
19
  }
20
20
  return this._autoLoginKey;
@@ -22,13 +22,13 @@ Spontaneous.Box = (function($, S) {
22
22
 
23
23
  type: function() {
24
24
  if (!this._type) {
25
- this._type = this.container.type().box_prototype(this.content.id)
25
+ this._type = this.container.type().box_prototype(this.content.id);
26
26
  }
27
27
  return this._type;
28
28
  },
29
29
 
30
30
  id: function() {
31
- return this.container.id() + "/" + this.schema_id();
31
+ return this.container.id() + '/' + this.schema_id();
32
32
  },
33
33
 
34
34
  schema_id: function() {
@@ -39,10 +39,14 @@ Spontaneous.Box = (function($, S) {
39
39
  return 'box';
40
40
  },
41
41
 
42
+ isWritable: function() {
43
+ return this.type().data.writable;
44
+ },
45
+
42
46
  mouseover: function() {
43
47
  if (this.fields_preview) {
44
48
  this.fields_preview.addClass('hover');
45
- };
49
+ }
46
50
  },
47
51
  mouseout: function() {
48
52
  if (this.fields_preview) {
@@ -57,11 +61,11 @@ Spontaneous.Box = (function($, S) {
57
61
  }
58
62
  var id = css_id.split('-')[1], entry;
59
63
 
60
- for (var i = 0, entries = this.entries(), ii = entries.length; i < ii; i++) {
64
+ for (i = 0, entries = this.entries(), ii = entries.length; i < ii; i++) {
61
65
  if (entries[i].id() == id) { entry = entries[i]; break; }
62
66
  }
63
67
  entry.reposition(position, function(entry) {
64
- this.sorted(entry)
68
+ this.sorted(entry);
65
69
  }.bind(this));
66
70
  },
67
71
  sorted: function(entry) {
@@ -73,7 +77,7 @@ Spontaneous.Box = (function($, S) {
73
77
  },
74
78
 
75
79
  entry_id: function(entry) {
76
- return "entry-" + entry.id();
80
+ return 'entry-' + entry.id();
77
81
  },
78
82
 
79
83
  entry_class: function() {
@@ -84,13 +88,20 @@ Spontaneous.Box = (function($, S) {
84
88
  Spontaneous.Ajax.post(['/content', this.id(), type.schema_id].join('/'), {position: position}, this.entry_added.bind(this));
85
89
  },
86
90
 
87
- add_alias: function(alias_target_id, type, position) {
88
- S.Ajax.post(["/alias", this.id()].join("/"), {'alias_id':type.schema_id, 'target_id':alias_target_id, 'position':position}, this.entry_added.bind(this));
91
+ add_alias: function(alias_target_ids, type, position) {
92
+ S.Ajax.post(['/alias', this.id()].join('/'), {'alias_id':type.schema_id, 'target_ids':alias_target_ids, 'position':position}, this.entries_added.bind(this));
93
+ },
94
+
95
+ entries_added: function(result) {
96
+ var self = this;
97
+ result.forEach(function(entry) {
98
+ self.entry_added(entry);
99
+ });
89
100
  },
90
101
 
91
102
  entry_added: function(result) {
92
103
  var box = this
93
- ,position = result.position
104
+ , position = result.position
94
105
  , e = result.entry
95
106
  , entry = this.wrap_entry(e);
96
107
 
@@ -125,7 +136,7 @@ Spontaneous.Box = (function($, S) {
125
136
  // return [this.id()].join('/');
126
137
  // },
127
138
  entry_wrappers: function() {
128
- return this._entry_container.find('> .'+this.entry_class())
139
+ return this._entry_container.find('> .'+this.entry_class());
129
140
  }
130
141
  });
131
142
 
@@ -21,18 +21,21 @@ Spontaneous.BoxContainer = (function($, S) {
21
21
  return wrapper;
22
22
  },
23
23
  tab_bar: function() {
24
+ var self = this;
24
25
  if (this.boxes().length === 0) { return ''; }
25
26
  if (!this._tab_bar) {
26
27
  var bar = dom.ul('.slot-tabs');
28
+ var clickFunction = function(i) {
29
+ return function() {
30
+ this.activate(i, true);
31
+ }.bind(self);
32
+ };
27
33
  for (var i = 0, boxes = this.boxes(), ii = boxes.length; i < ii; i++) {
28
34
  var box = boxes[i];
29
35
  var li = dom.li();
30
- li.text(box.name())
36
+ li.text(box.name());
31
37
  li.append(dom.span('.down'));
32
- var click = function(index) {
33
- this.activate(index, true);
34
- }.bind(this, i);
35
- li.click(click);
38
+ li.click(clickFunction(i));
36
39
  bar.append(li);
37
40
  }
38
41
  this._tab_bar = bar;
@@ -43,7 +46,7 @@ Spontaneous.BoxContainer = (function($, S) {
43
46
  var box = this.boxes()[box_index];
44
47
  if (box === this._active_box) { return; }
45
48
  $('li', this.tab_bar()).removeClass('active');
46
- $('li:nth-child('+(box_index+1)+')', this.tab_bar()).addClass('active')
49
+ $('li:nth-child('+(box_index+1)+')', this.tab_bar()).addClass('active');
47
50
  box.activate();
48
51
  this._active_box = box;
49
52
  if (manually) {
@@ -65,10 +68,13 @@ Spontaneous.BoxContainer = (function($, S) {
65
68
  this.activate(0);
66
69
  },
67
70
  boxes: function() {
71
+ var self = this;
68
72
  if (!this._boxes) {
69
73
  var _boxes = [], content_container = this.box_content_container;
70
74
  var f = function(i, box) {
71
- _boxes.push(new Spontaneous.Views.BoxView(box, content_container))
75
+ var view = new Spontaneous.Views.BoxView(box, content_container);
76
+ self._subviews.push(view);
77
+ _boxes.push(view);
72
78
  }.bind(this);
73
79
  $.each(this.content.boxes(), f);
74
80
  this._boxes = _boxes;
@@ -12,20 +12,22 @@
12
12
  // 2. Regularise access to the various APIs, removing vendor prefixes and providing the spec defined methods
13
13
  // 3. Add some useful CSS-visible attributes to the HTML element
14
14
  (function() {
15
+ 'use strict';
15
16
  var _window = window, _document = document;
16
17
  var testFlexBoxCompatibility = false;
18
+ var i, ii;
17
19
  var prefixes = ' -webkit- -moz- -o- -ms- -khtml- '.split(' ');
18
20
  try {
19
21
 
20
22
  ///////////////////////////// Flexible Box model
21
- function set_prefixed_property_css(element, property, value, extra) {
23
+ var set_prefixed_property_css = function(element, property, value, extra) {
22
24
  element.style.cssText = prefixes.join(property + ':' + value + ';') + (extra || '');
23
- }
25
+ };
24
26
 
25
- function set_prefixed_value_css(element, property, value, extra) {
27
+ var set_prefixed_value_css = function(element, property, value, extra) {
26
28
  property += ':';
27
29
  element.style.cssText = (property + prefixes.join(value + ';' + property)).slice(0, -property.length) + (extra || '');
28
- }
30
+ };
29
31
 
30
32
 
31
33
  if (testFlexBoxCompatibility) {
@@ -39,32 +41,32 @@
39
41
 
40
42
  c.appendChild(elem);
41
43
  docElement.appendChild(c);
42
- w = elem.offsetWidth
44
+ w = elem.offsetWidth;
43
45
  c.removeChild(elem);
44
46
  docElement.removeChild(c);
45
47
 
46
48
  if (w !== 42) {
47
49
  // console.error(w)
48
- throw (w) + " Flexible Box Model not supported"
50
+ throw (w) + ' Flexible Box Model not supported';
49
51
  }
50
52
  }
51
53
 
52
54
  ///////////////////////////// XHR Uploads
53
55
  var xhr = new XMLHttpRequest();
54
56
  if (!xhr.upload) {
55
- throw "XMLHttpRequestUpload not supported";
57
+ throw 'XMLHttpRequestUpload not supported';
56
58
  }
57
59
 
58
60
  ///////////////////////////// FormData
59
61
  try {
60
62
  var f = new FormData();
61
63
  } catch (e) {
62
- throw "FormData not supported";
64
+ throw 'FormData not supported';
63
65
  }
64
66
 
65
67
  ///////////////////////////// File API / File objects
66
68
  if (!_window.File) {
67
- throw "File API not supported";
69
+ throw 'File API not supported';
68
70
  }
69
71
 
70
72
  ///////////////////////////// File API / objectURLs
@@ -89,7 +91,7 @@
89
91
  //// would seriously limit users ability to make quick changes on the go, for instance)
90
92
  _window.URL[createObjectURL] = function(file) {
91
93
  return '';
92
- }
94
+ };
93
95
  // throw "File API not supported";
94
96
  }
95
97
  if (_window.revokeBlobURL) {
@@ -106,7 +108,7 @@
106
108
  //// would seriously limit users ability to make quick changes on the go, for instance)
107
109
  _window.URL[revokeObjectURL] = function(file) {
108
110
  return '';
109
- }
111
+ };
110
112
  // throw "File API not supported";
111
113
  }
112
114
  }
@@ -116,7 +118,7 @@
116
118
  var proto = _window.File.prototype;
117
119
  if (!proto.slice) {
118
120
  var methods = ['webkitSlice', 'mozSlice'];
119
- for (var i = 0, ii = methods.length; i < ii; i++) {
121
+ for (i = 0, ii = methods.length; i < ii; i++) {
120
122
  var method = methods[i];
121
123
  if (proto[method]) { proto.slice = proto[method]; }
122
124
  }
@@ -129,15 +131,15 @@
129
131
 
130
132
  ///////////////////////////// localStorage
131
133
  try {
132
- var i = localStorage.getItem;
134
+ i = localStorage.getItem;
133
135
  } catch(e) {
134
- throw "Local Storage not supported"
136
+ throw 'Local Storage not supported';
135
137
  }
136
138
 
137
139
  var b = _document.documentElement;
138
- b.setAttribute('data-useragent', navigator.userAgent);
139
- b.setAttribute('data-platform', navigator.platform );
140
+ b.setAttribute('data-useragent', navigator.userAgent);
141
+ b.setAttribute('data-platform', navigator.platform);
140
142
  } catch (e) {
141
- _window.location.href = "/@spontaneous/unsupported?msg=" + _window.encodeURIComponent(e) + "&useragent=" + _window.encodeURIComponent(_window.navigator.userAgent);
143
+ _window.location.href = '/@spontaneous/unsupported?msg=' + _window.encodeURIComponent(e) + '&useragent=' + _window.encodeURIComponent(_window.navigator.userAgent);
142
144
  }
143
145
  }());