win_gui 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. data/.gitignore +21 -21
  2. data/HISTORY +7 -0
  3. data/LICENSE +20 -20
  4. data/README.rdoc +77 -114
  5. data/Rakefile +24 -58
  6. data/VERSION +1 -1
  7. data/features/support/env.rb +7 -4
  8. data/features/win_gui.feature +9 -9
  9. data/lib/version.rb +8 -0
  10. data/lib/win_gui/window.rb +78 -69
  11. data/lib/win_gui.rb +25 -3
  12. data/spec/spec.opts +1 -1
  13. data/spec/spec_helper.rb +90 -118
  14. data/spec/win_gui/window_spec.rb +120 -123
  15. data/tasks/common.rake +14 -0
  16. data/tasks/doc.rake +14 -0
  17. data/tasks/gem.rake +39 -0
  18. data/tasks/git.rake +34 -0
  19. data/tasks/spec.rake +19 -0
  20. data/tasks/version.rake +71 -0
  21. metadata +68 -188
  22. data/.document +0 -5
  23. data/book_code/early_success/bundle.rb +0 -34
  24. data/book_code/early_success/english.txt +0 -1
  25. data/book_code/early_success/jruby_basics.rb +0 -47
  26. data/book_code/early_success/windows_basics.rb +0 -97
  27. data/book_code/guessing/locknote.rb +0 -379
  28. data/book_code/guessing/monkeyshines.rb +0 -14
  29. data/book_code/guessing/note.rb +0 -120
  30. data/book_code/guessing/note_spec.rb +0 -175
  31. data/book_code/guessing/replay.rb +0 -21
  32. data/book_code/guessing/seed.rb +0 -9
  33. data/book_code/guessing/spec_helper.rb +0 -69
  34. data/book_code/guessing/windows_gui.rb +0 -247
  35. data/book_code/home_stretch/junquenote.rb +0 -151
  36. data/book_code/home_stretch/locknote.rb +0 -180
  37. data/book_code/home_stretch/note.rb +0 -144
  38. data/book_code/home_stretch/note_spec.rb +0 -191
  39. data/book_code/home_stretch/spec_helper.rb +0 -55
  40. data/book_code/home_stretch/swing_gui.rb +0 -50
  41. data/book_code/home_stretch/windows_gui.rb +0 -232
  42. data/book_code/junquenote/exports.sh +0 -10
  43. data/book_code/junquenote/jruby_mac.sh +0 -10
  44. data/book_code/junquenote/junquenote_app.rb +0 -262
  45. data/book_code/novite/Rakefile +0 -10
  46. data/book_code/novite/app/controllers/application.rb +0 -18
  47. data/book_code/novite/app/controllers/guests_controller.rb +0 -28
  48. data/book_code/novite/app/controllers/parties_controller.rb +0 -77
  49. data/book_code/novite/app/helpers/application_helper.rb +0 -11
  50. data/book_code/novite/app/helpers/guests_helper.rb +0 -10
  51. data/book_code/novite/app/helpers/parties_helper.rb +0 -10
  52. data/book_code/novite/app/models/guest.rb +0 -11
  53. data/book_code/novite/app/models/party.rb +0 -32
  54. data/book_code/novite/app/models/party_mailer.rb +0 -19
  55. data/book_code/novite/app/views/layouts/application.rhtml +0 -44
  56. data/book_code/novite/app/views/parties/new.html.erb +0 -42
  57. data/book_code/novite/app/views/parties/show.html.erb +0 -43
  58. data/book_code/novite/app/views/party_mailer/invite.erb +0 -17
  59. data/book_code/novite/config/boot.rb +0 -117
  60. data/book_code/novite/config/database.yml +0 -19
  61. data/book_code/novite/config/environment.rb +0 -67
  62. data/book_code/novite/config/environments/development.rb +0 -29
  63. data/book_code/novite/config/environments/production.rb +0 -27
  64. data/book_code/novite/config/environments/test.rb +0 -30
  65. data/book_code/novite/config/initializers/inflections.rb +0 -18
  66. data/book_code/novite/config/initializers/mime_types.rb +0 -13
  67. data/book_code/novite/config/routes.rb +0 -47
  68. data/book_code/novite/db/migrate/001_create_parties.rb +0 -26
  69. data/book_code/novite/db/migrate/002_create_guests.rb +0 -23
  70. data/book_code/novite/db/schema.rb +0 -41
  71. data/book_code/novite/log/empty.txt +0 -0
  72. data/book_code/novite/public/.htaccess +0 -40
  73. data/book_code/novite/public/404.html +0 -38
  74. data/book_code/novite/public/422.html +0 -38
  75. data/book_code/novite/public/500.html +0 -38
  76. data/book_code/novite/public/dispatch.cgi +0 -10
  77. data/book_code/novite/public/dispatch.fcgi +0 -24
  78. data/book_code/novite/public/dispatch.rb +0 -18
  79. data/book_code/novite/public/favicon.ico +0 -0
  80. data/book_code/novite/public/images/rails.png +0 -0
  81. data/book_code/novite/public/index.html +0 -285
  82. data/book_code/novite/public/javascripts/application.js +0 -10
  83. data/book_code/novite/public/javascripts/controls.js +0 -971
  84. data/book_code/novite/public/javascripts/dragdrop.js +0 -980
  85. data/book_code/novite/public/javascripts/effects.js +0 -1128
  86. data/book_code/novite/public/javascripts/prototype.js +0 -4233
  87. data/book_code/novite/public/robots.txt +0 -5
  88. data/book_code/novite/script/about +0 -3
  89. data/book_code/novite/script/console +0 -3
  90. data/book_code/novite/script/destroy +0 -3
  91. data/book_code/novite/script/generate +0 -3
  92. data/book_code/novite/script/performance/benchmarker +0 -3
  93. data/book_code/novite/script/performance/profiler +0 -3
  94. data/book_code/novite/script/performance/request +0 -3
  95. data/book_code/novite/script/plugin +0 -3
  96. data/book_code/novite/script/process/inspector +0 -3
  97. data/book_code/novite/script/process/reaper +0 -3
  98. data/book_code/novite/script/process/spawner +0 -3
  99. data/book_code/novite/script/runner +0 -3
  100. data/book_code/novite/script/server +0 -3
  101. data/book_code/novite/test/test_helper.rb +0 -46
  102. data/book_code/one_more_thing/applescript.rb +0 -68
  103. data/book_code/one_more_thing/note_spec.rb +0 -50
  104. data/book_code/one_more_thing/spec_helper.rb +0 -17
  105. data/book_code/one_more_thing/textedit-pure.rb +0 -28
  106. data/book_code/one_more_thing/textedit.applescript +0 -26
  107. data/book_code/one_more_thing/textedit.rb +0 -32
  108. data/book_code/one_more_thing/textnote.rb +0 -87
  109. data/book_code/simplify/junquenote.rb +0 -48
  110. data/book_code/simplify/locknote.rb +0 -46
  111. data/book_code/simplify/note.rb +0 -35
  112. data/book_code/simplify/note_spec.rb +0 -28
  113. data/book_code/simplify/swing_gui.rb +0 -45
  114. data/book_code/simplify/windows_gui.rb +0 -232
  115. data/book_code/simplify/windows_gui_spec.rb +0 -35
  116. data/book_code/story/invite.story +0 -19
  117. data/book_code/story/journal.txt +0 -29
  118. data/book_code/story/novite_stories.rb +0 -156
  119. data/book_code/story/party.rb +0 -149
  120. data/book_code/story/password.rb +0 -61
  121. data/book_code/story/password.story +0 -26
  122. data/book_code/story/rsvp.story +0 -29
  123. data/book_code/tables/TestTime.html +0 -93
  124. data/book_code/tables/TestTimeSample.html +0 -63
  125. data/book_code/tables/calculate_time.rb +0 -39
  126. data/book_code/tables/calculator.rb +0 -108
  127. data/book_code/tables/calculator_actions.rb +0 -27
  128. data/book_code/tables/calculator_spec.rb +0 -47
  129. data/book_code/tables/fit.rb +0 -32
  130. data/book_code/tables/matrix.rb +0 -109
  131. data/book_code/tables/pseudocode.rb +0 -17
  132. data/book_code/tubes/book_selenium.rb +0 -67
  133. data/book_code/tubes/book_watir.rb +0 -60
  134. data/book_code/tubes/dragdrop.html +0 -81
  135. data/book_code/tubes/html_capture.rb +0 -33
  136. data/book_code/tubes/joke_list.rb +0 -67
  137. data/book_code/tubes/list_spec.rb +0 -41
  138. data/book_code/tubes/search_spec.rb +0 -32
  139. data/book_code/tubes/selenium_example.rb +0 -66
  140. data/book_code/tubes/selenium_link.rb +0 -23
  141. data/book_code/tubes/web_server.rb +0 -14
  142. data/book_code/windows/wgui.rb +0 -29
  143. data/book_code/windows/wobj.rb +0 -25
  144. data/book_code/windows/wsh.rb +0 -25
  145. data/book_code/with_rspec/empty_spec.rb +0 -13
  146. data/book_code/with_rspec/junquenote.rb +0 -60
  147. data/book_code/with_rspec/locknote.rb +0 -129
  148. data/book_code/with_rspec/note_spec.rb +0 -32
  149. data/book_code/with_rspec/should_examples.rb +0 -18
  150. data/lib/note/java/jemmy.jar +0 -0
  151. data/lib/note/java/jnote.rb +0 -48
  152. data/lib/note/java/jruby_basics.rb +0 -37
  153. data/lib/note/java/junquenote_app.rb +0 -262
  154. data/lib/note/java/note_spec.rb +0 -20
  155. data/lib/note/win/locknote.rb +0 -19
  156. data/lib/note.rb +0 -15
  157. data/lib/win_gui/constants.rb +0 -82
  158. data/lib/win_gui/def_api.rb +0 -160
  159. data/lib/win_gui/string_extensions.rb +0 -36
  160. data/lib/win_gui/win_gui.rb +0 -437
  161. data/old/windows_basics.rb +0 -80
  162. data/old/wnote.rb +0 -80
  163. data/old/wnote_spec.rb +0 -20
  164. data/spec/note/win/locknote_spec.rb +0 -7
  165. data/spec/test_apps/locknote/LockNote.exe +0 -0
  166. data/spec/win_gui/def_api_spec.rb +0 -339
  167. data/spec/win_gui/string_extensions_spec.rb +0 -61
  168. data/spec/win_gui/win_gui_spec.rb +0 -537
  169. data/win_gui.gemspec +0 -215
@@ -1,980 +0,0 @@
1
- /***
2
- * Excerpted from "Scripted GUI Testing With Ruby",
3
- * published by The Pragmatic Bookshelf.
4
- * Copyrights apply to this code. It may not be used to create training material,
5
- * courses, books, articles, and the like. Contact us if you are in doubt.
6
- * We make no guarantees that this code is fit for any purpose.
7
- * Visit http://www.pragmaticprogrammer.com/titles/idgtr for more book information.
8
- ***/
9
- // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
10
- // (c) 2005-2007 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)
11
- //
12
- // script.aculo.us is freely distributable under the terms of an MIT-style license.
13
- // For details, see the script.aculo.us web site: http://script.aculo.us/
14
-
15
- if(Object.isUndefined(Effect))
16
- throw("dragdrop.js requires including script.aculo.us' effects.js library");
17
-
18
- var Droppables = {
19
- drops: [],
20
-
21
- remove: function(element) {
22
- this.drops = this.drops.reject(function(d) { return d.element==$(element) });
23
- },
24
-
25
- add: function(element) {
26
- element = $(element);
27
- var options = Object.extend({
28
- greedy: true,
29
- hoverclass: null,
30
- tree: false
31
- }, arguments[1] || { });
32
-
33
- // cache containers
34
- if(options.containment) {
35
- options._containers = [];
36
- var containment = options.containment;
37
- if(Object.isArray(containment)) {
38
- containment.each( function(c) { options._containers.push($(c)) });
39
- } else {
40
- options._containers.push($(containment));
41
- }
42
- }
43
-
44
- if(options.accept) options.accept = [options.accept].flatten();
45
-
46
- Element.makePositioned(element); // fix IE
47
- options.element = element;
48
-
49
- this.drops.push(options);
50
- },
51
-
52
- findDeepestChild: function(drops) {
53
- deepest = drops[0];
54
-
55
- for (i = 1; i < drops.length; ++i)
56
- if (Element.isParent(drops[i].element, deepest.element))
57
- deepest = drops[i];
58
-
59
- return deepest;
60
- },
61
-
62
- isContained: function(element, drop) {
63
- var containmentNode;
64
- if(drop.tree) {
65
- containmentNode = element.treeNode;
66
- } else {
67
- containmentNode = element.parentNode;
68
- }
69
- return drop._containers.detect(function(c) { return containmentNode == c });
70
- },
71
-
72
- isAffected: function(point, element, drop) {
73
- return (
74
- (drop.element!=element) &&
75
- ((!drop._containers) ||
76
- this.isContained(element, drop)) &&
77
- ((!drop.accept) ||
78
- (Element.classNames(element).detect(
79
- function(v) { return drop.accept.include(v) } ) )) &&
80
- Position.within(drop.element, point[0], point[1]) );
81
- },
82
-
83
- deactivate: function(drop) {
84
- if(drop.hoverclass)
85
- Element.removeClassName(drop.element, drop.hoverclass);
86
- this.last_active = null;
87
- },
88
-
89
- activate: function(drop) {
90
- if(drop.hoverclass)
91
- Element.addClassName(drop.element, drop.hoverclass);
92
- this.last_active = drop;
93
- },
94
-
95
- show: function(point, element) {
96
- if(!this.drops.length) return;
97
- var drop, affected = [];
98
-
99
- this.drops.each( function(drop) {
100
- if(Droppables.isAffected(point, element, drop))
101
- affected.push(drop);
102
- });
103
-
104
- if(affected.length>0)
105
- drop = Droppables.findDeepestChild(affected);
106
-
107
- if(this.last_active && this.last_active != drop) this.deactivate(this.last_active);
108
- if (drop) {
109
- Position.within(drop.element, point[0], point[1]);
110
- if(drop.onHover)
111
- drop.onHover(element, drop.element, Position.overlap(drop.overlap, drop.element));
112
-
113
- if (drop != this.last_active) Droppables.activate(drop);
114
- }
115
- },
116
-
117
- fire: function(event, element) {
118
- if(!this.last_active) return;
119
- Position.prepare();
120
-
121
- if (this.isAffected([Event.pointerX(event), Event.pointerY(event)], element, this.last_active))
122
- if (this.last_active.onDrop) {
123
- this.last_active.onDrop(element, this.last_active.element, event);
124
- return true;
125
- }
126
- },
127
-
128
- reset: function() {
129
- if(this.last_active)
130
- this.deactivate(this.last_active);
131
- }
132
- }
133
-
134
- var Draggables = {
135
- drags: [],
136
- observers: [],
137
-
138
- register: function(draggable) {
139
- if(this.drags.length == 0) {
140
- this.eventMouseUp = this.endDrag.bindAsEventListener(this);
141
- this.eventMouseMove = this.updateDrag.bindAsEventListener(this);
142
- this.eventKeypress = this.keyPress.bindAsEventListener(this);
143
-
144
- Event.observe(document, "mouseup", this.eventMouseUp);
145
- Event.observe(document, "mousemove", this.eventMouseMove);
146
- Event.observe(document, "keypress", this.eventKeypress);
147
- }
148
- this.drags.push(draggable);
149
- },
150
-
151
- unregister: function(draggable) {
152
- this.drags = this.drags.reject(function(d) { return d==draggable });
153
- if(this.drags.length == 0) {
154
- Event.stopObserving(document, "mouseup", this.eventMouseUp);
155
- Event.stopObserving(document, "mousemove", this.eventMouseMove);
156
- Event.stopObserving(document, "keypress", this.eventKeypress);
157
- }
158
- },
159
-
160
- activate: function(draggable) {
161
- if(draggable.options.delay) {
162
- this._timeout = setTimeout(function() {
163
- Draggables._timeout = null;
164
- window.focus();
165
- Draggables.activeDraggable = draggable;
166
- }.bind(this), draggable.options.delay);
167
- } else {
168
- window.focus(); // allows keypress events if window isn't currently focused, fails for Safari
169
- this.activeDraggable = draggable;
170
- }
171
- },
172
-
173
- deactivate: function() {
174
- this.activeDraggable = null;
175
- },
176
-
177
- updateDrag: function(event) {
178
- if(!this.activeDraggable) return;
179
- var pointer = [Event.pointerX(event), Event.pointerY(event)];
180
- // Mozilla-based browsers fire successive mousemove events with
181
- // the same coordinates, prevent needless redrawing (moz bug?)
182
- if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return;
183
- this._lastPointer = pointer;
184
-
185
- this.activeDraggable.updateDrag(event, pointer);
186
- },
187
-
188
- endDrag: function(event) {
189
- if(this._timeout) {
190
- clearTimeout(this._timeout);
191
- this._timeout = null;
192
- }
193
- if(!this.activeDraggable) return;
194
- this._lastPointer = null;
195
- this.activeDraggable.endDrag(event);
196
- this.activeDraggable = null;
197
- },
198
-
199
- keyPress: function(event) {
200
- if(this.activeDraggable)
201
- this.activeDraggable.keyPress(event);
202
- },
203
-
204
- addObserver: function(observer) {
205
- this.observers.push(observer);
206
- this._cacheObserverCallbacks();
207
- },
208
-
209
- removeObserver: function(element) { // element instead of observer fixes mem leaks
210
- this.observers = this.observers.reject( function(o) { return o.element==element });
211
- this._cacheObserverCallbacks();
212
- },
213
-
214
- notify: function(eventName, draggable, event) { // 'onStart', 'onEnd', 'onDrag'
215
- if(this[eventName+'Count'] > 0)
216
- this.observers.each( function(o) {
217
- if(o[eventName]) o[eventName](eventName, draggable, event);
218
- });
219
- if(draggable.options[eventName]) draggable.options[eventName](draggable, event);
220
- },
221
-
222
- _cacheObserverCallbacks: function() {
223
- ['onStart','onEnd','onDrag'].each( function(eventName) {
224
- Draggables[eventName+'Count'] = Draggables.observers.select(
225
- function(o) { return o[eventName]; }
226
- ).length;
227
- });
228
- }
229
- }
230
-
231
- /*--------------------------------------------------------------------------*/
232
-
233
- var Draggable = Class.create({
234
- initialize: function(element) {
235
- var defaults = {
236
- handle: false,
237
- reverteffect: function(element, top_offset, left_offset) {
238
- var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02;
239
- new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur,
240
- queue: {scope:'_draggable', position:'end'}
241
- });
242
- },
243
- endeffect: function(element) {
244
- var toOpacity = Object.isNumber(element._opacity) ? element._opacity : 1.0;
245
- new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity,
246
- queue: {scope:'_draggable', position:'end'},
247
- afterFinish: function(){
248
- Draggable._dragging[element] = false
249
- }
250
- });
251
- },
252
- zindex: 1000,
253
- revert: false,
254
- quiet: false,
255
- scroll: false,
256
- scrollSensitivity: 20,
257
- scrollSpeed: 15,
258
- snap: false, // false, or xy or [x,y] or function(x,y){ return [x,y] }
259
- delay: 0
260
- };
261
-
262
- if(!arguments[1] || Object.isUndefined(arguments[1].endeffect))
263
- Object.extend(defaults, {
264
- starteffect: function(element) {
265
- element._opacity = Element.getOpacity(element);
266
- Draggable._dragging[element] = true;
267
- new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});
268
- }
269
- });
270
-
271
- var options = Object.extend(defaults, arguments[1] || { });
272
-
273
- this.element = $(element);
274
-
275
- if(options.handle && Object.isString(options.handle))
276
- this.handle = this.element.down('.'+options.handle, 0);
277
-
278
- if(!this.handle) this.handle = $(options.handle);
279
- if(!this.handle) this.handle = this.element;
280
-
281
- if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) {
282
- options.scroll = $(options.scroll);
283
- this._isScrollChild = Element.childOf(this.element, options.scroll);
284
- }
285
-
286
- Element.makePositioned(this.element); // fix IE
287
-
288
- this.options = options;
289
- this.dragging = false;
290
-
291
- this.eventMouseDown = this.initDrag.bindAsEventListener(this);
292
- Event.observe(this.handle, "mousedown", this.eventMouseDown);
293
-
294
- Draggables.register(this);
295
- },
296
-
297
- destroy: function() {
298
- Event.stopObserving(this.handle, "mousedown", this.eventMouseDown);
299
- Draggables.unregister(this);
300
- },
301
-
302
- currentDelta: function() {
303
- return([
304
- parseInt(Element.getStyle(this.element,'left') || '0'),
305
- parseInt(Element.getStyle(this.element,'top') || '0')]);
306
- },
307
-
308
- initDrag: function(event) {
309
- if(!Object.isUndefined(Draggable._dragging[this.element]) &&
310
- Draggable._dragging[this.element]) return;
311
- if(Event.isLeftClick(event)) {
312
- // abort on form elements, fixes a Firefox issue
313
- var src = Event.element(event);
314
- if((tag_name = src.tagName.toUpperCase()) && (
315
- tag_name=='INPUT' ||
316
- tag_name=='SELECT' ||
317
- tag_name=='OPTION' ||
318
- tag_name=='BUTTON' ||
319
- tag_name=='TEXTAREA')) return;
320
-
321
- var pointer = [Event.pointerX(event), Event.pointerY(event)];
322
- var pos = Position.cumulativeOffset(this.element);
323
- this.offset = [0,1].map( function(i) { return (pointer[i] - pos[i]) });
324
-
325
- Draggables.activate(this);
326
- Event.stop(event);
327
- }
328
- },
329
-
330
- startDrag: function(event) {
331
- this.dragging = true;
332
- if(!this.delta)
333
- this.delta = this.currentDelta();
334
-
335
- if(this.options.zindex) {
336
- this.originalZ = parseInt(Element.getStyle(this.element,'z-index') || 0);
337
- this.element.style.zIndex = this.options.zindex;
338
- }
339
-
340
- if(this.options.ghosting) {
341
- this._clone = this.element.cloneNode(true);
342
- this.element._originallyAbsolute = (this.element.getStyle('position') == 'absolute');
343
- if (!this.element._originallyAbsolute)
344
- Position.absolutize(this.element);
345
- this.element.parentNode.insertBefore(this._clone, this.element);
346
- }
347
-
348
- if(this.options.scroll) {
349
- if (this.options.scroll == window) {
350
- var where = this._getWindowScroll(this.options.scroll);
351
- this.originalScrollLeft = where.left;
352
- this.originalScrollTop = where.top;
353
- } else {
354
- this.originalScrollLeft = this.options.scroll.scrollLeft;
355
- this.originalScrollTop = this.options.scroll.scrollTop;
356
- }
357
- }
358
-
359
- Draggables.notify('onStart', this, event);
360
-
361
- if(this.options.starteffect) this.options.starteffect(this.element);
362
- },
363
-
364
- updateDrag: function(event, pointer) {
365
- if(!this.dragging) this.startDrag(event);
366
-
367
- if(!this.options.quiet){
368
- Position.prepare();
369
- Droppables.show(pointer, this.element);
370
- }
371
-
372
- Draggables.notify('onDrag', this, event);
373
-
374
- this.draw(pointer);
375
- if(this.options.change) this.options.change(this);
376
-
377
- if(this.options.scroll) {
378
- this.stopScrolling();
379
-
380
- var p;
381
- if (this.options.scroll == window) {
382
- with(this._getWindowScroll(this.options.scroll)) { p = [ left, top, left+width, top+height ]; }
383
- } else {
384
- p = Position.page(this.options.scroll);
385
- p[0] += this.options.scroll.scrollLeft + Position.deltaX;
386
- p[1] += this.options.scroll.scrollTop + Position.deltaY;
387
- p.push(p[0]+this.options.scroll.offsetWidth);
388
- p.push(p[1]+this.options.scroll.offsetHeight);
389
- }
390
- var speed = [0,0];
391
- if(pointer[0] < (p[0]+this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[0]+this.options.scrollSensitivity);
392
- if(pointer[1] < (p[1]+this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[1]+this.options.scrollSensitivity);
393
- if(pointer[0] > (p[2]-this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[2]-this.options.scrollSensitivity);
394
- if(pointer[1] > (p[3]-this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[3]-this.options.scrollSensitivity);
395
- this.startScrolling(speed);
396
- }
397
-
398
- // fix AppleWebKit rendering
399
- if(Prototype.Browser.WebKit) window.scrollBy(0,0);
400
-
401
- Event.stop(event);
402
- },
403
-
404
- finishDrag: function(event, success) {
405
- this.dragging = false;
406
-
407
- if(this.options.quiet){
408
- Position.prepare();
409
- var pointer = [Event.pointerX(event), Event.pointerY(event)];
410
- Droppables.show(pointer, this.element);
411
- }
412
-
413
- if(this.options.ghosting) {
414
- if (!this.element._originallyAbsolute)
415
- Position.relativize(this.element);
416
- delete this.element._originallyAbsolute;
417
- Element.remove(this._clone);
418
- this._clone = null;
419
- }
420
-
421
- var dropped = false;
422
- if(success) {
423
- dropped = Droppables.fire(event, this.element);
424
- if (!dropped) dropped = false;
425
- }
426
- if(dropped && this.options.onDropped) this.options.onDropped(this.element);
427
- Draggables.notify('onEnd', this, event);
428
-
429
- var revert = this.options.revert;
430
- if(revert && Object.isFunction(revert)) revert = revert(this.element);
431
-
432
- var d = this.currentDelta();
433
- if(revert && this.options.reverteffect) {
434
- if (dropped == 0 || revert != 'failure')
435
- this.options.reverteffect(this.element,
436
- d[1]-this.delta[1], d[0]-this.delta[0]);
437
- } else {
438
- this.delta = d;
439
- }
440
-
441
- if(this.options.zindex)
442
- this.element.style.zIndex = this.originalZ;
443
-
444
- if(this.options.endeffect)
445
- this.options.endeffect(this.element);
446
-
447
- Draggables.deactivate(this);
448
- Droppables.reset();
449
- },
450
-
451
- keyPress: function(event) {
452
- if(event.keyCode!=Event.KEY_ESC) return;
453
- this.finishDrag(event, false);
454
- Event.stop(event);
455
- },
456
-
457
- endDrag: function(event) {
458
- if(!this.dragging) return;
459
- this.stopScrolling();
460
- this.finishDrag(event, true);
461
- Event.stop(event);
462
- },
463
-
464
- draw: function(point) {
465
- var pos = Position.cumulativeOffset(this.element);
466
- if(this.options.ghosting) {
467
- var r = Position.realOffset(this.element);
468
- pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY;
469
- }
470
-
471
- var d = this.currentDelta();
472
- pos[0] -= d[0]; pos[1] -= d[1];
473
-
474
- if(this.options.scroll && (this.options.scroll != window && this._isScrollChild)) {
475
- pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft;
476
- pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop;
477
- }
478
-
479
- var p = [0,1].map(function(i){
480
- return (point[i]-pos[i]-this.offset[i])
481
- }.bind(this));
482
-
483
- if(this.options.snap) {
484
- if(Object.isFunction(this.options.snap)) {
485
- p = this.options.snap(p[0],p[1],this);
486
- } else {
487
- if(Object.isArray(this.options.snap)) {
488
- p = p.map( function(v, i) {
489
- return (v/this.options.snap[i]).round()*this.options.snap[i] }.bind(this))
490
- } else {
491
- p = p.map( function(v) {
492
- return (v/this.options.snap).round()*this.options.snap }.bind(this))
493
- }
494
- }}
495
-
496
- var style = this.element.style;
497
- if((!this.options.constraint) || (this.options.constraint=='horizontal'))
498
- style.left = p[0] + "px";
499
- if((!this.options.constraint) || (this.options.constraint=='vertical'))
500
- style.top = p[1] + "px";
501
-
502
- if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering
503
- },
504
-
505
- stopScrolling: function() {
506
- if(this.scrollInterval) {
507
- clearInterval(this.scrollInterval);
508
- this.scrollInterval = null;
509
- Draggables._lastScrollPointer = null;
510
- }
511
- },
512
-
513
- startScrolling: function(speed) {
514
- if(!(speed[0] || speed[1])) return;
515
- this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed];
516
- this.lastScrolled = new Date();
517
- this.scrollInterval = setInterval(this.scroll.bind(this), 10);
518
- },
519
-
520
- scroll: function() {
521
- var current = new Date();
522
- var delta = current - this.lastScrolled;
523
- this.lastScrolled = current;
524
- if(this.options.scroll == window) {
525
- with (this._getWindowScroll(this.options.scroll)) {
526
- if (this.scrollSpeed[0] || this.scrollSpeed[1]) {
527
- var d = delta / 1000;
528
- this.options.scroll.scrollTo( left + d*this.scrollSpeed[0], top + d*this.scrollSpeed[1] );
529
- }
530
- }
531
- } else {
532
- this.options.scroll.scrollLeft += this.scrollSpeed[0] * delta / 1000;
533
- this.options.scroll.scrollTop += this.scrollSpeed[1] * delta / 1000;
534
- }
535
-
536
- Position.prepare();
537
- Droppables.show(Draggables._lastPointer, this.element);
538
- Draggables.notify('onDrag', this);
539
- if (this._isScrollChild) {
540
- Draggables._lastScrollPointer = Draggables._lastScrollPointer || $A(Draggables._lastPointer);
541
- Draggables._lastScrollPointer[0] += this.scrollSpeed[0] * delta / 1000;
542
- Draggables._lastScrollPointer[1] += this.scrollSpeed[1] * delta / 1000;
543
- if (Draggables._lastScrollPointer[0] < 0)
544
- Draggables._lastScrollPointer[0] = 0;
545
- if (Draggables._lastScrollPointer[1] < 0)
546
- Draggables._lastScrollPointer[1] = 0;
547
- this.draw(Draggables._lastScrollPointer);
548
- }
549
-
550
- if(this.options.change) this.options.change(this);
551
- },
552
-
553
- _getWindowScroll: function(w) {
554
- var T, L, W, H;
555
- with (w.document) {
556
- if (w.document.documentElement && documentElement.scrollTop) {
557
- T = documentElement.scrollTop;
558
- L = documentElement.scrollLeft;
559
- } else if (w.document.body) {
560
- T = body.scrollTop;
561
- L = body.scrollLeft;
562
- }
563
- if (w.innerWidth) {
564
- W = w.innerWidth;
565
- H = w.innerHeight;
566
- } else if (w.document.documentElement && documentElement.clientWidth) {
567
- W = documentElement.clientWidth;
568
- H = documentElement.clientHeight;
569
- } else {
570
- W = body.offsetWidth;
571
- H = body.offsetHeight
572
- }
573
- }
574
- return { top: T, left: L, width: W, height: H };
575
- }
576
- });
577
-
578
- Draggable._dragging = { };
579
-
580
- /*--------------------------------------------------------------------------*/
581
-
582
- var SortableObserver = Class.create({
583
- initialize: function(element, observer) {
584
- this.element = $(element);
585
- this.observer = observer;
586
- this.lastValue = Sortable.serialize(this.element);
587
- },
588
-
589
- onStart: function() {
590
- this.lastValue = Sortable.serialize(this.element);
591
- },
592
-
593
- onEnd: function() {
594
- Sortable.unmark();
595
- if(this.lastValue != Sortable.serialize(this.element))
596
- this.observer(this.element)
597
- }
598
- });
599
-
600
- var Sortable = {
601
- SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/,
602
-
603
- sortables: { },
604
-
605
- _findRootElement: function(element) {
606
- while (element.tagName.toUpperCase() != "BODY") {
607
- if(element.id && Sortable.sortables[element.id]) return element;
608
- element = element.parentNode;
609
- }
610
- },
611
-
612
- options: function(element) {
613
- element = Sortable._findRootElement($(element));
614
- if(!element) return;
615
- return Sortable.sortables[element.id];
616
- },
617
-
618
- destroy: function(element){
619
- var s = Sortable.options(element);
620
-
621
- if(s) {
622
- Draggables.removeObserver(s.element);
623
- s.droppables.each(function(d){ Droppables.remove(d) });
624
- s.draggables.invoke('destroy');
625
-
626
- delete Sortable.sortables[s.element.id];
627
- }
628
- },
629
-
630
- create: function(element) {
631
- element = $(element);
632
- var options = Object.extend({
633
- element: element,
634
- tag: 'li', // assumes li children, override with tag: 'tagname'
635
- dropOnEmpty: false,
636
- tree: false,
637
- treeTag: 'ul',
638
- overlap: 'vertical', // one of 'vertical', 'horizontal'
639
- constraint: 'vertical', // one of 'vertical', 'horizontal', false
640
- containment: element, // also takes array of elements (or id's); or false
641
- handle: false, // or a CSS class
642
- only: false,
643
- delay: 0,
644
- hoverclass: null,
645
- ghosting: false,
646
- quiet: false,
647
- scroll: false,
648
- scrollSensitivity: 20,
649
- scrollSpeed: 15,
650
- format: this.SERIALIZE_RULE,
651
-
652
- // these take arrays of elements or ids and can be
653
- // used for better initialization performance
654
- elements: false,
655
- handles: false,
656
-
657
- onChange: Prototype.emptyFunction,
658
- onUpdate: Prototype.emptyFunction
659
- }, arguments[1] || { });
660
-
661
- // clear any old sortable with same element
662
- this.destroy(element);
663
-
664
- // build options for the draggables
665
- var options_for_draggable = {
666
- revert: true,
667
- quiet: options.quiet,
668
- scroll: options.scroll,
669
- scrollSpeed: options.scrollSpeed,
670
- scrollSensitivity: options.scrollSensitivity,
671
- delay: options.delay,
672
- ghosting: options.ghosting,
673
- constraint: options.constraint,
674
- handle: options.handle };
675
-
676
- if(options.starteffect)
677
- options_for_draggable.starteffect = options.starteffect;
678
-
679
- if(options.reverteffect)
680
- options_for_draggable.reverteffect = options.reverteffect;
681
- else
682
- if(options.ghosting) options_for_draggable.reverteffect = function(element) {
683
- element.style.top = 0;
684
- element.style.left = 0;
685
- };
686
-
687
- if(options.endeffect)
688
- options_for_draggable.endeffect = options.endeffect;
689
-
690
- if(options.zindex)
691
- options_for_draggable.zindex = options.zindex;
692
-
693
- // build options for the droppables
694
- var options_for_droppable = {
695
- overlap: options.overlap,
696
- containment: options.containment,
697
- tree: options.tree,
698
- hoverclass: options.hoverclass,
699
- onHover: Sortable.onHover
700
- }
701
-
702
- var options_for_tree = {
703
- onHover: Sortable.onEmptyHover,
704
- overlap: options.overlap,
705
- containment: options.containment,
706
- hoverclass: options.hoverclass
707
- }
708
-
709
- // fix for gecko engine
710
- Element.cleanWhitespace(element);
711
-
712
- options.draggables = [];
713
- options.droppables = [];
714
-
715
- // drop on empty handling
716
- if(options.dropOnEmpty || options.tree) {
717
- Droppables.add(element, options_for_tree);
718
- options.droppables.push(element);
719
- }
720
-
721
- (options.elements || this.findElements(element, options) || []).each( function(e,i) {
722
- var handle = options.handles ? $(options.handles[i]) :
723
- (options.handle ? $(e).select('.' + options.handle)[0] : e);
724
- options.draggables.push(
725
- new Draggable(e, Object.extend(options_for_draggable, { handle: handle })));
726
- Droppables.add(e, options_for_droppable);
727
- if(options.tree) e.treeNode = element;
728
- options.droppables.push(e);
729
- });
730
-
731
- if(options.tree) {
732
- (Sortable.findTreeElements(element, options) || []).each( function(e) {
733
- Droppables.add(e, options_for_tree);
734
- e.treeNode = element;
735
- options.droppables.push(e);
736
- });
737
- }
738
-
739
- // keep reference
740
- this.sortables[element.id] = options;
741
-
742
- // for onupdate
743
- Draggables.addObserver(new SortableObserver(element, options.onUpdate));
744
-
745
- },
746
-
747
- // return all suitable-for-sortable elements in a guaranteed order
748
- findElements: function(element, options) {
749
- return Element.findChildren(
750
- element, options.only, options.tree ? true : false, options.tag);
751
- },
752
-
753
- findTreeElements: function(element, options) {
754
- return Element.findChildren(
755
- element, options.only, options.tree ? true : false, options.treeTag);
756
- },
757
-
758
- onHover: function(element, dropon, overlap) {
759
- if(Element.isParent(dropon, element)) return;
760
-
761
- if(overlap > .33 && overlap < .66 && Sortable.options(dropon).tree) {
762
- return;
763
- } else if(overlap>0.5) {
764
- Sortable.mark(dropon, 'before');
765
- if(dropon.previousSibling != element) {
766
- var oldParentNode = element.parentNode;
767
- element.style.visibility = "hidden"; // fix gecko rendering
768
- dropon.parentNode.insertBefore(element, dropon);
769
- if(dropon.parentNode!=oldParentNode)
770
- Sortable.options(oldParentNode).onChange(element);
771
- Sortable.options(dropon.parentNode).onChange(element);
772
- }
773
- } else {
774
- Sortable.mark(dropon, 'after');
775
- var nextElement = dropon.nextSibling || null;
776
- if(nextElement != element) {
777
- var oldParentNode = element.parentNode;
778
- element.style.visibility = "hidden"; // fix gecko rendering
779
- dropon.parentNode.insertBefore(element, nextElement);
780
- if(dropon.parentNode!=oldParentNode)
781
- Sortable.options(oldParentNode).onChange(element);
782
- Sortable.options(dropon.parentNode).onChange(element);
783
- }
784
- }
785
- },
786
-
787
- onEmptyHover: function(element, dropon, overlap) {
788
- var oldParentNode = element.parentNode;
789
- var droponOptions = Sortable.options(dropon);
790
-
791
- if(!Element.isParent(dropon, element)) {
792
- var index;
793
-
794
- var children = Sortable.findElements(dropon, {tag: droponOptions.tag, only: droponOptions.only});
795
- var child = null;
796
-
797
- if(children) {
798
- var offset = Element.offsetSize(dropon, droponOptions.overlap) * (1.0 - overlap);
799
-
800
- for (index = 0; index < children.length; index += 1) {
801
- if (offset - Element.offsetSize (children[index], droponOptions.overlap) >= 0) {
802
- offset -= Element.offsetSize (children[index], droponOptions.overlap);
803
- } else if (offset - (Element.offsetSize (children[index], droponOptions.overlap) / 2) >= 0) {
804
- child = index + 1 < children.length ? children[index + 1] : null;
805
- break;
806
- } else {
807
- child = children[index];
808
- break;
809
- }
810
- }
811
- }
812
-
813
- dropon.insertBefore(element, child);
814
-
815
- Sortable.options(oldParentNode).onChange(element);
816
- droponOptions.onChange(element);
817
- }
818
- },
819
-
820
- unmark: function() {
821
- if(Sortable._marker) Sortable._marker.hide();
822
- },
823
-
824
- mark: function(dropon, position) {
825
- // mark on ghosting only
826
- var sortable = Sortable.options(dropon.parentNode);
827
- if(sortable && !sortable.ghosting) return;
828
-
829
- if(!Sortable._marker) {
830
- Sortable._marker =
831
- ($('dropmarker') || Element.extend(document.createElement('DIV'))).
832
- hide().addClassName('dropmarker').setStyle({position:'absolute'});
833
- document.getElementsByTagName("body").item(0).appendChild(Sortable._marker);
834
- }
835
- var offsets = Position.cumulativeOffset(dropon);
836
- Sortable._marker.setStyle({left: offsets[0]+'px', top: offsets[1] + 'px'});
837
-
838
- if(position=='after')
839
- if(sortable.overlap == 'horizontal')
840
- Sortable._marker.setStyle({left: (offsets[0]+dropon.clientWidth) + 'px'});
841
- else
842
- Sortable._marker.setStyle({top: (offsets[1]+dropon.clientHeight) + 'px'});
843
-
844
- Sortable._marker.show();
845
- },
846
-
847
- _tree: function(element, options, parent) {
848
- var children = Sortable.findElements(element, options) || [];
849
-
850
- for (var i = 0; i < children.length; ++i) {
851
- var match = children[i].id.match(options.format);
852
-
853
- if (!match) continue;
854
-
855
- var child = {
856
- id: encodeURIComponent(match ? match[1] : null),
857
- element: element,
858
- parent: parent,
859
- children: [],
860
- position: parent.children.length,
861
- container: $(children[i]).down(options.treeTag)
862
- }
863
-
864
- /* Get the element containing the children and recurse over it */
865
- if (child.container)
866
- this._tree(child.container, options, child)
867
-
868
- parent.children.push (child);
869
- }
870
-
871
- return parent;
872
- },
873
-
874
- tree: function(element) {
875
- element = $(element);
876
- var sortableOptions = this.options(element);
877
- var options = Object.extend({
878
- tag: sortableOptions.tag,
879
- treeTag: sortableOptions.treeTag,
880
- only: sortableOptions.only,
881
- name: element.id,
882
- format: sortableOptions.format
883
- }, arguments[1] || { });
884
-
885
- var root = {
886
- id: null,
887
- parent: null,
888
- children: [],
889
- container: element,
890
- position: 0
891
- }
892
-
893
- return Sortable._tree(element, options, root);
894
- },
895
-
896
- /* Construct a [i] index for a particular node */
897
- _constructIndex: function(node) {
898
- var index = '';
899
- do {
900
- if (node.id) index = '[' + node.position + ']' + index;
901
- } while ((node = node.parent) != null);
902
- return index;
903
- },
904
-
905
- sequence: function(element) {
906
- element = $(element);
907
- var options = Object.extend(this.options(element), arguments[1] || { });
908
-
909
- return $(this.findElements(element, options) || []).map( function(item) {
910
- return item.id.match(options.format) ? item.id.match(options.format)[1] : '';
911
- });
912
- },
913
-
914
- setSequence: function(element, new_sequence) {
915
- element = $(element);
916
- var options = Object.extend(this.options(element), arguments[2] || { });
917
-
918
- var nodeMap = { };
919
- this.findElements(element, options).each( function(n) {
920
- if (n.id.match(options.format))
921
- nodeMap[n.id.match(options.format)[1]] = [n, n.parentNode];
922
- n.parentNode.removeChild(n);
923
- });
924
-
925
- new_sequence.each(function(ident) {
926
- var n = nodeMap[ident];
927
- if (n) {
928
- n[1].appendChild(n[0]);
929
- delete nodeMap[ident];
930
- }
931
- });
932
- },
933
-
934
- serialize: function(element) {
935
- element = $(element);
936
- var options = Object.extend(Sortable.options(element), arguments[1] || { });
937
- var name = encodeURIComponent(
938
- (arguments[1] && arguments[1].name) ? arguments[1].name : element.id);
939
-
940
- if (options.tree) {
941
- return Sortable.tree(element, arguments[1]).children.map( function (item) {
942
- return [name + Sortable._constructIndex(item) + "[id]=" +
943
- encodeURIComponent(item.id)].concat(item.children.map(arguments.callee));
944
- }).flatten().join('&');
945
- } else {
946
- return Sortable.sequence(element, arguments[1]).map( function(item) {
947
- return name + "[]=" + encodeURIComponent(item);
948
- }).join('&');
949
- }
950
- }
951
- }
952
-
953
- // Returns true if child is contained within element
954
- Element.isParent = function(child, element) {
955
- if (!child.parentNode || child == element) return false;
956
- if (child.parentNode == element) return true;
957
- return Element.isParent(child.parentNode, element);
958
- }
959
-
960
- Element.findChildren = function(element, only, recursive, tagName) {
961
- if(!element.hasChildNodes()) return null;
962
- tagName = tagName.toUpperCase();
963
- if(only) only = [only].flatten();
964
- var elements = [];
965
- $A(element.childNodes).each( function(e) {
966
- if(e.tagName && e.tagName.toUpperCase()==tagName &&
967
- (!only || (Element.classNames(e).detect(function(v) { return only.include(v) }))))
968
- elements.push(e);
969
- if(recursive) {
970
- var grandchildren = Element.findChildren(e, only, recursive, tagName);
971
- if(grandchildren) elements.push(grandchildren);
972
- }
973
- });
974
-
975
- return (elements.length>0 ? elements.flatten() : []);
976
- }
977
-
978
- Element.offsetSize = function (element, type) {
979
- return element['offset' + ((type=='vertical' || type=='height') ? 'Height' : 'Width')];
980
- }