right-rails 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/init.rb +37 -8
  2. data/javascripts/right-autocompleter-src.js +55 -41
  3. data/javascripts/right-autocompleter.js +2 -2
  4. data/javascripts/right-behavior-src.js +5 -5
  5. data/javascripts/right-behavior.js +2 -2
  6. data/javascripts/right-calendar-src.js +139 -67
  7. data/javascripts/right-calendar.js +2 -2
  8. data/javascripts/right-dnd-src.js +7 -7
  9. data/javascripts/right-dnd.js +2 -2
  10. data/javascripts/right-effects-src.js +9 -9
  11. data/javascripts/right-effects.js +2 -2
  12. data/javascripts/right-events-src.js +8 -8
  13. data/javascripts/right-events.js +2 -2
  14. data/javascripts/right-in-edit-src.js +10 -8
  15. data/javascripts/right-in-edit.js +2 -2
  16. data/javascripts/right-json-src.js +14 -15
  17. data/javascripts/right-json.js +2 -2
  18. data/javascripts/right-lightbox-src.js +141 -86
  19. data/javascripts/right-lightbox.js +3 -3
  20. data/javascripts/right-olds-src.js +26 -48
  21. data/javascripts/right-olds.js +2 -2
  22. data/javascripts/right-rails-src.js +109 -31
  23. data/javascripts/right-rails.js +2 -2
  24. data/javascripts/right-rater-src.js +20 -12
  25. data/javascripts/right-rater.js +2 -2
  26. data/javascripts/right-selectable-src.js +3 -3
  27. data/javascripts/right-selectable.js +1 -1
  28. data/javascripts/right-slider-src.js +3 -3
  29. data/javascripts/right-slider.js +1 -1
  30. data/javascripts/right-sortable-src.js +28 -28
  31. data/javascripts/right-sortable.js +2 -2
  32. data/javascripts/right-src.js +612 -405
  33. data/javascripts/right-tabs-src.js +115 -44
  34. data/javascripts/right-tabs.js +2 -2
  35. data/javascripts/right-tooltips-src.js +131 -74
  36. data/javascripts/right-tooltips.js +2 -2
  37. data/javascripts/right-ui-i18n-fr.js +4 -4
  38. data/javascripts/right-uploader-src.js +170 -0
  39. data/javascripts/right-uploader.js +9 -0
  40. data/javascripts/right.js +2 -4
  41. data/lib/right_rails.rb +1 -1
  42. data/lib/right_rails/helpers/basic.rb +10 -2
  43. data/lib/right_rails/helpers/misc.rb +16 -17
  44. data/lib/right_rails/helpers/rails.rb +0 -7
  45. data/spec/lib/right_rails/helpers/basic_spec.rb +0 -1
  46. data/spec/lib/right_rails/helpers/rails_spec.rb +24 -0
  47. data/spec/spec_helper.rb +9 -1
  48. metadata +14 -5
data/init.rb CHANGED
@@ -1,12 +1,41 @@
1
1
  # Include hook code here
2
+ if defined?(Rails)
3
+ if Rails::VERSION::MAJOR == 2
4
+ # Rails 2.x.x initalizer
5
+
6
+ if defined?(ActionController)
7
+ class ActionController::Base
8
+ include RightRails::ControllerExtensions
9
+
10
+ helper RightRails::Helpers::Basic,
11
+ RightRails::Helpers::Rails,
12
+ RightRails::Helpers::Forms,
13
+ RightRails::Helpers::Misc
14
+ end
15
+ end
2
16
 
3
- if defined?(ActionController)
4
- class ActionController::Base
5
- include RightRails::ControllerExtensions
6
-
7
- helper RightRails::Helpers::Basic,
8
- RightRails::Helpers::Rails,
9
- RightRails::Helpers::Forms,
10
- RightRails::Helpers::Misc
17
+ else
18
+ # Rails 3 initializer
19
+ require 'action_controller/railtie'
20
+
21
+ if defined?(ActionController)
22
+ require 'right_rails'
23
+ require 'right_rails/controller_extensions'
24
+ require 'right_rails/java_script_generator'
25
+ require 'right_rails/helpers'
26
+ require 'right_rails/helpers/basic'
27
+ require 'right_rails/helpers/forms'
28
+ require 'right_rails/helpers/misc'
29
+ require 'right_rails/helpers/rails'
30
+
31
+ class ActionController::Base
32
+ include RightRails::ControllerExtensions
33
+
34
+ helper RightRails::Helpers::Basic,
35
+ RightRails::Helpers::Forms,
36
+ RightRails::Helpers::Misc,
37
+ RightRails::Helpers::Rails
38
+ end
39
+ end
11
40
  end
12
41
  end
@@ -3,14 +3,14 @@
3
3
  *
4
4
  * Home page: http://rightjs.org/ui/autocompleter
5
5
  *
6
- * @copyright (C) 2009 Nikolay V. Nemshilov aka St.
6
+ * @copyright (C) 2009-2010 Nikolay V. Nemshilov
7
7
  */
8
8
  if (!RightJS) { throw "Gimme RightJS. Please." };
9
9
 
10
10
  /**
11
11
  * The RightJS UI Autocompleter unit base class
12
12
  *
13
- * Copyright (C) Nikolay V. Nemshilov aka St.
13
+ * Copyright (C) 2009-2010 Nikolay V. Nemshilov
14
14
  */
15
15
  var Autocompleter = new Class(Observer, {
16
16
  extend: {
@@ -27,40 +27,29 @@ var Autocompleter = new Class(Observer, {
27
27
  cache: true, // the use the results cache
28
28
  local: null, // an optional local search results list
29
29
 
30
- fxName: 'slide',
31
- fxDuration: 'short',
30
+ fxName: 'slide', // list appearance fx name
31
+ fxDuration: 'short', // list appearance fx duration
32
32
 
33
- spinner: 'native',
33
+ spinner: 'native', // spinner element reference
34
34
 
35
- relName: 'autocompleter'
35
+ cssRule: '[rel^=autocompleter]'
36
36
  },
37
37
 
38
- // scans the document for autocompletion fields
39
- rescan: function(scope) {
40
- var key = Autocompleter.Options.relName;
41
- var reg = new RegExp('^'+key+'+\\[(.*?)\\]$');
42
-
43
- ($(scope)||document).select('input[rel^="'+key+'"]').each(function(input) {
44
- if (!input.autocompleter) {
45
- var data = input.get('data-'+key+'-options');
46
- var options = Object.merge(eval('('+data+')'));
47
- var match = input.get('rel').match(reg);
48
-
49
- if (match) {
50
- var url = match[1];
51
-
52
- // if looks like a list of local options
53
- if (url.match(/^['"].*?['"]$/)) {
54
- options.local = eval('['+url+']');
55
- } else if (!url.blank()) {
56
- options.url = url;
57
- }
58
- }
59
-
60
- new Autocompleter(input, options);
61
- }
62
- });
63
- }
38
+ current: null, // reference to the currently active options list
39
+ instances: {}, // the input <-> instance map
40
+
41
+ // finds/instances an autocompleter for the event
42
+ find: function(event) {
43
+ var input = event.target;
44
+ if (input.match(Autocompleter.Options.cssRule)) {
45
+ var uid = $uid(input);
46
+ if (!Autocompleter.instances[uid])
47
+ new Autocompleter(input);
48
+ }
49
+ },
50
+
51
+ // DEPRECATED scans the document for autocompletion fields
52
+ rescan: function(scope) { }
64
53
  },
65
54
 
66
55
  /**
@@ -70,16 +59,17 @@ var Autocompleter = new Class(Observer, {
70
59
  * @param Object options
71
60
  */
72
61
  initialize: function(input, options) {
62
+ this.input = $(input); // don't low it down!
73
63
  this.$super(options);
74
64
 
75
65
  // storing the callbacks so we could detach them later
76
66
  this._watch = this.watch.bind(this);
77
67
  this._hide = this.hide.bind(this);
78
68
 
79
- this.input = $(input).onKeyup(this._watch).onBlur(this._hide);
69
+ this.input.onKeyup(this._watch).onBlur(this._hide);
80
70
  this.container = $E('div', {'class': 'autocompleter'}).insertTo(this.input, 'after');
81
71
 
82
- this.input.autocompleter = this;
72
+ this.input.autocompleter = Autocompleter.instances[$uid(input)] = this;
83
73
  },
84
74
 
85
75
  // kills the autocompleter
@@ -91,7 +81,7 @@ var Autocompleter = new Class(Observer, {
91
81
 
92
82
  // catching up with some additonal options
93
83
  setOptions: function(options) {
94
- this.$super(options);
84
+ this.$super(this.grabOptions(options));
95
85
 
96
86
  // building the correct url template with a placeholder
97
87
  if (!this.options.url.includes('%{search}')) {
@@ -151,6 +141,28 @@ var Autocompleter = new Class(Observer, {
151
141
 
152
142
  // protected
153
143
 
144
+ // trying to extract the input element options
145
+ grabOptions: function(options) {
146
+ var input = this.input;
147
+ var options = options || eval('('+input.get('data-autocompleter-options')+')') || {};
148
+ var keys = Autocompleter.Options.cssRule.split('[').last().split(']')[0].split('^='),
149
+ key = keys[1], value = input.get(keys[0]), match;
150
+
151
+ // trying to extract options
152
+ if (value && (match = value.match(new RegExp('^'+ key +'+\\[(.*?)\\]$')))) {
153
+ match = match[1];
154
+
155
+ // deciding whether it's a list of local options or an url
156
+ if (match.match(/^['"].*?['"]$/)) {
157
+ options.local = eval('['+ match +']');
158
+ } else if (!match.blank()) {
159
+ options.url = match;
160
+ }
161
+ }
162
+
163
+ return options;
164
+ },
165
+
154
166
  // works with the 'prev' and 'next' methods
155
167
  select: function(what, fallback) {
156
168
  var current = this.container.first('li.current');
@@ -163,7 +175,7 @@ var Autocompleter = new Class(Observer, {
163
175
 
164
176
  // receives the keyboard events out of the input element
165
177
  watch: function(event) {
166
- // skip the overlaping key codes that are already watched in the hooker.js
178
+ // skip the overlaping key codes that are already watched in the document.js
167
179
  if ([27,37,38,39,40,13].include(event.keyCode)) return;
168
180
 
169
181
  if (this.input.value.length >= this.options.minLength) {
@@ -273,15 +285,12 @@ var Autocompleter = new Class(Observer, {
273
285
  /**
274
286
  * The document events hooking
275
287
  *
276
- * Copyright (C) Nikolay V. Nemshilov aka St.
288
+ * Copyright (C) 2009-2010 Nikolay V. Nemshilov
277
289
  */
278
290
  document.on({
279
- ready: function() {
280
- Autocompleter.rescan();
281
- },
282
-
283
291
  // the autocompletion list navigation
284
292
  keydown: function(event) {
293
+ // if there is an active options list, hijacking the navigation buttons
285
294
  if (Autocompleter.current) {
286
295
  var name;
287
296
 
@@ -299,6 +308,11 @@ document.on({
299
308
  event.stop();
300
309
  }
301
310
  }
311
+
312
+ // otherwise trying to find/instanciate an autocompliter
313
+ else {
314
+ Autocompleter.find(event);
315
+ }
302
316
  }
303
317
  });
304
318
 
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Home page: http://rightjs.org/ui/autocompleter
5
5
  *
6
- * @copyright (C) 2009 Nikolay V. Nemshilov aka St.
6
+ * @copyright (C) 2009-2010 Nikolay V. Nemshilov
7
7
  */
8
8
  if (!RightJS) { throw "Gimme RightJS. Please." };
9
- 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})("28 17=89 Class(Observer,{extend:{EVENTS:$w('46 33 52 101 30 57'),90:{60:41.location.href,116:'53',70:'113',47:1,80:200,35:true,62:102,106:'slide',67:'short',25:'72',91:'15'},107:11(s){28 k=17.90.91;28 r=89 73('^'+k+'+\\\\[(.*?)\\\\]$');($(s)||41).30('24[125^=\"'+k+'\"]').117(11(i){if(!i.15){28 d=i.113('data-'+k+'-16');28 o=Object.merge(119('('+d+')'));28 m=i.113('125').110(r);if(m){28 u=m[1];if(u.110(/^['\"].*?['\"]$/))o.62=119('['+u+']');81 if(!u.blank())o.60=u}89 17(i,o)}})}},initialize:11(i,o){5.103(o);5.74=5.115.36(5);5._33=5.33.36(5);5.24=$(i).onKeyup(5.74).onBlur(5._33);5.19=$E('26',{'87':'15'}).88(5.24,'111');5.24.15=5},destroy:11(){5.24.51('keyup',5.74).51('blur',5._33);delete(5.24.15);18 5},set90:11(o){5.103(o);if(!5.16.60.83('%{53}'))5.16.60+=(5.16.60.83('?')?'&':'?')+5.16.116+'=%{53}'},46:11(){if(5.19.71()){28 d=5.24.68();5.19.56({63:(d.63+d.54)+'px',49:d.49+'px',59:d.59+'px'}).46(5.16.106,{duration:5.16.67,onFinish:5.48.36(5,'46')})}18 17.22=5},33:11(){if(5.19.97()){5.19.33();5.48.36(5,'33')}17.22=102;18 5},78:11(){18 5.30('78',5.19.30('li').122())},76:11(){18 5.30('76',5.19.61('li'))},57:11(c){28 c=c||5.19.61('li.22');if(c)5.24.85=c.innerHTML.stripTags();18 5.48('57').33()},30:11(w,f){28 c=5.19.61('li.22');if(c)c=c[w]('li')||c;18 5.48('30',(c||f).65('22'))},115:11(e){if([27,37,38,39,40,13].include(e.99))18;if(5.24.85.108>=5.16.47){if(5.44)5.44.cancel();5.44=5.92.36(5).delay(5.16.80)}81 18 5.33()},92:11(){5.44=102;5.35=5.35||{};28 s=5.24.85;if(s.108<5.16.47)18 5.33();if(5.35[s])5.43(5.35[s],s);81 if(5.16.62)5.43(5.79(s),s);81 5.request=Xhr.101(5.16.60.98('%{53}',encodeURIComponent(s)),{70:5.16.70,25:5.69(),onComplete:11(r){5.48('101').43(r.responseText,s)}.36(5)})},43:11(r,s){5.19.52(r).30('li').117(11(l){l.onmouseover=11(){l.65('22')};l.onmousedown=11(){5.57(l)}.36(5)},5);if(5.16.35)5.35[s]=r;18 5.48('52').46()},79:11(s){28 r=89 73(\"(\"+73.escape(s)+\")\",'ig');18 $E('ul').insert(5.16.62.128(11(o){if(r.test(o))18 $E('li',{121:o.98(r,'<104>$1</104>')})}).compact())},69:11(){5.21=5.21||5.16.25;if(5.21=='72'){5.21=$E('26',{'87':'15-25'}).88(5.24,'111');28 c='123'.split('').128(11(a){18 $E('26',{'87':'96-'+a,121:'&raquo;'})});(11(){28 d=c.shift();c.push(d);5.21.52(d)}.36(5)).periodical(400)}if(5.16.25=='72'){28 b=5.24.68();5.21.56('visiblity: 71').46();5.21.56({visibility:'97',63:(b.63+1)+'px',54:(b.54-2)+'px',lineHeight:(b.54-2)+'px',49:(b.49+b.59-5.21.offsetWidth-1)+'px'}).33()}18 5.21}});41.on({ready:11(){17.107()},keydown:11(e){if(17.22){28 n;switch(e.99){50 27:n='33';42;50 37:n='78';42;50 39:n='76';42;50 38:n='78';42;50 40:n='76';42;50 13:n='57';42}if(n){17.22[n]();e.s63()}}}});41.write(\"<58 type=\\\"120/css\\\">26.15{93:32;82:84;z-114:77;29:32;34:0;45:0;31:white;-moz-126-105:#124 .75 .75 .109;-webkit-126-105:#124 .75 .75 .109;overflow:71}26.15 ul{118-58:32;34:0;45:0;29:32;31:32;*29-55:94 64 #95}26.15 ul li{118-58:32;100-weight:normal;34:0;45:.75 .109;29:94 64 #95;29-63:32;29-55:32;31:32;cursor:pointer}26.15 ul li:61-112{29-63:94 64 #95}26.15 ul li:122-112{29-55:94 64 #95;*29-55:32}26.15 ul li.22{31:#127}26.15-25{82:84;z-114:77;120-align:center;100-size:140%;100-family:Georgia;31:#127;color:#666;93:32;59:1em;34:0;45:0}26.15-25 26.96-1{34-49:-129}26.15-25 26.96-2{}26.15-25 26.96-3{34-49:129}</58>\");",",,,,,this,,,,,,function,,,,autocompleter,options,Autocompleter,return,container,,_spinner,current,,input,spinner,div,,var,border,select,background,none,hide,margin,cache,bind,,,,,document,break,suggest,timeout,padding,show,minLength,fire,left,case,stopObserving,update,search,height,bottom,setStyle,done,style,width,url,first,local,top,solid,radioClass,,fxDuration,dimensions,getSpinner,method,hidden,native,RegExp,_watch,2em,next,100000000,prev,findLocal,threshold,else,position,includes,absolute,value,_hide,class,insertTo,new,Options,relName,trigger,display,1px,CCC,dot,visible,replace,keyCode,font,load,null,$super,strong,shadow,fxName,rescan,length,4em,match,after,child,get,index,watch,param,each,list,eval,text,html,last,,BBB,rel,box,DDD,map,4px".split(",")));
9
+ 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})("29 16=99 Class(Observer,{extend:{EVENTS:$w('48 32 55 107 33 59'),63:{69:57.location.href,116:'53',80:'117',50:1,82:200,35:true,64:81,112:'slide',72:'short',25:'78',62:'[rel^=15]'},22:81,49:{},120:11(e){29 i=e.tar117;if(i.95(16.63.62)){29 u=125(i);if(!16.49[u])99 16(i)}},rescan:11(s){}},initialize:11(i,o){5.24=$(i);5.111(o);5.76=5.113.36(5);5._32=5.32.36(5);5.24.onKeyup(5.76).onBlur(5._32);5.19=$E('26',{'90':'15'}).94(5.24,'119');5.24.15=16.49[125(i)]=5},destroy:11(){5.24.52('keyup',5.76).52('blur',5._32);delete(5.24.15);18 5},set63:11(o){5.111(5.60(o));if(!5.17.69.93('%{53}'))5.17.69+=(5.17.69.93('?')?'&':'?')+5.17.116+'=%{53}'},48:11(){if(5.19.77()){29 d=5.24.74();5.19.56({71:(d.71+d.54)+'px',46:d.46+'px',67:d.67+'px'}).48(5.17.112,{duration:5.17.72,onFinish:5.45.36(5,'48')})}18 16.22=5},32:11(){if(5.19.96()){5.19.32();5.45.36(5,'32')}16.22=81;18 5},87:11(){18 5.33('87',5.19.33('li').105())},85:11(){18 5.33('85',5.19.61('li'))},59:11(c){29 c=c||5.19.61('li.22');if(c)5.24.89=c.innerHTML.stripTags();18 5.45('59').32()},60:11(o){29 i=5.24;29 o=o||122('('+i.117('data-15-17')+')')||{};29 a=16.63.62.68('[').105().68(']')[0].68('^='),k=a[1],v=i.117(a[0]),m;if(v&&(m=v.95(99 79('^'+k+'+\\\\[(.*?)\\\\]$')))){m=m[1];if(m.95(/^['\"].*?['\"]$/))o.64=122('['+m+']');58 if(!m.blank())o.69=m}18 o},33:11(w,f){29 c=5.19.61('li.22');if(c)c=c[w]('li')||c;18 5.45('33',(c||f).73('22'))},113:11(e){if([27,37,38,39,40,13].include(e.98))18;if(5.24.89.108>=5.17.50){if(5.44)5.44.cancel();5.44=5.102.36(5).delay(5.17.82)}58 18 5.32()},102:11(){5.44=81;5.35=5.35||{};29 s=5.24.89;if(s.108<5.17.50)18 5.32();if(5.35[s])5.42(5.35[s],s);58 if(5.17.64)5.42(5.84(s),s);58 5.request=Xhr.107(5.17.69.101('%{53}',encodeURIComponent(s)),{80:5.17.80,25:5.75(),onComplete:11(r){5.45('107').42(r.responseText,s)}.36(5)})},42:11(r,s){5.19.55(r).33('li').each(11(l){l.onmouseover=11(){l.73('22')};l.onmousedown=11(){5.59(l)}.36(5)},5);if(5.17.35)5.35[s]=r;18 5.45('55').48()},84:11(s){29 r=99 79(\"(\"+79.escape(s)+\")\",'ig');18 $E('ul').insert(5.17.64.128(11(o){if(r.test(o))18 $E('li',{121:o.101(r,'<109>$1</109>')})}).compact())},75:11(){5.21=5.21||5.17.25;if(5.21=='78'){5.21=$E('26',{'90':'15-25'}).94(5.24,'119');29 c='123'.68('').128(11(a){18 $E('26',{'90':'100-'+a,121:'&raquo;'})});(11(){29 d=c.shift();c.push(d);5.21.55(d)}.36(5)).periodical(400)}if(5.17.25=='78'){29 b=5.24.74();5.21.56('visiblity: 77').48();5.21.56({visibility:'96',71:(b.71+1)+'px',54:(b.54-2)+'px',lineHeight:(b.54-2)+'px',46:(b.46+b.67-5.21.offsetWidth-1)+'px'}).32()}18 5.21}});57.on({keydown:11(e){if(16.22){29 n;switch(e.98){47 27:n='32';41;47 37:n='87';41;47 39:n='85';41;47 38:n='87';41;47 40:n='85';41;47 13:n='59';41}if(n){16.22[n]();e.s71()}}58 16.120(e)}});57.write(\"<70 type=\\\"126/css\\\">26.15{104:30;88:91;z-118:83;28:30;34:0;43:0;31:white;-moz-129-110:#130 .86 .86 .114;-webkit-129-110:#130 .86 .86 .114;overflow:77}26.15 ul{124-70:30;34:0;43:0;28:30;31:30;*28-51:103 65 #97}26.15 ul li{124-70:30;106-weight:normal;34:0;43:.86 .114;28:103 65 #97;28-71:30;28-51:30;31:30;cursor:pointer}26.15 ul li:61-115{28-71:103 65 #97}26.15 ul li:105-115{28-51:103 65 #97;*28-51:30}26.15 ul li.22{31:#127}26.15-25{88:91;z-118:83;126-align:center;106-size:140%;106-family:Georgia;31:#127;color:#666;104:30;67:1em;34:0;43:0}26.15-25 26.100-1{34-46:-131}26.15-25 26.100-2{}26.15-25 26.100-3{34-46:131}</70>\");",",,,,,this,,,,,,function,,,,autocompleter,Autocompleter,options,return,container,,_spinner,current,,input,spinner,div,,border,var,none,background,hide,select,margin,cache,bind,,,,,break,suggest,padding,timeout,fire,left,case,show,instances,minLength,bottom,stopObserving,search,height,update,setStyle,document,else,done,grabOptions,first,cssRule,Options,local,solid,,width,split,url,style,top,fxDuration,radioClass,dimensions,getSpinner,_watch,hidden,native,RegExp,method,null,threshold,100000000,findLocal,next,2em,prev,position,value,class,absolute,_hide,includes,insertTo,match,visible,CCC,keyCode,new,dot,replace,trigger,1px,display,last,font,load,length,strong,shadow,$super,fxName,watch,4em,child,param,get,index,after,find,html,eval,,list,$uid,text,DDD,map,box,BBB,4px".split(",")));
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * See http://rightjs.org/goods/behave for more details
5
5
  *
6
- * Copyright (C) 2009 Nikolay V. Nemshilov aka St.
6
+ * Copyright (C) 2009-2010 Nikolay V. Nemshilov
7
7
  */
8
8
 
9
9
  /**
@@ -14,7 +14,7 @@
14
14
  * on the page, and will watch any updates on the page
15
15
  * and refresh the behaves automatically
16
16
  *
17
- * Copyright (C) 2009 Nikolay V. Nemshilov aka St.
17
+ * Copyright (C) 2009-2010 Nikolay V. Nemshilov
18
18
  */
19
19
  var Behavior = new Class({
20
20
  extend: {
@@ -207,9 +207,9 @@ document.onReady(Behavior.refresh);
207
207
  /**
208
208
  * The Element unit wrapups for automaticall behaves processing on the page updates
209
209
  *
210
- * Copyright (C) 2009 Nikolay V. Nemshilov aka St.
210
+ * Copyright (C) 2009-2010 Nikolay V. Nemshilov
211
211
  */
212
- Element.addMethods((function(old_methods) {
212
+ Element.include((function(old_methods) {
213
213
  var old_insert = old_methods.insert;
214
214
  var old_update = old_methods.update;
215
215
 
@@ -238,7 +238,7 @@ return {
238
238
  *
239
239
  * "div#sidebar ul li".stopBehave('click', function() {...});
240
240
  *
241
- * Copyright (C) 2009 Nikolay V Nemshilov aka St.
241
+ * Copyright (C) 2009-2010 Nikolay V Nemshilov
242
242
  */
243
243
  $ext(String.prototype, {
244
244
  /**
@@ -3,6 +3,6 @@
3
3
  *
4
4
  * See http://rightjs.org/goods/behave for more details
5
5
  *
6
- * Copyright (C) 2009 Nikolay V. Nemshilov aka St.
6
+ * Copyright (C) 2009-2010 Nikolay V. Nemshilov
7
7
  */
8
- 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})("8 4=28 Class({extend:{29:2(){8 a=$A(6);8 b=28 4(a.18());5 b.on.7(b,a).25()},16:2(r){8 b=4.10[r];if(b)b.16();5 b},delegate:2(r){5 2(a){8 e=$(a.target);24(8 s in r)if(e.match(s))5 r[s].7(3,6)}},9:2(){24(8 k in 4.10)4.10[k].9()},10:{}},12:21,17:21,14:21,initialize:2(){8 a=$A(6);3.12=a.18();3.on.7(3,a);3.14=[]},25:2(){5 4.10[3.12]=3.9()},16:2(){8 a=3.17;if(!isHash(a[0])){8 h={};h[a.18()]=a;a=h}27 a=a[0];$$(3.12).20(2(e){8 u=26(e);if(3.14[u])24(8 k in a){if(15(a[k])){a[k].20(2(o){if(15(o))e.11.7(e,[k].13(options[0]))});if(!15(a[k][0]))e.11.7(e,[k].13(a[k][0]))}27 e.11.7(e,[k].13(a[k]))}},3);3.14=[];delete(4.10[3.12]);5 3},10:2(){5 4.10[3.12]===3},on:2(){3.17=$A(6);5 3},9:2(){$$(3.12).20(2(e){8 u=26(e);if(!3.14[u]){e.on.7(e,3.17);3.14[u]=1}},3);5 3}});document.onReady(4.9);19.2930((2(a){8 o=a.23;8 b=a.22;5{23:2(){o.7(3,6);4.9();5 3},22:2(c){b.7(3,6);if(is31(c))4.9();5 3}}})(19.30));$ext(31.prototype,{behave:2(){5 4.29.7(4,[''+3].13($A(6)))},16Behave:2(){5 4.16.7(4,[''+3].13($A(6)))}});",",,function,this,Behavior,return,arguments,apply,var,refresh,active,stopObserving,rule,concat,regs,isArray,stop,args,shift,Element,each,null,update,insert,for,start,$uid,else,new,add,Methods,String".split(",")));
8
+ 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})("8 4=28 Class({extend:{29:2(){8 a=$A(6);8 b=28 4(a.18());5 b.on.7(b,a).25()},16:2(r){8 b=4.10[r];if(b)b.16();5 b},delegate:2(r){5 2(a){8 e=$(a.target);24(8 s in r)if(e.match(s))5 r[s].7(3,6)}},9:2(){24(8 k in 4.10)4.10[k].9()},10:{}},12:21,17:21,14:21,initialize:2(){8 a=$A(6);3.12=a.18();3.on.7(3,a);3.14=[]},25:2(){5 4.10[3.12]=3.9()},16:2(){8 a=3.17;if(!isHash(a[0])){8 h={};h[a.18()]=a;a=h}27 a=a[0];$$(3.12).20(2(e){8 u=26(e);if(3.14[u])24(8 k in a){if(15(a[k])){a[k].20(2(o){if(15(o))e.11.7(e,[k].13(options[0]))});if(!15(a[k][0]))e.11.7(e,[k].13(a[k][0]))}27 e.11.7(e,[k].13(a[k]))}},3);3.14=[];delete(4.10[3.12]);5 3},10:2(){5 4.10[3.12]===3},on:2(){3.17=$A(6);5 3},9:2(){$$(3.12).20(2(e){8 u=26(e);if(!3.14[u]){e.on.7(e,3.17);3.14[u]=1}},3);5 3}});document.onReady(4.9);19.include((2(a){8 o=a.23;8 b=a.22;5{23:2(){o.7(3,6);4.9();5 3},22:2(c){b.7(3,6);if(is30(c))4.9();5 3}}})(19.Methods));$ext(30.prototype,{behave:2(){5 4.29.7(4,[''+3].13($A(6)))},16Behave:2(){5 4.16.7(4,[''+3].13($A(6)))}});",",,function,this,Behavior,return,arguments,apply,var,refresh,active,stopObserving,rule,concat,regs,isArray,stop,args,shift,Element,each,null,update,insert,for,start,$uid,else,new,add,String".split(",")));
@@ -3,15 +3,14 @@
3
3
  *
4
4
  * Home page: http://rightjs.org/ui/calendar
5
5
  *
6
- * @copyright (C) 2009 Nikolay V. Nemshilov aka St.
6
+ * @copyright (C) 2009-2010 Nikolay V. Nemshilov
7
7
  */
8
8
  if (!RightJS) { throw "Gimme RightJS. Please." };
9
9
 
10
10
  /**
11
11
  * The calendar widget for RightJS
12
12
  *
13
- *
14
- * Copyright (C) 2009 Nikolay V. Nemshilov aka St.
13
+ * Copyright (C) 2009-2010 Nikolay V. Nemshilov
15
14
  */
16
15
  var Calendar = new Class(Observer, {
17
16
  extend: {
@@ -28,10 +27,11 @@ var Calendar = new Class(Observer, {
28
27
  fxDuration: 200,
29
28
  numberOfMonths: 1, // a number or [x, y] greed definition
30
29
  timePeriod: 1, // the timepicker minimal periods (in minutes, might be bigger than 60)
31
- checkTags: '*',
32
- relName: 'calendar',
30
+
33
31
  twentyFourHour: null, // null for automatic, or true|false to enforce
34
- listYears: false // show/hide the years listing buttons
32
+ listYears: false, // show/hide the years listing buttons
33
+
34
+ cssRule: '[rel^=calendar]' // css rule for calendar related elements
35
35
  },
36
36
 
37
37
  Formats: {
@@ -47,7 +47,7 @@ var Calendar = new Class(Observer, {
47
47
  Next: 'Next Month',
48
48
  Prev: 'Previous Month',
49
49
  NextYear: 'Next Year',
50
- PrevYear: 'Prev Year',
50
+ PrevYear: 'Previous Year',
51
51
 
52
52
  dayNames: $w('Sunday Monday Tuesday Wednesday Thursday Friday Saturday'),
53
53
  dayNamesShort: $w('Sun Mon Tue Wed Thu Fri Sat'),
@@ -56,26 +56,22 @@ var Calendar = new Class(Observer, {
56
56
  monthNamesShort: $w('Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec')
57
57
  },
58
58
 
59
- // scans for the auto-discoverable calendar inputs
60
- rescan: function(scope) {
61
- var key = Calendar.Options.relName;
62
- var rel_id_re = new RegExp(key+'\\[(.+?)\\]');
63
-
64
- ($(scope)||document).select(Calendar.Options.checkTags+'[rel*='+key+']').each(function(element) {
65
- var data = element.get('data-'+key+'-options');
66
- var calendar = new Calendar(eval('('+data+')') || {});
67
-
68
- var rel_id = element.get('rel').match(rel_id_re);
69
- if (rel_id) {
70
- var input = $(rel_id[1]);
71
- if (input) {
72
- calendar.assignTo(input, element);
73
- }
74
- } else {
75
- calendar.assignTo(element);
76
- }
77
- });
78
- }
59
+ current: null, // marker to the currently visible calendar
60
+ instances: {}, // list of registered instances
61
+
62
+ // finds and/or instanciates a Calendar related to the event target
63
+ find: function(event) {
64
+ var element = event.target;
65
+
66
+ if (isElement(element) && element.match(Calendar.Options.cssRule)) {
67
+ var uid = $uid(element);
68
+ return Calendar.instances[uid] = Calendar.instances[uid] ||
69
+ new Calendar(eval('('+element.get('data-calendar-options')+')'));
70
+ }
71
+ },
72
+
73
+ // DEPRECATED scans for the auto-discoverable calendar inputs
74
+ rescan: function(scope) { }
79
75
  },
80
76
 
81
77
  /**
@@ -190,8 +186,7 @@ var Calendar = new Class(Observer, {
190
186
  */
191
187
  show: function(position) {
192
188
  this.element.show(this.options.fxName, {duration: this.options.fxDuration});
193
- Calendar.current = this;
194
- return this;
189
+ return Calendar.current = this;
195
190
  },
196
191
 
197
192
  /**
@@ -210,7 +205,7 @@ var Calendar = new Class(Observer, {
210
205
  /**
211
206
  * This module handles the calendar elemnts building/updating processes
212
207
  *
213
- * Copyright (C) 2009 Nikolay V. Nemshilov aka St.
208
+ * Copyright (C) 2009-2010 Nikolay V. Nemshilov
214
209
  */
215
210
  Calendar.include({
216
211
 
@@ -440,35 +435,8 @@ Calendar.include({
440
435
  /**
441
436
  * This module handles the events connection
442
437
  *
443
- * Copyright (C) 2009 Nikolay V. Nemshilov aka St.
444
- */
445
-
446
- // the document keybindings hookup
447
- document.onKeydown(function(event) {
448
- if (Calendar.current) {
449
- var name;
450
-
451
- switch(event.keyCode) {
452
- case 27: name = 'hide'; break;
453
- case 37: name = 'prevDay'; break;
454
- case 39: name = 'nextDay'; break;
455
- case 38: name = 'prevWeek'; break;
456
- case 40: name = 'nextWeek'; break;
457
- case 34: name = 'nextMonth'; break;
458
- case 33: name = 'prevMonth'; break;
459
- case 13:
460
- Calendar.current.select(Calendar.current.date);
461
- name = 'done';
462
- break;
463
- }
464
-
465
- if (name) {
466
- Calendar.current[name]();
467
- event.stop();
468
- }
469
- }
470
- });
471
-
438
+ * Copyright (C) 2009-2010 Nikolay V. Nemshilov
439
+ */
472
440
  Calendar.include({
473
441
  /**
474
442
  * Initiates the 'select' event on the object
@@ -607,7 +575,7 @@ Calendar.include({
607
575
  /**
608
576
  * This module handles the calendar assignment to an input field
609
577
  *
610
- * Copyright (C) 2009 Nikolay V. Nemshilov aka St.
578
+ * Copyright (C) 2009-2010 Nikolay V. Nemshilov
611
579
  */
612
580
  Calendar.include({
613
581
  /**
@@ -634,7 +602,13 @@ Calendar.include({
634
602
  } else {
635
603
  input.on({
636
604
  focus: this.showAt.bind(this, input),
637
- click: function(e) { e.stop(); if (this.element.hidden()) this.showAt(input); }.bind(this),
605
+
606
+ click: function(e) {
607
+ e.stop();
608
+ if (this.element.hidden())
609
+ this.showAt(input);
610
+ }.bind(this),
611
+
638
612
  keyDown: function(e) {
639
613
  if (e.keyCode == 9 && this.element.visible())
640
614
  this.hide();
@@ -642,8 +616,6 @@ Calendar.include({
642
616
  });
643
617
  }
644
618
 
645
- document.onClick(this.hide.bind(this));
646
-
647
619
  return this;
648
620
  },
649
621
 
@@ -728,7 +700,7 @@ Calendar.include({
728
700
  * %S - Second of the minute (00..60)
729
701
  * %% - Literal ``%'' character
730
702
  *
731
- * Copyright (C) 2009 Nikolay V. Nemshilov aka St.
703
+ * Copyright (C) 2009-2010 Nikolay V. Nemshilov
732
704
  */
733
705
  Calendar.include({
734
706
 
@@ -794,7 +766,7 @@ Calendar.include({
794
766
  date = new Date();
795
767
  }
796
768
 
797
- return date;
769
+ return isNaN(date.getTime()) ? new Date : date;
798
770
  },
799
771
 
800
772
  /**
@@ -848,9 +820,109 @@ Calendar.include({
848
820
  /**
849
821
  * Calendar fields autodiscovery via the rel="calendar" attribute
850
822
  *
851
- * Copyright (C) 2009 Nikolay V. Nemshilov aka St.
823
+ * Copyright (C) 2009-2010 Nikolay V. Nemshilov
852
824
  */
853
- document.onReady(function() { Calendar.rescan(); });
825
+
826
+
827
+ (function() {
828
+ // shows a calendar by an event
829
+ var show_calendar = function(event) {
830
+ var calendar = Calendar.find(Event.ext(event));
831
+
832
+ if (calendar) {
833
+ var input = event.target;
834
+ var rule = Calendar.Options.cssRule.split('[').last();
835
+ var key = rule.split('=').last().split(']').first();
836
+ var rel_id_re = new RegExp(key+'\\[(.+?)\\]');
837
+ var rel_id = input.get(rule.split('^=')[0]);
838
+
839
+ if (rel_id && (rel_id = rel_id.match(rel_id_re))) {
840
+ input = $(rel_id[1]);
841
+ event.stop();
842
+ }
843
+
844
+ calendar.showAt(input);
845
+ }
846
+ };
847
+
848
+ // on-click handler
849
+ var on_mousedown = function(event) {
850
+ show_calendar(event);
851
+
852
+ var target = event.target;
853
+ if ([target].concat(target.parents()).first('hasClass', 'right-calendar')) event.stop();
854
+ };
855
+
856
+ var on_click = function(event) {
857
+ var target = event.target;
858
+
859
+ if (Calendar.find(event)) {
860
+ if (target.tagName == 'A')
861
+ event.stop();
862
+ } else if (Calendar.current) {
863
+ if (![target].concat(target.parents()).first('hasClass', 'right-calendar'))
864
+ Calendar.current.hide();
865
+ }
866
+ };
867
+
868
+ // on-focus handler
869
+ var on_focus = function(event) {
870
+ show_calendar(event);
871
+ };
872
+
873
+ // on-blur handler
874
+ var on_blur = function(event) {
875
+ var calendar = Calendar.find(Event.ext(event));
876
+
877
+ if (calendar)
878
+ calendar.hide();
879
+ };
880
+
881
+ var on_keydown = function(event) {
882
+ if (Calendar.current) {
883
+ var name;
884
+
885
+ switch(event.keyCode) {
886
+ case 27: name = 'hide'; break;
887
+ case 37: name = 'prevDay'; break;
888
+ case 39: name = 'nextDay'; break;
889
+ case 38: name = 'prevWeek'; break;
890
+ case 40: name = 'nextWeek'; break;
891
+ case 34: name = 'nextMonth'; break;
892
+ case 33: name = 'prevMonth'; break;
893
+ case 13:
894
+ Calendar.current.select(Calendar.current.date);
895
+ name = 'done';
896
+ break;
897
+ }
898
+
899
+ if (name) {
900
+ Calendar.current[name]();
901
+ event.stop();
902
+ }
903
+ }
904
+ };
905
+
906
+
907
+ document.on({
908
+ mousedown: on_mousedown,
909
+ click: on_click,
910
+ keydown: on_keydown
911
+ });
912
+
913
+ // the focus and blur events need some extra care
914
+ if (Browser.IE) {
915
+ // IE version
916
+ document.attachEvent('onfocusin', on_focus);
917
+ document.attachEvent('onfocusout', on_blur);
918
+ } else {
919
+ // W3C version
920
+ document.addEventListener('focus', on_focus, true);
921
+ document.addEventListener('blur', on_blur, true);
922
+ }
923
+ })();
924
+
925
+
854
926
 
855
927
 
856
928
  document.write("<style type=\"text/css\">div.right-calendar,div.right-calendar table,div.right-calendar table tr,div.right-calendar table th,div.right-calendar table td,div.right-calendar table tbody,div.right-calendar table thead{background:none;border:none;width:auto;height:auto;margin:0;padding:0}*.right-ui-button{display:inline-block;*display:inline;*zoom:1;height:1em;line-height:1em;padding:.2em .5em;text-align:center;border:1px solid #CCC;border-radius:.2em;-moz-border-radius:.2em;-webkit-border-radius:.2em;cursor:pointer;color:#555;background-color:#FFF}*.right-ui-button:hover{color:#222;border-color:#999;background-color:#CCC}*.right-ui-button-disabled,*.right-ui-button-disabled:hover{color:#888;background:#EEE;border-color:#CCC;cursor:default}*.right-ui-buttons{margin-top:.5em}div.right-calendar{position:absolute;height:auto;border:1px solid #BBB;position:relative;padding:.5em;border-radius:.3em;-moz-border-radius:.3em;-webkit-border-radius:.3em;cursor:default;background-color:#EEE;-moz-box-shadow:.2em .4em .8em #666;-webkit-box-shadow:.2em .4em .8em #666}div.right-calendar-inline{position:relative;display:inline-block;vertical-align:top;*display:inline;*zoom:1;-moz-box-shadow:none;-webkit-box-shadow:none}div.right-calendar-prev-button,div.right-calendar-next-button,div.right-calendar-prev-year-button,div.right-calendar-next-year-button{position:absolute;float:left;width:1em;padding:.15em .4em}div.right-calendar-next-button{right:.5em}div.right-calendar-prev-year-button{left:2.55em}div.right-calendar-next-year-button{right:2.55em}div.right-calendar-month-caption{text-align:center;height:1.2em;line-height:1.2em}table.right-calendar-greed{border-spacing:0px}table.right-calendar-greed td{vertical-align:top;padding-right:.4em}table.right-calendar-greed>tbody>td:last-child{padding:0}div.right-calendar-month table{margin-top:.2em;border-spacing:1px;border-collapse:separate}div.right-calendar-month table th{color:#777;text-align:center}div.right-calendar-month table td{text-align:right;padding:.1em .3em;background-color:#FFF;border:1px solid #CCC;cursor:pointer;color:#555;border-radius:.2em;-moz-border-radius:.2em;-webkit-border-radius:.2em}div.right-calendar-month table td:hover{background-color:#CCC;border-color:#AAA;color:#000}div.right-calendar-month table td.right-calendar-day-blank{background:transparent;cursor:default;border:none}div.right-calendar-month table td.right-calendar-day-selected{background-color:#BBB;border-color:#AAA;color:#222;font-weight:bold;padding:.1em .2em}div.right-calendar-month table td.right-calendar-day-disabled{color:#888;background:#EEE;border-color:#CCC;cursor:default}div.right-calendar-time{border-top:1px solid #ccc;margin-top:.3em;padding-top:.5em;text-align:center}div.right-calendar-time select{margin:0 .4em}div.right-calendar-buttons div.right-ui-button{width:3.2em}div.right-calendar-done-button{position:absolute;right:.5em}</style>");