[795] | 1 | /* |
---|
| 2 | Created By: Chris Campbell |
---|
| 3 | Website: http://particletree.com |
---|
| 4 | Date: 2/1/2006 |
---|
| 5 | |
---|
| 6 | Inspired by the lightbox implementation found at http://www.huddletogether.com/projects/lightbox/ |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /*-------------------------------GLOBAL VARIABLES------------------------------------*/ |
---|
| 10 | |
---|
| 11 | var detect = navigator.userAgent.toLowerCase(); |
---|
| 12 | var OS,browser,version,total,thestring; |
---|
| 13 | |
---|
| 14 | /*-----------------------------------------------------------------------------------------------*/ |
---|
| 15 | |
---|
| 16 | //Browser detect script origionally created by Peter Paul Koch at http://www.quirksmode.org/ |
---|
| 17 | |
---|
| 18 | function getBrowserInfo() { |
---|
| 19 | if (checkIt('konqueror')) { |
---|
| 20 | browser = "Konqueror"; |
---|
| 21 | OS = "Linux"; |
---|
| 22 | } |
---|
| 23 | else if (checkIt('safari')) browser = "Safari"; |
---|
| 24 | else if (checkIt('omniweb')) browser = "OmniWeb"; |
---|
| 25 | else if (checkIt('opera')) browser = "Opera"; |
---|
| 26 | else if (checkIt('webtv')) browser = "WebTV"; |
---|
| 27 | else if (checkIt('icab')) browser = "iCab"; |
---|
| 28 | else if (checkIt('msie')) browser = "Internet Explorer"; |
---|
| 29 | else if (!checkIt('compatible')) { |
---|
| 30 | browser = "Netscape Navigator"; |
---|
| 31 | version = detect.charAt(8); |
---|
| 32 | } |
---|
| 33 | else browser = "An unknown browser"; |
---|
| 34 | |
---|
| 35 | if (!version) version = detect.charAt(place + thestring.length); |
---|
| 36 | |
---|
| 37 | if (!OS) { |
---|
| 38 | if (checkIt('linux')) OS = "Linux"; |
---|
| 39 | else if (checkIt('x11')) OS = "Unix"; |
---|
| 40 | else if (checkIt('mac')) OS = "Mac"; |
---|
| 41 | else if (checkIt('win')) OS = "Windows"; |
---|
| 42 | else OS = "an unknown operating system"; |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | function checkIt(string) { |
---|
| 47 | place = detect.indexOf(string) + 1; |
---|
| 48 | thestring = string; |
---|
| 49 | return place; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | /*-----------------------------------------------------------------------------------------------*/ |
---|
| 53 | |
---|
| 54 | Event.observe(window, 'load', lb_initialize, false); |
---|
| 55 | Event.observe(window, 'load', getBrowserInfo, false); |
---|
| 56 | Event.observe(window, 'unload', Event.unloadCache, false); |
---|
| 57 | |
---|
| 58 | var lightbox = Class.create(); |
---|
| 59 | |
---|
| 60 | lightbox.prototype = { |
---|
| 61 | |
---|
| 62 | yPos : 0, |
---|
| 63 | xPos : 0, |
---|
| 64 | |
---|
| 65 | initialize: function(ctrl) { |
---|
| 66 | this.content = ctrl.onclick; |
---|
| 67 | Event.observe(ctrl, 'click', this.activate.bindAsEventListener(this), false); |
---|
| 68 | ctrl.onclick = function(){return false;}; |
---|
| 69 | }, |
---|
| 70 | |
---|
| 71 | // Turn everything on - mainly the IE fixes |
---|
| 72 | activate: function(){ |
---|
| 73 | if (browser == 'Internet Explorer'){ |
---|
| 74 | this.getScroll(); |
---|
| 75 | this.prepareIE('100%', 'hidden'); |
---|
| 76 | this.setScroll(0,0); |
---|
| 77 | this.hideSelects('hidden'); |
---|
| 78 | } |
---|
| 79 | this.displayLightbox("block"); |
---|
| 80 | }, |
---|
| 81 | |
---|
| 82 | // Ie requires height to 100% and overflow hidden or else you can scroll down past the lightbox |
---|
| 83 | prepareIE: function(height, overflow){ |
---|
| 84 | bod = document.getElementsByTagName('body')[0]; |
---|
| 85 | bod.style.height = height; |
---|
| 86 | bod.style.overflow = overflow; |
---|
| 87 | |
---|
| 88 | htm = document.getElementsByTagName('html')[0]; |
---|
| 89 | htm.style.height = height; |
---|
| 90 | htm.style.overflow = overflow; |
---|
| 91 | }, |
---|
| 92 | |
---|
| 93 | // In IE, select elements hover on top of the lightbox |
---|
| 94 | hideSelects: function(visibility){ |
---|
| 95 | selects = document.getElementsByTagName('select'); |
---|
| 96 | for(i = 0; i < selects.length; i++) { |
---|
| 97 | selects[i].style.visibility = visibility; |
---|
| 98 | } |
---|
| 99 | }, |
---|
| 100 | |
---|
| 101 | // Taken from lightbox implementation found at http://www.huddletogether.com/projects/lightbox/ |
---|
| 102 | getScroll: function(){ |
---|
| 103 | if (self.pageYOffset) { |
---|
| 104 | this.yPos = self.pageYOffset; |
---|
| 105 | } else if (document.documentElement && document.documentElement.scrollTop){ |
---|
| 106 | this.yPos = document.documentElement.scrollTop; |
---|
| 107 | } else if (document.body) { |
---|
| 108 | this.yPos = document.body.scrollTop; |
---|
| 109 | } |
---|
| 110 | }, |
---|
| 111 | |
---|
| 112 | setScroll: function(x, y){ |
---|
| 113 | window.scrollTo(x, y); |
---|
| 114 | }, |
---|
| 115 | |
---|
| 116 | displayLightbox: function(display){ |
---|
| 117 | $('overlay').style.display = display; |
---|
| 118 | $('lightbox').style.display = display; |
---|
| 119 | if(display != 'none') this.processInfo(); |
---|
| 120 | }, |
---|
| 121 | |
---|
| 122 | // Begin Ajax request based off of the href of the clicked linked |
---|
| 123 | loadInfo: function() { |
---|
| 124 | var myAjax = new Ajax.Request( |
---|
| 125 | this.content, |
---|
| 126 | {method: 'post', parameters: "", onComplete: this.processInfo.bindAsEventListener(this)} |
---|
| 127 | ); |
---|
| 128 | |
---|
| 129 | }, |
---|
| 130 | |
---|
| 131 | // Display Ajax response |
---|
| 132 | processInfo: function(response){ |
---|
| 133 | info = "<div id='lbContent'></div>"; |
---|
| 134 | new Insertion.Before($('lbLoadMessage'), info); |
---|
[7372] | 135 | |
---|
| 136 | if (typeof(this.content) == "function") |
---|
| 137 | { |
---|
| 138 | this.content(); |
---|
| 139 | } |
---|
| 140 | else |
---|
| 141 | { |
---|
| 142 | this.content; |
---|
| 143 | } |
---|
| 144 | |
---|
[795] | 145 | $('lightbox').className = "done"; |
---|
| 146 | //this.actions(); |
---|
| 147 | }, |
---|
| 148 | |
---|
| 149 | // Search through new links within the lightbox, and attach click event |
---|
| 150 | /* |
---|
| 151 | actions: function(){ |
---|
| 152 | lbActions = document.getElementsByClassName('lbAction'); |
---|
| 153 | |
---|
| 154 | for(i = 0; i < lbActions.length; i++) { |
---|
| 155 | Event.observe(lbActions[i], 'click', this[lbActions[i].rel].bindAsEventListener(this), false); |
---|
| 156 | lbActions[i].onclick = function(){return false;}; |
---|
| 157 | } |
---|
| 158 | }, |
---|
| 159 | */ |
---|
| 160 | |
---|
| 161 | // Example of creating your own functionality once lightbox is initiated |
---|
| 162 | insert: function(e){ |
---|
| 163 | link = Event.element(e).parentNode; |
---|
| 164 | Element.remove($('lbContent')); |
---|
| 165 | |
---|
| 166 | var myAjax = new Ajax.Request( |
---|
| 167 | link.href, |
---|
| 168 | {method: 'post', parameters: "", onComplete: this.processInfo.bindAsEventListener(this)} |
---|
| 169 | ); |
---|
| 170 | |
---|
| 171 | }, |
---|
| 172 | |
---|
| 173 | // Example of creating your own functionality once lightbox is initiated |
---|
| 174 | deactivate: function(){ |
---|
| 175 | Element.remove($('lbContent')); |
---|
| 176 | |
---|
| 177 | if (browser == "Internet Explorer"){ |
---|
| 178 | this.setScroll(0,this.yPos); |
---|
| 179 | this.prepareIE("auto", "auto"); |
---|
| 180 | this.hideSelects("visible"); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | this.displayLightbox("none"); |
---|
| 184 | } |
---|
| 185 | }; |
---|
| 186 | |
---|
| 187 | /*-----------------------------------------------------------------------------------------------*/ |
---|
| 188 | |
---|
| 189 | // Onload, make all links that need to trigger a lightbox active |
---|
| 190 | function lb_initialize(){ |
---|
| 191 | if (!$('overlay')) |
---|
| 192 | addLightboxMarkup(); |
---|
[7372] | 193 | |
---|
[795] | 194 | lbox = document.getElementsByClassName('lbOn'); |
---|
[7372] | 195 | |
---|
[795] | 196 | for(i = 0; i < lbox.length; i++) { |
---|
| 197 | valid = new lightbox(lbox[i]); |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | // Add in markup necessary to make this work. Basically two divs: |
---|
| 202 | // Overlay holds the shadow |
---|
| 203 | // Lightbox is the centered square that the content is put into. |
---|
| 204 | function addLightboxMarkup() { |
---|
| 205 | bod = document.getElementsByTagName('body')[0]; |
---|
| 206 | overlay = document.createElement('div'); |
---|
[7372] | 207 | overlay.id = 'overlay'; |
---|
[795] | 208 | lb = document.createElement('div'); |
---|
| 209 | lb.id = 'lightbox'; |
---|
[7372] | 210 | lb.className = 'loading'; |
---|
| 211 | lb.innerHTML = '<div id="lbLoadMessage">' + |
---|
[795] | 212 | '<p>Loading</p>' + |
---|
| 213 | '</div>'; |
---|
[7372] | 214 | |
---|
[795] | 215 | bod.appendChild(overlay); |
---|
| 216 | bod.appendChild(lb); |
---|
| 217 | } |
---|