source: branches/1.2/workflow/js/scriptaculous/lightbox.js @ 1349

Revision 1349, 5.8 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

  • Property svn:executable set to *
Line 
1/*
2Created By: Chris Campbell
3Website: http://particletree.com
4Date: 2/1/2006
5
6Inspired by the lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
7*/
8
9/*-------------------------------GLOBAL VARIABLES------------------------------------*/
10
11var detect = navigator.userAgent.toLowerCase();
12var OS,browser,version,total,thestring;
13
14/*-----------------------------------------------------------------------------------------------*/
15
16//Browser detect script origionally created by Peter Paul Koch at http://www.quirksmode.org/
17
18function 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
46function checkIt(string) {
47        place = detect.indexOf(string) + 1;
48        thestring = string;
49        return place;
50}
51
52/*-----------------------------------------------------------------------------------------------*/
53
54Event.observe(window, 'load', lb_initialize, false);
55Event.observe(window, 'load', getBrowserInfo, false);
56Event.observe(window, 'unload', Event.unloadCache, false);
57
58var lightbox = Class.create();
59
60lightbox.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);
135                this.content();
136                $('lightbox').className = "done";
137                //this.actions();
138        },
139       
140        // Search through new links within the lightbox, and attach click event
141        /*
142        actions: function(){
143                lbActions = document.getElementsByClassName('lbAction');
144
145                for(i = 0; i < lbActions.length; i++) {
146                        Event.observe(lbActions[i], 'click', this[lbActions[i].rel].bindAsEventListener(this), false);
147                        lbActions[i].onclick = function(){return false;};
148                }
149        },
150*/
151       
152        // Example of creating your own functionality once lightbox is initiated
153        insert: function(e){
154           link = Event.element(e).parentNode;
155           Element.remove($('lbContent'));
156         
157           var myAjax = new Ajax.Request(
158                          link.href,
159                          {method: 'post', parameters: "", onComplete: this.processInfo.bindAsEventListener(this)}
160           );
161         
162        },
163       
164        // Example of creating your own functionality once lightbox is initiated
165        deactivate: function(){
166                Element.remove($('lbContent'));
167               
168                if (browser == "Internet Explorer"){
169                        this.setScroll(0,this.yPos);
170                        this.prepareIE("auto", "auto");
171                        this.hideSelects("visible");
172                }
173               
174                this.displayLightbox("none");
175        }
176};
177
178/*-----------------------------------------------------------------------------------------------*/
179
180// Onload, make all links that need to trigger a lightbox active
181function lb_initialize(){
182        if (!$('overlay'))
183                addLightboxMarkup();
184        lbox = document.getElementsByClassName('lbOn');
185        for(i = 0; i < lbox.length; i++) {
186                valid = new lightbox(lbox[i]);
187        }
188}
189
190// Add in markup necessary to make this work. Basically two divs:
191// Overlay holds the shadow
192// Lightbox is the centered square that the content is put into.
193function addLightboxMarkup() {
194        bod                             = document.getElementsByTagName('body')[0];
195        overlay                         = document.createElement('div');
196        overlay.id              = 'overlay';
197        lb                                      = document.createElement('div');
198        lb.id                           = 'lightbox';
199        lb.className    = 'loading';
200        lb.innerHTML    = '<div id="lbLoadMessage">' +
201                                                  '<p>Loading</p>' +
202                                                  '</div>';
203        bod.appendChild(overlay);
204        bod.appendChild(lb);
205}
Note: See TracBrowser for help on using the repository browser.