Commit 83c7d50d8f54419b9c002ae8e82359bb386052f4
1 parent
0511c681
Exists in
staging
and in
42 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 | 22 | def lightbox_options(options, lightbox_type = 'lbOn') | 
| 23 | 23 | the_class = lightbox_type | 
| 24 | 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 | 26 | end | 
| 30 | 27 | |
| 31 | 28 | def lightbox? | ... | ... | 
public/javascripts/lightbox.js
| ... | ... | @@ -51,7 +51,6 @@ function checkIt(string) { | 
| 51 | 51 | |
| 52 | 52 | /*-----------------------------------------------------------------------------------------------*/ | 
| 53 | 53 | |
| 54 | -Event.observe(window, 'load', initialize, false); | |
| 55 | 54 | Event.observe(window, 'load', getBrowserInfo, false); | 
| 56 | 55 | |
| 57 | 56 | var lightbox = Class.create(); | 
| ... | ... | @@ -68,6 +67,7 @@ lightbox.prototype = { | 
| 68 | 67 | } | 
| 69 | 68 | Event.observe(ctrl, 'click', this.activate.bindAsEventListener(this), false); | 
| 70 | 69 | ctrl.onclick = function(){return false;}; | 
| 70 | + ctrl.lightbox = this; | |
| 71 | 71 | }, | 
| 72 | 72 | |
| 73 | 73 | // Turn everything on - mainly the IE fixes | 
| ... | ... | @@ -80,7 +80,6 @@ lightbox.prototype = { | 
| 80 | 80 | } | 
| 81 | 81 | this.hideObjectsAndEmbeds('hidden'); | 
| 82 | 82 | this.displayLightbox("block"); | 
| 83 | - window.location.href= "#"; | |
| 84 | 83 | }, | 
| 85 | 84 | |
| 86 | 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 | 168 | }, | 
| 170 | 169 | |
| 171 | 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 | 182 | // Example of creating your own functionality once lightbox is initiated | 
| ... | ... | @@ -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 | 214 | // Add in markup necessary to make this work. Basically two divs: | 
| 209 | 215 | // Overlay holds the shadow | 
| ... | ... | @@ -221,3 +227,7 @@ function addLightboxMarkup() { | 
| 221 | 227 | bod.appendChild(overlay); | 
| 222 | 228 | bod.appendChild(lb); | 
| 223 | 229 | } | 
| 230 | +function removeLightboxMarkup() { | |
| 231 | + Element.remove($('overlay')); | |
| 232 | + Element.remove($('lightbox')); | |
| 233 | +} | ... | ... |