merged cont.
[opensuse:yast-rest-service.git] / webyast / vendor / plugins / jrails / javascripts / sources / jrails.js
1 /*
2 * Source: jrails plugin
3 * jRails ajax extras
4 * version 0.1
5 * <aaron@ennerchi.com> | http://www.ennerchi.com
6 *
7 */
8
9 (function($) {
10         $().ajaxSend(function(a, xhr, s){ //Set request headers globally
11                 xhr.setRequestHeader("Accept", "text/javascript, text/html, application/xml, text/xml, */*");
12         });
13 })(jQuery);
14
15
16 /*
17 *
18 * jRails form extras
19 * <aaron@ennerchi.com> | http://www.ennerchi.com
20 *
21 */
22
23
24 (function($) {
25         // reset a form
26         $.fn.reset = function() {
27                 return this.each(function() {
28                         // guard against an input with the name of 'reset'
29                         // note that IE reports the reset function as an 'object'
30                         if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType))
31                                 this.reset();
32                 });
33         };
34         // enable a form element
35         $.fn.enable = function() {
36                 return this.each(function() {
37                         this.disabled = false;
38                 });
39         };
40         // disable a form element
41         $.fn.disable = function() {
42                 return this.each(function() {
43                         this.disabled = true;
44                 });
45         };
46
47 })(jQuery);
48
49 /*
50 *
51 * jRails form observer plugin
52 * version 0.2
53 * <aaron@ennerchi.com> | http://www.ennerchi.com
54 *
55 */
56
57 (function($) {
58         $.extend({ // Translate field to event
59                 fieldEvent: function(el, obs) {
60                         var field = el[0] || el, e = 'change';
61                         if (field.type == 'radio' || field.type == 'checkbox') e = 'click';
62                         else if (obs && field.type == 'text' || field.type == 'textarea') e = 'keyup';
63                         return e;
64                 }
65         });
66         $.fn.extend({ // Delayed observer for fields and forms
67                 delayedObserver: function(delay, callback){
68                         var el = $(this);
69                         if (typeof window.delayedObserverStack == 'undefined') window.delayedObserverStack = [];
70                         if (typeof window.delayedObserverCallback == 'undefined') {
71                                 window.delayedObserverCallback = function(stackPos) {
72                                         var observed = window.delayedObserverStack[stackPos];
73                                         if (observed.timer) clearTimeout(observed.timer);
74                                         observed.timer = setTimeout(function(){
75                                                 observed.timer = null;
76                                                 observed.callback(observed.obj, observed.obj.formVal());
77                                         }, observed.delay * 1000);
78                                         observed.oldVal = observed.obj.formVal();
79                                 };
80                         }
81                         window.delayedObserverStack.push({
82                                 obj: el, timer: null, delay: delay,
83                                 oldVal: el.formVal(), callback: callback
84                         });
85                         var stackPos = window.delayedObserverStack.length-1;
86                         if (el[0].tagName == 'FORM') {
87                                 $(':input', el).each(function(){
88                                         var field = $(this);
89                                         field.bind($.fieldEvent(field, delay), function(){
90                                                 var observed = window.delayedObserverStack[stackPos];
91                                                 if (observed.obj.formVal() == observed.oldVal) return;
92                                                 else window.delayedObserverCallback(stackPos);
93                                         });
94                                 });
95                         } else {
96                                 el.bind($.fieldEvent(el, delay), function(){
97                                         var observed = window.delayedObserverStack[stackPos];
98                                         if (observed.obj.formVal() == observed.oldVal) return;
99                                         else window.delayedObserverCallback(stackPos);
100                                 });
101                         };
102                 },
103                 formVal: function() { // Gets form values
104                         var el = this[0];
105                         if(el.tagName == 'FORM') return this.serialize();
106                         if(el.type == 'checkbox' || el.type == 'radio') return this.filter('input:checked').val() || '';
107                         else return this.val();
108                 }
109         });
110 })(jQuery);
111
112 /*
113 *
114 * jRails visual effects stubs
115 * version 0.2
116 * <aaron@ennerchi.com> | http://www.ennerchi.com
117 *
118 */
119
120 (function($) {
121         $.fn.extend({
122                 visualEffect : function(o) {
123                         e = o.replace(/\_(.)/g, function(m, l){return l.toUpperCase()});
124                         return eval('$(this).'+e+'()');
125                 },
126                 appear : function(speed, callback) {
127                         return this.fadeIn(speed, callback);
128                 },
129                 blindDown : function(speed, callback) {
130                         return this.show('blind', { direction: 'vertical' }, speed, callback);
131                 },
132                 blindUp : function(speed, callback) {
133                         return this.hide('blind', { direction: 'vertical' }, speed, callback);
134                 },
135                 blindRight : function(speed, callback) {
136                         return this.show('blind', { direction: 'horizontal' }, speed, callback);
137                 },
138                 blindLeft : function(speed, callback) {
139                         this.hide('blind', { direction: 'horizontal' }, speed, callback);
140                         return this;
141                 },
142                 dropOut : function(speed, callback) {
143                         return this.hide('drop', {direction: 'down' }, speed, callback);
144                 },
145                 dropIn : function(speed, callback) {
146                         return this.show('drop', { direction: 'up' }, speed, callback);
147                 },
148                 fade : function(speed, callback) {
149                         return this.fadeOut(speed, callback);
150                 },
151                 fadeToggle : function(speed, callback) {
152                         return this.animate({opacity: 'toggle'}, speed, callback);
153                 },
154                 fold : function(speed, callback) {
155                         return this.hide('fold', {}, speed, callback);
156                 },
157                 foldOut : function(speed, callback) {
158                         return this.show('fold', {}, speed, callback);
159                 },
160                 grow : function(speed, callback) {
161                         return this.show('scale', {}, speed, callback);
162                 },
163                 highlight : function(speed, callback) {
164                         return this.show('highlight', {}, speed, callback);
165                 },
166                 puff : function(speed, callback) {
167                         return this.hide('puff', {}, speed, callback);
168                 },
169                 pulsate : function(speed, callback) {
170                         return this.show('pulsate', {}, speed, callback);
171                 },
172                 shake : function(speed, callback) {
173                         return this.show('shake', {}, speed, callback);
174                 },
175                 shrink : function(speed, callback) {
176                         return this.hide('scale', {}, speed, callback);
177                 },
178                 squish : function(speed, callback) {
179                         return this.hide('scale', { origin: ['top', 'left'] }, speed, callback);
180                 },
181                 slideUp : function(speed, callback) {
182                         return this.hide('slide', { direction: 'up'}, speed, callback);
183                 },
184                 slideDown : function(speed, callback) {
185                         return this.show('slide', { direction: 'up'}, speed, callback);
186                 },
187                 switchOff : function(speed, callback) {
188                         return this.hide('clip', {}, speed, callback);
189                 },
190                 switchOn : function(speed, callback) {
191                         return this.show('clip', {}, speed, callback);
192                 }
193         });
194 })(jQuery);