concrete 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/CHANGELOG +32 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +87 -0
  4. data/concrete/basic_inline_editor.js +73 -0
  5. data/concrete/clipboard.js +72 -0
  6. data/concrete/concrete.js +58 -0
  7. data/concrete/constraint_checker.js +297 -0
  8. data/concrete/editor.js +964 -0
  9. data/concrete/element_extension.js +68 -0
  10. data/concrete/external_identifier_provider.js +112 -0
  11. data/concrete/helper.js +63 -0
  12. data/concrete/identifier_provider.js +168 -0
  13. data/concrete/inline_editor.js +55 -0
  14. data/concrete/metamodel_provider.js +171 -0
  15. data/concrete/model_interface.js +429 -0
  16. data/concrete/scroller.js +106 -0
  17. data/concrete/selector.js +302 -0
  18. data/concrete/template_provider.js +141 -0
  19. data/concrete/ui/abstract_dialog.js +80 -0
  20. data/concrete/ui/concrete_ui.js +28 -0
  21. data/concrete/ui/create_module_dialog.js +55 -0
  22. data/concrete/ui/images/close.png +0 -0
  23. data/concrete/ui/images/document-new.png +0 -0
  24. data/concrete/ui/images/document-save.png +0 -0
  25. data/concrete/ui/images/edit-find-replace.png +0 -0
  26. data/concrete/ui/images/emblem-symbolic-link.png +0 -0
  27. data/concrete/ui/images/help-browser.png +0 -0
  28. data/concrete/ui/images/minus_11px.png +0 -0
  29. data/concrete/ui/images/plus_11px.png +0 -0
  30. data/concrete/ui/images/preferences-system.png +0 -0
  31. data/concrete/ui/images/process-stop.png +0 -0
  32. data/concrete/ui/images/system-search.png +0 -0
  33. data/concrete/ui/layout_manager.js +54 -0
  34. data/concrete/ui/module_browser.js +88 -0
  35. data/concrete/ui/module_editor.js +217 -0
  36. data/concrete/ui/open_element_dialog.js +90 -0
  37. data/concrete/ui/preferences_dialog.js +75 -0
  38. data/concrete/ui/proceed_dialog.js +52 -0
  39. data/concrete/ui/search_replace_dialog.js +323 -0
  40. data/concrete/ui/style.css +296 -0
  41. data/concrete/ui/toolbar.js +74 -0
  42. data/concrete/ui/workbench.js +165 -0
  43. data/doc/concrete_developers_guide.html +1054 -0
  44. data/doc/concrete_developers_guide.txt +502 -0
  45. data/doc/concrete_users_guide.html +694 -0
  46. data/doc/concrete_users_guide.txt +223 -0
  47. data/example/formula_editor/example_data/example1.json +11 -0
  48. data/example/formula_editor/formula_editor.html +83 -0
  49. data/example/formula_editor/sqrt_horz.png +0 -0
  50. data/example/formula_editor/sqrt_vert.png +0 -0
  51. data/example/formula_editor/style.css +31 -0
  52. data/example/metamodel_editor/edit.rb +54 -0
  53. data/example/metamodel_editor/example_data/formula_metamodel.json +18 -0
  54. data/example/metamodel_editor/example_data/meta_metamodel.json +22 -0
  55. data/example/metamodel_editor/example_data/statemachine_metamodel.json +32 -0
  56. data/example/metamodel_editor/metamodel_editor.html +120 -0
  57. data/example/metamodel_editor/metamodel_editor2.html +135 -0
  58. data/example/metamodel_editor/metamodel_editor3.html +151 -0
  59. data/example/metamodel_editor/style.css +8 -0
  60. data/example/metamodel_editor/style2.css +19 -0
  61. data/example/metamodel_editor/style3.css +35 -0
  62. data/example/minimal_editor/minimal_editor.html +43 -0
  63. data/example/statemachine_editor/example_data/example1.json +11 -0
  64. data/example/statemachine_editor/state_background.png +0 -0
  65. data/example/statemachine_editor/statemachine_editor0.html +55 -0
  66. data/example/statemachine_editor/statemachine_editor1.html +62 -0
  67. data/example/statemachine_editor/statemachine_editor2.html +103 -0
  68. data/example/statemachine_editor/style0.css +8 -0
  69. data/example/statemachine_editor/style1.css +32 -0
  70. data/example/statemachine_editor/style2.css +43 -0
  71. data/example/themes/cobalt.css +176 -0
  72. data/example/themes/dialog-error.png +0 -0
  73. data/example/themes/dialog-information.png +0 -0
  74. data/example/themes/dialog-warning.png +0 -0
  75. data/example/themes/dots_12px.png +0 -0
  76. data/example/themes/fold_button_dots_when_hidden.css +18 -0
  77. data/example/themes/fold_button_plus_minus.css +21 -0
  78. data/example/themes/fold_button_plus_when_hidden.css +18 -0
  79. data/example/themes/light_blue.css +177 -0
  80. data/example/themes/minus_11px.png +0 -0
  81. data/example/themes/minus_13px.png +0 -0
  82. data/example/themes/minus_9px.png +0 -0
  83. data/example/themes/plus_11px.png +0 -0
  84. data/example/themes/plus_13px.png +0 -0
  85. data/example/themes/plus_9px.png +0 -0
  86. data/example/themes/white.css +177 -0
  87. data/lib/concrete/concrete_syntax_provider.rb +63 -0
  88. data/lib/concrete/config.rb +36 -0
  89. data/lib/concrete/file_cache_map.rb +88 -0
  90. data/lib/concrete/index_builder.rb +108 -0
  91. data/lib/concrete/metamodel/concrete_mmm.rb +45 -0
  92. data/lib/concrete/metamodel/ecore_to_concrete.rb +80 -0
  93. data/lib/concrete/server.rb +92 -0
  94. data/lib/concrete/util/logger.rb +24 -0
  95. data/lib/concrete/util/string_writer.rb +17 -0
  96. data/lib/concrete/working_set.rb +41 -0
  97. data/rakefile +33 -0
  98. data/redist/prototype.js +4320 -0
  99. data/redist/scriptaculous/builder.js +136 -0
  100. data/redist/scriptaculous/controls.js +991 -0
  101. data/redist/scriptaculous/dragdrop.js +975 -0
  102. data/redist/scriptaculous/effects.js +1130 -0
  103. data/redist/scriptaculous/scriptaculous.js +60 -0
  104. data/redist/scriptaculous/slider.js +275 -0
  105. data/redist/scriptaculous/sound.js +55 -0
  106. data/redist/scriptaculous/unittest.js +568 -0
  107. data/test/concrete_test.rb +5 -0
  108. data/test/file_cache_map_test.rb +90 -0
  109. data/test/file_cache_map_test/testdir/fileA +1 -0
  110. data/test/index_builder_test.rb +68 -0
  111. data/test/index_builder_test/ecore_index.js +85 -0
  112. data/test/index_builder_test/ecore_index_expected.js +85 -0
  113. data/test/integration/external_elements_test.html +114 -0
  114. data/test/metamodel_test.rb +40 -0
  115. data/test/metamodel_test/concrete_mmm_expected.js +19 -0
  116. data/test/metamodel_test/concrete_mmm_generated.js +19 -0
  117. data/test/metamodel_test/concrete_mmm_regenerated.js +19 -0
  118. data/test/unit/external_identifier_provider_test.html +138 -0
  119. data/test/unit/identifier_provider_test.html +269 -0
  120. data/test/unit/metamodel_provider_test.html +318 -0
  121. data/test/unit/model_interface_test.html +257 -0
  122. data/test/unit/template_provider_test.html +171 -0
  123. data/test/unit/test.css +90 -0
  124. data/test/working_set_test.rb +54 -0
  125. data/test/working_set_test/file1.txt +0 -0
  126. data/test/working_set_test/file2 +0 -0
  127. data/test/working_set_test/subdir/file3.xml +0 -0
  128. metadata +201 -0
@@ -0,0 +1,136 @@
1
+ // script.aculo.us builder.js v1.8.2, Tue Nov 18 18:30:58 +0100 2008
2
+
3
+ // Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
4
+ //
5
+ // script.aculo.us is freely distributable under the terms of an MIT-style license.
6
+ // For details, see the script.aculo.us web site: http://script.aculo.us/
7
+
8
+ var Builder = {
9
+ NODEMAP: {
10
+ AREA: 'map',
11
+ CAPTION: 'table',
12
+ COL: 'table',
13
+ COLGROUP: 'table',
14
+ LEGEND: 'fieldset',
15
+ OPTGROUP: 'select',
16
+ OPTION: 'select',
17
+ PARAM: 'object',
18
+ TBODY: 'table',
19
+ TD: 'table',
20
+ TFOOT: 'table',
21
+ TH: 'table',
22
+ THEAD: 'table',
23
+ TR: 'table'
24
+ },
25
+ // note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken,
26
+ // due to a Firefox bug
27
+ node: function(elementName) {
28
+ elementName = elementName.toUpperCase();
29
+
30
+ // try innerHTML approach
31
+ var parentTag = this.NODEMAP[elementName] || 'div';
32
+ var parentElement = document.createElement(parentTag);
33
+ try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
34
+ parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
35
+ } catch(e) {}
36
+ var element = parentElement.firstChild || null;
37
+
38
+ // see if browser added wrapping tags
39
+ if(element && (element.tagName.toUpperCase() != elementName))
40
+ element = element.getElementsByTagName(elementName)[0];
41
+
42
+ // fallback to createElement approach
43
+ if(!element) element = document.createElement(elementName);
44
+
45
+ // abort if nothing could be created
46
+ if(!element) return;
47
+
48
+ // attributes (or text)
49
+ if(arguments[1])
50
+ if(this._isStringOrNumber(arguments[1]) ||
51
+ (arguments[1] instanceof Array) ||
52
+ arguments[1].tagName) {
53
+ this._children(element, arguments[1]);
54
+ } else {
55
+ var attrs = this._attributes(arguments[1]);
56
+ if(attrs.length) {
57
+ try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
58
+ parentElement.innerHTML = "<" +elementName + " " +
59
+ attrs + "></" + elementName + ">";
60
+ } catch(e) {}
61
+ element = parentElement.firstChild || null;
62
+ // workaround firefox 1.0.X bug
63
+ if(!element) {
64
+ element = document.createElement(elementName);
65
+ for(attr in arguments[1])
66
+ element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
67
+ }
68
+ if(element.tagName.toUpperCase() != elementName)
69
+ element = parentElement.getElementsByTagName(elementName)[0];
70
+ }
71
+ }
72
+
73
+ // text, or array of children
74
+ if(arguments[2])
75
+ this._children(element, arguments[2]);
76
+
77
+ return $(element);
78
+ },
79
+ _text: function(text) {
80
+ return document.createTextNode(text);
81
+ },
82
+
83
+ ATTR_MAP: {
84
+ 'className': 'class',
85
+ 'htmlFor': 'for'
86
+ },
87
+
88
+ _attributes: function(attributes) {
89
+ var attrs = [];
90
+ for(attribute in attributes)
91
+ attrs.push((attribute in this.ATTR_MAP ? this.ATTR_MAP[attribute] : attribute) +
92
+ '="' + attributes[attribute].toString().escapeHTML().gsub(/"/,'&quot;') + '"');
93
+ return attrs.join(" ");
94
+ },
95
+ _children: function(element, children) {
96
+ if(children.tagName) {
97
+ element.appendChild(children);
98
+ return;
99
+ }
100
+ if(typeof children=='object') { // array can hold nodes and text
101
+ children.flatten().each( function(e) {
102
+ if(typeof e=='object')
103
+ element.appendChild(e);
104
+ else
105
+ if(Builder._isStringOrNumber(e))
106
+ element.appendChild(Builder._text(e));
107
+ });
108
+ } else
109
+ if(Builder._isStringOrNumber(children))
110
+ element.appendChild(Builder._text(children));
111
+ },
112
+ _isStringOrNumber: function(param) {
113
+ return(typeof param=='string' || typeof param=='number');
114
+ },
115
+ build: function(html) {
116
+ var element = this.node('div');
117
+ $(element).update(html.strip());
118
+ return element.down();
119
+ },
120
+ dump: function(scope) {
121
+ if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope
122
+
123
+ var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
124
+ "BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
125
+ "FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
126
+ "KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
127
+ "PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
128
+ "TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);
129
+
130
+ tags.each( function(tag){
131
+ scope[tag] = function() {
132
+ return Builder.node.apply(Builder, [tag].concat($A(arguments)));
133
+ };
134
+ });
135
+ }
136
+ };
@@ -0,0 +1,991 @@
1
+ // script.aculo.us controls.js v1.8.2, Tue Nov 18 18:30:58 +0100 2008
2
+
3
+ // Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
4
+ // (c) 2005-2008 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
5
+ // (c) 2005-2008 Jon Tirsen (http://www.tirsen.com)
6
+ // Contributors:
7
+ // Richard Livsey
8
+ // Rahul Bhargava
9
+ // Rob Wills
10
+ //
11
+ // script.aculo.us is freely distributable under the terms of an MIT-style license.
12
+ // For details, see the script.aculo.us web site: http://script.aculo.us/
13
+
14
+ // Autocompleter.Base handles all the autocompletion functionality
15
+ // that's independent of the data source for autocompletion. This
16
+ // includes drawing the autocompletion menu, observing keyboard
17
+ // and mouse events, and similar.
18
+ //
19
+ // Specific autocompleters need to provide, at the very least,
20
+ // a getUpdatedChoices function that will be invoked every time
21
+ // the text inside the monitored textbox changes. This method
22
+ // should get the text for which to provide autocompletion by
23
+ // invoking this.getToken(), NOT by directly accessing
24
+ // this.element.value. This is to allow incremental tokenized
25
+ // autocompletion. Specific auto-completion logic (AJAX, etc)
26
+ // belongs in getUpdatedChoices.
27
+ //
28
+ // Tokenized incremental autocompletion is enabled automatically
29
+ // when an autocompleter is instantiated with the 'tokens' option
30
+ // in the options parameter, e.g.:
31
+ // new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' });
32
+ // will incrementally autocomplete with a comma as the token.
33
+ // Additionally, ',' in the above example can be replaced with
34
+ // a token array, e.g. { tokens: [',', '\n'] } which
35
+ // enables autocompletion on multiple tokens. This is most
36
+ // useful when one of the tokens is \n (a newline), as it
37
+ // allows smart autocompletion after linebreaks.
38
+
39
+ if(typeof Effect == 'undefined')
40
+ throw("controls.js requires including script.aculo.us' effects.js library");
41
+
42
+ var Autocompleter = { };
43
+ Autocompleter.Base = Class.create({
44
+ baseInitialize: function(element, update, options) {
45
+ element = $(element);
46
+ this.element = element;
47
+ this.update = $(update);
48
+ this.hasFocus = false;
49
+ this.changed = false;
50
+ this.active = false;
51
+ this.index = 0;
52
+ this.entryCount = 0;
53
+ this.oldElementValue = this.element.value;
54
+
55
+ if(this.setOptions)
56
+ this.setOptions(options);
57
+ else
58
+ this.options = options || { };
59
+
60
+ this.options.paramName = this.options.paramName || this.element.name;
61
+ this.options.tokens = this.options.tokens || [];
62
+ this.options.frequency = this.options.frequency || 0.4;
63
+ this.options.minChars = this.options.minChars != undefined ? this.options.minChars : 1;
64
+ this.options.onShow = this.options.onShow ||
65
+ function(element, update){
66
+ if(!update.style.position || update.style.position=='absolute') {
67
+ update.style.position = 'absolute';
68
+ Position.clone(element, update, {
69
+ setHeight: false,
70
+ offsetTop: element.offsetHeight
71
+ });
72
+ }
73
+ Effect.Appear(update,{duration:0.15});
74
+ };
75
+ this.options.onHide = this.options.onHide ||
76
+ function(element, update){ new Effect.Fade(update,{duration:0.15}) };
77
+
78
+ if(typeof(this.options.tokens) == 'string')
79
+ this.options.tokens = new Array(this.options.tokens);
80
+ // Force carriage returns as token delimiters anyway
81
+ if (!this.options.tokens.include('\n'))
82
+ this.options.tokens.push('\n');
83
+
84
+ this.observer = null;
85
+
86
+ this.element.setAttribute('autocomplete','off');
87
+
88
+ Element.hide(this.update);
89
+
90
+ Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this));
91
+ Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this));
92
+ var _this = this;
93
+ Event.observe(document, 'mousedown', function(event) {
94
+ var dim = _this.update.getDimensions();
95
+ var off = _this.update.cumulativeOffset();
96
+ _this.undoBlur = (event.pageX >= off[0] &&
97
+ event.pageX <= off[0]+dim.width &&
98
+ event.pageY >= off[1] &&
99
+ event.pageY <= off[1]+dim.height);
100
+ });
101
+ },
102
+
103
+ show: function() {
104
+ if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
105
+ if(!this.iefix &&
106
+ (Prototype.Browser.IE) &&
107
+ (Element.getStyle(this.update, 'position')=='absolute')) {
108
+ new Insertion.After(this.update,
109
+ '<iframe id="' + this.update.id + '_iefix" '+
110
+ 'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
111
+ 'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
112
+ this.iefix = $(this.update.id+'_iefix');
113
+ }
114
+ if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
115
+ },
116
+
117
+ fixIEOverlapping: function() {
118
+ Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
119
+ this.iefix.style.zIndex = 1;
120
+ this.update.style.zIndex = 2;
121
+ Element.show(this.iefix);
122
+ },
123
+
124
+ hide: function() {
125
+ this.stopIndicator();
126
+ if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update);
127
+ if(this.iefix) Element.hide(this.iefix);
128
+ },
129
+
130
+ startIndicator: function() {
131
+ if(this.options.indicator) Element.show(this.options.indicator);
132
+ },
133
+
134
+ stopIndicator: function() {
135
+ if(this.options.indicator) Element.hide(this.options.indicator);
136
+ },
137
+
138
+ onKeyPress: function(event) {
139
+ if(this.active)
140
+ switch(event.keyCode) {
141
+ case Event.KEY_TAB:
142
+ case Event.KEY_RETURN:
143
+ this.selectEntry();
144
+ Event.stop(event);
145
+ case Event.KEY_ESC:
146
+ this.hide();
147
+ this.active = false;
148
+ Event.stop(event);
149
+ return;
150
+ case Event.KEY_LEFT:
151
+ case Event.KEY_RIGHT:
152
+ return;
153
+ case Event.KEY_UP:
154
+ this.markPrevious();
155
+ this.render();
156
+ Event.stop(event);
157
+ return;
158
+ case Event.KEY_DOWN:
159
+ this.markNext();
160
+ this.render();
161
+ Event.stop(event);
162
+ return;
163
+ }
164
+ else
165
+ if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
166
+ (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
167
+
168
+ this.changed = true;
169
+ this.hasFocus = true;
170
+
171
+ if(this.observer) clearTimeout(this.observer);
172
+ this.observer =
173
+ setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
174
+ },
175
+
176
+ activate: function() {
177
+ this.changed = false;
178
+ this.hasFocus = true;
179
+ this.getUpdatedChoices();
180
+ },
181
+
182
+ onHover: function(event) {
183
+ var element = Event.findElement(event, 'LI');
184
+ if(this.index != element.autocompleteIndex)
185
+ {
186
+ this.index = element.autocompleteIndex;
187
+ this.render();
188
+ }
189
+ Event.stop(event);
190
+ },
191
+
192
+ onClick: function(event) {
193
+ var element = Event.findElement(event, 'LI');
194
+ this.index = element.autocompleteIndex;
195
+ this.selectEntry();
196
+ this.hide();
197
+ },
198
+
199
+ onBlur: function(event) {
200
+ if (this.undoBlur) {
201
+ this.undoBlur = false;
202
+ this.element.focus();
203
+ }
204
+ else {
205
+ // needed to make click events working
206
+ setTimeout(this.hide.bind(this), 250);
207
+ this.hasFocus = false;
208
+ this.active = false;
209
+ }
210
+ },
211
+
212
+ render: function() {
213
+ if(this.entryCount > 0) {
214
+ for (var i = 0; i < this.entryCount; i++)
215
+ this.index==i ?
216
+ Element.addClassName(this.getEntry(i),"selected") :
217
+ Element.removeClassName(this.getEntry(i),"selected");
218
+ if(this.hasFocus) {
219
+ this.show();
220
+ this.active = true;
221
+ }
222
+ } else {
223
+ this.active = false;
224
+ this.hide();
225
+ }
226
+ },
227
+
228
+ markPrevious: function() {
229
+ if(this.index > 0) this.index--;
230
+ else this.index = this.entryCount-1;
231
+ this.moveHighlight('up');
232
+ },
233
+
234
+ markNext: function() {
235
+ if(this.index < this.entryCount-1) this.index++;
236
+ else this.index = 0;
237
+ this.moveHighlight('down');
238
+ },
239
+
240
+ moveHighlight: function(direction) {
241
+ var updatescroll = this.update.scrollTop;
242
+ var updateheight = Element.getDimensions(this.update).height;
243
+ var entryy = Position.positionedOffset(this.getEntry(this.index))[1];
244
+ var entryheight = Element.getDimensions(this.getEntry(this.index)).height;
245
+ if (((updatescroll + updateheight) < (entryy + entryheight)) || (entryy < updatescroll)) {
246
+ var newy = (direction == 'up') ? entryy : entryy - updateheight + entryheight;
247
+ this.update.scrollTop = newy;
248
+ }
249
+ },
250
+
251
+ getEntry: function(index) {
252
+ return this.update.firstChild.childNodes[index];
253
+ },
254
+
255
+ getCurrentEntry: function() {
256
+ return this.getEntry(this.index);
257
+ },
258
+
259
+ selectEntry: function() {
260
+ this.active = false;
261
+ this.updateElement(this.getCurrentEntry());
262
+ },
263
+
264
+ updateElement: function(selectedElement) {
265
+ if (this.options.updateElement) {
266
+ this.options.updateElement(selectedElement);
267
+ return;
268
+ }
269
+ var value = '';
270
+ if (this.options.select) {
271
+ var nodes = $(selectedElement).select('.' + this.options.select) || [];
272
+ if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
273
+ } else
274
+ value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
275
+
276
+ var bounds = this.getTokenBounds();
277
+ if (bounds[0] != -1) {
278
+ var newValue = this.element.value.substr(0, bounds[0]);
279
+ var whitespace = this.element.value.substr(bounds[0]).match(/^\s+/);
280
+ if (whitespace)
281
+ newValue += whitespace[0];
282
+ this.element.value = newValue + value + this.element.value.substr(bounds[1]);
283
+ } else {
284
+ this.element.value = value;
285
+ }
286
+ this.oldElementValue = this.element.value;
287
+ this.element.focus();
288
+
289
+ if (this.options.afterUpdateElement)
290
+ this.options.afterUpdateElement(this.element, selectedElement);
291
+ },
292
+
293
+ updateChoices: function(choices) {
294
+ if(!this.changed && this.hasFocus) {
295
+ this.update.innerHTML = choices;
296
+ Element.cleanWhitespace(this.update);
297
+ Element.cleanWhitespace(this.update.down());
298
+
299
+ if(this.update.firstChild && this.update.down().childNodes) {
300
+ this.entryCount =
301
+ this.update.down().childNodes.length;
302
+ for (var i = 0; i < this.entryCount; i++) {
303
+ var entry = this.getEntry(i);
304
+ entry.autocompleteIndex = i;
305
+ this.addObservers(entry);
306
+ }
307
+ } else {
308
+ this.entryCount = 0;
309
+ }
310
+
311
+ this.stopIndicator();
312
+ this.index = 0;
313
+
314
+ if(this.entryCount==1 && this.options.autoSelect) {
315
+ this.selectEntry();
316
+ this.hide();
317
+ } else {
318
+ this.render();
319
+ }
320
+ }
321
+ },
322
+
323
+ addObservers: function(element) {
324
+ Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
325
+ Event.observe(element, "click", this.onClick.bindAsEventListener(this));
326
+ },
327
+
328
+ onObserverEvent: function() {
329
+ this.changed = false;
330
+ this.tokenBounds = null;
331
+ if(this.getToken().length>=this.options.minChars) {
332
+ this.getUpdatedChoices();
333
+ } else {
334
+ this.active = false;
335
+ this.hide();
336
+ }
337
+ this.oldElementValue = this.element.value;
338
+ },
339
+
340
+ getToken: function() {
341
+ var bounds = this.getTokenBounds();
342
+ return this.element.value.substring(bounds[0], bounds[1]).strip();
343
+ },
344
+
345
+ getTokenBounds: function() {
346
+ if (null != this.tokenBounds) return this.tokenBounds;
347
+ var value = this.element.value;
348
+ if (value.strip().empty()) return [-1, 0];
349
+ var diff = arguments.callee.getFirstDifferencePos(value, this.oldElementValue);
350
+ var offset = (diff == this.oldElementValue.length ? 1 : 0);
351
+ var prevTokenPos = -1, nextTokenPos = value.length;
352
+ var tp;
353
+ for (var index = 0, l = this.options.tokens.length; index < l; ++index) {
354
+ tp = value.lastIndexOf(this.options.tokens[index], diff + offset - 1);
355
+ if (tp > prevTokenPos) prevTokenPos = tp;
356
+ tp = value.indexOf(this.options.tokens[index], diff + offset);
357
+ if (-1 != tp && tp < nextTokenPos) nextTokenPos = tp;
358
+ }
359
+ return (this.tokenBounds = [prevTokenPos + 1, nextTokenPos]);
360
+ }
361
+ });
362
+
363
+ Autocompleter.Base.prototype.getTokenBounds.getFirstDifferencePos = function(newS, oldS) {
364
+ var boundary = Math.min(newS.length, oldS.length);
365
+ for (var index = 0; index < boundary; ++index)
366
+ if (newS[index] != oldS[index])
367
+ return index;
368
+ return boundary;
369
+ };
370
+
371
+ Ajax.Autocompleter = Class.create(Autocompleter.Base, {
372
+ initialize: function(element, update, url, options) {
373
+ this.baseInitialize(element, update, options);
374
+ this.options.asynchronous = true;
375
+ this.options.onComplete = this.onComplete.bind(this);
376
+ this.options.defaultParams = this.options.parameters || null;
377
+ this.url = url;
378
+ },
379
+
380
+ getUpdatedChoices: function() {
381
+ this.startIndicator();
382
+
383
+ var entry = encodeURIComponent(this.options.paramName) + '=' +
384
+ encodeURIComponent(this.getToken());
385
+
386
+ this.options.parameters = this.options.callback ?
387
+ this.options.callback(this.element, entry) : entry;
388
+
389
+ if(this.options.defaultParams)
390
+ this.options.parameters += '&' + this.options.defaultParams;
391
+
392
+ new Ajax.Request(this.url, this.options);
393
+ },
394
+
395
+ onComplete: function(request) {
396
+ this.updateChoices(request.responseText);
397
+ }
398
+ });
399
+
400
+ // The local array autocompleter. Used when you'd prefer to
401
+ // inject an array of autocompletion options into the page, rather
402
+ // than sending out Ajax queries, which can be quite slow sometimes.
403
+ //
404
+ // The constructor takes four parameters. The first two are, as usual,
405
+ // the id of the monitored textbox, and id of the autocompletion menu.
406
+ // The third is the array you want to autocomplete from, and the fourth
407
+ // is the options block.
408
+ //
409
+ // Extra local autocompletion options:
410
+ // - choices - How many autocompletion choices to offer
411
+ //
412
+ // - partialSearch - If false, the autocompleter will match entered
413
+ // text only at the beginning of strings in the
414
+ // autocomplete array. Defaults to true, which will
415
+ // match text at the beginning of any *word* in the
416
+ // strings in the autocomplete array. If you want to
417
+ // search anywhere in the string, additionally set
418
+ // the option fullSearch to true (default: off).
419
+ //
420
+ // - fullSsearch - Search anywhere in autocomplete array strings.
421
+ //
422
+ // - partialChars - How many characters to enter before triggering
423
+ // a partial match (unlike minChars, which defines
424
+ // how many characters are required to do any match
425
+ // at all). Defaults to 2.
426
+ //
427
+ // - ignoreCase - Whether to ignore case when autocompleting.
428
+ // Defaults to true.
429
+ //
430
+ // It's possible to pass in a custom function as the 'selector'
431
+ // option, if you prefer to write your own autocompletion logic.
432
+ // In that case, the other options above will not apply unless
433
+ // you support them.
434
+
435
+ Autocompleter.Local = Class.create(Autocompleter.Base, {
436
+ initialize: function(element, update, array, options) {
437
+ this.baseInitialize(element, update, options);
438
+ this.options.array = array;
439
+ },
440
+
441
+ getUpdatedChoices: function() {
442
+ this.updateChoices(this.options.selector(this));
443
+ },
444
+
445
+ setOptions: function(options) {
446
+ this.options = Object.extend({
447
+ choices: 10,
448
+ partialSearch: true,
449
+ partialChars: 2,
450
+ ignoreCase: true,
451
+ fullSearch: false,
452
+ selector: function(instance) {
453
+ var ret = []; // Beginning matches
454
+ var partial = []; // Inside matches
455
+ var entry = instance.getToken();
456
+ var count = 0;
457
+
458
+ for (var i = 0; i < instance.options.array.length &&
459
+ ret.length < instance.options.choices ; i++) {
460
+
461
+ var elem = instance.options.array[i];
462
+ var foundPos = instance.options.ignoreCase ?
463
+ elem.toLowerCase().indexOf(entry.toLowerCase()) :
464
+ elem.indexOf(entry);
465
+
466
+ while (foundPos != -1) {
467
+ if (foundPos == 0 && elem.length != entry.length) {
468
+ ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
469
+ elem.substr(entry.length) + "</li>");
470
+ break;
471
+ } else if (entry.length >= instance.options.partialChars &&
472
+ instance.options.partialSearch && foundPos != -1) {
473
+ if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
474
+ partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
475
+ elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
476
+ foundPos + entry.length) + "</li>");
477
+ break;
478
+ }
479
+ }
480
+
481
+ foundPos = instance.options.ignoreCase ?
482
+ elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
483
+ elem.indexOf(entry, foundPos + 1);
484
+
485
+ }
486
+ }
487
+ if (partial.length)
488
+ ret = ret.concat(partial.slice(0, instance.options.choices - ret.length));
489
+ return "<ul>" + ret.join('') + "</ul>";
490
+ }
491
+ }, options || { });
492
+ }
493
+ });
494
+
495
+ // AJAX in-place editor and collection editor
496
+ // Full rewrite by Christophe Porteneuve <tdd@tddsworld.com> (April 2007).
497
+
498
+ // Use this if you notice weird scrolling problems on some browsers,
499
+ // the DOM might be a bit confused when this gets called so do this
500
+ // waits 1 ms (with setTimeout) until it does the activation
501
+ Field.scrollFreeActivate = function(field) {
502
+ setTimeout(function() {
503
+ Field.activate(field);
504
+ }, 1);
505
+ };
506
+
507
+ Ajax.InPlaceEditor = Class.create({
508
+ initialize: function(element, url, options) {
509
+ this.url = url;
510
+ this.element = element = $(element);
511
+ this.prepareOptions();
512
+ this._controls = { };
513
+ arguments.callee.dealWithDeprecatedOptions(options); // DEPRECATION LAYER!!!
514
+ Object.extend(this.options, options || { });
515
+ if (!this.options.formId && this.element.id) {
516
+ this.options.formId = this.element.id + '-inplaceeditor';
517
+ if ($(this.options.formId))
518
+ this.options.formId = '';
519
+ }
520
+ if (this.options.externalControl)
521
+ this.options.externalControl = $(this.options.externalControl);
522
+ if (!this.options.externalControl)
523
+ this.options.externalControlOnly = false;
524
+ this._originalBackground = this.element.getStyle('background-color') || 'transparent';
525
+ this.element.title = this.options.clickToEditText;
526
+ this._boundCancelHandler = this.handleFormCancellation.bind(this);
527
+ this._boundComplete = (this.options.onComplete || Prototype.emptyFunction).bind(this);
528
+ this._boundFailureHandler = this.handleAJAXFailure.bind(this);
529
+ this._boundSubmitHandler = this.handleFormSubmission.bind(this);
530
+ this._boundWrapperHandler = this.wrapUp.bind(this);
531
+ this.registerListeners();
532
+ },
533
+ checkForEscapeOrReturn: function(e) {
534
+ if (!this._editing || e.ctrlKey || e.altKey || e.shiftKey) return;
535
+ if (Event.KEY_ESC == e.keyCode)
536
+ this.handleFormCancellation(e);
537
+ else if (Event.KEY_RETURN == e.keyCode)
538
+ this.handleFormSubmission(e);
539
+ },
540
+ createControl: function(mode, handler, extraClasses) {
541
+ var control = this.options[mode + 'Control'];
542
+ var text = this.options[mode + 'Text'];
543
+ if ('button' == control) {
544
+ var btn = document.createElement('input');
545
+ btn.type = 'submit';
546
+ btn.value = text;
547
+ btn.className = 'editor_' + mode + '_button';
548
+ if ('cancel' == mode)
549
+ btn.onclick = this._boundCancelHandler;
550
+ this._form.appendChild(btn);
551
+ this._controls[mode] = btn;
552
+ } else if ('link' == control) {
553
+ var link = document.createElement('a');
554
+ link.href = '#';
555
+ link.appendChild(document.createTextNode(text));
556
+ link.onclick = 'cancel' == mode ? this._boundCancelHandler : this._boundSubmitHandler;
557
+ link.className = 'editor_' + mode + '_link';
558
+ if (extraClasses)
559
+ link.className += ' ' + extraClasses;
560
+ this._form.appendChild(link);
561
+ this._controls[mode] = link;
562
+ }
563
+ },
564
+ createEditField: function() {
565
+ var text = (this.options.loadTextURL ? this.options.loadingText : this.getText());
566
+ var fld;
567
+ if (1 >= this.options.rows && !/\r|\n/.test(this.getText())) {
568
+ fld = document.createElement('input');
569
+ fld.type = 'text';
570
+ var size = this.options.size || this.options.cols || 0;
571
+ if (0 < size) fld.size = size;
572
+ } else {
573
+ fld = document.createElement('textarea');
574
+ fld.rows = (1 >= this.options.rows ? this.options.autoRows : this.options.rows);
575
+ fld.cols = this.options.cols || 40;
576
+ }
577
+ fld.name = this.options.paramName;
578
+ fld.value = text; // No HTML breaks conversion anymore
579
+ fld.className = 'editor_field';
580
+ if (this.options.submitOnBlur)
581
+ fld.onblur = this._boundSubmitHandler;
582
+ this._controls.editor = fld;
583
+ if (this.options.loadTextURL)
584
+ this.loadExternalText();
585
+ this._form.appendChild(this._controls.editor);
586
+ },
587
+ createForm: function() {
588
+ var ipe = this;
589
+ function addText(mode, condition) {
590
+ var text = ipe.options['text' + mode + 'Controls'];
591
+ if (!text || condition === false) return;
592
+ ipe._form.appendChild(document.createTextNode(text));
593
+ };
594
+ this._form = $(document.createElement('form'));
595
+ this._form.id = this.options.formId;
596
+ this._form.addClassName(this.options.formClassName);
597
+ this._form.onsubmit = this._boundSubmitHandler;
598
+ this.createEditField();
599
+ if ('textarea' == this._controls.editor.tagName.toLowerCase())
600
+ this._form.appendChild(document.createElement('br'));
601
+ if (this.options.onFormCustomization)
602
+ this.options.onFormCustomization(this, this._form);
603
+ addText('Before', this.options.okControl || this.options.cancelControl);
604
+ this.createControl('ok', this._boundSubmitHandler);
605
+ addText('Between', this.options.okControl && this.options.cancelControl);
606
+ this.createControl('cancel', this._boundCancelHandler, 'editor_cancel');
607
+ addText('After', this.options.okControl || this.options.cancelControl);
608
+ },
609
+ destroy: function() {
610
+ if (this._oldInnerHTML)
611
+ this.element.innerHTML = this._oldInnerHTML;
612
+ this.leaveEditMode();
613
+ this.unregisterListeners();
614
+ },
615
+ enterEditMode: function(e) {
616
+ if (this._saving || this._editing) return;
617
+ this._editing = true;
618
+ this.triggerCallback('onEnterEditMode');
619
+ if (this.options.externalControl)
620
+ this.options.externalControl.hide();
621
+ this.element.hide();
622
+ this.createForm();
623
+ this.element.parentNode.insertBefore(this._form, this.element);
624
+ if (!this.options.loadTextURL)
625
+ this.postProcessEditField();
626
+ if (e) Event.stop(e);
627
+ },
628
+ enterHover: function(e) {
629
+ if (this.options.hoverClassName)
630
+ this.element.addClassName(this.options.hoverClassName);
631
+ if (this._saving) return;
632
+ this.triggerCallback('onEnterHover');
633
+ },
634
+ getText: function() {
635
+ return this.element.innerHTML.unescapeHTML();
636
+ },
637
+ handleAJAXFailure: function(transport) {
638
+ this.triggerCallback('onFailure', transport);
639
+ if (this._oldInnerHTML) {
640
+ this.element.innerHTML = this._oldInnerHTML;
641
+ this._oldInnerHTML = null;
642
+ }
643
+ },
644
+ handleFormCancellation: function(e) {
645
+ this.wrapUp();
646
+ if (e) Event.stop(e);
647
+ },
648
+ handleFormSubmission: function(e) {
649
+ var form = this._form;
650
+ var value = $F(this._controls.editor);
651
+ this.prepareSubmission();
652
+ var params = this.options.callback(form, value) || '';
653
+ if (Object.isString(params))
654
+ params = params.toQueryParams();
655
+ params.editorId = this.element.id;
656
+ if (this.options.htmlResponse) {
657
+ var options = Object.extend({ evalScripts: true }, this.options.ajaxOptions);
658
+ Object.extend(options, {
659
+ parameters: params,
660
+ onComplete: this._boundWrapperHandler,
661
+ onFailure: this._boundFailureHandler
662
+ });
663
+ new Ajax.Updater({ success: this.element }, this.url, options);
664
+ } else {
665
+ var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
666
+ Object.extend(options, {
667
+ parameters: params,
668
+ onComplete: this._boundWrapperHandler,
669
+ onFailure: this._boundFailureHandler
670
+ });
671
+ new Ajax.Request(this.url, options);
672
+ }
673
+ if (e) Event.stop(e);
674
+ },
675
+ leaveEditMode: function() {
676
+ this.element.removeClassName(this.options.savingClassName);
677
+ this.removeForm();
678
+ this.leaveHover();
679
+ this.element.style.backgroundColor = this._originalBackground;
680
+ this.element.show();
681
+ if (this.options.externalControl)
682
+ this.options.externalControl.show();
683
+ this._saving = false;
684
+ this._editing = false;
685
+ this._oldInnerHTML = null;
686
+ this.triggerCallback('onLeaveEditMode');
687
+ },
688
+ leaveHover: function(e) {
689
+ if (this.options.hoverClassName)
690
+ this.element.removeClassName(this.options.hoverClassName);
691
+ if (this._saving) return;
692
+ this.triggerCallback('onLeaveHover');
693
+ },
694
+ loadExternalText: function() {
695
+ this._form.addClassName(this.options.loadingClassName);
696
+ this._controls.editor.disabled = true;
697
+ var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
698
+ Object.extend(options, {
699
+ parameters: 'editorId=' + encodeURIComponent(this.element.id),
700
+ onComplete: Prototype.emptyFunction,
701
+ onSuccess: function(transport) {
702
+ this._form.removeClassName(this.options.loadingClassName);
703
+ var text = transport.responseText;
704
+ if (this.options.stripLoadedTextTags)
705
+ text = text.stripTags();
706
+ this._controls.editor.value = text;
707
+ this._controls.editor.disabled = false;
708
+ this.postProcessEditField();
709
+ }.bind(this),
710
+ onFailure: this._boundFailureHandler
711
+ });
712
+ new Ajax.Request(this.options.loadTextURL, options);
713
+ },
714
+ postProcessEditField: function() {
715
+ var fpc = this.options.fieldPostCreation;
716
+ if (fpc)
717
+ $(this._controls.editor)['focus' == fpc ? 'focus' : 'activate']();
718
+ },
719
+ prepareOptions: function() {
720
+ this.options = Object.clone(Ajax.InPlaceEditor.DefaultOptions);
721
+ Object.extend(this.options, Ajax.InPlaceEditor.DefaultCallbacks);
722
+ [this._extraDefaultOptions].flatten().compact().each(function(defs) {
723
+ Object.extend(this.options, defs);
724
+ }.bind(this));
725
+ },
726
+ prepareSubmission: function() {
727
+ this._saving = true;
728
+ this.removeForm();
729
+ this.leaveHover();
730
+ this.showSaving();
731
+ },
732
+ registerListeners: function() {
733
+ this._listeners = { };
734
+ var listener;
735
+ $H(Ajax.InPlaceEditor.Listeners).each(function(pair) {
736
+ listener = this[pair.value].bind(this);
737
+ this._listeners[pair.key] = listener;
738
+ if (!this.options.externalControlOnly)
739
+ this.element.observe(pair.key, listener);
740
+ if (this.options.externalControl)
741
+ this.options.externalControl.observe(pair.key, listener);
742
+ }.bind(this));
743
+ },
744
+ removeForm: function() {
745
+ if (!this._form) return;
746
+ this._form.remove();
747
+ this._form = null;
748
+ this._controls = { };
749
+ },
750
+ showSaving: function() {
751
+ this._oldInnerHTML = this.element.innerHTML;
752
+ this.element.innerHTML = this.options.savingText;
753
+ this.element.addClassName(this.options.savingClassName);
754
+ this.element.style.backgroundColor = this._originalBackground;
755
+ this.element.show();
756
+ },
757
+ triggerCallback: function(cbName, arg) {
758
+ if ('function' == typeof this.options[cbName]) {
759
+ this.options[cbName](this, arg);
760
+ }
761
+ },
762
+ unregisterListeners: function() {
763
+ $H(this._listeners).each(function(pair) {
764
+ if (!this.options.externalControlOnly)
765
+ this.element.stopObserving(pair.key, pair.value);
766
+ if (this.options.externalControl)
767
+ this.options.externalControl.stopObserving(pair.key, pair.value);
768
+ }.bind(this));
769
+ },
770
+ wrapUp: function(transport) {
771
+ this.leaveEditMode();
772
+ // Can't use triggerCallback due to backward compatibility: requires
773
+ // binding + direct element
774
+ this._boundComplete(transport, this.element);
775
+ }
776
+ });
777
+
778
+ Object.extend(Ajax.InPlaceEditor.prototype, {
779
+ dispose: Ajax.InPlaceEditor.prototype.destroy
780
+ });
781
+
782
+ Ajax.InPlaceCollectionEditor = Class.create(Ajax.InPlaceEditor, {
783
+ initialize: function($super, element, url, options) {
784
+ this._extraDefaultOptions = Ajax.InPlaceCollectionEditor.DefaultOptions;
785
+ $super(element, url, options);
786
+ },
787
+
788
+ createEditField: function() {
789
+ var list = document.createElement('select');
790
+ list.name = this.options.paramName;
791
+ list.size = 1;
792
+ this._controls.editor = list;
793
+ this._collection = this.options.collection || [];
794
+ if (this.options.loadCollectionURL)
795
+ this.loadCollection();
796
+ else
797
+ this.checkForExternalText();
798
+ this._form.appendChild(this._controls.editor);
799
+ },
800
+
801
+ loadCollection: function() {
802
+ this._form.addClassName(this.options.loadingClassName);
803
+ this.showLoadingText(this.options.loadingCollectionText);
804
+ var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
805
+ Object.extend(options, {
806
+ parameters: 'editorId=' + encodeURIComponent(this.element.id),
807
+ onComplete: Prototype.emptyFunction,
808
+ onSuccess: function(transport) {
809
+ var js = transport.responseText.strip();
810
+ if (!/^\[.*\]$/.test(js)) // TODO: improve sanity check
811
+ throw('Server returned an invalid collection representation.');
812
+ this._collection = eval(js);
813
+ this.checkForExternalText();
814
+ }.bind(this),
815
+ onFailure: this.onFailure
816
+ });
817
+ new Ajax.Request(this.options.loadCollectionURL, options);
818
+ },
819
+
820
+ showLoadingText: function(text) {
821
+ this._controls.editor.disabled = true;
822
+ var tempOption = this._controls.editor.firstChild;
823
+ if (!tempOption) {
824
+ tempOption = document.createElement('option');
825
+ tempOption.value = '';
826
+ this._controls.editor.appendChild(tempOption);
827
+ tempOption.selected = true;
828
+ }
829
+ tempOption.update((text || '').stripScripts().stripTags());
830
+ },
831
+
832
+ checkForExternalText: function() {
833
+ this._text = this.getText();
834
+ if (this.options.loadTextURL)
835
+ this.loadExternalText();
836
+ else
837
+ this.buildOptionList();
838
+ },
839
+
840
+ loadExternalText: function() {
841
+ this.showLoadingText(this.options.loadingText);
842
+ var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
843
+ Object.extend(options, {
844
+ parameters: 'editorId=' + encodeURIComponent(this.element.id),
845
+ onComplete: Prototype.emptyFunction,
846
+ onSuccess: function(transport) {
847
+ this._text = transport.responseText.strip();
848
+ this.buildOptionList();
849
+ }.bind(this),
850
+ onFailure: this.onFailure
851
+ });
852
+ new Ajax.Request(this.options.loadTextURL, options);
853
+ },
854
+
855
+ buildOptionList: function() {
856
+ this._form.removeClassName(this.options.loadingClassName);
857
+ this._collection = this._collection.map(function(entry) {
858
+ return 2 === entry.length ? entry : [entry, entry].flatten();
859
+ });
860
+ var marker = ('value' in this.options) ? this.options.value : this._text;
861
+ var textFound = this._collection.any(function(entry) {
862
+ return entry[0] == marker;
863
+ }.bind(this));
864
+ this._controls.editor.update('');
865
+ var option;
866
+ this._collection.each(function(entry, index) {
867
+ option = document.createElement('option');
868
+ option.value = entry[0];
869
+ option.selected = textFound ? entry[0] == marker : 0 == index;
870
+ option.appendChild(document.createTextNode(entry[1]));
871
+ this._controls.editor.appendChild(option);
872
+ }.bind(this));
873
+ this._controls.editor.disabled = false;
874
+ Field.scrollFreeActivate(this._controls.editor);
875
+ }
876
+ });
877
+
878
+ //**** DEPRECATION LAYER FOR InPlace[Collection]Editor! ****
879
+ //**** This only exists for a while, in order to let ****
880
+ //**** users adapt to the new API. Read up on the new ****
881
+ //**** API and convert your code to it ASAP! ****
882
+
883
+ Ajax.InPlaceEditor.prototype.initialize.dealWithDeprecatedOptions = function(options) {
884
+ if (!options) return;
885
+ function fallback(name, expr) {
886
+ if (name in options || expr === undefined) return;
887
+ options[name] = expr;
888
+ };
889
+ fallback('cancelControl', (options.cancelLink ? 'link' : (options.cancelButton ? 'button' :
890
+ options.cancelLink == options.cancelButton == false ? false : undefined)));
891
+ fallback('okControl', (options.okLink ? 'link' : (options.okButton ? 'button' :
892
+ options.okLink == options.okButton == false ? false : undefined)));
893
+ fallback('highlightColor', options.highlightcolor);
894
+ fallback('highlightEndColor', options.highlightendcolor);
895
+ };
896
+
897
+ Object.extend(Ajax.InPlaceEditor, {
898
+ DefaultOptions: {
899
+ ajaxOptions: { },
900
+ autoRows: 3, // Use when multi-line w/ rows == 1
901
+ cancelControl: 'link', // 'link'|'button'|false
902
+ cancelText: 'cancel',
903
+ clickToEditText: 'Click to edit',
904
+ externalControl: null, // id|elt
905
+ externalControlOnly: false,
906
+ fieldPostCreation: 'activate', // 'activate'|'focus'|false
907
+ formClassName: 'inplaceeditor-form',
908
+ formId: null, // id|elt
909
+ highlightColor: '#ffff99',
910
+ highlightEndColor: '#ffffff',
911
+ hoverClassName: '',
912
+ htmlResponse: true,
913
+ loadingClassName: 'inplaceeditor-loading',
914
+ loadingText: 'Loading...',
915
+ okControl: 'button', // 'link'|'button'|false
916
+ okText: 'ok',
917
+ paramName: 'value',
918
+ rows: 1, // If 1 and multi-line, uses autoRows
919
+ savingClassName: 'inplaceeditor-saving',
920
+ savingText: 'Saving...',
921
+ size: 0,
922
+ stripLoadedTextTags: false,
923
+ submitOnBlur: false,
924
+ textAfterControls: '',
925
+ textBeforeControls: '',
926
+ textBetweenControls: ''
927
+ },
928
+ DefaultCallbacks: {
929
+ callback: function(form) {
930
+ return Form.serialize(form);
931
+ },
932
+ onComplete: function(transport, element) {
933
+ // For backward compatibility, this one is bound to the IPE, and passes
934
+ // the element directly. It was too often customized, so we don't break it.
935
+ new Effect.Highlight(element, {
936
+ startcolor: this.options.highlightColor, keepBackgroundImage: true });
937
+ },
938
+ onEnterEditMode: null,
939
+ onEnterHover: function(ipe) {
940
+ ipe.element.style.backgroundColor = ipe.options.highlightColor;
941
+ if (ipe._effect)
942
+ ipe._effect.cancel();
943
+ },
944
+ onFailure: function(transport, ipe) {
945
+ alert('Error communication with the server: ' + transport.responseText.stripTags());
946
+ },
947
+ onFormCustomization: null, // Takes the IPE and its generated form, after editor, before controls.
948
+ onLeaveEditMode: null,
949
+ onLeaveHover: function(ipe) {
950
+ ipe._effect = new Effect.Highlight(ipe.element, {
951
+ startcolor: ipe.options.highlightColor, endcolor: ipe.options.highlightEndColor,
952
+ restorecolor: ipe._originalBackground, keepBackgroundImage: true
953
+ });
954
+ }
955
+ },
956
+ Listeners: {
957
+ click: 'enterEditMode',
958
+ keydown: 'checkForEscapeOrReturn',
959
+ mouseover: 'enterHover',
960
+ mouseout: 'leaveHover'
961
+ }
962
+ });
963
+
964
+ Ajax.InPlaceCollectionEditor.DefaultOptions = {
965
+ loadingCollectionText: 'Loading options...'
966
+ };
967
+
968
+ // Delayed observer, like Form.Element.Observer,
969
+ // but waits for delay after last key input
970
+ // Ideal for live-search fields
971
+
972
+ Form.Element.DelayedObserver = Class.create({
973
+ initialize: function(element, delay, callback) {
974
+ this.delay = delay || 0.5;
975
+ this.element = $(element);
976
+ this.callback = callback;
977
+ this.timer = null;
978
+ this.lastValue = $F(this.element);
979
+ Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this));
980
+ },
981
+ delayedListener: function(event) {
982
+ if(this.lastValue == $F(this.element)) return;
983
+ if(this.timer) clearTimeout(this.timer);
984
+ this.timer = setTimeout(this.onTimerEvent.bind(this), this.delay * 1000);
985
+ this.lastValue = $F(this.element);
986
+ },
987
+ onTimerEvent: function() {
988
+ this.timer = null;
989
+ this.callback(this.element, $F(this.element));
990
+ }
991
+ });