Changeset 13549 for extensions/simple_themes/simple/js/scripts.js
- Timestamp:
- Mar 14, 2012, 2:34:13 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/simple_themes/simple/js/scripts.js
r13546 r13549 1 jQuery.noConflict(); 1 // if cl_conflit is not used, use jQuery.noConflict to work with other libs 2 if (typeof (Conflit) == "undefined") 3 jQuery.noConflict(); 2 4 3 5 jQuery(document).ready(function($){ … … 28 30 }; 29 31 }); 30 31 /** 32 function SelectAll( formulaire ) 33 { 34 var elts = formulaire.elements; 35 for(var i=0; i <elts.length; i++) 36 { 37 if (elts[i].type=='checkbox') 38 elts[i].checked = true; 39 } 40 } 41 42 function DeselectAll( formulaire ) 43 { 44 var elts = formulaire.elements; 45 for(var i=0; i <elts.length; i++) 46 { 47 if (elts[i].type=='checkbox') 48 elts[i].checked = false; 49 } 50 } 51 52 function Inverser( formulaire ) 53 { 54 var elts = formulaire.elements; 55 for(var i=0; i <elts.length; i++) 56 { 57 if (elts[i].type=='checkbox') 58 elts[i].checked = !elts[i].checked; 59 } 60 } 61 62 function 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 78 function 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 85 Function.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 } 91 function 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 102 PwgWS.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 199 function 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 207 function 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 249 function resetRatingStarDisplay() 250 { 251 updateRatingStarDisplay( gUserRating ); 252 } 253 254 function 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 260 function updateRatingStarDisplayEvt(e) 261 { 262 updateRatingStarDisplay( 263 e.target ? e.target.initialRateValue : e.srcElement.initialRateValue); 264 } 265 266 function 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 }/** 32 298 * Cookie plugin 33 299 * Copyright (c) 2006 Klaus Hartl (stilbuero.de) … … 39 305 var 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;}}} 40 306 return cookieValue;}}; 41 42 /**43 * Piwigo scripts44 */45 function phpWGOpenWindow(theURL,winName,features)46 {img=new Image();img.src=theURL;if(img.complete)47 {var width=img.width+40;var height=img.height+40;}48 else49 {var width=640;var height=480;img.onload=resizeWindowToFit;}50 newWin=window.open(theURL,winName,features+',left=2,top=1,width='+width+',height='+height);}51 function resizeWindowToFit()52 {newWin.resizeTo(img.width+50,img.height+100);}53 function popuphelp(url)54 {window.open(url,'dc_popup','alwaysRaised=yes,dependent=yes,toolbar=no,height=420,width=500,menubar=no,resizable=yes,scrollbars=yes,status=no');}55 Function.prototype.pwgBind=function(){var __method=this,object=arguments[0],args=new Array();for(var i=1;i<arguments.length;i++)56 args[i-1]=arguments[i];return function(){return __method.apply(object,args);}}57 function PwgWS(urlRoot)58 {this.urlRoot=urlRoot;this.options={method:"GET",async:true,onFailure:null,onSuccess:null};};PwgWS.prototype={callService:function(method,parameters,options)59 {if(options)60 {for(var property in options)61 this.options[property]=options[property];}62 try{this.transport=new XMLHttpRequest();}63 catch(e){try{this.transport=new ActiveXObject('Msxml2.XMLHTTP');}64 catch(e){try{this.transport=new ActiveXObject('Microsoft.XMLHTTP');}65 catch(e){dispatchError(0,"Cannot create request object");}}}66 this.transport.onreadystatechange=this.onStateChange.pwgBind(this);var url=this.urlRoot+"ws.php?format=json";var body="method="+method;if(parameters)67 {for(var property in parameters)68 {if(typeof parameters[property]=='object'&¶meters[property])69 {for(var i=0;i<parameters[property].length;i++)70 body+="&"+property+"[]="+encodeURIComponent(parameters[property][i]);}71 else72 body+="&"+property+"="+encodeURIComponent(parameters[property]);}}73 if(this.options.method=="POST")74 {this.transport.open(this.options.method,url,this.options.async);this.transport.setRequestHeader("Content-Type","application/x-www-form-urlencoded");this.transport.send(body);}75 else76 {url+="&"+body;this.transport.open(this.options.method,url,this.options.async);this.transport.send(null);}},onStateChange:function(){var readyState=this.transport.readyState;if(readyState==4)77 this.respondToReadyState(this.transport.readyState);},dispatchError:function(httpCode,text)78 {!this.options.onFailure||this.options.onFailure(httpCode,text);},respondToReadyState:function(readyState)79 {var transport=this.transport;if(readyState==4&&transport.status==200)80 {var resp;try{eval('resp = '+transport.responseText);}81 catch(e){this.dispatchError(200,e.message+'\n'+transport.responseText.substr(0,512));}82 if(resp!=null)83 {if(resp.stat==null)84 this.dispatchError(200,"Invalid response");else if(resp.stat=='ok')85 {if(this.options.onSuccess)this.options.onSuccess(resp.result);}86 else87 this.dispatchError(200,resp.err+" "+resp.message);}}88 if(readyState==4&&transport.status!=200)89 this.dispatchError(transport.status,transport.statusText);},transport:null,urlRoot:null,options:{}}
Note: See TracChangeset
for help on using the changeset viewer.