Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 206
- Log:
Initial import of Gullery, an open source photo gallery:
http://nubyonrails.com/pages/gullery
- Author:
- rool
- Date:
- Sun May 20 19:05:59 +0100 2007
- Size:
- 7778 Bytes
1 | // Returns array with x,y page scroll values. |
2 | // Core code from - quirksmode.org |
3 | Position.getPageScroll = function() { |
4 | if(self.pageYOffset) |
5 | return self.pageYOffset; |
6 | if(document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict |
7 | return document.documentElement.scrollTop; |
8 | if(document.body) // all other Explorers |
9 | return document.body.scrollTop; |
10 | } |
11 | |
12 | // Returns array with page width, height and window width, height |
13 | // Core code from - quirksmode.org |
14 | // Edit for Firefox by pHaez |
15 | Position.getPageSize = function() { |
16 | var xScroll, yScroll; |
17 | |
18 | if (window.innerHeight && window.scrollMaxY) { |
19 | xScroll = document.body.scrollWidth; |
20 | yScroll = window.innerHeight + window.scrollMaxY; |
21 | } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac |
22 | xScroll = document.body.scrollWidth; |
23 | yScroll = document.body.scrollHeight; |
24 | } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari |
25 | xScroll = document.body.offsetWidth; |
26 | yScroll = document.body.offsetHeight; |
27 | } |
28 | |
29 | var windowWidth, windowHeight; |
30 | if (self.innerHeight) { // all except Explorer |
31 | windowWidth = self.innerWidth; |
32 | windowHeight = self.innerHeight; |
33 | } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode |
34 | windowWidth = document.documentElement.clientWidth; |
35 | windowHeight = document.documentElement.clientHeight; |
36 | } else if (document.body) { // other Explorers |
37 | windowWidth = document.body.clientWidth; |
38 | windowHeight = document.body.clientHeight; |
39 | } |
40 | |
41 | // for small pages with total height less then height of the viewport |
42 | pageHeight = Math.max(windowHeight, yScroll); |
43 | |
44 | // for small pages with total width less then width of the viewport |
45 | pageWidth = Math.max(windowWidth, xScroll); |
46 | |
47 | return { page: { width: pageWidth, height: pageHeight }, window: { width: windowWidth, height: windowHeight } }; |
48 | } |
49 | |
50 | var Dialog = { |
51 | clear_observers: function() { |
52 | if (!Dialog.resizeObserver) return; |
53 | Event.stopObserving(window, 'resize', Dialog.resizeObserver); |
54 | Event.stopObserving(window, 'scroll', Dialog.resizeObserver); |
55 | Dialog.resizeObserver = null; |
56 | Dialog.current = null; |
57 | }, |
58 | |
59 | close: function() { |
60 | this.clear_observers(); |
61 | ['dialog', 'dialog_box'].each(function(d) { if($(d)) Element.remove(d); }); |
62 | }, |
63 | |
64 | Base: Class.create(), |
65 | Confirm: Class.create(), |
66 | Iframe: Class.create() |
67 | }; |
68 | |
69 | Dialog.Base.prototype = { |
70 | defaultOptions: { |
71 | dialogClass: '', |
72 | message: '', |
73 | messageTemplate: "<div>#{message}</div>" |
74 | }, |
75 | |
76 | initialize: function(options) { |
77 | this.options = Object.extend(Object.extend({}, this.defaultOptions), options); |
78 | this.create(); |
79 | }, |
80 | |
81 | setupDialog: function() { |
82 | dialog = document.createElement('div'); |
83 | dialog_box = document.createElement('div'); |
84 | dialog.setAttribute('id', 'dialog'); |
85 | dialog_box.setAttribute('id', 'dialog_box'); |
86 | Element.setStyle(dialog, {zIndex: 100}); |
87 | Element.setStyle(dialog_box, {zIndex: 101, display:'none'}); |
88 | [dialog, dialog_box].each(function(d) { d.className = this.options.dialogClass; }.bind(this)); |
89 | this.setMessage(dialog_box); |
90 | }, |
91 | |
92 | setMessage: function(dialog_box) { |
93 | var tmpl = new Template(this.options.messageTemplate); |
94 | dialog_box.innerHTML = tmpl.evaluate({message: this.options.message}); |
95 | }, |
96 | |
97 | create: function() { |
98 | this.setupDialog(); |
99 | document.body.appendChild(dialog); |
100 | document.body.appendChild(dialog_box); |
101 | this.afterCreate(); |
102 | }, |
103 | |
104 | afterCreate: function() { |
105 | this.layout(); |
106 | Dialog.resizeObserver = this.layout.bind(this); |
107 | Event.observe(window, 'resize', Dialog.resizeObserver); |
108 | Event.observe(window, 'scroll', Dialog.resizeObserver); |
109 | |
110 | new Effect.Fade(dialog, {from: 0.1, to: 0.4, duration:0.15}); |
111 | new Effect.Appear(dialog_box, {duration:0.4}); |
112 | Dialog.current = this; |
113 | }, |
114 | |
115 | layout: function() { |
116 | var pg_dimensions = Position.getPageSize(); |
117 | var el_dimensions = Element.getDimensions('dialog_box'); |
118 | var scrollY = Position.getPageScroll(); |
119 | |
120 | Element.setStyle('dialog', { |
121 | position:'absolute', top:0, left:0, |
122 | width: pg_dimensions.page.width + 'px', |
123 | height:pg_dimensions.page.height + 'px' |
124 | }); |
125 | |
126 | Element.setStyle('dialog_box', { |
127 | position:'absolute', |
128 | top: ((pg_dimensions.window.height - el_dimensions.height) / 2) + scrollY + 'px', |
129 | left: ((pg_dimensions.page.width - el_dimensions.width) / 2) + 'px' |
130 | }) |
131 | }, |
132 | |
133 | close: function() { |
134 | new Effect.Fade('dialog_box', {duration: 0.2, afterFinish: function() { |
135 | if(Dialog.current.options.onClose) Dialog.current.options.onClose(); |
136 | Dialog.close(); |
137 | }}); |
138 | } |
139 | }; |
140 | |
141 | Object.extend(Object.extend(Dialog.Iframe.prototype, Dialog.Base.prototype), { |
142 | defaultOptions: Object.extend(Object.extend({}, Dialog.Base.prototype.defaultOptions), { |
143 | resultSrc: '', |
144 | onDismiss: function() {} |
145 | }), |
146 | |
147 | setMessage: function(dialog_box) { |
148 | var iframe = document.createElement('iframe'); |
149 | var dismiss_div = document.createElement('div'); |
150 | var dismiss = document.createElement('a'); |
151 | |
152 | iframe.setAttribute('id', 'result_frame'); |
153 | iframe.src = this.options.resultSrc; |
154 | dismiss_div.setAttribute('id', 'dismiss_result'); |
155 | dialog_box.appendChild(iframe); |
156 | dialog_box.appendChild(dismiss_div); |
157 | dismiss_div.appendChild(dismiss); |
158 | dismiss.innerHTML = 'Dismiss'; |
159 | Event.observe(dismiss, 'click', function() { Dialog.current.dismiss(); return false; }); |
160 | }, |
161 | |
162 | dismiss: function() { |
163 | Dialog.current.close(); |
164 | Dialog.current.options.onDismiss(); |
165 | } |
166 | }); |
167 | |
168 | Object.extend(Object.extend(Dialog.Confirm.prototype, Dialog.Base.prototype), { |
169 | defaultOptions: Object.extend(Object.extend({}, Dialog.Base.prototype.defaultOptions), { |
170 | okayText: "OK", |
171 | cancelText: "CANCEL", |
172 | okayImage: '', |
173 | cancelImage: '', |
174 | onOkay: function() {}, |
175 | onCancel: function() {} |
176 | }), |
177 | |
178 | beforeSetupDialog: Dialog.Base.prototype.setupDialog, |
179 | setupDialog: function() { |
180 | this.beforeSetupDialog(); |
181 | dialog_box.appendChild(this.create_buttons()); |
182 | }, |
183 | |
184 | onOkay: function() { |
185 | Dialog.current.options.onOkay(); |
186 | }, |
187 | |
188 | onCancel: function() { |
189 | Dialog.current.close(); |
190 | Dialog.current.options.onCancel(); |
191 | }, |
192 | |
193 | create_buttons: function() { |
194 | var buttons = document.createElement('p'); |
195 | buttons.className = 'buttons'; |
196 | |
197 | var okay_button = document.createElement('a'); |
198 | Event.observe(okay_button, 'click', function() { Dialog.current.onOkay(); return false; }); |
199 | okay_button.className = 'okay'; |
200 | okay_button.setAttribute('href', '#'); |
201 | if(this.options.okayImage == '') { |
202 | okay_button.innerHTML = this.options.okayText; |
203 | } else { |
204 | var okay_image = document.createElement('img'); |
205 | okay_image.src = this.options.okayImage; |
206 | okay_image.setAttribute('alt', this.options.okayText); |
207 | okay_button.appendChild(okay_image); |
208 | } |
209 | |
210 | var cancel_button = document.createElement('a'); |
211 | Event.observe(cancel_button, 'click', function() { Dialog.current.onCancel(); return false; }); |
212 | cancel_button.className = 'cancel'; |
213 | cancel_button.setAttribute('href', '#'); |
214 | if(this.options.cancelImage == '') { |
215 | cancel_button.innerHTML = this.options.cancelText; |
216 | } else { |
217 | var cancel_image = document.createElement('img'); |
218 | cancel_image.src = this.options.cancelImage; |
219 | cancel_image.setAttribute('alt', this.options.cancelText); |
220 | cancel_button.appendChild(cancel_image); |
221 | } |
222 | |
223 | buttons.appendChild(okay_button); |
224 | buttons.appendChild(cancel_button); |
225 | return buttons; |
226 | } |
227 | }); |