Changeset 7957
- Timestamp:
- Nov 30, 2010, 9:42:03 PM (14 years ago)
- Location:
- trunk/themes/default
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/themes/default/js/rating.js
r7852 r7957 3 3 function makeNiceRatingForm(options) 4 4 { 5 gRatingOptions = options || {};5 gRatingOptions = options; 6 6 var form = document.getElementById('rateForm'); 7 7 if (!form) return; //? template changed … … 37 37 38 38 pwgAddEventListener(rateButton, "click", updateRating); 39 pwgAddEventListener(rateButton, "mouseout", resetRatingStarDisplay); 40 pwgAddEventListener(rateButton, "mouseover", updateRatingStarDisplayEvt); 39 pwgAddEventListener(rateButton, "mouseout", function() {updateRatingStarDisplay( gUserRating );}); 40 pwgAddEventListener(rateButton, "mouseover", function(e) { 41 updateRatingStarDisplay( e.target ? e.target.initialRateValue : e.srcElement.initialRateValue); 42 }); 41 43 } 42 resetRatingStarDisplay();43 }44 45 function resetRatingStarDisplay()46 {47 44 updateRatingStarDisplay( gUserRating ); 48 45 } … … 52 49 for (var i=0; i<gRatingButtons.length; i++) 53 50 gRatingButtons[i].className = (userRating!=="" && userRating>=gRatingButtons[i].initialRateValue ) ? "rateButtonStarFull" : "rateButtonStarEmpty"; 54 }55 56 function updateRatingStarDisplayEvt(e)57 {58 updateRatingStarDisplay(59 e.target ? e.target.initialRateValue : e.srcElement.initialRateValue);60 51 } 61 52 … … 91 82 return false; 92 83 } 84 85 (function() { 86 if (typeof _pwgRatingAutoQueue!="undefined" && _pwgRatingAutoQueue.length) 87 { 88 for (var i=0; i<_pwgRatingAutoQueue.length; i++) 89 makeNiceRatingForm(_pwgRatingAutoQueue[i]); 90 } 91 _pwgRatingAutoQueue = { 92 push: function(opts) { 93 makeNiceRatingForm(opts); 94 } 95 } 96 })(); -
trunk/themes/default/js/scripts.js
r7852 r7957 22 22 } 23 23 24 Function.prototype.pwgBind = function() {25 var __method = this, object = arguments[0], args = Array.prototype.slice.call(arguments,1);26 27 return __method.apply(object, args.concat(arguments) );28 24 function pwgBind(object, method) { 25 var args = Array.prototype.slice.call(arguments,2); 26 return function() { 27 return method.apply(object, args.concat(Array.prototype.slice.call(arguments,0)) ); 28 } 29 29 } 30 30 31 function PwgWS(urlRoot) 31 32 { … … 40 41 41 42 PwgWS.prototype = { 42 43 43 callService : function(method, parameters, options) 44 44 { 45 45 if (options) 46 46 { 47 for (var prop ertyin options)48 this.options[prop erty] = options[property];47 for (var prop in options) 48 this.options[prop] = options[prop]; 49 49 } 50 try { this. transport= new XMLHttpRequest();}50 try { this.xhr = new XMLHttpRequest();} 51 51 catch(e) { 52 try { this. transport= new ActiveXObject('Msxml2.XMLHTTP'); }52 try { this.xhr = new ActiveXObject('Msxml2.XMLHTTP'); } 53 53 catch(e) { 54 try { this. transport= new ActiveXObject('Microsoft.XMLHTTP'); }54 try { this.xhr = new ActiveXObject('Microsoft.XMLHTTP'); } 55 55 catch (e){ 56 dispatchError(0, "Cannot create request object"); 56 this.error(0, "Cannot create request object"); 57 return; 57 58 } 58 59 } 59 60 } 60 this. transport.onreadystatechange = this.onStateChange.pwgBind(this);61 this.xhr.onreadystatechange = pwgBind(this, this.onStateChange); 61 62 62 63 var url = this.urlRoot+"ws.php?format=json"; … … 65 66 if (parameters) 66 67 { 67 for (var prop ertyin parameters)68 for (var prop in parameters) 68 69 { 69 if ( typeof parameters[prop erty] == 'object' && parameters[property])70 if ( typeof parameters[prop] == 'object' && parameters[prop]) 70 71 { 71 for (var i=0; i<parameters[prop erty].length; i++)72 body += "&"+prop erty+"[]="+encodeURIComponent(parameters[property][i]);72 for (var i=0; i<parameters[prop].length; i++) 73 body += "&"+prop+"[]="+encodeURIComponent(parameters[prop][i]); 73 74 } 74 75 else 75 body += "&"+prop erty+"="+encodeURIComponent(parameters[property]);76 body += "&"+prop+"="+encodeURIComponent(parameters[prop]); 76 77 } 77 78 } 78 79 79 80 if (this.options.method == "POST" ) 80 { 81 this.transport.open(this.options.method, url, this.options.async); 82 this.transport.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 83 this.transport.send(body); 84 } 81 this.xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 85 82 else 86 83 { 87 84 url += "&"+body; 88 this.transport.open(this.options.method, url, this.options.async); 89 this.transport.send(null); 85 body = null; 86 } 87 this.xhr.open(this.options.method, url, this.options.async); 88 try { 89 this.xhr.send(body); 90 } catch(e) { 91 this.error(0, e.message); 90 92 } 91 93 }, 92 94 93 95 onStateChange: function() { 94 var readyState = this. transport.readyState;96 var readyState = this.xhr.readyState; 95 97 if (readyState==4) 96 this.respondToReadyState(readyState); 98 { 99 try { 100 this.respondToReadyState(readyState); 101 } finally { 102 this.cleanup(); 103 } 104 } 97 105 }, 98 106 99 dispatchError: function( httpCode, text )107 error: function( httpCode, text ) 100 108 { 101 109 !this.options.onFailure || this.options.onFailure( httpCode, text); 110 this.cleanup(); 102 111 }, 103 112 104 113 respondToReadyState: function(readyState) 105 114 { 106 var transport = this.transport;107 if (readyState==4 && transport.status == 200)115 var xhr = this.xhr; 116 if (readyState==4 && xhr.status == 200) 108 117 { 109 118 var resp; 110 119 try { 111 eval('resp = ' + transport.responseText);120 resp = window.JSON && window.JSON.parse ? window.JSON.parse( xhr.responseText ) : (new Function("return " + xhr.responseText))(); 112 121 } 113 122 catch (e) { 114 this. dispatchError( 200, e.message + '\n' + transport.responseText.substr(0,512) );123 this.error( 200, e.message + '\n' + xhr.responseText.substr(0,512) ); 115 124 } 116 125 if (resp!=null) 117 126 { 118 127 if (resp.stat==null) 119 this. dispatchError( 200, "Invalid response" );128 this.error( 200, "Invalid response" ); 120 129 else if (resp.stat=='ok') 121 { 122 if (this.options.onSuccess) this.options.onSuccess( resp.result ); 123 } 130 !this.options.onSuccess || this.options.onSuccess( resp.result ); 124 131 else 125 this. dispatchError( 200, resp.err + " " + resp.message);132 this.error( 200, resp.err + " " + resp.message); 126 133 } 127 134 } 128 if (readyState==4 && transport.status != 200)129 this. dispatchError( transport.status, transport.statusText );135 if (readyState==4 && xhr.status != 200) 136 this.error( xhr.status, xhr.statusText ); 130 137 }, 131 138 139 cleanup: function() 140 { 141 if (this.xhr) this.xhr.onreadystatechange = null; 142 this.xhr = null; 143 this.options.onFailure = this.options.onSuccess = null; 144 }, 132 145 133 transport: null, 134 urlRoot: null, 135 options: {} 146 xhr: null 136 147 } 137 148 138 149 function pwgAddEventListener(elem, evt, fn) 139 150 { 140 if (window.a ttachEvent)141 elem.a ttachEvent('on'+evt, fn);151 if (window.addEventListener) 152 elem.addEventListener(evt, fn, false); 142 153 else 143 elem.a ddEventListener(evt, fn, false);154 elem.attachEvent('on'+evt, fn); 144 155 } -
trunk/themes/default/template/picture.tpl
r6993 r7957 209 209 {/if} 210 210 {/foreach} 211 <script type="text/javascript" src="{$ROOT_URL}themes/default/js/rating.js"></script>212 211 <script type="text/javascript"> 213 makeNiceRatingForm( {ldelim}rootUrl: '{$ROOT_URL|@escape:"javascript"}', image_id: {$current.id}, 214 updateRateText: "{'Update your rating'|@translate|@escape:'javascript'}", updateRateElement: document.getElementById("updateRate"), 215 ratingSummaryText: "{'%.2f (rated %d times)'|@translate|@escape:'javascript'}", ratingSummaryElement: document.getElementById("ratingSummary") {rdelim} ); 212 var _pwgRatingAutoQueue = _pwgRatingAutoQueue || []; 213 _pwgRatingAutoQueue.push( {ldelim}rootUrl: '{$ROOT_URL|@escape:"javascript"}', image_id: {$current.id}, 214 updateRateText: "{'Update your rating'|@translate|@escape:'javascript'}", updateRateElement: document.getElementById("updateRate"), 215 ratingSummaryText: "{'%.2f (rated %d times)'|@translate|@escape:'javascript'}", ratingSummaryElement: document.getElementById("ratingSummary") {rdelim} ); 216 (function () {ldelim} 217 var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = '{$ROOT_URL}themes/default/js/rating.js'; 218 var s0 = document.getElementsByTagName('script')[0]; s0.parentNode.insertBefore(s, s0); 219 })(); 216 220 </script> 217 221 </div>
Note: See TracChangeset
for help on using the changeset viewer.