distil 0.11.6 → 0.11.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/assets/distil.js +2 -1
- data/bin/distil +2 -0
- data/distil.gemspec +152 -2
- data/lib/distil/configurable.rb +3 -1
- data/lib/distil/error-reporter.rb +2 -0
- data/lib/distil/product/concatenated.rb +1 -3
- data/lib/distil/product/debug.rb +1 -3
- data/lib/distil/product/javascript-product.rb +2 -8
- data/lib/distil/product.rb +5 -5
- data/lib/distil/project/distil-project.rb +18 -1
- data/lib/distil/project/external-project.rb +1 -1
- data/lib/distil/project/remote-project.rb +39 -0
- data/lib/distil/project.rb +18 -9
- data/lib/distil/target.rb +13 -12
- data/lib/distil/task/css-dependency-task.rb +1 -1
- data/lib/distil/task/validate-js-task.rb +6 -1
- data/lib/distil.rb +1 -0
- data/vendor/pdoc/LICENSE +16 -0
- data/vendor/pdoc/PDoc.tmbundle/Commands/Continue PDoc Comment.tmCommand +39 -0
- data/vendor/pdoc/PDoc.tmbundle/Macros/Collapse PDoc Blocks.tmMacro +4084 -0
- data/vendor/pdoc/PDoc.tmbundle/Macros/Expand PDoc Blocks.tmMacro +1388 -0
- data/vendor/pdoc/PDoc.tmbundle/Preferences/PDoc.tmPreferences +50 -0
- data/vendor/pdoc/PDoc.tmbundle/Snippets/class.tmSnippet +24 -0
- data/vendor/pdoc/PDoc.tmbundle/Snippets/constant.tmSnippet +22 -0
- data/vendor/pdoc/PDoc.tmbundle/Snippets/event.tmSnippet +16 -0
- data/vendor/pdoc/PDoc.tmbundle/Snippets/method.tmSnippet +22 -0
- data/vendor/pdoc/PDoc.tmbundle/Snippets/mixin.tmSnippet +23 -0
- data/vendor/pdoc/PDoc.tmbundle/Snippets/namespace.tmSnippet +24 -0
- data/vendor/pdoc/PDoc.tmbundle/Snippets/param.tmSnippet +16 -0
- data/vendor/pdoc/PDoc.tmbundle/Snippets/property.tmSnippet +22 -0
- data/vendor/pdoc/PDoc.tmbundle/Snippets/section.tmSnippet +23 -0
- data/vendor/pdoc/PDoc.tmbundle/Syntaxes/PDoc.tmLanguage +33 -0
- data/vendor/pdoc/PDoc.tmbundle/info.plist +22 -0
- data/vendor/pdoc/README.markdown +34 -0
- data/vendor/pdoc/Rakefile +46 -0
- data/vendor/pdoc/bin/pdoc +58 -0
- data/vendor/pdoc/lib/pdoc/error.rb +4 -0
- data/vendor/pdoc/lib/pdoc/generators/abstract_generator.rb +16 -0
- data/vendor/pdoc/lib/pdoc/generators/html/helpers.rb +256 -0
- data/vendor/pdoc/lib/pdoc/generators/html/page.rb +71 -0
- data/vendor/pdoc/lib/pdoc/generators/html/syntax_highlighter.rb +41 -0
- data/vendor/pdoc/lib/pdoc/generators/html/template.rb +37 -0
- data/vendor/pdoc/lib/pdoc/generators/html/website.rb +194 -0
- data/vendor/pdoc/lib/pdoc/generators/html.rb +8 -0
- data/vendor/pdoc/lib/pdoc/generators/json.rb +15 -0
- data/vendor/pdoc/lib/pdoc/generators/pythonesque.rb +105 -0
- data/vendor/pdoc/lib/pdoc/generators.rb +6 -0
- data/vendor/pdoc/lib/pdoc/models/argument.rb +37 -0
- data/vendor/pdoc/lib/pdoc/models/base.rb +107 -0
- data/vendor/pdoc/lib/pdoc/models/callable.rb +19 -0
- data/vendor/pdoc/lib/pdoc/models/class.rb +28 -0
- data/vendor/pdoc/lib/pdoc/models/class_method.rb +18 -0
- data/vendor/pdoc/lib/pdoc/models/class_property.rb +9 -0
- data/vendor/pdoc/lib/pdoc/models/constant.rb +9 -0
- data/vendor/pdoc/lib/pdoc/models/constructor.rb +14 -0
- data/vendor/pdoc/lib/pdoc/models/container.rb +114 -0
- data/vendor/pdoc/lib/pdoc/models/entity.rb +54 -0
- data/vendor/pdoc/lib/pdoc/models/instance_method.rb +18 -0
- data/vendor/pdoc/lib/pdoc/models/instance_property.rb +9 -0
- data/vendor/pdoc/lib/pdoc/models/mixin.rb +10 -0
- data/vendor/pdoc/lib/pdoc/models/namespace.rb +10 -0
- data/vendor/pdoc/lib/pdoc/models/root.rb +27 -0
- data/vendor/pdoc/lib/pdoc/models/section.rb +19 -0
- data/vendor/pdoc/lib/pdoc/models/signature.rb +27 -0
- data/vendor/pdoc/lib/pdoc/models/utility.rb +11 -0
- data/vendor/pdoc/lib/pdoc/models.rb +47 -0
- data/vendor/pdoc/lib/pdoc/parser/argument_description_nodes.rb +21 -0
- data/vendor/pdoc/lib/pdoc/parser/basic_nodes.rb +31 -0
- data/vendor/pdoc/lib/pdoc/parser/description_nodes.rb +42 -0
- data/vendor/pdoc/lib/pdoc/parser/documentation_nodes.rb +483 -0
- data/vendor/pdoc/lib/pdoc/parser/ebnf_arguments_nodes.rb +58 -0
- data/vendor/pdoc/lib/pdoc/parser/ebnf_expression_nodes.rb +227 -0
- data/vendor/pdoc/lib/pdoc/parser/fragment.rb +55 -0
- data/vendor/pdoc/lib/pdoc/parser/section_content_nodes.rb +19 -0
- data/vendor/pdoc/lib/pdoc/parser/tags_nodes.rb +14 -0
- data/vendor/pdoc/lib/pdoc/parser/treetop_files/argument_description.treetop +31 -0
- data/vendor/pdoc/lib/pdoc/parser/treetop_files/basic.treetop +41 -0
- data/vendor/pdoc/lib/pdoc/parser/treetop_files/description.treetop +7 -0
- data/vendor/pdoc/lib/pdoc/parser/treetop_files/documentation.treetop +75 -0
- data/vendor/pdoc/lib/pdoc/parser/treetop_files/ebnf_arguments.treetop +33 -0
- data/vendor/pdoc/lib/pdoc/parser/treetop_files/ebnf_expression.treetop +70 -0
- data/vendor/pdoc/lib/pdoc/parser/treetop_files/ebnf_javascript.treetop +54 -0
- data/vendor/pdoc/lib/pdoc/parser/treetop_files/events.treetop +17 -0
- data/vendor/pdoc/lib/pdoc/parser/treetop_files/section_content.treetop +8 -0
- data/vendor/pdoc/lib/pdoc/parser/treetop_files/tags.treetop +31 -0
- data/vendor/pdoc/lib/pdoc/parser.rb +109 -0
- data/vendor/pdoc/lib/pdoc/runner.rb +110 -0
- data/vendor/pdoc/lib/pdoc/treemaker.rb +94 -0
- data/vendor/pdoc/lib/pdoc.rb +32 -0
- data/vendor/pdoc/pdoc-0.2.0.gem +0 -0
- data/vendor/pdoc/pdoc.gemspec +31 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/alias.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/class.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/class_deprecated.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/class_method.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/class_property.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/constant.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/constructor.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/deprecated.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/description.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/information.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/instance_method.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/instance_property.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/method.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/method_deprecated.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/mixin.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/namespace.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/property.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/related_to.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/search-background.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/section-background.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/section.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/selected-section-background.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/subclass.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/superclass.png +0 -0
- data/vendor/pdoc/templates/html/assets/images/pdoc/utility.png +0 -0
- data/vendor/pdoc/templates/html/assets/javascripts/pdoc/application.js +478 -0
- data/vendor/pdoc/templates/html/assets/javascripts/pdoc/prototype.js +4874 -0
- data/vendor/pdoc/templates/html/assets/javascripts/pdoc/tabs.js +506 -0
- data/vendor/pdoc/templates/html/assets/stylesheets/pdoc/api.css +677 -0
- data/vendor/pdoc/templates/html/assets/stylesheets/pdoc/pygments.css +62 -0
- data/vendor/pdoc/templates/html/helpers.rb +35 -0
- data/vendor/pdoc/templates/html/index.erb +18 -0
- data/vendor/pdoc/templates/html/item_index.js.erb +6 -0
- data/vendor/pdoc/templates/html/layout.erb +67 -0
- data/vendor/pdoc/templates/html/leaf.erb +22 -0
- data/vendor/pdoc/templates/html/node.erb +30 -0
- data/vendor/pdoc/templates/html/partials/class_relationships.erb +19 -0
- data/vendor/pdoc/templates/html/partials/classes.erb +7 -0
- data/vendor/pdoc/templates/html/partials/constructor.erb +5 -0
- data/vendor/pdoc/templates/html/partials/description.erb +5 -0
- data/vendor/pdoc/templates/html/partials/link_list.erb +1 -0
- data/vendor/pdoc/templates/html/partials/method_signatures.erb +14 -0
- data/vendor/pdoc/templates/html/partials/methodized_note.erb +9 -0
- data/vendor/pdoc/templates/html/partials/mixins.erb +7 -0
- data/vendor/pdoc/templates/html/partials/namespaces.erb +7 -0
- data/vendor/pdoc/templates/html/partials/related_utilities.erb +5 -0
- data/vendor/pdoc/templates/html/partials/relationships.erb +11 -0
- data/vendor/pdoc/templates/html/partials/short_description_list.erb +7 -0
- data/vendor/pdoc/templates/html/partials/title.erb +22 -0
- data/vendor/pdoc/templates/html/section.erb +18 -0
- data/vendor/pdoc/test/fixtures/ajax.js +809 -0
- data/vendor/pdoc/test/fixtures/prototype.js +5789 -0
- data/vendor/pdoc/test/fixtures/test.txt +1 -0
- data/vendor/pdoc/test/fixtures/text.txt +13 -0
- data/vendor/pdoc/test/unit/parser/argument_description_test.rb +40 -0
- data/vendor/pdoc/test/unit/parser/basic_test.rb +55 -0
- data/vendor/pdoc/test/unit/parser/description_test.rb +34 -0
- data/vendor/pdoc/test/unit/parser/documentation_test.rb +520 -0
- data/vendor/pdoc/test/unit/parser/ebnf_arguments_test.rb +81 -0
- data/vendor/pdoc/test/unit/parser/ebnf_expression_test.rb +382 -0
- data/vendor/pdoc/test/unit/parser/ebnf_javascript_test.rb +37 -0
- data/vendor/pdoc/test/unit/parser/events_test.rb +27 -0
- data/vendor/pdoc/test/unit/parser/section_content_test.rb +44 -0
- data/vendor/pdoc/test/unit/parser/tags_test.rb +39 -0
- data/vendor/pdoc/test/unit/parser/test_fragment.rb +80 -0
- data/vendor/pdoc/test/unit/parser_test_helper.rb +62 -0
- data/vendor/pdoc/test/unit/runner/basic_test.rb +14 -0
- data/vendor/pdoc/test/unit/templates/html_helpers_test.rb +25 -0
- data/vendor/pdoc/vendor/albino.rb +122 -0
- data/vendor/pdoc/website/html/documentation.html +280 -0
- data/vendor/pdoc/website/html/images/pdoc.jpg +0 -0
- data/vendor/pdoc/website/html/index.html +84 -0
- data/vendor/pdoc/website/html/stylesheets/main.css +73 -0
- data/vendor/pdoc/website/html/stylesheets/reset.css +18 -0
- data/vendor/pdoc/website/markdown/syntax.markdown +226 -0
- metadata +153 -3
@@ -0,0 +1,809 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
/**
|
4
|
+
* == DOM ==
|
5
|
+
* The DOM section
|
6
|
+
**/
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
/**
|
11
|
+
* == ajax ==
|
12
|
+
* The AJAX section
|
13
|
+
**/
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
/**
|
18
|
+
* == lang ==
|
19
|
+
* The LANG section
|
20
|
+
**/
|
21
|
+
|
22
|
+
|
23
|
+
/** section: DOM
|
24
|
+
* class Element
|
25
|
+
* The Element class
|
26
|
+
**/
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
/** related to: Element
|
31
|
+
* $(element) -> Element
|
32
|
+
* the $ function
|
33
|
+
**/
|
34
|
+
|
35
|
+
/** section: DOM
|
36
|
+
* $$(selector) -> Array
|
37
|
+
* the $$ function
|
38
|
+
**/
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Element.setStyle(@element, styles) -> Element
|
44
|
+
* - element (String | Element): an id or DOM node
|
45
|
+
* - styles (String | Object | Hash): can be either a regular CSS string or
|
46
|
+
* a hash or regular object, in which case, properties need to be camelized
|
47
|
+
*
|
48
|
+
* fires element:style:updated
|
49
|
+
*
|
50
|
+
* Sets the style of element
|
51
|
+
* and returns it
|
52
|
+
**/
|
53
|
+
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Element#foo() -> Element
|
57
|
+
* a dummy non methodized method
|
58
|
+
**/
|
59
|
+
|
60
|
+
/** alias of: Element#foo
|
61
|
+
* Element#bar() -> Element
|
62
|
+
* fires click
|
63
|
+
**/
|
64
|
+
|
65
|
+
|
66
|
+
/** section: ajax
|
67
|
+
* Ajax
|
68
|
+
* All requester object in the Ajax namespace share a common set of options and callbacks.
|
69
|
+
* Callbacks are called at various points in the life-cycle of a request, and always feature
|
70
|
+
* the same list of arguments. They are passed to requesters right along with their other options.
|
71
|
+
**/
|
72
|
+
var Ajax = {
|
73
|
+
/**
|
74
|
+
* Ajax.getTransport( ) -> XMLHttpRequest | ActiveXObject
|
75
|
+
* returns: a new instance of the XMLHttpRequest object for
|
76
|
+
* standard compliant browsers, the available ActiveXObject
|
77
|
+
* counter part for IE.
|
78
|
+
**/
|
79
|
+
getTransport: function() {
|
80
|
+
return Try.these(
|
81
|
+
function() {return new XMLHttpRequest()},
|
82
|
+
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
|
83
|
+
function() {return new ActiveXObject('Microsoft.XMLHTTP')}
|
84
|
+
) || false;
|
85
|
+
},
|
86
|
+
/**
|
87
|
+
* Ajax.activeRequestCount -> 0
|
88
|
+
**/
|
89
|
+
activeRequestCount: 0,
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Ajax.__private__() -> Boolean
|
93
|
+
**/
|
94
|
+
__private__: function() { return true }
|
95
|
+
};
|
96
|
+
|
97
|
+
/** section: ajax
|
98
|
+
* Ajax.Responders
|
99
|
+
* includes Enumerable
|
100
|
+
**/
|
101
|
+
Ajax.Responders = {
|
102
|
+
/**
|
103
|
+
* Ajax.Responders.responders -> Array
|
104
|
+
**/
|
105
|
+
responders: [],
|
106
|
+
|
107
|
+
_each: function(iterator) {
|
108
|
+
this.responders._each(iterator);
|
109
|
+
},
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Ajax.Responders.register(responder) -> undefined
|
113
|
+
* Registers a responder.
|
114
|
+
**/
|
115
|
+
register: function(responder) {
|
116
|
+
if (!this.include(responder))
|
117
|
+
this.responders.push(responder);
|
118
|
+
},
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Ajax.Responders.unregister(responder) -> undefined
|
122
|
+
* Unregisters a responder.
|
123
|
+
**/
|
124
|
+
unregister: function(responder) {
|
125
|
+
this.responders = this.responders.without(responder);
|
126
|
+
},
|
127
|
+
/**
|
128
|
+
* Ajax.Responders.dispatch(callback, request, transport, json) -> undefined
|
129
|
+
* Dispatches a callback.
|
130
|
+
**/
|
131
|
+
dispatch: function(callback, request, transport, json) {
|
132
|
+
this.each(function(responder) {
|
133
|
+
if (Object.isFunction(responder[callback])) {
|
134
|
+
try {
|
135
|
+
responder[callback].apply(responder, [request, transport, json]);
|
136
|
+
} catch (e) { }
|
137
|
+
}
|
138
|
+
});
|
139
|
+
}
|
140
|
+
};
|
141
|
+
|
142
|
+
Object.extend(Ajax.Responders, Enumerable);
|
143
|
+
|
144
|
+
Ajax.Responders.register({
|
145
|
+
onCreate: function() { Ajax.activeRequestCount++ },
|
146
|
+
onComplete: function() { Ajax.activeRequestCount-- }
|
147
|
+
});
|
148
|
+
|
149
|
+
/**
|
150
|
+
* class Ajax.Base
|
151
|
+
* Abstract class
|
152
|
+
**/
|
153
|
+
|
154
|
+
Ajax.Base = Klass.create({
|
155
|
+
initialize: function(options) {
|
156
|
+
this.options = {
|
157
|
+
method: 'post',
|
158
|
+
asynchronous: true,
|
159
|
+
contentType: 'application/x-www-form-urlencoded',
|
160
|
+
encoding: 'UTF-8',
|
161
|
+
parameters: '',
|
162
|
+
evalJSON: true,
|
163
|
+
evalJS: true
|
164
|
+
};
|
165
|
+
Object.extend(this.options, options || { });
|
166
|
+
|
167
|
+
this.options.method = this.options.method.toLowerCase();
|
168
|
+
|
169
|
+
if (Object.isString(this.options.parameters))
|
170
|
+
this.options.parameters = this.options.parameters.toQueryParams();
|
171
|
+
else if (Object.isHash(this.options.parameters))
|
172
|
+
this.options.parameters = this.options.parameters.toObject();
|
173
|
+
}
|
174
|
+
});
|
175
|
+
/**
|
176
|
+
* class Ajax.Request < Ajax.Base
|
177
|
+
* Main Ajax class
|
178
|
+
**/
|
179
|
+
|
180
|
+
|
181
|
+
/**
|
182
|
+
* new Ajax.Request(url, options)
|
183
|
+
* the Ajax Request constructor
|
184
|
+
**/
|
185
|
+
Ajax.Request = Klass.create(Ajax.Base, {
|
186
|
+
_complete: false,
|
187
|
+
|
188
|
+
initialize: function($super, url, options) {
|
189
|
+
$super(options);
|
190
|
+
this.transport = Ajax.getTransport();
|
191
|
+
this.request(url);
|
192
|
+
},
|
193
|
+
/**
|
194
|
+
* Ajax.Request#request(url) -> undefined
|
195
|
+
* instanciates the request
|
196
|
+
* not to be confused with [[Ajax.Request foo bar]]
|
197
|
+
**/
|
198
|
+
request: function(url) {
|
199
|
+
this.url = url;
|
200
|
+
this.method = this.options.method;
|
201
|
+
var params = Object.clone(this.options.parameters);
|
202
|
+
|
203
|
+
if (!['get', 'post'].include(this.method)) {
|
204
|
+
// simulate other verbs over post
|
205
|
+
params['_method'] = this.method;
|
206
|
+
this.method = 'post';
|
207
|
+
}
|
208
|
+
|
209
|
+
this.parameters = params;
|
210
|
+
|
211
|
+
if (params = Object.toQueryString(params)) {
|
212
|
+
// when GET, append parameters to URL
|
213
|
+
if (this.method == 'get')
|
214
|
+
this.url += (this.url.include('?') ? '&' : '?') + params;
|
215
|
+
else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent))
|
216
|
+
params += '&_=';
|
217
|
+
}
|
218
|
+
|
219
|
+
try {
|
220
|
+
var response = new Ajax.Response(this);
|
221
|
+
if (this.options.onCreate) this.options.onCreate(response);
|
222
|
+
Ajax.Responders.dispatch('onCreate', this, response);
|
223
|
+
|
224
|
+
this.transport.open(this.method.toUpperCase(), this.url,
|
225
|
+
this.options.asynchronous);
|
226
|
+
|
227
|
+
if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1);
|
228
|
+
|
229
|
+
this.transport.onreadystatechange = this.onStateChange.bind(this);
|
230
|
+
this.setRequestHeaders();
|
231
|
+
|
232
|
+
this.body = this.method == 'post' ? (this.options.postBody || params) : null;
|
233
|
+
this.transport.send(this.body);
|
234
|
+
|
235
|
+
/* Force Firefox to handle ready state 4 for synchronous requests */
|
236
|
+
if (!this.options.asynchronous && this.transport.overrideMimeType)
|
237
|
+
this.onStateChange();
|
238
|
+
|
239
|
+
}
|
240
|
+
catch (e) {
|
241
|
+
this.dispatchException(e);
|
242
|
+
}
|
243
|
+
},
|
244
|
+
/**
|
245
|
+
* Ajax.Request#dummy -> "dummy"
|
246
|
+
* a dummy instance property for the sake of testing
|
247
|
+
**/
|
248
|
+
onStateChange: function() {
|
249
|
+
var readyState = this.transport.readyState;
|
250
|
+
if (readyState > 1 && !((readyState == 4) && this._complete))
|
251
|
+
this.respondToReadyState(this.transport.readyState);
|
252
|
+
},
|
253
|
+
|
254
|
+
setRequestHeaders: function() {
|
255
|
+
var headers = {
|
256
|
+
'X-Requested-With': 'XMLHttpRequest',
|
257
|
+
'X-Prototype-Version': Prototype.Version,
|
258
|
+
'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
|
259
|
+
};
|
260
|
+
|
261
|
+
if (this.method == 'post') {
|
262
|
+
headers['Content-type'] = this.options.contentType +
|
263
|
+
(this.options.encoding ? '; charset=' + this.options.encoding : '');
|
264
|
+
|
265
|
+
/* Force "Connection: close" for older Mozilla browsers to work
|
266
|
+
* around a bug where XMLHttpRequest sends an incorrect
|
267
|
+
* Content-length header. See Mozilla Bugzilla #246651.
|
268
|
+
*/
|
269
|
+
if (this.transport.overrideMimeType &&
|
270
|
+
(navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
|
271
|
+
headers['Connection'] = 'close';
|
272
|
+
}
|
273
|
+
|
274
|
+
// user-defined headers
|
275
|
+
if (typeof this.options.requestHeaders == 'object') {
|
276
|
+
var extras = this.options.requestHeaders;
|
277
|
+
|
278
|
+
if (Object.isFunction(extras.push))
|
279
|
+
for (var i = 0, length = extras.length; i < length; i += 2)
|
280
|
+
headers[extras[i]] = extras[i+1];
|
281
|
+
else
|
282
|
+
$H(extras).each(function(pair) { headers[pair.key] = pair.value });
|
283
|
+
}
|
284
|
+
|
285
|
+
for (var name in headers)
|
286
|
+
this.transport.setRequestHeader(name, headers[name]);
|
287
|
+
},
|
288
|
+
/**
|
289
|
+
* Ajax.Request#success() -> Boolean
|
290
|
+
* verifies the status of the request
|
291
|
+
**/
|
292
|
+
success: function() {
|
293
|
+
var status = this.getStatus();
|
294
|
+
return !status || (status >= 200 && status < 300);
|
295
|
+
},
|
296
|
+
|
297
|
+
getStatus: function() {
|
298
|
+
try {
|
299
|
+
return this.transport.status || 0;
|
300
|
+
} catch (e) { return 0 }
|
301
|
+
},
|
302
|
+
|
303
|
+
respondToReadyState: function(readyState) {
|
304
|
+
var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this);
|
305
|
+
|
306
|
+
if (state == 'Complete') {
|
307
|
+
try {
|
308
|
+
this._complete = true;
|
309
|
+
(this.options['on' + response.status]
|
310
|
+
|| this.options['on' + (this.success() ? 'Success' : 'Failure')]
|
311
|
+
|| Prototype.emptyFunction)(response, response.headerJSON);
|
312
|
+
} catch (e) {
|
313
|
+
this.dispatchException(e);
|
314
|
+
}
|
315
|
+
|
316
|
+
var contentType = response.getHeader('Content-type');
|
317
|
+
if (this.options.evalJS == 'force'
|
318
|
+
|| (this.options.evalJS && this.isSameOrigin() && contentType
|
319
|
+
&& contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i)))
|
320
|
+
this.evalResponse();
|
321
|
+
}
|
322
|
+
|
323
|
+
try {
|
324
|
+
(this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON);
|
325
|
+
Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON);
|
326
|
+
} catch (e) {
|
327
|
+
this.dispatchException(e);
|
328
|
+
}
|
329
|
+
|
330
|
+
if (state == 'Complete') {
|
331
|
+
// avoid memory leak in MSIE: clean up
|
332
|
+
this.transport.onreadystatechange = Prototype.emptyFunction;
|
333
|
+
}
|
334
|
+
},
|
335
|
+
|
336
|
+
isSameOrigin: function() {
|
337
|
+
var m = this.url.match(/^\s*https?:\/\/[^\/]*/);
|
338
|
+
return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({
|
339
|
+
protocol: location.protocol,
|
340
|
+
domain: document.domain,
|
341
|
+
port: location.port ? ':' + location.port : ''
|
342
|
+
}));
|
343
|
+
},
|
344
|
+
|
345
|
+
getHeader: function(name) {
|
346
|
+
try {
|
347
|
+
return this.transport.getResponseHeader(name) || null;
|
348
|
+
} catch (e) { return null }
|
349
|
+
},
|
350
|
+
|
351
|
+
evalResponse: function() {
|
352
|
+
try {
|
353
|
+
return eval((this.transport.responseText || '').unfilterJSON());
|
354
|
+
} catch (e) {
|
355
|
+
this.dispatchException(e);
|
356
|
+
}
|
357
|
+
},
|
358
|
+
|
359
|
+
dispatchException: function(exception) {
|
360
|
+
(this.options.onException || Prototype.emptyFunction)(this, exception);
|
361
|
+
Ajax.Responders.dispatch('onException', this, exception);
|
362
|
+
}
|
363
|
+
});
|
364
|
+
|
365
|
+
/**
|
366
|
+
* Ajax.Request.classProp -> "dummy"
|
367
|
+
* a dummy class property for the sake of testing
|
368
|
+
**/
|
369
|
+
|
370
|
+
|
371
|
+
/**
|
372
|
+
* Ajax.Request.Events = ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete']
|
373
|
+
* array of possible states of an xhr request
|
374
|
+
**/
|
375
|
+
Ajax.Request.Events =
|
376
|
+
['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
|
377
|
+
|
378
|
+
Ajax.Response = Klass.create({
|
379
|
+
initialize: function(request){
|
380
|
+
this.request = request;
|
381
|
+
var transport = this.transport = request.transport,
|
382
|
+
readyState = this.readyState = transport.readyState;
|
383
|
+
|
384
|
+
if((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) {
|
385
|
+
this.status = this.getStatus();
|
386
|
+
this.statusText = this.getStatusText();
|
387
|
+
this.responseText = String.interpret(transport.responseText);
|
388
|
+
this.headerJSON = this._getHeaderJSON();
|
389
|
+
}
|
390
|
+
|
391
|
+
if(readyState == 4) {
|
392
|
+
var xml = transport.responseXML;
|
393
|
+
this.responseXML = Object.isUndefined(xml) ? null : xml;
|
394
|
+
this.responseJSON = this._getResponseJSON();
|
395
|
+
}
|
396
|
+
},
|
397
|
+
|
398
|
+
status: 0,
|
399
|
+
statusText: '',
|
400
|
+
|
401
|
+
getStatus: Ajax.Request.prototype.getStatus,
|
402
|
+
|
403
|
+
getStatusText: function() {
|
404
|
+
try {
|
405
|
+
return this.transport.statusText || '';
|
406
|
+
} catch (e) { return '' }
|
407
|
+
},
|
408
|
+
|
409
|
+
getHeader: Ajax.Request.prototype.getHeader,
|
410
|
+
|
411
|
+
getAllHeaders: function() {
|
412
|
+
try {
|
413
|
+
return this.getAllResponseHeaders();
|
414
|
+
} catch (e) { return null }
|
415
|
+
},
|
416
|
+
|
417
|
+
getResponseHeader: function(name) {
|
418
|
+
return this.transport.getResponseHeader(name);
|
419
|
+
},
|
420
|
+
|
421
|
+
getAllResponseHeaders: function() {
|
422
|
+
return this.transport.getAllResponseHeaders();
|
423
|
+
},
|
424
|
+
|
425
|
+
_getHeaderJSON: function() {
|
426
|
+
var json = this.getHeader('X-JSON');
|
427
|
+
if (!json) return null;
|
428
|
+
json = decodeURIComponent(escape(json));
|
429
|
+
try {
|
430
|
+
return json.evalJSON(this.request.options.sanitizeJSON ||
|
431
|
+
!this.request.isSameOrigin());
|
432
|
+
} catch (e) {
|
433
|
+
this.request.dispatchException(e);
|
434
|
+
}
|
435
|
+
},
|
436
|
+
|
437
|
+
_getResponseJSON: function() {
|
438
|
+
var options = this.request.options;
|
439
|
+
if (!options.evalJSON || (options.evalJSON != 'force' &&
|
440
|
+
!(this.getHeader('Content-type') || '').include('application/json')) ||
|
441
|
+
this.responseText.blank())
|
442
|
+
return null;
|
443
|
+
try {
|
444
|
+
return this.responseText.evalJSON(options.sanitizeJSON ||
|
445
|
+
!this.request.isSameOrigin());
|
446
|
+
} catch (e) {
|
447
|
+
this.request.dispatchException(e);
|
448
|
+
}
|
449
|
+
}
|
450
|
+
});
|
451
|
+
|
452
|
+
Ajax.Updater = Klass.create(Ajax.Request, {
|
453
|
+
initialize: function($super, container, url, options) {
|
454
|
+
this.container = {
|
455
|
+
success: (container.success || container),
|
456
|
+
failure: (container.failure || (container.success ? null : container))
|
457
|
+
};
|
458
|
+
|
459
|
+
options = Object.clone(options);
|
460
|
+
var onComplete = options.onComplete;
|
461
|
+
options.onComplete = (function(response, json) {
|
462
|
+
this.updateContent(response.responseText);
|
463
|
+
if (Object.isFunction(onComplete)) onComplete(response, json);
|
464
|
+
}).bind(this);
|
465
|
+
|
466
|
+
$super(url, options);
|
467
|
+
},
|
468
|
+
|
469
|
+
updateContent: function(responseText) {
|
470
|
+
var receiver = this.container[this.success() ? 'success' : 'failure'],
|
471
|
+
options = this.options;
|
472
|
+
|
473
|
+
if (!options.evalScripts) responseText = responseText.stripScripts();
|
474
|
+
|
475
|
+
if (receiver = $(receiver)) {
|
476
|
+
if (options.insertion) {
|
477
|
+
if (Object.isString(options.insertion)) {
|
478
|
+
var insertion = { }; insertion[options.insertion] = responseText;
|
479
|
+
receiver.insert(insertion);
|
480
|
+
}
|
481
|
+
else options.insertion(receiver, responseText);
|
482
|
+
}
|
483
|
+
else receiver.update(responseText);
|
484
|
+
}
|
485
|
+
}
|
486
|
+
});
|
487
|
+
|
488
|
+
Ajax.PeriodicalUpdater = Klass.create(Ajax.Base, {
|
489
|
+
initialize: function($super, container, url, options) {
|
490
|
+
$super(options);
|
491
|
+
this.onComplete = this.options.onComplete;
|
492
|
+
|
493
|
+
this.frequency = (this.options.frequency || 2);
|
494
|
+
this.decay = (this.options.decay || 1);
|
495
|
+
|
496
|
+
this.updater = { };
|
497
|
+
this.container = container;
|
498
|
+
this.url = url;
|
499
|
+
|
500
|
+
this.start();
|
501
|
+
},
|
502
|
+
|
503
|
+
start: function() {
|
504
|
+
this.options.onComplete = this.updateComplete.bind(this);
|
505
|
+
this.onTimerEvent();
|
506
|
+
},
|
507
|
+
|
508
|
+
stop: function() {
|
509
|
+
this.updater.options.onComplete = undefined;
|
510
|
+
clearTimeout(this.timer);
|
511
|
+
(this.onComplete || Prototype.emptyFunction).apply(this, arguments);
|
512
|
+
},
|
513
|
+
|
514
|
+
updateComplete: function(response) {
|
515
|
+
if (this.options.decay) {
|
516
|
+
this.decay = (response.responseText == this.lastText ?
|
517
|
+
this.decay * this.options.decay : 1);
|
518
|
+
|
519
|
+
this.lastText = response.responseText;
|
520
|
+
}
|
521
|
+
this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
|
522
|
+
},
|
523
|
+
|
524
|
+
onTimerEvent: function() {
|
525
|
+
this.updater = new Ajax.Updater(this.container, this.url, this.options);
|
526
|
+
}
|
527
|
+
});
|
528
|
+
|
529
|
+
|
530
|
+
/** deprecated, section: DOM
|
531
|
+
* Toggle
|
532
|
+
**/
|
533
|
+
|
534
|
+
/** deprecated
|
535
|
+
* Toggle.display() -> undefined
|
536
|
+
**/
|
537
|
+
|
538
|
+
/**
|
539
|
+
* Toggle.foo() -> undefined
|
540
|
+
* Here is a paragraph.
|
541
|
+
*
|
542
|
+
* Another... and some code examples below:
|
543
|
+
*
|
544
|
+
* alert(Toggle.foo());
|
545
|
+
* // -> does nothing
|
546
|
+
*
|
547
|
+
* foo.show();
|
548
|
+
*
|
549
|
+
* An HTML block
|
550
|
+
*
|
551
|
+
* language: html
|
552
|
+
* <div id="my_div"></div>
|
553
|
+
*
|
554
|
+
* Now a title.
|
555
|
+
* ===========
|
556
|
+
*
|
557
|
+
**/
|
558
|
+
|
559
|
+
/** section: lang
|
560
|
+
* class String
|
561
|
+
* the string class.
|
562
|
+
**/
|
563
|
+
|
564
|
+
/** section: lang
|
565
|
+
* String.interpret(obj) -> String
|
566
|
+
* a foo bar baz
|
567
|
+
**/
|
568
|
+
|
569
|
+
/** section: ajax
|
570
|
+
* class Ajax.Namespace
|
571
|
+
**/
|
572
|
+
|
573
|
+
/**
|
574
|
+
* class Ajax.Namespace.Manager
|
575
|
+
**/
|
576
|
+
|
577
|
+
/** section: lang
|
578
|
+
* mixin Enumerable
|
579
|
+
* ruby inspired niceness
|
580
|
+
**/
|
581
|
+
var Enumerable = {
|
582
|
+
|
583
|
+
/**
|
584
|
+
* Enumerable#each(iterator[, context]) -> Enumerable
|
585
|
+
* - iterator (Function): A `Function` that expects an item in the
|
586
|
+
* collection as the first argument and a numerical index as the second.
|
587
|
+
* - context (Object): The scope in which to call `iterator`. Affects what
|
588
|
+
* the keyword `this` means inside `iterator`.
|
589
|
+
*
|
590
|
+
* Calls `iterator` for each item in the collection.
|
591
|
+
**/
|
592
|
+
each: function(iterator, context) {
|
593
|
+
var index = 0;
|
594
|
+
iterator = iterator.bind(context);
|
595
|
+
try {
|
596
|
+
this._each(function(value) {
|
597
|
+
iterator(value, index++);
|
598
|
+
});
|
599
|
+
} catch (e) {
|
600
|
+
if (e != $break) throw e;
|
601
|
+
}
|
602
|
+
return this;
|
603
|
+
},
|
604
|
+
|
605
|
+
eachSlice: function(number, iterator, context) {
|
606
|
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
607
|
+
var index = -number, slices = [], array = this.toArray();
|
608
|
+
if (number < 1) return array;
|
609
|
+
while ((index += number) < array.length)
|
610
|
+
slices.push(array.slice(index, index+number));
|
611
|
+
return slices.collect(iterator, context);
|
612
|
+
},
|
613
|
+
|
614
|
+
all: function(iterator, context) {
|
615
|
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
616
|
+
var result = true;
|
617
|
+
this.each(function(value, index) {
|
618
|
+
result = result && !!iterator(value, index);
|
619
|
+
if (!result) throw $break;
|
620
|
+
});
|
621
|
+
return result;
|
622
|
+
},
|
623
|
+
|
624
|
+
any: function(iterator, context) {
|
625
|
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
626
|
+
var result = false;
|
627
|
+
this.each(function(value, index) {
|
628
|
+
if (result = !!iterator(value, index))
|
629
|
+
throw $break;
|
630
|
+
});
|
631
|
+
return result;
|
632
|
+
},
|
633
|
+
|
634
|
+
collect: function(iterator, context) {
|
635
|
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
636
|
+
var results = [];
|
637
|
+
this.each(function(value, index) {
|
638
|
+
results.push(iterator(value, index));
|
639
|
+
});
|
640
|
+
return results;
|
641
|
+
},
|
642
|
+
|
643
|
+
detect: function(iterator, context) {
|
644
|
+
iterator = iterator.bind(context);
|
645
|
+
var result;
|
646
|
+
this.each(function(value, index) {
|
647
|
+
if (iterator(value, index)) {
|
648
|
+
result = value;
|
649
|
+
throw $break;
|
650
|
+
}
|
651
|
+
});
|
652
|
+
return result;
|
653
|
+
},
|
654
|
+
|
655
|
+
findAll: function(iterator, context) {
|
656
|
+
iterator = iterator.bind(context);
|
657
|
+
var results = [];
|
658
|
+
this.each(function(value, index) {
|
659
|
+
if (iterator(value, index))
|
660
|
+
results.push(value);
|
661
|
+
});
|
662
|
+
return results;
|
663
|
+
},
|
664
|
+
|
665
|
+
grep: function(filter, iterator, context) {
|
666
|
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
667
|
+
var results = [];
|
668
|
+
|
669
|
+
if (Object.isString(filter))
|
670
|
+
filter = new RegExp(filter);
|
671
|
+
|
672
|
+
this.each(function(value, index) {
|
673
|
+
if (filter.match(value))
|
674
|
+
results.push(iterator(value, index));
|
675
|
+
});
|
676
|
+
return results;
|
677
|
+
},
|
678
|
+
|
679
|
+
include: function(object) {
|
680
|
+
if (Object.isFunction(this.indexOf))
|
681
|
+
if (this.indexOf(object) != -1) return true;
|
682
|
+
|
683
|
+
var found = false;
|
684
|
+
this.each(function(value) {
|
685
|
+
if (value == object) {
|
686
|
+
found = true;
|
687
|
+
throw $break;
|
688
|
+
}
|
689
|
+
});
|
690
|
+
return found;
|
691
|
+
},
|
692
|
+
|
693
|
+
inGroupsOf: function(number, fillWith) {
|
694
|
+
fillWith = Object.isUndefined(fillWith) ? null : fillWith;
|
695
|
+
return this.eachSlice(number, function(slice) {
|
696
|
+
while(slice.length < number) slice.push(fillWith);
|
697
|
+
return slice;
|
698
|
+
});
|
699
|
+
},
|
700
|
+
|
701
|
+
inject: function(memo, iterator, context) {
|
702
|
+
iterator = iterator.bind(context);
|
703
|
+
this.each(function(value, index) {
|
704
|
+
memo = iterator(memo, value, index);
|
705
|
+
});
|
706
|
+
return memo;
|
707
|
+
},
|
708
|
+
|
709
|
+
invoke: function(method) {
|
710
|
+
var args = $A(arguments).slice(1);
|
711
|
+
return this.map(function(value) {
|
712
|
+
return value[method].apply(value, args);
|
713
|
+
});
|
714
|
+
},
|
715
|
+
|
716
|
+
max: function(iterator, context) {
|
717
|
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
718
|
+
var result;
|
719
|
+
this.each(function(value, index) {
|
720
|
+
value = iterator(value, index);
|
721
|
+
if (result == null || value >= result)
|
722
|
+
result = value;
|
723
|
+
});
|
724
|
+
return result;
|
725
|
+
},
|
726
|
+
|
727
|
+
min: function(iterator, context) {
|
728
|
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
729
|
+
var result;
|
730
|
+
this.each(function(value, index) {
|
731
|
+
value = iterator(value, index);
|
732
|
+
if (result == null || value < result)
|
733
|
+
result = value;
|
734
|
+
});
|
735
|
+
return result;
|
736
|
+
},
|
737
|
+
|
738
|
+
partition: function(iterator, context) {
|
739
|
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
740
|
+
var trues = [], falses = [];
|
741
|
+
this.each(function(value, index) {
|
742
|
+
(iterator(value, index) ?
|
743
|
+
trues : falses).push(value);
|
744
|
+
});
|
745
|
+
return [trues, falses];
|
746
|
+
},
|
747
|
+
|
748
|
+
pluck: function(property) {
|
749
|
+
var results = [];
|
750
|
+
this.each(function(value) {
|
751
|
+
results.push(value[property]);
|
752
|
+
});
|
753
|
+
return results;
|
754
|
+
},
|
755
|
+
|
756
|
+
reject: function(iterator, context) {
|
757
|
+
iterator = iterator.bind(context);
|
758
|
+
var results = [];
|
759
|
+
this.each(function(value, index) {
|
760
|
+
if (!iterator(value, index))
|
761
|
+
results.push(value);
|
762
|
+
});
|
763
|
+
return results;
|
764
|
+
},
|
765
|
+
|
766
|
+
sortBy: function(iterator, context) {
|
767
|
+
iterator = iterator.bind(context);
|
768
|
+
return this.map(function(value, index) {
|
769
|
+
return {value: value, criteria: iterator(value, index)};
|
770
|
+
}).sort(function(left, right) {
|
771
|
+
var a = left.criteria, b = right.criteria;
|
772
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
773
|
+
}).pluck('value');
|
774
|
+
},
|
775
|
+
|
776
|
+
toArray: function() {
|
777
|
+
return this.map();
|
778
|
+
},
|
779
|
+
|
780
|
+
zip: function() {
|
781
|
+
var iterator = Prototype.K, args = $A(arguments);
|
782
|
+
if (Object.isFunction(args.last()))
|
783
|
+
iterator = args.pop();
|
784
|
+
|
785
|
+
var collections = [this].concat(args).map($A);
|
786
|
+
return this.map(function(value, index) {
|
787
|
+
return iterator(collections.pluck(index));
|
788
|
+
});
|
789
|
+
},
|
790
|
+
|
791
|
+
size: function() {
|
792
|
+
return this.toArray().length;
|
793
|
+
},
|
794
|
+
|
795
|
+
inspect: function() {
|
796
|
+
return '#<Enumerable:' + this.toArray().inspect() + '>';
|
797
|
+
}
|
798
|
+
};
|
799
|
+
|
800
|
+
Object.extend(Enumerable, {
|
801
|
+
map: Enumerable.collect,
|
802
|
+
find: Enumerable.detect,
|
803
|
+
select: Enumerable.findAll,
|
804
|
+
filter: Enumerable.findAll,
|
805
|
+
member: Enumerable.include,
|
806
|
+
entries: Enumerable.toArray,
|
807
|
+
every: Enumerable.all,
|
808
|
+
some: Enumerable.any
|
809
|
+
});
|