Changeset 13551 for extensions/simple_themes/simple/js/scripts.js
- Timestamp:
- Mar 14, 2012, 2:37:30 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/simple_themes/simple/js/scripts.js
r13549 r13551 30 30 }; 31 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 else71 {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: null99 };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 else136 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 else147 {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 else186 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 else204 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 changed212 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 property228 try { rateButton.type = "button"; } catch (e){}// avoid normal submit (use ajax); not working in IE6229 230 if (navigator.userAgent.indexOf('AppleWebKit/')==-1 && navigator.userAgent.indexOf('MSIE 8')==-1) rateButton.value = ""; //hide the text IE<8/Opera - breaks safari231 with (rateButton.style)232 {233 textIndent = "-50px"; //hide the text FF234 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 do271 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 plugin299 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)300 * Dual licensed under the MIT and GPL licenses:301 */302 jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options=$.extend({},options);options.expires=-1;}303 var 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;}304 expires='; expires='+date.toUTCString();}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;}}}306 return cookieValue;}};
Note: See TracChangeset
for help on using the changeset viewer.