right-rails 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.textile +50 -0
- data/Rakefile +23 -0
- data/generators/right_rails/right_rails_generator.rb +41 -0
- data/generators/right_rails/templates/iframed.html.erb +10 -0
- data/generators/right_scaffold/right_scaffold_generator.rb +53 -0
- data/generators/right_scaffold/templates/controller.rb +99 -0
- data/generators/right_scaffold/templates/helper.rb +2 -0
- data/generators/right_scaffold/templates/layout.html.erb +18 -0
- data/generators/right_scaffold/templates/style.css +54 -0
- data/generators/right_scaffold/templates/view__form.html.erb +16 -0
- data/generators/right_scaffold/templates/view__item.html.erb +13 -0
- data/generators/right_scaffold/templates/view_edit.html.erb +6 -0
- data/generators/right_scaffold/templates/view_index.html.erb +9 -0
- data/generators/right_scaffold/templates/view_new.html.erb +5 -0
- data/generators/right_scaffold/templates/view_show.html.erb +10 -0
- data/init.rb +12 -0
- data/javascripts/right-autocompleter-src.js +303 -0
- data/javascripts/right-autocompleter.js +9 -0
- data/javascripts/right-behavior-src.js +240 -0
- data/javascripts/right-behavior.js +8 -0
- data/javascripts/right-calendar-src.js +855 -0
- data/javascripts/right-calendar.js +9 -0
- data/javascripts/right-dnd-src.js +555 -0
- data/javascripts/right-dnd.js +9 -0
- data/javascripts/right-effects-src.js +425 -0
- data/javascripts/right-effects.js +6 -0
- data/javascripts/right-events-src.js +369 -0
- data/javascripts/right-events.js +6 -0
- data/javascripts/right-json-src.js +176 -0
- data/javascripts/right-json.js +6 -0
- data/javascripts/right-lightbox-src.js +597 -0
- data/javascripts/right-lightbox.js +9 -0
- data/javascripts/right-rails-src.js +269 -0
- data/javascripts/right-rails.js +9 -0
- data/javascripts/right-rater-src.js +248 -0
- data/javascripts/right-rater.js +9 -0
- data/javascripts/right-selectable-src.js +507 -0
- data/javascripts/right-selectable.js +7 -0
- data/javascripts/right-slider-src.js +291 -0
- data/javascripts/right-slider.js +7 -0
- data/javascripts/right-sortable-src.js +221 -0
- data/javascripts/right-sortable.js +9 -0
- data/javascripts/right-src.js +4939 -0
- data/javascripts/right-tabs-src.js +776 -0
- data/javascripts/right-tabs.js +6 -0
- data/javascripts/right-tooltips-src.js +130 -0
- data/javascripts/right-tooltips.js +9 -0
- data/javascripts/right-ui-i18n-de.js +29 -0
- data/javascripts/right-ui-i18n-en-us.js +11 -0
- data/javascripts/right-ui-i18n-es.js +29 -0
- data/javascripts/right-ui-i18n-fr.js +29 -0
- data/javascripts/right-ui-i18n-jp.js +33 -0
- data/javascripts/right-ui-i18n-ru.js +29 -0
- data/javascripts/right-ui-i18n-uk.js +29 -0
- data/javascripts/right.js +10 -0
- data/lib/right-rails.rb +11 -0
- data/lib/right_rails/controller_extensions.rb +85 -0
- data/lib/right_rails/helpers/basic.rb +111 -0
- data/lib/right_rails/helpers/forms.rb +239 -0
- data/lib/right_rails/helpers/misc.rb +164 -0
- data/lib/right_rails/helpers/rails.rb +166 -0
- data/lib/right_rails/helpers.rb +5 -0
- data/lib/right_rails/java_script_generator.rb +313 -0
- data/lib/right_rails.rb +6 -0
- data/spec/lib/right_rails/controller_extensions_spec.rb +60 -0
- data/spec/lib/right_rails/helpers/basic_spec.rb +74 -0
- data/spec/lib/right_rails/helpers/forms_spec.rb +51 -0
- data/spec/lib/right_rails/helpers/misc_spec.rb +120 -0
- data/spec/lib/right_rails/helpers/rails_spec.rb +149 -0
- data/spec/lib/right_rails/java_script_generator_spec.rb +317 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +15 -0
- metadata +128 -0
@@ -0,0 +1,369 @@
|
|
1
|
+
/**
|
2
|
+
* Advanced dom events handling module
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2009 Nikolay V. Nemshilov aka St. <nemshilov#gma-il>
|
5
|
+
*/
|
6
|
+
|
7
|
+
/**
|
8
|
+
* The Event class additional functionality
|
9
|
+
*
|
10
|
+
* Copyright (C) 2008-2009 Nikolay V. Nemshilov aka St. <nemshilov#gma-il>
|
11
|
+
*/
|
12
|
+
Event.extend((function() {
|
13
|
+
var old_ext = Event.ext;
|
14
|
+
|
15
|
+
return {
|
16
|
+
/**
|
17
|
+
* extends a native object with additional functionality
|
18
|
+
*
|
19
|
+
* @param Event event
|
20
|
+
* @return Event same event but extended
|
21
|
+
*/
|
22
|
+
ext: function(event) {
|
23
|
+
if (!event.stop) {
|
24
|
+
old_ext.call(Event, event);
|
25
|
+
|
26
|
+
if (Event.Mouse.NAMES.includes(event.type)) {
|
27
|
+
Event.Mouse.ext(event);
|
28
|
+
} else if (defined(event.keyCode)){
|
29
|
+
Event.Keyboard.ext(event);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
return event;
|
34
|
+
},
|
35
|
+
|
36
|
+
// keyboard key codes
|
37
|
+
KEYS: {
|
38
|
+
BACKSPACE: 8,
|
39
|
+
TAB: 9,
|
40
|
+
ENTER: 13,
|
41
|
+
ESCAPE: 27,
|
42
|
+
SPACE: 32,
|
43
|
+
PAGE_UP: 33,
|
44
|
+
PAGE_DOWN: 34,
|
45
|
+
END: 35,
|
46
|
+
HOME: 36,
|
47
|
+
LEFT: 37,
|
48
|
+
UP: 38,
|
49
|
+
RIGHT: 39,
|
50
|
+
DOWN: 40,
|
51
|
+
INSERT: 45,
|
52
|
+
DELETE: 46
|
53
|
+
},
|
54
|
+
|
55
|
+
// mouse button codes
|
56
|
+
BUTTONS: (Browser.IE || Browser.Konqueror) ? {
|
57
|
+
LEFT: 1,
|
58
|
+
MIDDLE: 4,
|
59
|
+
RIGHT: 2
|
60
|
+
} : {
|
61
|
+
LEFT: 0,
|
62
|
+
MIDDLE: 1,
|
63
|
+
RIGHT: 2
|
64
|
+
}
|
65
|
+
|
66
|
+
}})());
|
67
|
+
|
68
|
+
Event.include({
|
69
|
+
/**
|
70
|
+
* constructor. pretty much plays a virtual factory, instances new events or extends
|
71
|
+
* existing ones and always returns an event instead of void as a normal constructor
|
72
|
+
*
|
73
|
+
* @param mixed native Event instance or String event name
|
74
|
+
* @param Object options
|
75
|
+
* @return Event instance
|
76
|
+
*/
|
77
|
+
initialize: function() {
|
78
|
+
var args = $A(arguments), event = args.shift(), options = args.pop() || {};
|
79
|
+
|
80
|
+
if (isString(event)) {
|
81
|
+
var name = Event.cleanName(event);
|
82
|
+
if (Event.Mouse.NAMES.includes(name)) {
|
83
|
+
event = new Event.Mouse(name, options);
|
84
|
+
} else if (Event.Keyboard.NAMES.includes(name)) {
|
85
|
+
event = new Event.Keyboard(name, options);
|
86
|
+
} else {
|
87
|
+
event = new Event.Custom(name, options);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
return Event.ext(event);
|
92
|
+
}
|
93
|
+
});
|
94
|
+
/**
|
95
|
+
* presents the basic events class
|
96
|
+
*
|
97
|
+
* Copyright (C) 2008-2009 Nikolay V. Nemshilov aka St. <nemshilov#gma-ilc-om>
|
98
|
+
*/
|
99
|
+
Event.Base = new Class({
|
100
|
+
extend: {
|
101
|
+
// basic default events options
|
102
|
+
Options: {
|
103
|
+
bubbles: true,
|
104
|
+
cancelable: true,
|
105
|
+
altKey: false,
|
106
|
+
ctrlKey: false,
|
107
|
+
shiftKey: false,
|
108
|
+
metaKey: false
|
109
|
+
}
|
110
|
+
},
|
111
|
+
|
112
|
+
/**
|
113
|
+
* basic constructor
|
114
|
+
*
|
115
|
+
* NOTE: that's a virtual constructor, it returns a new object instance
|
116
|
+
* not the actual class instance.
|
117
|
+
*
|
118
|
+
* @param String event name
|
119
|
+
* @param Object options
|
120
|
+
* @return Event new event
|
121
|
+
*/
|
122
|
+
initialize: function(name, options) {
|
123
|
+
return this.build(this.options(name, options));
|
124
|
+
},
|
125
|
+
|
126
|
+
// protected
|
127
|
+
|
128
|
+
/**
|
129
|
+
* default building method
|
130
|
+
*
|
131
|
+
* the main purpose is that IE browsers share events instaciation interface
|
132
|
+
*
|
133
|
+
* @param Object options
|
134
|
+
* @return Event new event
|
135
|
+
*/
|
136
|
+
build: Browser.IE ? function(options) {
|
137
|
+
var event = document.createEventObject();
|
138
|
+
event.type = event.eventType = "on" + options.name;
|
139
|
+
event.altKey = options.altKey;
|
140
|
+
event.ctrlKey = options.ctrlKey;
|
141
|
+
event.shiftKey = options.shiftKey;
|
142
|
+
return event;
|
143
|
+
} : null,
|
144
|
+
|
145
|
+
/**
|
146
|
+
* initial options parsing
|
147
|
+
*
|
148
|
+
* @params Sting event name
|
149
|
+
* @params Object user options
|
150
|
+
* @return Object clean options
|
151
|
+
*/
|
152
|
+
options: function(name, options) {
|
153
|
+
options = Object.merge({}, Event.Base.Options, this.Options, options);
|
154
|
+
options.name = name;
|
155
|
+
|
156
|
+
return options;
|
157
|
+
}
|
158
|
+
});
|
159
|
+
/**
|
160
|
+
* presents the mouse events class
|
161
|
+
*
|
162
|
+
* NOTE: this class generally is for an internal usage, it builds a new clean
|
163
|
+
* unextended mouse event.
|
164
|
+
* Use the Event general constructor, if you need a usual extened event.
|
165
|
+
*
|
166
|
+
* Copyright (C) 2008-2009 Nikolay V. Nemshilov aka St. <nemshilov#gma-ilc-om>
|
167
|
+
*/
|
168
|
+
Event.Mouse = new Class(Event.Base, {
|
169
|
+
|
170
|
+
extend: {
|
171
|
+
NAMES: $w('click middleclick rightclick dblclick mousedown mouseup mouseover mouseout mousemove'),
|
172
|
+
|
173
|
+
Methods: {
|
174
|
+
isLeftClick: function() {
|
175
|
+
return this.which == 1;
|
176
|
+
},
|
177
|
+
|
178
|
+
isRightClick : function() {
|
179
|
+
return this.which == 3;
|
180
|
+
}
|
181
|
+
},
|
182
|
+
|
183
|
+
/**
|
184
|
+
* proceses the event extending as if it's a mouse event
|
185
|
+
*
|
186
|
+
* @param Event new event
|
187
|
+
* @return Event extended event
|
188
|
+
*/
|
189
|
+
ext: function(event) {
|
190
|
+
$ext(event, this.Methods, true);
|
191
|
+
|
192
|
+
return event;
|
193
|
+
}
|
194
|
+
},
|
195
|
+
|
196
|
+
// default mouse events related options
|
197
|
+
Options: {
|
198
|
+
pointerX: 0,
|
199
|
+
pointerY: 0,
|
200
|
+
button: 0
|
201
|
+
},
|
202
|
+
|
203
|
+
// protecteds
|
204
|
+
build: function(options) {
|
205
|
+
var event = Browser.IE ? this.$super(options) : document.createEvent("MouseEvent");
|
206
|
+
this[Browser.IE ? 'initIE' : 'initW3C'](event, options);
|
207
|
+
return event;
|
208
|
+
},
|
209
|
+
|
210
|
+
options: function(name, options) {
|
211
|
+
options = this.$super(name, options);
|
212
|
+
options.button = Event.BUTTONS[options.name == 'rightclick' ? 'RIGHT' : options.name == 'middleclick' ? 'MIDDLE' : 'LEFT'];
|
213
|
+
options.name = Event.realName(options.name);
|
214
|
+
|
215
|
+
return options;
|
216
|
+
},
|
217
|
+
|
218
|
+
// private
|
219
|
+
initIE: function(event, options) {
|
220
|
+
event.clientX = options.pointerX;
|
221
|
+
event.clientY = options.pointerY;
|
222
|
+
event.button = options.button;
|
223
|
+
},
|
224
|
+
|
225
|
+
initW3C: function(event, options) {
|
226
|
+
event.initMouseEvent(options.name, options.bubbles, options.cancelable, document.defaultView,
|
227
|
+
name == 'dblclick' ? 2 : 1, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
|
228
|
+
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, options.element
|
229
|
+
);
|
230
|
+
}
|
231
|
+
});
|
232
|
+
|
233
|
+
try {
|
234
|
+
// boosting up the native events by preextending the prototype if available
|
235
|
+
$ext(Event.parent.prototype, Event.Mouse.Methods, true);
|
236
|
+
} catch(e) {};
|
237
|
+
|
238
|
+
/**
|
239
|
+
* presents the keyboard events class
|
240
|
+
*
|
241
|
+
* NOTE: this class generally is for an internal usage, it builds a new clean
|
242
|
+
* unextended mouse event.
|
243
|
+
* Use the Event general constructor, if you need a usual extened event.
|
244
|
+
*
|
245
|
+
* Copyright (C) 2008-2009 Nikolay V. Nemshilov aka St. <nemshilov#gma-ilc-om>
|
246
|
+
*/
|
247
|
+
Event.Keyboard = new Class(Event.Base, {
|
248
|
+
|
249
|
+
extend: {
|
250
|
+
NAMES: $w('keypress keydown keyup'),
|
251
|
+
|
252
|
+
/**
|
253
|
+
* automatically generates the key checking methods like
|
254
|
+
* isEscape()
|
255
|
+
* isEnter()
|
256
|
+
* etc
|
257
|
+
*/
|
258
|
+
Methods: {}, // generated at the end of the file
|
259
|
+
|
260
|
+
/**
|
261
|
+
* processes the event extending as a keyboard event
|
262
|
+
*
|
263
|
+
* @param Event before extending
|
264
|
+
* @return Event after extending
|
265
|
+
*/
|
266
|
+
ext: function(event) {
|
267
|
+
$ext(event, this.Methods, true);
|
268
|
+
|
269
|
+
return event;
|
270
|
+
}
|
271
|
+
},
|
272
|
+
|
273
|
+
// default keyboard related events options
|
274
|
+
Options: {
|
275
|
+
keyCode: 0,
|
276
|
+
charCode: 0
|
277
|
+
},
|
278
|
+
|
279
|
+
// protected
|
280
|
+
build: function(options) {
|
281
|
+
var event = null;
|
282
|
+
|
283
|
+
if (Browser.IE) {
|
284
|
+
event = this.$super(options);
|
285
|
+
this.initIE(event, options)
|
286
|
+
} else try {
|
287
|
+
// Gecko, WebKit, Chrome
|
288
|
+
event = document.createEvent('KeyboardEvent');
|
289
|
+
this['init'+(Browser.WebKit ? 'Webkit' : 'Gecko')](event, options);
|
290
|
+
} catch(e) {
|
291
|
+
// basically Opera
|
292
|
+
event = document.createEvent('UIEvent');
|
293
|
+
this.initDOM2(event, options);
|
294
|
+
}
|
295
|
+
|
296
|
+
return event;
|
297
|
+
},
|
298
|
+
|
299
|
+
initGecko: function(event, options) {
|
300
|
+
event.initKeyEvent(options.name,
|
301
|
+
options.bubbles, options.cancelable, document.defaultView,
|
302
|
+
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey,
|
303
|
+
options.keyCode, options.charCode
|
304
|
+
);
|
305
|
+
},
|
306
|
+
|
307
|
+
initWebkit: function(event, options) {
|
308
|
+
event.initKeyboardEvent(options.name,
|
309
|
+
options.bubbles, options.cancelable, document.defaultView,
|
310
|
+
null, 0, options.ctrlKey, options.altKey, options.shiftKey, options.metaKey
|
311
|
+
);
|
312
|
+
},
|
313
|
+
|
314
|
+
initDOM2: function(event, options) {
|
315
|
+
event.initUIEvent(options.name, options.bubbles, options.cancelable, document.defaultView, 1);
|
316
|
+
|
317
|
+
event.keyCode = options.keyCode;
|
318
|
+
event.charCode = options.charCode;
|
319
|
+
event.altKey = options.altKey;
|
320
|
+
event.metaKey = options.metaKey;
|
321
|
+
event.ctrlKey = options.ctrlKey;
|
322
|
+
event.shiftKey = options.shiftKey;
|
323
|
+
},
|
324
|
+
|
325
|
+
initIE: function(event, options) {
|
326
|
+
event.keyCode = options.keyCode;
|
327
|
+
event.charCode = options.charCode;
|
328
|
+
}
|
329
|
+
});
|
330
|
+
|
331
|
+
// generates the key checking methods
|
332
|
+
(function() {
|
333
|
+
for (var key in Event.KEYS) {
|
334
|
+
(function(key, key_code) {
|
335
|
+
Event.Keyboard.Methods[('is_'+key.toLowerCase()).camelize()] = function() {
|
336
|
+
return this.keyCode == key_code;
|
337
|
+
};
|
338
|
+
})(key, Event.KEYS[key]);
|
339
|
+
};
|
340
|
+
try {
|
341
|
+
// boosting up the native events by preextending the prototype if available
|
342
|
+
$ext(Event.parent.prototype, Event.Keyboard.Methods, true);
|
343
|
+
} catch(e) {};
|
344
|
+
})();
|
345
|
+
|
346
|
+
/**
|
347
|
+
* Reassigning the element #fire method to support the native events dispatching
|
348
|
+
*
|
349
|
+
* @copyright 2009 Nikolay V. Nemshilov aka St.
|
350
|
+
*/
|
351
|
+
Element.addMethods({
|
352
|
+
fire: function() {
|
353
|
+
var args = $A(arguments), event = new Event(args.shift(), Object.merge(args.shift(), {element: this}));
|
354
|
+
|
355
|
+
if (event instanceof Event.Custom) {
|
356
|
+
(this.$listeners || []).each(function(i) {
|
357
|
+
if (i.e == event.eventName) {
|
358
|
+
i.f.apply(this, [event].concat(i.a).concat(args));
|
359
|
+
}
|
360
|
+
}, this);
|
361
|
+
} else if (this.dispatchEvent) {
|
362
|
+
this.dispatchEvent(event);
|
363
|
+
} else {
|
364
|
+
this.fireEvent(event.eventType, event);
|
365
|
+
}
|
366
|
+
|
367
|
+
return this;
|
368
|
+
}
|
369
|
+
});
|
@@ -0,0 +1,6 @@
|
|
1
|
+
/**
|
2
|
+
* Advanced dom events handling module
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2009 Nikolay V. Nemshilov aka St. <nemshilov#gma-il>
|
5
|
+
*/
|
6
|
+
eval((function(s,d){for(var i=d.length-1;i>-1;i--)if(d[i])s=s.replace(new RegExp(i,'g'),d[i]);return s})("11.53((10(){47 o=11.54;14{54:10(e){if(!e.stop){o.call(11,e);if(11.31.48.57(e.90))11.31.54(e);49 if(defined(e.18))11.25.54(e)}14 e},82:{BACKSPACE:8,TAB:9,ENTER:13,ESCAPE:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,67:37,UP:38,61:39,DOWN:40,INSERT:45,DELETE:46},78:(19.IE||19.Konqueror)?{67:1,65:4,61:2}:{67:0,65:1,61:2}}})());11.include({63:10(){47 a=$A(70),e=a.76(),o=a.pop()||{};if(isString(e)){47 n=11.clean91(e);if(11.31.48.57(n))e=56 11.31(n,o);49 if(11.25.48.57(n))e=56 11.25(n,o);49 e=56 11.83(n,o)}14 11.54(e)}});11.69=56 75({53:{30:{29:50,22:50,20:60,17:60,16:60,28:60}},63:10(n,o){14 12.62(12.58(n,o))},62:19.IE?10(o){47 e=15.create1185();e.90=e.71=\"on\"+o.23;e.20=o.20;e.17=o.17;e.16=o.16;14 e}:81,58:10(n,o){o=85.87({},11.69.30,12.30,o);o.23=n;14 o}});11.31=56 75(11.69,{53:{48:$w('click 59 64 77 mousedown mouseup mouseover mouseout mousemove'),21:{isLeft94:10(){14 12.88==1},isRight94:10(){14 12.88==3}},54:10(e){$54(e,12.21,50);14 e}},30:{42:0,43:0,44:0},62:10(o){47 e=19.IE?12.66(o):15.create11(\"3111\");12[19.IE?'55':'79'](e,o);14 e},58:10(n,o){o=12.66(n,o);o.44=11.78[o.23=='64'?'61':o.23=='59'?'65':'67'];o.23=11.real91(o.23);14 o},55:10(e,o){e.clientX=o.42;e.clientY=o.43;e.44=o.44},79:10(e,o){e.init3111(o.23,o.29,o.22,15.26,23=='77'?2:1,o.42,o.43,o.42,o.43,o.17,o.20,o.16,o.28,o.44,o.80)}});89{$54(11.86.72,11.31.21,50)}74(e){};11.25=56 75(11.69,{53:{48:$w('keypress keydown keyup'),21:{},54:10(e){$54(e,12.21,50);14 e}},30:{18:0,24:0},62:10(o){47 a=81;if(19.IE){a=12.66(o);12.55(a,o)}49 89{a=15.create11('2511');12['init'+(19.WebKit?'92':'93')](a,o)}74(e){a=15.create11('UI11');12.73(a,o)}14 a},init93:10(e,o){e.initKey11(o.23,o.29,o.22,15.26,o.17,o.20,o.16,o.28,o.18,o.24)},init92:10(e,o){e.init2511(o.23,o.29,o.22,15.26,81,0,o.17,o.20,o.16,o.28)},73:10(e,o){e.initUI11(o.23,o.29,o.22,15.26,1);e.18=o.18;e.24=o.24;e.20=o.20;e.28=o.28;e.17=o.17;e.16=o.16},55:10(e,o){e.18=o.18;e.24=o.24}});(10(){for(47 b in 11.82)(10(k,a){11.25.21[('is_'+k.toLowerCase()).camelize()]=10(){14 12.18==a}})(b,11.82[b]);;89{$54(11.86.72,11.25.21,50)}74(e){}})();Element.add21({fire:10(){47 b=$A(70),e=56 11(b.76(),85.87(b.76(),{80:12}));if(e instanceof 11.83){(12.$listeners||[]).each(10(a){if(a.e==e.event91)a.f.apply(12,[e].84(a.a).84(b))},12)}49 if(12.dispatch11)12.dispatch11(e);49 12.fire11(e.71,e);14 12}});",",,,,,,,,,,function,Event,this,,return,document,shiftKey,ctrlKey,keyCode,Browser,altKey,Methods,cancelable,name,charCode,Keyboard,defaultView,,metaKey,bubbles,Options,Mouse,,,,,,,,,,createEvent,pointerX,pointerY,button,,,var,NAMES,else,true,,dispatchEvent,extend,ext,initIE,new,includes,options,middleclick,false,RIGHT,build,initialize,rightclick,MIDDLE,$super,LEFT,$ext,Base,arguments,eventType,prototype,initDOM2,catch,Class,shift,dblclick,BUTTONS,initW3C,element,null,KEYS,Custom,concat,Object,parent,merge,which,try,type,Name,Webkit,Gecko,Click".split(",")));
|
@@ -0,0 +1,176 @@
|
|
1
|
+
/**
|
2
|
+
* The JSON encode/decode feature
|
3
|
+
*
|
4
|
+
* Copyright (C) 2009 Nikolay V. Nemshilov aka St. <nemshilov#gma-il>
|
5
|
+
*/
|
6
|
+
|
7
|
+
/**
|
8
|
+
* String to JSON export
|
9
|
+
*
|
10
|
+
* Credits:
|
11
|
+
* Based on the original JSON escaping implementation
|
12
|
+
* http://www.json.org/json2.js
|
13
|
+
*
|
14
|
+
* @copyright (C) 2009 Nikolay V. Nemshilov aka St.
|
15
|
+
*/
|
16
|
+
(function(String_proto) {
|
17
|
+
var specials = {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\'},
|
18
|
+
quotables = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
19
|
+
|
20
|
+
// quotes the string
|
21
|
+
function quote(string) {
|
22
|
+
return string.replace(quotables, function(chr) {
|
23
|
+
return specials[chr] || '\\u' + ('0000' + chr.charCodeAt(0).toString(16)).slice(-4);
|
24
|
+
});
|
25
|
+
};
|
26
|
+
|
27
|
+
String_proto.toJSON = function() {
|
28
|
+
return '"'+ quote(this) + '"';
|
29
|
+
}
|
30
|
+
|
31
|
+
})(String.prototype);
|
32
|
+
/**
|
33
|
+
* Dates to JSON convertion
|
34
|
+
*
|
35
|
+
* Credits:
|
36
|
+
* Based on the original JSON escaping implementation
|
37
|
+
* http://www.json.org/json2.js
|
38
|
+
*
|
39
|
+
* @copyright (C) 2009 Nikolay V. Nemshilov aka St.
|
40
|
+
*/
|
41
|
+
(function(Date_proto) {
|
42
|
+
var z = function(num) {
|
43
|
+
return (num < 10 ? '0' : '')+num;
|
44
|
+
};
|
45
|
+
|
46
|
+
|
47
|
+
Date_proto.toJSON = function() {
|
48
|
+
return this.getUTCFullYear() + '-' +
|
49
|
+
z(this.getUTCMonth() + 1) + '-' +
|
50
|
+
z(this.getUTCDate()) + 'T' +
|
51
|
+
z(this.getUTCHours()) + ':' +
|
52
|
+
z(this.getUTCMinutes()) + ':' +
|
53
|
+
z(this.getUTCSeconds()) + 'Z';
|
54
|
+
};
|
55
|
+
|
56
|
+
})(Date.prototype);
|
57
|
+
/**
|
58
|
+
* Number to JSON export
|
59
|
+
*
|
60
|
+
* @copyright (C) 2009 Nikolay V. Nemshilov aka St.
|
61
|
+
*/
|
62
|
+
Number.prototype.toJSON = function() { return String(this+0); };
|
63
|
+
/**
|
64
|
+
* The boolean types to prototype export
|
65
|
+
*
|
66
|
+
* @copyright (C) 2009 Nikolay V. Nemshilov aka St.
|
67
|
+
*/
|
68
|
+
Boolean.prototype.toJSON = function() { return String(this); };
|
69
|
+
/**
|
70
|
+
* Array instances to JSON export
|
71
|
+
*
|
72
|
+
* @copyright (C) 2009 Nikolay V. Nemshilov aka St.
|
73
|
+
*/
|
74
|
+
Array.prototype.toJSON = function() {
|
75
|
+
return '['+this.map(JSON.encode).join(',')+']'
|
76
|
+
};
|
77
|
+
/**
|
78
|
+
* The Hash instances to JSON export
|
79
|
+
*
|
80
|
+
* Copyright (C) 2009 Nikolay V. Nemshilov
|
81
|
+
*/
|
82
|
+
if (window['Hash']) {
|
83
|
+
window['Hash'].prototype.toJSON = function() {
|
84
|
+
return window['JSON'].encode(this.toObject());
|
85
|
+
};
|
86
|
+
}
|
87
|
+
/**
|
88
|
+
* The generic JSON interface
|
89
|
+
*
|
90
|
+
* Credits:
|
91
|
+
* Based on the original JSON escaping implementation
|
92
|
+
* http://www.json.org/json2.js
|
93
|
+
*
|
94
|
+
* @copyright (C) 2009 Nikolay V. Nemshilov aka St.
|
95
|
+
*/
|
96
|
+
var JSON = {
|
97
|
+
encode: function(value) {
|
98
|
+
var result;
|
99
|
+
|
100
|
+
if (value === null) {
|
101
|
+
result = 'null';
|
102
|
+
} else if (value.toJSON) {
|
103
|
+
result = value.toJSON();
|
104
|
+
} else if (isHash(value)){
|
105
|
+
result = [];
|
106
|
+
for (var key in value) {
|
107
|
+
result.push(key.toJSON()+":"+JSON.encode(value[key]));
|
108
|
+
}
|
109
|
+
result = '{'+result+'}';
|
110
|
+
} else {
|
111
|
+
throw "JSON can't encode: "+value;
|
112
|
+
}
|
113
|
+
|
114
|
+
return result;
|
115
|
+
},
|
116
|
+
|
117
|
+
// see the original JSON decoder implementation for descriptions http://www.json.org/json2.js
|
118
|
+
cx: /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
119
|
+
|
120
|
+
decode: function(string) {
|
121
|
+
if (isString(string) && string) {
|
122
|
+
// getting back the UTF-8 symbols
|
123
|
+
string = string.replace(JSON.cx, function (a) {
|
124
|
+
return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
125
|
+
});
|
126
|
+
|
127
|
+
// checking the JSON string consistency
|
128
|
+
if (/^[\],:{}\s]*$/.test(string.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
129
|
+
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
130
|
+
.replace(/(?:^|:|,)(?:\s*\[)+/g, '')))
|
131
|
+
|
132
|
+
return eval('('+string+')');
|
133
|
+
}
|
134
|
+
|
135
|
+
throw "JSON parse error: "+string;
|
136
|
+
}
|
137
|
+
};
|
138
|
+
/**
|
139
|
+
* Wraps up the Cooke set/get methods so that the values
|
140
|
+
* were automatically exported/imported into JSON strings
|
141
|
+
* and it allowed transparent objects and arrays saving
|
142
|
+
*
|
143
|
+
* @copyright (C) 2009 Nikolay V. Nemshilov aka St.
|
144
|
+
*/
|
145
|
+
if (window['Cookie']) {
|
146
|
+
(function(Cookie_prototype) {
|
147
|
+
var old_set = Cookie_prototype.set,
|
148
|
+
old_get = Cookie_prototype.get;
|
149
|
+
|
150
|
+
$ext(Cookie_prototype, {
|
151
|
+
set: function(value) {
|
152
|
+
return old_set.call(this, JSON.encode(value));
|
153
|
+
},
|
154
|
+
|
155
|
+
get: function() {
|
156
|
+
return JSON.decode(old_get.call(this));
|
157
|
+
}
|
158
|
+
});
|
159
|
+
})(Cookie.prototype);
|
160
|
+
}
|
161
|
+
/**
|
162
|
+
* Better JSON sanitizing for the Xhr requests
|
163
|
+
*
|
164
|
+
* Copyright (C) 2009 Nikolay V. Nemshilov
|
165
|
+
*/
|
166
|
+
Xhr.prototype.sanitizedJSON = function() {
|
167
|
+
try {
|
168
|
+
return JSON.decode(this.text);
|
169
|
+
} catch(e) {
|
170
|
+
if (this.secureJSON) {
|
171
|
+
throw e;
|
172
|
+
} else {
|
173
|
+
return null;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
};
|
@@ -0,0 +1,6 @@
|
|
1
|
+
/**
|
2
|
+
* The JSON encode/decode feature
|
3
|
+
*
|
4
|
+
* Copyright (C) 2009 Nikolay V. Nemshilov aka St. <nemshilov#gma-il>
|
5
|
+
*/
|
6
|
+
eval((function(s,d){for(var i=d.length-1;i>-1;i--)if(d[i])s=s.replace(new RegExp(i,'g'),d[i]);return s})("(3(S){22 b={'\\b':'\\\\b','\\t':'\\\\t','\\n':'\\\\n','\\f':'\\\\f','\\r':'\\\\r','\"':'\\\\\"','\\\\\': '\\\\\\\\\'},q=/[\\\\\\\"\\x00-\\x1f\\x7f-\\x9f\\33\\46-\\41\\42\\47\\45\\35-\\43\\32-\\39\\37-\\36\\34\\38-\\40]/g;3 a(s){11 s.19(q,3(c){11 b[c]||'\\\\u'+('48'+c.23(0).to24(16)).44(-4)})};S.14=3(){11 '\"'+a(13)+'\"'}})(24.12);(3(D){22 z=3(n){11(n<10?'0':'')+n};D.14=3(){11 13.52UTCFullYear()+'-'+z(13.52UTCMonth()+1)+'-'+z(13.52UTC53())+'T'+z(13.52UTCHours())+':'+z(13.52UTCMinutes())+':'+z(13.52UTCSeconds())+'Z'}})(53.12);Number.12.14=3(){11 24(13+0)};Boolean.12.14=3(){11 24(13)};Array.12.14=3(){11 '['+13.map(15.18).join(',')+']'};if(21['50'])21['50'].12.14=3(){11 21['15'].18(13.toObject())};22 15={18:3(v){22 r;if(v===26)r='26';27 if(v.14)r=v.14();27 if(is50(v)){r=[];for(22 k in v)r.push(k.14()+\":\"+15.18(v[k]));r='{'+r+'}'}27 30 \"15 can't 18: \"+v;11 r},cx:/[\\u48\\33\\46-\\41\\42\\47\\45\\35-\\43\\32-\\39\\37-\\36\\34\\38-\\40]/g,25:3(s){if(is24(s)&&s){s=s.19(15.cx,3(b){11 '\\\\u'+('48'+b.23(0).to24(16)).44(-4)});if(/^[\\],:{}\\s]*$/.test(s.19(/\\\\(?:[\"\\\\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').19(/\"[^\"\\\\\\n\\r]*\"|true|false|26|-?\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?/g,']').19(/(?:^|:|,)(?:\\s*\\[)+/g,'')))11 eval('('+s+')')}30 \"15 parse error: \"+s}};if(21['31'])(3(C){22 a=C.51,o=C.52;$ext(C,{51:3(v){11 a.49(13,15.18(v))},52:3(){11 15.25(o.49(13))}})})(31.12);Xhr.12.sanitized15=3(){try{11 15.25(13.text)}catch(e){if(13.secure15)30 e;27 11 26}};",",,,function,,,,,,,,return,prototype,this,toJSON,JSON,,,encode,replace,,window,var,charCodeAt,String,decode,null,else,,toString,throw,Cookie,u2028,u00ad,ufeff,u200c,u206f,u2060,ufff0,u202f,uffff,u0604,u070f,u200f,slice,u17b5,u0600,u17b4,0000,call,Hash,set,get,Date".split(",")));
|