rasputin 0.12.1 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +0,0 @@
1
- (function() {
2
-
3
- Ember.I18n = I18n;
4
-
5
- Ember.String.loc = function(scope, options) {
6
- return Ember.I18n.translate(scope, options);
7
- };
8
-
9
- Ember.STRINGS = Ember.I18n.translations;
10
-
11
- Ember.Handlebars.registerHelper('loc', function(property) {
12
- return Ember.String.loc(property);
13
- });
14
-
15
- if (Ember.EXTEND_PROTOTYPES) {
16
- String.prototype.loc = function(options) {
17
- return Ember.String.loc(String(this), options);
18
- };
19
- }
20
-
21
- })();
@@ -1,568 +0,0 @@
1
-
2
- (function(exports) {
3
- /**
4
- @class
5
-
6
- Route is a class used internally by Ember.RoutesManager. The routes defined by your
7
- application are stored in a tree structure, and this is the class for the
8
- nodes.
9
- */
10
- Ember.Route = Ember.Object.extend({
11
-
12
- target: null,
13
-
14
- method: null,
15
-
16
- staticRoutes: null,
17
-
18
- dynamicRoutes: null,
19
-
20
- wildcardRoutes: null,
21
-
22
- add: function(parts, target, method) {
23
- var part, nextRoute;
24
-
25
- // clone the parts array because we are going to alter it
26
- parts = Ember.copy(parts);
27
-
28
- if (!parts || parts.length === 0) {
29
- this.target = target;
30
- this.method = method;
31
-
32
- } else {
33
- part = parts.shift();
34
-
35
- // there are 3 types of routes
36
- switch (part.slice(0, 1)) {
37
-
38
- // 1. dynamic routes
39
- case ':':
40
- part = part.slice(1, part.length);
41
- if (!this.dynamicRoutes) this.dynamicRoutes = {};
42
- if (!this.dynamicRoutes[part]) this.dynamicRoutes[part] = Ember.Route.create();
43
- nextRoute = this.dynamicRoutes[part];
44
- break;
45
-
46
- // 2. wildcard routes
47
- case '*':
48
- part = part.slice(1, part.length);
49
- if (!this.wildcardRoutes) this.wildcardRoutes = {};
50
- nextRoute = this.wildcardRoutes[part] = Ember.Route.create();
51
- break;
52
-
53
- // 3. static routes
54
- default:
55
- if (!this.staticRoutes) this.staticRoutes = {};
56
- if (!this.staticRoutes[part]) this.staticRoutes[part] = Ember.Route.create();
57
- nextRoute = this.staticRoutes[part];
58
- }
59
-
60
- // recursively add the rest of the route
61
- if (nextRoute) nextRoute.add(parts, target, method);
62
- }
63
- },
64
-
65
- routeForParts: function(parts, params) {
66
- var part, key, route;
67
-
68
- // clone the parts array because we are going to alter it
69
- parts = Ember.copy(parts);
70
-
71
- // if parts is empty, we are done
72
- if (!parts || parts.length === 0) {
73
- return this.method ? this : null;
74
-
75
- } else {
76
- part = parts.shift();
77
-
78
- // try to match a static route
79
- if (this.staticRoutes && this.staticRoutes[part]) {
80
- route = this.staticRoutes[part].routeForParts(parts, params);
81
- if (route) {
82
- return route;
83
- }
84
- }
85
-
86
- // else, try to match a dynamic route
87
- for (key in this.dynamicRoutes) {
88
- route = this.dynamicRoutes[key].routeForParts(parts, params);
89
- if (route) {
90
- params[key] = part;
91
- return route;
92
- }
93
- }
94
-
95
- // else, try to match a wilcard route
96
- for (key in this.wildcardRoutes) {
97
- parts.unshift(part);
98
- params[key] = parts.join('/');
99
- return this.wildcardRoutes[key].routeForParts(null, params);
100
- }
101
-
102
- // if nothing was found, it means that there is no match
103
- return null;
104
- }
105
- }
106
-
107
- });
108
-
109
- })({});
110
-
111
-
112
- (function(exports) {
113
- // ==========================================================================
114
- // Project: Ember - JavaScript Application Framework
115
- // Copyright: ©2006-2011 Strobe Inc. and contributors.
116
- // Portions ©2008-2011 Apple Inc. All rights reserved.
117
- // License: Licensed under MIT license (see license.js)
118
- // ==========================================================================
119
- var get = Ember.get, set = Ember.set;
120
-
121
- /**
122
- Wether the browser supports HTML5 history.
123
- */
124
- var supportsHistory = !!(window.history && window.history.pushState);
125
-
126
- /**
127
- Wether the browser supports the hashchange event.
128
- */
129
- var supportsHashChange = ('onhashchange' in window) && (document.documentMode === undefined || document.documentMode > 7);
130
-
131
- /**
132
- @class
133
-
134
- Ember.routes manages the browser location. You can change the hash part of the
135
- current location. The following code
136
-
137
- Ember.routes.set('location', 'notes/edit/4');
138
-
139
- will change the location to http://domain.tld/my_app#notes/edit/4. Adding
140
- routes will register a handler that will be called whenever the location
141
- changes and matches the route:
142
-
143
- Ember.routes.add(':controller/:action/:id', MyApp, MyApp.route);
144
-
145
- You can pass additional parameters in the location hash that will be relayed
146
- to the route handler:
147
-
148
- Ember.routes.set('location', 'notes/show/4?format=xml&language=fr');
149
-
150
- The syntax for the location hash is described in the location property
151
- documentation, and the syntax for adding handlers is described in the
152
- add method documentation.
153
-
154
- Browsers keep track of the locations in their history, so when the user
155
- presses the 'back' or 'forward' button, the location is changed, Ember.route
156
- catches it and calls your handler. Except for Internet Explorer versions 7
157
- and earlier, which do not modify the history stack when the location hash
158
- changes.
159
-
160
- Ember.routes also supports HTML5 history, which uses a '/' instead of a '#'
161
- in the URLs, so that all your website's URLs are consistent.
162
- */
163
- Ember.RoutesManager = Ember.Object.extend({
164
-
165
- /**
166
- Set this property to true if you want to use HTML5 history, if available on
167
- the browser, instead of the location hash.
168
-
169
- HTML 5 history uses the history.pushState method and the window's popstate
170
- event.
171
-
172
- By default it is false, so your URLs will look like:
173
-
174
- http://domain.tld/my_app#notes/edit/4
175
-
176
- If set to true and the browser supports pushState(), your URLs will look
177
- like:
178
-
179
- http://domain.tld/my_app/notes/edit/4
180
-
181
- You will also need to make sure that baseURI is properly configured, as
182
- well as your server so that your routes are properly pointing to your
183
- Ember application.
184
-
185
- @see http://dev.w3.org/html5/spec/history.html#the-history-interface
186
- @property
187
- @type {Boolean}
188
- */
189
- wantsHistory: false,
190
-
191
- /**
192
- A read-only boolean indicating whether or not HTML5 history is used. Based
193
- on the value of wantsHistory and the browser's support for pushState.
194
-
195
- @see wantsHistory
196
- @property
197
- @type {Boolean}
198
- */
199
- usesHistory: null,
200
-
201
- /**
202
- The base URI used to resolve routes (which are relative URLs). Only used
203
- when usesHistory is equal to true.
204
-
205
- The build tools automatically configure this value if you have the
206
- html5_history option activated in the Buildfile:
207
-
208
- config :my_app, :html5_history => true
209
-
210
- Alternatively, it uses by default the value of the href attribute of the
211
- <base> tag of the HTML document. For example:
212
-
213
- <base href="http://domain.tld/my_app">
214
-
215
- The value can also be customized before or during the exectution of the
216
- main() method.
217
-
218
- @see http://www.w3.org/TR/html5/semantics.html#the-base-element
219
- @property
220
- @type {String}
221
- */
222
- baseURI: document.baseURI,
223
-
224
- /** @private
225
- A boolean value indicating whether or not the ping method has been called
226
- to setup the Ember.routes.
227
-
228
- @property
229
- @type {Boolean}
230
- */
231
- _didSetup: false,
232
-
233
- /** @private
234
- Internal representation of the current location hash.
235
-
236
- @property
237
- @type {String}
238
- */
239
- _location: null,
240
-
241
- /** @private
242
- Routes are stored in a tree structure, this is the root node.
243
-
244
- @property
245
- @type {Route}
246
- */
247
- _firstRoute: null,
248
-
249
- /** @private
250
- Internal method used to extract and merge the parameters of a URL.
251
-
252
- @returns {Hash}
253
- */
254
- _extractParametersAndRoute: function(obj) {
255
- var params = {},
256
- route = obj.route || '',
257
- separator, parts, i, len, crumbs, key;
258
-
259
- //separator = (route.indexOf('?') < 0 && route.indexOf('&') >= 0) ? '&' : '?';
260
- separator = '?';
261
- parts = route.split(separator);
262
- route = parts[0];
263
- if (parts.length === 1) {
264
- parts = [];
265
- } else if (parts.length === 2) {
266
- parts = parts[1].split('&');
267
- } else if (parts.length > 2) {
268
- parts.shift();
269
- }
270
-
271
- // extract the parameters from the route string
272
- len = parts.length;
273
- for (i = 0; i < len; ++i) {
274
- crumbs = parts[i].split('=');
275
- params[crumbs[0]] = crumbs[1];
276
- }
277
-
278
- // overlay any parameter passed in obj
279
- for (key in obj) {
280
- if (obj.hasOwnProperty(key) && key !== 'route') {
281
- params[key] = '' + obj[key];
282
- }
283
- }
284
-
285
- // build the route
286
- parts = [];
287
- for (key in params) {
288
- parts.push([key, params[key]].join('='));
289
- }
290
- params.params = separator + parts.join('&');
291
- params.route = route;
292
-
293
- return params;
294
- },
295
-
296
- /**
297
- The current location hash. It is the part in the browser's location after
298
- the '#' mark.
299
-
300
- The following code
301
-
302
- Ember.routes.set('location', 'notes/edit/4');
303
-
304
- will change the location to http://domain.tld/my_app#notes/edit/4 and call
305
- the correct route handler if it has been registered with the add method.
306
-
307
- You can also pass additional parameters. They will be relayed to the route
308
- handler. For example, the following code
309
-
310
- Ember.routes.add(':controller/:action/:id', MyApp, MyApp.route);
311
- Ember.routes.set('location', 'notes/show/4?format=xml&language=fr');
312
-
313
- will change the location to
314
- http://domain.tld/my_app#notes/show/4?format=xml&language=fr and call the
315
- MyApp.route method with the following argument:
316
-
317
- { route: 'notes/show/4',
318
- params: '?format=xml&language=fr',
319
- controller: 'notes',
320
- action: 'show',
321
- id: '4',
322
- format: 'xml',
323
- language: 'fr' }
324
-
325
- The location can also be set with a hash, the following code
326
-
327
- Ember.routes.set('location',
328
- { route: 'notes/edit/4', format: 'xml', language: 'fr' });
329
-
330
- will change the location to
331
- http://domain.tld/my_app#notes/show/4?format=xml&language=fr.
332
-
333
- @property
334
- @type {String}
335
- */
336
- location: Ember.computed(function(key, value) {
337
- this._skipRoute = false;
338
- return this._extractLocation(key, value);
339
- }).property(),
340
-
341
- _extractLocation: function(key, value) {
342
- var crumbs, encodedValue;
343
-
344
- if (value !== undefined) {
345
- if (value === null) {
346
- value = '';
347
- }
348
-
349
- if (typeof(value) === 'object') {
350
- crumbs = this._extractParametersAndRoute(value);
351
- value = crumbs.route + crumbs.params;
352
- }
353
-
354
- if (!this._skipPush && (!Ember.empty(value) || (this._location && this._location !== value))) {
355
- encodedValue = encodeURI(value);
356
-
357
- if (this.usesHistory) {
358
- if (encodedValue.length > 0) {
359
- encodedValue = '/' + encodedValue;
360
- }
361
- window.history.pushState(null, null, get(this, 'baseURI') + encodedValue);
362
- } else if (encodedValue.length > 0 || window.location.hash.length > 0) {
363
- window.location.hash = encodedValue;
364
- }
365
- }
366
-
367
- this._location = value;
368
- }
369
-
370
- return this._location;
371
- },
372
-
373
- updateLocation: function(loc){
374
- this._skipRoute = true;
375
- return this._extractLocation('location', loc);
376
- },
377
-
378
- /**
379
- You usually don't need to call this method. It is done automatically after
380
- the application has been initialized.
381
-
382
- It registers for the hashchange event if available. If not, it creates a
383
- timer that looks for location changes every 150ms.
384
- */
385
- ping: function() {
386
- if (!this._didSetup) {
387
- this._didSetup = true;
388
-
389
- var state;
390
- if (get(this, 'wantsHistory') && supportsHistory) {
391
- this.usesHistory = true;
392
-
393
- // Move any hash state to url state
394
- // TODO: Make sure we have a hash before adding slash
395
- state = window.location.hash.slice(1);
396
- if (state.length > 0) {
397
- state = '/' + state;
398
- window.history.replaceState(null, null, get(this, 'baseURI')+state);
399
- }
400
-
401
- popState.call(this);
402
- Ember.$(window).bind('popstate', Ember.$.proxy(popState, this));
403
-
404
- } else {
405
- this.usesHistory = false;
406
-
407
- if (get(this, 'wantsHistory')) {
408
- // Move any url state to hash
409
- var base = get(this, 'baseURI'),
410
- loc = (base.charAt(0) === '/') ? document.location.pathname : document.location.href.replace(document.location.hash, '');
411
- state = loc.slice(base.length+1);
412
- if (state.length > 0) {
413
- window.location.href = base+'#'+state;
414
- }
415
- }
416
-
417
- if (supportsHashChange) {
418
- hashChange.call(this);
419
- Ember.$(window).bind('hashchange', Ember.$.proxy(hashChange, this));
420
-
421
- } else {
422
- // we don't use a Ember.Timer because we don't want
423
- // a run loop to be triggered at each ping
424
- var invokeHashChange = Ember.$.proxy(function() {
425
- hashChange.call(this);
426
- setTimeout(invokeHashChange, 100);
427
- }, this);
428
- invokeHashChange();
429
- }
430
- }
431
- }
432
- },
433
-
434
- /**
435
- Adds a route handler. Routes have the following format:
436
-
437
- - 'users/show/5' is a static route and only matches this exact string,
438
- - ':action/:controller/:id' is a dynamic route and the handler will be
439
- called with the 'action', 'controller' and 'id' parameters passed in a
440
- hash,
441
- - '*url' is a wildcard route, it matches the whole route and the handler
442
- will be called with the 'url' parameter passed in a hash.
443
-
444
- Route types can be combined, the following are valid routes:
445
-
446
- - 'users/:action/:id'
447
- - ':controller/show/:id'
448
- - ':controller/ *url' (ignore the space, because of jslint)
449
-
450
- @param {String} route the route to be registered
451
- @param {Object} target the object on which the method will be called, or
452
- directly the function to be called to handle the route
453
- @param {Function} method the method to be called on target to handle the
454
- route, can be a function or a string
455
- */
456
- add: function(route, target, method) {
457
- if (!this._didSetup) {
458
- Ember.run.once(this, 'ping');
459
- }
460
-
461
- if (method === undefined && Ember.typeOf(target) === 'function') {
462
- method = target;
463
- target = null;
464
- } else if (Ember.typeOf(method) === 'string') {
465
- method = target[method];
466
- }
467
-
468
- if (!this._firstRoute) this._firstRoute = Ember.Route.create();
469
- this._firstRoute.add(route.split('/'), target, method);
470
-
471
- return this;
472
- },
473
-
474
- /**
475
- Observer of the 'location' property that calls the correct route handler
476
- when the location changes.
477
- */
478
- locationDidChange: Ember.observer(function() {
479
- this.trigger();
480
- }, 'location'),
481
-
482
- /**
483
- Triggers a route even if already in that route (does change the location, if it
484
- is not already changed, as well).
485
-
486
- If the location is not the same as the supplied location, this simply lets "location"
487
- handle it (which ends up coming back to here).
488
- */
489
- trigger: function() {
490
- var location = get(this, 'location'),
491
- params, route;
492
-
493
- if (this._firstRoute) {
494
- params = this._extractParametersAndRoute({ route: location });
495
- location = params.route;
496
- delete params.route;
497
- delete params.params;
498
-
499
- route = this.getRoute(location, params);
500
- if (route && route.method) {
501
- route.method.call(route.target || this, params);
502
- }
503
- }
504
- },
505
-
506
- getRoute: function(route, params) {
507
- var firstRoute = this._firstRoute;
508
- if (Ember.none(params)) {
509
- params = {};
510
- }
511
-
512
- return firstRoute.routeForParts(route.split('/'), params);
513
- },
514
-
515
- exists: function(route, params) {
516
- route = this.getRoute(route, params);
517
- return route !== null && route.method !== null;
518
- }
519
-
520
- });
521
-
522
- Ember.routes = Ember.RoutesManager.create();
523
-
524
- /**
525
- Event handler for the hashchange event. Called automatically by the browser
526
- if it supports the hashchange event, or by our timer if not.
527
- */
528
- function hashChange(event) {
529
- var loc = window.location.hash;
530
-
531
- // Remove the '#' prefix
532
- loc = (loc && loc.length > 0) ? loc.slice(1, loc.length) : '';
533
-
534
- if (!jQuery.browser.mozilla) {
535
- // because of bug https://bugzilla.mozilla.org/show_bug.cgi?id=483304
536
- loc = decodeURI(loc);
537
- }
538
-
539
- if (get(this, 'location') !== loc && !this._skipRoute) {
540
- Ember.run.once(this, function() {
541
- this._skipPush = true;
542
- set(this, 'location', loc);
543
- this._skipPush = false;
544
- });
545
- }
546
- this._skipRoute = false;
547
- }
548
-
549
- function popState(event) {
550
- var base = get(this, 'baseURI'),
551
- loc = (base.charAt(0) === '/') ? document.location.pathname : document.location.href;
552
-
553
- if (loc.slice(0, base.length) === base) {
554
- // Remove the base prefix and the extra '/'
555
- loc = loc.slice(base.length + 1, loc.length);
556
-
557
- if (get(this, 'location') !== loc && !this._skipRoute) {
558
- Ember.run.once(this, function() {
559
- this._skipPush = true;
560
- set(this, 'location', loc);
561
- this._skipPush = false;
562
- });
563
- }
564
- }
565
- this._skipRoute = false;
566
- }
567
-
568
- })({});