- better javascript funcs + shorter notation

git-svn-id: http://piwigo.org/svn/branches/2.1@6576 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices 2010-06-22 19:39:12 +00:00
parent 5b19405ff2
commit 7629b2723a
2 changed files with 34 additions and 55 deletions

View file

@ -35,16 +35,9 @@ function makeNiceRatingForm(options)
if (i>0 && rateButton.previousSibling.nodeType == 3 /*TEXT_NODE*/) if (i>0 && rateButton.previousSibling.nodeType == 3 /*TEXT_NODE*/)
rateButton.parentNode.removeChild(rateButton.previousSibling); rateButton.parentNode.removeChild(rateButton.previousSibling);
if(window.addEventListener){ // Mozilla, Netscape, Firefox pwgAddEventListener(rateButton, "click", updateRating);
rateButton.addEventListener("click", updateRating, false ); pwgAddEventListener(rateButton, "mouseout", resetRatingStarDisplay);
rateButton.addEventListener("mouseout", resetRatingStarDisplay, false ); pwgAddEventListener(rateButton, "mouseover", updateRatingStarDisplayEvt);
rateButton.addEventListener("mouseover", updateRatingStarDisplayEvt, false );
}
else if(window.attachEvent) { // IE
rateButton.attachEvent("onclick", updateRating);
rateButton.attachEvent("onmouseout", resetRatingStarDisplay);
rateButton.attachEvent("onmouseover", updateRatingStarDisplayEvt);
}
} }
resetRatingStarDisplay(); resetRatingStarDisplay();
} }
@ -88,8 +81,8 @@ function updateRating(e)
if (gRatingOptions.ratingSummaryElement) if (gRatingOptions.ratingSummaryElement)
{ {
var t = gRatingOptions.ratingSummaryText; var t = gRatingOptions.ratingSummaryText;
var args =[result.average, result.count, result.stdev], idx = 0, rexp = new RegExp( /%\.?\d*[sdf]/ ); var args =[result.average, result.count], idx = 0, rexp = new RegExp( /%\.?\d*[sdf]/ );
_xxx = t.match( rexp ); //_xxx = t.match( rexp );
while (idx<args.length) t=t.replace(rexp, args[idx++]); while (idx<args.length) t=t.replace(rexp, args[idx++]);
gRatingOptions.ratingSummaryElement.innerHTML = t; gRatingOptions.ratingSummaryElement.innerHTML = t;
} }

View file

@ -1,42 +1,30 @@
function SelectAll( formulaire ) function SelectAll( formulaire )
{ {
var len = formulaire.elements.length; var elts = formulaire.elements;
var i=0; for(var i=0; i <elts.length; i++)
for( i = 0; i < len; i++)
{ {
if ( formulaire.elements[i].type=='checkbox' if (elts[i].type=='checkbox')
&& formulaire.elements[i].name != 'copie') elts[i].checked = true;
{
formulaire.elements[i].checked = true;
}
} }
} }
function DeselectAll( formulaire ) function DeselectAll( formulaire )
{ {
var len = formulaire.elements.length; var elts = formulaire.elements;
var i=0; for(var i=0; i <elts.length; i++)
for( i = 0; i < len; i++)
{ {
if ( formulaire.elements[i].type=='checkbox' if (elts[i].type=='checkbox')
&& formulaire.elements[i].name != 'copie') elts[i].checked = false;
{
formulaire.elements[i].checked = false;
}
} }
} }
function Inverser( formulaire ) function Inverser( formulaire )
{ {
var len = formulaire.elements.length; var elts = formulaire.elements;
var i=0; for(var i=0; i <elts.length; i++)
for( i=0; i<len; i++)
{ {
if ( formulaire.elements[i].type=='checkbox' if (elts[i].type=='checkbox')
&& formulaire.elements[i].name != 'copie') elts[i].checked = !elts[i].checked;
{
formulaire.elements[i].checked = !formulaire.elements[i].checked;
}
} }
} }
@ -46,23 +34,16 @@ function phpWGOpenWindow(theURL,winName,features)
img.src = theURL; img.src = theURL;
if (img.complete) if (img.complete)
{ {
var width=img.width +40; var width=img.width+40, height=img.height+40;
var height=img.height +40;
} }
else else
{ {
var width=640; var width=640, height=480;
var height=480; img.onload = function () { newWin.resizeTo( img.width+50, img.height+100); };
img.onload = resizeWindowToFit;
} }
newWin = window.open(theURL,winName,features+',left=2,top=1,width=' + width + ',height=' + height); newWin = window.open(theURL,winName,features+',left=2,top=1,width=' + width + ',height=' + height);
} }
function resizeWindowToFit()
{
newWin.resizeTo( img.width+50, img.height+100);
}
function popuphelp(url) function popuphelp(url)
{ {
window.open( url, 'dc_popup', window.open( url, 'dc_popup',
@ -70,15 +51,12 @@ function popuphelp(url)
); );
} }
Function.prototype.pwgBind = function() { Function.prototype.pwgBind = function() {
var __method = this, object = arguments[0], args = new Array(); var __method = this, object = arguments[0], args = Array.prototype.slice.call(arguments,1);
for (var i=1; i<arguments.length; i++) return function() {
args[i-1] = arguments[i]; return __method.apply(object, args.concat(arguments) );
return function() { return __method.apply(object, args); } }
} }
function PwgWS(urlRoot) function PwgWS(urlRoot)
{ {
this.urlRoot = urlRoot; this.urlRoot = urlRoot;
@ -144,8 +122,8 @@ PwgWS.prototype = {
onStateChange: function() { onStateChange: function() {
var readyState = this.transport.readyState; var readyState = this.transport.readyState;
if (readyState == 4) if (readyState==4)
this.respondToReadyState(this.transport.readyState); this.respondToReadyState(readyState);
}, },
dispatchError: function( httpCode, text ) dispatchError: function( httpCode, text )
@ -186,3 +164,11 @@ PwgWS.prototype = {
urlRoot: null, urlRoot: null,
options: {} options: {}
} }
function pwgAddEventListener(elem, evt, fn)
{
if (window.attachEvent)
elem.attachEvent('on'+evt, fn);
else
elem.addEventListener(evt, fn, false);
}