From 208a5acddcfebc131af01855edbf7f6cdc903bf7 Mon Sep 17 00:00:00 2001 From: rvelices Date: Tue, 30 Nov 2010 20:42:03 +0000 Subject: bug 2043: some Javascript errors in default theme (also makes the rating.js script async) git-svn-id: http://piwigo.org/svn/trunk@7957 68402e56-0260-453c-a942-63ccdbb3a9ee --- themes/default/js/rating.js | 34 ++++++------ themes/default/js/scripts.js | 101 ++++++++++++++++++++---------------- themes/default/template/picture.tpl | 12 +++-- 3 files changed, 83 insertions(+), 64 deletions(-) (limited to 'themes') diff --git a/themes/default/js/rating.js b/themes/default/js/rating.js index f0f838c72..668aed930 100644 --- a/themes/default/js/rating.js +++ b/themes/default/js/rating.js @@ -2,7 +2,7 @@ var gRatingOptions, gRatingButtons, gUserRating; function makeNiceRatingForm(options) { - gRatingOptions = options || {}; + gRatingOptions = options; var form = document.getElementById('rateForm'); if (!form) return; //? template changed @@ -36,14 +36,11 @@ function makeNiceRatingForm(options) rateButton.parentNode.removeChild(rateButton.previousSibling); pwgAddEventListener(rateButton, "click", updateRating); - pwgAddEventListener(rateButton, "mouseout", resetRatingStarDisplay); - pwgAddEventListener(rateButton, "mouseover", updateRatingStarDisplayEvt); + pwgAddEventListener(rateButton, "mouseout", function() {updateRatingStarDisplay( gUserRating );}); + pwgAddEventListener(rateButton, "mouseover", function(e) { + updateRatingStarDisplay( e.target ? e.target.initialRateValue : e.srcElement.initialRateValue); + }); } - resetRatingStarDisplay(); -} - -function resetRatingStarDisplay() -{ updateRatingStarDisplay( gUserRating ); } @@ -53,12 +50,6 @@ function updateRatingStarDisplay(userRating) gRatingButtons[i].className = (userRating!=="" && userRating>=gRatingButtons[i].initialRateValue ) ? "rateButtonStarFull" : "rateButtonStarEmpty"; } -function updateRatingStarDisplayEvt(e) -{ - updateRatingStarDisplay( - e.target ? e.target.initialRateValue : e.srcElement.initialRateValue); -} - function updateRating(e) { var rateButton = e.target || e.srcElement; @@ -89,4 +80,17 @@ function updateRating(e) } ); return false; -} \ No newline at end of file +} + +(function() { +if (typeof _pwgRatingAutoQueue!="undefined" && _pwgRatingAutoQueue.length) +{ + for (var i=0; i<_pwgRatingAutoQueue.length; i++) + makeNiceRatingForm(_pwgRatingAutoQueue[i]); +} +_pwgRatingAutoQueue = { + push: function(opts) { + makeNiceRatingForm(opts); + } +} +})(); \ No newline at end of file diff --git a/themes/default/js/scripts.js b/themes/default/js/scripts.js index 0447d4c93..bcc5c1e63 100644 --- a/themes/default/js/scripts.js +++ b/themes/default/js/scripts.js @@ -21,12 +21,13 @@ function popuphelp(url) ); } -Function.prototype.pwgBind = function() { - var __method = this, object = arguments[0], args = Array.prototype.slice.call(arguments,1); - return function() { - return __method.apply(object, args.concat(arguments) ); - } +function pwgBind(object, method) { + var args = Array.prototype.slice.call(arguments,2); + return function() { + return method.apply(object, args.concat(Array.prototype.slice.call(arguments,0)) ); + } } + function PwgWS(urlRoot) { this.urlRoot = urlRoot; @@ -39,106 +40,116 @@ function PwgWS(urlRoot) }; PwgWS.prototype = { - callService : function(method, parameters, options) { if (options) { - for (var property in options) - this.options[property] = options[property]; + for (var prop in options) + this.options[prop] = options[prop]; } - try { this.transport = new XMLHttpRequest();} + try { this.xhr = new XMLHttpRequest();} catch(e) { - try { this.transport = new ActiveXObject('Msxml2.XMLHTTP'); } + try { this.xhr = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { - try { this.transport = new ActiveXObject('Microsoft.XMLHTTP'); } + try { this.xhr = new ActiveXObject('Microsoft.XMLHTTP'); } catch (e){ - dispatchError(0, "Cannot create request object"); + this.error(0, "Cannot create request object"); + return; } } } - this.transport.onreadystatechange = this.onStateChange.pwgBind(this); + this.xhr.onreadystatechange = pwgBind(this, this.onStateChange); var url = this.urlRoot+"ws.php?format=json"; var body = "method="+method; if (parameters) { - for (var property in parameters) + for (var prop in parameters) { - if ( typeof parameters[property] == 'object' && parameters[property]) + if ( typeof parameters[prop] == 'object' && parameters[prop]) { - for (var i=0; i {/if} {/foreach} - -- cgit v1.2.3