hobo 1.3.3 → 1.4.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. data/{CHANGES.txt → CHANGES-1.3.txt} +0 -0
  2. data/CHANGES-1.4.txt +678 -0
  3. data/Rakefile +13 -3
  4. data/TODO-1.4.txt +69 -0
  5. data/VERSION +1 -1
  6. data/app/helpers/hobo_debug_helper.rb +16 -0
  7. data/app/helpers/hobo_deprecated_helper.rb +45 -0
  8. data/app/helpers/hobo_helper_base.rb +8 -0
  9. data/app/helpers/hobo_permissions_helper.rb +136 -0
  10. data/app/helpers/hobo_route_helper.rb +196 -0
  11. data/{lib/hobo/helper/translations.rb → app/helpers/hobo_translations_helper.rb} +4 -7
  12. data/{lib/hobo/helper/translations/normalizer.rb → app/helpers/hobo_translations_normalizer_helper.rb} +3 -10
  13. data/app/helpers/hobo_type_helper.rb +24 -0
  14. data/app/helpers/hobo_view_hint_helper.rb +13 -0
  15. data/hobo.gemspec +3 -3
  16. data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +0 -9
  17. data/lib/generators/hobo/admin_subsite/templates/application.dryml +2 -0
  18. data/lib/generators/hobo/admin_subsite/templates/gitkeep +0 -0
  19. data/lib/generators/hobo/admin_subsite/templates/site.css.erb +9 -0
  20. data/lib/generators/hobo/admin_subsite/templates/site.js.erb +10 -0
  21. data/lib/generators/hobo/assets/assets_generator.rb +16 -2
  22. data/lib/generators/hobo/assets/templates/application.css +9 -0
  23. data/lib/generators/hobo/assets/templates/application.dryml.erb +0 -5
  24. data/lib/generators/hobo/assets/templates/application.js +11 -0
  25. data/lib/generators/hobo/assets/templates/front.css +10 -0
  26. data/lib/generators/hobo/assets/templates/front.js +11 -0
  27. data/lib/generators/hobo/assets/templates/front_site.dryml.erb +6 -0
  28. data/lib/generators/hobo/assets/templates/gitkeep +0 -0
  29. data/lib/generators/hobo/dev_tweaks/dev_tweaks_generator.rb +31 -0
  30. data/lib/generators/hobo/i18n/templates/hobo.en.yml +1 -1
  31. data/lib/generators/hobo/install_plugin/USAGE +3 -0
  32. data/lib/generators/hobo/install_plugin/install_plugin_generator.rb +36 -0
  33. data/lib/generators/hobo/plugin.rb +112 -0
  34. data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +31 -14
  35. data/lib/generators/hobo/subsite.rb +16 -2
  36. data/lib/generators/hobo/subsite/templates/gitkeep +0 -0
  37. data/lib/generators/hobo/subsite/templates/site.css.erb +9 -0
  38. data/lib/generators/hobo/subsite/templates/site.js.erb +10 -0
  39. data/lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb +0 -17
  40. data/lib/generators/hobo/test_framework/test_framework_generator.rb +1 -1
  41. data/lib/hobo.rb +3 -2
  42. data/lib/hobo/controller.rb +43 -24
  43. data/lib/hobo/controller/model.rb +63 -42
  44. data/lib/hobo/controller/user_base.rb +1 -3
  45. data/lib/hobo/engine.rb +1 -1
  46. data/lib/hobo/extensions/active_record/associations/association.rb +36 -0
  47. data/lib/hobo/extensions/active_record/associations/collection.rb +10 -19
  48. data/lib/hobo/extensions/active_record/associations/proxy.rb +3 -15
  49. data/lib/hobo/extensions/active_record/associations/scope.rb +2 -2
  50. data/lib/hobo/extensions/active_record/permissions.rb +32 -38
  51. data/lib/hobo/extensions/active_record/relation_with_origin.rb +5 -5
  52. data/lib/hobo/model.rb +12 -7
  53. data/lib/hobo/model/accessible_associations.rb +8 -15
  54. data/lib/hobo/model/lifecycles/creator.rb +1 -1
  55. data/lib/hobo/model/lifecycles/transition.rb +1 -1
  56. data/lib/hobo/model/permissions.rb +4 -4
  57. data/lib/hobo/model/scopes.rb +4 -17
  58. data/lib/hobo/model/scopes/automatic_scopes.rb +5 -13
  59. data/lib/hobo/rapid/helper.rb +1 -161
  60. data/lib/hobo/rapid/taglibs/rapid.dryml +3 -17
  61. data/test/doctest/hobo/hobo_helper.rdoctest +8 -44
  62. data/{doctests → test/doctest}/hobo/lifecycles.rdoctest +0 -0
  63. data/{doctests → test/doctest}/hobo/model.rdoctest +2 -4
  64. data/{doctests → test/doctest}/hobo/multi_model_forms.rdoctest +3 -24
  65. data/{doctests → test/doctest}/hobo/scopes.rdoctest +3 -53
  66. data/test/doctest/prepare_testapp.rb +11 -0
  67. data/test/irt/generators/admin_subsite.irt +1 -19
  68. data/test/irt/generators/assets.irt +4 -9
  69. data/test/irt/generators/controller.irt +0 -3
  70. data/test/irt/generators/front_controller.irt +0 -5
  71. data/test/irt/generators/{helper.rb → irt_helper.rb} +2 -2
  72. data/test/irt/generators/model.irt +1 -12
  73. data/test/irt/generators/partials/_account_user_model_tests.rb +0 -8
  74. data/test/irt/generators/partials/_accounts_users_controller_tests.rb +0 -2
  75. data/test/irt/generators/partials/_default_user_model_tests.rb +0 -8
  76. data/test/irt/generators/partials/_default_users_controller_tests.rb +0 -2
  77. data/test/irt/generators/partials/_house_controller_tests.rb +0 -2
  78. data/test/irt/generators/partials/_house_model_tests.rb +1 -9
  79. data/test/irt/generators/partials/_subsite_taglib_admin.rb +5 -2
  80. data/test/irt/generators/partials/_subsite_taglib_admin_invite_only.rb +1 -1
  81. data/test/irt/generators/partials/_subsite_taglib_noopt.rb +2 -2
  82. data/test/irt/generators/partials/_subsite_taglib_variables.rb +0 -15
  83. data/test/irt/generators/partials/_user_mailer_tests.rb +1 -3
  84. data/test/irt/generators/resource.irt +0 -3
  85. data/test/irt/generators/subsite.irt +6 -22
  86. data/test/irt/generators/subsite_taglib.irt +0 -18
  87. data/test/irt/generators/test_framework.irt +2 -5
  88. data/test/irt/generators/user_controller.irt +0 -3
  89. data/test/irt/generators/user_mailer.irt +0 -3
  90. data/test/irt/generators/user_model.irt +0 -3
  91. data/test/irt/generators/user_resource.irt +0 -3
  92. data/test/irt/readme.txt +6 -3
  93. metadata +116 -159
  94. data/app/controllers/dev_controller.rb +0 -25
  95. data/app/views/dev/summary.dryml +0 -102
  96. data/doctests/prepare_testapp.rb +0 -8
  97. data/lib/generators/hobo/admin_subsite/templates/admin.css +0 -20
  98. data/lib/generators/hobo/rapid/USAGE +0 -3
  99. data/lib/generators/hobo/rapid/rapid_generator.rb +0 -24
  100. data/lib/generators/hobo/rapid/templates/IE7.js +0 -2
  101. data/lib/generators/hobo/rapid/templates/blank.gif +0 -0
  102. data/lib/generators/hobo/rapid/templates/hobo-rapid.css +0 -94
  103. data/lib/generators/hobo/rapid/templates/hobo-rapid.js +0 -1015
  104. data/lib/generators/hobo/rapid/templates/ie7-recalc.js +0 -166
  105. data/lib/generators/hobo/rapid/templates/lowpro.js +0 -339
  106. data/lib/generators/hobo/rapid/templates/reset.css +0 -95
  107. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/101-3B5F87-ACD3E6.png +0 -0
  108. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/30-3E547A-242E42.png +0 -0
  109. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/30-DBE1E5-FCFEF5.png +0 -0
  110. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/300-ACD3E6-fff.png +0 -0
  111. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/50-ACD3E6-fff.png +0 -0
  112. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/fieldbg.gif +0 -0
  113. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/pencil.png +0 -0
  114. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/small_close.png +0 -0
  115. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/spinner.gif +0 -0
  116. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/clean.css +0 -327
  117. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +0 -102
  118. data/lib/generators/hobo/rapid/templates/themes/clean/views/clean.dryml +0 -10
  119. data/lib/hobo/helper.rb +0 -460
  120. data/lib/hobo/rapid/taglibs/rapid_core.dryml +0 -808
  121. data/lib/hobo/rapid/taglibs/rapid_document_tags.dryml +0 -56
  122. data/lib/hobo/rapid/taglibs/rapid_editing.dryml +0 -287
  123. data/lib/hobo/rapid/taglibs/rapid_forms.dryml +0 -1156
  124. data/lib/hobo/rapid/taglibs/rapid_generics.dryml +0 -48
  125. data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +0 -173
  126. data/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml +0 -96
  127. data/lib/hobo/rapid/taglibs/rapid_navigation.dryml +0 -108
  128. data/lib/hobo/rapid/taglibs/rapid_pages.dryml +0 -259
  129. data/lib/hobo/rapid/taglibs/rapid_plus.dryml +0 -247
  130. data/lib/hobo/rapid/taglibs/rapid_summary.dryml +0 -283
  131. data/lib/hobo/rapid/taglibs/rapid_support.dryml +0 -102
  132. data/lib/hobo/rapid/taglibs/rapid_user_pages.dryml +0 -182
  133. data/test/irt/generators/rapid.irt +0 -29
@@ -1,166 +0,0 @@
1
-
2
- // =========================================================================
3
- // ie7-recalc.js
4
- // =========================================================================
5
-
6
- (function() {
7
- /* ---------------------------------------------------------------------
8
-
9
- This allows refreshing of IE7 style rules. If you modify the DOM
10
- you can update IE7 by calling document.recalc().
11
-
12
- This should be the LAST module included.
13
-
14
- --------------------------------------------------------------------- */
15
-
16
- if (!IE7.loaded) return;
17
-
18
- // remove all IE7 classes from an element
19
- CLASSES = /\sie7_class\d+/g;
20
-
21
- IE7.CSS.extend({
22
- // store for elements that have style properties calculated
23
- elements: {},
24
- handlers: [],
25
-
26
- // clear IE7 classes and styles
27
- reset: function() {
28
- this.removeEventHandlers();
29
- // reset IE7 classes here
30
- var elements = this.elements;
31
- for (var i in elements) elements[i].runtimeStyle.cssText = "";
32
- this.elements = {};
33
- // reset runtimeStyle here
34
- var elements = IE7.Rule.elements;
35
- for (var i in elements) {
36
- with (elements[i]) className = className.replace(CLASSES, "");
37
- }
38
- IE7.Rule.elements = {};
39
- },
40
-
41
- reload: function() {
42
- this.rules = [];
43
- this.getInlineStyles();
44
- this.screen.load();
45
- if (this.print) this.print.load();
46
- this.refresh();
47
- this.trash();
48
- },
49
-
50
- addRecalc: function(propertyName, test, handler, replacement) {
51
- // call the ancestor method to add a wrapped recalc method
52
- this.base(propertyName, test, function(element) {
53
- // execute the original recalc method
54
- handler(element);
55
- // store a reference to this element so we can clear its style later
56
- IE7.CSS.elements[element.uniqueID] = element;
57
- }, replacement);
58
- },
59
-
60
- recalc: function() {
61
- // clear IE7 styles and classes
62
- this.reset();
63
- // execute the ancestor method to perform recalculations
64
- this.base();
65
- },
66
-
67
- addEventHandler: function(element, type, handler) {
68
- element.attachEvent(type, handler);
69
- // store the handler so it can be detached later
70
- this.handlers.push(arguments);
71
- },
72
-
73
- removeEventHandlers: function() {
74
- var handler;
75
- while (handler = this.handlers.pop()) {
76
- handler[0].detachEvent(handler[1], handler[2]);
77
- }
78
- },
79
-
80
- getInlineStyles: function() {
81
- // load inline styles
82
- var styleSheets = document.getElementsByTagName("style"), styleSheet;
83
- for (var i = styleSheets.length - 1; (styleSheet = styleSheets[i]); i--) {
84
- if (!styleSheet.disabled && !styleSheet.ie7) {
85
- var cssText = styleSheet.cssText || styleSheet.innerHTML;
86
- this.styles.push(cssText);
87
- styleSheet.cssText = cssText;
88
- }
89
- }
90
- },
91
-
92
- trash: function() {
93
- // trash the old style sheets
94
- var styleSheets = document.styleSheets, styleSheet, i;
95
- for (i = 0; i < styleSheets.length; i++) {
96
- styleSheet = styleSheets[i];
97
- if (!styleSheet.ie7 && !styleSheet.cssText && styleSheet.cssText != '') {
98
- styleSheet.cssText = styleSheet.cssText;
99
- }
100
- }
101
- this.base();
102
- },
103
-
104
- getText: function(styleSheet) {
105
- return styleSheet.cssText || this.base(styleSheet);
106
- }
107
- });
108
-
109
- // remove event handlers (they eat memory)
110
- IE7.CSS.addEventHandler(window, "onunload", function() {
111
- IE7.CSS.removeEventHandlers();
112
- });
113
-
114
- // store all elements with an IE7 class assigned
115
- IE7.Rule.elements = {};
116
-
117
- IE7.Rule.prototype.extend({
118
- add: function(element) {
119
- // execute the ancestor "add" method
120
- this.base(element);
121
- // store a reference to this element so we can clear its classes later
122
- IE7.Rule.elements[element.uniqueID] = element;
123
- }
124
- });
125
-
126
- // store created pseudo elements
127
- if (IE7.PseudoElement) {
128
- IE7.PseudoElement.hash = {};
129
-
130
- IE7.PseudoElement.prototype.extend({
131
- create: function(target) {
132
- var key = this.selector + ":" + target.uniqueID;
133
- if (!IE7.PseudoElement.hash[key]) {
134
- IE7.PseudoElement.hash[key] = true;
135
- this.base(target);
136
- }
137
- }
138
- });
139
- }
140
-
141
- IE7.HTML.extend({
142
- elements: {},
143
-
144
- addRecalc: function(selector, handler) {
145
- // call the ancestor method to add a wrapped recalc method
146
- this.base(selector, function(element) {
147
- if (!this.elements[element.uniqueID]) {
148
- // execute the original recalc method
149
- handler(element);
150
- // store a reference to this element so that
151
- // it is not "fixed" again
152
- this.elements[element.uniqueID] = element;
153
- }
154
- });
155
- }
156
- });
157
-
158
- // allow refreshing of IE7 fixes
159
- document.recalc = function(reload) {
160
- if (IE7.CSS.screen) {
161
- if (reload) IE7.CSS.reload();
162
- IE7.recalc();
163
- }
164
- };
165
-
166
- })();
@@ -1,339 +0,0 @@
1
- LowPro = {};
2
- LowPro.Version = '0.5';
3
- LowPro.CompatibleWithPrototype = '1.6';
4
-
5
- if (Prototype.Version.indexOf(LowPro.CompatibleWithPrototype) != 0 && window.console && window.console.warn)
6
- console.warn("This version of Low Pro is tested with Prototype " + LowPro.CompatibleWithPrototype +
7
- " it may not work as expected with this version (" + Prototype.Version + ")");
8
-
9
- if (!Element.addMethods)
10
- Element.addMethods = function(o) { Object.extend(Element.Methods, o) };
11
-
12
- // Simple utility methods for working with the DOM
13
- DOM = {};
14
-
15
- // DOMBuilder for prototype
16
- DOM.Builder = {
17
- tagFunc : function(tag) {
18
- return function() {
19
- var attrs, children;
20
- if (arguments.length>0) {
21
- if (arguments[0].constructor == Object) {
22
- attrs = arguments[0];
23
- children = Array.prototype.slice.call(arguments, 1);
24
- } else {
25
- children = arguments;
26
- };
27
- children = $A(children).flatten()
28
- }
29
- return DOM.Builder.create(tag, attrs, children);
30
- };
31
- },
32
- create : function(tag, attrs, children) {
33
- attrs = attrs || {}; children = children || []; tag = tag.toLowerCase();
34
- var el = new Element(tag, attrs);
35
-
36
- for (var i=0; i<children.length; i++) {
37
- if (typeof children[i] == 'string')
38
- children[i] = document.createTextNode(children[i]);
39
- el.appendChild(children[i]);
40
- }
41
- return $(el);
42
- }
43
- };
44
-
45
- // Automatically create node builders as $tagName.
46
- (function() {
47
- var els = ("p|div|span|strong|em|img|table|tr|td|th|thead|tbody|tfoot|pre|code|" +
48
- "h1|h2|h3|h4|h5|h6|ul|ol|li|form|input|textarea|legend|fieldset|" +
49
- "select|option|blockquote|cite|br|hr|dd|dl|dt|address|a|button|abbr|acronym|" +
50
- "script|link|style|bdo|ins|del|object|param|col|colgroup|optgroup|caption|" +
51
- "label|dfn|kbd|samp|var").split("|");
52
- var el, i=0;
53
- while (el = els[i++])
54
- window['$' + el] = DOM.Builder.tagFunc(el);
55
- })();
56
-
57
- DOM.Builder.fromHTML = function(html) {
58
- var root;
59
- if (!(root = arguments.callee._root))
60
- root = arguments.callee._root = document.createElement('div');
61
- root.innerHTML = html;
62
- return root.childNodes[0];
63
- };
64
-
65
-
66
-
67
- // Wraps the 1.6 contentloaded event for backwards compatibility
68
- //
69
- // Usage:
70
- //
71
- // Event.onReady(callbackFunction);
72
- Object.extend(Event, {
73
- onReady : function(f) {
74
- if (document.body) f();
75
- else document.observe('dom:loaded', f);
76
- }
77
- });
78
-
79
- // Based on event:Selectors by Justin Palmer
80
- // http://encytemedia.com/event-selectors/
81
- //
82
- // Usage:
83
- //
84
- // Event.addBehavior({
85
- // "selector:event" : function(event) { /* event handler. this refers to the element. */ },
86
- // "selector" : function() { /* runs function on dom ready. this refers to the element. */ }
87
- // ...
88
- // });
89
- //
90
- // Multiple calls will add to exisiting rules. Event.addBehavior.reassignAfterAjax and
91
- // Event.addBehavior.autoTrigger can be adjusted to needs.
92
- Event.addBehavior = function(rules) {
93
- var ab = this.addBehavior;
94
- Object.extend(ab.rules, rules);
95
-
96
- if (!ab.responderApplied) {
97
- Ajax.Responders.register({
98
- onComplete : function() {
99
- if (Event.addBehavior.reassignAfterAjax)
100
- setTimeout(function() { ab.reload() }, 10);
101
- }
102
- });
103
- ab.responderApplied = true;
104
- }
105
-
106
- if (ab.autoTrigger) {
107
- this.onReady(ab.load.bind(ab, rules));
108
- }
109
-
110
- };
111
-
112
- Event.delegate = function(rules) {
113
- return function(e) {
114
- var element = $(e.element());
115
- for (var selector in rules)
116
- if (element.match(selector)) return rules[selector].apply(this, $A(arguments));
117
- }
118
- }
119
-
120
- Object.extend(Event.addBehavior, {
121
- rules : {}, cache : [],
122
- reassignAfterAjax : false,
123
- autoTrigger : true,
124
-
125
- load : function(rules) {
126
- for (var selector in rules) {
127
- var observer = rules[selector];
128
- var sels = selector.split(',');
129
- sels.each(function(sel) {
130
- var match = sel.match(/^([^:]*)(?::(.*)$)?/), css = match[1], event = match[2];
131
- $$(css).each(function(element) {
132
- if (event) {
133
- var wrappedObserver = Event.addBehavior._wrapObserver(observer);
134
- $(element).observe(event, wrappedObserver);
135
- Event.addBehavior.cache.push([element, event, wrappedObserver]);
136
- } else {
137
- if (!element.$$assigned || !element.$$assigned.include(observer)) {
138
- if (observer.attach) observer.attach(element);
139
-
140
- else observer.call($(element));
141
- element.$$assigned = element.$$assigned || [];
142
- element.$$assigned.push(observer);
143
- }
144
- }
145
- });
146
- });
147
- }
148
- },
149
-
150
- unload : function() {
151
- this.cache.each(function(c) {
152
- Event.stopObserving.apply(Event, c);
153
- });
154
- this.cache = [];
155
- },
156
-
157
- reload: function() {
158
- var ab = Event.addBehavior;
159
- ab.unload();
160
- ab.load(ab.rules);
161
- },
162
-
163
- _wrapObserver: function(observer) {
164
- return function(event) {
165
- if (observer.call(this, event) === false) event.stop();
166
- }
167
- }
168
-
169
- });
170
-
171
- Event.observe(window, 'unload', Event.addBehavior.unload.bind(Event.addBehavior));
172
-
173
- // A silly Prototype style shortcut for the reckless
174
- $$$ = Event.addBehavior.bind(Event);
175
-
176
- // Behaviors can be bound to elements to provide an object orientated way of controlling elements
177
- // and their behavior. Use Behavior.create() to make a new behavior class then use attach() to
178
- // glue it to an element. Each element then gets it's own instance of the behavior and any
179
- // methods called onxxx are bound to the relevent event.
180
- //
181
- // Usage:
182
- //
183
- // var MyBehavior = Behavior.create({
184
- // onmouseover : function() { this.element.addClassName('bong') }
185
- // });
186
- //
187
- // Event.addBehavior({ 'a.rollover' : MyBehavior });
188
- //
189
- // If you need to pass additional values to initialize use:
190
- //
191
- // Event.addBehavior({ 'a.rollover' : MyBehavior(10, { thing : 15 }) })
192
- //
193
- // You can also use the attach() method. If you specify extra arguments to attach they get passed to initialize.
194
- //
195
- // MyBehavior.attach(el, values, to, init);
196
- //
197
- // Finally, the rawest method is using the new constructor normally:
198
- // var draggable = new Draggable(element, init, vals);
199
- //
200
- // Each behaviour has a collection of all its instances in Behavior.instances
201
- //
202
- var Behavior = {
203
- create: function() {
204
- var parent = null, properties = $A(arguments);
205
- if (Object.isFunction(properties[0]))
206
- parent = properties.shift();
207
-
208
- var behavior = function() {
209
- if (!this.initialize) {
210
- var args = $A(arguments);
211
-
212
- return function() {
213
- var initArgs = [this].concat(args);
214
- behavior.attach.apply(behavior, initArgs);
215
- };
216
- } else {
217
- var args = (arguments.length == 2 && arguments[1] instanceof Array) ?
218
- arguments[1] : Array.prototype.slice.call(arguments, 1);
219
-
220
- this.element = $(arguments[0]);
221
- this.initialize.apply(this, args);
222
- behavior._bindEvents(this);
223
- behavior.instances.push(this);
224
- }
225
- };
226
-
227
- Object.extend(behavior, Class.Methods);
228
- Object.extend(behavior, Behavior.Methods);
229
- behavior.superclass = parent;
230
- behavior.subclasses = [];
231
- behavior.instances = [];
232
-
233
- if (parent) {
234
- var subclass = function() { };
235
- subclass.prototype = parent.prototype;
236
- behavior.prototype = new subclass;
237
- parent.subclasses.push(behavior);
238
- }
239
-
240
- for (var i = 0; i < properties.length; i++)
241
- behavior.addMethods(properties[i]);
242
-
243
- if (!behavior.prototype.initialize)
244
- behavior.prototype.initialize = Prototype.emptyFunction;
245
-
246
- behavior.prototype.constructor = behavior;
247
-
248
- return behavior;
249
- },
250
- Methods : {
251
- attach : function(element) {
252
- return new this(element, Array.prototype.slice.call(arguments, 1));
253
- },
254
- _bindEvents : function(bound) {
255
- for (var member in bound) {
256
- var matches = member.match(/^on(.+)/);
257
- if (matches && typeof bound[member] == 'function')
258
- bound.element.observe(matches[1], Event.addBehavior._wrapObserver(bound[member].bindAsEventListener(bound)));
259
- }
260
- }
261
- }
262
- };
263
-
264
-
265
-
266
- Remote = Behavior.create({
267
- initialize: function(options) {
268
- if (this.element.nodeName == 'FORM') new Remote.Form(this.element, options);
269
- else new Remote.Link(this.element, options);
270
- }
271
- });
272
-
273
- Remote.Base = {
274
- initialize : function(options) {
275
- this.options = Object.extend({
276
- evaluateScripts : true
277
- }, options || {});
278
-
279
- this._bindCallbacks();
280
- },
281
- _makeRequest : function(options) {
282
- if (options.update) new Ajax.Updater(options.update, options.url, options);
283
- else new Ajax.Request(options.url, options);
284
- return false;
285
- },
286
- _bindCallbacks: function() {
287
- $w('onCreate onComplete onException onFailure onInteractive onLoading onLoaded onSuccess').each(function(cb) {
288
- if (Object.isFunction(this.options[cb]))
289
- this.options[cb] = this.options[cb].bind(this);
290
- }.bind(this));
291
- }
292
- }
293
-
294
- Remote.Link = Behavior.create(Remote.Base, {
295
- onclick : function() {
296
- var options = Object.extend({ url : this.element.href, method : 'get' }, this.options);
297
- return this._makeRequest(options);
298
- }
299
- });
300
-
301
-
302
- Remote.Form = Behavior.create(Remote.Base, {
303
- onclick : function(e) {
304
- var sourceElement = e.element();
305
-
306
- if (['input', 'button'].include(sourceElement.nodeName.toLowerCase()) &&
307
- sourceElement.type == 'submit')
308
- this._submitButton = sourceElement;
309
- },
310
- onsubmit : function() {
311
- var options = Object.extend({
312
- url : this.element.action,
313
- method : this.element.method || 'get',
314
- parameters : this.element.serialize({ submit: this._submitButton.name })
315
- }, this.options);
316
- this._submitButton = null;
317
- return this._makeRequest(options);
318
- }
319
- });
320
-
321
- Observed = Behavior.create({
322
- initialize : function(callback, options) {
323
- this.callback = callback.bind(this);
324
- this.options = options || {};
325
- this.observer = (this.element.nodeName == 'FORM') ? this._observeForm() : this._observeField();
326
- },
327
- stop: function() {
328
- this.observer.stop();
329
- },
330
- _observeForm: function() {
331
- return (this.options.frequency) ? new Form.Observer(this.element, this.options.frequency, this.callback) :
332
- new Form.EventObserver(this.element, this.callback);
333
- },
334
- _observeField: function() {
335
- return (this.options.frequency) ? new Form.Element.Observer(this.element, this.options.frequency, this.callback) :
336
- new Form.Element.EventObserver(this.element, this.callback);
337
- }
338
- });
339
-