Commit 83c7d50d8f54419b9c002ae8e82359bb386052f4
1 parent
0511c681
Exists in
master
and in
28 other branches
Allow lightbox to popin before page load
Showing
2 changed files
with
30 additions
and
23 deletions
Show diff stats
app/helpers/lightbox_helper.rb
@@ -22,10 +22,7 @@ module LightboxHelper | @@ -22,10 +22,7 @@ module LightboxHelper | ||
22 | def lightbox_options(options, lightbox_type = 'lbOn') | 22 | def lightbox_options(options, lightbox_type = 'lbOn') |
23 | the_class = lightbox_type | 23 | the_class = lightbox_type |
24 | the_class << " #{options[:class]}" if options.has_key?(:class) | 24 | the_class << " #{options[:class]}" if options.has_key?(:class) |
25 | - options.merge( | ||
26 | - :class => the_class, | ||
27 | - :onclick => 'alert("%s"); return false' % _('Please, try again when the page loading completes.') | ||
28 | - ) | 25 | + options.merge(:class => the_class) |
29 | end | 26 | end |
30 | 27 | ||
31 | def lightbox? | 28 | def lightbox? |
public/javascripts/lightbox.js
@@ -51,7 +51,6 @@ function checkIt(string) { | @@ -51,7 +51,6 @@ function checkIt(string) { | ||
51 | 51 | ||
52 | /*-----------------------------------------------------------------------------------------------*/ | 52 | /*-----------------------------------------------------------------------------------------------*/ |
53 | 53 | ||
54 | -Event.observe(window, 'load', initialize, false); | ||
55 | Event.observe(window, 'load', getBrowserInfo, false); | 54 | Event.observe(window, 'load', getBrowserInfo, false); |
56 | 55 | ||
57 | var lightbox = Class.create(); | 56 | var lightbox = Class.create(); |
@@ -68,6 +67,7 @@ lightbox.prototype = { | @@ -68,6 +67,7 @@ lightbox.prototype = { | ||
68 | } | 67 | } |
69 | Event.observe(ctrl, 'click', this.activate.bindAsEventListener(this), false); | 68 | Event.observe(ctrl, 'click', this.activate.bindAsEventListener(this), false); |
70 | ctrl.onclick = function(){return false;}; | 69 | ctrl.onclick = function(){return false;}; |
70 | + ctrl.lightbox = this; | ||
71 | }, | 71 | }, |
72 | 72 | ||
73 | // Turn everything on - mainly the IE fixes | 73 | // Turn everything on - mainly the IE fixes |
@@ -80,7 +80,6 @@ lightbox.prototype = { | @@ -80,7 +80,6 @@ lightbox.prototype = { | ||
80 | } | 80 | } |
81 | this.hideObjectsAndEmbeds('hidden'); | 81 | this.hideObjectsAndEmbeds('hidden'); |
82 | this.displayLightbox("block"); | 82 | this.displayLightbox("block"); |
83 | - window.location.href= "#"; | ||
84 | }, | 83 | }, |
85 | 84 | ||
86 | // Ie requires height to 100% and overflow hidden or else you can scroll down past the lightbox | 85 | // Ie requires height to 100% and overflow hidden or else you can scroll down past the lightbox |
@@ -169,15 +168,15 @@ lightbox.prototype = { | @@ -169,15 +168,15 @@ lightbox.prototype = { | ||
169 | }, | 168 | }, |
170 | 169 | ||
171 | // Example of creating your own functionality once lightbox is initiated | 170 | // Example of creating your own functionality once lightbox is initiated |
172 | - insert: function(e){ | ||
173 | - link = Event.element(e).parentNode; | ||
174 | - Element.remove($('lbContent')); | ||
175 | - | ||
176 | - var myAjax = new Ajax.Request( | ||
177 | - link.href, | ||
178 | - {method: 'post', parameters: "", onComplete: this.processInfo.bindAsEventListener(this)} | ||
179 | - ); | ||
180 | - | 171 | + insert: function(e){ |
172 | + link = Event.element(e).parentNode; | ||
173 | + Element.remove($('lbContent')); | ||
174 | + | ||
175 | + var myAjax = new Ajax.Request( | ||
176 | + link.href, | ||
177 | + {method: 'post', parameters: "", onComplete: this.processInfo.bindAsEventListener(this)} | ||
178 | + ); | ||
179 | + | ||
181 | }, | 180 | }, |
182 | 181 | ||
183 | // Example of creating your own functionality once lightbox is initiated | 182 | // Example of creating your own functionality once lightbox is initiated |
@@ -196,14 +195,21 @@ lightbox.prototype = { | @@ -196,14 +195,21 @@ lightbox.prototype = { | ||
196 | 195 | ||
197 | /*-----------------------------------------------------------------------------------------------*/ | 196 | /*-----------------------------------------------------------------------------------------------*/ |
198 | 197 | ||
199 | -// Onload, make all links that need to trigger a lightbox active | ||
200 | -function initialize(){ | ||
201 | - addLightboxMarkup(); | ||
202 | - lbox = document.getElementsByClassName('lbOn'); | ||
203 | - for(i = 0; i < lbox.length; i++) { | ||
204 | - valid = new lightbox(lbox[i]); | ||
205 | - } | ||
206 | -} | 198 | +jQuery('.lbOn').live('click', function(event) { |
199 | + if (jQuery('#lbLoadMessage').length == 0) | ||
200 | + addLightboxMarkup(); | ||
201 | + if (this.lightbox == undefined) | ||
202 | + valid = new lightbox(this); | ||
203 | + else { | ||
204 | + removeLightboxMarkup(); | ||
205 | + addLightboxMarkup(); | ||
206 | + } | ||
207 | + | ||
208 | + this.lightbox.activate(); | ||
209 | + | ||
210 | + event.preventDefault(); | ||
211 | + return false; | ||
212 | +}); | ||
207 | 213 | ||
208 | // Add in markup necessary to make this work. Basically two divs: | 214 | // Add in markup necessary to make this work. Basically two divs: |
209 | // Overlay holds the shadow | 215 | // Overlay holds the shadow |
@@ -221,3 +227,7 @@ function addLightboxMarkup() { | @@ -221,3 +227,7 @@ function addLightboxMarkup() { | ||
221 | bod.appendChild(overlay); | 227 | bod.appendChild(overlay); |
222 | bod.appendChild(lb); | 228 | bod.appendChild(lb); |
223 | } | 229 | } |
230 | +function removeLightboxMarkup() { | ||
231 | + Element.remove($('overlay')); | ||
232 | + Element.remove($('lightbox')); | ||
233 | +} |