source: extensions/simple_themes/simple/js/scripts.js @ 13549

Last change on this file since 13549 was 13549, checked in by plg, 12 years ago

import theme Simple version 2.3

  • if cl_conflit is used, don't add jQuery.noConflict
  • fix the possibility to toggle visibility of image informations
  • show logout link when connected - thanks to gbo
  • update jquery to 1.4.4
  • backport commit from piwigo: r6244, r6430 & r6438
  • add gitignore
  • update javascripts + add script to combine/minify
  • apply r6594 from piwigo's trunk
  • move jquery in the header, using known_script
  • translation for the menu title
  • add 1px icon start_filter.png to avoid loading error with rvtree plugin
  • margin for error & info divs
File size: 9.0 KB
Line 
1// if cl_conflit is not used, use jQuery.noConflict to work with other libs
2if (typeof (Conflit) == "undefined")
3   jQuery.noConflict();
4
5jQuery(document).ready(function($){
6  $("#theComments h3").click(function () {
7    $("#theComments > div").toggle("slow");
8  });
9
10  $("#menuswitcher").click(function(){
11    if ($("#menubar").is(":hidden")) {
12      $("#menubar").show("slow");
13      $.cookie('side-menu', 'showing', {path: "/"});
14      return false;
15    } else {
16      $("#menubar").hide("slow");
17      $.cookie('side-menu', 'hiding', {path: "/"});
18      return false;
19    }
20  });
21
22  // creates a variable with the contents of the cookie side-menu
23  var sidemenu = $.cookie('side-menu');
24  // if cookie says the menu is hiding, keep it hidden!
25  if (sidemenu == 'hiding') {
26    $("#menubar").hide();
27  }
28  if (sidemenu == 'showing') {
29    $("#menubar").show();
30  };
31});
32function SelectAll( formulaire )
33{
34var elts = formulaire.elements;
35for(var i=0; i <elts.length; i++)
36{
37        if (elts[i].type=='checkbox')
38                elts[i].checked = true;
39}
40}
41
42function DeselectAll( formulaire )
43{
44var elts = formulaire.elements;
45for(var i=0; i <elts.length; i++)
46{
47        if (elts[i].type=='checkbox')
48                elts[i].checked = false;
49}
50}
51
52function Inverser( formulaire )
53{
54var elts = formulaire.elements;
55for(var i=0; i <elts.length; i++)
56{
57        if (elts[i].type=='checkbox')
58                elts[i].checked = !elts[i].checked;
59}
60}
61
62function phpWGOpenWindow(theURL,winName,features)
63{
64        img = new Image();
65        img.src = theURL;
66        if (img.complete)
67        {
68                var width=img.width+40, height=img.height+40;
69        }
70        else
71        {
72                var width=640, height=480;
73                img.onload = function () { newWin.resizeTo( img.width+50, img.height+100); };
74        }
75        newWin = window.open(theURL,winName,features+',left=2,top=1,width=' + width + ',height=' + height);
76}
77
78function popuphelp(url)
79{
80        window.open( url, 'dc_popup',
81                'alwaysRaised=yes,dependent=yes,toolbar=no,height=420,width=500,menubar=no,resizable=yes,scrollbars=yes,status=no'
82        );
83}
84
85Function.prototype.pwgBind = function() {
86                var __method = this, object = arguments[0], args = Array.prototype.slice.call(arguments,1);
87                return function() {
88                                return __method.apply(object, args.concat(arguments) );
89                }
90}
91function PwgWS(urlRoot)
92{
93        this.urlRoot = urlRoot;
94        this.options = {
95                method: "GET",
96                async:  true,
97                onFailure: null,
98                onSuccess: null
99        };
100};
101
102PwgWS.prototype = {
103
104        callService : function(method, parameters, options)
105        {
106                if (options)
107                {
108                        for (var property in options)
109                                this.options[property] = options[property];
110                }
111                try { this.transport = new XMLHttpRequest();}
112                catch(e) {
113                        try { this.transport = new ActiveXObject('Msxml2.XMLHTTP'); }
114                        catch(e) {
115                                try { this.transport = new ActiveXObject('Microsoft.XMLHTTP'); }
116                                catch (e){
117                                        dispatchError(0, "Cannot create request object");
118                                }
119                        }
120                }
121                this.transport.onreadystatechange = this.onStateChange.pwgBind(this);
122
123                var url = this.urlRoot+"ws.php?format=json";
124
125                var body = "method="+method;
126                if (parameters)
127                {
128                        for (var property in parameters)
129                        {
130                                if ( typeof parameters[property] == 'object' && parameters[property])
131                                {
132                                        for (var i=0; i<parameters[property].length; i++)
133                                                body += "&"+property+"[]="+encodeURIComponent(parameters[property][i]);
134                                }
135                                else
136                                        body += "&"+property+"="+encodeURIComponent(parameters[property]);
137                        }
138                }
139
140                if (this.options.method == "POST" )
141                {
142                        this.transport.open(this.options.method, url, this.options.async);
143                        this.transport.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
144                        this.transport.send(body);
145                }
146                else
147                {
148                        url += "&"+body;
149                        this.transport.open(this.options.method, url, this.options.async);
150                        this.transport.send(null);
151                }
152        },
153
154        onStateChange: function() {
155                var readyState = this.transport.readyState;
156                if (readyState==4)
157                        this.respondToReadyState(readyState);
158        },
159
160        dispatchError: function( httpCode, text )
161        {
162                !this.options.onFailure || this.options.onFailure( httpCode, text);
163        },
164
165        respondToReadyState: function(readyState)
166        {
167                var transport = this.transport;
168                if (readyState==4 && transport.status == 200)
169                {
170                        var resp;
171                        try {
172                                eval('resp = ' + transport.responseText);
173                        }
174                        catch (e) {
175                                this.dispatchError( 200, e.message + '\n' + transport.responseText.substr(0,512) );
176                        }
177                        if (resp!=null)
178                        {
179                                if (resp.stat==null)
180                                        this.dispatchError( 200, "Invalid response" );
181                                else if (resp.stat=='ok')
182                                {
183                                        if (this.options.onSuccess) this.options.onSuccess( resp.result );
184                                }
185                                else
186                                        this.dispatchError( 200, resp.err + " " + resp.message);
187                        }
188                }
189                if (readyState==4 && transport.status != 200)
190                        this.dispatchError( transport.status, transport.statusText );
191        },
192
193
194        transport: null,
195        urlRoot: null,
196        options: {}
197}
198
199function pwgAddEventListener(elem, evt, fn)
200{
201        if (window.attachEvent)
202                elem.attachEvent('on'+evt, fn);
203        else
204                elem.addEventListener(evt, fn, false);
205}var gRatingOptions, gRatingButtons, gUserRating;
206
207function makeNiceRatingForm(options)
208{
209        gRatingOptions = options || {};
210        var form = document.getElementById('rateForm');
211        if (!form) return; //? template changed
212
213        gRatingButtons = form.getElementsByTagName('input');
214        gUserRating = "";
215        for (var i=0; i<gRatingButtons.length; i++)
216        {
217                if ( gRatingButtons[i].type=="button" )
218                {
219                        gUserRating = gRatingButtons[i].value;
220                        break;
221                }
222        }
223
224        for (var i=0; i<gRatingButtons.length; i++)
225        {
226                var rateButton = gRatingButtons[i];
227                rateButton.initialRateValue = rateButton.value; // save it as a property
228                try { rateButton.type = "button"; } catch (e){}// avoid normal submit (use ajax); not working in IE6
229
230                if (navigator.userAgent.indexOf('AppleWebKit/')==-1 && navigator.userAgent.indexOf('MSIE 8')==-1) rateButton.value = ""; //hide the text IE<8/Opera - breaks safari
231                with (rateButton.style)
232                {
233                        textIndent = "-50px"; //hide the text FF
234                        marginLeft = marginRight = 0;
235                }
236
237                if (i!=gRatingButtons.length-1 && rateButton.nextSibling.nodeType == 3 /*TEXT_NODE*/)
238                        rateButton.parentNode.removeChild(rateButton.nextSibling);
239                if (i>0 && rateButton.previousSibling.nodeType == 3 /*TEXT_NODE*/)
240                        rateButton.parentNode.removeChild(rateButton.previousSibling);
241
242                pwgAddEventListener(rateButton, "click", updateRating);
243                pwgAddEventListener(rateButton, "mouseout", resetRatingStarDisplay);
244                pwgAddEventListener(rateButton, "mouseover", updateRatingStarDisplayEvt);
245        }
246        resetRatingStarDisplay();
247}
248
249function resetRatingStarDisplay()
250{
251        updateRatingStarDisplay( gUserRating );
252}
253
254function updateRatingStarDisplay(userRating)
255{
256        for (var i=0; i<gRatingButtons.length; i++)
257                gRatingButtons[i].className = (userRating!=="" && userRating>=gRatingButtons[i].initialRateValue ) ? "rateButtonStarFull" : "rateButtonStarEmpty";
258}
259
260function updateRatingStarDisplayEvt(e)
261{
262        updateRatingStarDisplay(
263                e.target ? e.target.initialRateValue : e.srcElement.initialRateValue);
264}
265
266function updateRating(e)
267{
268        var rateButton = e.target || e.srcElement;
269        if (rateButton.initialRateValue == gUserRating)
270                return false; //nothing to do
271
272        for (var i=0; i<gRatingButtons.length; i++) gRatingButtons[i].disabled=true;
273        var y = new PwgWS(gRatingOptions.rootUrl);
274        y.callService(
275                "pwg.images.rate", {image_id: gRatingOptions.image_id, rate: rateButton.initialRateValue } ,
276                {
277                        onFailure: function(num, text) {
278                                alert(num + " " + text);
279                                document.location = rateButton.form.action + "&rate="+rateButton.initialRateValue;
280                        },
281                        onSuccess: function(result) {
282                                gUserRating = rateButton.initialRateValue;
283                                for (var i=0; i<gRatingButtons.length; i++) gRatingButtons[i].disabled=false;
284                                if (gRatingOptions.updateRateElement) gRatingOptions.updateRateElement.innerHTML = gRatingOptions.updateRateText;
285                                if (gRatingOptions.ratingSummaryElement)
286                                {
287                                        var t = gRatingOptions.ratingSummaryText;
288                                        var args =[result.average, result.count], idx = 0, rexp = new RegExp( /%\.?\d*[sdf]/ );
289                                        //_xxx = t.match( rexp );
290                                        while (idx<args.length) t=t.replace(rexp, args[idx++]);
291                                        gRatingOptions.ratingSummaryElement.innerHTML = t;
292                                }
293                        }
294                }
295        );
296        return false;
297}/**
298 * Cookie plugin
299 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
300 * Dual licensed under the MIT and GPL licenses:
301 */
302jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options=$.extend({},options);options.expires=-1;}
303var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
304expires='; expires='+date.toUTCString();}
305var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
306return cookieValue;}};
Note: See TracBrowser for help on using the repository browser.