source: trunk/phpgwapi/js/expressoAjax/dom.js @ 2674

Revision 2674, 8.4 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1009 - Criando persistência da última requisicao a ser recuperada no reload.

Line 
1XEvents.add( window, "onload", function( )
2{
3        if ( template == 'classic' || template == 'celepar' )
4                return false;
5
6        var icons = document.getElementById( "app_icons" ).getElementsByTagName( "td" );
7        for ( var i = 0; i < icons.length; i++ )
8        {
9                XEvents.add( icons.item( i ), "onmouseover", function( )
10                {
11                        if ( this.className != "navbar_butOut" )
12                        {
13                                this.className = "navbar_butOver";
14                                /*zoom_in( this.firstChild.firstChild.id );*/
15                        }
16                } );
17                XEvents.add( icons.item( i ), "onmouseout", function( )
18                {
19                        if ( this.className != "navbar_butOut" )
20                        {
21                                this.className = "navbar_but";
22                                /*zoom_out( this.firstChild.firstChild.id );*/
23                        }
24                } );
25                XEvents.add( icons.item( i ), "onclick", function( )
26                {
27                        if ( this.className != "navbar_butOut" )
28                        {
29                                this.className = "navbar_butOut";
30                                /*zoom_out( this.firstChild.firstChild.id );*/
31                                var app = document.getElementById( curr_app );
32                                if ( app )
33                                        app.parentNode.parentNode.className= "navbar_but";
34                                //curr_app = "' . str_replace( '_', '', $app ) . 'id"
35                        }
36                } );
37        }
38} );
39
40function openWindow( newWidth, newHeight, link )
41{
42        newScreenX  = screen.width - newWidth;
43        newScreenY  = 0;
44        Window1 = window.open( link, "",
45                "width=" + newWidth + ", height=" + newHeight
46                + ", screenX=" + newScreenX + ", screenY=" + newScreenY
47                + ", top=" + newScreenY + ", left=" + newScreenX
48                + ", toolbar=no, scrollbars=yes, resizable=no"
49        );
50}
51
52function borkb(size){
53        kbyte = 1024;
54        mbyte = kbyte*1024;
55        gbyte = mbyte*1024;
56        if (!size)
57                size = 0;
58        if (size < kbyte)
59                return size + ' B';
60        else if (size < mbyte)
61                return parseInt(size/kbyte) + ' KB';
62        else if (size < gbyte)
63                if (size/mbyte > 100)
64                        return (size/mbyte).toFixed(0) + ' MB';
65                else
66                        return (size/mbyte).toFixed(1) + ' MB';
67        else
68                return parseInt(size/gbyte).toFixed(1) + ' GB';
69}
70
71function url_encode(str){
72    return escape(str);
73}
74function url_decode(str) {
75        return unescape(str);
76}
77
78function replaceAll(string, token, newtoken) {
79        while (string.indexOf(token) != -1) {
80                string = string.replace(token, newtoken);
81        }
82        return string;
83}
84
85function config_events(pObj, pEvent, pHandler)
86{
87    if( typeof pObj == 'object')
88    {
89        if( pEvent.substring(0, 2) == 'on')
90            pEvent = pEvent.substring(2, pEvent.length);
91
92        if ( pObj.addEventListener )
93            pObj.addEventListener(pEvent, pHandler, false);
94        else if( pObj.attachEvent )
95            pObj.attachEvent('on' + pEvent, pHandler );
96    }
97}
98
99function removeAll(id){
100        do
101        {
102                if (typeof(Element(id)) == 'undefined')
103                        break;
104                Element(id).parentNode.removeChild(Element(id));
105        }
106        while(Element(id));
107}
108function validateEmail(email){
109        if (typeof(email) != 'string')
110                return false;
111        var validName = /^[a-z][a-z-_0-9\.]*/i;
112        emailParts = email.split('@');
113        return (validName.test(emailParts[0]) && validateDomain(emailParts[1]));
114}
115function validateDomain(domain){
116        var domainReg = /^(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/i;
117        return (domainReg.test(domain));
118}
119
120function validateUrl(url){
121        var urlReg = /([A-Za-z]{2,7}:\/\/)(.*)/i;
122        urlParts = url.split(urlReg);
123        return (urlParts[1].length > 4 &&  validateDomain(urlParts[2]));
124}
125
126function trim(inputString) {
127   if (typeof inputString != "string")
128        return inputString;
129
130   var retValue = inputString;
131   var ch = retValue.substring(0, 1);
132   while (ch == " ") {
133          retValue = retValue.substring(1, retValue.length);
134          ch = retValue.substring(0, 1);
135   }
136   ch = retValue.substring(retValue.length-1, retValue.length);
137   while (ch == " ") {
138          retValue = retValue.substring(0, retValue.length-1);
139          ch = retValue.substring(retValue.length-1, retValue.length);
140   }
141   while (retValue.indexOf("  ") != -1) {
142          retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
143   }
144   return retValue;
145}
146
147
148function LTrim(value){
149        var w_space = String.fromCharCode(32);
150        var strTemp = "";
151        var iTemp = 0;
152
153        var v_length = value ? value.length : 0;
154        if(v_length < 1)
155                return "";
156
157        while(iTemp < v_length){
158                if(value && value.charAt(iTemp) != w_space){
159                        strTemp = value.substring(iTemp,v_length);
160                        break;
161                }
162                iTemp++;
163        }
164        return strTemp;
165}
166
167
168function add_className(obj, className){
169        if (obj && !exist_className(obj, className))
170                obj.className = obj.className + ' ' + className;
171}
172
173function remove_className(obj, className){
174        var re = new RegExp("\\s*"+className);
175        if (obj)
176                obj.className = obj.className.replace(re, ' ');
177}
178
179function exist_className(obj, className){
180        return ( obj && obj.className.indexOf(className) != -1 );
181}
182
183
184
185function validate_date(date){
186    if (date.match(/^[0-3][0-9]\/[0-1][0-9]\/\d{4,4}$/))
187    {
188        tmp = date.split('/');
189
190        day = new Number(tmp[0]);
191        month = new Number(tmp[1]);
192        year = new Number(tmp[2]);
193        if (month >= 1 && month <= 12 && day >= 1 && day <= 31)
194        {
195            if (month == 02 && day <= 29)
196            {
197                return true;
198            }
199            return true;
200        }
201        else
202            {
203                return false;
204            }
205    }
206    else
207        {
208            return false;
209        }
210}
211
212// Translate words and phrases using user language from eGroupware.
213function get_lang(_key) {
214        try
215        {
216                var key = _key.toLowerCase();
217                if(array_lang[key])
218                        var _value = array_lang[key];
219                else
220                        var _value = _key+"*";
221
222                if(arguments.length > 1)
223                        for(j = 1; typeof(arguments[j]) != 'undefined'; j++)
224                                _value = _value.replace("%"+j,arguments[j]);
225                return _value;
226        }
227        catch ( e )
228        {
229                return _key+"*";
230        }
231}
232
233
234function showBar(){
235        bar = document.getElementById("toolbar");
236        bar.style.visibility = "";
237        bar.style.position ="static";
238        but = document.getElementById("hiddenButton");
239        but.style.visibility = "";
240        but.style.position = "absolute";
241        but.style.top = "55px";
242        but.style.left = "2px";
243        title = get_lang('hide_bar_txt');
244        extra = document.getElementById("extraButton");
245        extra.style.visibility = "hidden";
246        but.innerHTML='<a title="' +title + '" onClick="javascript:changeBar()"><img src="' + URL_SERVER + 'phpgwapi/templates/default/images/up.button.png"></a>';
247        var neverExpires = new Date("January 01, 2100 00:00:00");
248        document.cookie = "showHeader=true"+
249                ";expires=" + neverExpires.toGMTString()+
250                ";path=/";
251}
252
253function hideBar(){
254        bar = document.getElementById("toolbar");
255        bar.style.position ="absolute";
256        bar.style.visibility = "hidden";
257        but = document.getElementById("hiddenButton");
258        but.style.visibility = "hidden";
259        title = get_lang('show_bar_txt');
260        extra = document.getElementById("extraButton");
261        extra.style.visibility = "";
262        extra.style.top = "-11px";
263        extra.style.left = "-10px";
264        var neverExpires = new Date("January 01, 2100 00:00:00");
265        document.cookie = "showHeader=false"+
266                ";expires=" + neverExpires.toGMTString()+
267                ";path=/";
268}
269function changeBar(){
270        bar = document.getElementById("toolbar");
271        if(bar.style.visibility == "hidden")
272                showBar();
273        else
274                hideBar();
275}
276function initBar(val){
277
278        if(val == 'true')
279                showBar();
280        else
281                hideBar();
282}
283var zoominTimer = new Array();
284var zoomoutTimer = new Array();
285function zoom_in(id)
286{
287        clearTimeout(zoomoutTimer[id]);
288        var elem = document.getElementById(id);
289        if (elem.height > 34)
290        {
291                clearTimeout(zoominTimer[id]);
292                return false;
293        }
294        elem.height += 4;
295        elem.width += 4;
296        zoominTimer[id] = setTimeout('zoom_in("'+id+'");',30);
297}
298function zoom_out(id)
299{
300        clearTimeout(zoominTimer[id]);
301        var elem = document.getElementById(id);
302        if ( ! elem )
303                return;
304        if (elem.height < 24)
305        {
306                clearTimeout(zoomoutTimer[id]);
307                return false;
308        }
309        elem.height -= 2;
310        elem.width -= 2;
311        zoomoutTimer[id] = setTimeout('zoom_out("'+id+'");',30);
312};
313
Note: See TracBrowser for help on using the repository browser.