locomotive-aloha-rails 0.20.1.2 → 0.20.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/Rakefile +1 -1
  2. data/lib/aloha/rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/aloha/css/aloha.css +3 -0
  4. data/vendor/assets/javascripts/aloha/css/ext-aloha.css +3 -0
  5. data/vendor/assets/javascripts/aloha/lib/aloha-bootstrap.js +4565 -3934
  6. data/vendor/assets/javascripts/aloha/lib/aloha.js +1357 -702
  7. data/vendor/assets/javascripts/aloha/lib/aloha/command.js +16 -13
  8. data/vendor/assets/javascripts/aloha/lib/aloha/core.js +23 -3
  9. data/vendor/assets/javascripts/aloha/lib/aloha/ecma5shims.js +23 -7
  10. data/vendor/assets/javascripts/aloha/lib/aloha/editable.js +57 -14
  11. data/vendor/assets/javascripts/aloha/lib/aloha/engine.js +9 -5
  12. data/vendor/assets/javascripts/aloha/lib/aloha/floatingmenu.js +288 -96
  13. data/vendor/assets/javascripts/aloha/lib/aloha/jquery.js +11 -1
  14. data/vendor/assets/javascripts/aloha/lib/aloha/markup.js +318 -40
  15. data/vendor/assets/javascripts/aloha/lib/aloha/repositorymanager.js +11 -10
  16. data/vendor/assets/javascripts/aloha/lib/aloha/selection.js +20 -1
  17. data/vendor/assets/javascripts/aloha/lib/aloha/sidebar.js +11 -1
  18. data/vendor/assets/javascripts/aloha/lib/jquery-plugin.js +10 -7
  19. data/vendor/assets/javascripts/aloha/lib/util/dom.js +18 -6
  20. data/vendor/assets/javascripts/aloha/lib/util/range.js +6 -6
  21. data/vendor/assets/javascripts/aloha/lib/vendor/ext-3.2.1/ext-all-debug.js +26 -2
  22. data/vendor/assets/javascripts/aloha/lib/vendor/jquery.store.js +39 -15
  23. data/vendor/assets/javascripts/aloha/plugins/common/abbr/lib/abbr-plugin.js +1 -0
  24. data/vendor/assets/javascripts/aloha/plugins/common/align/lib/align-plugin.js +344 -334
  25. data/vendor/assets/javascripts/aloha/plugins/common/block/css/block.css +65 -12
  26. data/vendor/assets/javascripts/aloha/plugins/common/block/lib/block-plugin.js +12 -15
  27. data/vendor/assets/javascripts/aloha/plugins/common/block/lib/block.js +796 -180
  28. data/vendor/assets/javascripts/aloha/plugins/common/block/lib/blockcontenthandler.js +54 -13
  29. data/vendor/assets/javascripts/aloha/plugins/common/block/lib/blockmanager.js +315 -78
  30. data/vendor/assets/javascripts/aloha/plugins/common/block/lib/editor.js +111 -8
  31. data/vendor/assets/javascripts/aloha/plugins/common/block/lib/editormanager.js +2 -0
  32. data/vendor/assets/javascripts/aloha/plugins/common/block/lib/jquery-ui-1.8.16.custom.min.js +198 -0
  33. data/vendor/assets/javascripts/aloha/plugins/common/block/lib/sidebarattributeeditor.js +7 -20
  34. data/vendor/assets/javascripts/aloha/plugins/common/characterpicker/lib/characterpicker-plugin.js +15 -3
  35. data/vendor/assets/javascripts/aloha/plugins/common/contenthandler/lib/sanitizecontenthandler.js +3 -2
  36. data/vendor/assets/javascripts/aloha/plugins/common/contenthandler/lib/wordcontenthandler.js +111 -5
  37. data/vendor/assets/javascripts/aloha/plugins/common/dom-to-xhtml/lib/dom-to-xhtml-plugin.js +29 -0
  38. data/vendor/assets/javascripts/aloha/plugins/common/dom-to-xhtml/lib/dom-to-xhtml.js +306 -0
  39. data/vendor/assets/javascripts/aloha/plugins/common/format/lib/format-plugin.js +59 -5
  40. data/vendor/assets/javascripts/aloha/plugins/common/format/nls/i18n.js +1 -1
  41. data/vendor/assets/javascripts/aloha/plugins/common/horizontalruler/lib/horizontalruler-plugin.js +18 -3
  42. data/vendor/assets/javascripts/aloha/plugins/common/image/img/crop-buttons.gif +0 -0
  43. data/vendor/assets/javascripts/aloha/plugins/common/image/lib/image-plugin.js +1629 -1601
  44. data/vendor/assets/javascripts/aloha/plugins/common/image/vendor/jcrop/jquery.jcrop.css +11 -0
  45. data/vendor/assets/javascripts/aloha/plugins/common/link/extra/linklist.js +8 -6
  46. data/vendor/assets/javascripts/aloha/plugins/common/link/lib/link-plugin.js +26 -10
  47. data/vendor/assets/javascripts/aloha/plugins/common/list/nls/de/i18n.js +5 -1
  48. data/vendor/assets/javascripts/aloha/plugins/common/paste/lib/paste-plugin.js +3 -4
  49. data/vendor/assets/javascripts/aloha/plugins/common/table/lib/table-cell.js +13 -12
  50. data/vendor/assets/javascripts/aloha/plugins/common/table/lib/table-plugin.js +108 -61
  51. data/vendor/assets/javascripts/aloha/plugins/common/table/lib/table-selection.js +61 -1
  52. data/vendor/assets/javascripts/aloha/plugins/common/table/lib/table.js +1 -0
  53. data/vendor/assets/javascripts/aloha/plugins/common/table/nls/de/i18n.js +28 -1
  54. data/vendor/assets/javascripts/aloha/plugins/common/table/nls/i18n.js +36 -10
  55. data/vendor/assets/javascripts/aloha/plugins/extra/browser/css/browser.jqgrid.css +292 -292
  56. data/vendor/assets/javascripts/aloha/plugins/extra/browser/lib/browser.js +28 -5
  57. data/vendor/assets/javascripts/aloha/plugins/extra/browser/lib/locale.js +2 -2
  58. data/vendor/assets/javascripts/aloha/plugins/extra/browser/vendor/grid.locale.de.js +6 -1
  59. data/vendor/assets/javascripts/aloha/plugins/extra/browser/vendor/grid.locale.en.js +5 -0
  60. data/vendor/assets/javascripts/aloha/plugins/extra/browser/vendor/jquery.jqGrid.js +5 -0
  61. data/vendor/assets/javascripts/aloha/plugins/extra/browser/vendor/jquery.jstree.js +6 -1
  62. data/vendor/assets/javascripts/aloha/plugins/extra/browser/vendor/jquery.ui.js +6 -1
  63. data/vendor/assets/javascripts/aloha/plugins/extra/browser/vendor/ui-layout.js +6 -1
  64. data/vendor/assets/javascripts/aloha/plugins/extra/cite/lib/cite-plugin.js +18 -4
  65. data/vendor/assets/javascripts/aloha/plugins/extra/formatlesspaste/lib/formatlesspaste-plugin.js +1 -1
  66. data/vendor/assets/javascripts/aloha/plugins/extra/linkbrowser/lib/linkbrowser-plugin.js +14 -2
  67. data/vendor/assets/javascripts/aloha/plugins/extra/numerated-headers/demo/js/aloha-config.js +2 -2
  68. data/vendor/assets/javascripts/aloha/plugins/extra/toc/lib/toc-plugin.js +382 -0
  69. data/vendor/assets/javascripts/aloha/plugins/extra/toc/nls/de/i18n.js +3 -0
  70. data/vendor/assets/javascripts/aloha/plugins/extra/toc/nls/i18n.js +4 -0
  71. metadata +15 -11
  72. data/vendor/assets/javascripts/aloha/plugins/extra/toc/i18n/de.json +0 -1
  73. data/vendor/assets/javascripts/aloha/plugins/extra/toc/i18n/en.json +0 -1
  74. data/vendor/assets/javascripts/aloha/plugins/extra/toc/src/toc.js +0 -350
@@ -0,0 +1,3 @@
1
+ define(
2
+ {"button.addtoc.tooltip":"Table of contents"}
3
+ );
@@ -0,0 +1,4 @@
1
+ define({
2
+ root: {"button.addtoc.tooltip":"Table of contents"},
3
+ "de":true
4
+ });
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locomotive-aloha-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.1.2
4
+ version: 0.20.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-13 00:00:00.000000000 Z
12
+ date: 2012-04-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
16
- requirement: &2162208140 !ruby/object:Gem::Requirement
16
+ requirement: &2158238760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.2.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2162208140
24
+ version_requirements: *2158238760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &2162207600 !ruby/object:Gem::Requirement
27
+ requirement: &2158237600 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 0.9.2
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2162207600
35
+ version_requirements: *2158237600
36
36
  description: Seamlessly integrates Aloha Editor into the Rails 3.1 asset pipeline.
37
37
  email: didier.lafforgue@gmail.com
38
38
  executables: []
@@ -485,6 +485,7 @@ files:
485
485
  - vendor/assets/javascripts/aloha/plugins/common/block/lib/blockmanager.js
486
486
  - vendor/assets/javascripts/aloha/plugins/common/block/lib/editor.js
487
487
  - vendor/assets/javascripts/aloha/plugins/common/block/lib/editormanager.js
488
+ - vendor/assets/javascripts/aloha/plugins/common/block/lib/jquery-ui-1.8.16.custom.min.js
488
489
  - vendor/assets/javascripts/aloha/plugins/common/block/lib/sidebarattributeeditor.js
489
490
  - vendor/assets/javascripts/aloha/plugins/common/block/package.json
490
491
  - vendor/assets/javascripts/aloha/plugins/common/block/README
@@ -504,6 +505,8 @@ files:
504
505
  - vendor/assets/javascripts/aloha/plugins/common/contenthandler/lib/wordcontenthandler.js
505
506
  - vendor/assets/javascripts/aloha/plugins/common/contenthandler/package.json
506
507
  - vendor/assets/javascripts/aloha/plugins/common/contenthandler/README.md
508
+ - vendor/assets/javascripts/aloha/plugins/common/dom-to-xhtml/lib/dom-to-xhtml-plugin.js
509
+ - vendor/assets/javascripts/aloha/plugins/common/dom-to-xhtml/lib/dom-to-xhtml.js
507
510
  - vendor/assets/javascripts/aloha/plugins/common/format/css/format.css
508
511
  - vendor/assets/javascripts/aloha/plugins/common/format/img/em.png
509
512
  - vendor/assets/javascripts/aloha/plugins/common/format/img/strong.png
@@ -531,6 +534,7 @@ files:
531
534
  - vendor/assets/javascripts/aloha/plugins/common/image/demo/cropnresize.jpg
532
535
  - vendor/assets/javascripts/aloha/plugins/common/image/demo/index.html
533
536
  - vendor/assets/javascripts/aloha/plugins/common/image/img/blank.jpg
537
+ - vendor/assets/javascripts/aloha/plugins/common/image/img/crop-buttons.gif
534
538
  - vendor/assets/javascripts/aloha/plugins/common/image/img/cropnresize.png
535
539
  - vendor/assets/javascripts/aloha/plugins/common/image/img/handle-sw.png
536
540
  - vendor/assets/javascripts/aloha/plugins/common/image/img/image-align-left.png
@@ -1057,10 +1061,10 @@ files:
1057
1061
  - vendor/assets/javascripts/aloha/plugins/extra/ribbon/LICENSE.md
1058
1062
  - vendor/assets/javascripts/aloha/plugins/extra/ribbon/package.json
1059
1063
  - vendor/assets/javascripts/aloha/plugins/extra/ribbon/README.md
1060
- - vendor/assets/javascripts/aloha/plugins/extra/toc/i18n/de.json
1061
- - vendor/assets/javascripts/aloha/plugins/extra/toc/i18n/en.json
1064
+ - vendor/assets/javascripts/aloha/plugins/extra/toc/lib/toc-plugin.js
1065
+ - vendor/assets/javascripts/aloha/plugins/extra/toc/nls/de/i18n.js
1066
+ - vendor/assets/javascripts/aloha/plugins/extra/toc/nls/i18n.js
1062
1067
  - vendor/assets/javascripts/aloha/plugins/extra/toc/package.json
1063
- - vendor/assets/javascripts/aloha/plugins/extra/toc/src/toc.js
1064
1068
  - vendor/assets/javascripts/aloha/plugins/extra/vie/demo/index.html
1065
1069
  - vendor/assets/javascripts/aloha/plugins/extra/vie/img/cms-decoupled-communications.png
1066
1070
  - vendor/assets/javascripts/aloha/plugins/extra/vie/LICENSE
@@ -1086,7 +1090,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
1086
1090
  version: '0'
1087
1091
  segments:
1088
1092
  - 0
1089
- hash: 4386440858070789900
1093
+ hash: 338053049680169151
1090
1094
  required_rubygems_version: !ruby/object:Gem::Requirement
1091
1095
  none: false
1092
1096
  requirements:
@@ -1095,7 +1099,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1095
1099
  version: '0'
1096
1100
  segments:
1097
1101
  - 0
1098
- hash: 4386440858070789900
1102
+ hash: 338053049680169151
1099
1103
  requirements: []
1100
1104
  rubyforge_project:
1101
1105
  rubygems_version: 1.8.11
@@ -1 +0,0 @@
1
- {"button.addtoc.tooltip":"Inhaltsverzeichnis"}
@@ -1 +0,0 @@
1
- {"button.addtoc.tooltip":"Table of contents"}
@@ -1,350 +0,0 @@
1
- /**
2
- * Problem: can't regenerate ids to reflect the heading text, because
3
- * that would invalidate any external links
4
- *
5
- * Some assumptions are made about the order of the elements that jQuery
6
- * returns. Usually, this is document order. With $.prevAll() and
7
- * .parents(), however, the order is reversed.
8
- *
9
- * It would be nice to have some way to register for a 'modified' event
10
- * on descendants of editables that were actually edited.
11
- *
12
- * How to handle dynamically registered editables?
13
- */
14
-
15
- (function(){
16
- var
17
- deps = GENTICS.Aloha.TOC ||
18
- {'jQuery': jQuery},
19
- //,'underscore': _},
20
-
21
- $ = deps['jQuery'];
22
- // u = deps['underscore'],
23
-
24
- // each = u.each,
25
- // map = u.map,
26
- // detect = u.detect,
27
- // indexOf = u.indexOf,
28
- // head = u.head,
29
- // tail = u.tail,
30
- // last = u.last;
31
- function last(a) { return a[a.length - 1]; }
32
- function head(a) { return a[0]; }
33
- function tail(a) { return a.slice(1); }
34
- function indexOf(a, item) {
35
- return detect(a, function(cmp){
36
- return cmp === item;
37
- });
38
- }
39
- function detect(a, f) {
40
- for (var i = 0; i < a.length; i++) {
41
- if (f(a[i])) {
42
- return a[i];
43
- }
44
- }
45
- return null;
46
- }
47
- function map(a, f) {
48
- var result = [];
49
- for (var i = 0; i < a.length; i++) {
50
- result.push(f(a[i]));
51
- }
52
- return result;
53
- }
54
- function each(a, f) {
55
- map(a, f);
56
- }
57
-
58
- var namespace = 'toc';
59
- var TOC = GENTICS.Aloha.TOC = new GENTICS.Aloha.Plugin(namespace);
60
- GENTICS.Aloha.TOC.languages = ['en', 'de' ];
61
-
62
- var $containers = null;
63
- var allTocs = [];
64
-
65
- //-------------- plugin interface ---------------
66
-
67
- TOC.init = function(){
68
- var s = TOC.settings;
69
- s.updateInterval = s.updateInterval || 5000;
70
- // minimum number of entries in the TOC. if the TOC contains less entries, it will be hidden
71
- s.minEntries = s.minEntries || 0;
72
- TOC.initButtons();
73
- $(document).ready(function(){
74
- TOC.spawn();
75
- });
76
- };
77
-
78
- TOC.initButtons = function(){
79
- TOC.insertTocButton = new GENTICS.Aloha.ui.Button({
80
- 'iconClass' : 'GENTICS_button GENTICS_button_ul',
81
- 'size' : 'small',
82
- 'onclick' : function () { TOC.insertAtSelection($containers); },
83
- 'tooltip' : this.i18n('button.addtoc.tooltip'),
84
- 'toggle' : false
85
- });
86
- GENTICS.Aloha.FloatingMenu.addButton(
87
- 'GENTICS.Aloha.continuoustext',
88
- this.insertTocButton,
89
- GENTICS.Aloha.i18n(GENTICS.Aloha, 'floatingmenu.tab.insert'),
90
- 1
91
- );
92
- };
93
-
94
- TOC.register = function($c){
95
- $containers = $c;
96
- };
97
-
98
- //-------------- module methods -----------------
99
-
100
- TOC.generateId = function(elemOrText){
101
- var validId;
102
- if (typeof elemOrText == "object") {
103
- validId = $(elemOrText).text().
104
- replace(/[^a-zA-Z-]+/g, '-').
105
- replace(/^[^a-zA-Z]+/, '');
106
- } else if (elemOrText) {
107
- validId = elemOrText;
108
- }
109
- for (var uniquifier = 0;; uniquifier++) {
110
- var uniqueId = validId;
111
- if (uniquifier) {
112
- uniqueId += '-' + uniquifier;
113
- }
114
- var conflict = document.getElementById(uniqueId);
115
- if ( !conflict
116
- || ( typeof elemOrText == "object"
117
- && conflict === elemOrText))
118
- {
119
- return uniqueId;
120
- }
121
- }
122
- //unreachable
123
- };
124
- /**
125
- * returns a tree of sections in the given context. if the context
126
- * element(s) begin a section, they will be included. First element
127
- * of each branch in the tree is a $(section) or $() for the
128
- * root node.
129
- * TODO: http://www.w3.org/TR/html5/sections.html#outline
130
- */
131
- TOC.outline = function (ctx) {
132
- var rootNode = [$()];
133
- var potentialParents = [rootNode];
134
- TOC.headings(ctx).each(function(){
135
- var $heading = $(this);
136
- var nodeName = this.nodeName.toLowerCase();
137
- var hLevels = ['h6', 'h5', 'h4', 'h3', 'h2', 'h1'];
138
- var currLevel = $.inArray(nodeName, hLevels);
139
- var higherEq = hLevels.slice(currLevel).join(',');
140
- var $section = $heading.nextUntil(higherEq).andSelf();
141
- var node = [$section];
142
-
143
- var parent = detect(potentialParents, function (parent) {
144
- var parentSection = parent[0];
145
- return !parentSection.length || //top-level contains everything
146
- detect(parentSection, function (sectionElem) {
147
- return $heading.get(0) === sectionElem ||
148
- $.contains(sectionElem, $heading.get(0));
149
- });
150
- });
151
- parent.push(node);
152
- potentialParents.splice(0, indexOf(potentialParents, parent), node);
153
- });
154
- return rootNode;
155
- };
156
-
157
- TOC.editableContainers = function () {
158
- return $(map(GENTICS.Aloha.editables, function (editable) {
159
- return document.getElementById(editable.getId());
160
- }));
161
- };
162
-
163
- TOC.headings = function ($ctx) {
164
- return $ctx.find(':header').add($ctx.filter(':header'));
165
- };
166
-
167
- TOC.anchorFromLinkId = function ($ctx, linkId) {
168
- return linkId ? $ctx.find('a[href $= "#' + linkId + '"]') : $();
169
- };
170
-
171
- TOC.linkIdFromAnchor = function ($anchor){
172
- var href = $anchor.attr('href');
173
- return href ? href.match(/#(.*?)$/)[1] : null;
174
- };
175
- /**
176
- * inserts a new TOC at the current selection
177
- */
178
- TOC.insertAtSelection = function($containers){
179
- $containers = $containers || TOC.editableContainers();
180
- var id = TOC.generateId('toc');
181
-
182
- // we start out with an empty ordered list
183
- var $tocElement = $("<ol class='toc_root'></ol>").
184
- attr('id', id).attr('contentEditable', 'false');
185
- var range = GENTICS.Aloha.Selection.getRangeObject();
186
- var tocEditable = GENTICS.Aloha.activeEditable;
187
- var $tocContainer = $(document.getElementById(tocEditable.getId()));
188
- GENTICS.Utils.Dom.insertIntoDOM($tocElement, range, $tocContainer);
189
-
190
- TOC.create(id).register($containers).update().tickTock();
191
- };
192
- /**
193
- * Spawn containers for all ols with the toc_root class.
194
- */
195
- TOC.spawn = function ($ctx, $containers) {
196
- $ctx = $ctx || $('body');
197
- $containers = $containers || TOC.editableContainers();
198
- $ctx.find('ol.toc_root').each(function(){
199
- var id = $(this).attr('id');
200
- if (!id) {
201
- id = TOC.generateId('toc');
202
- $(this).attr('id', id);
203
- }
204
- TOC.create(id).register($containers).tickTock();
205
- });
206
- };
207
-
208
- TOC.create = function (id) {
209
- allTocs.push(this);
210
- return {
211
- 'id': id,
212
- '$containers': $(),
213
- /**
214
- * find the TOC root element for this instance
215
- */
216
- root: function(){
217
- return $(document.getElementById(this.id));
218
- },
219
- /**
220
- * registers the given containers with the TOC. a
221
- * container is an element that may begin or contain
222
- * sections. Note: use .live on all [contenteditable=true]
223
- * to catch dynamically added editables.
224
- * the same containers can be passed in multiple times. they will
225
- * be registered only once.
226
- */
227
- register: function ($containers){
228
- var self = this;
229
- // the .add() method ensures that the $containers will be in
230
- // document order (required for correct TOC order)
231
- self.$containers = self.$containers.add($containers);
232
- self.$containers.filter(function(){
233
- return !$(this).data(namespace + '.' + self.id + '.listening');
234
- }).each(function(){
235
- var $container = $(this);
236
- $container.data(namespace + '.' + self.id + '.listening', true);
237
- $container.bind('blur', function(){
238
- self.cleanupIds($container.get(0));
239
- self.update($container);
240
- });
241
- });
242
- return self;
243
- },
244
- tickTock: function (interval) {
245
- var self = this;
246
- interval = interval || TOC.settings.updateInterval;
247
- if (!interval) {
248
- return;
249
- }
250
- window.setInterval(function(){
251
- self.register(TOC.editableContainers());
252
- // TODO: use the active editable instead of rebuilding
253
- // the entire TOC
254
- self.update();
255
- }, interval);
256
- return self;
257
- },
258
- /**
259
- * there are various ways which can cause duplicate ids on targets
260
- * (e.g. pressing enter in a heading and writing in a new line, or
261
- * copy&pasting). Passing a ctx updates only those elements
262
- * either inside or equal to it.
263
- * TODO: to be correct this should do
264
- * a $.contains(documentElement...
265
- */
266
- cleanupIds: function (ctx) {
267
- var ids = [];
268
- TOC.headings(this.$containers).each(function(){
269
- var id = $(this).attr('id');
270
- if ( (id && -1 != $.inArray(id, ids))
271
- || ( ctx
272
- && ($.contains(ctx, this) || ctx === this)))
273
- {
274
- $(this).attr('id', TOC.generateId(this));
275
- }
276
- ids.push(id);
277
- });
278
- return this;
279
- },
280
- /**
281
- * Updates the TOC from the sections in the given context, or in
282
- * all containers that have been registered with this TOC, if no
283
- * context is given.
284
- */
285
- update: function ($ctx) {
286
- var self = this;
287
- $ctx = $ctx || self.$containers;
288
- var outline = TOC.outline(self.$containers);
289
- var ancestors = [self.root()];
290
- var prevSiblings = [];
291
- //TODO: handle TOC rebuilding more intelligently. currently,
292
- //the TOC is always rebuilt from scratch.
293
- last(ancestors).empty();
294
- (function descend(outline) {
295
- var prevSiblings = [];
296
- each(outline, function (node) {
297
- var $section = head(node);
298
- var $entry = self.linkSection($section, ancestors, prevSiblings);
299
- ancestors.push($entry);
300
- descend(tail(node));
301
- ancestors.pop();
302
- prevSiblings.push($entry);
303
- });
304
- })(tail(outline));
305
-
306
- // count number of li's in the TOC, if less than minEntries, hide the TOC
307
- var minEntries = self.root().attr('data-TOC-minEntries') || TOC.settings.minEntries;
308
- if (self.root().find('li').length >= minEntries) {
309
- self.root().show();
310
- } else {
311
- self.root().hide();
312
- }
313
-
314
- return this;
315
- },
316
- /**
317
- * updates or creates an entry in the TOC for the given section.
318
- */
319
- linkSection: function ($section, ancestors, prevSiblings) {
320
- var linkId = $section.eq(0).attr('id');
321
- if (!linkId) {
322
- linkId = TOC.generateId($section.get(0));
323
- $section.eq(0).attr('id', linkId);
324
- }
325
- var $root = this.root();
326
- var $entry = TOC.anchorFromLinkId($root, linkId);
327
- if (!$entry.length) {
328
- $entry = $('<li><a/></li>');
329
- }
330
- $entry.find('a').
331
- attr('href', '#' + linkId).
332
- text($section.eq(0).text());
333
- if (last(prevSiblings)) {
334
- last(prevSiblings).after($entry);
335
- }
336
- else {
337
- if (last(ancestors).get(0) == $root.get(0)) {
338
- $root.append($entry);
339
- }
340
- else {
341
- var $subToc = $('<ol/>').append($entry);
342
- last(ancestors).append($subToc);
343
- }
344
- }
345
- return $entry;
346
- }};
347
- };//create
348
- }());
349
-
350
- //EOF